Discrete math

profilefcyad9q
ebooksclub.org__Discrete_Mathematics_with_Applications.pdf

1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

S 50 R 51

1st Pass Pages

1019763_FM_VOL-I.qxp 9/17/07 4:22 PM Page viii

This page was intentionally left blank

List of Symbols

Subject Symbol Meaning Page

Logic ∼p not p 25 p ∧ q p and q 25 p ∨ q p or q 25 p ⊕ q or p XOR q p or q but not both p and q 28 P ≡ Q P is logically equivalent to Q 30 p → q if p then q 40 p ↔ q p if and only if q 45 ∴ therefore 51 P(x) predicate in x 97

P(x)⇒ Q(x) every element in the truth set for P(x) is in 104 the truth set for Q(x)

P(x)⇔ Q(x) P(x) and Q(x) have identical truth sets 104 ∀ for all 101 ∃ there exists 103

Applications of Logic NOT NOT-gate 67

AND AND-gate 67

OR OR-gate 67

NAND NAND-gate 75

NOR NOR-gate 75

| Sheffer stroke 74

↓ Peirce arrow 74 n2 number written in binary notation 78

n10 number written in decimal notation 78

n16 number written in hexadecimal notation 91

Number Theory and Applications

d | n d divides n 170 d |/ n d does not divide n 172 n div d the integer quotient of n divided by d 181

n mod d the integer remainder of n divided by d 181

⌊x⌋ the floor of x 191 ⌈x⌉ the ceiling of x 191 |x | the absolute value of x 187 gcd(a, b) the greatest common divisor of a and b 220

x := e x is assigned the value e 214

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Subject Symbol Meaning Page

Sequences . . . and so forth 227 n∑

k=m ak the summation from k equals m to n of ak 230

n∏

k=m ak the product from k equals m to n of ak 223

n! n factorial 237

Set a ∈ A a is an element of A 7 Theory a /∈ A a is not an element of A 7

{a1, a2, . . . , an} the set with elements a1, a2, . . . , an 7 {x ∈ D | P(x)} the set of all x in D for which P(x) is true 8 R, R−, R+, Rnonneg the sets of all real numbers, negative real 7, 8

numbers, positive real numbers, and nonnegative real numbers

Z, Z−, Z+, Znonneg the sets of all integers, negative integers, 7, 8 positive integers, and nonnegative integers

Q, Q−, Q+, Qnonneg the sets of all rational numbers, negative 7, 8 rational numbers, positive rational numbers, and nonnegative rational numbers

N the set of natural numbers 8

A ⊆ B A is a subset of B 9 A ̸⊆ B A is not a subset of B 9 A = B A equals B 339 A ∪ B A union B 341 A ∩ B A intersect B 341 B − A the difference of B minus A 341 Ac the complement of A 341

(x, y) ordered pair 11

(x1, x2, . . . , xn) ordered n-tuple 346

A × B the Cartesian product of A and B 12 A1 × A2 × · · ·× An the Cartesian product of A1, A2, . . . , An 347 ∅ the empty set 361 P(A) the power set of A 346

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

List of Symbols

Subject Symbol Meaning Page

Counting and N (A) the number of elements in set A 518 Probability P(A) the probability of a set A 518

P(n, r) the number of r -permutations of a set of 553 n elements

(n r

) n choose r , the number of r -combinations 566 of a set of n elements, the number of r -element subsets of a set of n elements

[xi1 , xi2 , . . . , xir ] multiset of size r 584 P(A | B) the probability of A given B 612

Functions f : X → Y f is a function from X to Y 384 f (x) the value of f at x 384

x f→y f sends x to y 384

f (A) the image of A 397

f −1(C) the inverse image of C 397

Ix the identity function on X 387

bx b raised to the power x 405, 406

expb(x) b raised to the power x 405, 406

logb(x) logarithm with base b of x 388

F−1 the inverse function of F 411

f ◦ g the composition of g and f 417

Algorithm x ∼= y x is approximately equal to y 237 Efficiency O( f (x)) big-O of f of x 727

!( f (x)) big-Omega of f of x 727

"( f (x)) big-Theta of f of x 727

Relations x R y x is related to y by R 14

R−1 the inverse relation of R 444

m ≡ n (mod d) m is congruent to n modulo d 473 [a] the equivalence class of a 465 x ≼ y x is related to y by a partial order relation ≼ 502

Continued on first page of back endpapers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

DISCRETE MATHEMATICS

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

DISCRETE MATHEMATICS WITH APPLICATIONS

FOURTH EDITION

SUSANNA S. EPP DePaul University

Australia · Brazil · Japan · Korea · Mexico · Singapore · Spain · United Kingdom · United States

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

S 50 R 51

1st Pass Pages

1019763_FM_VOL-I.qxp 9/17/07 4:22 PM Page viii

This page was intentionally left blank

52609_00_fm_pi-pxxvi.indd ii52609_00_fm_pi-pxxvi.indd ii 2/1/10 11:37:43 PM2/1/10 11:37:43 PM

This is an electronic version of the print textbook. Due to electronic rights

restrictions, some third party content may be suppressed. Editorial review has deemed that any suppres ed content does not materially

affect the overall learning experience. The publisher reserves the right to remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for materials in your areas of interest.

s

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Cover Photo: The stones are discrete objects placed one on top of another like a chain of careful reasoning. A person who decides to build such a tower aspires to the heights and enjoys playing with a challenging problem. 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 metaphor for discrete mathematics!

DiscreteMathematics with Applications, Fourth Edition Susanna S. Epp

Publisher: Richard Stratton

Senior Sponsoring Editor: Molly Taylor

Associate Editor: Daniel Seibert

Editorial Assistant: Shaylin Walsh

Associate Media Editor: Andrew Coppola

Senior Marketing Manager: Jennifer Pursley Jones

Marketing Communications Manager: Mary Anne Payumo

Marketing Coordinator: Erica O’Connell

Content Project Manager: Alison Eigel Zade

Senior Art Director: Jill Ort

Senior Print Buyer: Diane Gibbons

Right Acquisition Specialists: Timothy Sisler and Don Schlotman

Production Service: Elm Street Publishing Services

Photo Manager: Chris Althof, Bill Smith Group

Cover Designer: Hanh Luu

Cover Image: GettyImages.com (Collection: OJO Images, Photographer: Martin Barraud)

Compositor: Integra Software Services Pvt. Ltd.

c⃝ 2011, 2004, 1995 Brooks/Cole Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher.

For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706.

For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions.

Further permissions questions can be emailed to [email protected].

Library of Congress Control Number: 2010927831

Student Edition: ISBN-13: 978-0-495-39132-6 ISBN-10: 0-495-39132-8

Brooks/Cole 20 Channel Center Street Boston, MA 02210 USA

Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region.

Cengage Learning products are represented in Canada by Nelson Education, Ltd.

For your course and learning solutions, visit www.cengage.com

Purchase any of our products at your local college store or at our preferred online store www.cengagebrain.com.

Printed in Canada 1 2 3 4 5 6 7 14 13 12 11 10

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

To Jayne and Ernest

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

vi

CONTENTS

Chapter 1 Speaking Mathematically 1

1.1 Variables 1 Using Variables in Mathematical Discourse; Introduction to Universal, Existential, and Conditional Statements

1.2 The Language of Sets 6 The Set-Roster and Set-Builder Notations; Subsets; Cartesian Products

1.3 The Language of Relations and Functions 13 Definition of a Relation from One Set to Another; Arrow Diagram of a Relation; Definition of Function; Function Machines; Equality of Functions

Chapter 2 The Logic of Compound Statements 23

2.1 Logical Form and Logical Equivalence 23 Statements; Compound Statements; Truth Values; Evaluating the Truth of More Gen- eral Compound Statements; Logical Equivalence; Tautologies and Contradictions; Summary of Logical Equivalences

2.2 Conditional Statements 39 Logical Equivalences Involving →; Representation of If-Then As Or; The Nega- tion 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

2.3 Valid and Invalid Arguments 51 Modus Ponens and Modus Tollens; Additional Valid Argument Forms: Rules of Inference; Fallacies; Contradictions and Valid Arguments; Summary of Rules of Inference

2.4 Application: Digital Logic Circuits 64 Black Boxes and Gates; The Input/Output Table for a Circuit; The Boolean Expres- sion Corresponding to a Circuit; The Circuit Corresponding to a Boolean Expres- sion; Finding a Circuit That Corresponds to a Given Input/Output Table; Simplifying Combinational Circuits; NAND and NOR Gates

2.5 Application: Number Systems and Circuits for Addition 78 Binary Representation of Numbers; Binary Addition and Subtraction; Circuits for Computer Addition; Two’s Complements and the Computer Representation of

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Contents vii

Negative Integers; 8-Bit Representation of a Number; Computer Addition with Negative Integers; Hexadecimal Notation

Chapter 3 The Logic of Quantified Statements 96

3.1 Predicates and Quantified Statements I 96 The Universal Quantifier: ∀; The Existential Quantifier: ∃; Formal Versus Informal Language; Universal Conditional Statements; Equivalent Forms of Universal and Existential Statements; Implicit Quantification; Tarski’s World

3.2 Predicates and Quantified Statements II 108 Negations of Quantified Statements; Negations of Universal Conditional Statements; The Relation among ∀, ∃, ∧, and ∨; Vacuous Truth of Universal Statements; Variants of Universal Conditional Statements; Necessary and Sufficient Conditions, Only If

3.3 Statements with Multiple Quantifiers 117 Translating from Informal to Formal Language; Ambiguous Language; Negations of Multiply-Quantified Statements; Order of Quantifiers; Formal Logical Notation; Prolog

3.4 Arguments with Quantified Statements 132 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 4 Elementary Number Theory and Methods of Proof 145

4.1 Direct Proof and Counterexample I: Introduction 146 Definitions; Proving Existential Statements; Disproving Universal Statements by Counterexample; Proving Universal Statements; Directions for Writing Proofs of Universal Statements; Variations among Proofs; Common Mistakes; Getting Proofs Started; Showing That an Existential Statement Is False; Conjecture, Proof, and Disproof

4.2 Direct Proof and Counterexample II: Rational Numbers 163 More on Generalizing from the Generic Particular; Proving Properties of Rational Numbers; Deriving New Mathematics from Old

4.3 Direct Proof and Counterexample III: Divisibility 170 Proving Properties of Divisibility; Counterexamples and Divisibility; The Unique Factorization of Integers Theorem

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

viii Contents

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 180 Discussion of the Quotient-Remainder Theorem and Examples; div and mod; Alter- native Representations of Integers and Applications to Number Theory; Absolute Value and the Triangle Inequality

4.5 Direct Proof and Counterexample V: Floor and Ceiling 191 Definition and Basic Properties; The Floor of n/2

4.6 Indirect Argument: Contradiction and Contraposition 198 Proof by Contradiction; Argument by Contraposition; Relation between Proof by Contradiction and Proof by Contraposition; Proof as a Problem-Solving Tool

4.7 Indirect Argument: Two Classical Theorems 207 The Irrationality of

√ 2; Are There Infinitely Many Prime Numbers?; When to Use

Indirect Proof; Open Questions in Number Theory

4.8 Application: Algorithms 214 An Algorithmic Language; A Notation for Algorithms; Trace Tables; The Division Algorithm; The Euclidean Algorithm

Chapter 5 Sequences, Mathematical Induction, and Recursion 227

5.1 Sequences 227 Explicit Formulas for Sequences; Summation Notation; Product Notation; Properties of Summations and Products; Change of Variable; Factorial and n Choose r Notation; Sequences in Computer Programming; Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2

5.2 Mathematical Induction I 244 Principle of Mathematical Induction; Sum of the First n Integers; Proving an Equal- ity; Deducing Additional Formulas; Sum of a Geometric Sequence

5.3 Mathematical Induction II 258 Comparison of Mathematical Induction and Inductive Reasoning; Proving Divisibil- ity Properties; Proving Inequalities; A Problem with Trominoes

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 268 Strong Mathematical Induction;Binary Representation of Integers;The Well-Ordering Principle for the Integers

5.5 Application: Correctness of Algorithms 279 Assertions; Loop Invariants; Correctness of the Division Algorithm; Correctness of the Euclidean Theorem

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Contents ix

5.6 Defining Sequences Recursively 290 Definition of Recurrence Relation; Examples of Recursively Defined Sequences; Recursive Definitions of Sum and Product

5.7 Solving Recurrence Relations by Iteration 304 The Method of Iteration; Using Formulas to Simplify Solutions Obtained by Itera- tion; Checking the Correctness of a Formula by Mathematical Induction; Discovering That an Explicit Formula Is Incorrect

5.8 Second-Order Linear Homogenous Recurrence Relations with Constant Coefficients 317 Derivation of a Technique for Solving These Relations; The Distinct-Roots Case; The Single-Root Case

5.9 General Recursive Definitions and Structural Induction 328 Recursively Defined Sets; Using Structural Induction to Prove Properties about Recursively Defined Sets; Recursive Functions

Chapter 6 Set Theory 336

6.1 Set Theory: Definitions and the Element Method of Proof 336 Subsets; Proof and Disproof; Set Equality; Venn Diagrams; Operations on Sets; The Empty Set; Partitions of Sets; Power Sets; Cartesian Products; An Algorithm to Check Whether One Set Is a Subset of Another (Optional)

6.2 Properties of Sets 352 Set Identities; Proving Set Identities; Proving That a Set Is the Empty Set

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras 367 Disproving an Alleged Set Property; Problem-Solving Strategy; The Number of Sub- sets of a Set; “Algebraic” Proofs of Set Identities

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem 374 Boolean Algebras; Description of Russell’s Paradox; The Halting Problem

Chapter 7 Functions 383

7.1 Functions Defined on General Sets 383 Additional Function Terminology; More Examples of Functions; Boolean Functions; Checking Whether a Function Is Well Defined; Functions Acting on Sets

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

x Contents

7.2 One-to-One and Onto, Inverse Functions 397 One-to-One Functions; One-to-One Functions on Infinite Sets; Application: Hash Functions; Onto Functions; Onto Functions on Infinite Sets; Relations between Expo- nential and Logarithmic Functions; One-to-One Correspondences; Inverse Functions

7.3 Composition of Functions 416 Definition and Examples; Composition of One-to-One Functions; Composition of Onto Functions

7.4 Cardinality with Applications to Computability 428 Definition of Cardinal Equivalence; Countable Sets; The Search for Larger Infinities: The Cantor Diagonalization Process; Application: Cardinality and Computability

Chapter 8 Relations 442

8.1 Relations on Sets 442 Additional Examples of Relations; The Inverse of a Relation; Directed Graph of a Relation; N -ary Relations and Relational Databases

8.2 Reflexivity, Symmetry, and Transitivity 449 Reflexive, Symmetric, and Transitive Properties; Properties of Relations on Infinite Sets; The Transitive Closure of a Relation

8.3 Equivalence Relations 459 The Relation Induced by a Partition; Definition of an Equivalence Relation; Equiva- lence Classes of an Equivalence Relation

8.4 Modular Arithmetic with Applications to Cryptography 478 Properties of Congruence Modulo n; Modular Arithmetic; Extending the Euclidean Algorithm; Finding an Inverse Modulo n; RSA Cryptography; Euclid’s Lemma; Fermat’s Little Theorem; Why Does the RSA Cipher Work?; Additional Remarks on Number Theory and Cryptography

8.5 Partial Order Relations 498 Antisymmetry; Partial Order Relations; Lexicographic Order; Hasse Diagrams; Partially and Totally Ordered Sets; Topological Sorting; An Application; PERT and CPM

Chapter 9 Counting and Probability 516

9.1 Introduction 517 Definition of Sample Space and Event; Probability in the Equally Likely Case; Count- ing the Elements of Lists, Sublists, and One-Dimensional Arrays

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Contents xi

9.2 Possibility Trees and the Multiplication Rule 525 Possibility Trees; The Multiplication Rule; When the Multiplication Rule Is Difficult or Impossible to Apply; Permutations; Permutations of Selected Elements

9.3 Counting Elements of Disjoint Sets: The Addition Rule 540 The Addition Rule; The Difference Rule; The Inclusion/Exclusion Rule

9.4 The Pigeonhole Principle 554 Statement and Discussion of the Principle; Applications; Decimal Expansions of Fractions; Generalized Pigeonhole Principle; Proof of the Pigeonhole Principle

9.5 Counting Subsets of a Set: Combinations 565 r -Combinations; Ordered and Unordered Selections; Relation between Permutations and Combinations; Permutation of a Set with Repeated Elements; Some Advice about Counting; The Number of Partitions of a Set into r Subsets

9.6 r-Combinations with Repetition Allowed 584 Multisets and How to Count Them; Which Formula to Use?

9.7 Pascal’s Formula and the Binomial Theorem 592 Combinatorial Formulas; Pascal’s Triangle; Algebraic and Combinatorial Proofs of Pascal’s Formula; The Binomial Theorem and Algebraic and Combinatorial Proofs for It; Applications

9.8 Probability Axioms and Expected Value 605 Probability Axioms; Deriving Additional Probability Formulas; Expected Value

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 611 Conditional Probability; Bayes’ Theorem; Independent Events

Chapter 10 Graphs and Trees 625

10.1 Graphs: Definitions and Basic Properties 625 Basic Terminology and Examples of Graphs; Special Graphs; The Concept of Degree

10.2 Trails, Paths, and Circuits 642 Definitions; Connectedness; Euler Circuits; Hamiltonian Circuits

10.3 Matrix Representations of Graphs 661 Matrices; Matrices and Directed Graphs; Matrices and Undirected Graphs; Matrices and Connected Components; Matrix Multiplication; Counting Walks of Length N

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xii Contents

10.4 Isomorphisms of Graphs 675 Definition of Graph Isomorphism and Examples; Isomorphic Invariants; Graph Isomorphism for Simple Graphs

10.5 Trees 683 Definition and Examples of Trees; Characterizing Trees

10.6 Rooted Trees 694 Definition and Examples of Rooted Trees; Binary Trees and Their Properties

10.7 Spanning Trees and Shortest Paths 701 Definition of a Spanning Tree; Minimum Spanning Trees; Kruskal’s Algorithm; Prim’s Algorithm; Dijkstra’s Shortest Path Algorithm

Chapter 11 Analysis of Algorithm Efficiency 717

11.1 Real-Valued Functions of a Real Variable and Their Graphs 717 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

11.2 O-, !-, and "-Notations 725 Definition and General Properties of O-, !-, and "-Notations; Orders of Power Functions; Orders of Polynomial Functions; Orders for Functions of Integer Vari- ables; Extension to Functions Composed of Rational Power Functions

11.3 Application: Analysis of Algorithm Efficiency I 739 Computing Orders of Simple Algorithms; The Sequential Search Algorithm; The Insertion Sort Algorithm; Time Efficiency of an Algorithm

11.4 Exponential and Logarithmic Functions: Graphs and Orders 751 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

11.5 Application: Analysis of Algorithm Efficiency II 764 Binary Search; Divide-and-Conquer Algorithms; The Efficiency of the Binary Search Algorithm; Merge Sort; Tractable and Intractable Problems; A Final Remark on Algorithm Efficiency

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Contents xiii

Chapter 12 Regular Expressions and Finite-State Automata 779

12.1 Formal Languages and Regular Expressions 780 Definitions and Examples of Formal Languages and Regular Expressions; The Lan- guage Defined by a Regular Expression; Practical Uses of Regular Expressions

12.2 Finite-State Automata 791 Definition of a Finite-State Automaton; The Language Accepted by an Automa- ton; The Eventual-State Function; Designing a Finite-State Automaton; Simulating a Finite-State Automaton Using Software; Finite-State Automata and Regular Expres- sions; Regular Languages

12.3 Simplifying Finite-State Automata 808 *-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-1

Appendix B Solutions and Hints to Selected Exercises A-4

Index I-1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xiv

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, math- ematics 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 cryptog- raphy, 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 applica- tions 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 Amer- ica, 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 com- puter 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 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 under- stood 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 con- tinuing 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 fash- ion. 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 technol- ogy of the computer age. The main themes of a first course in discrete mathematics are logic and proof, induction and recursion, discrete structures, combinatorics and discrete probability, algorithms and their analysis, and applications and modeling.

Logic and Proof Probably the most important goal of a first course in discrete math- ematics 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

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Preface xv

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.

Induction and Recursion An exciting development of recent years has been the increased appreciation for the power and beauty of “recursive thinking.” To think recur- sively 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.

Discrete Structures Discrete mathematical structures are the abstract structures that describe, categorize, and reveal the underlying relationships among discrete mathemat- ical 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.

Combinatorics and Discrete Probability Combinatorics is the mathematics of count- ing and arranging objects, and probability is the study of laws concerning the measure- ment 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 combina- torics 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 mid- dle 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 algo- rithm 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 algo- rithm will need in order to compare it to other algorithms that produce the same output requires knowledge of combinatorics, recurrence relations, functions, and O-, !-, and "-notations.

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

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xvi Preface

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 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 in Section 8.4, they have been introduced to the logic of mathematical discourse in Chapters 1, 2, and 3, learned the basic methods of proof and the concepts of mod and div in Chapter 4, explored mod and div as functions in Chapter 7, and become familiar with equivalence relations in Sections 8.2 and 8.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 problem- solution 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.

Marginal Notes and Test Yourself Questions Notes about issues of particular importance and cautionary comments to help students avoid common mistakes are included in the margins throughout the book. Questions designed to focus attention on the main ideas of each section are located between the text and the exercises. For convenience, the questions use a fill-in-the-blank format, and the answers are found immediately after the exercises.

Exercises The book contains almost 2600 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 con- tains 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.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Preface xvii

There are also plenty of exercises without solutions to help students learn to grapple with mathematical problems in a realistic environment.

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 one edition so extensively that it had fallen apart, and he actually went out and bought a copy of the next edition, which he was continuing to use in a master’s program. Figures and tables are included where doing so would help readers to a better understanding. In most, a second color is used to highlight meaning. My rationale for screening statements of definitions and theorems, for putting titles on exercises, and for giving the meanings 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. In addition to the following items, there is additional instructor support on the book’s website, described later in the preface.

Exercises The large variety of exercises at all levels of difficulty allows instructors great free- dom 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 and Study Guide have numbers that are a multi- ple of three. There are exercises of every type that are represented in this book that 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 assign- ments 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 proofs and disproofs, I have tried to describe the kinds of approaches that mathematicians use when confronting challenging problems in their own research.

Instructor Solutions Complete instructor solutions to all exercises are available to anyone teaching a course from this book via Cengage’s Solution Builder service. Instructors can sign up for access at www.cengage.com/solutionbuilder.

Highlights of the Fourth Edition The changes made for this edition are based on suggestions from colleagues and other long-time users of previous editions, on continuing interactions with my students, and on developments within the evolving fields of computer science and mathematics.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xviii Preface

Reorganization A new Chapter 1 introduces students to some of the precise language that is a foun- dation for much mathematical thought: the language of variables, sets, relations, and functions. In response to requests from some instructors, core material is now placed together in Chapter 1–8, with the chapter on recursion now joined to the chapter on induction. Chapters 9–12 were placed together at the end because, although many instructors cover one or more of them, there is considerable diversity in their choices, with some of the topics from these chapters being included in other courses.

Improved Pedagogy

• The number of exercises has been increased to almost 2600. Approximately 300 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.

• The exposition has been reexamined throughout and revised where needed. • Discussion of historical background and recent results has been expanded and the

number of photographs of mathematicians and computer scientists whose contribu- tions are discussed in the book has been increased.

Logic and Set theory

• The definition of sound argument is now included, and there is additional clarifica- tion of the difference between a valid argument and a true conclusion.

• Examples and exercises about trailing quantifiers have been added. • Definitions for infinite unions and intersections have been incorporated.

Introduction to Proof

• The directions for writing proofs and the discussion of common mistakes 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

well-ordering principle and on recursive definitions have been expanded. • Increased attention has been given to structural induction.

Number Theory

• A subsection on open problems in number theory has been expanded and includes additional discussion of recent mathematical discoveries in number theory.

• The presentation in the section on modular arithmetic and cryptography has been streamlined.

• The discussion of testing for primality has been clarified.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Preface xix

Combinatorics and Discrete Probability

• The discussion of the pigeonhole principle has been moved to this chapter.

Functions

• There is increased coverage of functions of more than one variable and of functions acting on sets.

Graph Theory

• The terminology about traveling in a graph has been updated. • Dijkstra’s shortest path algorithm is now included. • Exercises were added to introduce students to graph coloring.

Companion Website www.cengage.com/math/epp

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 mathe- matics,

• additional examples and exercises with solutions, • review guides for the chapters of the book.

A special section for instructors contains:

• suggestions about how to approach the material of each chapter, • solutions for all exercises not fully solved in Appendix B, • ideas for projects and writing assignments, • PowerPoint slides, • review sheets and additional exercises for quizzes and exams.

Student Solutions Manual and Study Guide (ISBN-10: 0-495-82613-8; ISBN-13: 978-0-495-82613-2)

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 became aware that some students wanted the opportunity to obtain additional helpful materials. In response, I developed a Student Solutions Manual and 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.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xx Preface

Organization This book may be used effectively for a one- or two-semester course. Chapters contain 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.

Sections Containing Optional Sections Containing Optional Chapter Core Sections Mathematical Material Computer Science Applications

1 1.1–1.3

2 2.1–2.3 2.5 2.4, 2.5

3 3.1–3.4 3.3 3.3

4 4.1–4.4, 4.6 4.5, 4.7 4.8

5 5.1, 5.2, 5.6, 5.7 5.3, 5.4, 5.8 5.1, 5.5, 5.9

6 6.1 6.2–6.4 6.1, 6.4

7 7.1, 7.2 7.3, 7.4 7.1, 7.2, 7.4

8 8.1–8.3 8.4, 8.5 8.4, 8.5

9 9.1–9.4 9.5–9.9 9.3

10 10.1, 10.5 10.2–10.4, 10.6 10.1, 10.2, 10.5–10.7

11 11.1, 11.2 11.4 11.3, 11.5

12 12.1, 12.2 12.3 12.1–12.3

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 inde- pendent that instructors need to make at most minor adjustments if they skip chapters but follow paths along branches of the tree.

In most cases, covering only the core sections of the chapters is adequate preparation for moving down the tree.

34

1

2

33

5

10 12*

6

8

11

7 9

∗Section 8.3 is needed for Section 12.3 but not for Sections 12.1 and 12.2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Preface xxi

Acknowledgments 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, Wal- ter 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 pro- cesses 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, Charles Suchar, and my former deans, Michael Mezey and 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: David Addis, Texas Christian University; Rachel Esselstein, California State University- Monterrey Bay; William Marion, Valparaiso University; Michael McClendon, Univer- sity of Central Oklahoma; and Steven Miller, Brown University. For their help with previous editions of the book, I am grateful to Itshak Borosh, Texas A & M Univer- sity; 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 Arling- ton; Pablo Echeverria, Camden County College; Henry A. Etlinger, Rochester Insti- tute of Technology; Melvin J. Friske, Wisconsin Lutheran College; William Gasarch, University of Maryland; Ladnor Geissinger, University of North Carolina; Jerrold R. Griggs, University of South Carolina; Nancy Baxter Hastings, Dickinson College; Lillian Hupert, Loyola University Chicago; Joseph Kolibal, University of Southern Mississippi; Benny Lo, International Technological University; George Luger, University of New Mexico; 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; Norman Richert, University of Houston–Clear Lake; 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; Peter Williams, California State Uni- versity at San Bernardino; and Jay Zimmerman, Towson University 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 pre- vious editions of the book, especially Jonathan Goldstine, Pennsylvania State University; David Hecker, St. Joseph’s University; Edward Huff, Northern Virginia Community Col- lege; Robert Messer, Albion College; Sophie Quigley, Ryerson University; Piotr Rud- nicki, University of Alberta; Anwar Shiek, Diné College; Norton Starr, Amherst College; and Eng Wee, National University of Singapore. Production of the third edition received valuable assistance from Christopher Novak, University of Michigan, Dearborn, and Ian Crewe, Ascension Collegiate School. For the third and fourth editions I am especially grateful for the many excellent suggestions for improvement made by Tom Jenkyns, Brock University, whose assistance throughout the production process was invaluable.

I owe many thanks to the Brooks/Cole staff, especially my editor, Dan Seibert, for his thoughtful advice and reassuringly calm direction of the production process, and my

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

xxii Preface

previous editors, Stacy Green, Robert Pirtle, Barbara Holland, and Heather Bennett, for their encouragement and enthusiasm.

The older I get the more I realize the profound debt I owe my own mathematics teach- ers 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

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1

CHAPTER 1

SPEAKING MATHEMATICALLY

Therefore O students study mathematics and do not build without foundations. —Leonardo da Vinci (1452–1519)

The aim of this book is to introduce you to a mathematical way of thinking that can serve you in a wide variety of situations. Often when you start work on a mathematical problem, you may have only a vague sense of how to proceed. You may begin by looking at examples, drawing pictures, playing around with notation, rereading the problem to focus on more of its details, and so forth. The closer you get to a solution, however, the more your thinking has to crystallize. And the more you need to understand, the more you need language that expresses mathematical ideas clearly, precisely, and unambiguously.

This chapter will introduce you to some of the special language that is a foundation for much mathematical thought, the language of variables, sets, relations, and functions. Think of the chapter like the exercises you would do before an important sporting event. Its goal is to warm up your mental muscles so that you can do your best.

1.1 Variables A variable is sometimes thought of as a mathematical “John Doe” because you can use it as a placeholder when you want to talk about something but either (1) you imagine that it has one or more values but you don’t know what they are, or (2) you want whatever you say about it to be equally true for all elements in a given set, and so you don’t want to be restricted to considering only a particular, concrete value for it. To illustrate the first use, consider asking

Is there a number with the following property: doubling it and adding 3 gives the same result as squaring it?

In this sentence you can introduce a variable to replace the potentially ambiguous word “it”:

Is there a number x with the property that 2x + 3 = x2?

The advantage of using a variable is that it allows you to give a temporary name to what you are seeking so that you can perform concrete computations with it to help discover its possible values. To emphasize the role of the variable as a placeholder, you might write the following:

Is there a number " with the property that 2 ·"+ 3 = "2?

The emptiness of the box can help you imagine filling it in with a variety of different values, some of which might make the two sides equal and others of which might not.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2 Chapter 1 Speaking Mathematically

To illustrate the second use of variables, consider the statement:

No matter what number might be chosen, if it is greater than 2, then its square is greater than 4.

In this case introducing a variable to give a temporary name to the (arbitrary) number you might choose enables you to maintain the generality of the statement, and replacing all instances of the word “it” by the name of the variable ensures that possible ambiguity is avoided:

No matter what number n might be chosen, if n is greater than 2, then n2 is greater than 4.

Example 1.1.1 Writing Sentences Using Variables

Use variables to rewrite the following sentences more formally.

a. Are there numbers with the property that the sum of their squares equals the square of their sum?

b. Given any real number, its square is nonnegative.

Solution

a. Are there numbers a and b with the property that a2 + b2 = (a + b)2? Or: Are there numbers a and b such that a2 + b2 = (a + b)2? Or: Do there exist any numbers a and b such that a2 + b2 = (a + b)2?

Note In part (a) the answer is yes. For instance, a = 1 and b = 0 would work. Can you think of other numbers that would also work?

b. Given any real number r, r2 is nonnegative. Or: For any real number r, r2 ≥ 0. Or: For all real numbers r, r2 ≥ 0. ■

Some Important Kinds of Mathematical Statements Three of the most important kinds of sentences in mathematics are universal statements, conditional statements, and existential statements:

A universal statement says that a certain property is true for all elements in a set. (For example: All positive numbers are greater than zero.)

A conditional statement says that if one thing is true then some other thing also has to be true. (For example: If 378 is divisible by 18, then 378 is divisible by 6.)

Given a property that may or may not be true, an existential statement says that there is at least one thing for which the property is true. (For example: There is a prime number that is even.)

In later sections we will define each kind of statement carefully and discuss all of them in detail. The aim here is for you to realize that combinations of these statements can be expressed in a variety of different ways. One way uses ordinary, everyday language and another expresses the statement using one or more variables. The exercises are designed to help you start becoming comfortable in translating from one way to another.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.1 Variables 3

Universal Conditional Statements Universal statements contain some variation of the words “for all” and conditional state- ments contain versions of the words “if-then.” A universal conditional statement is a statement that is both universal and conditional. Here is an example:

For all animals a, if a is a dog, then a is a mammal.

One of the most important facts about universal conditional statements is that they can be rewritten in ways that make them appear to be purely universal or purely conditional. For example, the previous statement can be rewritten in a way that makes its conditional nature explicit but its universal nature implicit:

If a is a dog, then a is a mammal. Or : If an animal is a dog, then the animal is a mammal.

The statement can also be expressed so as to make its universal nature explicit and its conditional nature implicit:

For all dogs a, a is a mammal. Or : All dogs are mammals.

The crucial point is that the ability to translate among various ways of expressing univer- sal conditional statements is enormously useful for doing mathematics and many parts of computer science.

Example 1.1.2 Rewriting a Universal Conditional Statement

Fill in the blanks to rewrite the following statement:

For all real numbers x , if x is nonzero then x2 is positive.

a. If a real number is nonzero, then its square .

Note If you introduce x in the first part of the sentence, be sure to include it in the second part of the sentence.

b. For all nonzero real numbers x , .

c. If x , then .

d. The square of any nonzero real number is .

e. All nonzero real numbers have .

Solution

a. is positive

b. x2 is positive

c. is a nonzero real number; x2 is positive

d. positive

e. positive squares (or: squares that are positive) ■

Universal Existential Statements A universal existential statement is a statement that is universal because its first part says that a certain property is true for all objects of a given type, and it is existential because its second part asserts the existence of something. For example:Note For a number b to

be an additive inverse for a number a means that a + b = 0. Every real number has an additive inverse.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4 Chapter 1 Speaking Mathematically

In this statement the property “has an additive inverse” applies universally to all real num- bers. “Has an additive inverse” asserts the existence of something—an additive inverse— for each real number. However, the nature of the additive inverse depends on the real number; different real numbers have different additive inverses. Knowing that an additive inverse is a real number, you can rewrite this statement in several ways, some less formal and some more formal∗:

All real numbers have additive inverses. Or : For all real numbers r , there is an additive inverse for r . Or : For all real numbers r, there is a real number s such that s is an additive inverse

for r.

Introducing names for the variables simplifies references in further discussion. For instance, after the third version of the statement you might go on to write: When r is positive, s is negative, when r is negative, s is positive, and when r is zero, s is also zero.

One of the most important reasons for using variables in mathematics is that it gives you the ability to refer to quantities unambiguously throughout a lengthy mathematical argument, while not restricting you to consider only specific values for them.

Example 1.1.3 Rewriting a Universal Existential Statement

Fill in the blanks to rewrite the following statement: Every pot has a lid.

a. All pots .

b. For all pots P , there is .

c. For all pots P , there is a lid L such that .

Solution

a. have lids

b. a lid for P

c. L is a lid for P ■

Existential Universal Statements An existential universal statement is a statement that is existential because its first part asserts that a certain object exists and is universal because its second part says that the object satisfies a certain property for all things of a certain kind. For example:

There is a positive integer that is less than or equal to every positive integer:

This statement is true because the number one is a positive integer, and it satisfies the property of being less than or equal to every positive integer. We can rewrite the statement in several ways, some less formal and some more formal:

Some positive integer is less than or equal to every positive integer. Or : There is a positive integer m that is less than or equal to every positive integer. Or : There is a positive integer m such that every positive integer is greater than or

equal to m. Or : There is a positive integer m with the property that for all positive integers

n, m ≤ n.

∗A conditional could be used to help express this statement, but we postpone the additional com- plexity to a later chapter.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.1 Variables 5

Example 1.1.4 Rewriting an Existential Universal Statement

Fill in the blanks to rewrite the following statement in three different ways:

There is a person in my class who is at least as old as every person in my class.

a. Some is at least as old as .

b. There is a person p in my class such that p is .

c. There is a person p in my class with the property that for every person q in my class, p is .

Solution a. person in my class; every person in my class

b. at least as old as every person in my class

c. at least as old as q ■

Some of the most important mathematical concepts, such as the definition of limit of a sequence, can only be defined using phrases that are universal, existential, and condi- tional, and they require the use of all three phrases “for all,” “there is,” and “if-then.” For example, if a1, a2, a3, . . . is a sequence of real numbers, saying that

the limit of an as n approaches infinity is L

means that

for all positive real numbers ε, there is an integer N such that for all integers n, if n > N then −ε < an − L < ε.

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. A universal statement asserts that a certain property is for .

2. A conditional statement asserts that if one thing then some other thing .

3. Given a property that may or may not be true, an existential statement asserts that for which the property is true.

Exercise Set 1.1 Appendix B contains either full or partial solutions to all exercises with blue numbers. When the solution is not complete, the exercise number has an H next to it. A ✶ next to an exercise number signals that the exercise is more challenging than usual. Be careful not to get into the habit of turning to the solutions too quickly. Make every effort to work exercises on your own before checking your answers. See the Preface for additional sources of assistance and further study.

In each of 1–6, fill in the blanks using a variable or variables to rewrite the given statement.

1. Is there a real number whose square is −1? a. Is there a real number x such that ? b. Does there exist such that x2 = −1?

2. Is there an integer that has a remainder of 2 when it is divided by 5 and a remainder of 3 when it is divided by 6? a. Is there an integer n such that n has ? b. Does there exist such that if n is divided by 5 the

remainder is 2 and if ? Note: There are integers with this property. Can you think of one?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6 Chapter 1 Speaking Mathematically

3. Given any two real numbers, there is a real number in between. a. Given any two real numbers a and b, there is a real num-

ber c such that c is .

b. For any two , such that a < c < b.

4. Given any real number, there is a real number that is greater. a. Given any real number r , there is s such that s is

. b. For any , such that s > r .

5. The reciprocal of any positive real number is positive. a. Given any positive real number r , the reciprocal of . b. For any real number r , if r is , then . c. If a real number r , then .

6. The cube root of any negative real number is negative. a. Given any negative real number s, the cube root of . b. For any real number s, if s is , then . c. If a real number s , then .

7. Rewrite the following statements less formally, without using variables. Determine, as best as you can, whether the statements are true or false.

a. There are real numbers u and v with the property that u + v < u − v.

b. There is a real number x such that x2 < x . c. For all positive integers n, n2 ≥ n. d. For all real numbers a and b, |a + b| ≤ |a| + |b|.

In each of 8–13, fill in the blanks to rewrite the given statement.

8. For all objects J , if J is a square then J has four sides. a. All squares . b. Every square . c. If an object is a square, then it .

d. If J , then J . e. For all squares J , .

9. For all equations E , if E is quadratic then E has at most two real solutions. a. All quadratic equations . b. Every quadratic equation . c. If an equation is quadratic, then it . d. If E , then E . e. For all quadratic equations E , .

10. Every nonzero real number has a reciprocal. a. All nonzero real numbers . b. For all nonzero real numbers r , there is for r . c. For all nonzero real numbers r , there is a real number s

such that .

11. Every positive number has a positive square root. a. All positive numbers . b. For any positive number e, there is for e. c. For all positive numbers e, there is a positive number r

such that .

12. There is a real number whose product with every number leaves the number unchanged. a. Some has the property that its . b. There is a real number r such that the product of r . c. There is a real number r with the property that for every

real number s, .

13. There is a real number whose product with every real number equals zero. a. Some has the property that its . b. There is a real number a such that the product of a . c. There is a real number a with the property that for every

real number b, .

Answers for Test Yourself 1. true; all elements of a set 2. is true; also has to be true 3. there is at least one thing

1.2 The Language of Sets . . . when we attempt to express in mathematical symbols a condition proposed in words. First, we must understand thoroughly the condition. Second, we must be familiar with the forms of mathematical expression. —George Polyá (1887–1985)

Use of the word set as a formal mathematical term was introduced in 1879 by Georg Cantor (1845–1918). For most mathematical purposes we can think of a set intuitively, as

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.2 The Language of Sets 7

Cantor did, simply as a collection of elements. For instance, if C is the set of all countries that are currently in the United Nations, then the United States is an element of C , and if I is the set of all integers from 1 to 100, then the number 57 is an element of I .

• Notation If S is a set, the notation x ∈ S means that x is an element of S. The notation x /∈ S means that x is not an element of S. A set may be specified using the set-roster notation by writing all of its elements between braces. For example, {1, 2, 3} denotes the set whose elements are 1, 2, and 3. A variation of the notation is sometimes used to describe a very large set, as when we write {1, 2, 3, . . . , 100} to refer to the set of all integers from 1 to 100. A similar notation can also describe an infinite set, as when we write {1, 2, 3, . . .} to refer to the set of all positive integers. (The symbol . . . is called an ellipsis and is read “and so forth.”)

The axiom of extension says that a set is completely determined by what its elements are—not the order in which they might be listed or the fact that some elements might be listed more than once.

Example 1.2.1 Using the Set-Roster Notation

a. Let A = {1, 2, 3}, B = {3, 1, 2}, and C = {1, 1, 2, 3, 3, 3}. What are the elements of A, B, and C? How are A, B, and C related?

b. Is {0} = 0? c. How many elements are in the set {1, {1}}?

d. For each nonnegative integer n, let Un = {n,−n}. Find U1, U2, and U0.

Solution

a. A, B, and C have exactly the same three elements: 1, 2, and 3. Therefore, A, B, and C are simply different ways to represent the same set.

b. {0} ̸= 0 because {0} is a set with one element, namely 0, whereas 0 is just the symbol that represents the number zero.

c. The set {1, {1}} has two elements: 1 and the set whose only element is 1.

d. U1 = {1,−1}, U2 = {2,−2}, U0 = {0,−0} = {0, 0} = {0}.

Certain sets of numbers are so frequently referred to that they are given special symbolic names. These are summarized in the table on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8 Chapter 1 Speaking Mathematically

Symbol Set

R set of all real numbers

Z set of all integers

Q set of all rational numbers, or quotients of integers

Note The Z is the first letter of the German word for integers, Zahlen. It stands for the set of all integers and should not be used as a shorthand for the word integer. Addition of a superscript + or − or the letters nonneg indicates that only the positive

or negative or nonnegative elements of the set, respectively, are to be included. Thus R+ denotes the set of positive real numbers, and Znonneg refers to the set of nonnegative integers: 0, 1, 2, 3, 4, and so forth. Some authors refer to the set of nonnegative integers as the set of natural numbers and denote it as N. Other authors call only the positive integers natural numbers. To prevent confusion, we simply avoid using the phrase natural numbers in this book.

The set of real numbers is usually pictured as the set of all points on a line, as shown below. The number 0 corresponds to a middle point, called the origin. A unit of dis- tance is marked off, and each point to the right of the origin corresponds to a positive real number found by computing its distance from the origin. Each point to the left of the origin corresponds to a negative real number, which is denoted by computing its dis- tance from the origin and putting a minus sign in front of the resulting number. The set of real numbers is therefore divided into three parts: the set of positive real numbers, the set of negative real numbers, and the number 0. Note that 0 is neither positive nor neg- ative Labels are given for a few real numbers corresponding to points on the line shown below.

–3 –2 –1 0 1 2 3

13 4

1 3

2.6–0.8–√35 2

– √2

The real number line is called continuous because it is imagined to have no holes. The set of integers corresponds to a collection of points located at fixed intervals along the real number line. Thus every integer is a real number, and because the integers are all separated from each other, the set of integers is called discrete. The name discrete mathematics comes from the distinction between continuous and discrete mathematical objects.

Another way to specify a set uses what is called the set-builder notation. Note We read the left-hand brace as “the set of all” and the vertical line as “such that.” In all other mathematical contexts, however, we do not use a vertical line to denote the words “such that”; we abbreviate “such that” as “s. t.” or “s. th.” or “ · ∋ · .”

• Set-Builder Notation Let S denote a set and let P(x) be a property that elements of S may or may not satisfy. We may define a new set to be the set of all elements x in S such that P(x) is true. We denote this set as follows:

{x ∈ S | P(x)}↗ ↖ the set of all such that

Occasionally we will write {x | P(x)} without being specific about where the ele- ment x comes from. It turns out that unrestricted use of this notation can lead to genuine contradictions in set theory. We will discuss one of these in Section 6.4 and will be careful to use this notation purely as a convenience in cases where the set S could be specified if necessary.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.2 The Language of Sets 9

Example 1.2.2 Using the Set-Builder Notation

Given that R denotes the set of all real numbers, Z the set of all integers, and Z+ the set of all positive integers, describe each of the following sets.

a. {x ∈ R |−2 < x < 5} b. {x ∈ Z |−2 < x < 5} c. {x ∈ Z+ |−2 < x < 5}

Solution

a. {x ∈ R |−2 < x < 5} is the open interval of real numbers (strictly) between −2 and 5. It is pictured as follows:

–2–3 –1 0 1 2 3 4 5 6 7 8

b. {x ∈ Z |−2 < x < 5} is the set of all integers (strictly) between −2 and 5. It is equal to the set {−1, 0, 1, 2, 3, 4}.

c. Since all the integers in Z+ are positive, {x ∈ Z+|−2 < x < 5} = {1, 2, 3, 4}. ■

Subsets

A basic relation between sets is that of subset.

• Definition If A and B are sets, then A is called a subset of B, written A ⊆ B, if, and only if, every element of A is also an element of B.

Symbolically:

A ⊆ B means that For all elements x , if x ∈ A then x ∈ B. The phrases A is contained in B and B contains A are alternative ways of saying that A is a subset of B.

It follows from the definition of subset that for a set A not to be a subset of a set B means that there is at least one element of A that is not an element of B. Symbolically:

A ! B means that There is at least one element x such that x ∈ A and x /∈ B.

• Definition Let A and B be sets. A is a proper subset of B if, and only if, every element of A is in B but there is at least one element of B that is not in A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10 Chapter 1 Speaking Mathematically

Example 1.2.3 Subsets

Let A = Z+, B = {n ∈ Z | 0 ≤ n ≤ 100}, and C = {100, 200, 300, 400, 500}. Evaluate the truth and falsity of each of the following statements.

a. B ⊆ A b. C is a proper subset of A c. C and B have at least one element in common d. C ⊆ B e. C ⊆ C

Solution

a. False. Zero is not a positive integer. Thus zero is in B but zero is not in A, and so B ! A.

b. True. Each element in C is a positive integer and, hence, is in A, but there are elements in A that are not in C . For instance, 1 is in A and not in C .

c. True. For example, 100 is in both C and B.

d. False. For example, 200 is in C but not in B.

e. True. Every element in C is in C . In general, the definition of subset implies that all sets are subsets of themselves.

Example 1.2.4 Distinction between ∈ and ⊆ Which of the following are true statements?

a. 2 ∈ {1, 2, 3} b. {2} ∈ {1, 2, 3} c. 2 ⊆ {1, 2, 3} d. {2} ⊆ {1, 2, 3} e. {2} ⊆ {{1}, {2}} f. {2} ∈ {{1}, {2}}

Solution Only (a), (d), and (f) are true. For (b) to be true, the set {1, 2, 3} would have to contain the element {2}. But the only

elements of {1, 2, 3} are 1, 2, and 3, and 2 is not equal to {2}. Hence (b) is false. For (c) to be true, the number 2 would have to be a set and every element in the set 2

would have to be an element of {1, 2, 3}. This is not the case, so (c) is false. For (e) to be true, every element in the set containing only the number 2 would have

to be an element of the set whose elements are {1} and {2}. But 2 is not equal to either {1} or {2}, and so (e) is false. ■

Cartesian Products

Pr ob

le m

y m

on th

ly ,J

ul y

19 59

Kazimierz Kuratowski (1896–1980)

With the introduction of Georg Cantor’s set theory in the late nineteenth century, it began to seem possible to put mathematics on a firm logical foundation by developing all of its various branches from set theory and logic alone. A major stumbling block was how to use sets to define an ordered pair because the definition of a set is unaffected by the order in which its elements are listed. For example, {a, b} and {b, a} represent the same set, whereas in an ordered pair we want to be able to indicate which element comes first.

In 1914 crucial breakthroughs were made by Norbert Wiener (1894–1964), a young American who had recently received his Ph.D. from Harvard and the German mathe- matician Felix Hausdorff (1868–1942). Both gave definitions showing that an ordered pair can be defined as a certain type of set, but both definitions were somewhat awkward. Finally, in 1921, the Polish mathematician Kazimierz Kuratowski (1896–1980) published

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.2 The Language of Sets 11

the following definition, which has since become standard. It says that an ordered pair is a set of the form

{{a}, {a, b}}.

This set has elements, {a} and {a, b}. If a ̸= b, then the two sets are distinct and a is in both sets whereas b is not. This allows us to distinguish between a and b and say that a is the first element of the ordered pair and b is the second element of the pair. If a = b, then we can simply say that a is both the first and the second element of the pair. In this case the set that defines the ordered pair becomes {{a}, {a, a}}, which equals {{a}}.

However, it was only long after ordered pairs had been used extensively in mathemat- ics that mathematicians realized that it was possible to define them entirely in terms of sets, and, in any case, the set notation would be cumbersome to use on a regular basis. The usual notation for ordered pairs refers to {{a}, {a, b}} more simply as (a, b).

• Notation Given elements a and b, the symbol (a, b) denotes the ordered pair consisting of a and b together with the specification that a is the first element of the pair and b is the second element. Two ordered pairs (a, b) and (c, d) are equal if, and only if, a = c and b = d. Symbolically:

(a, b) = (c, d) means that a = c and b = d.

Example 1.2.5 Ordered Pairs

a. Is (1, 2) = (2, 1)?

b. Is (

3, 510

) = (√

9, 12

) ?

c. What is the first element of (1, 1)?

Solution

a. No. By definition of equality of ordered pairs,

(1, 2) = (2.1) if, and only if, 1 = 2 and 2 = 1. But 1 ̸= 2, and so the ordered pairs are not equal.

b. Yes. By definition of equality of ordered pairs, (

3, 510

) = (√

9, 12

) if, and only if, 3 =

√ 9 and 510 =

1 2 .

Because these equations are both true, the ordered pairs are equal.

c. In the ordered pair (1, 1), the first and the second elements are both 1.

• Definition Given sets A and B, the Cartesian product of A and B, denoted A× B and read “A cross B,” is the set of all ordered pairs (a, b), where a is in A and b is in B. Symbolically:

A× B = {(a, b) | a ∈ A and b ∈ B} .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12 Chapter 1 Speaking Mathematically

Example 1.2.6 Cartesian Products

Let A = {1, 2, 3} and B = {u, v}. a. Find A × B b. Find B × A c. Find B × B d. How many elements are in A × B, B × A, and B × B? e. Let R denote the set of all real numbers. Describe R× R.

Solution

a. A × B = {(1, u), (2, u), (3, u), (1, v), (2, v), (3, v)} b. B × A = {(u, 1), (u, 2), (u, 3), (v, 1), (v, 2), (v, 3)} c. B × B = {(u, u), (u, v), (v, u), (v, v)} d. A × B has six elements. Note that this is the number of elements in A times the num-

ber of elements in B. B × A has six elements, the number of elements in B times the number of elements in A. B × B has four elements, the number of elements in B times the number of elements in B.

e. R× R is the set of all ordered pairs (x, y) where both x and y are real numbers. If horizontal and vertical axes are drawn on a plane and a unit length is marked off, then each ordered pair in R× R corresponds to a unique point in the plane, with the first and second elements of the pair indicating, respectively, the horizontal and vertical positions of the point. The term Cartesian plane is often used to refer to a plane with this coordinate system, as illustrated in Figure 1.2.1.

Note This is why it makes sense to call a Cartesian product a product!

x

y

1

1

2

3

–2–3–4 –1 –1

–2

–3

2

(1, –2)(–2, –2)

(–3, 2)

(2, 1)

3 4

Figure 1.2.1: A Cartesian Plane

Test Yourself 1. When the elements of a set are given using the set-roster

notation, the order in which they are listed .

2. The symbol R denotes .

3. The symbol Z denotes .

4. The symbol Q denotes .

5. The notation {x | P(x)} is read . 6. For a set A to be a subset of a set B means that,

.

7. Given sets A and B, the Cartesian product A × B is .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.3 The Language of Relations and Functions 13

Exercise Set 1.2 1. Which of the following sets are equal?

A = {a, b, c, d} B = {d, e, a, c} C = {d, b, a, c} D = {a, a, d, e, c, e}

2. Write in words how to read each of the following out loud. a. {x ∈ R+ | 0 < x < 1} b. {x ∈ R | x ≤ 0 or x ≥ 1} c. {n ∈ Z | n is a factor of 6} d. {n ∈ Z+ | n is a factor of 6}

3. a. Is 4 = {4}? b. How many elements are in the set {3, 4, 3, 5}? c. How many elements are in the set {1, {1}, {1, {1}}}?

4. a. Is 2 ∈ {2}? b. How many elements are in the set {2, 2, 2, 2}? c. How many elements are in the set {0, {0}}? d. Is {0} ∈ {{0}, {1}}? e. Is 0 ∈ {{0}, {1}}?

5.H Which of the following sets are equal?

A = {0, 1, 2} B = {x ∈ R |−1 ≤ x < 3} C = {x ∈ R |−1 < x < 3} D = {x ∈ Z |−1 < x < 3} E = {x ∈ Z+ |−1 < x < 3}

6.H For each integer n, let Tn = {n, n2}. How many elements are in each of T2, T−3, T1 and T0? Justify your answers.

7. Use the set-roster notation to indicate the elements in each of the following sets. a. S = {n ∈ Z | n = (−1)k , for some integer k}. b. T = {m ∈ Z | m = 1 + (−1)i, for some integer i}.

c. U = {r ∈ Z | 2 ≤ r ≤ −2} d. V = {s ∈ Z | s > 2 or s < 3} e. W = {t ∈ Z | 1 < t < −3} f. X = {u ∈ Z | u ≤ 4 or u ≥ 1}

8. Let A = {c, d, f, g}, B = { f, j}, and C = {d, g}. Answer each of the following questions. Give reasons for your answers. a. Is B ⊆ A? b. Is C ⊆ A? b. Is C ⊆ C? d. Is C a proper subset of A?

9. a. Is 3 ∈ {1, 2, 3}? b. Is 1 ⊆ {1}? c. Is {2} ∈ {1, 2}? d. Is {3} ∈ {1, {2}, {3}}? e. Is 1 ∈ {1}? f. Is {2} ⊆ {1, {2}, {3}}? g. Is {1} ⊆ {1, 2}? h. Is 1 ∈ {{1}, 2}? i. Is {1} ⊆ {1, {2}}? j. Is {1} ⊆ {1}?

10. a. Is ((−2)2,−22) = (−22, (−2)2)? b. Is (5,−5) = (−5, 5)? c. Is ( 8− 9, 3

√ −1 )

= (−1,−1)? d. Is (−2 −4 , (−2)

3 )

= (

3 6 ,−8 )

?

11. Let A = {w, x, y, z} and B = {a, b}. Use the set-roster notation to write each of the following sets, and indicate the number of elements that are in each set: a. A × B b. B × A c. A × A d. B × B

12. Let S = {2, 4, 6} and T = {1, 3, 5}. Use the set-roster notation to write each of the following sets, and indicate the number of elements that are in each set: a. S × T b. T × S c. S × S d. T × T

Answers for Test Yourself 1. does not matter 2. the set of all real numbers 3. the set of all integers 4. the set of all rational numbers 5. the set of all x such that P(x) 6. every element in A is an element in B 7. the set of all ordered pairs (a, b) where a is in A and b is in B

1.3 The Language of Relations and Functions Mathematics is a language. — Josiah Willard Gibbs (1839–1903)

There are many kinds of relationships in the world. For instance, we say that two people are related by blood if they share a common ancestor and that they are related by marriage if one shares a common ancestor with the spouse of the other. We also speak of the rela- tionship between student and teacher, between people who work for the same employer, and between people who share a common ethnic background.

Similarly, the objects of mathematics may be related in various ways. A set A may be said to be related to a set B if A is a subset of B, or if A is not a subset of B, or if A and B have at least one element in common. A number x may be said to be related to a number y if x < y, or if x is a factor of y, or if x2 + y2 = 1. Two identifiers in a computer

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

14 Chapter 1 Speaking Mathematically

program may be said to be related if they have the same first eight characters, or if the same memory location is used to store their values when the program is executed. And the list could go on!

Let A = {0, 1, 2} and B = {1, 2, 3} and let us say that an element x in A is related to an element y in B if, and only if, x is less than y. Let us use the notation x R y as a shorthand for the sentence “x is related to y.” Then

0 R 1 since 0 < 1, 0 R 2 since 0 < 2, 0 R 3 since 0 < 3, 1 R 2 since 1 < 2, 1 R 3 since 1 < 3, and 2 R 3 since 2 < 3.

On the other hand, if the notation x ̸R y represents the sentence “x is not related to y,” then

1 ̸R 1 since 1 ≮ 1, 2 ̸R 1 since 2 ≮ 1, and 2 ̸R 2 since 2 ≮ 2.

Recall that the Cartesian product of A and B, A × B, consists of all ordered pairs whose first element is in A and whose second element is in B:

A × B = { (x, y) | x ∈ A and y ∈ B

} .

In this case,

A × B = { (0, 1) , (0, 2), (0, 3), (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)

} .

The elements of some ordered pairs in A × B are related, whereas the elements of other ordered pairs are not. Consider the set of all ordered pairs in A × B whose elements are related

{ (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)

} .

Observe that knowing which ordered pairs lie in this set is equivalent to knowing which elements are related to which. The relation itself can therefore be thought of as the totality of ordered pairs whose elements are related by the given condition. The formal mathe- matical definition of relation, based on this idea, was introduced by the American math- ematician and logician C. S. Peirce in the nineteenth century.

• Definition Let A and B be sets. A relation R from A to B is a subset of A × B. Given an ordered pair (x, y) in A × B, x is related to y by R, written x R y, if, and only if, (x, y) is in R. The set A is called the domain of R and the set B is called its co-domain.

The notation for a relation R may be written symbolically as follows:

x R y means that (x, y) ∈ R. The notation x ̸R y means that x is not related to y by R:

x ̸R y means that (x, y) /∈ R.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.3 The Language of Relations and Functions 15

Example 1.3.1 A Relation as a Subset

Let A = {1, 2} and B = {1, 2, 3} and define a relation R from A to B as follows: Given any (x, y) ∈ A × B,

(x, y) ∈ R means that x − y 2

is an integer.

a. State explicitly which ordered pairs are in A × B and which are in R. b. Is 1 R 3? Is 2 R 3? Is 2 R 2?

c. What are the domain and co-domain of R?

Solution

a. A × B = {(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)}. To determine explicitly the com- position of R, examine each ordered pair in A × B to see whether its elements satisfy the defining condition for R.

(1, 1) ∈ R because 1−12 = 0 2 = 0, which is an integer.

(1, 2) /∈ R because 1−22 = −1 2 , which is not an integer.

(1, 3) ∈ R because 1−32 = −2 2 = −1, which is an integer.

(2, 1) /∈ R because 2−12 = 1 2 , which is not an integer.

(2, 2) ∈ R because 2−22 = 0 2 = 0, which is an integer.

(2, 3) /∈ R because 2−32 = −1 2 , which is an integer.

Thus R = {(1, 1), (1, 3), (2, 2)}

b. Yes, 1 R 3 because (1, 3) ∈ R. No, 2 ̸R 3 because (2, 3) /∈ R. Yes, 2 R 2 because (2, 2) ∈ R.

c. The domain of R is {1, 2} and the co-domain is {1, 2, 3}. ■

Example 1.3.2 The Circle Relation

Define a relation C from R to R as follows: For any (x, y) ∈ R× R, (x, y) ∈ C means that x2 + y2 = 1.

a. Is (1, 0) ∈ C? Is (0, 0) ∈ C? Is ( −12 ,

√ 3

2

) ∈ C? Is −2 C 0? Is 0 C (−1)? Is 1 C 1?

b. What are the domain and co-domain of C?

c. Draw a graph for C by plotting the points of C in the Cartesian plane.

Solution

a. Yes, (1, 0) ∈ C because 12 + 02 = 1. No, (0, 0) /∈ C because 02 + 02 = 0 ̸= 1. Yes, ( −12 ,

√ 3

2

) ∈ C because

( −12 )2

+ (√

3 2

)2 = 14 +

3 4 = 1.

No, −2 C/ 0 because (−2)2 + 02 = 4 ̸= 1. Yes, 0 C (−1) because 02 + (−1)2 = 1. No, 1 C/ 1 because 12 + 12 = 2 ̸= 1.

b. The domain and co-domain of C are both R, the set of all real numbers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

16 Chapter 1 Speaking Mathematically

c.

x

y

x2 + y2 = 1

1–1

Arrow Diagram of a Relation Suppose R is a relation from a set A to a set B. The arrow diagram for R is obtained as follows:

1. Represent the elements of A as points in one region and the elements of B as points in another region.

2. For each x in A and y in B, draw an arrow from x to y if, and only if, x is related to y by R. Symbolically:

Draw an arrow from x to y if, and only if, x R y if, and only if, (x, y) ∈ R.

Example 1.3.3 Arrow Diagrams of Relations

Let A = {1, 2, 3} and B = {1, 3, 5} and define relations S and T from A to B as follows: For all (x, y) ∈ A × B,

(x, y) ∈ S means that x < y S is a “less than” relation. T = {(2, 1), (2, 5)}.

Draw arrow diagrams for S and T .

Solution

1

2

3

S 1

3

5

1

2

3

T 1

3

5

These example relations illustrate that it is possible to have several arrows coming out of the same element of A pointing in different directions. Also, it is quite possible to have an element of A that does not have an arrow coming out of it. ■

Functions In Section 1.2 we showed that ordered pairs can be defined in terms of sets and we defined Cartesian products in terms of ordered pairs. In this section we introduced relations as subsets of Cartesian products. Thus we can now define functions in a way that depends only on the concept of set. Although this definition is not obviously related to the way we usually work with functions in mathematics, it is satisfying from a theoretical point

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.3 The Language of Relations and Functions 17

of view and computer scientists like it because it is particularly well suited for operating with functions on a computer.

• Definition A function F from a set A to a set B is a relation with domain A and co-domain B that satisfies the following two properties:

1. For every element x in A, there is an element y in B such that (x, y) ∈ F . 2. For all elements x in A and y and z in B,

if (x, y) ∈ F and (x, z) ∈ F, then y = z.

Properties (1) and (2) can be stated less formally as follows: A relation F from A to B is a function if, and only if:

1. Every element of A is the first element of an ordered pair of F .

2. No two distinct ordered pairs in F have the same first element.

In most mathematical situations we think of a function as sending elements from one set, the domain, to elements of another set, the co-domain. Because of the definition of function, each element in the domain corresponds to one and only one element of the co-domain.

More precisely, if F is a function from a set A to a set B, then given any element x in A, property (1) from the function definition guarantees that there is at least one element of B that is related to x by F and property (2) guarantees that there is at most one such element. This makes it possible to give the element that corresponds to x a special name.

• Notation If A and B are sets and F is a function from A to B, then given any element x in A, the unique element in B that is related to x by F is denoted F(x), which is read “F of x.”

Example 1.3.4 Functions and Relations on Finite Sets

Let A = {2, 4, 6} and B = {1, 3, 5}. Which of the relations R, S, and T defined below are functions from A to B?

a. R = {(2, 5), (4, 1), (4, 3), (6, 5)} b. For all (x, y) ∈ A × B, (x, y) ∈ S means that y = x + 1. c. T is defined by the arrow diagram

B

1

3

5

A

2

4

6

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

18 Chapter 1 Speaking Mathematically

Solution

a. R is not a function because it does not satisfy property (2). The ordered pairs (4, 1) and (4, 3) have the same first element but different second elements. You can see this graphically if you draw the arrow diagram for R. There are two arrows coming out of 4: One points to 1 and the other points to 3.

BR

1

3

5

A

2

4

6

b. S is not a function because it does not satisfy property (1). It is not true that every element of A is the first element of an ordered pair in S. For example, 6 ∈ A but there is no y in B such that y = 6 + 1 = 7. You can also see this graphically by drawing the arrow diagram for S.

BS

1

3

5

A

2

4

6

c. T is a function: Each element in {2, 4, 6} is related to some element in {1, 3, 5} and no element in {2, 4, 6} is related to more than one element in {1, 3, 5}. When these properties are stated in terms of the arrow diagram, they become (1) there is an arrow coming out of each element of the domain, and (2) no element of the domain has more than one arrow coming out of it. So you can write T (2) = 5, T (4) = 1, and T (6) = 1. ■

Note In part (c), T (4) = T (6). This illustrates the fact that although no element of the domain of a function can be related to more than one element of the co-domain, several elements in the domain can be related to the same element in the co-domain.

Example 1.3.5 Functions and Relations on Sets of Real Numbers

a. In Example 1.3.2 the circle relation C was defined as follows:

For all (x, y) ∈ R× R, (x, y) ∈ C means that x2 + y2 = 1.

Is C a function? If it is, find C(0) and C(1).

b. Define a relation from R to R as follows:

For all (x, y) ∈ R× R, (x, y) ∈ L means that y = x − 1.

Is L a function? If it is, find L(0) and L(1).

Solution

a. The graph of C , shown on the next page, indicates that C does not satisfy either func- tion property. To see why C does not satisfy property (1), observe that there are many real numbers x such that (x, y) /∈ C for any y.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.3 The Language of Relations and Functions 19

x = 2

Graph of C

x2 + y2 = 1 1 2 2

,( )

1 2

√3 2

, –( ) x = 1

2

√3

For instance, when x = 2, there is no real number y so that x2 + y2 = 22 + y2 = 4 + y2 = 1

because if there were, then it would have to be true that

y2 = −3. which is not the case for any real number y.

To see why C does not satisfy property (2), note that for some values of x there are two distinct values of y so that (x, y) ∈ C . One way to see this graphically is to observe that there are vertical lines, such as x = 12 , that intersect the graph of C at two separate points:

( 1 2 ,

√ 3

2

) and (

1 2 , −

√ 3

2

) .

b. L is a function. For each real number x, y = x − 1 is a real number, and so there is a real number y with (x, y) ∈ L . Also if (x, y) ∈ L and (x, z) ∈ L , then y = x − 1 and z = x − 1, and so y = z. In particular, L(0) = 0− 1 = −1 and L(1) = 1− 1 = 0.

You can also check these results by inspecting the graph of L , shown below. Note that for every real number x , the vertical line through (x , 0) passes through the graph of L exactly once. This indicates both that every real number x is the first element of an ordered pair in L and also that no two distinct ordered pairs in L have the same first element.

(x, 0)

y = x – 1

Graph of L

Function Machines Another useful way to think of a function is as a machine. Suppose f is a function from X to Y and an input x of X is given. Imagine f to be a machine that processes x in a certain way to produce the output f (x). This is illustrated in Figure 1.3.1 on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

20 Chapter 1 Speaking Mathematically

function machine

Input x

f (x) Output

Figure 1.3.1

Example 1.3.6 Functions Defined by Formulas

The squaring function f from R to R is defined by the formula f (x) = x2 for all real numbers x . This means that no matter what real number input is substituted for x , the output of f will be the square of that number. This idea can be represented by writing f (") = "2. In other words, f sends each real number x to x2, or, symbolically, f : x → x2. Note that the variable x is a dummy variable; any other symbol could replace it, as long as the replacement is made everywhere the x appears.

The successor function g from Z to Z is defined by the formula g(n) = n + 1. Thus, no matter what integer is substituted for n, the output of g will be that number plus one: g(") = "+ 1. In other words, g sends each integer n to n + 1, or, symbolically, g: n → n + 1.

An example of a constant function is the function h from Q to Z defined by the formula h(r) = 2 for all rational numbers r . This function sends each rational number r to 2. In other words, no matter what the input, the output is always 2: h(") = 2 or h: r → 2.

The functions f, g, and h are represented by the function machines in Figure 1.3.2.

squaring function

x

f (x) = x2

(a)

successor function

n

g(n) = n + 1

(b)

constant function

r

h(r) = 2

(c)

Figure 1.3.2 ■

A function is an entity in its own right. It can be thought of as a certain relationship between sets or as an input/output machine that operates according to a certain rule. This is the reason why a function is generally denoted by a single symbol or string of symbols, such as f, G, of log, or sin.

A relation is a subset of a Cartesian product and a function is a special kind of relation. Specifically, if f and g are functions from a set A to a set B, then

f = {(x, y) ∈ A × B | y = f (x)} and g = {(x, y) ∈ A × B | y = g(x)}. It follows that

f equals g, written f = g, if, and only if, f (x) = g(x) for all x in A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

1.3 The Language of Relations and Functions 21

Example 1.3.7 Equality of Functions

Define f : R → R and g: R → R by the following formulas: f (x) = |x | for all x ∈ R.

g(x) = √

x2 for all x ∈ R. Does f = g?

Solution Yes. Because the absolute value of any real number equals the square root of its square, |x | =

√ x2 for all x ∈ R. Hence f = g. ■

Test Yourself 1. Given sets A and B, a relation from A to B is .

2. A function F from A to B is a relation from A to B that satisfies the following two properties:

a. for every element x of A, there is .

b. for all elements x in A and y and z in B, if then .

3. If F is a function from A to B and x is an element of A, then F(x) is .

Exercise Set 1.3 1. Let A = {2, 3, 4} and B = {6, 8, 10} and define a relation

R from A to B as follows: For all (x, y) ∈ A × B,

(x, y) ∈ R means that y x

is an integer.

a. Is 4 R 6? Is 4 R 8? Is (3, 8) ∈ R? Is (2, 10) ∈ R? b. Write R as a set of ordered pairs. c. Write the domain and co-domain of R. d. Draw an arrow diagram for R.

2. Let C = D = {−3,−2,−1, 1, 2, 3} and define a relation S from C to D as follows: For all (x, y) ∈ C × D,

(x, y) ∈ S means that 1 x − 1

y is an integer.

a. Is 2 S 2? Is −1S − 1? Is (3, 3) ∈ S? Is (3,−3) ∈ S? b. Write S as a set of ordered pairs. c. Write the domain and co-domain of S. d. Draw an arrow diagram for S.

3. Let E = {1, 2, 3} and F = {−2,−1, 0} and define a rela- tion T from E to F as follows: For all (x, y) ∈ E × F ,

(x, y) ∈ T means that x − y 3

is an integer.

a. Is 3 T 0? Is 1T (−1)? Is (2,−1) ∈ T ? Is (3,−2) ∈ T ? b. Write T as a set of ordered pairs. c. Write the domain and co-domain of T . d. Draw an arrow diagram for T .

4. Let G = {−2, 0, 2} and H = {4, 6, 8} and define a relation V from G to H as follows: For all (x, y) ∈ G × H ,

(x, y) ∈ V means that x − y 4

is an integer.

a. Is 2 V 6? Is (−2)V (−6)? Is (0, 6) ∈ V ? Is (2, 4) ∈ V ?

b. Write V as a set of ordered pairs. c. Write the domain and co-domain of V . d. Draw an arrow diagram for V .

5. Define a relation S from R to R as follows: For all (x, y) ∈ R× R,

(x, y) ∈ S means that x ≥ y. a. Is (2, 1) ∈ S? Is (2, 2) ∈ S? Is 2 S 3? Is (−1) S (−2)? b. Draw the graph of S in the Cartesian plane.

6. Define a relation R from R to R as follows: For all (x, y) ∈ R× R,

(x, y) ∈ R means that y = x2.

a. Is (2, 4) ∈ R? Is (4, 2) ∈ R? Is (−3) R 9? Is 9 R (−3)? b. Draw the graph of R in the Cartesian plane.

7. Let A = {4, 5, 6} and B = {5, 6, 7} and define relations R, S, and T from A to B as follows: For all (x, y) ∈ A × B,

(x, y) ∈ R means that x ≥ y. (x, y) ∈ S means that x − y

2 is an integer.

T = {(4, 7), (6, 5), (6, 7)}. a. Draw arrow diagrams for R, S, and T . b. Indicate whether any of the relations R, S, and T are

functions.

8. Let A = {2, 4} and B = {1, 3, 5} and define relations U, V, and W from A to B as follows: For all (x, y) ∈ A × B,

(x, y) ∈ U means that y − x > 2. (x, y) ∈ V means that y − 1 = x

2 .

W = {(2, 5), (4, 1), (2, 3)}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

22 Chapter 1 Speaking Mathematically

a. Draw arrow diagrams for U, V, and W . b. Indicate whether any of the relations U, V, and W are

functions.

9. a. Find all relations from {0,1} to {1}. b. Find all functions from {0,1} to {1}. c. What fraction of the relations from {0,1} to {1} are

functions?

10. Find four relations from {a, b} to {x, y} that are not func- tions from {a, b} to {x, y}.

11. Define a relation P from R+ to R as follows: For all real numbers x and y with x > 0,

(x, y) ∈ P means that x = y2. Is P a function? Explain.

12. Define a relation T from R to R as follows: For all real numbers x and y,

(x, y) ∈ T means that y2 − x2 = 1. Is T a function? Explain.

13. Let A = {−1, 0, 1} and B = {t, u, v, w}. Define a function F : A → B by the following arrow diagram:

B

t

u

v

w

A

–1

0

1

a. Write the domain and co-domain of F . b. Find F(−1), F(0), and F(1).

14. Let C = {1, 2, 3, 4} and D = {a, b, c, d}. Define a function G: C → D by the following arrow diagram:

a

b

c

d

1

2

3

4

a. Write the domain and co-domain of G. b. Find G(1), G(2), G(3), and G(4).

15. Let X = {2, 4, 5} and Y = {1, 2, 4, 6}. Which of the fol- lowing arrow diagrams determine functions from X to Y ?

a. Y

6

X

2

2

1

4 4

5

b. Y

6

X

2

2

1

4 4

5

c. Y

1

2

4

6

X

2

4

5

d.

2

1

4

6

2

4

5

YX

e.

2

1

4

6

2

4

5

YX

16. Let f be the squaring function defined in Example 1.3.6. Find f (−1), f (0), and f

( 1 2

) .

17. Let g be the successor function defined in Example 1.3.6. Find g(−1000), g(0), and g(999).

18. Let h be the constant function defined in Example 1.3.6.

Find h ( − 125 ) , h (

0 1

) , and h

( 9 17

) .

19. Define functions f and g from R to R by the following formulas: For all x ∈ R,

f (x) = 2x and g(x) = 2x 3 + 2x

x2 + 1 .

Does f = g? Explain. 20. Define functions H and K from R to R by the following

formulas: For all x ∈ R, H(x) = (x − 2)2 and K (x) = (x − 1)(x − 3) + 1.

Does H = K ? Explain.

Answers for Test Yourself 1. a subset of the Cartesian product A × B 2. a. an element y of B such that (x, y) ∈ F (i.e., such that x is related to y by F) b. (x, y) ∈ F and (x, z) ∈ F; y = z 3. the unique element of B that is related to x by F

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

23

CHAPTER 2

THE LOGIC OF COMPOUND STATEMENTS

The first great treatises on logic were written by the Greek philosopher Aristotle. They

B et

tm an

n/ CO

R B

IS

Aristotle (384 B.C.–322 B.C.)

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 modern 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 2.4 and 2.5), relational database theory (see Section 8.1), automata theory and computability (see Section 7.4 and Chapter 12), and artificial intel- ligence (see Sections 3.3, 10.1, and 10.5).

2.1 Logical Form and Logical Equivalence Logic is a science of the necessary laws of thought, without which no employment of the understanding and the reason takes place. —Immanuel Kant, 1785

The central concept of deductive logic is the concept of argument form. An argument is a sequence of statements aimed at demonstrating the truth of an assertion. The assertion at the end of the sequence is called the conclusion, and the preceding statements are called premises. To have confidence in the conclusion that you draw from an argument, you must be sure that the premises are acceptable on 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 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 premises. For this reason logic is sometimes defined as the science of necessary inference or the science of reasoning.

Consider the following two arguments, for example. Although their content is very different, their logical form is the same. Both arguments are valid in the sense that if their premises are true, then their conclusions must also be true. (In Section 2.3 you will learn how to test whether an argument is valid.)

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

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

24 Chapter 2 The Logic of Compound Statements

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 > 4. Therefore, if x2 ≯ 4, then x ≮ −2 and x ≯ 2.

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 logical form of both the previous arguments is as follows:

If p or q, then r .

Therefore, if not r , then not p and not q .

Example 2.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 .

q.

Therefore, r . ■

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, and false are the initial undefined terms.

• Definition A statement (or proposition) is a sentence that is true or false but not both.

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

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 25

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 sen- tence 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 3.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,∧ denotes and, and∨ 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 ∧ q” is read “p and q” and is called the conjunction of p and q. The sentence “p ∨ q” is read “p or q” and is called the disjunction of p and q.

In expressions that include the symbol ∼as well as ∧ or ∨, the order of operations specifies that ∼ is performed first. For instance, ∼p ∧ q = (∼p) ∧ q . In logical expres- sions, as in ordinary algebraic expressions, the order of operations can be overridden through the use of parentheses. Thus∼(p ∧ q) represents the negation of the conjunction of p and q. In this, as in most treatments of logic, the symbols ∧ and ∨ are considered coequal in order of operation, and an expression such as p ∧ q ∨ r is considered ambigu- ous. This expression must be written as either (p ∧ q) ∨ r or p ∧ (q ∨ r) to have meaning.

A variety of English words translate into logic as ∧,∨, 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 2.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 ∧ s.

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 ∧ ∼s. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

26 Chapter 2 The Logic of Compound Statements

The notation for inequalities involves and and or statements. For instance, if x, a, and b are particular real numbers, then

x ≤ a means x < a or x = a a ≤ x ≤ b means a ≤ x and x ≤ b.

Note that the inequality 2 ≤ x ≤ 1 is not satisfied by any real numbers because 2 ≤ x ≤ 1 means 2 ≤ x and x ≤ 1,

and this is false no matter what number x happens to be. By the way, the point of specify- ing x, a, and b to be particular real numbers is to ensure that sentences such as “x < a” and “x ≥ b” are either true or false and hence that they are statements.

Example 2.1.3 And, Or, and Inequalities

Suppose x is a particular real number. Let p, q , and r symbolize “0 < x ,” “x < 3,” and “x = 3,” respectively. Write the following inequalities symbolically: a. x ≤ 3 b. 0 < x < 3 c. 0 < x ≤ 3

Solution

a. q ∨ r b. p ∧ q c. p ∧ (q ∨ r) ■

Truth Values In Examples 2.1.2 and 2.1.3 we built compound sentences out of component statements and the terms not, and, and or. If such sentences are to be statements, however, they must have well-defined truth values—they must be either true or false. We now define such compound sentences as statements by specifying their truth values in terms of the statements that compose them.

The negation of a statement is a statement that exactly expresses what it would mean for the statement to be false.

• Definition If p is a statement variable, the negation of p is “not p” or “It is not the case that p” and is denoted ∼p. It has opposite truth value from p: if p is true, ∼p is false; if p is false, ∼p is true.

The truth values for negation are summarized in a truth table.

Truth Table for ∼p

p ∼p T F

F T

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 27

In ordinary language the sentence “It is hot and it is sunny” is understood to be true when both conditions—being hot and being sunny—are satisfied. If it is hot but not sunny, or sunny but not hot, or neither hot nor sunny, the sentence is understood to be false. The formal definition of truth values for an and statement agrees with this general understanding.

• Definition If p and q are statement variables, the conjunction of p and q is “p and q ,” denoted p ∧ q. It is true when, and only when, both p and q are true. If either p or q is false, or if both are false, p ∧ q is false.

The truth values for conjunction can also be summarized in a truth table. The table is obtained by considering the four possible combinations of truth values for p and q. Each combination is displayed in one row of the table; the corresponding truth value for the whole statement is placed in the right-most column of that row. Note that the only row containing a T is the first one since the only way for an and statement to be true is for both component statements to be true.

Truth Table for p ∧ q

p q p ∧ q T T T

T F F

F T F

F F F

By the way, the order of truth values for p and q in the table above is TT, TF, FT, FF. It is not absolutely necessary to write the truth values in this order, although it is customary to do so. We will use this order for all truth tables involving two statement variables. In Example 2.1.5 we will show the standard order for truth tables that involve three statement variables.

In the case of disjunction—statements of the form “p or q”—intuitive logic offers two alternative interpretations. In ordinary language or is sometimes used in an exclusive sense (p or q but not both) and sometimes in an inclusive sense (p or q or both). A waiter who says you may have “coffee, tea, or milk” uses the word or in an exclusive sense: Extra payment is generally required if you want more than one beverage. On the other hand, a waiter who offers “cream or sugar” uses the word or in an inclusive sense: You are entitled to both cream and sugar if you wish to have them.

Mathematicians and logicians avoid possible ambiguity about the meaning of the word or by understanding it to mean the inclusive “and/or.” The symbol ∨ comes from the Latin word vel, which means or in its inclusive sense. To express the exclusive or, the phrase p or q but not both is used.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

28 Chapter 2 The Logic of Compound Statements

• Definition If p and q are statement variables, the disjunction of p and q is “p or q,” denoted p ∨ q. It is true when either p is true, or q is true, or both p and q are true; it is false only when both p and q are false.

Here is the truth table for disjunction:

Truth Table for p ∨ q

p q p ∨ q T T T

T F T

F T T

F F F

Note The statement “2 ≤ 2” means that 2 is less than 2 or 2 equals 2. It is true because 2 = 2.

Evaluating the Truth of More General Compound Statements

Now that truth values have been assigned to ∼p, p ∧ q, and p ∨ q, consider the question of assigning truth values to more complicated expressions such as ∼p ∨ q, (p ∨ q) ∧ ∼(p ∧ q), and (p ∧ q) ∨ r . Such expressions are called statement forms (or propositional forms). The close relationship between statement forms and Boolean expressions is discussed in Section 2.4.

• Definition A statement form (or propositional form) is an expression made up of statement variables (such as p, q , and r ) and logical connectives (such as ∼,∧, and ∨) that becomes a statement when actual statements are substituted for the component state- ment variables. The truth table for a given statement form displays the truth values that correspond to all possible combinations of truth values for its component state- ment variables.

To compute the truth values for a statement form, follow rules similar to those used to evaluate algebraic expressions. For each combination of truth values for the statement variables, first evaluate the expressions within the innermost parentheses, then evaluate the expressions within the next innermost set of parentheses, and so forth until you have the truth values for the complete expression.

Example 2.1.4 Truth Table for Exclusive Or

Construct the truth table for the statement form (p ∨ q) ∧ ∼(p ∧ q). Note that when or is used in its exclusive sense, the statement “p or q” means “p or q but not both” or “p or q and not both p and q,” which translates into symbols as (p ∨ q) ∧ ∼(p ∧ q). This is sometimes abbreviated p ⊕ q or p XOR q.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 29

Solution Set up columns labeled p, q, p ∨ q, p ∧ q,∼(p ∧ q), and (p ∨ q) ∧ ∼(p ∧ q). Fill in the p and q columns with all the logically possible combinations of T’s and F’s. Then use the truth tables for ∨ and ∧ to fill in the p ∨ q and p ∧ q columns with the appropriate truth values. Next fill in the ∼(p ∧ q) column by taking the opposites of the truth values for p ∧ q . For example, the entry for ∼(p ∧ q) in the first row is F because in the first row the truth value of p ∧ q is T. Finally, fill in the (p ∨ q) ∧ ∼(p ∧ q) col- umn by considering the truth table for an and statement together with the computed truth values for p ∨ q and ∼(p ∧ q). For example, the entry in the first row is F because the entry for p ∨ q is T, the entry for∼(p ∧ q) is F, and an and statement is false unless both components are true. The entry in the second row is T because both components are true in this row.

Truth Table for Exclusive Or: ( p ∨ q) ∧ ∼( p ∧ q)

p q p ∨ q p ∧ q ∼( p ∧ q) ( p ∨ q)∧ ∼( p ∧ q) T T T T F F

T F T F T T

F T T F T T

F F F F T F ■

Example 2.1.5 Truth Table for ( p ∧ q) ∨ ∼r Construct a truth table for the statement form (p ∧ q) ∨ ∼r .

Solution Make columns headed p, q, r, p ∧ q, ∼r, and (p ∧ q) ∨ ∼r . Enter the eight logically possible combinations of truth values for p, q, and r in the three left-most columns. Then fill in the truth values for p ∧ q and for ∼r . Complete the table by con- sidering the truth values for (p ∧ q) and for ∼r and the definition of an or statement. Since an or statement is false only when both components are false, the only rows in which the entry is F are the third, fifth, and seventh rows because those are the only rows in which the expressions p ∧ q and ∼r are both false. The entry for all the other rows is T.

p q r p ∧ q ∼r ( p ∧ q)∨ ∼r T T T T F T

T T F T T T

T F T F F F

T F F F T T

F T T F F F

F T F F T T

F F T F F F

F F F F T T ■

The essential point about assigning truth values to compound statements is that it allows you—using logic alone—to judge the truth of a compound statement on the basis of your knowledge of the truth of its component parts. Logic does not help you determine the truth or falsity of the component statements. Rather, logic helps link these separate pieces of information together into a coherent whole.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

30 Chapter 2 The Logic of Compound Statements

Logical Equivalence The statements

6 is greater than 2 and 2 is less than 6

are two different ways of saying the same thing. Why? Because of the definition of the phrases greater than and less than. By contrast, although the statements

(1) Dogs bark and cats meow and (2) Cats meow and dogs bark

are also two different ways of saying the same thing, the reason has nothing to do with the definition of the words. It has to do with the logical form of the statements. Any two statements whose logical forms are related in the same way as (1) and (2) would either both be true or both be false. You can see this by examining the following truth table, where the statement variables p and q are substituted for the component statements “Dogs bark” and “Cats meow,” respectively. The table shows that for each combination of truth values for p and q, p ∧ q is true when, and only when, q ∧ p is true. In such a case, the statement forms are called logically equivalent, and we say that (1) and (2) are logically equivalent statements.

p q p ∧ q q ∧ p T T T T

T F F F

F T F F

F F F F

↑ ↑ p ∧ q and q ∧ p always have the same truth values, so they are logically equivalent

• Definition Two statement forms are called logically equivalent if, and only if, they have identical truth values for each possible substitution of statements for their statement variables. The logical equivalence of statement forms P and Q is denoted by writing P ≡ Q.

Two statements are called logically equivalent if, and only if, they have logically equivalent forms when identical component statement variables are used to replace identical component statements.

Testing Whether Two Statement Forms P and Q Are Logically Equivalent

1. Construct a truth table with one column for the truth values of P and another column for the truth values of Q.

2. Check each combination of truth values of the statement variables to see whether the truth value of P is the same as the truth value of Q.

a. If in each row the truth value of P is the same as the truth value of Q, then P and Q are logically equivalent.

b. If in some row P has a different truth value from Q, then P and Q are not logically equivalent.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 31

Example 2.1.6 Double Negative Property: ∼(∼p) ≡ p Construct a truth table to show that the negation of the negation of a statement is logically equivalent to the statement, annotating the table with a sentence of explanation.

Solution p ∼p ∼(∼p) T F T

F T F

↑ ↑ p and∼(∼p) always have the same truth values, so they are logically equivalent ■

There are two ways to show that statement forms P and Q are not logically equiva- lent. As indicated previously, one is to use a truth table to find rows for which their truth values differ. The other way is to find concrete statements for each of the two forms, one of which is true and the other of which is false. The next example illustrates both of these ways.

Example 2.1.7 Showing Nonequivalence

Show that the statement forms ∼(p ∧ q) and ∼p ∧ ∼q are not logically equivalent. Solution

a. This method uses a truth table annotated with a sentence of explanation.

p q ∼p ∼q p ∧ q ∼( p ∧ q) ∼p ∧ ∼q T T F F T F F

T F F T F T ̸= F F T T F F T ̸= F F F T T F T T

↑ ↑ ∼(p ∧ q) and∼p ∧ ∼q have different truth values in rows 2 and 3, so they are not logically equivalent

b. This method uses an example to show that ∼(p ∧ q) and ∼p ∧ ∼q are not logically equivalent. Let p be the statement “0 < 1” and let q be the statement “1 < 0.” Then

∼(p ∧ q) is “It is not the case that both 0 < 1 and 1 < 0, ” which is true. On the other hand,

∼p ∧ ∼q is “0 ≮ 1 and 1 ≮ 0, ” which is false. This example shows that there are concrete statements you can substi- tute for p and q to make one of the statement forms true and the other false. Therefore, the statement forms are not logically equivalent. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

32 Chapter 2 The Logic of Compound Statements

Example 2.1.8 Negations of And and Or: De Morgan’s Laws

For the statement “John is tall and Jim is redheaded” to be true, both components must be true. So for the statement to be false, one or both components must be false. Thus the negation can be written as “John is not tall or Jim is not redheaded.” In general, the negation of the conjunction of two statements is logically equivalent to the disjunction of their negations. That is, statements of the forms ∼(p ∧ q) and ∼p ∨ ∼q are logically equivalent. Check this using truth tables.

Solution p q ∼p ∼q p ∧ q ∼( p ∧ q) ∼p ∨ ∼q T T F F T F F

T F F T F T T

F T T F F T T

F F T T F T T

↑ ↑ ∼(p ∧ q) and∼p ∨ ∼q always have the same truth values, so they are logically equivalent

Cu lv

er Pi

ct ur

es

Augustus De Morgan (1806–1871)

Symbolically,

∼(p ∧ q) ≡ ∼p ∨ ∼q.

In the exercises at the end of this section you are asked to show the analogous law that the negation of the disjunction of two statements is logically equivalent to the conjunction of their negations:

∼(p ∨ q) ≡ ∼p ∧ ∼q. ■

The two logical equivalences of Example 2.1.8 are known as De Morgan’s laws of logic in honor of Augustus De Morgan, who was the first to state them in formal mathematical terms.

De Morgan’s Laws

The negation of an and statement is logically equivalent to the or statement in which each component is negated.

The negation of an or statement is logically equivalent to the and statement in which each component is negated.

Example 2.1.9 Applying De Morgan’s Laws

Write negations for each of the following statements:

a. John is 6 feet tall and he weighs at least 200 pounds.

b. The bus was late or Tom’s watch was slow.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 33

Solution

a. John is not 6 feet tall or he weighs less than 200 pounds.

b. The bus was not late and Tom’s watch was not slow.

Since the statement “neither p nor q” means the same as “∼p and ∼q ,” an alternative answer for (b) is “Neither was the bus late nor was Tom’s watch slow.” ■

If x is a particular real number, saying that x is not less than 2 (x ≮ 2) means that x does not lie to the left of 2 on the number line. This is equivalent to saying that either x = 2 or x lies to the right of 2 on the number line (x = 2 or x > 2). Hence,

x ≮ 2 is equivalent to x ≥ 2. Pictorially,

–2 –1 0 1 2 3 4 5

If x ! 2, then x lies in here.

Similarly,

x ≯ 2 is equivalent to x ≤ 2, x $ 2 is equivalent to x > 2, and x % 2 is equivalent to x < 2.

Example 2.1.10 Inequalities and De Morgan’s Laws

Use De Morgan’s laws to write the negation of −1 < x ≤ 4. Solution The given statement is equivalent to

−1 < x and x ≤ 4. By De Morgan’s laws, the negation is

−1 ≮ x or x $ 4, which is equivalent to

−1 ≥ x or x > 4.

! Caution! The negation of −1 < x ≤ 4 is not −1 ≮ x " 4. It is also not −1 ≥ x > 4.

Pictorially, if −1 ≥ x or x > 4, then x lies in the shaded region of the number line, as shown below.

–2 –1 0 1 2 3 4 5 6

De Morgan’s laws are frequently used in writing computer programs. For instance, suppose you want your program to delete all files modified outside a certain range of dates, say from date 1 through date 2 inclusive. You would use the fact that

∼(date1 ≤ file_modification_date ≤ date2)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

34 Chapter 2 The Logic of Compound Statements

is equivalent to

( file_modification_date < date1) or (date2 < file_modification_date).

Example 2.1.11 A Cautionary Example

According to De Morgan’s laws, the negation of

p: Jim is tall and Jim is thin

is ∼p: Jim is not tall or Jim is not thin because the negation of an and statement is the or statement in which the two components are negated.

Unfortunately, a potentially confusing aspect of the English language can arise when you are taking negations of this kind. Note that statement p can be written more com- pactly as

p′: Jim is tall and thin.

When it is so written, another way to negate it is

∼(p′): Jim is not tall and thin.

But in this form the negation looks like an and statement. Doesn’t that violate De Morgan’s laws?

Actually no violation occurs. The reason is that in formal logic the words and and or are allowed only between complete statements, not between sentence fragments.

One lesson to be learned from this example is that when you apply De Morgan’s laws, you must have complete statements on either side of each and and on either side of each or.

! Caution! Although the laws of logic are extremely useful, they should be used as an aid to thinking, not as a mechanical substitute for it.

Tautologies and Contradictions It has been said that all of mathematics reduces to tautologies. Although this is formally true, most working mathematicians think of their subject as having substance as well as form. Nonetheless, an intuitive grasp of basic logical tautologies is part of the equipment of anyone who reasons with mathematics.

• Definition A tautology is a statement form that is always true regardless of the truth values of the individual statements substituted for its statement variables. A statement whose form is a tautology is a tautological statement.

A contradication is a statement form that is always false regardless of the truth val- ues of the individual statements substituted for its statement variables. A statement whose form is a contradication is a contradictory statement.

According to this definition, the truth of a tautological statement and the falsity of a contradictory statement are due to the logical structure of the statements themselves and are independent of the meanings of the statements.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 35

Example 2.1.12 Tautologies and Contradictions

Show that the statement form p ∨ ∼p is a tautology and that the statement form p ∧ ∼p is a contradiction.

Solution p ∼p p ∨ ∼p p ∧ ∼p T F T F

F T T F

↑ ↑ all T’s so all F’s so p ∨ ∼p is p ∧ ∼p is a a tautology contradiction

Example 2.1.13 Logical Equivalence Involving Tautologies and Contradictions

If t is a tautology and c is a contradiction, show that p∧ t ≡ p and p∧ c ≡ c.

Solution p t p ∧ t p c p ∧ c T T T T F F

F T F F F F

↑ ↑ ↑ ↑ same truth same truth values, so values, so p ∧ t ≡ p p ∧ c ≡ c ■

Summary of Logical Equivalences Knowledge of logically equivalent statements is very useful for constructing arguments. It often happens that it is difficult to see how a conclusion follows from one form of a statement, whereas it is easy to see how it follows from a logically equivalent form of the statement. A number of logical equivalences are summarized in Theorem 2.1.1 for future reference.

Theorem 2.1.1 Logical Equivalences

Given any statement variables p, q , and r , a tautology t and a contradiction c, the following logical equivalences hold.

1. Commutative laws: p ∧ q ≡ q ∧ p p ∨ q ≡ q ∨ p 2. Associative laws: (p ∧ q) ∧ r ≡ p ∧ (q ∧ r) (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) 3. Distributive laws: p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) 4. Identity laws: p ∧ t ≡ p p ∨ c ≡ p 5. Negation laws: p ∨ ∼p ≡ t p ∧ ∼p ≡ c 6. Double negative law: ∼(∼p) ≡ p 7. Idempotent laws: p ∧ p ≡ p p ∨ p ≡ p 8. Universal bound laws: p ∨ t ≡ t p ∧ c ≡ c 9. De Morgan’s laws: ∼(p ∧ q) ≡ ∼p ∨ ∼q ∼(p ∨ q) ≡ ∼p ∧ ∼q

10. Absorption laws: p ∨ (p ∧ q) ≡ p p ∧ (p ∨ q) ≡ p 11. Negations of t and c: ∼t ≡ c ∼c ≡ t

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

36 Chapter 2 The Logic of Compound Statements

The proofs of laws 4 and 6, the first parts of laws 1 and 5, and the second part of law 9 have already been given as examples in the text. Proofs of the other parts of the theorem are left as exercises. In fact, it can be shown that the first five laws of Theorem 2.1.1 form a core from which the other laws can be derived. The first five laws are the axioms for a mathematical structure known as a Boolean algebra, which is discussed in Section 6.4.

The equivalences of Theorem 2.1.1 are general laws of thought that occur in all areas of human endeavor. They can also be used in a formal way to rewrite complicated state- ment forms more simply.

Example 2.1.14 Simplifying Statement Forms

Use Theorem 2.1.1 to verify the logical equivalence

∼(∼p ∧ q) ∧ (p ∨ q) ≡ p. Solution Use the laws of Theorem 2.1.1 to replace sections of the statement form on the

left by logically equivalent expressions. Each time you do this, you obtain a logically equivalent statement form. Continue making replacements until you obtain the statement form on the right.

∼(∼p ∧ q) ∧ (p ∨ q) ≡ (∼(∼p)∨ ∼q) ∧ (p ∨ q) by De Morgan’s laws ≡ (p∨ ∼q) ∧ (p ∨ q) by the double negative law ≡ p ∨ (∼q ∧ q) by the distributive law ≡ p ∨ (q ∧ ∼q) by the commutative law for ∧ ≡ p ∨ c by the negation law ≡ p by the identity law. ■

Skill in simplifying statement forms is useful in constructing logically efficient computer programs and in designing digital logic circuits.

Although the properties in Theorem 2.1.1 can be used to prove the logical equivalence of two statement forms, they cannot be used to prove that statement forms are not logically equivalent. On the other hand, truth tables can always be used to determine both equivalence and nonequivalence, and truth tables are easy to program on a computer. When truth tables are used, however, checking for equivalence always requires 2n steps, where n is the number of variables. Sometimes you can quickly see that two statement forms are equivalent by Theorem 2.1.1, whereas it would take quite a bit of calculating to show their equivalence using truth tables. For instance, it follows immediately from the associative law for ∧ that p ∧ (∼q ∧ ∼r) ≡ (p∧ ∼q)∧ ∼r , whereas a truth table verification requires constructing a table with eight rows.

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. An and statement is true if, and only if, both components are .

2. An or statement is false if, and only if, both components are .

3. Two statement forms are logically equivalent if, and only if, they always have .

4. De Morgan’s laws say (1) that the negation of an and state- ment is logically equivalent to the statement in which

each component is , and (2) that the negation of an or statement is logically equivalent to the statement in which each component is .

5. A tautology is a statement that is always .

6. A contradiction is a statement that is always .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Logical Form and Logical Equivalence 37

Exercise Set 2.1 *

In each of 1–4 represent the common form of each argument using letters to stand for component sentences, and fill in the blanks so that the argument in part (b) has the same logical form as the argument in part (a).

1. a. If all integers are rational, then the number 1 is rational. All integers are rational. Therefore, the number 1 is rational.

b. If all algebraic expressions can be written in prefix notation, then .

. Therefore, (a + 2b)(a2 − b) can be written in prefix notation.

2. a. If all computer programs contain errors, then this program contains an error. This program does not contain an error. Therefore, it is not the case that all computer programs contain errors.

b. If , then . 2 is not odd. Therefore, it is not the case that all prime numbers are odd.

3. a. This number is even or this number is odd. This number is not even. Therefore, this number is odd.

b. or logic is confusing. My mind is not shot. Therefore, .

4. a. If n is divisible by 6, then n is divisible by 3. If n is divisible by 3, then the sum of the digits of n is divisible by 3. Therefore, if n is divisible by 6, then the sum of the dig- its of n is divisible by 3. (Assume that n is a particular, fixed integer.)

b. If this function is then this function is differen- tiable. If this function is then this function is continuous. Therefore, if this function is a polynomial, then this function .

5. Indicate which of the following sentences are statements. a. 1,024 is the smallest four-digit number that is a perfect

square. b. She is a mathematics major. c. 128 = 26 d. x = 26

Write the statements in 6–9 in symbolic form using the symbols ∼,∨, and ∧ and the indicated letters to represent component statements.

6. Let s = “stocks are increasing” and i = “interest rates are steady.”

a. Stocks are increasing but interest rates are steady. b. Neither are stocks increasing nor are interest rates

steady.

7. Juan is a math major but not a computer science major. (m = “Juan is a math major,” c = “Juan is a computer science major”)

8. Let h = “John is healthy,” w = “John is wealthy,” and s = “John is wise.” a. John is healthy and wealthy but not wise. b. John is not wealthy but he is healthy and wise. c. John is neither healthy, wealthy, nor wise. d. John is neither wealthy nor wise, but he is healthy. e. John is wealthy, but he is not both healthy and wise.

9. Either this polynomial has degree 2 or it has degree 3 but not both. (n = “This polynomial has degree 2,” k = “This polynomial has degree 3”)

10. Let p be the statement “DATAENDFLAG is off,” q the statement “ERROR equals 0,” and r the statement “SUM is less than 1,000.” Express the following sentences in sym- bolic notation. a. DATAENDFLAG is off, ERROR equals 0, and SUM is

less than 1,000. b. DATAENDFLAG is off but ERROR is not equal to 0. c. DATAENDFLAG is off; however, ERROR is not 0 or

SUM is greater than or equal to 1,000. d. DATAENDFLAG is on and ERROR equals 0 but SUM

is greater than or equal to 1,000. e. Either DATAENDFLAG is on or it is the case that both

ERROR equals 0 and SUM is less than 1,000.

11. In the following sentence, is the word or used in its inclu- sive or exclusive sense? A team wins the playoffs if it wins two games in a row or a total of three games.

Write truth tables for the statement forms in 12–15.

12. ∼p ∧ q 13. ∼(p ∧ q) ∨ (p ∨ q) 14. p ∧ (q ∧ r) 15. p ∧ (∼q ∨ r) Determine whether the statement forms in 16–24 are logically equivalent. In each case, construct a truth table and include a sentence justifying your answer. Your sentence should show that you understand the meaning of logical equivalence.

16. p ∨ (p ∧ q) and p 17. ∼(p ∧ q) and ∼p ∧ ∼q 18. p ∨ t and t 19. p ∧ t and p 20. p ∧ c and p ∨ c 21. (p ∧ q) ∧ r and p ∧ (q ∧ r)

*For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

38 Chapter 2 The Logic of Compound Statements

22. p ∧ (q ∨ r) and (p ∧ q) ∨ (p ∧ r) 23. (p ∧ q) ∨ r and p ∧ (q ∨ r) 24. (p ∨ q) ∨ (p ∧ r) and (p ∨ q) ∧ r

Use De Morgan’s laws to write negations for the statements in 25–31.

25. Hal is a math major and Hal’s sister is a computer science major.

26. Sam is an orange belt and Kate is a red belt.

27. The connector is loose or the machine is unplugged.

28. The units digit of 467 is 4 or it is 6.

29. This computer program has a logical error in the first ten lines or it is being run with an incomplete data set.

30. The dollar is at an all-time high and the stock market is at a record low.

31. The train is late or my watch is fast.

Assume x is a particular real number and use De Morgan’s laws to write negations for the statements in 32–37.

32. −2 < x < 7 33. −10 < x < 2 34. x < 2 or x > 5 35. x ≤ −1 or x > 1 36. 1 > x ≥ −3 37. 0 > x ≥ −7

In 38 and 39, imagine that num_orders and num_instock are par- ticular values, such as might occur during execution of a com- puter program. Write negations for the following statements.

38. (num_orders > 100 and num_instock ≤ 500) or num_instock < 200

39. (num_orders < 50 and num_instock > 300) or (50 ≤ num_orders < 75 and num_instock > 500)

Use truth tables to establish which of the statement forms in 40–43 are tautologies and which are contradictions.

40. (p ∧ q) ∨ (∼p ∨ (p ∧ ∼q)) 41. (p ∧ ∼q) ∧ (∼p ∨ q) 42. ((∼p ∧ q) ∧ (q ∧ r))∧ ∼q 43. (∼p ∨ q) ∨ (p ∧ ∼q)

In 44 and 45, determine whether the statements in (a) and (b) are logically equivalent.

44. Assume x is a particular real number.

a. x < 2 or it is not the case that 1 < x < 3.

b. x ≤ 1 or either x < 2 or x ≥ 3.

45. a. Bob is a double math and computer science major and Ann is a math major, but Ann is not a double math and computer science major.

b. It is not the case that both Bob and Ann are dou- ble math and computer science majors, but it is the case that Ann is a math major and Bob is a double math and computer science major.

46.✶ In Example 2.1.4, the symbol ⊕ was introduced to denote exclusive or, so p ⊕ q ≡ (p ∨ q)∧ ∼(p ∧ q). Hence the truth table for exclusive or is as follows:

p q p ⊕ q T T F

T F T

F T T

F F F

a. Find simpler statement forms that are logically equiva- lent to p ⊕ p and (p ⊕ p)⊕ p.

b. Is (p ⊕ q)⊕ r ≡ p ⊕ (q ⊕ r)? Justify your answer. c. Is (p ⊕ q) ∧ r ≡ (p ∧ r)⊕ (q ∧ r)? Justify your

answer.

47.✶ In logic and in standard English, a double negative is equiv- alent to a positive. There is one fairly common English usage in which a “double positive” is equivalent to a nega- tive. What is it? Can you think of others?

In 48 and 49 below, a logical equivalence is derived from Theo- rem 2.1.1. Supply a reason for each step.

48. (p ∧ ∼q) ∨ (p ∧ q) ≡ p ∧ (∼q ∨ q) by (a)

≡ p ∧ (q ∨ ∼q) by (b)

≡ p ∧ t by (c)

≡ p by (d)

Therefore, (p ∧ ∼q) ∨ (p ∧ q) ≡ p. 49. (p ∨ ∼q) ∧ (∼p ∨ ∼q)

≡ (∼q ∨ p) ∧ (∼q ∨ ∼p) by (a)

≡ ∼q ∨ (p ∧ ∼p) by (b)

≡ ∼q ∨ c by (c)

≡ ∼q by (d)

Therefore, (p ∨ ∼q) ∧ (∼p ∨ ∼q) ≡ ∼q . Use Theorem 2.1.1 to verify the logical equivalences in 50–54. Supply a reason for each step.

50. (p ∧ ∼q) ∨ p ≡ p 51. p ∧ (∼q ∨ p) ≡ p 52. ∼(p ∨ ∼q) ∨ (∼p ∧ ∼q) ≡ ∼p 53. ∼((∼p ∧ q) ∨ (∼p ∧ ∼q)) ∨ (p ∧ q) ≡ p 54. (p ∧ (∼(∼p ∨ q))) ∨ (p ∧ q) ≡ p

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 39

Answers for Test Yourself 1. true 2. false 3. the same truth values 4. or; negated; and; negated 5. true 6. false

2.2 Conditional Statements . . . hypothetical reasoning implies the subordination of the real to the realm of the possible . . . — Jean Piaget, 1972

When you make a logical inference or deduction, you reason from a hypothesis to a conclusion. Your aim is to be able to say, “If such and such is known, then something or other must be the case.”

Let p and q be statements. A sentence of the form “If p then q” is denoted symboli- cally by “p → q”; p is called the hypothesis and q is called the conclusion. For instance, consider the following statement:

If 4,686 is divisible by 6︸ ︷︷ ︸, then 4,686 is divisible by 3︸ ︷︷ ︸ hypothesis conclusion

Such a sentence is called conditional because the truth of statement q is conditioned on the truth of statement p.

The notation p → q indicates that→ is a connective, like ∧ or ∨, that can be used to join statements to create new statements. To define p → q as a statement, therefore, we must specify the truth values for p → q as we specified truth values for p ∧ q and for p ∨ q. As is the case with the other connectives, the formal definition of truth values for → (if-then) is based on its everyday, intuitive meaning. Consider an example.

Suppose you go to interview for a job at a store and the owner of the store makes you the following promise:

If you show up for work Monday morning, then you will get the job.

Under what circumstances are you justified in saying the owner spoke falsely? That is, under what circumstances is the above sentence false? The answer is: You do show up for work Monday morning and you do not get the job.

After all, the owner’s promise only says you will get the job if a certain condition (showing up for work Monday morning) is met; it says nothing about what will hap- pen if the condition is not met. So if the condition is not met, you cannot in fairness say the promise is false regardless of whether or not you get the job.

The above example was intended to convince you that the only combination of circum- stances in which you would call a conditional sentence false occurs when the hypothesis is true and the conclusion is false. In all other cases, you would not call the sentence false. This implies that the only row of the truth table for p → q that should be filled in with an F is the row where p is T and q is F. No other row should contain an F. But each row of a truth table must be filled in with either a T or an F. Thus all other rows of the truth table for p → q must be filled in with T’s.

Truth Table for p → q

p q p → q T T T

T F F

F T T

F F T

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

40 Chapter 2 The Logic of Compound Statements

• Definition If p and q are statement variables, the conditional of q by p is “If p then q” or “p implies q” and is denoted p → q. It is false when p is true and q is false; otherwise it is true. We call p the hypothesis (or antecedent) of the conditional and q the conclusion (or consequent).

A conditional statement that is true by virtue of the fact that its hypothesis is false is often called vacuously true or true by default. Thus the statement “If you show up for work Monday morning, then you will get the job” is vacuously true if you do not show up for work Monday morning. In general, when the “if” part of an if-then statement is false, the statement as a whole is said to be true, regardless of whether the conclusion is true or false.

Example 2.2.1 A Conditional Statement with a False Hypothesis

Consider the statement:

If 0 = 1 then 1 = 2. As strange as it may seem, since the hypothesis of this statement is false, the statement as a whole is true. ■

The philosopher Willard Van Orman Quine advises against using the phrase “p implies q” to mean “p → q” because the word implies suggests that q can be logically deduced from p and this is often not the case. Nonetheless, the phrase is used by many people, probably because it is a convenient replacement for the → symbol. And, of course, in many cases a conclusion can be deduced from a hypothesis, even when the hypothesis is false.

Note For example, if 0 = 1, then, by adding 1 to both sides of the equation, you can deduce that 1 = 2.

In expressions that include→ as well as other logical operators such as ∧,∨, and ∼, the order of operations is that→ is performed last. Thus, according to the specification of order of operations in Section 2.1, ∼ is performed first, then ∧ and ∨, and finally→.

Example 2.2.2 Truth Table for p ∨ ∼q →∼p Construct a truth table for the statement form p ∨ ∼q →∼p.

Solution By the order of operations given above, the following two expressions are equiv- alent: p ∨ ∼q →∼p and (p ∨ (∼q))→ (∼p), and this order governs the construction of the truth table. First fill in the four possible combinations of truth values for p and q, and then enter the truth values for∼p and∼q using the definition of negation. Next fill in the p ∨ ∼q column using the definition of ∨. Finally, fill in the p ∨ ∼q →∼p column using the definition of→. The only rows in which the hypothesis p ∨ ∼q is true and the conclusion ∼p is false are the first and second rows. So you put F’s in those two rows and T’s in the other two rows.

conclusion︷ ︸︸ ︷ hypothesis︷ ︸︸ ︷

p q ∼p ∼q p ∨ ∼q p ∨ ∼q → ∼p T T F F T F

T F F T T F

F T T F F T

F F T T T T ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 41

Logical Equivalences Involving → Imagine that you are trying to solve a problem involving three statements: p, q, and r . Suppose you know that the truth of r follows from the truth of p and also that the truth of r follows from the truth of q. Then no matter whether p or q is the case, the truth of r must follow. The division-into-cases method of analysis is based on this idea.

Example 2.2.3 Division into Cases: Showing that p ∨ q → r ≡ ( p → r) ∧ (q → r) Use truth tables to show the logical equivalence of the statement forms p ∨ q → r and (p → r) ∧ (q → r). Annotate the table with a sentence of explanation.

Solution First fill in the eight possible combinations of truth values for p, q , and r . Then fill in the columns for p ∨ q, p → r , and q → r using the definitions of or and if-then. For instance, the p → r column has F’s in the second and fourth rows because these are the rows in which p is true and q is false. Next fill in the p ∨ q → r column using the definition of if-then. The rows in which the hypothesis p ∨ q is true and the conclusion r is false are the second, fourth, and sixth. So F’s go in these rows and T’s in all the others. The complete table shows that p ∨ q → r and (p → r) ∧ (q → r) have the same truth values for each combination of truth values of p, q, and r . Hence the two statement forms are logically equivalent.

p q r p ∨ q p → r q → r p ∨ q → r ( p → r) ∧ (q → r) T T T T T T T T

T T F T F F F F

T F T T T T T T

T F F T F T F F

F T T T T T T T

F T F T T F F F

F F T F T T T T

F F F F T T T T

↑ ↑ p ∨ q → r and (p → r) ∧ (q → r) always have the same truth values, so they are logically equivalent ■

Representation of If-Then As Or In exercise 13(a) at the end of this section you are asked to use truth tables to show that

p → q ≡ ∼p ∨ q. The logical equivalence of “if p then q” and “not p or q” is occasionally used in everyday speech. Here is one instance.

Example 2.2.4 Application of the Equivalence between ∼p ∨ q and p → q Rewrite the following statement in if-then form.

Either you get to work on time or you are fired.

Solution Let ∼p be You get to work on time.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

42 Chapter 2 The Logic of Compound Statements

and q be

You are fired.

Then the given statement is ∼p ∨ q . Also p is You do not get to work on time.

So the equivalent if-then version, p → q, is If you do not get to work on time, then you are fired. ■

The Negation of a Conditional Statement By definition, p → q is false if, and only if, its hypothesis, p, is true and its conclusion, q , is false. It follows that

The negation of “if p then q” is logically equivalent to “p and not q.”

This can be restated symbolically as follows:

∼(p → q) ≡ p ∧ ∼q

You can also obtain this result by starting from the logical equivalence p → q ≡ ∼ p ∨ q. Take the negation of both sides to obtain

∼(p → q) ≡ ∼(∼p ∨ q) ≡ ∼(∼p) ∧ (∼q) by De Morgan’s laws ≡ p ∧ ∼q by the double negative law.

Yet another way to derive this result is to construct truth tables for ∼(p → q) and for p ∧ ∼q and to check that they have the same truth values. (See exercise 13(b) at the end of this section.)

Example 2.2.5 Negations of If-Then Statements

Write negations for each of the following statements:

a. If my car is in the repair shop, then I cannot get to class.

b. If Sara lives in Athens, then she lives in Greece.

Solution

a. My car is in the repair shop and I can get to class.

b. Sara lives in Athens and she does not live in Greece. (Sara might live in Athens, Georgia; Athens, Ohio; or Athens, Wisconsin.) ■

It is tempting to write the negation of an if-then statement as another if-then statement. Please resist that temptation!

! Caution! Remember that the negation of an if-then statement does not start with the word if.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 43

The Contrapositive of a Conditional Statement One of the most fundamental laws of logic is the equivalence between a conditional statement and its contrapositive.

• Definition The contrapositive of a conditional statement of the form “If p then q” is

If ∼q then ∼p. Symbolically,

The contrapositive of p → q is ∼q →∼p.

The fact is that

A conditional statement is logically equivalent to its contrapositive.

You are asked to establish this equivalence in exercise 26 at the end of this section.

Example 2.2.6 Writing the Contrapositive

Write each of the following statements in its equivalent contrapositive form:

a. If Howard can swim across the lake, then Howard can swim to the island.

b. If today is Easter, then tomorrow is Monday.

Solution

a. If Howard cannot swim to the island, then Howard cannot swim across the lake.

b. If tomorrow is not Monday, then today is not Easter. ■

When you are trying to solve certain problems, you may find that the contrapositive form of a conditional statement is easier to work with than the original statement. Replac- ing a statement by its contrapositive may give the extra push that helps you over the top in your search for a solution. This logical equivalence is also the basis for one of the most important laws of deduction, modus tollens (to be explained in Section 2.3), and for the contrapositive method of proof (to be explained in Section 4.6).

The Converse and Inverse of a Conditional Statement The fact that a conditional statement and its contrapositive are logically equivalent is very important and has wide application. Two other variants of a conditional statement are not logically equivalent to the statement.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

44 Chapter 2 The Logic of Compound Statements

• Definition Suppose a conditional statement of the form “If p then q” is given.

1. The converse is “If q then p.”

2. The inverse is “If ∼p then ∼q.” Symbolically,

The converse of p → q is q → p, and

The inverse of p → q is ∼p →∼q .

Example 2.2.7 Writing the Converse and the Inverse

Write the converse and inverse of each of the following statements:

a. If Howard can swim across the lake, then Howard can swim to the island.

b. If today is Easter, then tomorrow is Monday.

Solution

a. Converse: If Howard can swim to the island, then Howard can swim across the lake.

Inverse: If Howard cannot swim across the lake, then Howard cannot swim to the island.

b. Converse: If tomorrow is Monday, then today is Easter.

Inverse: If today is not Easter, then tomorrow is not Monday. ■

Note that while the statement “If today is Easter, then tomorrow is Monday” is always true, both its converse and inverse are false on every Sunday except Easter.

1. A conditional statement and its converse are not logically equivalent.

2. A conditional statement and its inverse are not logically equivalent.

3. The converse and the inverse of a conditional statement are logically equivalent to each other.

! Caution! Many people believe that if a conditional statement is true, then its converse and inverse must also be true. This is not correct!

In exercises 24, 25, and 27 at the end of this section, you are asked to use truth tables to verify the statements in the box above. Note that the truth of statement 3 also follows from the observation that the inverse of a conditional statement is the contrapositive of its converse.

Only If and the Biconditional To say “p only if q” means that p can take place only if q takes place also. That is, if q does not take place, then p cannot take place. Another way to say this is that if p occurs, then q must also occur (by the logical equivalence between a statement and its contrapositive).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 45

• Definition It p and q are statements,

p only if q means “if not q then not p,”

or, equivalently,

“if p then q .”

Example 2.2.8 Converting Only If to If-Then

Rewrite the following statement in if-then form in two ways, one of which is the contra- positive of the other.

John will break the world’s record for the mile run only if he runs the mile in under four minutes.

Solution Version 1: If John does not run the mile in under four minutes, then he will not break the world’s record.

Version 2: If John breaks the world’s record, then he will have run the mile in under four minutes. ■

! Caution! “p only if q” does not mean “p if q.”

Note that it is possible for “p only if q” to be true at the some time that “p if q” is false. For instance, to say that John will break the world’s record only if he runs the mile in under four minutes does not mean that John will break the world’s record if he runs the mile in under four minutes. His time could be under four minutes but still not be fast enough to break the record.

• Definition Given statement variables p and q, the biconditional of p and q is “p if, and only if, q” and is denoted p ↔ q . It is true if both p and q have the same truth values and is false if p and q have opposite truth values. The words if and only if are sometimes abbreviated iff.

The biconditional has the following truth table:

Truth Table for p ↔ q

p q p ↔ q T T T

T F F

F T F

F F T

In order of operations ↔ is coequal with →. As with ∧ and ∨, the only way to indicate precedence between them is to use parentheses. The full hierarchy of operations for the five logical operators is on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

46 Chapter 2 The Logic of Compound Statements

Order of Operations for Logical Operators

1. ∼ Evaluate negations first.

2. ∧,∨ Evaluate ∧ and ∨ second. When both are present, parentheses may be needed.

3. →,↔ Evaluate → and ↔ third. When both are present, parentheses may be needed.

According to the separate definitions of if and only if, saying “p if, and only if, q” should mean the same as saying both “p if q” and “p only if q.” The following annotated truth table shows that this is the case:

Truth Table Showing that p ↔ q ≡ ( p → q) ∧ (q → p)

p q p → q q → p p ↔ q ( p → q) ∧ (q → p) T T T T T T

T F F T F F

F T T F F F

F F T T T T

↑ ↑ p ↔ q and (p → q) ∧ (q → p) always have the same truth values, so they are logically equivalent

Example 2.2.9 If and Only If

Rewrite the following statement as a conjunction of two if-then statements:

This computer program is correct if, and only if, it produces correct answers for all possible sets of input data.

Solution If this program is correct, then it produces the correct answes for all possible sets of input data; and if this program produces the correct answers for all possible sets of input data, then it is correct. ■

Necessary and Sufficient Conditions The phrases necessary condition and sufficient condition, as used in formal English, cor- respond exactly to their definitions in logic.

• Definition If r and s are statements:

r is a sufficient condition for s means “if r then s.” r is a necessary condition for s means “if not r then not s.”

In other words, to say “r is a sufficient condition for s” means that the occurrence of r is sufficient to guarantee the occurrence of s. On the other hand, to say “r is a necessary condition for s” means that if r does not occur, then s cannot occur either:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 47

The occurrence of r is necessary to obtain the occurrence of s. Note that because of the equivalence between a statement and its contrapositive,

r is a necessary condition for s also means “if s then r.”

Consequently,

r is a necessary and sufficient condition for s means “r if, and only if, s.”

Example 2.2.10 Interpreting Necessary and Sufficient Conditions

Consider the statement “If John is eligible to vote, then he is at least 18 years old.” The truth of the condition “John is eligible to vote” is sufficient to ensure the truth of the condition “John is at least 18 years old.” In addition, the condition “John is at least 18 years old” is necessary for the condition “John is eligible to vote” to be true. If John were younger than 18, then he would not be eligible to vote. ■

Example 2.2.11 Converting a Sufficient Condition to If-Then Form

Rewrite the following statement in the form “If A then B”:

Pia’s birth on U.S soil is a sufficient condition for her to be a U.S. citizen.

Solution If Pia was born on U.S. soil, then she is a U.S. citizen. ■

Example 2.2.12 Converting a Necessary Condition to If-Then Form

Use the contrapositive to rewrite the following statement in two ways:

George’s attaining age 35 is a necessary condition for his being president of the United States.

Solution Version 1: If George has not attained the age of 35, then he cannot be presi- dent of the United States.

Version 2: If George can be president of the United States, then he has attained the age of 35. ■

Remarks 1. In logic, a hypothesis and conclusion are not required to have related subject matters.

In ordinary speech we never say things like “If computers are machines, then Babe Ruth was a baseball player” or “If 2 + 2 = 5, then Mickey Mouse is president of the United States.” We formulate a sentence like “If p then q” only if there is some connection of content between p and q .

In logic, however, the two parts of a conditional statement need not have related meanings. The reason? If there were such a requirement, who would enforce it? What one person perceives as two unrelated clauses may seem related to someone else. There would have to be a central arbiter to check each conditional sentence before anyone could use it, to be sure its clauses were in proper relation. This is impractical, to say the least!

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

48 Chapter 2 The Logic of Compound Statements

Thus a statement like “if computers are machines, then Babe Ruth was a baseball player” is allowed, and it is even called true because both its hypothesis and its conclu- sion are true. Similarly, the statement “If 2 + 2 = 5, then Mickey Mouse is president of the United States” is allowed and is called true because its hypothesis is false, even though doing so may seem ridiculous.

In mathematics it often happens that a carefully formulated definition that suc- cessfully covers the situations for which it was primarily intended is later seen to be satisfied by some extreme cases that the formulator did not have in mind. But those are the breaks, and it is important to get into the habit of exploring definitions fully to seek out and understand all their instances, even the unusual ones.

2. In informal language, simple conditionals are often used to mean biconditionals. The formal statement “p if, and only if, q” is seldom used in ordinary language.

Frequently, when people intend the biconditional they leave out either the and only if or the if and. That is, they say either “p if q” or “p only if q” when they really mean “p if, and only if, q .” For example, consider the statement “You will get dessert if, and only if, you eat your dinner.” Logically, this is equivalent to the conjunction of the following two statements.

Statement 1: If you eat your dinner, then you will get dessert.

Statement 2: You will get dessert only if you eat your dinner. or

If you do not eat your dinner, then you will not get dessert.

Now how many parents in the history of the world have said to their children “You will get dessert if, and only if, you eat your dinner”? Not many! Most say either “If you eat your dinner, you will get dessert” (these take the positive approach—they emphasize the reward) or “You will get dessert only if you eat your dinner” (these take the negative approach—they emphasize the punishment). Yet the parents who promise the reward intend to suggest the punishment as well, and those who threaten the punishment will certainly give the reward if it is earned. Both sets of parents expect that their conditional statements will be interpreted as biconditionals.

Since we often (correctly) interpret conditional statements as biconditionals, it is not surprising that we may come to believe (mistakenly) that conditional statements are always logically equivalent to their inverses and converses. In formal settings, however, statements must have unambiguous interpretations. If-then statements can’t sometimes mean “if-then” and other times mean “if and only if.” When using language in mathe- matics, science, or other situations where precision is important, it is essential to interpret if-then statements according to the formal definition and not to confuse them with their converses and inverses.

Test Yourself 1. An if-then statement is false if, and only if, the hypothesis is

and the conclusion is .

2. The negation of “if p then q” is .

3. The converse of “if p then q” is .

4. The contrapositive of “if p then q” is .

5. The inverse of “if p then q” is .

6. A conditional statement and its contrapositive are .

7. A conditional statement and its converse are not .

8. “R is a sufficient condition for S” means “if then .”

9. “R is a necessary condition for S” means “if then .”

10. “R only if S” means “if then .”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Conditional Statements 49

Exercise Set 2.2 Rewrite the statements in 1–4 in if-then form.

1. This loop will repeat exactly N times if it does not contain a stop or a go to.

2. I am on time for work if I catch the 8:05 bus.

3. Freeze or I’ll shoot.

4. Fix my ceiling or I won’t pay my rent.

Construct truth tables for the statement forms in 5–11.

5. ∼p ∨ q →∼q 6. (p ∨ q) ∨ (∼p ∧ q)→ q 7. p ∧ ∼q → r 8. ∼p ∨ q → r 9. p ∧ ∼r ↔ q ∨ r 10. (p → r)↔ (q → r)

11. (p → (q → r))↔ ((p ∧ q)→ r) 12. Use the logical equivalence established in Example 2.2.3,

p ∨ q → r ≡ (p → r) ∧ (q → r), to rewrite the follow- ing statement. (Assume that x represents a fixed real number.)

If x > 2 or x < −2, then x2 > 4. 13. Use truth tables to verify the following logical equiv-

alences. Include a few words of explanation with your answers. a. p → q ≡ ∼p ∨ q b. ∼(p → q) ≡ p ∧ ∼q.

14.H a. Show that the following statement forms are all logically equivalent.

p → q ∨ r, p ∧ ∼q → r, and p ∧ ∼r → q b. Use the logical equivalences established in part (a) to

rewrite the following sentence in two different ways. (Assume that n represents a fixed integer.)

If n is prime, then n is odd or n is 2.

15. Determine whether the following statement forms are logi- cally equivalent:

p → (q → r) and (p → q)→ r

In 16 and 17, write each of the two statements in symbolic form and determine whether they are logically equivalent. Include a truth table and a few words of explanation.

16. If you paid full price, you didn’t buy it at Crown Books. You didn’t buy it at Crown Books or you paid full price.

17. If 2 is a factor of n and 3 is a factor of n, then 6 is a factor of n. 2 is not a factor of n or 3 is not a factor of n or 6 is a factor of n.

18. Write each of the following three statements in symbolic form and determine which pairs are logically equivalent. Include truth tables and a few words of explanation.

If it walks like a duck and it talks like a duck, then it is a duck.

Either it does not walk like a duck or it does not talk like a duck, or it is a duck.

If it does not walk like a duck and it does not talk like a duck, then it is not a duck.

19. True or false? The negation of “If Sue is Luiz’s mother, then Ali is his cousin” is “If Sue is Luiz’s mother, then Ali is not his cousin.”

20. Write negations for each of the following statements. (Assume that all variables represent fixed quantities or enti- ties, as appropriate.) a. If P is a square, then P is a rectangle. b. If today is New Year’s Eve, then tomorrow is January. c. If the decimal expansion of r is terminating, then r is

rational. d. If n is prime, then n is odd or n is 2. e. If x is nonnegative, then x is positive or x is 0. f. If Tom is Ann’s father, then Jim is her uncle and Sue is

her aunt. g. If n is divisible by 6, then n is divisible by 2 and n is

divisible by 3.

21. Suppose that p and q are statements so that p → q is false. Find the truth values of each of the following:

a. ∼p → q b. p ∨ q c. q → p 22.H Write contrapositives for the statements of exercise 20.

23.H Write the converse and inverse for each statement of exercise 20.

Use truth tables to establish the truth of each statement in 24–27.

24. A conditional statement is not logically equivalent to its converse.

25. A conditional statement is not logically equivalent to its inverse.

26. A conditional statement and its contrapositive are logically equivalent to each other.

27. The converse and inverse of a conditional statement are log- ically equivalent to each other.

28.H “Do you mean that you think you can find out the answer to it?” said the March Hare.

“Exactly so,” said Alice. “Then you should say what you mean,” the March Hare

went on. “I do,” Alice hastily replied; “at least—at least I mean

what I say—that’s the same thing, you know.”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

50 Chapter 2 The Logic of Compound Statements

“Not the same thing a bit!” said the Hatter. “Why, you might just as well say that ‘I see what I eat’ is the same thing as ‘I eat what I see’!”

—from “A Mad Tea-Party” in Alice in Wonderland, by Lewis Carroll

The Hatter is right. “I say what I mean” is not the same thing as “I mean what I say.” Rewrite each of these two sentences in if-then form and explain the logical relation between them. (This exercise is referred to in the introduc- tion to Chapter 4.)

If statement forms P and Q are logically equivalent, then P ↔ Q is a tautology. Conversely, if P ↔ Q is a tautology, then P and Q are logically equivalent. Use ↔ to convert each of the logical equivalences in 29–31 to a tautology. Then use a truth table to verify each tautology.

29. p → (q ∨ r) ≡ (p ∧ ∼q)→ r 30. p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) 31. p → (q → r) ≡ (p ∧ q)→ r Rewrite each of the statements in 32 and 33 as a conjunction of two if-then statements.

32. This quadratic equation has two distinct real roots if, and only if, its discriminant is greater than zero.

33. This integer is even if, and only if, it equals twice some integer.

Rewrite the statements in 34 and 35 in if-then form in two ways, one of which is the contrapositive of the other.

34. The Cubs will win the pennant only if they win tomorrow’s game.

35. Sam will be allowed on Signe’s racing boat only if he is an expert sailor.

36. Taking the long view on your education, you go to the Pres- tige Corporation and ask what you should do in college to be hired when you graduate. The personnel director replies that you will be hired only if you major in mathematics or computer science, get a B average or better, and take accounting. You do, in fact, become a math major, get a B+

average, and take accounting. You return to Prestige Cor- poration, make a formal application, and are turned down. Did the personnel director lie to you?

Some programming languages use statements of the form “r unless sn” to mean that as long as s does not happen, then r will happen. More formally:

Definition: If r and s are statements, r unless s means if ∼s then r.

In 37–39, rewrite the statements in if-then form.

37. Payment will be made on the fifth unless a new hearing is granted.

38. Ann will go unless it rains.

39. This door will not open unless a security code is entered.

Rewrite the statements in 40 and 41 in if-then form.

40. Catching the 8:05 bus is a sufficient condition for my being on time for work.

41. Having two 45◦ angles is a sufficient condition for this tri- angle to be a right triangle.

Use the contrapositive to rewrite the statements in 42 and 43 in if-then form in two ways.

42. Being divisible by 3 is a necessary condition for this num- ber to be divisible by 9.

43. Doing homework regularly is a necessary condition for Jim to pass the course.

Note that “a sufficient condition for s is r” means r is a suffi- cient condition for s and that “a necessary condition for s is r” means r is a necessary condition for s. Rewrite the statements in 44 and 45 in if-then form.

44. A sufficient condition for Jon’s team to win the champi- onship is that it win the rest of its games.

45. A necessary condition for this computer program to be cor- rect is that it not produce error messages during translation.

46. “If compound X is boiling, then its temperature must be at least 150◦C.” Assuming that this statement is true, which of the following must also be true? a. If the temperature of compound X is at least 150◦C, then

compound X is boiling. b. If the temperature of compound X is less than 150◦C,

then compound X is not boiling. c. Compound X will boil only if its temperature is at least

150◦C. d. If compound X is not boiling, then its temperature is less

than 150◦C. e. A necessary condition for compound X to boil is that its

temperature be at least 150◦C. f. A sufficient condition for compound X to boil is that its

temperature be at least 150◦C.

In 47–50 (a) use the logical equivalences p → q ≡∼p ∨ q and p ↔ q ≡ (∼p ∨ q) ∧ (∼q ∨ p) to rewrite the given statement forms without using the symbol → or ↔, and (b) use the logi- cal equivalence p ∨ q ≡∼(∼p∧ ∼q) to rewrite each statement form using only ∧ and ∼.

47. p ∧ ∼q → r 48. p ∨ ∼q → r ∨ q 49. (p → r)↔ (q → r) 50. (p → (q → r))↔ ((p ∧ q)→ r) 51. Given any statement form, is it possible to find a logi-

cally equivalent form that uses only ∼ and ∧? Justify your answer.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 51

Answers for Test Yourself 1. true; false 2. p∧ ∼q 3. if q then p 4. if ∼q then ∼p 5. if ∼p then ∼q 6. logically equivalent 7. logically equivalent 8. R; S 9. S; R 10. R; S

2.3 Valid and Invalid Arguments “Contrariwise,” continued Tweedledee, “if it was so, it might be; and if it were so, it would be; but as it isn’t, it ain’t. That’s logic.” — Lewis Carroll, Through the Looking Glass

In mathematics and logic an argument is not a dispute. It is a sequence of statements ending in a conclusion. In this section we show how to determine whether an argument is valid—that is, whether the conclusion follows necessarily from the preceding statements. We will show that this determination depends only on the form of an argument, not on its content.

It was shown in Section 2.1 that the logical form of an argument can be abstracted from its content. For example, the argument

If Socrates is a man, then Socrates is mortal.

Socrates is a man.

∴ Socrates is mortal.

has the abstract form

If p then q p

∴ q When considering the abstract form of an argument, think of p and q as variables

for which statements may be substituted. An argument form is called valid if, and only if, whenever statements are substituted that make all the premises true, the conclusion is also true.

• Definition An argument is a sequence of statements, and an argument form is a sequence of statement forms. All statements in an argument and all statement forms in an argument form, except for the final one, are called premises (or assumptions or hypotheses). The final statement or statement form is called the conclusion. The symbol ∴ , which is read “therefore,” is normally placed just before the conclusion.

To say that an argument form is valid means that no matter what particular state- ments are substituted for the statement variables in its premises, if the resulting premises are all true, then the conclusion is also true. To say that an argument is valid means that its form is valid.

The crucial fact about a valid argument is that the truth of its conclusion follows necessarily or inescapably or by logical form alone from the truth of its premises. It is impossible to have a valid argument with true premises and a false conclusion. When an argument is valid and its premises are true, the truth of the conclusion is said to be inferred or deduced from the truth of the premises. If a conclusion “ain’t necessarily so,” then it isn’t a valid deduction.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

52 Chapter 2 The Logic of Compound Statements

Testing an Argument Form for Validity

1. Identify the premises and conclusion of the argument form.

2. Construct a truth table showing the truth values of all the premises and the con- clusion.

3. A row of the truth table in which all the premises are true is called a critical row. If there is a critical row in which the conclusion is false, then it is possible for an argument of the given form to have true premises and a false conclusion, and so the argument form is invalid. If the conclusion in every critical row is true, then the argument form is valid.

Example 2.3.1 Determining Validity or Invalidity

Determine whether the following argument form is valid or invalid by drawing a truth table, indicating which columns represent the premises and which represent the conclu- sion, and annotating the table with a sentence of explanation. When you fill in the table, you only need to indicate the truth values for the conclusion in the rows where all the premises are true (the critical rows) because the truth values of the conclusion in the other rows are irrelevant to the validity or invalidity of the argument.

p → q ∨ ∼r q → p ∧ r

∴ p → r Solution The truth table shows that even though there are several situations in which the

premises and the conclusion are all true (rows 1, 7, and 8), there is one situation (row 4) where the premises are true and the conclusion is false.

premises︷ ︸︸ ︷ conclusion

p q r ∼r q ∨ ∼r p ∧ r p → q ∨ ∼r q → p ∧ r p → r T T T F T T T T T

T T F T T F T F

T F T F F T F T

T F F T T F T T F

This row shows that an argument of this form can have true premises and a false conclusion. Hence this form of argument is invalid.F T T F T F T F

F T F T T F T F

F F T F F F T T T

F F F T T F T T T ■

Modus Ponens and Modus Tollens An argument form consisting of two premises and a conclusion is called a syllogism. The first and second premises are called the major premise and minor premise, respectively.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 53

The most famous form of syllogism in logic is called modus ponens. It has the following form:

If p then q.

p

∴ q Here is an argument of this form:

If the sum of the digits of 371,487 is divisible by 3, then 371,487 is divisible by 3.

The sum of the digits of 371,487 is divisible by 3.

∴ 371,487 is divisible by 3. The term modus ponens is Latin meaning “method of affirming” (the conclusion is an affirmation). Long before you saw your first truth table, you were undoubtedly being convinced by arguments of this form. Nevertheless, it is instructive to prove that modus ponens is a valid form of argument, if for no other reason than to confirm the agreement between the formal definition of validity and the intuitive concept. To do so, we construct a truth table for the premises and conclusion.

premises︷ ︸︸ ︷ conclusion

p q p → q p q T T T T T ←− critical row T F F T

F T T F

F F T F

The first row is the only one in which both premises are true, and the conclusion in that row is also true. Hence the argument form is valid.

Now consider another valid argument form called modus tollens. It has the following form:

If p then q.

∼q ∴ ∼p

Here is an example of modus tollens:

If Zeus is human, then Zeus is mortal.

Zeus is not mortal.

∴ Zeus is not human. An intuitive explanation for the validity of modus tollens uses proof by contradiction.

It goes like this:

Suppose

(1) If Zeus is human, then Zeus is mortal; and

(2) Zeus is not mortal.

Must Zeus necessarily be nonhuman?

Yes!

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

54 Chapter 2 The Logic of Compound Statements

Because, if Zeus were human, then by (1) he would be mortal.

But by (2) he is not mortal.

Hence, Zeus cannot be human.

Modus tollens is Latin meaning “method of denying” (the conclusion is a denial). The validity of modus tollens can be shown to follow from modus ponens together with the fact that a conditional statement is logically equivalent to its contrapositive. Or it can be established formally by using a truth table. (See exercise 13.)

Studies by cognitive psychologists have shown that although nearly 100% of college students have a solid, intuitive understanding of modus ponens, less than 60% are able to apply modus tollens correctly.∗ Yet in mathematical reasoning, modus tollens is used almost as often as modus ponens. Thus it is important to study the form of modus tollens carefully to learn to use it effectively.

Example 2.3.2 Recognizing Modus Ponens and Modus Tollens

Use modus ponens or modus tollens to fill in the blanks of the following arguments so that they become valid inferences.

a. If there are more pigeons than there are pigeonholes, then at least two pigeons roost in the same hole. There are more pigeons than there are pigeonholes. ∴ .

b. If 870,232 is divisible by 6, then it is divisible by 3. 870,232 is not divisible by 3. ∴ .

Solution

a. At least two pigeons roost in the same hole. by modus ponens

b. 870,232 is not divisible by 6. by modus tollens ■

Additional Valid Argument Forms: Rules of Inference A rule of inference is a form of argument that is valid. Thus modus ponens and modus tollens are both rules of inference. The following are additional examples of rules of inference that are frequently used in deductive reasoning.

Example 2.3.3 Generalization

The following argument forms are valid: a. p ∴ p ∨ q

b. q ∴ p ∨ q

These argument forms are used for making generalizations. For instance, according to the first, if p is true, then, more generally, “p or q” is true for any other statement q . As an example, suppose you are given the job of counting the upperclassmen at your school. You ask what class Anton is in and are told he is a junior.

∗Cognitive Psychology and Its Implications, 3d ed. by John R. Anderson (New York: Freeman, 1990), pp. 292–297.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 55

You reason as follows:

Anton is a junior.

∴ (more generally) Anton is a junior or Anton is a senior. Knowing that upperclassman means junior or senior, you add Anton to your list. ■

Example 2.3.4 Specialization

The following argument forms are valid: a. p ∧ q ∴ p

b. p ∧ q ∴ q

These argument forms are used for specializing. When classifying objects according to some property, you often know much more about them than whether they do or do not have that property. When this happens, you discard extraneous information as you con- centrate on the particular property of interest.

For instance, suppose you are looking for a person who knows graph algorithms to work with you on a project. You discover that Ana knows both numerical analysis and graph algorithms. You reason as follows:

Ana knows numerical analysis and Ana knows graph algorithms.

∴ (in particular) Ana knows graph algorithms. Accordingly, you invite her to work with you on your project. ■

Both generalization and specialization are used frequently in mathematics to tailor facts to fit into hypotheses of known theorems in order to draw further conclusions. Elim- ination, transitivity, and proof by division into cases are also widely used tools.

Example 2.3.5 Elimination

The following argument forms are valid:

a. p ∨ q ∼q

∴ p

b. p ∨ q ∼p

∴ q These argument forms say that when you have only two possibilities and you can rule one out, the other must be the case. For instance, suppose you know that for a particular number x ,

x − 3 = 0 or x + 2 = 0. If you also know that x is not negative, then x ̸= −2, so

x + 2 ̸= 0. By elimination, you can then conclude that

∴ x − 3 = 0. ■ Example 2.3.6 Transitivity

The following argument form is valid:

p → q q → r

∴ p → r

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

56 Chapter 2 The Logic of Compound Statements

Many arguments in mathematics contain chains of if-then statements. From the fact that one statement implies a second and the second implies a third, you can conclude that the first statement implies the third. Here is an example:

If 18,486 is divisible by 18, then 18,486 is divisible by 9.

If 18,486 is divisible by 9, then the sum of the digits of 18,486 is divisible by 9.

∴ If 18,486 is divisible by 18, then the sum of the digits of 18,486 is divisible by 9. ■

Example 2.3.7 Proof by Division into Cases

The following argument form is valid: p ∨ q p → r q → r

∴ r It often happens that you know one thing or another is true. If you can show that in either case a certain conclusion follows, then this conclusion must also be true. For instance, suppose you know that x is a particular nonzero real number. The trichotomy property of the real numbers says that any number is positive, negative, or zero. Thus (by elimination) you know that x is positive or x is negative. You can deduce that x2 > 0 by arguing as follows:

x is positive or x is negative.

If x is positive, then x2 > 0.

If x is negative, then x2 > 0.

∴ x2 > 0. ■

The rules of valid inference are used constantly in problem solving. Here is an example from everyday life.

Example 2.3.8 Application: A More Complex Deduction

You are about to leave for school in the morning and discover that you don’t have your glasses. You know the following statements are true:

a. If I was reading the newspaper in the kitchen, then my glasses are on the kitchen table.

b. If my glasses are on the kitchen table, then I saw them at breakfast.

c. I did not see my glasses at breakfast.

d. I was reading the newspaper in the living room or I was reading the newspaper in the kitchen.

e. If I was reading the newspaper in the living room then my glasses are on the coffee table.

Where are the glasses?

Solution Let RK = I was reading the newspaper in the kitchen. GK = My glasses are on the kitchen table. SB = I saw my glasses at breakfast. RL = I was reading the newspaper in the living room. GC = My glasses are on the coffee table.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 57

Here is a sequence of steps you might use to reach the answer, together with the rules of inference that allow you to draw the conclusion of each step:

1. RK → GK by (a) GK → SB by (d)

∴ RK → SB by transitivity 2. RK → SB by the conclusion of (1)

∼SB by (c) ∴ ∼RK by modus tollens

3. RL ∨ RK by (d) ∼RK by the conclusion of (2)

∴ RL by elimination 4. RL → GC by (e)

RL by the conclusion of (3)

∴ GC by modus ponens

Thus the glasses are on the coffee table. ■

Fallacies A fallacy is an error in reasoning that results in an invalid argument. Three common fallacies are using ambiguous premises, and treating them as if they were unambiguous, circular reasoning (assuming what is to be proved without having derived it from the premises), and jumping to a conclusion (without adequate grounds). In this section we discuss two other fallacies, called converse error and inverse error, which give rise to arguments that superficially resemble those that are valid by modus ponens and modus tollens but are not, in fact, valid.

As in previous examples, you can show that an argument is invalid by constructing a truth table for the argument form and finding at least one critical row in which all the premises are true but the conclusion is false. Another way is to find an argument of the same form with true premises and a false conclusion.

For an argument to be valid, every argument of the same form whose premises are all true must have a true conclusion. It follows that for an argument to be invalid means that there is an argument of that form whose premises are all true and whose conclusion is false.

Example 2.3.9 Converse Error

Show that the following argument is invalid:

If Zeke is a cheater, then Zeke sits in the back row.

Zeke sits in the back row.

∴ Zeke is a cheater. Solution Many people recognize the invalidity of the above argument intuitively, reasoning

something like this: The first premise gives information about Zeke if it is known he is a cheater. It doesn’t give any information about him if it is not already known that he is a cheater. One can certainly imagine a person who is not a cheater but happens to sit in the

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

58 Chapter 2 The Logic of Compound Statements

back row. Then if that person’s name is substituted for Zeke, the first premise is true by default and the second premise is also true but the conclusion is false.

The general form of the previous argument is as follows:

p → q q

∴ p In exercise 12(a) at the end of this section you are asked to use a truth table to show that this form of argument is invalid. ■

The fallacy underlying this invalid argument form is called the converse error because the conclusion of the argument would follow from the premises if the premise p → q were replaced by its converse. Such a replacement is not allowed, however, because a conditional statement is not logically equivalent to its converse. Converse error is also known as the fallacy of affirming the consequent.

Another common error in reasoning is called the inverse error.

Example 2.3.10 Inverse Error

Consider the following argument:

If interest rates are going up, stock market prices will go down.

Interest rates are not going up.

∴ Stock market prices will not go down. Note that this argument has the following form:

p → q ∼p

∴ ∼q You are asked to give a truth table verification of the invalidity of this argument form in exercise 12(b) at the end of this section.

The fallacy underlying this invalid argument form is called the inverse error because the conclusion of the argument would follow from the premises if the premise p → q were replaced by its inverse. Such a replacement is not allowed, however, because a conditional statement is not logically equivalent to its inverse. Inverse error is also known as the fallacy of denying the antecedent. ■

! Caution! In logic, the words true and valid have very different meanings. A valid argument may have a false conclusion, and an invalid argument may have a true conclusion.

Sometimes people lump together the ideas of validity and truth. If an argument seems valid, they accept the conclusion as true. And if an argument seems fishy (really a slang expression for invalid), they think the conclusion must be false. This is not correct!

Example 2.3.11 A Valid Argument with a False Premise and a False Conclusion

The argument below is valid by modus ponens. But its major premise is false, and so is its conclusion.

If John Lennon was a rock star, then John Lennon had red hair.

John Lennon was a rock star.

∴ John Lennon had red hair. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 59

Example 2.3.12 An Invalid Argument with True Premises and a True Conclusion

The argument below is invalid by the converse error, but it has a true conclusion.

If New York is a big city, then New York has tall buildings.

New York has tall buildings.

∴ New York is a big city. ■

• Definition An argument is called sound if, and only if, it is valid and all its premises are true. An argument that is not sound is called unsound.

The important thing to note is that validity is a property of argument forms: If an argument is valid, then so is every other argument that has the same form. Similarly, if an argument is invalid, then so is every other argument that has the same form. What characterizes a valid argument is that no argument whose form is valid can have all true premises and a false conclusion. For each valid argument, there are arguments of that form with all true premises and a true conclusion, with at least one false premise and a true conclusion, and with at least one false premise and a false conclusion. On the other hand, for each invalid argument, there are arguments of that form with every combination of truth values for the premises and conclusion, including all true premises and a false conclusion. The bottom line is that we can only be sure that the conclusion of an argument is true when we know that the argument is sound, that is, when we know both that the argument is valid and that it has all true premises.

Contradictions and Valid Arguments The concept of logical contradiction can be used to make inferences through a technique of reasoning called the contradiction rule. Suppose p is some statement whose truth you wish to deduce.

Contradiction Rule

If you can show that the supposition that statement p is false leads logically to a contradiction, then you can conclude that p is true.

Example 2.3.13 Contradiction Rule

Show that the following argument form is valid:

∼p → c, where c is a contradiction ∴ p

Solution Construct a truth table for the premise and the conclusion of this argument. premises conclusion

p ∼p c ∼p → c p

T F F T T

There is only one critical row in which the premise is true, and in this row the conclusion is also true. Hence this form of argument is valid.F T F F ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

60 Chapter 2 The Logic of Compound Statements

The contradiction rule is the logical heart of the method of proof by contradiction. A slight variation also provides the basis for solving many logical puzzles by eliminating contradictory answers: If an assumption leads to a contradiction, then that assumption must be false.

Example 2.3.14 Knights and Knaves

The logician Raymond Smullyan describes an island containing two types of people: knights who always tell the truth and knaves who always lie.∗ You visit the island and are approached by two natives who speak to you as follows:

A says: B is a knight.

B says: A and I are of opposite type.

What are A and B?

Solution A and B are both knaves. To see this, reason as follows: Suppose A is a knight.

∴ What A says is true. by definition of knight

In di

an a

U ni

ve rs

ity Ar

ch iv

es

Raymond Smullyan (born 1919)

∴ B is also a knight. That’s what A said. ∴ What B says is true. by definition of knight ∴ A and B are of opposite types. That’s what B said. ∴ We have arrived at the following contradiction: A and B

are both knights and A and B are of opposite type.

∴ The supposition is false. by the contradiction rule ∴ A is not a knight. negation of supposition ∴ A is a knave. by elimination: It’s given that all inhabitants

are knights or knaves, so since A is not a knight, A is a knave.

∴ What A says is false. ∴ B is not a knight. ∴ B is also a knave. by elimination

This reasoning shows that if the problem has a solution at all, then A and B must both be knaves. It is conceivable, however, that the problem has no solution. The problem statement could be inherently contradictory. If you look back at the solution, though, you can see that it does work out for both A and B to be knaves. ■

Summary of Rules of Inference Table 2.3.1 summarizes some of the most important rules of inference.

∗Raymond Smullyan has written a delightful series of whimsical yet profound books of logical puzzles starting with What Is the Name of This Book? (Englewood Cliffs, New Jersey: Prentice-Hall, 1978). Other good sources of logical puzzles are the many excellent books of Martin Gardner, such as Aha! Insight and Aha! Gotcha (New York: W. H. Freeman, 1978, 1982).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 61

Table 2.3.1 Valid Argument Forms

Modus Ponens p → q Elimination a. p ∨ q b. p ∨ q p ∼q ∼p

∴ q ∴ p ∴ q Modus Tollens p → q Transitivity p → q

∼q q → r ∴ ∼p ∴ p → r

Generalization a. p b. q Proof by p ∨ q ∴ p ∨ q ∴ p ∨ q Division into Cases p → r

Specialization a. p ∧ q b. p ∧ q q → r ∴ p ∴ q ∴ r

Conjunction p Contradiction Rule ∼p → c q ∴ p

∴ p ∧ q

Test Yourself 1. For an argument to be valid means that every argument of

the same form whose premises has a conclusion.

2. For an argument to be invalid means that there is an argument of the same form whose premises and whose conclu- sion .

3. For an argument to be sound means that it is and its premises . In this case we can be sure that its conclu- sion .

Exercise Set 2.3 Use modus ponens or modus tollens to fill in the blanks in the arguments of 1–5 so as to produce valid inferences.

1. If √

2 is rational, then √

2 = a/b for some integers a and b. It is not true that

√ 2 = a/b for some integers a and b.

∴ . 2. If 1− 0.99999 . . . is less than every positive real number,

then it equals zero. .

∴ The number 1− 0.99999 . . . equals zero. 3. If logic is easy, then I am a monkey’s uncle.

I am not a monkey’s uncle. ∴ .

4. If this figure is a quadrilateral, then the sum of its interior angles is 360◦. The sum of the interior angles of this figure is not 360◦.

∴ .

5. If they were unsure of the address, then they would have telephoned.

. ∴ They were sure of the address.

Use truth tables to determine whether the argument forms in 6– 11 are valid. Indicate which columns represent the premises and which represent the conclusion, and include a sentence explain- ing how the truth table supports your answer. Your explanation should show that you understand what it means for a form of argument to be valid or invalid.

6. p → q q → p

∴ p ∨ q

7. p p → q ∼q ∨ r

∴ r

8. p ∨ q p →∼q p → r

∴ r

9. p ∧ q →∼r p ∨ ∼q ∼q → p

∴ ∼r

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

62 Chapter 2 The Logic of Compound Statements

10. p → r q → r

∴ p ∨ q → r

11. p → q ∨ r ∼q ∨ ∼r

∴ ∼p ∨ ∼r 12. Use truth tables to show that the following forms of argu-

ment are invalid. a. p → q

q ∴ p

(converse error)

b. p → q ∼p

∴ ∼q (inverse error)

Use truth tables to show that the argument forms referred to in 13–21 are valid. Indicate which columns represent the premises and which represent the conclusion, and include a sen- tence explaining how the truth table supports your answer. Your explanation should show that you understand what it means for a form of argument to be valid.

13. Modus tollens: p → q ∼q

∴ ∼p 14. Example 2.3.3(a) 15. Example 2.3.3(b)

16. Example 2.3.4(a) 17. Example 2.3.4(b)

18. Example 2.3.5(a) 19. Example 2.3.5(b)

20. Example 2.3.6 21. Example 2.3.7

Use symbols to write the logical form of each argument in 22 and 23, and then use a truth table to test the argument for valid- ity. Indicate which columns represent the premises and which represent the conclusion, and include a few words of explana- tion showing that you understand the meaning of validity.

22. If Tom is not on team A, then Hua is on team B. If Hua is not on team B, then Tom is on team A.

∴ Tom is not on team A or Hua is not on team B. 23. Oleg is a math major or Oleg is an economics major.

If Oleg is a math major, then Oleg is required to take Math 362.

∴ Oleg is an economics major or Oleg is not required to take Math 362.

Some of the arguments in 24–32 are valid, whereas others exhibit the converse or the inverse error. Use symbols to write the logical form of each argument. If the argument is valid, iden- tify the rule of inference that guarantees its validity. Otherwise, state whether the converse or the inverse error is made.

24. If Jules solved this problem correctly, then Jules obtained the answer 2. Jules obtained the answer 2.

∴ Jules solved this problem correctly. 25. This real number is rational or it is irrational.

This real number is not rational. ∴ This real number is irrational.

26. If I go to the movies, I won’t finish my homework. If I don’t finish my homework, I won’t do well on the

exam tomorrow. ∴ If I go to the movies, I won’t do well on the exam

tomorrow.

27. If this number is larger than 2, then its square is larger than 4. This number is not larger than 2.

∴ The square of this number is not larger than 4. 28. If there are as many rational numbers as there are

irrational numbers, then the set of all irrational numbers is infinite. The set of all irrational numbers is infinite.

∴ There are as many rational numbers as there are irrational numbers.

29. If at least one of these two numbers is divisible by 6, then the product of these two numbers is divisible by 6. Neither of these two numbers is divisible by 6.

∴ The product of these two numbers is not divisible by 6. 30. If this computer program is correct, then it produces the

correct output when run with the test data my teacher gave me. This computer program produces the correct output when run with the test data my teacher gave me. ∴ This computer program is correct.

31. Sandra knows Java and Sandra knows C++. ∴ Sandra knows C++.

32. If I get a Christmas bonus, I’ll buy a stereo. If I sell my motorcycle, I’ll buy a stereo.

∴ If I get a Christmas bonus or I sell my motorcycle, then I’ll buy a stereo.

33. Give an example (other than Example 2.3.11) of a valid argument with a false conclusion.

34. Give an example (other than Example 2.3.12) of an invalid argument with a true conclusion.

35. Explain in your own words what distinguishes a valid form of argument from an invalid one.

36. Given the following information about a computer pro- gram, find the mistake in the program. a. There is an undeclared variable or there is a syntax error

in the first five lines. b. If there is a syntax error in the first five lines, then there

is a missing semicolon or a variable name is misspelled. c. There is not a missing semicolon. d. There is not a misspelled variable name.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Valid and Invalid Arguments 63

37. In the back of an old cupboard you discover a note signed by a pirate famous for his bizarre sense of humor and love of logical puzzles. In the note he wrote that he had hidden treasure somewhere on the property. He listed five true statements (a–e below) and challenged the reader to use them to figure out the location of the treasure. a. If this house is next to a lake, then the treasure is not in

the kitchen. b. If the tree in the front yard is an elm, then the treasure is

in the kitchen. c. This house is next to a lake. d. The tree in the front yard is an elm or the treasure is

buried under the flagpole. e. If the tree in the back yard is an oak, then the treasure is

in the garage. Where is the treasure hidden?

38. You are visiting the island described in Example 2.3.14 and have the following encounters with natives. a. Two natives A and B address you as follows:

A says: Both of us are knights. B says: A is a knave. What are A and B?

b. Another two natives C and D approach you but only C speaks. C says: Both of us are knaves. What are C and D?

c. You then encounter natives E and F . E says: F is a knave. F says: E is a knave. How many knaves are there?

d.H Finally, you meet a group of six natives, U, V, W, X, Y , and Z , who speak to you as follows: U says: None of us is a knight. V says: At least three of us are knights. W says: At most three of us are knights. X says: Exactly five of us are knights. Y says: Exactly two of us are knights. Z says: Exactly one of us is a knight. Which are knights and which are knaves?

39. The famous detective Percule Hoirot was called in to solve a baffling murder mystery. He determined the following facts: a. Lord Hazelton, the murdered man, was killed by a blow

on the head with a brass candlestick. b. Either Lady Hazelton or a maid, Sara, was in the dining

room at the time of the murder.

c. If the cook was in the kitchen at the time of the murder, then the butler killed Lord Hazelton with a fatal dose of strychnine.

d. If Lady Hazelton was in the dining room at the time of the murder, then the chauffeur killed Lord Hazelton.

e. If the cook was not in the kitchen at the time of the mur- der, then Sara was not in the dining room when the mur- der was committed.

f. If Sara was in the dining room at the time the murder was committed, then the wine steward killed Lord Hazelton.

Is it possible for the detective to deduce the identity of the murderer from these facts? If so, who did murder Lord Hazelton? (Assume there was only one cause of death.)

40. Sharky, a leader of the underworld, was killed by one of his own band of four henchmen. Detective Sharp interviewed the men and determined that all were lying except for one. He deduced who killed Sharky on the basis of the following statements: a. Socko: Lefty killed Sharky. b. Fats: Muscles didn’t kill Sharky. c. Lefty: Muscles was shooting craps with Socko when

Sharky was knocked off. d. Muscles: Lefty didn’t kill Sharky. Who did kill Sharky?

In 41–44 a set of premises and a conclusion are given. Use the valid argument forms listed in Table 2.3.1 to deduce the con- clusion from the premises, giving a reason for each step as in Example 2.3.8. Assume all variables are statement variables.

41. a. ∼p ∨ q → r b. s ∨ ∼q c. ∼t d. p → t e. ∼p ∧ r →∼s f. ∴ ∼q

42. a. p ∨ q b. q → r c. p ∧ s → t d. ∼r e. ∼q → u ∧ s f. ∴ t

43. a. ∼p → r ∧ ∼s b. t → s c. u →∼p d. ∼w e. u ∨ w f. ∴ ∼t

44. a. p → q b. r ∨ s c. ∼s →∼t d. ∼q ∨ s e. ∼s f. ∼p ∧ r → u g. w ∨ t h. ∴ u ∧ w

Answers for Test Yourself 1. are all true; true 2. are all true; is false 3. valid; are all true; is true

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

64 Chapter 2 The Logic of Compound Statements

2.4 Application: Digital Logic Circuits Only connect! — E. M. Forster, Howards End

In the late 1930s, a young M.I.T. graduate student named Claude Shannon noticed an M

IT M

us eu

m

Claude Shannon (1916–2001)

analogy between the operations of switching devices, such as telephone switching circuits, and the operations of logical connectives. He used this analogy with striking success to solve problems of circuit design and wrote up his results in his master’s thesis, which was published in 1938.

The drawing in Figure 2.4.1(a) shows the appearance of the two positions of a simple switch. When the switch is closed, current can flow from one terminal to the other; when it is open, current cannot flow. Imagine that such a switch is part of the circuit shown in Figure 2.4.1(b). The light bulb turns on if, and only if, current flows through it. And this happens if, and only if, the switch is closed.

Open Closed

The symbol denotes a battery and the symbol

denotes a light bulb.

(a) (b)

Figure 2.4.1

Now consider the more complicated circuits of Figures 2.4.2(a) and 2.4.2(b).

P Q Q

P

Switches “in series” Switches “in parallel”

(a) (b)

Figure 2.4.2

In the circuit of Figure 2.4.2(a) current flows and the light bulb turns on if, and only if, both switches P and Q are closed. The switches in this circuit are said to be in series. In the circuit of Figure 2.4.2(b) current flows and the light bulb turns on if, and only if, at least one of the switches P or Q is closed. The switches in this circuit are said to be in parallel. All possible behaviors of these circuits are described by Table 2.4.1.

Table 2.4.1

(a) Switches in Series (b) Switches in Parallel

Switches Light Bulb

P Q State

closed closed on

closed open off

open closed off

open open off

Switches Light Bulb

P Q State

closed closed on

closed open on

open closed on

open open off

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 65

Observe that if the words closed and on are replaced by T and open and off are replaced by F, Table 2.4.1(a) becomes the truth table for and and Table 2.4.1(b) becomes the truth table for or. Consequently, the switching circuit of Figure 2.4.2(a) is said to cor- respond to the logical expression P ∧ Q, and that of Figure 2.4.2(b) is said to correspond to P ∨ Q.

More complicated circuits correspond to more complicated logical expressions. This correspondence has been used extensively in the design and study of circuits.

In the 1940s and 1950s, switches were replaced by electronic devices, with the physical states of closed and open corresponding to electronic states such as high and low voltages. The new electronic technology led to the development of modern digi- tal systems such as electronic computers, electronic telephone switching systems, traffic light controls, electronic calculators, and the control mechanisms used in hundreds of other types of electronic equipment. The basic electronic components of a digital system are called digital logic circuits. The word logic indicates the important role of logic in the design of such circuits, and the word digital indicates that the circuits process discrete, or separate, signals as opposed to continuous ones.

Co ur

te sy

of IB

M

John W. Tukey (1915–2000)

The Intel 4004, introduced in 1971, is generally considered to be the first commercially viable microprocessor or central pro- cessing unit (CPU) contained on a chip about the size of a fingernail. It consisted of 2,300 transistors and could execute 70,000 instructions per second, essentially the same computing power as the first electronic computer, the ENIAC, built in 1946, which filled an entire room. Modern microprocessors consist of several CPUs on one chip, contain close to a billion transistors and many hundreds of millions of logic circuits, and can compute hundreds of millions of instructions per second. In

te l

Electrical engineers continue to use the language of logic when they refer to values of signals produced by an electronic switch as being “true” or “false.” But they generally use the symbols 1 and 0 rather than T and F to denote these values. The symbols 0 and 1 are called bits, short for binary digits. This terminology was introduced in 1946 by the statistician John Tukey.

Black Boxes and Gates Combinations of signal bits (1’s and 0’s) can be transformed into other combinations of signal bits (1’s and 0’s) by means of various circuits. Because a variety of different

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

66 Chapter 2 The Logic of Compound Statements

technologies are used in circuit construction, computer engineers and digital system designers find it useful to think of certain basic circuits as black boxes. The inside of a black box contains the detailed implementation of the circuit and is often ignored while attention is focused on the relation between the input and the output signals.

P Q R

S Input

signals Output signalblack box

The operation of a black box is completely specified by constructing an input/output table that lists all its possible input signals together with their corresponding output signals. For example, the black box pictured above has three input signals. Since each of these signals can take the value 1 or 0, there are eight possible combinations of input signals. One possible correspondence of input to output signals is as follows:

An Input/Output Table

Input Output

P Q R S

1 1 1 1

1 1 0 0

1 0 1 0

1 0 0 1

0 1 1 0

0 1 0 1

0 0 1 1

0 0 0 0

The third row, for instance, indicates that for inputs P = 1, Q = 0, and R = 1, the output S is 0.

An efficient method for designing more complicated circuits is to build them by con- necting less complicated black box circuits. Three such circuits are known as NOT-, AND-, and OR-gates.

A NOT-gate (or inverter) is a circuit with one input signal and one output signal. If the input signal is 1, the output signal is 0. Conversely, if the input signal is 0, then the output signal is 1. An AND-gate is a circuit with two input signals and one output signal. If both input signals are 1, then the output signal is 1. Otherwise, the output signal is 0. An OR-gate also has two input signals and one output signal. If both input signals are 0, then the output signal is 0. Otherwise, the output signal is 1.

The actions of NOT-, AND-, and OR-gates are summarized in Figure 2.4.3, where P and Q represent input signals and R represents the output signal. It should be clear from Figure 2.4.3 that the actions of the NOT-, AND-, and OR-gates on signals correspond exactly to those of the logical connectives ∼,∧, and ∨ on statements, if the symbol 1 is identified with T and the symbol 0 is identified with F.

Gates can be combined into circuits in a variety of ways. If the rules shown on the next page are obeyed, the result is a combinational circuit, one whose output at any time is determined entirely by its input at that time without regard to previous inputs.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 67

Type of Symbolic Gate Representation Action

NOT P RNOT

Input Output

P R

1 0

0 1

AND P

Q RAND

Input Output

P Q R

1 1 1

1 0 0

0 1 0

0 0 0

OR P

Q ROR

Input Output

P Q R

1 1 1

1 0 1

0 1 1

0 0 0

Figure 2.4.3

Rules for a Combinational Circuit

Never combine two input wires. 2.4.1

A single input wire can be split partway and used as input for two separate gates. 2.4.2

An output wire can be used as input. 2.4.3

No output of a gate can eventually feed back into that gate. 2.4.4

Rule (2.4.4) is violated in more complex circuits, called sequential circuits, whose output at any given time depends both on the input at that time and also on previous inputs. These circuits are discussed in Section 12.2.

The Input/Output Table for a Circuit If you are given a set of input signals for a circuit, you can find its output by tracing through the circuit gate by gate.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

68 Chapter 2 The Logic of Compound Statements

Example 2.4.1 Determining Output for a Given Input

Indicate the output of the circuits shown below for the given input signals.

a.

P

Q

RAND NOT

Input signals: P = 0 and Q = 1

b.

P

Q

R SAND

OR NOT

Input signals: P = 1, Q = 0, R = 1

Solution

a. Move from left to right through the diagram, tracing the action of each gate on the input signals. The NOT-gate changes P = 0 to a 1, so both inputs to the AND-gate are 1; hence the output R is 1. This is illustrated by annotating the diagram as shown below.

P

Q

NOT RAND

0 1 1

1

b. The output of the OR-gate is 1 since one of the input signals, P , is 1. The NOT-gate changes this 1 into a 0, so the two inputs to the AND-gate are 0 and R = 1. Hence the output S is 0. The trace is shown below.

P

Q

R SAND

OR NOT

1

1

1 0

0

0

To construct the entire input/output table for a circuit, trace through the circuit to find the corresponding output signals for each possible combination of input signals.

Example 2.4.2 Constructing the Input/Output Table for a Circuit

Construct the input/output table for the following circuit.

P

Q

ROR

NOT

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 69

Solution List the four possible combinations of input signals, and find the output for each by tracing through the circuit.

CO R

B IS

George Boole (1815–1864)

Input Output

P Q R

1 1 1

1 0 1

0 1 0

0 0 1 ■

The Boolean Expression Corresponding to a Circuit In logic, variables such as p, q and r represent statements, and a statement can have one of only two truth values: T (true) or F (false). A statement form is an expression, such as p ∧ (∼q ∨ r), composed of statement variables and logical connectives.

As noted earlier, one of the founders of symbolic logic was the English mathemati- cian George Boole. In his honor, any variable, such as a statement variable or an input signal, that can take one of only two values is called a Boolean variable. An expres- sion composed of Boolean variables and the connectives ∼,∧, and ∨ is called a Boolean expression.

Note Strictly speaking, only meaningful expressions such as (∼p ∧ q) ∨ (p ∧ r) and ∼(∼(p ∧ q) ∨ r) are allowed as Boolean, not meaningless ones like p ∼q((rs ∨ ∧ q ∼. We use recursion to give a careful definition of Boolean expressions in Section 5.9.

Given a circuit consisting of combined NOT-, AND-, and OR-gates, a correspond- ing Boolean expression can be obtained by tracing the actions of the gates on the input variables.

Example 2.4.3 Finding a Boolean Expression for a Circuit

Find the Boolean expressions that correspond to the circuits shown below. A dot indicates a soldering of two wires; wires that cross without a dot are assumed not to touch.

P

Q

R

P

Q AND OR

NOTAND NOT

AND

(a) (b)

AND

Solution

a. Trace through the circuit from left to right, indicating the output of each gate symbol- ically, as shown below.

P

Q

P ∧ Q

P ∨ Q

~(P ∧ Q)

(P ∨ Q) ∧ ~(P ∧ Q)

NOT

AND

AND

OR

The final expression obtained, (P ∨ Q)∧ ∼(P ∧ Q), is the expression for exclusive or: P or Q but not both.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

70 Chapter 2 The Logic of Compound Statements

b. The Boolean expression corresponding to the circuit is (P ∧ Q)∧ ∼R, as shown below.

P

Q

R

P ∧ Q

~R (P ∧ Q) ∧~RAND

AND

NOT

Observe that the output of the circuit shown in Example 2.4.3(b) is 1 for exactly one combination of inputs (P = 1, Q = 1, and R = 0) and is 0 for all other combinations of inputs. For this reason, the circuit can be said to “recognize” one particular combination of inputs. The output column of the input/output table has a 1 in exactly one row and 0’s in all other rows.

• Definition A recognizer is a circuit that outputs a 1 for exactly one particular combination of input signals and outputs 0’s for all other combinations.

Input/Output Table for a Recognizer

P Q R (P ∧ Q)∧ ∼R 1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 0

0 1 0 0

0 0 1 0

0 0 0 0

The Circuit Corresponding to a Boolean Expression The preceding examples showed how to find a Boolean expression corresponding to a cir- cuit. The following example shows how to construct a circuit corresponding to a Boolean expression.

Example 2.4.4 Constructing Circuits for Boolean Expressions

Construct circuits for the following Boolean expressions.

a. (∼P ∧ Q)∨ ∼Q b. ((P ∧ Q) ∧ (R ∧ S)) ∧ T Solution

a. Write the input variables in a column on the left side of the diagram. Then go from the right side of the diagram to the left, working from the outermost part of the expression to the innermost part. Since the last operation executed when evaluating (∼P ∧ Q)∨ ∼Q is ∨, put an OR-gate at the extreme right of the diagram. One input to this gate is ∼P ∧ Q, so draw an AND-gate to the left of the OR-gate and show its

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 71

output coming into the OR-gate. Since one input to the AND-gate is ∼P , draw a line from P to a NOT-gate and from there to the AND-gate. Since the other input to the AND-gate is Q, draw a line from Q directly to the AND-gate. The other input to the OR-gate is ∼Q, so draw a line from Q to a NOT-gate and from the NOT-gate to the OR-gate. The circuit you obtain is shown below.

P

Q AND

NOT

OR

NOT

b. To start constructing this circuit, put one AND-gate at the extreme right for the ∧ between ((P ∧ Q) ∧ (R ∧ S)) and T . To the left of that put the AND-gate corre- sponding to the ∧ between P ∧ Q and R ∧ S. To the left of that put the AND-gates corresponding to the ∧’s between P and Q and between R and S. The circuit is shown in Figure 2.4.4.

P

Q

R

S

T

AND AND

AND

AND

Figure 2.4.4 ■

It follows from Theorem 2.1.1 that all the ways of adding parentheses to P ∧ Q ∧ R ∧ S ∧ T are logically equivalent. Thus, for example,

((P ∧ Q) ∧ (R ∧ S)) ∧ T ≡ (P ∧ (Q ∧ R)) ∧ (S ∧ T ).

It also follows that the circuit in Figure 2.4.5, which corresponds to (P ∧ (Q ∧ R)) ∧ (S ∧ T ), has the same input/output table as the circuit in Figure 2.4.4, which corresponds to ((P ∧ Q) ∧ (R ∧ S)) ∧ T .

P

Q

R

S

T

AND AND AND

AND

Figure 2.4.5

Each of the circuits in Figures 2.4.4 and 2.4.5 is, therefore, an implementation of the expression P ∧ Q ∧ R ∧ S ∧ T . Such a circuit is called a multiple-input AND-gate and is represented by the diagram shown in Figure 2.4.6. Multiple-input OR-gates are constructed similarly.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

72 Chapter 2 The Logic of Compound Statements

P

Q

R

S

T

AND

Figure 2.4.6

Finding a Circuit That Corresponds to a Given Input/Output Table

To this point, we have discussed how to construct the input/output table for a circuit, how to find the Boolean expression corresponding to a given circuit, and how to construct the circuit corresponding to a given Boolean expression. Now we address the question of how to design a circuit (or find a Boolean expression) corresponding to a given input/output table. The way to do this is to put several recognizers together in parallel.

Example 2.4.5 Designing a Circuit for a Given Input/Output Table

Design a circuit for the following input/output table:

Input Output

P Q R S

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 1

0 1 1 0

0 1 0 0

0 0 1 0

0 0 0 0

Solution First construct a Boolean expression with this table as its truth table. To do this, identify each row for which the output is 1—in this case, the first, third, and fourth rows. For each such row, construct an and expression that produces a 1 (or true) for the exact combination of input values for that row and a 0 (or false) for all other combinations of input values. For example, the expression for the first row is P ∧ Q ∧ R because P ∧ Q ∧ R is 1 if P = 1 and Q = 1 and R = 1, and it is 0 for all other values of P, Q, and R. The expression for the third row is P ∧ ∼Q ∧ R because P ∧ ∼Q ∧ R is 1 if P = 1 and Q = 0 and R = 1, and it is 0 for all other values of P, Q, and R. Similarly, the expression for the fourth row is P ∧ ∼Q ∧ ∼R.

Now any Boolean expression with the given table as its truth table has the value 1 in case P ∧ Q ∧ R = 1, or in case P ∧ ∼Q ∧ R = 1, or in case P ∧ ∼Q ∧ ∼R = 1, and in no other cases. It follows that a Boolean expression with the given truth table is

(P ∧ Q ∧ R) ∨ (P ∧ ∼Q ∧ R) ∨ (P ∧ ∼Q ∧ ∼R). 2.4.5 The circuit corresponding to this expression has the diagram shown in Figure 2.4.7. Observe that expression (2.4.5) is a disjunction of terms that are themselves conjunc- tions in which one of P or ∼P , one of Q or ∼Q, and one of R or ∼R all appear. Such expressions are said to be in disjunctive normal form or sum-of-products form.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 73

AND P Q R

AND

NOT

NOT

ANDNOT

OR

Figure 2.4.7 ■

Simplifying Combinational Circuits Consider the two combinational circuits shown in Figure 2.4.8.

R

AND P

Q NOT OR

AND

AND

R

P

Q

(a)

(b)

AND

Figure 2.4.8

If you trace through circuit (a), you will find that its input/output table is

Input Output

P Q R

1 1 1

1 0 0

0 1 0

0 0 0

which is the same as the input/output table for circuit (b). Thus these two circuits do the same job in the sense that they transform the same combinations of input signals

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

74 Chapter 2 The Logic of Compound Statements

into the same output signals. Yet circuit (b) is simpler than circuit (a) in that it contains many fewer logic gates. Thus, as part of an integrated circuit, it would take less space and require less power.

• Definition Two digital logic circuits are equivalent if, and only if, their input/output tables are identical.

Since logically equivalent statement forms have identical truth tables, you can determine that two circuits are equivalent by finding the Boolean expressions corresponding to the circuits and showing that these expressions, regarded as statement forms, are logically equivalent. Example 2.4.6 shows how this procedure works for cir- cuits (a) and (b) in Figure 2.4.8.

Example 2.4.6 Showing That Two Circuits Are Equivalent

Find the Boolean expressions for each circuit in Figure 2.4.8. Use Theorem 2.1.1 to show that these expressions are logically equivalent when regarded as statement forms.

Solution The Boolean expressions that correspond to circuits (a) and (b) are ((P ∧ ∼Q) ∨ (P ∧ Q)) ∧ Q and P ∧ Q, respectively. By Theorem 2.1.1,

((P ∧ ∼Q) ∨ (P ∧ Q)) ∧ Q ≡ (P ∧ (∼Q ∨ Q)) ∧ Q by the distributive law ≡ (P ∧ (Q ∨ ∼Q)) ∧ Q by the commutative law for ∨ ≡ (P ∧ t) ∧ Q by the negation law ≡ P ∧ Q by the identity law.

It follows that the truth tables for ((P ∧ ∼Q) ∨ (P ∧ Q)) ∧ Q and P ∧ Q are the same. Hence the input/output tables for the circuits corresponding to these expressions are also the same, and so the circuits are equivalent. ■

In general, you can simplify a combinational circuit by finding the corresponding Boolean expression, using the properties listed in Theorem 2.1.1 to find a Boolean expres- sion that is shorter and logically equivalent to it (when both are regarded as statement forms), and constructing the circuit corresponding to this shorter Boolean expression.

NAND and NOR Gates Another way to simplify a circuit is to find an equivalent circuit that uses the least number of different kinds of logic gates. Two gates not previously introduced are particularly

H ar

va rd

U ni

ve rs

ity Ar

ch iv

es

H. M. Sheffer (1882–1964)

useful for this: NAND-gates and NOR-gates. A NAND-gate is a single gate that acts like an AND-gate followed by a NOT-gate. A NOR-gate acts like an OR-gate followed by a NOT-gate. Thus the output signal of a NAND-gate is 0 when, and only when, both input signals are 1, and the output signal for a NOR-gate is 1 when, and only when, both input signals are 0. The logical symbols corresponding to these gates are | (for NAND) and ↓ (for NOR), where | is called a Sheffer stroke (after H. M. Sheffer, 1882–1964) and ↓ is called a Peirce arrow (after C. S. Peirce, 1839–1914; see page 101). Thus

P | Q ≡ ∼(P ∧ Q) and P ↓ Q ≡ ∼(P ∨ Q).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 75

The table below summarizes the actions of NAND and NOR gates.

Type of Gate Symbolic Representation Action

NAND P

Q NAND R

Input Output

P Q R = P | Q 1 1 0

1 0 1

0 1 1

0 0 1

NOR P

Q RNOR

Input Output

P Q R = P ↓ Q 1 1 0

1 0 0

0 1 0

0 0 1

It can be shown that any Boolean expression is equivalent to one written entirely with Sheffer strokes or entirely with Peirce arrows. Thus any digital logic circuit is equivalent to one that uses only NAND-gates or only NOR-gates. Example 2.4.7 develops part of the derivation of this result; the rest is left for the exercises.

Example 2.4.7 Rewriting Expressions Using the Sheffer Stroke

Use Theorem 2.1.1 and the definition of Sheffer stroke to show that

a. ∼P ≡ P | P and b. P ∨ Q ≡ (P | P) | (Q | Q). Solution

a. ∼P ≡ ∼(P ∧ P) by the idempotent law for ∧ ≡ P | P by definition of |.

b. P ∨ Q ≡ ∼(∼(P ∨ Q)) by the double negative law ≡ ∼(∼P ∧ ∼Q) by De Morgan’s laws ≡ ∼((P | P) ∧ (Q | Q)) by part (a) ≡ (P | P) | (Q | Q) by definition of |. ■

Test Yourself 1. The input/output table for a digital logic circuit is a table that

shows .

2. The Boolean expression that corresponds to a digital logic circuit is .

3. A recognizer is a digital logic circuit that .

4. Two digital logic circuits are equivalent if, and only if, .

5. A NAND-gate is constructed by placing a gate imme- diately following an gate.

6. A NOR-gate is constructed by placing a gate immedi- ately following an gate.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

76 Chapter 2 The Logic of Compound Statements

Exercise Set 2.4 Give the output signals for the circuits in 1–4 if the input signals are as indicated.

1. P

Q

ROR

NOT

input signals: P = 1 and Q = 1 2.

OR

NOT

P

RQ AND

input signals: P = 1 and Q = 0 3. P

Q

R

ORNOT AND

S

input signals: P = 1, Q = 0, R = 0 4. P

Q

R NOT

OR OR

AND

S

input signals: P = 0, Q = 0, R = 0

In 5–8, write an input/output table for the circuit in the refer- enced exercise.

5. Exercise 1 6. Exercise 2

7. Exercise 3 8. Exercise 4

In 9–12, find the Boolean expression that corresponds to the cir- cuit in the referenced exercise.

9. Exercise 1 10. Exercise 2

11. Exercise 3 12. Exercise 4

Construct circuits for the Boolean expressions in 13–17.

13. ∼P ∨ Q 14. ∼(P ∨ Q) 15. P ∨ (∼P ∧ ∼Q) 16. (P ∧ Q)∨ ∼R 17. (P ∧ ∼Q) ∨ (∼P ∧ R) For each of the tables in 18–21, construct (a) a Boolean expres- sion having the given table as its truth table and (b) a circuit having the given table as its input/output table.

18. P Q R S

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 1

0 1 0 0

0 0 1 0

0 0 0 0

19. P Q R S

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 1

0 1 1 0

0 1 0 1

0 0 1 0

0 0 0 0

20. P Q R S

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 0

0 1 1 0

0 1 0 0

0 0 1 0

0 0 0 1

21. P Q R S

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 1

0 1 0 1

0 0 1 0

0 0 0 0

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Application: Digital Logic Circuits 77

22. Design a circuit to take input signals P, Q, and R and out- put a 1 if, and only if, P and Q have the same value and Q and R have opposite values.

23. Design a circuit to take input signals P , Q, and R and out- put a 1 if, and only if, all three of P, Q, and R have the same value.

24. The lights in a classroom are controlled by two switches: one at the back and one at the front of the room. Moving either switch to the opposite position turns the lights off if they are on and on if they are off. Assume the lights have been installed so that when both switches are in the down position, the lights are off. Design a circuit to control the switches.

25. An alarm system has three different control panels in three different locations. To enable the system, switches in at least two of the panels must be in the on position. If fewer than two are in the on position, the system is disabled. Design a circuit to control the switches.

Use the properties listed in Theorem 2.1.1 to show that each pair of circuits in 26–29 have the same input/output table. (Find the Boolean expressions for the circuits and show that they are logically equivalent when regarded as statement forms.)

26. a. P

Q OR AND

b. P

Q OR

AND

27. a. P

Q

AND

AND

NOT

NOT

b. P

Q NOTOR

28. a. P

Q

NOT

NOT

NOT

AND

AND

AND

OR

b. P

Q NOT OR

29. a. P

Q AND

AND OR NOT

AND NOT

b. P

Q OR

For the circuits corresponding to the Boolean expressions in each of 30 and 31 there is an equivalent circuit with at most two logic gates. Find such a circuit.

30. (P ∧ Q) ∨ (∼P ∧ Q) ∨ (∼P ∧ ∼Q) 31. (∼P ∧ ∼Q) ∨ (∼P ∧ Q) ∨ (P ∧ ∼Q) 32. The Boolean expression for the circuit in Example 2.4.5 is

(P ∧ Q ∧ R) ∨ (P ∧ ∼Q ∧ R) ∨ (P ∧ ∼Q ∧ ∼R) (a disjunctive normal form). Find a circuit with at most three logic gates that is equivalent to this circuit.

33. a. Show that for the Sheffer stroke |, P ∧ Q ≡ (P | Q) | (P | Q).

b. Use the results of Example 2.4.7 and part (a) above to write P ∧ (∼Q ∨ R) using only Sheffer strokes.

34. Show that the following logical equivalences hold for the Peirce arrow ↓, where P ↓ Q ≡ ∼(P ∨ Q). a. ∼P ≡ P ↓ P b. P ∨ Q ≡ (P ↓ Q) ↓ (P ↓ Q) c. P ∧ Q ≡ (P ↓ P) ↓ (Q ↓ Q) d.H Write P → Q using Peirce arrows only. e. Write P ↔ Q using Peirce arrows only.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

78 Chapter 2 The Logic of Compound Statements

Answers for Test Yourself 1. the output signal(s) that correspond to all possible combinations of input signals to the circuit 2. a Boolean expression that represents the input signals as variables and indicates the successive actions of the logic gates on the input signals 3. outputs a 1 for exactly one particular combination of input signals and outputs 0’s for all other combinations 4. they have the same input/output table 5. NOT; AND 6. NOT; OR

2.5 Application: Number Systems and Circuits for Addition Counting in binary is just like counting in decimal if you are all thumbs. — Glaser and Way

In elementary school, you learned the meaning of decimal notation: that to interpret a string of decimal digits as a number, you mentally multiply each digit by its place value. For instance, 5,049 has a 5 in the thousands place, a 0 in the hundreds place, a 4 in the tens place, and a 9 in the ones place. Thus

5,049 = 5 ·(1,000) + 0 ·(100) + 4 ·(10) + 9 ·(1). Using exponential notation, this equation can be rewritten as

5,049 = 5 ·103 + 0 ·102 + 4 ·101 + 9 ·100. More generally, decimal notation is based on the fact that any positive integer can be written uniquely as a sum of products of the form

d ·10n, where each n is a nonnegative integer and each d is one of the decimal digits 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. The word decimal comes from the Latin root deci, meaning “ten.” Decimal (or base 10) notation expresses a number as a string of digits in which each digit’s position indicates the power of 10 by which it is multiplied. The right-most position is the ones place (or 100 place), to the left of that is the tens place (or 101 place), to the left of that is the hundreds place (or 102 place), and so forth, as illustrated below.

Place 103 102 101 100

thousands hundreds tens ones

Decimal Digit 5 0 4 9

Binary Representation of Numbers There is nothing sacred about the number 10; we use 10 as a base for our usual number system because we happen to have ten fingers. In fact, any integer greater than 1 can serve as a base for a number system. In computer science, base 2 notation, or binary notation, is of special importance because the signals used in modern electronics are always in one of only two states. (The Latin root bi means “two.”)

In Section 5.4, we show that any integer can be represented uniquely as a sum of products of the form

d ·2n, where each n is an integer and each d is one of the binary digits (or bits) 0 or 1. For example,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 79

27 = 16 + 8 + 2 + 1 = 1 ·24 + 1 ·23 + 0 ·22 + 1 ·21 + 1 ·20.

In binary notation, as in decimal notation, we write just the binary digits, and not the powers of the base. In binary notation, then,

1

· 24 + 1 →

· 23 + 0 →

· 22 + 1 →

· 21 + 1 →

· 20

2710 = 1 1 0 1 1 2

where the subscripts indicate the base, whether 10 or 2, in which the number is written. The places in binary notation correspond to the various powers of 2. The right-most position is the ones place (or 20 place), to the left of that is the twos place (or 21 place), to the left of that is the fours place (or 22 place), and so forth, as illustrated below.

Place 24 23 22 21 20

sixteens eights fours twos ones

Binary Digit 1 1 0 1 1

As in the decimal notation, leading zeros may be added or dropped as desired. For example,

00310 = 310 = 1 ·21 + 1 ·20 = 112 = 0112.

Example 2.5.1 Binary Notation for Integers from 1 to 9

Derive the binary notation for the integers from 1 to 9.

Solution 110 = 1 ·20 = 12 210 = 1 ·21 + 0 ·20 = 102 310 = 1 ·21 + 1 ·20 = 112 410 = 1 ·22 + 0 ·21 + 0 ·20 = 1002 510 = 1 ·22 + 0 ·21 + 1 ·20 = 1012 610 = 1 ·22 + 1 ·21 + 0 ·20 = 1102 710 = 1 ·22 + 1 ·21 + 1 ·20 = 1112 810 = 1 ·23 + 0 ·22 + 0 ·21 + 0 ·20 = 10002 910 = 1 ·23 + 0 ·22 + 0 ·21 + 1 ·20 = 10012 ■

A list of powers of 2 is useful for doing binary-to-decimal and decimal-to-binary conversions. See Table 2.5.1.

Table 2.5.1 Powers of 2

Power of 2 210 29 28 27 26 25 24 23 22 21 20

Decimal Form 1024 512 256 128 64 32 16 8 4 2 1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

80 Chapter 2 The Logic of Compound Statements

Example 2.5.2 Converting a Binary to a Decimal Number

Represent 1101012 in decimal notation.

Solution 1101012 = 1 ·25 + 1 ·24 + 0 ·23 + 1 ·22 + 0 ·21 + 1 ·20 = 32 + 16 + 4 + 1 = 5310

Alternatively, the schema below may be used.

2 5 =

32

2 4 =

16

2 3 =

8

2 2 =

4

2 1 =

2

2 0 =

1

1

1

0

1

0

12 → 1 ·1 = 1

0 ·2 = 0 1 ·4 = 4 0 ·8 = 0

1 ·16 = 16 1 ·32 = 32

5310 ■

Example 2.5.3 Converting a Decimal to a Binary Number

Represent 209 in binary notation.

Solution Use Table 2.5.1 to write 209 as a sum of powers of 2, starting with the highest power of 2 that is less than 209 and continuing to lower powers.

Since 209 is between 128 and 256, the highest power of 2 that is less than 209 is 128. Hence

20910 = 128 + a smaller number. Now 209− 128 = 81, and 81 is between 64 and 128, so the highest power of 2 that is less than 81 is 64. Hence

20910 = 128 + 64 + a smaller number. Continuing in this way, you obtain

20910 = 128 + 64 + 16 + 1 = 1 ·27 + 1 ·26 + 0 ·25 + 1 ·24 + 0 ·23 + 0 ·22 + 0 ·21 + 1 ·20.

For each power of 2 that occurs in the sum, there is a 1 in the corresponding position of the binary number. For each power of 2 that is missing from the sum, there is a 0 in the corresponding position of the binary number. Thus

20910 = 110100012 ■

Another procedure for converting from decimal to binary notation is discussed in Section 5.1.

! Caution! Do not read 102 as “ten”; it is the number two. Read 102 as “one oh base two.”

Binary Addition and Subtraction The computational methods of binary arithmetic are analogous to those of decimal arith- metic. In binary arithmetic the number 2 (= 102 in binary notation) plays a role similar to that of the number 10 in decimal arithmetic.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 81

Example 2.5.4 Addition in Binary Notation

Add 11012 and 1112 using binary notation.

Solution Because 210 = 102 and 110 = 12, the translation of 110 + 110 = 210 to binary notation is

12 + 12

102

It follows that adding two 1’s together results in a carry of 1 when binary notation is used. Adding three 1’s together also results in a carry of 1 since 310 = 112 (“one one base two”).

12 + 12 + 12

112

Thus the addition can be performed as follows:

1 1 1 ← carry row 1 1 0 12

+ 1 1 12 1 0 1 0 02 ■

Example 2.5.5 Subtraction in Binary Notation

Subtract 10112 from 110002 using binary notation.

Solution In decimal subtraction the fact that 1010 − 110 = 910 is used to borrow across several columns. For example, consider the following:

9 9 1 1 ← borrow row

1 0 0 010 − 5 810

9 4 210

In binary subtraction it may also be necessary to borrow across more than one column. But when you borrow a 12 from 102, what remains is 12.

102 − 12

12

Thus the subtraction can be performed as follows:

0 1 1 1 1 1 ← borrow row

1 1 0 0 02 − 1 0 1 12

1 1 0 12 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

82 Chapter 2 The Logic of Compound Statements

Circuits for Computer Addition Consider the question of designing a circuit to produce the sum of two binary digits P and Q. Both P and Q can be either 0 or 1. And the following facts are known:

12 + 12 = 102, 12 + 02 = 12 = 012, 02 + 12 = 12 = 012, 02 + 02 = 02 = 002.

It follows that the circuit to be designed must have two outputs—one for the left binary digit (this is called the carry) and one for the right binary digit (this is called the sum). The carry output is 1 if both P and Q are 1; it is 0 otherwise. Thus the carry can be produced using the AND-gate circuit that corresponds to the Boolean expression P ∧ Q. The sum output is 1 if either P or Q, but not both, is 1. The sum can, therefore, be produced using a circuit that corresponds to the Boolean expression for exclusive or: (P ∨ Q)∧ ∼(P ∧ Q). (See Example 2.4.3(a).) Hence, a circuit to add two binary digits P and Q can be constructed as in Figure 2.5.1. This circuit is called a half-adder.

HALF-ADDER

Circuit Input/Output Table

P

Q NOT

AND

AND

OR Sum

Carry

P Q Carry Sum

1 1 1 0

1 0 0 1

0 1 0 1

0 0 0 0

Figure 2.5.1 Circuit to Add P + Q, Where P and Q Are Binary Digits

Now consider the question of how to construct a circuit to add two binary integers, each with more than one digit. Because the addition of two binary digits may result in a carry to the next column to the left, it may be necessary to add three binary digits at certain points. In the following example, the sum in the right column is the sum of two binary digits, and, because of the carry, the sum in the left column is the sum of three binary digits.

1 ← carry row 1 12

+ 1 12 1 1 02

Thus, in order to construct a circuit that will add multidigit binary numbers, it is necessary to incorporate a circuit that will compute the sum of three binary digits. Such a circuit is called a full-adder. Consider a general addition of three binary digits P, Q, and R that results in a carry (or left-most digit) C and a sum (or right-most digit) S.

P + Q + R

C S

The operation of the full-adder is based on the fact that addition is a binary operation: Only two numbers can be added at one time. Thus P is first added to Q and then the

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 83

result is added to R. For instance, consider the following addition:

12 + 02 + 12

102

} 12 + 02 = 012

⎫ ⎬

⎭ 12 + 12 = 102

The process illustrated here can be broken down into steps that use half-adder circuits.

Step 1: Add P and Q using a half-adder to obtain a binary number with two digits.

P + Q

C1S1

Step 2: Add R to the sum C1S1 of P and Q.

C1S1 + R

To do this, proceed as follows:

Step 2a: Add R to S1 using a half-adder to obtain the two-digit number C2S.

S1 + R

C2S

Then S is the right-most digit of the entire sum of P, Q, and R.

Step 2b: Determine the left-most digit, C , of the entire sum as follows: First note that it is impossible for both C1 and C2 to be 1’s. For if C1 = 1, then P and Q are both 1, and so S1 = 0. Consequently, the addition of S1 and R gives a binary number C2S1 where C2 = 0. Next observe that C will be a 1 in the case that the addition of P and Q gives a carry of 1 or in the case that the addition of S1 (the right-most digit of P + Q) and R gives a carry of 1. In other words, C = 1 if, and only if, C1 = 1 or C2 = 1. It follows that the circuit shown in Figure 2.5.2 will compute the sum of three binary digits.

FULL-ADDER Circuit Input/Output Table

half-adder #1

half-adder #2

AND P

Q

R

S

T

C1

C2

S1

P Q R C S

1 1 1 1 1

1 1 0 1 0

1 0 1 1 0

1 0 0 0 1

0 1 1 1 0

0 1 0 0 1

0 0 1 0 1

0 0 0 0 0

Figure 2.5.2 Circuit to Add P + Q + R, Where P, Q, and R Are Binary Digits

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

84 Chapter 2 The Logic of Compound Statements

Two full-adders and one half-adder can be used together to build a circuit that will add two three-digit binary numbers P Q R and ST U to obtain the sum W XY Z . This is illustrated in Figure 2.5.3. Such a circuit is called a parallel adder. Parallel adders can be constructed to add binary numbers of any finite length.

half-adder U

Q

P

S1 = Z

S2 = Y

half-adder

R

U

Q

T

P

S

C2

C1

S1 = Z

S2 = Y

S3 = X

C3 = W

full-adder

full-adder

Figure 2.5.3 A Parallel Adder to Add P Q R and STU to Obtain W XY Z

Two’s Complements and the Computer Representation of Negative Integers

Typically, a fixed number of bits is used to represent integers on a computer, and these are required to represent negative as well as nonnegative integers. Sometimes a particular bit, normally the left-most, is used as a sign indicator, and the remaining bits are taken to be the absolute value of the number in binary notation. The problem with this approach is that the procedures for adding the resulting numbers are somewhat complicated and the representation of 0 is not unique. A more common approach, using two’s complements, makes it possible to add integers quite easily and results in a unique representation for 0. The two’s complement of an integer relative to a fixed bit length is defined as follows:

• Definition Given a positive integer a, the two’s complement of a relative to a fixed bit length n is the n-bit binary representation of

2n − a.

Bit lengths of 16 and 32 are the most commonly used in practice. However, because the principles are the same for all bit lengths, we use a bit length of 8 for simplicity in this discussion. For instance, because

(28 − 27)10 = (256− 27)10 = 22910 = (128 + 64 + 32 + 4 + 1)10 = 111001012, the 8-bit two’s complement of 27 is 111001012.

It turns out that there is a convenient way to compute two’s complements that involves less arithmetic than direct application of the definition. For an 8-bit representation, it is based on three facts:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 85

1. 28 − a = [(28 − 1)− a] + 1. 2. The binary representation of 28 − 1 is 111111112. 3. Subtracting an 8-bit binary number a from 111111112 just switches all the 0’s in a

to 1’s and all the 1’s to 0’s. (The resulting number is called the one’s complement of the given number.)

For instance, by (2) and (3), with a = 27,

1 1 1 1 1 1 1 1 28 − 1 −

0 0 0 1 1 0 1 1 270’s and 1’s are switched

→ →

1 1 1 0 0 1 0 0 (28 − 1)− 27 2.5.1

and so in binary notation the difference (28 − 1)− 27 is 111001002. But by (1) with a = 27, 28 − 27 = [(28 − 1)− 27] + 1, and so if we add 1 to (2.5.1), we obtain the 8-bit binary representation of 28 − 27, which is the 8-bit two’s complement of 27:

1 1 1 0 0 1 0 0 (28 − 1)− 27 +

0 0 0 0 0 0 0 1 1

1 1 1 0 0 1 0 1 28 − 27

In general,

To find the 8-bit two’s complement of a positive integer a that is at most 255:

• Write the 8-bit binary representation for a. • Flip the bits (that is, switch all the 1’s to 0’s and all the 0’s to 1’s). • Add 1 in binary notation.

Example 2.5.6 Finding a Two’s Complement

Find the 8-bit two’s complement of 19.

Solution Write the 8-bit binary representation for 19, switch all the 0’s to 1’s and all the 1’s to 0’s, and add 1.

1910 = (16 + 2 + 1)10 = 000100112 flip the bits−−−−−−−→ 11101100 add 1−−−−→ 11101101 To check this result, note that

111011012 = (128 + 64 + 32 + 8 + 4 + 1)10 = 23710 = (256− 19)10 = (28 − 19)10,

which is the two’s complement of 19. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

86 Chapter 2 The Logic of Compound Statements

Observe that because

28 − (28 − a) = a the two’s complement of the two’s complement of a number is the number itself, and therefore,

To find the decimal representation of the integer with a given 8-bit two’s complement:

• Find the two’s complement of the given two’s complement. • Write the decimal equivalent of the result.

Example 2.5.7 Finding a Number with a Given Two’s Complement

What is the decimal representation for the integer with two’s complement 10101001?

Solution

101010012 flip the bits−−−−−−−→ 01010110 add 1−−−−→ 010101112 = (64 + 16 + 4 + 2 + 1)10 = 8710

To check this result, note that the given number is

101010012 = (128 + 32 + 8 + 1)10 = 16910 = (256− 87)10 = (28 − 87)10, which is the two’s complement of 87. ■

8-Bit Representation of a Number Now consider the two’s complement of an integer n that satisfies the inequality 1 ≤ n ≤ 128. Then

−1 ≥ −n ≥ −128 because multiplying by −1 reverses the direction of the inequality

and

28 − 1 ≥ 28 − n ≥ 28 − 128 by adding 28 to all parts of the inequality. But 28 − 128 = 256− 128 = 128 = 27. Hence

27 ≤ the two’s complement of n < 28. It follows that the 8-bit two’s complement of an integer from 1 through 128 has a leading bit of 1. Note also that the ordinary 8-bit representation of an integer from 0 through 127 has a leading bit of 0. Consequently, eight bits can be used to represent both nonnegative and negative integers by representing each nonnegative integer up through 127 using ordinary 8-bit binary notation and representing each negative integer from −1 through −128 as the two’s complement of its absolute value. That is, for any integer a from −128 through 127,

The 8-bit representation of a

= {

the 8-bit binary representation of a if a ≥ 0 the 8-bit binary representation of 28 − |a| if a < 0 .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 87

The representations are illustrated in Table 2.5.2.

Table 2.5.2

8-Bit Representation (ordinary 8-bit Decimal Form of binary notation if nonnegative or 8-bit two’s Two’s Complement

Integer complement of absolute value if negative) for Negative Integers

127 01111111

126 01111110 ...

...

2 00000010

1 00000001

0 00000000

−1 11111111 28 − 1 −2 11111110 28 − 2 −3 11111101 28 − 3 ...

... ...

−127 10000001 28 − 127 −128 10000000 28 − 128

Computer Addition with Negative Integers Here is an example of how two’s complements enable addition circuits to perform sub- traction. Suppose you want to compute 72− 54. First note that this is the same as 72 + (−54), and the 8-bit binary representations of 72 and −54 are 01001000 and 11001010, respectively. So if you add the 8-bit binary representations for both numbers, you get

0 1 0 0 1 0 0 0 + 1 1 0 0 1 0 1 0

1 0 0 0 1 0 0 1 0

And if you truncate the leading 1, you get 00010010. This is the 8-bit binary representation for 18, which is the right answer!

The description below explains how to use this method to add any two integers between −128 and 127. It is easily generalized to apply to 16-bit and 32-bit represen- tations in order to add integers between about −2,000,000,000 and 2,000,000,000.

To add two integers in the range −128 through 127 whose sum is also in the range −128 through 127:

• Convert both integers to their 8-bit representations (representing negative integers by using the two’s complements of their absolute values).

• Add the resulting integers using ordinary binary addition. • Truncate any leading 1 (overflow) that occurs in the 28th position. • Convert the result back to decimal form (interpreting 8-bit integers with leading

0’s as nonnegative and 8-bit integers with leading 1’s as negative).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

88 Chapter 2 The Logic of Compound Statements

To see why this result is true, consider four cases: (1) both integers are nonnegative, (2) one integer is nonnegative and the other is negative and the absolute value of the nonnegative integer is less than that of the negative one, (3) one integer is nonnegative and the other is negative and the absolute value of the negative integer is less than or equal to that of the nonnegative one, and (4) both integers are negative.

Case 1, (both integers are nonnegative): This case is easy because if two nonnegative integers from 0 through 127 are written in their 8-bit representations and if their sum is also in the range 0 through 127, then the 8-bit representation of their sum has a lead- ing 0 and is therefore interpreted correctly as a nonnegative integer. The example below illustrates what happens when 38 and 69 are added.

0 0 1 0 0 1 1 0 38 +

0 1 0 0 0 1 0 1 69

0 1 1 0 1 0 1 1 107

Cases (2) and (3) both involve adding a negative and a nonnegative integer. To be concrete, let the nonnegative integer be a and the negative integer be −b and suppose both a and −b are in the range −128 through 127. The crucial observation is that adding the 8-bit representations of a and −b is equivalent to computing

a + (28 − b) because the 8-bit representation of −b is the binary representation of 28 − b.

Case 2 (a is nonnegative and −b is negative and |a| < |b|): In this case, observe that a = |a| < |b| = b and

a + (28 − b) = 28 − (b − a), and the binary representation of this number is the 8-bit representation of −(b − a) = a + (−b). We must be careful to check that 28 − (b − a) is between 27 and 28. But it is because

27 = 28 − 27 ≤ 28 − (b − a) < 28 since 0 < b − a ≤ b ≤ 128 = 27. Hence in case |a| < |b|, adding the 8-bit representations of a and −b gives the 8-bit representation of a + (−b).

Example 2.5.8 Computing a + (−b) Where 0 ≤ a < b ≤ 128 Use 8-bit representations to compute 39 + (−89).

Solution

Step 1: Change from decimal to 8-bit representations using the two’s complement to represent −89.

Since 3910 = (32 + 4 + 2 + 1)10 = 1001112, the 8-bit representation of 39 is 00100111. Now the 8-bit representation of −89 is the two’s complement of 89. This is obtained as follows:

8910 = (64 + 16 + 8 + 1)10 = 010110012 flip the bits−−−−−−−→ 10100110 add 1−−−−→ 10100111

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 89

So the 8-bit representation of −89 is 10100111. Step 2: Add the 8-bit representations in binary notation and truncate the 1 in the 28th

position if there is one:

0 0 1 0 0 1 1 1 +

1 0 1 0 0 1 1 1

There is no 1 in the 28th position to truncate→ 1 1 0 0 1 1 1 0

Step 3: Find the decimal equivalent of the result. Since its leading bit is 1, this number is the 8-bit representation of a negative integer.

11001110 flip the bits−−−−−−−→ 00110001 add 1−−−−→ 00110010 ↔ −(32 + 16 + 2)10 = −5010

Note that since 39− 89 = −50, this procedure gives the correct answer. ■

Case 3 (a is nonnegative and −b is negative and |b| ≤ |a|): In this case, observe that b = |b| ≤ |a| = a and

a + (28 − b) = 28 + (a − b). Also

28 ≤ 28 + (a − b) < 28 + 27 because 0 ≤ a − b ≤ a < 128 = 27. So the binary representation of a + (28 − b) = 28 + (a − b) has a leading 1 in the ninth (28th) position. This leading 1 is often called “overflow” because it does not fit in the 8-bit integer format. Now subtracting 28 from 28 + (a − b) is equivalent to truncating the leading 1 in the 28th position of the binary representation of the number. But

[a + (28 − b)]− 28 = 28 + (a − b)− 28 = a − b = a + (−b). Hence in case |a| ≥ |b|, adding the 8-bit representations of a and −b and truncating the leading 1 (which is sure to be present) gives the 8-bit representation of a + (−b).

Example 2.5.9 Computing a + (−b) Where 1 ≤ b ≤ a ≤ 127 Use 8-bit representations to compute 39 + (−25).

Solution

Step 1: Change from decimal to 8-bit representations using the two’s complement to represent −25.

As in Example 2.5.8, the 8-bit representation of 39 is 00100111. Now the 8-bit representation of −25 is the two’s complement of 25, which is obtained as follows:

2510 = (16 + 8 + 1)10 = 000110012 flip the bits−−−−−−−→ 11100110 add 1−−−−→ 11100111

So the 8-bit representation of −25 is 11100111. Step 2: Add the 8-bit representations in binary notation and truncate the 1 in the 28th

position if there is one:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

90 Chapter 2 The Logic of Compound Statements

0 0 1 0 0 1 1 1 +

1 1 1 0 0 1 1 1

Truncate→ 1 0 0 0 0 1 1 1 0

Step 3: Find the decimal equivalent of the result:

000011102 = (8 + 4 + 2)10 = 1410. Since 39− 25 = 14, this is the correct answer. ■

Case 4 (both integers are negative): This case involves adding two negative integers in the range −1 through −128 whose sum is also in this range. To be specific, consider the sum (−a) + (−b) where a, b, and a + b are all in the range 1 through 128. In this case, the 8-bit representations of−a and−b are the 8-bit representations of 28 − a and 28 − b. So if the 8-bit representations of −a and −b are added, the result is

(28 − a) + (28 − b) = [28 − (a + b)] + 28. Recall that truncating a leading 1 in the ninth (28th) position of a binary number is equivalent to subtracting 28. So when the leading 1 is truncated from the 8-bit repre- sentation of (28 − a) + (28 − b), the result is 28 − (a + b), which is the 8-bit represen- tation of −(a + b) = (−a) + (−b). (In exercise 37 you are asked to show that the sum (28 − a) + (28 − b) has a leading 1 in the ninth (28th) position.)

Example 2.5.10 Computing (−a) + (−b) Where 1 ≤ a, b ≤ 128, and 1 ≤ a + b ≤ 128 Use 8-bit representations to compute (−89) + (−25).

Solution

Step 1: Change from decimal to 8-bit representations using the two’s complements to represent −89 and −25.

The 8-bit representations of−89 and−25 were shown in Examples 2.5.8 and 2.5.9 to be 10100111 and 11100111, respectively.

Step 2: Add the 8-bit representations in binary notation and truncate the 1 in the 28th position if there is one:

1 0 1 0 0 1 1 1 +

1 1 1 0 0 1 1 1

Truncate→ 1 1 0 0 0 1 1 1 0

Step 3: Find the decimal equivalent of the result. Because its leading bit is 1, this number is the 8-bit representation of a negative integer.

10001110 flip the bits−−−−−−−→ 01110001 add 1−−−−→ 011100102 ↔ −(64 + 32 + 16 + 2)10 = −11410

Since (−89) + (−25) = −114, that is the correct answer. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 91

Hexadecimal Notation It should now be obvious that numbers written in binary notation take up much more space than numbers written in decimal notation. Yet many aspects of computer opera- tion can best be analyzed using binary numbers. Hexadecimal notation is even more compact than decimal notation, and it is much easier to convert back and forth between hexadecimal and binary notation than it is between binary and decimal notation. The word hexadecimal comes from the Greek root hex-, meaning “six,” and the Latin root deci-, meaning “ten.” Hence hexadecimal refers to “sixteen,” and hexadecimal notation is also called base 16 notation. Hexadecimal notation is based on the fact that any integer can be uniquely expressed as a sum of numbers of the form

d ·16n, where each n is a nonnegative integer and each d is one of the integers from 0 to 15. In order to avoid ambiguity, each hexadecimal digit must be represented by a single symbol. The integers 10 through 15 are represented by the symbols A, B, C, D, E, and F. The sixteen hexadecimal digits are shown in Table 2.5.3, together with their decimal equivalents and, for future reference, their 4-bit binary equivalents.

Table 2.5.3

4-Bit Binary Decimal Hexadecimal Equivalent

0 0 0000

1 1 0001

2 2 0010

3 3 0011

4 4 0100

5 5 0101

6 6 0110

7 7 0111

8 8 1000

9 9 1001

10 A 1010

11 B 1011

12 C 1100

13 D 1101

14 E 1110

15 F 1111

Example 2.5.11 Converting from Hexadecimal to Decimal Notation

Convert 3CF16 to decimal notation.

Solution A schema similar to the one introduced in Example 2.5.2 can be used here.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

92 Chapter 2 The Logic of Compound Statements

16 2 =

25 6

16 1 =

16

16 0 =

1

316 C16 F16

= = =

310 1210 1510

→ → →15 · 1 = 15

12 · 16 = 192 3 ·256 = 768

97510

So 3CF16 = 97510. ■

Now consider how to convert from hexadecimal to binary notation. In the example below the numbers are rewritten using powers of 2, and the laws of exponents are applied. The result suggests a general procedure.

16 3 =

40 96

16 2 =

25 6

16 1 =

16

16 0 =

1

C16 516 016 A16

= = = =

1210 510 010 1010

→ → → → 10 ·160 = (23 + 2) ·1 = 23 + 2 since 10 = 23 + 2

0 ·161 = 0 ·24 = 0 since 161 = 24 5 ·162 = (22 + 1) ·28 = 210 + 28 since 5 = 22 + 1, 162 = (24)2 = 28 and 22 ·28 = 210

12 ·163 = (23 + 22) ·212 = 215 + 214 since 12 = 23 + 22, 162 = (24)3 = 212, 23 ·212 = 215, and 22 ·212 = 214

But

(215 + 214) + (210 + 28) + 0 + (23 + 2) = 1100 0000 0000 00002 + 0101 0000 00002 by the rules for writing

binary numbers.+ 0000 00002 + 10102

So C50A16 = 1100︸︷︷︸ 0101︸︷︷︸ 0000︸︷︷︸ 10102︸ ︷︷ ︸

C16 516 016 A16

by the rules for adding binary numbers.

The procedure illustrated in this example can be generalized. In fact, the following sequence of steps will always give the correct answer:

To convert an integer from hexadecimal to binary notation:

• Write each hexadecimal digit of the integer in 4-bit binary notation. • Juxtapose the results.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 93

Example 2.5.12 Converting from Hexadecimal to Binary Notation

Convert B09F16 to binary notation.

Solution B16 = 1110 = 10112, 016 = 010 = 00002, 916 = 910 = 10012, and F16 = 1510 = 11112. Consequently,

B 0 9 F

↔ ↔ ↔ ↔

1011 0000 1001 1111

and the answer is 10110000100111112. ■

To convert integers written in binary notation into hexadecimal notation, reverse the steps of the previous procedure.

To convert an integer from binary to hexadecimal notation:

• Group the digits of the binary number into sets of four, starting from the right and adding leading zeros as needed.

• Convert the binary numbers in each set of four into hexadecimal digits. Juxtapose those hexadecimal digits.

Example 2.5.13 Converting from Binary to Hexadecimal Notation

Convert 1001101101010012 to hexadecimal notation.

Solution First group the binary digits in sets of four, working from right to left and adding leading 0’s if necessary.

0100 1101 1010 1001.

Convert each group of four binary digits into a hexadecimal digit.

0100 1101 1010 1001

↔ ↔ ↔ ↔

4 D A 9

Then juxtapose the hexadecimal digits.

4DA916 ■

Example 2.5.14 Reading a Memory Dump

The smallest addressable memory unit on most computers is one byte, or eight bits. In some debugging operations a dump is made of memory contents; that is, the contents of each memory location are displayed or printed out in order. To save space and make the output easier on the eye, the hexadecimal versions of the memory contents are given, rather than the binary versions. Suppose, for example, that a segment of the memory dump looks like

A3 BB 59 2E.

What is the actual content of the four memory locations?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

94 Chapter 2 The Logic of Compound Statements

Solution A316 = 101000112 BB16 = 101110112 5916 = 010110012 2E16 = 001011102 ■

Test Yourself 1. To represent a nonnegative integer in binary notation means

to write it as a sum of products of the form , where .

2. To add integers in binary notation, you use the facts that 12 + 12 = and 12 + 12 + 12 = .

3. To subtract integers in binary notation, you use the facts that 102 − 12 = and 112 − 12 = .

4. A half-adder is a digital logic circuit that , and a full-adder is a digital logic circuit

that .

5. The 8-bit two’s complement of a positive integer a is .

6. To find the 8-bit two’s complement of a positive integer a that is at most 255, you , , and .

7. If a is an integer with −128 ≤ a ≤ 127, the 8-bit represen- tation of a is if a ≥ 0 and is if a < 0.

8. To add two integers in the range −128 through 127 whose sum is also in the range −128 through 127, you , ,

, and .

9. To represent a nonnegative integer in hexadecimal notation means to write it as a sum of products of the form , where .

10. To convert a nonnegative integer from hexadecimal to binary notation, you and .

Exercise Set 2.5 Represent the decimal integers in 1–6 in binary notation.

1. 19 2. 55 3. 287

4. 458 5. 1609 6. 1424

Represent the integers in 7–12 in decimal notation.

7. 11102 8. 101112 9. 1101102

10. 11001012 11. 10001112 12. 10110112

Perform the arithmetic in 13–20 using binary notation.

13. 10112 + 1012

14. 10012 + 10112

15. 1011012 + 111012

16. 1101110112 + 10010110102

17. 101002 − 11012

18. 110102 − 11012

19. 1011012 − 100112

20. 10101002 − 101112

21. Give the output signals S and T for the circuit in the right column if the input signals P, Q, and R are as specified. Note that this is not the circuit for a full-adder. a. P = 1, Q = 1, R = 1 b. P = 0, Q = 1, R = 0 c. P = 1, Q = 0, R = 1

half-adder #1

half-adder #2

AND P

Q

R

S

T

C1

C2

S1

22. Add 111111112 + 12 and convert the result to decimal nota- tion, to verify that 111111112 = (28 − 1)10.

Find the 8-bit two’s complements for the integers in 23–26.

23. 23 24. 67 25. 4 26. 115

Find the decimal representations for the integers with the 8-bit representations given in 27–30.

27. 11010011 28. 10011001

29. 11110010 30. 10111010

Use 8-bit representations to compute the sums in 31–36.

31. 57 + (−118) 32. 62 + (−18) 33. (−6) + (−73) 34. 89 + (−55) 35. (−15) + (−46) 36. 123 + (−94)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.5 Application: Number Systems and Circuits for Addition 95

37.✶ Show that if a, b, and a + b are integers in the range 1 through 128, then

(28 − a) + (28 − b) = (28 − (a + b)) + 28 ≥ 28 + 27. Explain why it follows that if the 8-bit binary representa- tion of the sum of the negatives of two numbers in the given range is computed, the result is a negative number.

Convert the integers in 38–40 from hexadecimal to decimal notation.

38. A2BC16 39. E0D16 40. 39EB16

Convert the integers in 41–43 from hexadecimal to binary nota- tion.

41. 1C0ABE16 42. B53DF816 43. 4ADF8316

Convert the integers in 44–46 from binary to hexadecimal notation.

44. 001011102 45. 10110111110001012

46. 110010010111002

47. Octal Notation: In addition to binary and hexadecimal, computer scientists also use octal notation (base 8) to rep- resent numbers. Octal notation is based on the fact that any integer can be uniquely represented as a sum of numbers of the form d · 8n , where each n is a nonnegative integer and each d is one of the integers from 0 to 7. Thus, for example, 50738 = 5 ·83 + 0 ·82 + 7 ·81 + 3 ·80 = 261910. a. Convert 615028 to decimal notation. b. Convert 207638 to decimal notation. c. Describe methods for converting integers from octal to

binary notation and the reverse that are similar to the methods used in Examples 2.5.12 and 2.5.13 for con- verting back and forth from hexadecimal to binary nota- tion. Give examples showing that these methods result in correct answers.

Answers for Test Yourself 1. d ·2n; d = 0 or d = 1, and n is a nonnegative integer 2. 102;112 3. 12;102 4. outputs the sum of any two binary digits; outputs the sum of any three binary digits 5. 28 − a 6. write the 8-bit binary representation of a; flip the bits; add 1 in binary notation 7. the 8-bit binary representation of a; the 8-bit binary representation of 28 − a 8. convert both integers to their 8-bit binary representations; add the results using binary notation; truncate any leading 1; convert back to decimal form 9. d ·16n; d = 0, 1, 2, . . . 9, A, B, C, D, E, F , and n is a nonnegative integer 10. write each hexadecimal digit in 4-bit binary notation; juxtapose the results

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

96

CHAPTER 3

THE LOGIC OF QUANTIFIED STATEMENTS

In Chapter 2 we discussed the logical analysis of compound statements—those made of simple statements joined by the connectives ∼,∧,∨,→, and ↔. Such analysis casts light on many aspects of human reasoning, but it cannot be used to determine validity in the majority of everyday and mathematical situations. For example, the argument

All men are mortal.

Socrates is a man.

∴ Socrates is mortal. is intuitively perceived as correct. Yet its validity cannot be derived using the methods outlined in Section 2.3. To determine validity in examples like this, it is necessary to separate the statements into parts in much the same way that you separate declarative sentences into subjects and predicates. And you must analyze and understand the special role played by words that denote quantities such as “all” or “some.” The symbolic analysis of predicates and quantified statements is called the predicate calculus. The symbolic analysis of ordinary compound statements (as outlined in Sections 2.1–2.3) is called the statement calculus (or the propositional calculus).

3.1 Predicates and Quantified Statements I . . . it was not till within the last few years that it has been realized how fundamental any and some are to the very nature of mathematics. — A. N. Whitehead (1861–1947)

As noted in Section 2.1, the sentence “He is a college student” is not a statement because it may be either true or false depending on the value of the pronoun he. Similarly, the sentence “x + y is greater than 0” is not a statement because its truth value depends on the values of the variables x and y.

In grammar, the word predicate refers to the part of a sentence that gives information about the subject. In the sentence “James is a student at Bedford College,” the word James is the subject and the phrase is a student at Bedford College is the predicate. The predicate is the part of the sentence from which the subject has been removed.

In logic, predicates can be obtained by removing some or all of the nouns from a statement. For instance, let P stand for “is a student at Bedford College” and let Q stand for “is a student at.” Then both P and Q are predicate symbols. The sentences “x is a student at Bedford College” and “x is a student at y” are symbolized as P(x) and as Q(x, y) respectively, where x and y are predicate variables that take values in appropri- ate sets. When concrete values are substituted in place of predicate variables, a statement results. For simplicity, we define a predicate to be a predicate symbol together with suit- able predicate variables. In some other treatments of logic, such objects are referred to as propositional functions or open sentences.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 97

• Definition A predicate is a sentence that contains a finite number of variables and becomes a statement when specific values are substituted for the variables. The domain of a predicate variable is the set of all values that may be substituted in place of the variable.

Example 3.1.1 Finding Truth Values of a Predicate

Let P(x) be the predicate “x2 > x” with domain the set R of all real numbers. Write P(2), P( 12 ), and P(− 12 ), and indicate which of these statements are true and which are false.

Solution P(2): 22 > 2, or 4 > 2. True.

P (

1 2

) : (

1 2

)2 >

1 2 , or

1 4 >

1 2 . False.

P ( −12 ) : ( −12 )2

> −12 , or 1 4 > −

1 2 . True. ■

When an element in the domain of the variable of a one-variable predicate is substi- tuted for the variable, the resulting statement is either true or false. The set of all such elements that make the predicate true is called the truth set of the predicate.

Note Recall that we read these symbols as “the set of all x in D such that P(x).”

• Definition If P(x) is a predicate and x has domain D, the truth set of P(x) is the set of all elements of D that make P(x) true when they are substituted for x . The truth set of P(x) is denoted

{x ∈ D | P(x)}.

Example 3.1.2 Finding the Truth Set of a Predicate

Let Q(n) be the predicate “n is a factor of 8.” Find the truth set of Q(n) if

a. the domain of n is the set Z+ of all positive integers

b. the domain of n is the set Z of all integers.

Solution

a. The truth set is {1, 2, 4, 8} because these are exactly the positive integers that divide 8 evenly.

b. The truth set is {1, 2, 4, 8,−1,−2,−4,−8} because the negative integers−1,−2,−4, and −8 also divide into 8 without leaving a remainder. ■

The Universal Quantifier: ∀ One sure way to change predicates into statements is to assign specific values to all their variables. For example, if x represents the number 35, the sentence “x is (evenly) divis- ible by 5” is a true statement since 35 = 5 ·7. Another way to obtain statements from predicates is to add quantifiers. Quantifiers are words that refer to quantities such as “some” or “all” and tell for how many elements a given predicate is true. The formal concept of quantifier was introduced into symbolic logic in the late nineteenth century by

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

98 Chapter 3 The Logic of Quantified Statements

the American philosopher, logician, and engineer Charles Sanders Peirce and, indepen- dently, by the German logician Gottlob Frege.

The symbol ∀ denotes “for all” and is called the universal quantifier. For example, another way to express the sentence “All human beings are mortal” is to write

∀ human beings x, x is mortal. Cu

lv er

Pi ct

ur es

Charles Sanders Peirce (1839–1914)

When the symbol x is introduced into the phrase “∀ human beings x ,” you are sup- posed to think of x as an individual, but generic, object—with all the properties shared by every human being but no other properties. Thus you should say “x is mortal” rather than “x are mortal.” In other words, use the singular “is” rather than the plural verb “are” when describing the property satisfied by x . If you let H be the set of all human beings, then you can symbolize the statement more formally by writing

∀x ∈ H, x is mortal, which is read as “For all x in the set of all human beings, x is mortal.”

Note Think “for all” when you see the symbol ∀.

The domain of the predicate variable is generally indicated between the ∀ symbol and the variable name (as in ∀ human beings x) or immediately following the variable name (as in ∀x ∈ H ). Some other expressions that can be used instead of for all are for every, for arbitrary, for any, for each, and given any. In a sentence such as “∀ real numbers x and y, x + y = y + x ,” the ∀ symbol is understood to refer to both x and y.∗

Fr ie

dr ic

h Sc

hi lle

r, U

ni ve

rs íta

t Je

na

Gottlob Frege (1848–1925)

Sentences that are quantified universally are defined as statements by giving them the truth values specified in the following definition:

• Definition Let Q(x) be a predicate and D the domain of x . A universal statement is a statement of the form “∀x ∈ D, Q(x).” It is defined to be true if, and only if, Q(x) is true for every x in D. It is defined to be false if, and only if, Q(x) is false for at least one x in D. A value for x for which Q(x) is false is called a counterexample to the universal statement.

Example 3.1.3 Truth and Falsity of Universal Statements

a. Let D = {1, 2, 3, 4, 5}, and consider the statement ∀x ∈ D, x2 ≥ x .

Show that this statement is true.

b. Consider the statement

∀x ∈ R, x2 ≥ x . Find a counterexample to show that this statement is false.

Solution

a. Check that “x2 ≥ x” is true for each individual x in D. 12 ≥ 1, 22 ≥ 2, 32 ≥ 3, 42 ≥ 4, 52 ≥ 5.

Hence “∀x ∈ D, x2 ≥ x” is true.

∗More formal versions of symbolic logic would require writing a separate ∀ for each variable: “∀x ∈ R(∀y ∈ R(x + y = y + x)).”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 99

b. Counterexample: Take x = 12 . Then x is in R (since 12 is a real number) and (

1 2

)2 = 1

4 %

1 2 .

Hence “∀x ∈ R, x2 ≥ x” is false. ■

The technique used to show the truth of the universal statement in Example 3.1.3(a) is called the method of exhaustion. It consists of showing the truth of the predicate sep- arately for each individual element of the domain. (The idea is to exhaust the possibilities before you exhaust yourself!) This method can, in theory, be used whenever the domain of the predicate variable is finite. In recent years the prevalence of digital computers has greatly increased the convenience of using the method of exhaustion. Computer expert systems, or knowledge-based systems, use this method to arrive at answers to many of the questions posed to them. Because most mathematical sets are infinite, however, the method of exhaustion can rarely be used to derive general mathematical results.

The Existential Quantifier: ∃ The symbol ∃ denotes “there exists” and is called the existential quantifier. For example, the sentence “There is a student in Math 140” can be written as

∃ a person p such that p is a student in Math 140, or, more formally,

∃p ∈ P such that p is a student in Math 140, Note Think “there exists” when you see the symbol ∃.

where P is the set of all people. The domain of the predicate variable is generally indi- cated either between the ∃ symbol and the variable name or immediately following the variable name. The words such that are inserted just before the predicate. Some other expressions that can be used in place of there exists are there is a, we can find a, there is at least one, for some, and for at least one. In a sentence such as “∃ integers m and n such that m + n = m ·n,” the ∃ symbol is understood to refer to both m and n.∗

Sentences that are quantified existentially are defined as statements by giving them the truth values specified in the following definition.

• Definition Let Q(x) be a predicate and D the domain of x . An existential statement is a statement of the form “∃x ∈ D such that Q(x).” It is defined to be true if, and only if, Q(x) is true for at least one x in D. It is false if, and only if, Q(x) is false for all x in D.

Example 3.1.4 Truth and Falsity of Existential Statements

a. Consider the statement

∃m ∈ Z+ such that m2 = m. Show that this statement is true.

∗In more formal versions of symbolic logic, the words such that are not written out (although they are understood) and a separate ∃ symbol is used for each variable: “∃m ∈ Z(∃n ∈ Z(m + n = m ·n)).”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

100 Chapter 3 The Logic of Quantified Statements

b. Let E = {5, 6, 7, 8} and consider the statement ∃m ∈ E such that m2 = m.

Show that this statement is false.

Solution

a. Observe that 12 = 1. Thus “m2 = m” is true for at least one integer m. Hence “∃m ∈ Z such that m2 = m” is true.

b. Note that m2 = m is not true for any integers m from 5 through 8: 52 = 25 ̸= 5, 62 = 36 ̸= 6, 72 = 49 ̸= 7, 82 = 64 ̸= 8.

Thus “∃m ∈ E such that m2 = m” is false. ■

Formal Versus Informal Language It is important to be able to translate from formal to informal language when trying to make sense of mathematical concepts that are new to you. It is equally important to be able to translate from informal to formal language when thinking out a complicated problem.

Example 3.1.5 Translating from Formal to Informal Language

Rewrite the following formal statements in a variety of equivalent but more informal ways. Do not use the symbol ∀ or ∃. a. ∀x ∈ R, x2 ≥ 0. b. ∀x ∈ R, x2 ̸= −1. c. ∃m ∈ Z+such that m2 = m.

Solution

a. All real numbers have nonnegative squares. Or: Every real number has a nonnegative square. Or: Any real number has a nonnegative square. Or: The square of each real number is nonnegative.

Note The singular noun is used to refer to the domain when the ∀ symbol is translated as every, any, or each.

b. All real numbers have squares that are not equal to −1. Or: No real numbers have squares equal to −1. (The words none are or no . . . are are equivalent to the words all are not.)

c. There is a positive integer whose square is equal to itself. Or: We can find at least one positive integer equal to its own square. Or: Some positive integer equals its own square. Or: Some positive integers equal their own squares.

Note In ordinary English, the statement in part (c) might be taken to be true only if there are at least two positive integers equal to their own squares. In mathematics, we understand the last two statements in part (c) to mean the same thing.

Another way to restate universal and existential statements informally is to place the quantification at the end of the sentence. For instance, instead of saying “For any real number x , x2 is nonnegative,” you could say “x2 is nonnegative for any real number x .” In such a case the quantifier is said to “trail” the rest of the sentence.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 101

Example 3.1.6 Trailing Quantifiers

Rewrite the following statements so that the quantifier trails the rest of the sentence.

a. For any integer n, 2n is even.

b. There exists at least one real number x such that x2 ≤ 0. Solution

a. 2n is even for any integer n.

b. x2 ≤ 0 for some real number x . Or: x2 ≤ 0 for at least one real number x . ■

Example 3.1.7 Translating from Informal to Formal Language

Rewrite each of the following statements formally. Use quantifiers and variables.

a. All triangles have three sides.

b. No dogs have wings.

c. Some programs are structured.

Solution

a. ∀ triangles t, t has three sides. Or: ∀t ∈ T, t has three sides (where T is the set of all triangles).

b. ∀ dogs d, d does not have wings. Or: ∀d ∈ D, d does not have wings (where D is the set of all dogs).

c. ∃ a program p such that p is structured. Or: ∃p ∈ P such that p is structured (where P is the set of all programs). ■

Universal Conditional Statements A reasonable argument can be made that the most important form of statement in mathe- matics is the universal conditional statement:

∀x, if P(x) then Q(x). Familiarity with statements of this form is essential if you are to learn to speak mathematics.

Example 3.1.8 Writing Universal Conditional Statements Informally

Rewrite the following statement informally, without quantifiers or variables.

∀x ∈ R, if x > 2 then x2 > 4. Solution If a real number is greater than 2 then its square is greater than 4.

Or: Whenever a real number is greater than 2, its square is greater than 4.

Or: The square of any real number greater than 2 is greater than 4.

Or: The squares of all real numbers greater than 2 are greater than 4. ■

Example 3.1.9 Writing Universal Conditional Statements Formally

Rewrite each of the following statements in the form

∀ , if then . a. If a real number is an integer, then it is a rational number.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

102 Chapter 3 The Logic of Quantified Statements

b. All bytes have eight bits.

c. No fire trucks are green.

Solution

a. ∀ real numbers x , if x is an integer, then x is a rational number. Or: ∀x ∈ R, if x ∈ Z then x ∈ Q.

b. ∀x , if x is a byte, then x has eight bits. c. ∀x , if x is a fire truck, then x is not green.

It is common, as in (b) and (c) above, to omit explicit identification of the domain of predicate variables in universal conditional statements. ■

Careful thought about the meaning of universal conditional statements leads to another level of understanding for why the truth table for an if-then statement must be defined as it is. Consider again the statement

∀ real numbers x, if x > 2 then x2 > 4. Your experience and intuition tell you that this statement is true. But that means that

If x > 2 then x2 > 4

must be true for every single real number x . Consequently, it must be true even for values of x that make its hypothesis “x > 2” false. In particular, both statements

If 1 > 2 then 12 > 4 and If − 3 > 2 then (−3)2 > 4 must be true. In both cases the hypothesis is false, but in the first case the conclusion “12 > 4” is false, and in the second case the conclusion “(−3)2 > 4” is true. Hence, regardless of whether its conclusion is true or false, an if-then statement with a false hypothesis must be true.

Note also that the definition of valid argument is a universal conditional statement:

∀ combinations of truth values for the component statements, if the premises are all true then the conclusion is also true.

Equivalent Forms of Universal and Existential Statements Observe that the two statements “∀ real numbers x , if x is an integer then x is rational” and “∀ integers x, x is rational” mean the same thing. Both have informal translations “All integers are rational.” In fact, a statement of the form

∀x ∈ U, if P(x) then Q(x) can always be rewritten in the form

∀x ∈ D, Q(x) by narrowing U to be the domain D consisting of all values of the variable x that make P(x) true. Conversely, a statement of the form

∀x ∈ D, Q(x) can be rewritten as

∀x, if x is in D then Q(x).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 103

Example 3.1.10 Equivalent Forms for Universal Statements

Rewrite the following statement in the two forms “∀x , if then ” and “∀ x , ”: All squares are rectangles.

Solution ∀x , if x is a square then x is a rectangle. ∀ squares x, x is a rectangle. ■

Similarly, a statement of the form “∃x such that p(x) and Q(x)” can be rewritten as “∃xεD such that Q(x),” where D is the set of all x for which P(x) is true.

Example 3.1.11 Equivalent Forms for Existential Statements

A prime number is an integer greater than 1 whose only positive integer factors are itself and 1. Consider the statement “There is an integer that is both prime and even.” Let Prime(n) be “n is prime” and Even(n) be “n is even.” Use the notation Prime(n) and Even(n) to rewrite this statement in the following two forms:

a. ∃n such that ∧ . b. ∃ n such that .

Solution

a. ∃n such that Prime(n)∧ Even(n). b. Two answers: ∃ a prime number n such that Even(n).

∃ an even number n such that Prime(n). ■

Implicit Quantification Consider the statement

If a number is an integer, then it is a rational number.

As shown earlier, this statement is equivalent to a universal statement. However, it does not contain the telltale word all or every or any or each. The only clue to indicate its universal quantification comes from the presence of the indefinite article a. This is an example of implicit universal quantification.

Existential quantification can also be implicit. For instance, the statement “The num- ber 24 can be written as a sum of two even integers” can be expressed formally as “∃ even integers m and n such that 24 = m + n.”

Mathematical writing contains many examples of implicitly quantified statements. Some occur, as in the first example above, through the presence of the word a or an. Others occur in cases where the general context of a sentence supplies part of its meaning. For example, in an algebra course in which the letter x is always used to indicate a real number, the predicate

If x > 2 then x2 > 4

is interpreted to mean the same as the statement

∀ real numbers x, if x > 2 then x2 > 4. Mathematicians often use a double arrow to indicate implicit quantification symbolically. For instance, they might express the above statement as

x > 2 ⇒ x2 > 4.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

104 Chapter 3 The Logic of Quantified Statements

• Notation Let P(x) and Q(x) be predicates and suppose the common domain of x is D.

• The notation P(x) ⇒ Q (x) means that every element in the truth set of P(x) is in the truth set of Q(x), or, equivalently, ∀x, P(x) → Q(x).

• The notation P(x) ⇔ Q (x) means that P(x) and Q(x) have identical truth sets, or, equivalently, ∀x, P(x) ↔ Q(x).

Example 3.1.12 Using ⇒ and ⇔ Let

Q(n) be “n is a factor of 8,”

R(n) be “n is a factor of 4,”

S(n) be “n < 5 and n ̸= 3,” and suppose the domain of n is Z+, the set of positive integers. Use the⇒ and⇔ symbols to indicate true relationships among Q(n), R(n), and S(n).

Solution

1. As noted in Example 3.1.2, the truth set of Q(n) is {1, 2, 4, 8} when the domain of n is Z+. By similar reasoning the truth set of R(n) is {1, 2, 4}. Thus it is true that every element in the truth set of R(n) is in the truth set of Q(n), or, equivalently, ∀n in Z+, R(n) → Q(n). So R(n)⇒ Q(n), or, equivalently

n is a factor of 4 ⇒ n is a factor of 8. 2. The truth set of S(n) is {1, 2, 4}, which is identical to the truth set of R(n), or, equiv-

alently, ∀n in Z+, R(n) ↔ S(n). So R(n)⇔ S(n), or, equivalently, n is a factor of 4 ⇔ n < 5 and n ̸= 3.

Moreover, since every element in the truth set of S(n) is in the truth set of Q(n), or, equivalently, ∀n in Z+, S(n)→ Q(n), then S(n) ⇒ Q(n), or, equivalently,

n < 5 and n ̸= 3 ⇒ n is a factor of 8. ■

Some questions of quantification can be quite subtle. For instance, a mathematics text might contain the following:

a. (x + 1)2 = x2 + 2x + 1. b. Solve 3x − 4 = 5. Although neither (a) nor (b) contains explicit quantification, the reader is supposed to understand that the x in (a) is universally quantified whereas the x in (b) is existentially quantified. When the quantification is made explicit, (a) and (b) become

a. ∀ real numbers x, (x + 1)2 = x2 + 2x + 1. b. Show (by finding a value) that ∃ a real number x such that 3x − 4 = 5.

The quantification of a statement—whether universal or existential—crucially deter- mines both how the statement can be applied and what method must be used to establish its truth. Thus it is important to be alert to the presence of hidden quantifiers when you read mathematics so that you will interpret statements in a logically correct way.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 105

Tarski’s World Tarski’s World is a computer program developed by information scientists Jon Barwise and John Etchemendy to help teach the principles of logic. It is described in their book The Language of First-Order Logic, which is accompanied by a CD-Rom containing the program Tarski’s World, named after the great logician Alfred Tarski.

Example 3.1.13 Investigating Tarski’s World

The program for Tarski’s World provides pictures of blocks of various sizes, shapes, and colors, which are located on a grid. Shown in Figure 3.1.1 is a picture of an arrangement of objects in a two-dimensional Tarski world. The configuration can be described using logical operators and—for the two-dimensional version—notation such as Triangle(x), meaning “x is a triangle,” Blue(y), meaning “y is blue,” and RightOf(x, y), meaning “x is to the right of y (but possibly in a different row).” Individual objects can be given names such as a, b, or c.

Alfred Tarski (1902–1983)

ba

d

f

i

k

e

h

j

c

g

Figure 3.1.1

Determine the truth or falsity of each of the following statements. The domain for all variables is the set of objects in the Tarski world shown above.

a. ∀t , Triangle(t)→ Blue(t). b. ∀x , Blue(x) → Triangle(x). c. ∃y such that Square(y)∧ RightOf(d, y). d. ∃z such that Square(z)∧ Gray(z).

Solution

a. This statement is true: All the triangles are blue.

b. This statement is false. As a counterexample, note that e is blue and it is not a triangle.

c. This statement is true because e and h are both square and d is to their right.

d. This statement is false: All the squares are either blue or black. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

106 Chapter 3 The Logic of Quantified Statements

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. If P(x) is a predicate with domain D, the truth set of P(x) is denoted . We read these symbols out loud as .

2. Some ways to express the symbol ∀ in words are . 3. Some ways to express the symbol ∃ in words are .

4. A statement of the form ∀x ∈ D, Q(x) is true if, and only if, Q(x) is for .

5. A statement of the form ∃x ∈ D such that Q(x) is true if, and only if, Q(x) is for .

Exercise Set 3.1* 1. A menagerie consists of seven brown dogs, two black dogs,

six gray cats, ten black cats, five blue birds, six yellow birds, and one black bird. Determine which of the following state- ments are true and which are false. a. There is an animal in the menagerie that is red. b. Every animal in the menagerie is a bird or a mammal. c. Every animal in the menagerie is brown or gray or black. d. There is an animal in the menagerie that is neither a cat

nor a dog. e. No animal in the menagerie is blue. f. There are in the menagerie a dog, a cat, and a bird that

all have the same color.

2. Indicate which of the following statements are true and which are false. Justify your answers as best as you can. a. Every integer is a real number. b. 0 is a positive real number. c. For all real numbers r,−r is a negative real number. d. Every real number is an integer.

3. Let P(x) be the predicate “x > 1/x .” a. Write P(2), P( 12 ), P(−1), P(− 12 ), and P(−8), and

indicate which of these statements are true and which are false.

b. Find the truth set of P(x) if the domain of x is R, the set of all real numbers.

c. If the domain is the set R+ of all positive real numbers, what is the truth set of P(x)?

4. Let Q(n) be the predicate “n2 ≤ 30.” a. Write Q(2), Q(−2), Q(7), and Q(−7), and indicate

which of these statements are true and which are false. b. Find the truth set of Q(n) if the domain of n is Z, the set

of all integers. c. If the domain is the set Z+ of all positive integers, what

is the truth set of Q(n)?

5. Let Q(x, y) be the predicate “If x < y then x2 < y2” with domain for both x and y being the set R of real numbers. a. Explain why Q(x, y) is false if x = −2 and y = 1. b. Give values different from those in part (a) for which

Q(x, y) is false. c. Explain why Q(x, y) is true if x = 3 and y = 8. d. Give values different from those in part (c) for which

Q(x, y) is true.

6. Let R(m, n) be the predicate “If m is a factor of n2 then m is a factor of n,” with domain for both m and n being the set Z of integers. a. Explain why R(m, n) is false if m = 25 and n = 10. b. Give values different from those in part (a) for which

R(m, n) is false. c. Explain why R(m, n) is true if m = 5 and n = 10. d. Give values different from those in part (c) for which

R(m, n) is true.

7. Find the truth set of each predicate. a. predicate: 6/d is an integer, domain: Z b. predicate: 6/d is an integer, domain: Z+

c. predicate: 1 ≤ x2 ≤ 4, domain: R d. predicate: 1 ≤ x2 ≤ 4, domain: Z

8. Let B(x) be “−10 < x < 10.” Find the truth set of B(x) for each of the following domains. a. Z b. Z+ c. The set of all even integers

Find counterexamples to show that the statements in 9–12 are false.

9. ∀x ∈ R, x > 1/x . 10. ∀a ∈ Z, (a − 1)/a is not an integer. 11. ∀ positive integers m and n, m ·n ≥ m + n. 12. ∀ real numbers x and y,√x + y = √x +√y. 13. Consider the following statement:

∀ basketball players x, x is tall. Which of the following are equivalent ways of expressing this statement? a. Every basketball player is tall. b. Among all the basketball players, some are tall. c. Some of all the tall people are basketball players. d. Anyone who is tall is a basketball player. e. All people who are basketball players are tall. f. Anyone who is a basketball player is a tall person.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Predicates and Quantified Statements I 107

14. Consider the following statement:

∃x ∈ R such that x2 = 2. Which of the following are equivalent ways of expressing this statement? a. The square of each real number is 2. b. Some real numbers have square 2. c. The number x has square 2, for some real number x . d. If x is a real number, then x2 = 2. e. Some real number has square 2. f. There is at least one real number whose square is 2.

15.H Rewrite the following statements informally in at least two different ways without using variables or quantifiers. a. ∀ rectangles x, x is a quadrilateral. b. ∃ a set A such that A has 16 subsets.

16. Rewrite each of the following statements in the form “∀ x, .” a. All dinosaurs are extinct. b. Every real number is positive, negative, or zero. c. No irrational numbers are integers. d. No logicians are lazy. e. The number 2,147,581,953 is not equal to the square of

any integer. f. The number −1 is not equal to the square of any real

number.

17. Rewrite each of the following in the form “∃ x such that .” a. Some exercises have answers. b. Some real numbers are rational.

18. Let D be the set of all students at your school, and let M(s) be “s is a math major,” let C(s) be “s is a computer sci- ence student,” and let E(s) be “s is an engineering student.” Express each of the following statements using quantifiers, variables, and the predicates M(s), C(s), and E(s). a. There is an engineering student who is a math major. b. Every computer science student is an engineering stu-

dent. c. No computer science students are engineering students. d. Some computer science students are also math majors. e. Some computer science students are engineering stu-

dents and some are not.

19. Consider the following statement:

∀ integers n, if n2 is even then n is even. Which of the following are equivalent ways of expressing this statement? a. All integers have even squares and are even. b. Given any integer whose square is even, that integer is

itself even. c. For all integers, there are some whose square is even. d. Any integer with an even square is even. e. If the square of an integer is even, then that integer is

even. f. All even integers have even squares.

20.H Rewrite the following statement informally in at least two different ways without using variables or the symbol ∀ or the words “for all.”

∀ real numbers x, if x is positive, then the square root of x is positive.

21. Rewrite the following statements so that the quantifier trails the rest of the sentence. a. For any graph G, the total degree of G is even. b. For any isosceles triangle T , the base angles of T are

equal. c. There exists a prime number p such that p is even. d. There exists a continuous function f such that f is not

differentiable.

22. Rewrite each of the following statements in the form “∀ x , if then .” a. All Java programs have at least 5 lines. b. Any valid argument with true premises has a true con-

clusion.

23. Rewrite each of the following statements in the two forms “∀x , if then ” and “∀ x , ” (without an if-then). a. All equilateral triangles are isosceles. b. Every computer science student needs to take data struc-

tures.

24. Rewrite the following statements in the two forms “∃ x such that ” and “∃x such that and .” a. Some hatters are mad. b. Some questions are easy.

25. The statement “The square of any rational number is ratio- nal” can be rewritten formally as “For all rational numbers x , x2 is rational” or as “For all x , if x is rational then x2

is rational.” Rewrite each of the following statements in the two forms “∀ x , ” and “∀x , if , then

” or in the two forms “∀ x and y, ” and “∀x and y, if , then .” a. The reciprocal of any nonzero fraction is a fraction. b. The derivative of any polynomial function is a polyno-

mial function. c. The sum of the angles of any triangle is 180◦. d. The negative of any irrational number is irrational. e. The sum of any two even integers is even. f. The product of any two fractions is a fraction.

26. Consider the statement “All integers are rational numbers but some rational numbers are not integers.” a. Write this statement in the form “∀x , if then

, but ∃ x such that .” b. Let Ratl(x) be “x is a rational number” and Int(x) be “x

is an integer.” Write the given statement formally using only the symbols Ratl(x), Int(x),∀, ∃,∧,∨,∼, and→.

27. Refer to the picture of Tarski’s world given in Example 3.1.13. Let Above(x, y) mean that x is above y (but pos- sibly in a different column). Determine the truth or falsity

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

108 Chapter 3 The Logic of Quantified Statements

of each of the following statements. Give reasons for your answers. a. ∀u, Circle(u)→ Gray(u). b. ∀u, Gray(u)→ Circle(u). c. ∃y such that Square(y) ∧ Above(y, d). d. ∃z such that Triangle(z) ∧ Above( f, z).

In 28–30, rewrite each statement without using quantifiers or variables. Indicate which are true and which are false, and jus- tify your answers as best as you can.

28. Let the domain of x be the set D of objects discussed in mathematics courses, and let Real(x) be “x is a real number,” Pos(x) be “x is a positive real number,” Neg(x) be “x is a negative real number,” and Int(x) be “x is an integer.” a. Pos(0) b. ∀x , Real(x) ∧ Neg(x) → Pos(−x). c. ∀x , Int(x)→ Real(x). d. ∃x such that Real(x) ∧ ∼Int(x).

29. Let the domain of x be the set of geometric figures in the plane, and let Square(x) be “x is a square” and Rect(x) be “x is a rectangle.” a. ∃x such that Rect(x) ∧ Square(x). b. ∃x such that Rect(x) ∧ ∼Square(x). c. ∀x , Square(x)→ Rect(x).

30. Let the domain of x be the set Z of integers, and let Odd(x) be “x is odd,” Prime(x) be “x is prime,” and Square(x) be

“x is a perfect square.” (An integer n is said to be a perfect square if, and only if, it equals the square of some integer. For example, 25 is a perfect square because 25 = 52.) a. ∃x such that Prime(x) ∧ ∼Odd(x). b. ∀x , Prime(x)→∼Square(x). c. ∃x such that Odd(x) ∧ Square(x).

31.H In any mathematics or computer science text other than this book, find an example of a statement that is universal but is implicitly quantified. Copy the statement as it appears and rewrite it making the quantification explicit. Give a com- plete citation for your example, including title, author, pub- lisher, year, and page number.

32. Let R be the domain of the predicate variable x . Which of the following are true and which are false? Give counter examples for the statements that are false. a. x > 2 ⇒ x > 1 b. x > 2 ⇒ x2 > 4 c. x2 > 4 ⇒ x > 2 d. x2 > 4 ⇔ |x | > 2

33. Let R be the domain of the predicate variables a, b, c, and d. Which of the following are true and which are false? Give counterexamples for the statements that are false. a. a > 0 and b > 0 ⇒ ab > 0 b. a < 0 and b < 0 ⇒ ab < 0 c. ab = 0 ⇒ a = 0 or b = 0 d. a < b and c < d ⇒ ac < bd

Answers for Test Yourself 1. {x ∈ D | P(x)}; the set of all x in D such that P(x) 2. Possible answers: for all, for every, for any, for each, for arbitrary, given any 3. Possible answers: there exists, there exist, there exists at least one, for some, for at least one, we can find a 4. true; every x in D (Alternative answers: all x in D; each x in D) 5. true; at least one x in D (Alternative answer: some x in D)

3.2 Predicates and Quantified Statements II TOUCHSTONE: Stand you both forth now: stroke your chins, and swear by your beards that I am a knave. CELIA: By our beards—if we had them—thou art. TOUCHSTONE: By my knavery—if I had it—then I were; but if you swear by that that is not, you are not forsworn. — William Shakespeare, As You Like It

This section continues the discussion of predicates and quantified statements begun in Section 3.1. It contains the rules for negating quantified statements; an exploration of the relation among ∀, ∃,∧, and∨; an introduction to the concept of vacuous truth of universal statements; examples of variants of universal conditional statements; and an extension of the meaning of necessary, sufficient, and only if to quantified statements.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.2 Predicates and Quantified Statements II 109

Negations of Quantified Statements Consider the statement “All mathematicians wear glasses.” Many people would say that its negation is “No mathematicians wear glasses,” but if even one mathematician does not wear glasses, then the sweeping statement that all mathematicians wear glasses is false. So a correct negation is “There is at least one mathematician who does not wear glasses.”

The general form of the negation of a universal statement follows immediately from the definitions of negation and of the truth values for universal and existential statements.

Theorem 3.2.1 Negation of a Universal Statement

The negation of a statement of the form

∀x in D, Q(x) is logically equivalent to a statement of the form

∃x in D such that ∼Q(x). Symbolically, ∼(∀x ∈ D, Q(x)) ≡ ∃x ∈ D such that ∼Q(x).

Thus

The negation of a universal statement (“all are”) is logically equivalent to an existential statement (“some are not” or “there is at least one that is not”).

Note that when we speak of logical equivalence for quantified statements, we mean that the statements always have identical truth values no matter what predicates are sub- stituted for the predicate symbols and no matter what sets are used for the domains of the predicate variables.

Now consider the statement “Some snowflakes are the same.” What is its negation? For this statement to be false means that not a single snowflake is the same as any other. In other words, “No snowflakes are the same,” or “All snowflakes are different.”

The general form for the negation of an existential statement follows immediately from the definitions of negation and of the truth values for existential and universal statements.

Theorem 3.2.2 Negation of an Existential Statement

The negation of a statement of the form

∃x in D such that Q(x) is logically equivalent to a statement of the form

∀x in D,∼Q(x). Symbolically, ∼(∃x ∈ D such that Q(x)) ≡ ∀x ∈ D,∼Q(x).

Thus

The negation of an existential statement (“some are”) is logically equivalent to a universal statement (“none are” or “all are not”).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

110 Chapter 3 The Logic of Quantified Statements

Example 3.2.1 Negating Quantified Statements

Write formal negations for the following statements:

a. ∀ primes p, p is odd. b. ∃ a triangle T such that the sum of the angles of T equals 200◦.

Solution

a. By applying the rule for the negation of a ∀ statement, you can see that the answer is ∃ a prime p such that p is not odd.

b. By applying the rule for the negation of a ∃ statement, you can see that the answer is ∀ triangles T, the sum of the angles of T does not equal 200◦. ■

You need to exercise special care to avoid mistakes when writing negations of state- ments that are given informally. One way to avoid error is to rewrite the statement for- mally and take the negation using the formal rule.

Example 3.2.2 More Negations

Rewrite the following statement formally. Then write formal and informal negations.

No politicians are honest.

Solution Formal version: ∀ politicians x, x is not honest. Formal negation: ∃ a politician x such that x is honest.

Informal negation: Some politicians are honest. ■

Another way to avoid error when taking negations of statements that are given in informal language is to ask yourself, “What exactly would it mean for the given statement to be false? What statement, if true, would be equivalent to saying that the given statement is false?”

Example 3.2.3 Still More Negations

Write informal negations for the following statements:

a. All computer programs are finite.

b. Some computer hackers are over 40.

c. The number 1,357 is divisible by some integer between 1 and 37.

Solution

a. What exactly would it mean for this statement to be false? The statement asserts that all computer programs satisfy a certain property. So for it to be false, there would have to be at least one computer program that does not satisfy the property. Thus the answer is

There is a computer program that is not finite.

Or: Some computer programs are infinite.

b. This statement is equivalent to saying that there is at least one computer hacker with a certain property. So for it to be false, not a single computer hacker can have that property. Thus the negation is

No computer hackers are over 40.

Or: All computer hackers are 40 or under.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.2 Predicates and Quantified Statements II 111

c. This statement has a trailing quantifier. Written formally it becomes:Note Which is true: the statement in part (c) or its negation? Is 1,357 divisible by some integer between 1 and 37? Or is 1,357 not divisible by any integer between 1 and 37?

∃ an integer n between 1 and 37 such that 1,357 is divisible by n. Its negation is therefore

∀ integers n between 1 and 37; 1,357 is not divisible by n. An informal version of the negation is

The number 1,357 is not divisible by any integer between 1 and 37. ■

! Caution! Just inserting the word not to negate a quantified statement can result in a statement that is ambiguous.

Informal negations of many universal statements can be constructed simply by insert- ing the word not or the words do not at an appropriate place. However, the resulting state- ments may be ambiguous. For example, a possible negation of “All mathematicians wear glasses” is “All mathematicians do not wear glasses.” The problem is that this sentence has two meanings. With the proper verbal stress on the word not, it could be interpreted as the logical negation. (What! You say that all mathematicians wear glasses? Nonsense! All mathematicians do not wear glasses.) On the other hand, stated in a flat tone of voice (try it!), it would mean that all mathematicians are nonwearers of glasses; that is, not a single mathematician wears glasses. This is a much stronger statement than the logical negation: It implies the negation but is not equivalent to it.

Negations of Universal Conditional Statements Negations of universal conditional statements are of special importance in mathematics. The form of such negations can be derived from facts that have already been established.

By definition of the negation of a for all statement,

∼(∀x, P(x) → Q(x)) ≡ ∃x such that ∼(P(x)→ Q(x)). 3.2.1 But the negation of an if-then statement is logically equivalent to an and statement. More precisely,

∼(P(x) → Q(x)) ≡ P(x) ∧ ∼Q(x). 3.2.2 Substituting (3.2.2) into (3.2.1) gives

∼(∀x, P(x) → Q(x)) ≡ ∃x such that (P(x)∧ ∼Q(x)). Written less symbolically, this becomes

Negation of a Universal Conditional Statement

∼(∀x, if P(x) then Q(x)) ≡ ∃x such that P(x) and ∼Q(x).

Example 3.2.4 Negating Universal Conditional Statements

Write a formal negation for statement (a) and an informal negation for statement (b).

a. ∀ people p, if p is blond then p has blue eyes. b. If a computer program has more than 100,000 lines, then it contains a bug.

Solution

a. ∃ a person p such that p is blond and p does not have blue eyes. b. There is at least one computer program that has more than 100,000 lines and does not

contain a bug. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

112 Chapter 3 The Logic of Quantified Statements

The Relation among ∀, ∃, ∧, and ∨ The negation of a for all statement is a there exists statement, and the negation of a there exists statement is a for all statement. These facts are analogous to De Morgan’s laws, which state that the negation of an and statement is an or statement and that the nega- tion of an or statement is an and statement. This similarity is not accidental. In a sense, universal statements are generalizations of and statements, and existential statements are generalizations of or statements.

If Q(x) is a predicate and the domain D of x is the set {x1, x2, . . . , xn}, then the statements

∀x ∈ D, Q(x) and Q(x1) ∧ Q(x2) ∧ · · · ∧ Q(xn) are logically equivalent. For example, let Q(x) be “x ·x = x” and suppose D = {0, 1}. Then

∀x ∈ D, Q(x) can be rewritten as ∀ binary digits x, x ·x = x . This is equivalent to

0 ·0 = 0 and 1 ·1 = 1, which can be rewritten in symbols as

Q(0) ∧ Q(1). Similarly, if Q(x) is a predicate and D = {x1, x2, . . . , xn}, then the statements

∃x ∈ D such that Q(x) and Q(x1) ∨ Q(x2) ∨ · · · ∨ Q(xn) are logically equivalent. For example, let Q(x) be “x + x = x” and suppose D = {0, 1}. Then

∃x ∈ D such that Q(x) can be rewritten as ∃ a binary digit x such that x + x = x . This is equivalent to

0 + 0 = 0 or 1 + 1 = 1, which can be rewritten in symbols as

Q(0) ∨ Q(1).

Vacuous Truth of Universal Statements Suppose a bowl sits on a table and next to the bowl is a pile of five blue and five gray balls, any of which may be placed in the bowl. If three blue balls and one gray ball are placed in the bowl, as shown in Figure 3.2.1(a), the statement “All the balls in the bowl are blue” would be false (since one of the balls in the bowl is gray).

Now suppose that no balls at all are placed in the bowl, as shown in Figure 3.2.1(b). Consider the statement

All the balls in the bowl are blue.

Is this statement true or false? The statement is false if, and only if, its negation is true. And its negation is

There exists a ball in the bowl that is not blue.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.2 Predicates and Quantified Statements II 113

But the only way this negation can be true is for there actually to be a nonblue ball in the bowl. And there is not! Hence the negation is false, and so the statement is true “by default.”

(a) (b)

Figure 3.2.1

In general, a statement of the form

∀x in D, if P(x) then Q(x) is called vacuously true or true by default if, and only if, P(x) is false for every x in D.

By the way, in ordinary language the words in general mean that something is usu- ally, but not always, the case. (In general, I take the bus home, but today I walked.) In mathematics, the words in general are used quite differently. When they occur just after discussion of a particular example (as in the preceding paragraph), they are a signal that what is to follow is a generalization of some aspect of the example that always holds true.

Variants of Universal Conditional Statements Recall from Section 2.2 that a conditional statement has a contrapositive, a converse, and an inverse. The definitions of these terms can be extended to universal conditional statements.

• Definition

Consider a statement of the form: ∀x ∈ D, if P(x) then Q(x). 1. Its contrapositive is the statement: ∀x ∈ D, if ∼Q(x) then ∼P(x). 2. Its converse is the statement: ∀x ∈ D, if Q(x) then P(x). 3. Its inverse is the statement: ∀x ∈ D, if ∼P(x) then ∼Q(x).

Example 3.2.5 Contrapositive, Converse, and Inverse of a Universal Conditional Statement

Write a formal and an informal contrapositive, converse, and inverse for the following statement:

If a real number is greater than 2, then its square is greater than 4.

Solution The formal version of this statement is ∀x ∈ R, if x > 2 then x2 > 4. Contrapositive: ∀x ∈ R, if x2 ≤ 4 then x ≤ 2.

Or: If the square of a real number is less than or equal to 4, then the number is less than or equal to 2.

Converse: ∀x ∈ R, if x2 > 4 then x > 2. Or: If the square of a real number is greater than 4, then the number is greater than 2.

Inverse: ∀x ∈ R, if x ≤ 2 then x2 ≤ 4. Or: If a real number is less than or equal to 2, then the square of the number is less than or equal to 4.

Note that in solving this example, we have used the equivalence of “x ≯ a” and “x ≤ a” for all real numbers x and a. (See page 33.) ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

114 Chapter 3 The Logic of Quantified Statements

In Section 2.2 we showed that a conditional statement is logically equivalent to its contrapositive and that it is not logically equivalent to either its converse or its inverse. The following discussion shows that these facts generalize to the case of universal condi- tional statements and their contrapositives, converses, and inverses.

Let P(x) and Q(x) be any predicates, let D be the domain of x , and consider the statement

∀x ∈ D, if P(x) then Q(x) and its contrapositive

∀x ∈ D, if ∼Q(x) then ∼P(x). Any particular x in D that makes “if P(x) then Q(x)” true also makes “if ∼Q(x) then ∼P(x)” true (by the logical equivalence between p → q and ∼q →∼p). It follows that the sentence “If P(x) then Q(x)” is true for all x in D if, and only if, the sentence “If ∼Q(x) then ∼P(x)” is true for all x in D.

Thus we write the following and say that a universal conditional statement is logically equivalent to its contrapositive:

∀x ∈ D, if P(x) then Q(x) ≡ ∀x ∈ D, if ∼Q(x) then ∼P(x)

In Example 3.2.5 we noted that the statement

∀x ∈ R, if x > 2 then x2 > 4 has the converse ∀x ∈ R, if x2 > 4 then x > 2. Observe that the statement is true whereas its converse is false (since, for instance, (−3)2 = 9 > 4 but −3 ≯ 2). This shows that a universal conditional statement may have a different truth value from its converse. Hence a universal conditional statement is not logically equivalent to its converse. This is written in symbols as follows:

∀x ∈ D, if P(x) then Q(x) ≡/ ∀x ∈ D, if Q(x) then P(x).

In the exercises at the end of this section, you are asked to show similarly that a universal conditional statement is not logically equivalent to its inverse.

∀x ∈ D, if P(x) then Q(x) ≡/ ∀x ∈ D, if ∼P(x) then ∼Q(x).

Necessary and Sufficient Conditions, Only If The definitions of necessary, sufficient, and only if can also be extended to apply to uni- versal conditional statements.

• Definition • “∀x, r(x) is a sufficient condition for s(x)” means “∀x , if r(x) then s(x).” • “∀x, r(x) is a necessary condition for s(x)” means “∀x , if ∼r(x) then ∼s(x)”

or, equivalently, “∀x , if s(x) then r(x).” • “∀x, r(x) only if s(x)” means “∀x , if ∼s(x) then ∼r(x)” or, equivalently, “∀x ,

if r(x) then s(x).”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.2 Predicates and Quantified Statements II 115

Example 3.2.6 Necessary and Sufficient Conditions

Rewrite the following statements as quantified conditional statements. Do not use the word necessary or sufficient. a. Squareness is a sufficient condition for rectangularity.

b. Being at least 35 years old is a necessary condition for being President of the United States.

Solution

a. A formal version of the statement is

∀x , if x is a square, then x is a rectangle. Or, in informal language:

If a figure is a square, then it is a rectangle.

b. Using formal language, you could write the answer as

∀ people x, if x is younger than 35, then x cannot be President of the United States.

Or, by the equivalence between a statement and its contrapositive:

∀ people x, if x is President of the United States, then x is at least 35 years old. ■

Example 3.2.7 Only If

Rewrite the following as a universal conditional statement:

A product of two numbers is 0 only if one of the numbers is 0.

Solution Using informal language, you could write the answer as

If neither of two numbers is 0, then the product of the numbers is not 0.

Or, by the equivalence between a statement and its contrapositive,

If a product of two numbers is 0, then one of the numbers is 0. ■

Test Yourself 1. A negation for “All R have property S” is “There is R

that .”

2. A negation for “Some R have property S” is “ .”

3. A negation for “For all x , if x has property P then x has property Q” is “ .”

4. The converse of “For all x , if x has property P then x has property Q” is “ .”

5. The contrapositive of “For all x , if x has property P then x has property Q” is “ .”

6. The inverse of “For all x , if x has property P then x has property Q” is “ .”

Exercise Set 3.2 1. Which of the following is a negation for “All discrete math-

ematics students are athletic”? More than one answer may be correct. a. There is a discrete mathematics student who is nonath-

letic. b. All discrete mathematics students are nonathletic.

c. There is an athletic person who is a discrete mathematics student.

d. No discrete mathematics students are athletic. e. Some discrete mathematics students are nonathletic. f. No athletic people are discrete mathematics students.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

116 Chapter 3 The Logic of Quantified Statements

2. Which of the following is a negation for “All dogs are loyal”? More than one answer may be correct. a. All dogs are disloyal. b. No dogs are loyal. c. Some dogs are disloyal. d. Some dogs are loyal. e. There is a disloyal animal that is not a dog. f. There is a dog that is disloyal. g. No animals that are not dogs are loyal. h. Some animals that are not dogs are loyal.

3. Write a formal negation for each of the following state- ments: a. ∀ fish x, x has gills. b. ∀ computers c, c has a CPU. c. ∃ a movie m such that m is over 6 hours long. d. ∃ a band b such that b has won at least 10 Grammy

awards.

4. Write an informal negation for each of the following state- ments. Be careful to avoid negations that are ambiguous.

a. All dogs are friendly. b. All people are happy. c. Some suspicions were substantiated. d. Some estimates are accurate.

5. Write a negation for each of the following statements. a. Any valid argument has a true conclusion. b. Every real number is positive, negative, or zero.

6. Write a negation for each of the following statements. a. Sets A and B do not have any points in common. b. Towns P and Q are not connected by any road on the

map.

7. Informal language is actually more complex than formal language. For instance, the sentence “There are no orders from store A for item B” contains the words there are. Is the statement existential? Write an informal negation for the statement, and then write the statement formally using quantifiers and variables.

8. Consider the statement “There are no simple solutions to life’s problems.” Write an informal negation for the state- ment, and then write the statement formally using quanti- fiers and variables.

Write a negation for each statement in 9 and 10.

9. ∀ real numbers x , if x > 3 then x2 > 9. 10. ∀ computer programs P , if P compiles without error mes-

sages, then P is correct.

In each of 11–14 determine whether the proposed negation is correct. If it is not, write a correct negation.

11. Statement: The sum of any two irrational numbers is irrational.

Proposed negation: The sum of any two irrational numbers is rational.

12. Statement: The product of any irrational number and any rational number is irrational.

Proposed negation: The product of any irrational number and any rational number is rational.

13. Statement: For all integers n, if n2 is even then n is even.

Proposed negation: For all integers n, if n2 is even then n is not even.

14. Statement: For all real numbers x1 and x2, if x21 = x22 then x1 = x2.

Proposed negation: For all real numbers x1 and x2, if x21 = x22 then x1 ̸= x2.

15. Let D = {−48, −14, −8, 0, 1, 3, 16, 23, 26, 32, 36}. Determine which of the following statements are true and which are false. Provide counterexamples for those state- ments that are false. a. ∀x ∈ D, if x is odd then x > 0. b. ∀x ∈ D, if x is less than 0 then x is even. c. ∀x ∈ D, if x is even then x ≤ 0. d. ∀x ∈ D, if the ones digit of x is 2, then the tens digit is

3 or 4. e. ∀x ∈ D, if the ones digit of x is 6, then the tens digit is

1 or 2.

In 16–23, write a negation for each statement.

16. ∀ real numbers x , if x2 ≥ 1 then x > 0. 17. ∀ integers d , if 6/d is an integer then d = 3. 18. ∀x ∈ R, if x(x + 1) > 0 then x > 0 or x < −1. 19. ∀n ∈ Z, if n is prime then n is odd or n = 2. 20. ∀ integers a, b and c, if a − b is even and b − c is even,

then a − c is even. 21. ∀ integers n, if n is divisible by 6, then n is divisible by 2

and n is divisible by 3.

22. If the square of an integer is odd, then the integer is odd.

23. If a function is differentiable then it is continuous.

24. Rewrite the statements in each pair in if-then form and indi- cate the logical relationship between them.

a. All the children in Tom’s family are female. All the females in Tom’s family are children.

b. All the integers that are greater than 5 and end in 1, 3, 7, or 9 are prime. All the integers that are greater than 5 and are prime end in 1, 3, 7, or 9.

25. Each of the following statements is true. In each case write the converse of the statement, and give a counterexample showing that the converse is false.

a. If n is any prime number that is greater than 2, then n + 1 is even.

b. If m is any odd integer, then 2m is even. c. If two circles intersect in exactly two points, then they

do not have a common center.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 117

In 26–33, for each statement in the referenced exercise write the converse, inverse, and contrapositive. Indicate as best as you can which among the statement, its converse, its inverse, and its con- trapositive are true and which are false. Give a counterexample for each that is false.

26. Exercise 16 27. Exercise 17

28. Exercise 18 29. Exercise 19

30. Exercise 20 31. Exercise 21

32. Exercise 22 33. Exercise 23

34. Write the contrapositive for each of the following state- ments. a. If n is prime, then n is not divisible by any prime num-

ber between 1 and √

n strictly. (Assume that n is a fixed integer that is greater than 1.)

b. If A and B do not have any elements in common, then they are disjoint. (Assume that A and B are fixed sets.)

35. Give an example to show that a universal conditional state- ment is not logically equivalent to its inverse.

36.✶ If P(x) is a predicate and the domain of x is the set of all real numbers, let R be “∀x ∈ Z, P(x),” let S be “∀x ∈ Q, P(x),” and let T be “∀x ∈ R, P(x).” a. Find a definition for P(x) (but do not use “x ∈ Z”) so

that R is true and both S and T are false. b. Find a definition for P(x) (but do not use “x ∈ Q”) so

that both R and S are true and T is false.

37. Consider the following sequence of digits: 0204. A person claims that all the 1’s in the sequence are to the left of all the 0’s in the sequence. Is this true? Justify your answer. (Hint: Write the claim formally and write a formal negation for it. Is the negation true or false?)

38. True or false? All occurrences of the letter u in Discrete Mathematics are lowercase. Justify your answer.

Rewrite each statement of 39–42 in if-then form.

39. Earning a grade of C− in this course is a sufficient condi- tion for it to count toward graduation.

40. Being divisible by 8 is a sufficient condition for being divis- ible by 4.

41. Being on time each day is a necessary condition for keeping this job.

42. Passing a comprehensive exam is a necessary condition for obtaining a master’s degree.

Use the facts that the negation of a ∀ statement is a ∃ statement and that the negation of an if-then statement is an and statement to rewrite each of the statements 43–46 without using the word necessary or sufficient.

43. Being divisible by 8 is not a necessary condition for being divisible by 4.

44. Having a large income is not a necessary condition for a person to be happy.

45. Having a large income is not a sufficient condition for a person to be happy.

46. Being a polynomial is not a sufficient condition for a func- tion to have a real root.

47. The computer scientists Richard Conway and David Gries once wrote:

The absence of error messages during translation of a computer program is only a necessary and not a sufficient condition for reasonable [program] correctness.

Rewrite this statement without using the words necessary or sufficient.

48. A frequent-flyer club brochure states, “You may select among carriers only if they offer the same lowest fare.” Assuming that “only if” has its formal, logical meaning, does this statement guarantee that if two carriers offer the same lowest fare, the customer will be free to choose between them? Explain.

Answers for Test Yourself 1. some (Alternative answers: at least one; an); does not have property S. 2. No R have property S. 3. There is an x such that x has property P and x does not have property Q. 4. For all x , if x has property Q then x has property P . 5. For all x , if x does not have property Q then x does not have property P . 6. For all x , if x does not have property P then x does not have property Q.

3.3 Statements with Multiple Quantifiers It is not enough to have a good mind. The main thing is to use it well. — René Descartes

Imagine you are visiting a factory that manufactures computer microchips. The factory guide tells you,

There is a person supervising every detail of the production process.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

118 Chapter 3 The Logic of Quantified Statements

Note that this statement contains informal versions of both the existential quantifier there is and the universal quantifier every. Which of the following best describes its meaning?

• There is one single person who supervises all the details of the production process. • For any particular production detail, there is a person who supervises that detail,

but there might be different supervisors for different details.

As it happens, either interpretation could be what the guide meant. (Reread the sentence to be sure you agree!) Taken by itself, his statement is genuinely ambiguous, although other things he may have said (the context for his statement) might have clarified it. In our ordinary lives, we deal with this kind of ambiguity all the time. Usually context helps resolve it, but sometimes we simply misunderstand each other.

In mathematics, formal logic, and computer science, by contrast, it is essential that we all interpret statements in exactly the same way. For instance, the initial stage of software development typically involves careful discussion between a programmer analyst and a client to turn vague descriptions of what the client wants into unambiguous program specifications that client and programmer can mutually agree on.

Because many important technical statements contain both ∃ and ∀, a convention has developed for interpreting them uniformly. When a statement contains more than one quantifier, we imagine the actions suggested by the quantifiers as being performed in the order in which the quantifiers occur. For instance, consider a statement of the form

∀x in set D, ∃y in set E such that x and y satisfy property P(x, y). To show that such a statement is true, you must be able to meet the following challenge:

• Imagine that someone is allowed to choose any element whatsoever from the set D, and imagine that the person gives you that element. Call it x .

• The challenge for you is to find an element y in E so that the person’s x and your y, taken together, satisfy property P(x, y).

Note that because you do not have to specify the y until after the other person has specified the x, you are allowed to find a different value of y for each different x you are given.

Example 3.3.1 Truth of a ∀∃ Statement in a Tarski World Consider the Tarski world shown in Figure 3.3.1.

a

b c

f

i

e g

h

j

d

Figure 3.3.1

Show that the following statement is true in this world:

For all triangles x , there is a square y such that x and y have the same color.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 119

Solution The statement says that no matter which triangle someone gives you, you will be able to find a square of the same color. There are only three triangles, d, f , and i . The following table shows that for each of these triangles a square of the same color can be found.

Given x = choose y = and check that y is the same color as x. d e yes $

f or i h or g yes $ ■

Now consider a statement containing both ∀ and ∃, where the ∃ comes before the ∀: ∃ an x in D such that ∀y in E, x and y satisfy property P(x, y).

To show that a statement of this form is true:

You must find one single element (call it x) in D with the following property:

• After you have found your x , someone is allowed to choose any element whatsoever from E . The person challenges you by giving you that element. Call it y.

• Your job is to show that your x together with the person’s y satisfy property P(x, y).

Note that your x has to work for any y the person gives you; you are not allowed to change your x once you have specified it initially.

Example 3.3.2 Truth of a ∃∀ Statement in a Tarski World Consider again the Tarski world in Figure 3.3.1. Show that the following statement is true: There is a triangle x such that for all circles y, x is to the right of y.

Solution The statement says that you can find a triangle that is to the right of all the circles. Actually, either d or i would work for all of the three circles, a, b, and c, as you can see in the following table.

Choose x = Then, given y = check that x is to the right of y. d or i a yes $

b yes $ c yes $ ■

Here is a summary of the convention for interpreting statements with two different quantifiers:

Interpreting Statements with Two Different Quantifiers

If you want to establish the truth of a statement of the form

∀x in D, ∃y in E such that P(x, y) your challenge is to allow someone else to pick whatever element x in D they wish and then you must find an element y in E that “works” for that particular x .

If you want to establish the truth of a statement of the form

∃x in D such that ∀y in E, P(x, y) your job is to find one particular x in D that will “work” no matter what y in E anyone might choose to challenge you with.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

120 Chapter 3 The Logic of Quantified Statements

Example 3.3.3 Interpreting Multiply-Quantified∗ Statements

A college cafeteria line has four stations: salads, main courses, desserts, and beverages. The salad station offers a choice of green salad or fruit salad; the main course station offers spaghetti or fish; the dessert station offers pie or cake; and the beverage station offers milk, soda, or coffee. Three students, Uta, Tim, and Yuen, go through the line and make the following choices:

Uta: green salad, spaghetti, pie, milk

Tim: fruit salad, fish, pie, cake, milk, coffee

Yuen: spaghetti, fish, pie, soda

These choices are illustrated in Figure 3.3.2.

green salad fruit salad

Salads

spaghetti fish

Main courses

pie cake

Desserts

milk soda coffee

Beverages

Uta

Tim

Yuen

Figure 3.3.2

Write each of following statements informally and find its truth value.

a. ∃ an item I such that ∀ students S, S chose I . b. ∃ a student S such that ∀ items I, S chose I . c. ∃ a student S such that ∀ stations Z , ∃ an item I in Z such that S chose I . d. ∀ students S and ∀ stations Z , ∃ an item I in Z such that S chose I .

Solution

a. There is an item that was chosen by every student. This is true; every student chose pie.

b. There is a student who chose every available item. This is false; no student chose all nine items.

c. There is a student who chose at least one item from every station. This is true; both Uta and Tim chose at least one item from every station.

d. Every student chose at least one item from every station. This is false; Yuen did not choose a salad. ■

∗The term “multiply-quantified” is pronounced MUL-ti-plee QUAN-ti-fied. A multiply-quantified statement is a statement that contains more than one quantifier.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 121

Translating from Informal to Formal Language Most problems are stated in informal language, but solving them often requires translating them into more formal terms.

Example 3.3.4 Translating Multiply-Quantified Statements from Informal to Formal Language

The reciprocal of a real number a is a real number b such that ab = 1. The following two statements are true. Rewrite them formally using quantifiers and variables:

a. Every nonzero real number has a reciprocal.

b. There is a real number with no reciprocal. The number 0 has no reciprocal.

Solution

a. ∀ nonzero real numbers u, ∃ a real number v such that uv = 1. b. ∃ a real number c such that ∀ real numbers d, cd ̸= 1. ■

Example 3.3.5 There Is a Smallest Positive Integer

Recall that every integer is a real number and that real numbers are of three types: posi- tive, negative, and zero (zero being neither positive nor negative). Consider the statement “There is a smallest positive integer.” Write this statement formally using both symbols ∃ and ∀.

Solution To say that there is a smallest positive integer means that there is a positive integer m with the property that no matter what positive integer n a person might pick, m will be less than or equal to n:

∃ a positive integer m such that ∀ positive integers n, m ≤ n. Note that this statement is true because 1 is a positive integer that is less than or equal to every positive integer.

–3–4–5 –2 –1 0 1 2 3 4 5

positive integers

Example 3.3.6 There Is No Smallest Positive Real Number

Imagine any positive real number x on the real number line. These numbers correspond to all the points to the right of 0. Observe that no matter how small x is, the number x/2 will be both positive and less than x .∗

–2 –1 0 1 2x

x 2

∗This can be deduced from the properties of the real numbers given in Appendix A. Because x is positive, 0 < x . Add x to both sides to obtain x < 2x . Then 0 < x < 2x . Now multiply all parts of the inequality by the positive number 1/2. This does not change the direction of the inequality, so 0 < x/2 < x .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

122 Chapter 3 The Logic of Quantified Statements

Thus the following statement is true: “There is no smallest positive real number.” Write this statement formally using both symbols ∀ and ∃.

Solution ∀ positive real numbers x, ∃ a positive real number y such that y < x . ■ Example 3.3.7 The Definition of Limit of a Sequence

The definition of limit of a sequence, studied in calculus, uses both quantifiers ∀ and ∃ and also if-then. We say that the limit of the sequence an as n goes to infinity equals L and write

lim n→∞

an = L if, and only if, the values of an become arbitrarily close to L as n gets larger and larger without bound. More precisely, this means that given any positive number ε, we can find an integer N such that whenever n is larger than N , the number an sits between L − ε and L + ε on the number line.

L – ε L + εL

an must lie in here when n > N

Symbolically:

∀ε > 0, ∃ an integer N such that ∀ integers n, if n > N then L − ε < an < L + ε.

Considering the logical complexity of this definition, it is no wonder that many students find it hard to understand. ■

Ambiguous Language The drawing in Figure 3.3.3 is a famous example of visual ambiguity. When you look at it for a while, you will probably see either a silhouette of a young woman wearing a large hat or an elderly woman with a large nose. Whichever image first pops into your mind,

Figure 3.3.3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 123

try to see how the drawing can be interpreted in the other way. (Hint: The mouth of the elderly woman is the necklace on the young woman.)

Once most people see one of the images, it is difficult for them to perceive the other. So it is with ambiguous language. Once you interpreted the sentence at the beginning of this section in one way, it may have been hard for you to see that it could be understood in the other way. Perhaps you had difficulty even though the two possible meanings were explained, just as many people have difficulty seeing the second interpretation for the drawing even when they are told what to look for.

Although statements written informally may be open to multiple interpretations, we cannot determine their truth or falsity without interpreting them one way or another. Therefore, we have to use context to try to ascertain their meaning as best we can.

Negations of Multiply-Quantified Statements You can use the same rules to negate multiply-quantified statements that you used to negate simpler quantified statements. Recall that

∼(∀x in D, P(x)) ≡ ∃x in D such that ∼P(x).

and

∼(∃x in D such that P(x)) ≡ ∀x in D,∼P(x).

We apply these laws to find

∼(∀x in D, ∃y in E such that P(x, y))

by moving in stages from left to right along the sentence.

First version of negation: ∃x in D such that ∼(∃y in E such that P(x, y)). Final version of negation: ∃x in D such that ∀y in E,∼P(x, y).

Similarly, to find

∼(∃x in D such that ∀y in E, P(x, y)),

we have

First version of negation: ∀x in D,∼(∀y in E, P(x, y)). Final version of negation: ∀x in D, ∃y in E such that ∼P(x, y).

These facts can be summarized as follows:

Negations of Multiply-Quantified Statements

∼(∀ x in D, ∃y in E such that P(x, y)) ≡ ∃x in D such that ∀y in E,∼P(x, y). ∼(∃x in D such that ∀y in E, P(x, y)) ≡ ∀x in D, ∃y in E such that ∼P(x, y).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

124 Chapter 3 The Logic of Quantified Statements

Example 3.3.8 Negating Statements in a Tarski World

Refer to the Tarski world of Figure 3.3.1, which is reprinted here for reference.

a

b c

f

i

e g

h

j

d

Write a negation for each of the following statements, and determine which is true, the given statement or its negation.

a. For all squares x , there is a circle y such that x and y have the same color.

b. There is a triangle x such that for all squares y, x is to the right of y.

Solution

a. First version of negation: ∃ a square x such that ∼(∃ a circle y such that x and y have the same color).

Final version of negation: ∃ a square x such that ∀ circles y, x and y do not have the same color.

The negation is true. Square e is black and no circle is black, so there is a square that does not have the same color as any circle.

b. First version of negation: ∀ triangles x,∼ (∀ squares y, x is to the right of y).

Final version of negation: ∀ triangles x, ∃ a square y such that x is not to the right of y.

The negation is true because no matter what triangle is chosen, it is not to the right of square g (or square j). ■

Order of Quantifiers Consider the following two statements:

∀ people x, ∃ a person y such that x loves y. ∃ a person y such that ∀ people x, x loves y.

Note that except for the order of the quantifiers, these statements are identical. How- ever, the first means that given any person, it is possible to find someone whom that person loves, whereas the second means that there is one amazing individual who is loved by all people. (Reread the statements carefully to verify these interpretations!) The two sentences illustrate an extremely important property about multiply-quantified statements:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 125

In a statement containing both ∀ and ∃, changing the order of the quantifiers usually changes the meaning of the statement.!

Caution! If a statement contains two different quantifiers, reversing their order can change the truth value of the statement to its opposite.

Interestingly, however, if one quantifier immediately follows another quantifier of the same type, then the order of the quantifiers does not affect the meaning. Consider the commutative property of addition of real numbers, for example:

∀ real numbers x and ∀ real numbers y, x + y = y + x . This means the same as

∀ real numbers y and ∀ real numbers x, x + y = y + x . Thus the property can be expressed more briefly as

∀ real numbers x and y, x + y = y + x .

Example 3.3.9 Quantifier Order in a Tarski World

Look again at the Tarski world of Figure 3.3.1. Do the following two statements have the same truth value?

a. For every square x there is a triangle y such that x and y have different colors.

b. There exists a triangle y such that for every square x, x and y have different colors.

Solution Statement (a) says that if someone gives you one of the squares from the Tarski world, you can find a triangle that has a different color. This is true. If someone gives you square g or h (which are gray), you can use triangle d (which is black); if someone gives you square e (which is black), you can use either triangle f or triangle i (which are both gray); and if someone gives you square j (which is blue), you can use triangle d (which is black) or triangle f or i (which are both gray).

Statement (b) says that there is one particular triangle in the Tarski world that has a different color from every one of the squares in the world. This is false. Two of the triangles are gray, but they cannot be used to show the truth of the statement because the Tarski world contains gray squares. The only other triangle is black, but it cannot be used either because there is a black square in the Tarski world.

Thus one of the statements is true and the other is false, and so they have opposite truth values. ■

Formal Logical Notation In some areas of computer science, logical statements are expressed in purely symbolic notation. The notation involves using predicates to describe all properties of variables and omitting the words such that in existential statements. (When you try to figure out the meaning of a formal statement, however, it is helpful to think the words such that to yourself each time they are appropriate.) The formalism also depends on the following facts:

“∀x in D, P(x)” can be written as“∀x(x in D → P(x)),” and “∃x in D such that P(x)” can be written as “∃x(x in D ∧ P(x)).”

We illustrate the use of these facts in Example 3.3.10.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

126 Chapter 3 The Logic of Quantified Statements

Example 3.3.10 Formalizing Statements in a Tarski World

Consider once more the Tarski world of Figure 3.3.1:

a

b c

f

i

e g

h

j

d

Let Triangle(x), Circle(x), and Square(x) mean “x is a triangle,” “x is a circle,” and “x is a square”; let Blue(x), Gray(x), and Black(x) mean “x is blue,” “x is gray,” and “x is black”; let RightOf(x, y), Above(x, y), and SameColorAs(x, y) mean “x is to the right of y,” “x is above y,” and “x has the same color as y”; and use the notation x = y to denote the predicate “x is equal to y”. Let the common domain D of all variables be the set of all the objects in the Tarski world. Use formal, logical notation to write each of the following statements, and write a formal negation for each statement.

a. For all circles x, x is above f .

b. There is a square x such that x is black.

c. For all circles x , there is a square y such that x and y have the same color.

d. There is a square x such that for all triangles y, x is to right of y.

Solution a. Statement: ∀x(Circle(x) → Above(x, f )).

Negation: ∼(∀x(Circle(x)→ Above(x, f ))) ≡ ∃x ∼ (Circle(x)→ Above(x, f ))

by the law for negating a ∀ statement ≡ ∃x(Circle(x) ∧ ∼Above(x, f ))

by the law of negating an if-then statement

b. Statement: ∃x(Square(x) ∧ Black(x)). Negation: ∼(∃x(Square(x) ∧ Black(x)))

≡ ∀x ∼ (Square(x) ∧ Black(x)) by the law for negating a ∃ statement

≡ ∀x(∼Square(x) ∨ ∼Black(x)) by De Morgan’s law

c. Statement: ∀x(Circle(x) → ∃y(Square(y) ∧ SameColor(x, y))). Negation: ∼(∀x(Circle(x)→ ∃y(Square(y) ∧ SameColor(x, y))))

≡ ∃x ∼ (Circle(x)→ ∃y(Square(y) ∧ SameColor(x, y))) by the law for negating a ∀ statement

≡ ∃x(Circle(x) ∧ ∼(∃y(Square(y) ∧ SameColor(x, y)))) by the law for negating an if-then statement

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 127

≡ ∃x(Circle(x) ∧ ∀y(∼(Square(y) ∧ SameColor(x, y)))) by the law for negating a ∃ statement

≡ ∃x(Circle(x) ∧ ∀y(∼Square(y) ∨ ∼SameColor(x, y))) by De Morgan’s law

d. Statement: ∃x(Square(x) ∧ ∀y(Triangle(y) → RightOf(x, y))). Negation: ∼(∃x(Square(x) ∧ ∀y(Triangle(y)→ RightOf(x, y))))

≡ ∀x ∼ (Square(x) ∧ ∀y(Triangle(x) → RightOf(x, y))) by the law for negating a ∃ statement

≡ ∀x(∼Square(x) ∨ ∼(∀y(Triangle(y)→ RightOf(x, y)))) by De Morgan’s law

≡ ∀x(∼Square(x) ∨ ∃y(∼(Triangle(y)→ RightOf(x, y)))) by the law for negating a ∀ statement

≡ ∀x(∼Square(x) ∨ ∃y(Triangle(y) ∧ ∼RightOf(x, y))) by the law for negating an if-then statement

The disadvantage of the fully formal notation is that because it is complex and somewhat remote from intuitive understanding, when we use it, we may make errors that go unrecognized. The advantage, however, is that operations, such as taking nega- tions, can be made completely mechanical and programmed on a computer. Also, when we become comfortable with formal manipulations, we can use them to check our intu- ition, and then we can use our intuition to check our formal manipulations. Formal logical notation is used in branches of computer science such as artificial intelligence, program verification, and automata theory and formal languages.

Taken together, the symbols for quantifiers, variables, predicates, and logical connectives make up what is known as the language of first-order logic. Even though this language is simpler in many respects than the language we use every day, learning it requires the same kind of practice needed to acquire any foreign language.

Prolog The programming language Prolog (short for programming in logic) was developed in France in the 1970s by A. Colmerauer and P. Roussel to help programmers working in the field of artificial intelligence. A simple Prolog program consists of a set of statements describing some situation together with questions about the situation. Built into the lan- guage are search and inference techniques needed to answer the questions by deriving the answers from the given statements. This frees the programmer from the necessity of having to write separate programs to answer each type of question. Example 3.3.11 gives a very simple example of a Prolog program.

Example 3.3.11 A Prolog Program

Consider the following picture, which shows colored blocks stacked on a table.

g

b1

w1

w2

b2

b3

g

b1 w1

= gray block

= blue block 1

= blue block 2

= blue block 3

= white block 1

= white block 2w2b2

b3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

128 Chapter 3 The Logic of Quantified Statements

The following are statements in Prolog that describe this picture and ask two questions about it.

Note Different Prolog implementations follow different conventions as to how to represent constant, variable, and predicate names and forms of questions and answers. The conventions used here are similar to those of Edinburgh Prolog.

isabove(g, b1) color(g, gray) color(b3, blue)

isabove(b1, w1) color(b1, blue) color(w1, white)

isabove(w2, b2) color(b2, blue) color(w2, white)

isabove(b2, b3) isabove(X, Z) if isabove(X, Y ) and isabove(Y, Z)

?color(b1, blue) ?isabove(X, w1)

The statements “isabove(g, b1)” and “color(g, gray)” are to be interpreted as “g is above b1” and “g is colored gray”. The statement “isabove(X, Z) if isabove(X, Y ) and isabove(Y, Z)” is to be interpreted as “For all X , Y , and Z , if X is above Y and Y is above Z , then X is above Z .” The program statement

?color(b1, blue)

is a question asking whether block b1 is colored blue. Prolog answers this by writing

Yes.

The statement

?isabove(X, w1)

is a question asking for which blocks X the predicate “X is above w1” is true. Prolog answers by giving a list of all such blocks. In this case, the answer is

X = b1, X = g. Note that Prolog can find the solution X = b1 by merely searching the original set of given facts. However, Prolog must infer the solution X = g from the following statements:

isabove(g, b1),

isabove(b1, w1),

isabove(X, Z) if isabove(X, Y ) and isabove(Y, Z).

Write the answers Prolog would give if the following questions were added to the pro- gram above.

a. ?isabove(b2, w1) b. ?color(w1, X) c. ?color(X , blue)

Solution

a. The question means “Is b2 above w1?”; so the answer is “No.”

b. The question means “For what colors X is the predicate ‘w1 is colored X ’ true?”; so the answer is “X = white.”

c. The question means “For what blocks is the predicate ‘X is colored blue’ true?”; so the answer is “X = b1,” “X = b2,” and “X = b3.” ■

Test Yourself 1. To establish the truth of a statement of the form “∀x in

D, ∃y in E such that P(x, y),” you imagine that some- one has given you an element x from D but that you have no control over what that element is. Then you need to find with the property that the x the person gave you together with the you subsequently found satisfy .

2. To establish the truth of a statement of the form “∃x in D such that ∀y in E , P(x, y),” you need to find so that no matter what a person might subsequently give you,

will be true.

3. Consider the statement “∀x , ∃y such that P(x, y), a property involving x and y, is true.” A negation for this statement is “ .”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 129

4. Consider the statement “∃x such that ∀y, P(x, y), a prop- erty involing x and y, is true.” A negation for this statement is “ .”

5. Suppose P(x, y) is some property involving x and y, and suppose the statement“∀x in D, ∃y in E such that P(x, y)”

is true. Then the statement “∃x in D such that ∀y in E , P(x, y)”

a. is true. b. is false. c. may be true or may be false.

Exercise Set 3.3 1. Let C be the set of cities in the world, let N be the set

of nations in the world, and let P(c, n) be “c is the capi- tal city of n.” Determine the truth values of the following statements. a. P(Tokyo, Japan) b. P(Athens, Egypt) c. P(Paris, France) d. P(Miami, Brazil)

2. Let G(x, y) be “x2 > y.” Indicate which of the following statements are true and which are false. a. G(2, 3) b. G(1, 1) c. G (

1 2 ,

1 2

) d. G(−2, 2)

3. The following statement is true: “∀ nonzero numbers x, ∃ a real number y such that xy = 1.” For each x given below, find a y to make the predicate “xy = 1” true. a. x = 2 b. x = −1 c. x = 3/4

4. The following statement is true: “∀ real numbers x, ∃ an integer n such that n > x .”∗ For each x given below, find an n to make the predicate “n > x” true. a. x = 15.83 b. x = 108 c. x = 101010

The statements in exercises 5–8 refer to the Tarski world given in Example 3.3.1. Explain why each is true.

5. For all circles x there is a square y such that x and y have the same color.

6. For all squares x there is a circle y such that x and y have different colors and y is above x .

7. There is a triangle x such that for all squares y, x is above y.

8. There is a triangle x such that for all circles y, y is above x .

9. Let D = E = {−2,−1, 0, 1, 2}. Explain why the following statements are true. a. ∀x in D, ∃y in E such that x + y = 0. b. ∃x in D such that ∀y in E, x + y = y.

10. This exercise refers to Example 3.3.3. Determine whether each of the following statements is true or false. a. ∀ students S, ∃ a dessert D such that S chose D. b. ∀ students S, ∃ a salad T such that S chose T . c. ∃ a dessert D such that ∀ students S, S chose D. d. ∃ a beverage B such that ∀ students D, D chose B. e. ∃ an item I such that ∀ students S, S did not choose I . f. ∃ a station Z such that ∀ students S, ∃ an item I such

that S chose I from Z .

11. Let S be the set of students at your school, let M be the set of movies that have ever been released, and let V (s, m) be “student s has seen movie m.” Rewrite each of the follow- ing statements without using the symbol ∀, the symbol ∃, or variables. a. ∃s ∈ S such that V (s, Casablanca). b. ∀s ∈ S, V (s, Star Wars). c. ∀s ∈ S, ∃m ∈ M such that V (s, m). d. ∃m ∈ M such that ∀s ∈ S, V (s, m). e. ∃s ∈ S, ∃t ∈ S, and ∃m ∈ M such that s ̸= t and

V (s, m) ∧ V (t, m). f. ∃s ∈ S and ∃t ∈ S such that s ̸= t and ∀m ∈ M,

V (s, m)→ V (t, m). 12. Let D = E = {−2,−1, 0, 1, 2}. Write negations for each

of the following statements and determine which is true, the given statement or its negation. a. ∀x in D, ∃y in E such that x + y = 1. b. ∃x in D such that ∀y in E, x + y = −y. c. ∀x in D, ∃y in E such that xy ≥ y. d. ∃x in D such that ∀y in E , x ≤ y.

In each of 13–19, (a) rewrite the statement in English without using the symbol ∀ or ∃ or variables and expressing your answer as simply as possible, and (b) write a negation for the statement.

13. ∀ colors C, ∃ an animal A such that A is colored C . 14. ∃ a book b such that ∀ people p, p has read b. 15. ∀ odd integers n, ∃ an integer k such that n = 2k + 1. 16. ∃ a real number u such that ∀ real numbers v, uv = v. 17. ∀r ∈ Q, ∃ integers a and b such that r = a/b. 18. ∀x ∈ R, ∃ a real number y such that x + y = 0. 19. ∃x ∈ R such that for all real numbers y, x + y = 0. 20. Recall that reversing the order of the quantifiers in a state-

ment with two different quantifiers may change the truth value of the statement—but it does not necessarily do so. All the statements in the pairs on the next page refer to the Tarski world of Figure 3.3.1. In each pair, the order of the quantifiers is reversed but everything else is the same. For each pair, determine whether the statements have the same or opposite truth values. Justify your answers.

∗This is called the Archimedean principle because it was first formulated (in geometric terms) by the great Greek mathematician Archimedes of Syracuse, who lived from about 287 to 212 B.C.E.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

130 Chapter 3 The Logic of Quantified Statements

a. (1) For all squares y there is a triangle x such that x and y have different color. (2) There is a triangle x such that for all squares y, x and y have different colors.

b. (1) For all circles y there is a square x such that x and y have the same color. (2) There is a square x such that for all circles y, x and y have the same color.

21. For each of the following equations, determine which of the following statements are true: (1) For all real numbers x , there exists a real number y

such that the equation is true. (2) There exists a real number x , such that for all real num-

bers y, the equation is true. Note that it is possible for both statements to be true or for both to be false.

a. 2x + y = 7 b. y + x = x + y c. x2 − 2xy + y2 = 0 d. (x − 5)(y − 1) = 0 e. x2 + y2 = −1

In 22 and 23, rewrite each statement without using variables or the symbol ∀ or ∃. Indicate whether the statement is true or false. 22. a. ∀ real numbers x, ∃ a real number y such that x + y = 0.

b. ∃ a real number y such that ∀ real numbers x, x + y = 0. 23. a. ∀ nonzero real numbers r, ∃ a real number s such that

rs = 1. b. ∃ a real number r such that ∀ nonzero real numbers

s, rs = 1. 24. Use the laws for negating universal and existential state-

ments to derive the following rules: a. ∼(∀x ∈ D(∀y ∈ E(P(x, y))))

≡ ∃x ∈ D(∃y ∈ E(∼P(x, y))) b. ∼(∃x ∈ D(∃y ∈ E(P(x, y))))

≡ ∀x ∈ D(∀y ∈ E(∼P(x, y)))

Each statement in 25–28 refers to the Tarski world of Figure 3.3.1. For each, (a) determine whether the statement is true or false and justify your answer, (b) write a negation for the state- ment (referring, if you wish, to the result in exercise 24).

25. ∀ circles x and ∀ squares y, x is above y. 26. ∀ circles x and ∀ triangles y, x is above y. 27. ∃ a circle x and ∃ a square y such that x is above y and x

and y have different colors.

28. ∃ a triangle x and ∃ a square y such that x is above y and x and y have the same color.

For each of the statements in 29 and 30, (a) write a new state- ment by interchanging the symbols ∀ and ∃, and (b) state which is true: the given statement, the version with interchanged quan- tifiers, neither, or both.

29. ∀x ∈ R, ∃y ∈ R such that x < y.

30. ∃x ∈ R such that ∀y ∈ R− (the set of negative real numbers), x > y.

31. Consider the statement “Everybody is older than some- body.” Rewrite this statement in the form “∀ people x, ∃ .”

32. Consider the statement “Somebody is older than every- body.” Rewrite this statement in the form “∃ a person x such that ∀ .”

In 33–39, (a) rewrite the statement formally using quantifiers and variables, and (b) write a negation for the statement.

33. Everybody loves somebody.

34. Somebody loves everybody.

35. Everybody trusts somebody.

36. Somebody trusts everybody.

37. Any even integer equals twice some integer.

38. Every action has an equal and opposite reaction.

39. There is a program that gives the correct answer to every question that is posed to it.

40. In informal speech most sentences of the form “There is every ” are intended to be understood as

meaning “∀ ∃ ,” even though the existen- tial quantifier there is comes before the universal quantifier every. Note that this interpretation applies to the following well-known sentences. Rewrite them using quantifiers and variables. a. There is a sucker born every minute. b. There is a time for every purpose under heaven.

41. Indicate which of the following statements are true and which are false. Justify your answers as best you can. a. ∀x ∈ Z+, ∃y ∈ Z+ such that x = y + 1. b. ∀x ∈ Z, ∃y ∈ Z such that x = y + 1. c. ∃x ∈ R such that ∀y ∈ R, x = y + 1. d. ∀x ∈ R+, ∃y ∈ R+ such that xy = 1. e. ∀x ∈ R, ∃y ∈ R such that xy = 1. f. ∀x ∈ Z+ and ∀y ∈ Z+, ∃z ∈ Z+ such that z = x − y. g. ∀x ∈ Z and ∀y ∈ Z, ∃z ∈ Z such that z = x − y. h. ∃u ∈ R+ such that ∀v ∈ R+, uv < v.

42. Write the negation of the definition of limit of a sequence given in Example 3.3.7.

43. The following is the definition for limx→a f (x) = L: For all real numbers ε > 0, there exists a real number δ > 0 such that for all real numbers x, if a− δ < x < a + δ and x ̸= a then L− ε < f(x) < L + ε. Write what it means for limx→a f (x) ̸= L . In other words, write the negation of the definition.

44. The notation ∃! stands for the words “there exists a unique.” Thus, for instance, “∃! x such that x is prime and x is even”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Statements with Multiple Quantifiers 131

means that there is one and only one even prime number. Which of the following statements are true and which are false? Explain. a. ∃! real number x such that ∀ real numbers y, xy = y. b. ∃! integer x such that 1/x is an integer. c. ∀ real numbers x, ∃! real number y such that x + y = 0.

45.✶ Suppose that P(x) is a predicate and D is the domain of x . Rewrite the statement “∃! x ∈ D such that P(x)” without using the symbol ∃!. (See exercise 44 for the meaning of ∃!.)

In 46–54, refer to the Tarski world given in Figure 3.1.1, which is printed again here for reference. The domains of all variables consist of all the objects in the Tarski world. For each state- ment, (a) indicate whether the statement is true or false and jus- tify your answer, (b) write the given statement using the formal logical notation illustrated in Example 3.3.10, and (c) write the negation of the given statement using the formal logical notation of Example 3.3.10.

ba

d

f

i

k

e

h

j

c

g

46. There is a triangle x such that for all squares y, x is above y.

47. There is a triangle x such that for all circles y, x is above y.

48. For all circles x , there is a square y such that y is to the right of x .

49. For every object x , there is an object y such that x ̸= y and x and y have different colors.

50. For every object x , there is an object y such that if x ̸= y then x and y have different colors.

51. There is an object y such that for all objects x , if x ̸= y then x and y have different colors.

52. For all circles x and for all triangles y, x is to the right of y.

53. There is a circle x and there is a square y such that x and y have the same color.

54. There is a circle x and there is a triangle y such that x and y have the same color.

Let P(x) and Q(x) be predicates and suppose D is the domain of x . In 55–58, for the statement forms in each pair, determine whether (a) they have the same truth value for every choice of P(x), Q(x), and D, or (b) there is a choice of P(x), Q(x), and D for which they have opposite truth values.

55. ∀x ∈ D, (P(x) ∧ Q(x)), and (∀x ∈ D, P(x)) ∧ (∀x ∈ D, Q(x))

56. ∃x ∈ D, (P(x) ∧ Q(x)), and (∃x ∈ D, P(x)) ∧ (∃x ∈ D, Q(x))

57. ∀x ∈ D, (P(x) ∨ Q(x)), and (∀x ∈ D, P(x)) ∨ (∀x ∈ D, Q(x))

58. ∃x ∈ D, (P(x) ∨ Q(x)), and (∃x ∈ D, P(x)) ∨ (∃x ∈ D, Q(x))

In 59–61, find the answers Prolog would give if the following questions were added to the program given in Example 3.3.11.

59. a. ?isabove(b1, w1) b. ?color(X , white) c. ?isabove(X, b3)

60. a. ?isabove(w1, g) b. ?color(w2, blue) c. ?isabove(X, b1)

61. a. ?isabove(w2, b3) b. ?color(X , gray) c. ?isabove(g, X )

Answers for Test Yourself 1. an element y in E ; y; P(x, y) 2. an element x in D; y in E ; P(x, y) 3. ∃x such that ∀y, the property P(x, y) is false. 4. ∀x , ∃y such that the property P(x, y) is false. 5. The answer is (c): the truth or falsity of a statement in which the quantifiers are reversed depends on the nature of the property involving x and y.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

132 Chapter 3 The Logic of Quantified Statements

3.4 Arguments with Quantified Statements The only complete safeguard against reasoning ill, is the habit of reasoning well; familiarity with the principles of correct reasoning; and practice in applying those principles. — John Stuart Mill

The rule of universal instantiation (in-stan-she-AY-shun) says the following:

If some property is true of everything in a set, then it is true of any particular thing in the set.

Use of the words universal instantiation indicates that the truth of a property in a particu- lar case follows as a special instance of its more general or universal truth. The validity of this argument form follows immediately from the definition of truth values for a universal statement. One of the most famous examples of universal instantiation is the following:

All men are mortal.

Socrates is a man.

∴ Socrates is mortal.

Universal instantiation is the fundamental tool of deductive reasoning. Mathematical formulas, definitions, and theorems are like general templates that are used over and over in a wide variety of particular situations. A given theorem says that such and such is true for all things of a certain type. If, in a given situation, you have a particular object of that type, then by universal instantiation, you conclude that such and such is true for that particular object. You may repeat this process 10, 20, or more times in a single proof or problem solution.

As an example of universal instantiation, suppose you are doing a problem that requires you to simplify rk+1·r, where r is a particular real number and k is a particular integer. You know from your study of algebra that the following universal statements are true:

1. For all real numbers x and all integers m and n, xm ·xn = xm+n . 2. For all real numbers x, x1 = x . So you proceed as follows:

rk+1·r = rk+1·r1 Step 1 = r (k+1)+1 Step 2 = rk+2 by basic algebra.

The reasoning behind step 1 and step 2 is outlined as follows.

Step 1: For all real numbers x, x1 = x . universal truth r is a particular real number. particular instance

∴ r1 = r. conclusion Step 2: For all real numbers x and all integers

m and n, xm·xn = xm+n. universal truth r is a particular real number and k + 1 and 1 are particular integers. particular instance

∴ rk+1·r1 = r (k+1)+1. conclusion Both arguments are examples of universal instantiation.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 133

Universal Modus Ponens The rule of universal instantiation can be combined with modus ponens to obtain the valid form of argument called universal modus ponens.

Universal Modus Ponens

Formal Version Informal Version

∀x , if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true. P(a) for a particular a. a makes P(x) true.

∴ Q(a). ∴ a makes Q(x) true.

Note that the first, or major, premise of universal modus ponens could be written “All things that make P(x) true make Q(x) true,” in which case the conclusion would follow by universal instantiation alone. However, the if-then form is more natural to use in the majority of mathematical situations.

Example 3.4.1 Recognizing Universal Modus Ponens

Rewrite the following argument using quantifiers, variables, and predicate symbols. Is this argument valid? Why?

If an integer is even, then its square is even.

k is a particular integer that is even.

∴ k2 is even. Solution The major premise of this argument can be rewritten as

∀x, if x is an even integer then x2 is even. Let E(x) be “x is an even integer,” let S(x) be “x2 is even,” and let k stand for a particular integer that is even. Then the argument has the following form:

∀x, if E(x) then S(x). E(k), for a particular k.

∴ S(k). This argument has the form of universal modus ponens and is therefore valid. ■

Example 3.4.2 Drawing Conclusions Using Universal Modus Ponens

Write the conclusion that can be inferred using universal modus ponens.

If T is any right triangle with hypotenuse c and legs a and b, then c2 = a2 + b2. The triangle shown at the right is a right triangle with both legs equal to 1 and hypotenuse c.

∴ .

Pythagorean theorem

1

c 1

Solution c2 = 12 + 12 = 2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

134 Chapter 3 The Logic of Quantified Statements

Note that if you take the nonnegative square root of both sides of this equation, you obtain c =

√ 2. This shows that there is a line segment whose length is

√ 2. Section 4.7

contains a proof that √

2 is not a rational number. ■

Use of Universal Modus Ponens in a Proof In Chapter 4 we discuss methods of proving quantified statements. Here is a proof that the sum of any two even integers is even. It makes use of the definition of even integer, namely, that an integer is even if, and only if, it equals twice some integer. (Or, more formally: ∀ integers x , x is even if, and only if, ∃ an integer k such that x = 2k.)

Suppose m and n are particular but arbitrarily chosen even integers. Then m = 2r for some integer r,(1) and n = 2s for some integer s.(2) Hence

m + n = 2r + 2s by substitution = 2(r + s)(3) by factoring out the 2.

Now r + s is an integer,(4) and so 2(r + s) is even.(5) Thus m + n is even.

Note The logical principle of existential instantiation says that if we know something exists, we may give it a name. This principle, discussed further in Section 4.1 allows us to give the integers the names r and s.

The following expansion of the proof shows how each of the numbered steps is justified by arguments that are valid by universal modus ponens.

(1) If an integer is even, then it equals twice some integer. m is a particular even integer.

∴ m equals twice some integer r . (2) If an integer is even, then it equals twice some integer.

n is a particular even integer. ∴ n equals twice some integer s.

(3) If a quantity is an integer, then it is a real number. r and s are particular integers.

∴ r and s are real numbers. For all a, b, and c, if a, b, and c are real numbers, then ab + ac = a(b + c). 2, r , and s are particular real numbers.

∴ 2r + 2s = 2(r + s). (4) For all u and v, if u and v are integers, then u + v is an integer.

r and s are two particular integers. ∴ r + s is an integer.

(5) If a number equals twice some integer, then that number is even. 2(r + s) equals twice the integer r + s.

∴ 2(r + s) is even.

Of course, the actual proof that the sum of even integers is even does not explic- itly contain the sequence of arguments given above. (Heaven forbid!) And, in fact, peo- ple who are good at analytical thinking are normally not even conscious that they are reasoning in this way. But that is because they have absorbed the method so completely that it has become almost as automatic as breathing.

Universal Modus Tollens Another crucially important rule of inference is universal modus tollens. Its validity results from combining universal instantiation with modus tollens. Universal modus tol- lens is the heart of proof of contradiction, which is one of the most important methods of mathematical argument.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 135

Universal Modus Tollens

Formal Version Informal Version

∀x , if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true. ∼Q(a), for a particular a. a does not make Q(x) true.

∴ ∼P(a). ∴ a does not make P(x) true.

Example 3.4.3 Recognizing the Form of Universal Modus Tollens

Rewrite the following argument using quantifiers, variables, and predicate symbols. Write the major premise in conditional form. Is this argument valid? Why?

All human beings are mortal.

Zeus is not mortal.

∴ Zeus is not human. Solution The major premise can be rewritten as

∀x, if x is human then x is mortal. Let H(x) be “x is human,” let M(x) be “x is mortal,” and let Z stand for Zeus. The argument becomes

∀x, if H(x) then M(x) ∼M(Z)

∴ ∼H(Z). This argument has the form of universal modus tollens and is therefore valid. ■

Example 3.4.4 Drawing Conclusions Using Universal Modus Tollens

Write the conclusion that can be inferred using universal modus tollens.

All professors are absent-minded.

Tom Hutchins is not absent-minded.

∴ . Solution Tom Hutchins is not a professor. ■

Proving Validity of Arguments with Quantified Statements

The intuitive definition of validity for arguments with quantified statements is the same as for arguments with compound statements. An argument is valid if, and only if, the truth of its conclusion follows necessarily from the truth of its premises. The formal definition is as follows:

• Definition To say that an argument form is valid means the following: No matter what particular predicates are substituted for the predicate symbols in its premises, if the resulting premise statements are all true, then the conclusion is also true. An argument is called valid if, and only if, its form is valid.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

136 Chapter 3 The Logic of Quantified Statements

As already noted, the validity of universal instantiation follows immediately from the definition of the truth value of a universal statement. General formal proofs of validity of arguments in the predicate calculus are beyond the scope of this book. We give the proof of the validity of universal modus ponens as an example to show that such proofs are possible and to give an idea of how they look.

Universal modus ponens asserts that

∀x, if P(x) then Q(x). P(a) for a particular a.

∴ Q(a). To prove that this form of argument is valid, suppose the major and minor premises are both true. [We must show that the conclusion “Q(a)” is also true.] By the minor premise, P(a) is true for a particular value of a. By the major premise and universal instantiation, the statement “If P(a) then Q(a)” is true for that particular a. But by modus ponens, since the statements “If P(a) then Q(a)” and “P(a)” are both true, it follows that Q(a) is true also. [This is what was to be shown.]

The proof of validity given above is abstract and somewhat subtle. We include the proof not because we expect that you will be able to make up such proofs yourself at this stage of your study. Rather, it is intended as a glimpse of a more advanced treatment of the subject, which you can try your hand at in exercises 35 and 36 at the end of this section if you wish.

One of the paradoxes of the formal study of logic is that the laws of logic are used to prove that the laws of logic are valid!

In the next part of this section we show how you can use diagrams to analyze the validity or invalidity of arguments that contain quantified statements. Diagrams do not provide totally rigorous proofs of validity and invalidity, and in some complex settings they may even be confusing, but in many situations they are helpful and convincing.

Using Diagrams to Test for Validity Consider the statement

All integers are rational numbers.

Or, formally,

∀ integers n, n is a rational number. Picture the set of all integers and the set of all rational numbers as disks. The truth of the given statement is represented by placing the integers disk entirely inside the rationals disk, as shown in Figure 3.4.1.

rational numbers

integers

Figure 3.4.1

Because the two statements “∀x ∈ D, Q(x)” and “∀x , if x is in D then Q(x)” are logi- cally equivalent, both can be represented by diagrams like the foregoing.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 137

Perhaps the first person to use diagrams like these to analyze arguments was the German mathematician and philosopher Gottfried Wilhelm Leibniz. Leibniz (LIPE-nits) was far ahead of his time in anticipating modern symbolic logic. He also developed the main ideas of the differential and integral calculus at approximately the same time as (and independently of) Isaac Newton (1642–1727).

Cu lv

er Pi

ct ur

es

G. W. Leibniz (1646–1716)

To test the validity of an argument diagrammatically, represent the truth of both premises with diagrams. Then analyze the diagrams to see whether they necessarily rep- resent the truth of the conclusion as well.

Example 3.4.5 Using a Diagram to Show Validity

Use diagrams to show the validity of the following syllogism:

All human beings are mortal.

Zeus is not mortal.

∴ Zeus is not a human being. Solution The major premise is pictured on the left in Figure 3.4.2 by placing a disk labeled

“human beings” inside a disk labeled “mortals.” The minor premise is pictured on the right in Figure 3.4.2 by placing a dot labeled “Zeus” outside the disk labeled “mortals.”

human beings

mortals

Major premise

mortals

Minor premise

Zeus

Figure 3.4.2

The two diagrams fit together in only one way, as shown in Figure 3.4.3.

human beings

mortals

Zeus

Figure 3.4.3

Since the Zeus dot is outside the mortals disk, it is necessarily outside the human beings disk. Thus the truth of the conclusion follows necessarily from the truth of the premises. It is impossible for the premises of this argument to be true and the conclusion false; hence the argument is valid. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

138 Chapter 3 The Logic of Quantified Statements

Example 3.4.6 Using Diagrams to Show Invalidity

Use a diagram to show the invalidity of the following argument:

All human beings are mortal.

Felix is mortal.

∴ Felix is a human being. Solution The major and minor premises are represented diagrammatically in Figure 3.4.4.

human beings

mortals

Major premise

mortals

Minor premise

Felix

Figure 3.4.4

All that is known is that the Felix dot is located somewhere inside the mortals disk. Where it is located with respect to the human beings disk cannot be determined. Either one of the situations shown in Figure 3.4.5 might be the case.

human beings human beings

mortals

(a)

mortals

(b)

Felix

Felix

Figure 3.4.5

The conclusion “Felix is a human being” is true in the first case but not in the second (Felix might, for example, be a cat). Because the conclusion does not necessarily follow from the premises, the argument is invalid. ■

! Caution! Be careful when using diagrams to test for validity! For instance, in this example if you put the diagrams for the premises together to obtain only Figure 3.4.5(a) and not Figure 3.4.5(b), you would conclude erroneously that the argument was valid.

The argument of Example 3.4.6 would be valid if the major premise were replaced by its converse. But since a universal conditional statement is not logically equivalent to its converse, such a replacement cannot, in general, be made. We say that this argument exhibits the converse error.

Converse Error (Quantified Form)

Formal Version Informal Version

∀x , if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true. Q(a) for a particular a. a makes Q(x) true.

∴ P(a). ← invalid conclusion

∴ a makes P(x) true. ← invalid conclusion

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 139

The following form of argument would be valid if a conditional statement were logi- cally equivalent to its inverse. But it is not, and the argument form is invalid. We say that it exhibits the inverse error. You are asked to show the invalidity of this argument form in the exercises at the end of this section.

Inverse Error (Quantified Form)

Formal Version Informal Version

∀x , if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true. ∼P(a), for a particular a. a does not make P(x) true.

∴ ∼Q(a). ← invalid conclusion

∴ a does not make Q(x) true. ← invalid conclusion

Example 3.4.7 An Argument with “No”

Use diagrams to test the following argument for validity:

No polynomial functions have horizontal asymptotes.

This function has a horizontal asymptote.

∴ This function is not a polynomial function. Solution A good way to represent the major premise diagrammatically is shown in Figure

3.4.6, two disks—a disk for polynomial functions and a disk for functions with horizontal asymptotes—that do not overlap at all. The minor premise is represented by placing a dot labeled “this function” inside the disk for functions with horizontal asymptotes.

polynomial functions functions with

horizontal asymptotes

this function

Figure 3.4.6

The diagram shows that “this function” must lie outside the polynomial functions disk, and so the truth of the conclusion necessarily follows from the truth of the premises. Hence the argument is valid. ■

An alternative approach to this example is to transform the statement “No polynomial functions have horizontal asymptotes” into the equivalent form “∀x , if x is a polynomial function, then x does not have a horizontal asymptote.” If this is done, the argument can be seen to have the form

∀x, if P(x) then Q(x). ∼Q(a), for a particular a.

∴∼P(a). where P(x) is “x is a polynomial function” and Q(x) is “x does not have a horizontal asymptote.” This is valid by universal modus tollens.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

140 Chapter 3 The Logic of Quantified Statements

Creating Additional Forms of Argument Universal modus ponens and modus tollens were obtained by combining universal instan- tiation with modus ponens and modus tollens. In the same way, additional forms of argu- ments involving universally quantified statements can be obtained by combining universal instantiation with other of the valid argument forms given in Section 2.3. For instance, in Section 2.3 the argument form called transitivity was introduced:

p → q q → r

∴ p → r This argument form can be combined with universal instantiation to obtain the following valid argument form.

Universal Transitivity

Formal Version Informal Version

∀x P(x) → Q(x). Any x that makes P(x) true makes Q(x) true. ∀x Q(x) → R(x). Any x that makes Q(x) true makes R(x) true.

∴ ∀x P(x) → R(x). ∴ Any x that makes P(x) true makes R(x) true.

Example 3.4.8 Evaluating an Argument for Tarski’s World

The following argument refers to the kind of arrangement of objects of various types and colors described in Examples 3.1.13 and 3.3.1. Reorder and rewrite the premises to show that the conclusion follows as a valid consequence from the premises.

1. All the triangles are blue.

2. If an object is to the right of all the squares, then it is above all the circles.

3. If an object is not to the right of all the squares, then it is not blue.

∴ All the triangles are above all the circles. Solution It is helpful to begin by rewriting the premises and the conclusion in if-then form:

1. ∀x , if x is a triangle, then x is blue. 2. ∀x , if x is to the right of all the squares, then x is above all the circles. 3. ∀x , if x is not to the right of all the squares, then x is not blue. ∴ ∀x , if x is a triangle, then x is above all the circles.

The goal is to reorder the premises so that the conclusion of each is the same as the hypothesis of the next. Also, the hypothesis of the argument’s conclusion should be the same as the hypothesis of the first premise, and the conclusion of the argument’s conclusion should be the same as the conclusion of the last premise. To achieve this goal, it may be necessary to rewrite some of the statements in contrapositive form.

In this example you can see that the first premise should remain where it is, but the second and third premises should be interchanged. Then the hypothesis of the argument is the same as the hypothesis of the first premise, and the conclusion of the argument’s conclusion is the same as the conclusion of the third premise. But the hypotheses and

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 141

conclusions of the premises do not quite line up. This is remedied by rewriting the third premise in contrapositive form.

Thus the premises and conclusion of the argument can be rewritten as follows:

1. ∀x , if x is a triangle, then x is blue. 3. ∀x , if x is blue, then x is to the right of all the squares. 2. ∀x , if x is to the right of all the squares, then x is above all the circles. ∴ ∀x , if x is a triangle, then x is above all the circles. The validity of this argument follows easily from the validity of universal transitivity. Putting 1 and 3 together and using universal transitivity gives that

4. ∀x , if x is a triangle, then x is to the right of all the squares.

And putting 4 together with 2 and using universal transitivity gives that

∀x, if x is a triangle, then x is above all the circles, which is the conclusion of the argument. ■

Remark on the Converse and Inverse Errors One reason why so many people make converse and inverse errors is that the forms of the resulting arguments would be valid if the major premise were a biconditional rather than a simple conditional. And, as we noted in Section 2.2, many people tend to conflate biconditionals and conditionals.

Consider, for example, the following argument:

All the town criminals frequent the Den of Iniquity bar.

John frequents the Den of Iniquity bar.

∴ John is one of the town criminals. The conclusion of this argument is invalid—it results from making the converse error.

Therefore, it may be false even when the premises of the argument are true. This type of argument attempts unfairly to establish guilt by association.

The closer, however, the major premise comes to being a biconditional, the more likely the conclusion is to be true. If hardly anyone but criminals frequents the bar and John also frequents the bar, then it is likely (though not certain) that John is a criminal. On the basis of the given premises, it might be sensible to be suspicious of John, but it would be wrong to convict him.

A variation of the converse error is a very useful reasoning tool, provided that it is used with caution. It is the type of reasoning that is used by doctors to make medical diagnoses and by auto mechanics to repair cars. It is the type of reasoning used to generate explanations for phenomena. It goes like this: If a statement of the form

For all x, if P(x) then Q(x)

is true, and if

Q(a) is true, for a particular a,

then check out the statement P(a); it just might be true. For instance, suppose a doctor knows that

For all x, if x has pneumonia, then x has a fever and chills, coughs deeply, and feels exceptionally tired and miserable.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

142 Chapter 3 The Logic of Quantified Statements

And suppose the doctor also knows that

John has a fever and chills, coughs deeply, and feels exceptionally tired and miserable.

On the basis of these data, the doctor concludes that a diagnosis of pneumonia is a strong possibility, though not a certainty. The doctor will probably attempt to gain further sup- port for this diagnosis through laboratory testing that is specifically designed to detect pneumonia. Note that the closer a set of symptoms comes to being a necessary and suf- ficient condition for an illness, the more nearly certain the doctor can be of his or her diagnosis.

This form of reasoning has been named abduction by researchers working in artificial intelligence. It is used in certain computer programs, called expert systems, that attempt to duplicate the functioning of an expert in some field of knowledge.

Test Yourself 1. The rule of universal instantiation says that if some property

is true for in a domain, then it is true for .

2. If the first two premises of universal modus ponens are writ- ten as “If x makes P(x) true, then x makes Q(x) true” and “For a particular value of a ,” then the conclusion can be written as “ .”

3. If the first two premises of universal modus tollens are writ- ten as “If x makes P(x) true, then xmakes Q(x) true” and

“For a particular value of a ,” then the conclusion can be written as “ .”

4. If the first two premises of universal transitivity are written as “Any x that makes P(x) true makes Q(x) true” and “Any x that makes Q(x) true makes R(x) true,” then the conclu- sion can be written as “ .”

5. Diagrams can be helpful in testing an argument for validity. However, if some possible configurations of the premises are not drawn, a person could conclude that an argument was when it was actually .

Exercise Set 3.4 1. Let the following law of algebra be the first statement of an

argument: For all real numbers a and b,

(a + b)2 = a2 + 2ab + b2. Suppose each of the following statements is, in turn, the second statement of the argument. Use universal instantia- tion or universal modus ponens to write the conclusion that follows in each case. a. a = x and b = y are particular real numbers. b. a = fi and b = f j are particular real numbers. c. a = 3u and b = 5v are particular real numbers. d. a = g(r) and b = g(s) are particular real numbers. e. a = log(t1) and b = log(t2) are particular real numbers.

Use universal instantiation or universal modus ponens to fill in valid conclusions for the arguments in 2–4.

2. If an integer n equals 2 ·k and k is an integer, then n is even. 0 equals 2 ·0 and 0 is an integer.

∴ . 3. For all real numbers a, b, c, and d , if b ̸= 0 and d ̸= 0,

then a/b + c/d = (ad + bc)/bd. a = 2, b = 3, c = 4, and d = 5 are particular real numbers such that b ̸= 0 and d ̸= 0.

∴ .

4. ∀ real numbers r , a, and b, if r is positive, then (ra)b = rab. r = 3, a = 1/2, and b = 6 are particular real numbers such that r is positive.

∴ .

Use universal modus tollens to fill in valid conclusions for the arguments in 5 and 6.

5. All irrational numbers are real numbers 1 0 is not a real number.∴ .

6. If a computer program is correct, then compilation of the program does not produce error messages. Compilation of this program produces error messages.

∴ .

Some of the arguments in 7–18 are valid by universal modus ponens or universal modus tollens; others are invalid and exhibit the converse or the inverse error. State which are valid and which are invalid. Justify your answers.

7. All healthy people eat an apple a day. Keisha eats an apple a day.

∴ Keisha is a healthy person.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Arguments with Quantified Statements 143

8. All freshmen must take writing. Caroline is a freshman.

∴ Caroline must take writing. 9. All healthy people eat an apple a day.

Herbert is not a healthy person. ∴ Herbert does not eat an apple a day.

10. If a product of two numbers is 0, then at least one of the numbers is 0. For a particular number x , neither (2x + 1) nor (x − 7) equals 0.

∴ The product (2x + 1)(x − 7) is not 0. 11. All cheaters sit in the back row.

Monty sits in the back row. ∴ Monty is a cheater.

12. All honest people pay their taxes. Darth is not honest.

∴ Darth does not pay his taxes. 13. For all students x , if x studies discrete mathematics, then

x is good at logic. Tarik studies discrete mathematics.

∴ Tarik is good at logic. 14. If compilation of a computer program produces error

messages, then the program is not correct. Compilation of this program does not produce error messages.

∴ This program is correct. 15. Any sum of two rational numbers is rational.

The sum r + s is rational. ∴ The numbers r and s are both rational.

16. If a number is even, then twice that number is even. The number 2n is even, for a particular number n.

∴ The particular number n is even. 17. If an infinite series converges, then the terms go to 0.

The terms of the infinite series ∞∑

n=1

1 n

go to 0.

∴ The infinite series ∞∑

n=1

1 n

converges.

18. If an infinite series converges, then its terms go to 0.

The terms of the infinite series ∞∑

n=1

n n + 1 do not go to 0.

∴ The infinite series ∞∑

n=1

n n + 1 does not converge.

19. Rewrite the statement “No good cars are cheap” in the form “∀x , if P(x) then ∼Q(x).” Indicate whether each of the following arguments is valid or invalid, and justify your answers. a. No good car is cheap.

A Rimbaud is a good car. ∴ A Rimbaud is not cheap.

b. No good car is cheap. A Simbaru is not cheap.

∴ A Simbaru is a good car. c. No good car is cheap.

A VX Roadster is cheap. ∴ A VX Roadster is not good.

d. No good car is cheap. An Omnex is not a good car.

∴ An Omnex is cheap. 20. a. Use a diagram to show that the following argument can

have true premises and a false conclusion.

All dogs are carnivorous. Aaron is not a dog.

∴ Aaron is not carnivorous. b. What can you conclude about the validity or invalidity

of the following argument form? Explain how the result from part (a) leads to this conclusion.

∀x, if P(x) then Q(x). ∼P(a) for a particular a.

∴ ∼Q(a). Indicate whether the arguments in 21–27 are valid or invalid. Support your answers by drawing diagrams.

21. All people are mice. All mice are mortal.

∴ All people are mortal. 22. All discrete mathematics students can tell a valid

argument from an invalid one. All thoughtful people can tell a valid argument from an invalid one.

∴ All discrete mathematics students are thoughtful. 23. All teachers occasionally make mistakes.

No gods ever make mistakes. ∴ No teachers are gods.

24. No vegetarians eat meat. All vegans are vegetarian.

∴ No vegans eat meat. 25. No college cafeteria food is good.

No good food is wasted. ∴ No college cafeteria food is wasted.

26. All polynomial functions are differentiable. All differentiable functions are continuous.

∴ All polynomial functions are continuous. 27. [Adapted from Lewis Carroll.]

Nothing intelligible ever puzzles me. Logic puzzles me.

∴ Logic is unintelligible.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

144 Chapter 3 The Logic of Quantified Statements

In exercises 28–32, reorder the premises in each of the arguments to show that the conclusion follows as a valid con- sequence from the premises. It may be helpful to rewrite the statements in if-then form and replace some statements by their contrapositives. Exercises 28–30 refer to the kinds of Tarski worlds discussed in Example 3.1.13 and 3.3.1. Exercises 31 and 32 are adapted from Symbolic Logic by Lewis Carroll.∗

28. 1. Every object that is to the right of all the blue objects is above all the triangles.

2. If an object is a circle, then it is to the right of all the blue objects.

3. If an object is not a circle, then it is not gray. ∴ All the gray objects are above all the triangles.

29. 1. All the objects that are to the right of all the triangles are above all the circles.

2. If an object is not above all the black objects, then it is not a square.

3. All the objects that are above all the black objects are to the right of all the triangles.

∴ All the squares are above all the circles.

30. 1. If an object is above all the triangles, then it is above all the blue objects.

2. If an object is not above all the gray objects, then it is not a square.

3. Every black object is a square. 4. Every object that is above all the gray objects is above

all the triangles. ∴ If an object is black, then it is above all the blue objects.

31. 1. I trust every animal that belongs to me. 2. Dogs gnaw bones. 3. I admit no animals into my study unless they will beg

when told to do so. 4. All the animals in the yard are mine. 5. I admit every animal that I trust into my study.

∗Lewis Carroll, Symbolic Logic (New York: Dover, 1958), pp. 118, 120, 123.

6. The only animals that are really willing to beg when told to do so are dogs.

∴ All the animals in the yard gnaw bones.

32. 1. When I work a logic example without grumbling, you may be sure it is one I understand.

2. The arguments in these examples are not arranged in regular order like the ones I am used to.

3. No easy examples make my head ache. 4. I can’t understand examples if the arguments are not

arranged in regular order like the ones I am used to. 5. I never grumble at an example unless it gives me a

headache. ∴ These examples are not easy.

In 33 and 34 a single conclusion follows when all the given premises are taken into consideration, but it is difficult to see because the premises are jumbled up. Reorder the premises to make it clear that a conclusion follows logically, and state the valid conclusion that can be drawn. (It may be helpful to rewrite some of the statements in if-then form and to replace some state- ments by their contrapositives.)

33. 1. No birds except ostriches are at least 9 feet tall. 2. There are no birds in this aviary that belong to anyone

but me. 3. No ostrich lives on mince pies. 4. I have no birds less than 9 feet high.

34. 1. All writers who understand human nature are clever. 2. No one is a true poet unless he can stir the human heart. 3. Shakespeare wrote Hamlet. 4. No writer who does not understand human nature can

stir the human heart. 5. None but a true poet could have written Hamlet.

35.✶ Derive the validity of universal modus tollens from the validity of universal instantiation and modus tollens.

36.✶ Derive the validity of universal form of part(a) of the elim- ination rule from the validity of universal instantiation and the valid argument called elimination in Section 2.3.

Answers for Test Yourself 1. all elements; any particular element in the domain (Or: each individual element of the domain) 2. P(a) is true; Q(a) is true 3. Q(a) is false; P(a) is false 4. Any x that makes P(x) true makes R(x) true. 5. valid; invalid (Or: invalid; valid).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

145

CHAPTER 4

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

The underlying content of this chapter is likely to be familiar to you. It consists of proper- ties of integers (whole numbers), rational numbers (integer fractions), and real numbers. The underlying theme of this chapter is the question of how to determine the truth or falsity of a mathematical statement.

Here is an example involving a concept used frequently in computer science. Given any real number x , the floor of x , or greatest integer in x , denoted ⌊x⌋, is the largest integer that is less than or equal to x . On the number line, ⌊x⌋ is the integer immediately to the left of x (or equal to x if x is, itself, an integer). Thus ⌊2.3⌋ = 2, ⌊12.99999⌋ = 12, and ⌊−1.5⌋ = −2. Consider the following two questions: 1. For any real number x , is ⌊x − 1⌋ = ⌊x⌋ − 1? 2. For any real numbers x and y, is ⌊x − y⌋ = ⌊x⌋ − ⌊y⌋? Take a few minutes to try to answer these questions for yourself.

It turns out that the answer to (1) is yes, whereas the answer to (2) is no. Are these the answers you got? If not, don’t worry. In Section 4.5 you will learn the techniques you need to answer these questions and more. If you did get the correct answers, congratulations! You have excellent mathematical intuition. Now ask yourself, “How sure am I of my answers? Were they plausible guesses or absolute certainties? Was there any difference in certainty between my answers to (1) and (2)? Would 1 have been willing to bet a large sum of money on the correctness of my answers?”

One of the best ways to think of a mathematical proof is as a carefully reasoned argument to convince a skeptical listener (often yourself) that a given statement is true. Imagine the listener challenging your reasoning every step of the way, constantly asking, “Why is that so?” If you can counter every possible challenge, then your proof as a whole will be correct.

As an example, imagine proving to someone not very familiar with mathematical notation that if x is a number with 5x + 3 = 33, then x = 6. You could argue as follows:

If 5x + 3 = 33, then 5x + 3 minus 3 will equal 33− 3 since subtracting the same number from two equal quantities gives equal results. But 5x + 3 minus 3 equals 5x because adding 3 to 5x and then subtracting 3 just leaves 5x . Also, 33− 3 = 30. Hence 5x = 30. This means that x is a number which when multiplied by 5 equals 30. But the only number with this property is 6. Therefore, if 5x + 3 = 33 then x = 6. Of course there are other ways to phrase this proof, depending on the level of math-

ematical sophistication of the intended reader. In practice, mathematicians often omit

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

146 Chapter 4 Elementary Number Theory and Methods of Proof

reasons for certain steps of an argument when they are confident that the reader can easily supply them. When you are first learning to write proofs, however, it is better to err on the side of supplying too many reasons rather than too few. All too frequently, when even the best mathematicians carefully examine some “details” in their arguments, they discover that those details are actually false. One of the most important reason’s for requiring proof in mathematics is that writing a proof forces us to become aware of weaknesses in our arguments and in the unconscious assumptions we have made.

Sometimes correctness of a mathematical argument can be a matter of life or death. Suppose, for example, that a mathematician is part of a team charged with designing a new type of airplane engine, and suppose that the mathematician is given the job of determining whether the thrust delivered by various engine types is adequate. If you knew that the mathematician was only fairly sure, but not positive, of the correctness of his analysis, you would probably not want to ride in the resulting aircraft.

At a certain point in Lewis Carroll’s Alice in Wonderland (see exercise 28 in Section 2.2), the March Hare tells Alice to “say what you mean.” In other words, she should be precise in her use of language: If she means a thing, then that is exactly what she should say. In this chapter, perhaps more than in any other mathematics course you have ever taken, you will find it necessary to say what you mean. Precision of thought and language is essential to achieve the mathematical certainty that is needed if you are to have complete confidence in your solutions to mathematical problems.

4.1 Direct Proof and Counterexample I: Introduction

Mathematics, as a science, commenced when first someone, probably a Greek, proved propositions about “any” things or about “some” things without specification of definite particular things. — Alfred North Whitehead, 1861–1947

Both discovery and proof are integral parts of problem solving. When you think you have discovered that a certain statement is true, try to figure out why it is true. If you succeed, you will know that your discovery is genuine. Even if you fail, the process of trying will give you insight into the nature of the problem and may lead to the discovery that the statement is false. For complex problems, the interplay between discovery and proof is not reserved to the end of the problem-solving process but, rather, is an important part of each step.

Assumptions

• In this text we assume a familiarity with the laws of basic algebra, which are listed in Appendix A.

• We also use the three properties of equality: For all objects A, B, and C , (1) A = A, (2) if A = B then B = A, and (3) if A = B and B = C , then A = C .

• In addition, we assume that there is no integer between 0 and 1 and that the set of all integers is closed under addition, subtraction, and multiplication. This means that sums, differences, and products of integers are integers.

• Of course, most quotients of integers are not integers. For example, 3 ÷ 2, which equals 3/2, is not an integer, and 3 ÷ 0 is not even a number.

The mathematical content of this section primarily concerns even and odd integers and prime and composite numbers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 147

Definitions In order to evaluate the truth or falsity of a statement, you must understand what the statement is about. In other words, you must know the meanings of all terms that occur in the statement. Mathematicians define terms very carefully and precisely and consider it important to learn definitions virtually word for word.

• Definitions An integer n is even if, and only if, n equals twice some integer. An integer n is odd if, and only if, n equals twice some integer plus 1.

Symbolically, if n is an integer, then

n is even ⇔ ∃ an integer k such that n = 2k. n is odd ⇔ ∃ an integer k such that n = 2k + 1.

It follows from the definition that if you are doing a problem in which you happen to know that a certain integer is even, you can deduce that it has the form 2 · (some integer). Conversely, if you know in some situation that an integer equals 2 · (some integer), then you can deduce that the integer is even.

Know a particular n has the form integer n is even.

deduce−−−−−→ 2 · (some integer). Know n has the form n is even. 2 · (some integer).

deduce−−−−−→

Example 4.1.1 Even and Odd Integers

Use the definitions of even and odd to justify your answers to the following questions.

a. Is 0 even?

b. Is −301 odd? c. If a and b are integers, is 6a2b even?

d. If a and b are integers, is 10a + 8b + 1 odd? e. Is every integer either even or odd?

Solution

a. Yes, 0 = 2 ·0. b. Yes, −301 = 2(−151) + 1. c. Yes, 6a2b = 2(3a2b), and since a and b are integers, so is 3a2b (being a product of

integers).

d. Yes, 10a + 8b + 1 = 2(5a + 4b) + 1, and since a and b are integers, so is 5a + 4b (being a sum of products of integers).

e. The answer is yes, although the proof is not obvious. (Try giving a reason yourself.) We will show in Section 4.4 that this fact results from another fact known as the quotient-remainder theorem. ■

The integer 6, which equals 2 ·3, is a product of two smaller positive integers. On the other hand, 7 cannot be written as a product of two smaller positive integers; its only

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

148 Chapter 4 Elementary Number Theory and Methods of Proof

positive factors are 1 and 7. A positive integer, such as 7, that cannot be written as a product of two smaller positive integers is called prime.

• Definition An integer n is prime if, and only if, n > 1 and for all positive integers r and s, if n = rs, then either r or s equals n. An integer n is composite if, and only if, n > 1 and n = rs for some integers r and s with 1 < r < n and 1 < s < n.

In symbols: n is prime ⇔ ∀ positive integers r and s, if n = rs

then either r = 1 and s = n or r = n and s = 1. n is composite ⇔ ∃ positive integers r and s such that n = rs

and 1 < r < n and 1 < s < n.

Example 4.1.2 Prime and Composite Numbers

a. Is 1 prime?

b. Is every integer greater than 1 either prime or composite?

c. Write the first six prime numbers.

d. Write the first six composite numbers.

Solution

a. No. A prime number is required to be greater than 1.Note The reason for not allowing 1 to be prime is discussed in Section 4.3. b. Yes. Let n be any integer that is greater than 1. Consider all pairs of positive integers

r and s such that n = rs. There exist at least two such pairs, namely r = n and s = 1 and r = 1 and s = n. Moreover, since n = rs, all such pairs satisfy the inequalities 1 ≤ r ≤ n and 1 ≤ s ≤ n. If n is prime, then the two displayed pairs are the only ways to write n as rs. Otherwise, there exists a pair of positive integers r and s such that n = rs and neither r nor s equals either 1 or n. Therefore, in this case 1 < r < n and 1 < s < n, and hence n is composite.

c. 2, 3, 5, 7, 11, 13

d. 4, 6, 8, 9, 10, 12 ■

Proving Existential Statements According to the definition given in Section 3.1, a statement in the form

∃x ∈ D such that Q(x)

is true if, and only if,

Q(x) is true for at least one x in D.

One way to prove this is to find an x in D that makes Q(x) true. Another way is to give a set of directions for finding such an x . Both of these methods are called constructive proofs of existence.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 149

Example 4.1.3 Constructive Proofs of Existence

a. Prove the following: ∃ an even integer n that can be written in two ways as a sum of two prime numbers.

b. Suppose that r and s are integers. Prove the following: ∃ an integer k such that 22r + 18s = 2k.

Solution

a. Let n = 10. Then 10 = 5 + 5 = 3 + 7 and 3, 5, and 7 are all prime numbers. b. Let k = 11r + 9s. Then k is an integer because it is a sum of products of integers; and

by substitution, 2k = 2(11r + 9s), which equals 22r + 18s by the distributive law of algebra. ■

A nonconstructive proof of existence involves showing either (a) that the existence of a value of x that makes Q(x) true is guaranteed by an axiom or a previously proved theorem or (b) that the assumption that there is no such x leads to a contradiction. The disadvantage of a nonconstructive proof is that it may give virtually no clue about where or how x may be found. The widespread use of digital computers in recent years has led to some dissatisfaction with this aspect of nonconstructive proofs and to increased efforts to produce constructive proofs containing directions for computer calculation of the quantity in question.

Disproving Universal Statements by Counterexample To disprove a statement means to show that it is false. Consider the question of disproving a statement of the form

∀x in D, if P(x) then Q(x). Showing that this statement is false is equivalent to showing that its negation is true. The negation of the statement is existential:

∃x in D such that P(x) and not Q(x). But to show that an existential statement is true, we generally give an example, and because the example is used to show that the original statement is false, we call it a coun- terexample. Thus the method of disproof by counterexample can be written as follows:

Disproof by Counterexample

To disprove a statement of the form “∀x ∈ D, if P(x) then Q(x),” find a value of x in D for which the hypothesis P(x) is true and the conclusion Q(x) is false. Such an x is called a counterexample.

Example 4.1.4 Disproof by Counterexample

Disprove the following statement by finding a counterexample:

∀ real numbers a and b, if a2 = b2 then a = b. Solution To disprove this statement, you need to find real numbers a and b such that the

hypothesis a2 = b2 is true and the conclusion a = b is false. The fact that both positive

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

150 Chapter 4 Elementary Number Theory and Methods of Proof

and negative integers have positive squares helps in the search. If you flip through some possibilities in your mind, you will quickly see that 1 and −1 will work (or 2 and −2, or 0.5 and −0.5, and so forth).

Statement: ∀ real numbers a and b, if a2 = b2, then a = b. Counterexample: Let a = 1 and b = −1. Then a2 = 12 = 1 and b2 = (−1)2 = 1, and so a2 = b2. But a ̸= b since 1 ̸= −1.

It is a sign of intelligence to make generalizations. Frequently, after observing a prop- erty to hold in a large number of cases, you may guess that it holds in all cases. You may, however, run into difficulty when you try to prove your guess. Perhaps you just have not figured out the key to the proof. But perhaps your guess is false. Consequently, when you are having serious difficulty proving a general statement, you should interrupt your efforts to look for a counterexample. Analyzing the kinds of problems you are encoun- tering in your proof efforts may help in the search. It may even happen that if you find a counterexample and therefore prove the statement false, your understanding may be suf- ficiently clarified that you can formulate a more limited but true version of the statement. For instance, Example 4.1.4 shows that it is not always true that if the squares of two numbers are equal, then the numbers are equal. However, it is true that if the squares of two positive numbers are equal, then the numbers are equal.

Proving Universal Statements The vast majority of mathematical statements to be proved are universal. In discussing how to prove such statements, it is helpful to imagine them in a standard form:

∀x ∈ D, if P(x) then Q(x). Sections 1.1 and 3.1 give examples showing how to write any universal statement in this form. When D is finite or when only a finite number of elements satisfy P(x), such a statement can be proved by the method of exhaustion.

Example 4.1.5 The Method of Exhaustion

Use the method of exhaustion to prove the following statement:

∀n ∈ Z, if n is even and 4 ≤ n ≤ 26, then n can be written as a sum of two prime numbers.

Solution 4 = 2 + 2 6 = 3 + 3 8 = 3 + 5 10 = 5 + 5 12 = 5 + 7 14 = 11 + 3 16 = 5 + 11 18 = 7 + 11 20 = 7 + 13 22 = 5 + 17 24 = 5 + 19 26 = 7 + 19 ■

In most cases in mathematics, however, the method of exhaustion cannot be used. For instance, can you prove by exhaustion that every even integer greater than 2 can be written as a sum of two prime numbers? No. To do that you would have to check every even integer, and because there are infinitely many such numbers, this is an impossible task.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 151

Even when the domain is finite, it may be infeasible to use the method of exhaustion. Imagine, for example, trying to check by exhaustion that the multiplication circuitry of a particular computer gives the correct result for every pair of numbers in the computer’s range. Since a typical computer would require thousands of years just to compute all possible products of all numbers in its range (not to mention the time it would take to check the accuracy of the answers), checking correctness by the method of exhaustion is obviously impractical.

The most powerful technique for proving a universal statement is one that works regardless of the size of the domain over which the statement is quantified. It is called the method of generalizing from the generic particular. Here is the idea underlying the method:

Method of Generalizing from the Generic Particular

To show that every element of a set satisfies a certain property, suppose x is a particular but arbitrarily chosen element of the set, and show that x satisfies the property.

Example 4.1.6 Generalizing from the Generic Particular

At some time you may have been shown a “mathematical trick” like the following. You ask a person to pick any number, add 5, multiply by 4, subtract 6, divide by 2, and subtract twice the original number. Then you astound the person by announcing that their final result was 7. How does this “trick” work? Let an empty box " or the symbol x stand for the number the person picks. Here is what happens when the person follows your directions:

Step Visual Result Algebraic Result

Pick a number. " x Add 5. " | | | | | x + 5 Multiply by 4. " | | | | |

(x + 5) ·4 = 4x + 20" | | | | |" | | | | | " | | | | |

Subtract 6. " | | (4x + 20)− 6 = 4x + 14" | |" | | | | |

" | | | | | Divide by 2. " | | 4x + 14

2 = 2x + 7" | | | | |

Subtract twice the original number. | | (2x + 7)− 2x = 7| | | | |

Thus no matter what number the person starts with, the result will always be 7. Note that the x in the analysis above is particular (because it represents a single quantity), but it is also arbitrarily chosen or generic (because any number whatsoever can be put in its place). This illustrates the process of drawing a general conclusion from a particular but generic object. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

152 Chapter 4 Elementary Number Theory and Methods of Proof

The point of having x be arbitrarily chosen (or generic) is to make a proof that can be generalized to all elements of the domain. By choosing x arbitrarily, you are making no special assumptions about x that are not also true of all other elements of the domain. The word generic means “sharing all the common characteristics of a group or class.” Thus everything you deduce about a generic element x of the domain is equally true of any other element of the domain.

When the method of generalizing from the generic particular is applied to a property of the form “If P(x) then Q(x),” the result is the method of direct proof. Recall that the only way an if-then statement can be false is for the hypothesis to be true and the conclusion to be false. Thus, given the statement “If P(x) then Q(x),” if you can show that the truth of P(x) compels the truth of Q(x), then you will have proved the statement. It follows by the method of generalizing from the generic particular that to show that “∀x , if P(x) then Q(x),” is true for all elements x in a set D, you suppose x is a particular but arbitrarily chosen element of D that makes P(x) true, and then you show that x makes Q(x) true.

Method of Direct Proof

1. Express the statement to be proved in the form “∀x ∈ D, if P(x) then Q(x).” (This step is often done mentally.)

2. Start the proof by supposing x is a particular but arbitrarily chosen element of D for which the hypothesis P(x) is true. (This step is often abbreviated “Suppose x ∈ D and P(x).”)

3. Show that the conclusion Q(x) is true by using definitions, previously established results, and the rules for logical inference.

Example 4.1.7 A Direct Proof of a Theorem

Prove that the sum of any two even integers is even.! Caution! The word two in this statement does not necessarily refer to two distinct integers. If a choice of integers is made arbitrarily, the integers are very likely to be distinct, but they might be the same.

Solution Whenever you are presented with a statement to be proved, it is a good idea to ask yourself whether you believe it to be true. In this case you might imagine some pairs of even integers, say 2 + 4, 6 + 10, 12 + 12, 28 + 54, and mentally check that their sums are even. However, since you cannot possibly check all pairs of even numbers, you cannot know for sure that the statement is true in general by checking its truth in these particular instances. Many properties hold for a large number of examples and yet fail to be true in general.

To prove this statement in general, you need to show that no matter what even integers are given, their sum is even. But given any two even integers, it is possible to represent them as 2r and 2s for some integers r and s. And by the distributive law of algebra, 2r + 2s = 2(r + s), which is even. Thus the statement is true in general.

Suppose the statement to be proved were much more complicated than this. What is the method you could use to derive a proof?

Formal Restatement: ∀ integers m and n, if m and n are even then m + n is even. This statement is universally quantified over an infinite domain. Thus to prove it in gen- eral, you need to show that no matter what two integers you might be given, if both of them are even then their sum will also be even.

Next ask yourself, “Where am I starting from?” or “What am I supposing?” The answer to such a question gives you the starting point, or first sentence, of the proof.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 153

Starting Point: Suppose m and n are particular but arbitrarily chosen integers that are even.

Or, in abbreviated form:

Suppose m and n are any even integers.

Then ask yourself, “What conclusion do I need to show in order to complete the proof?”

To Show: m + n is even. At this point you need to ask yourself, “How do I get from the starting point to the conclusion?” Since both involve the term even integer, you must use the definition of this term—and thus you must know what it means for an integer to be even. It follows from the definition that since m and n are even, each equals twice some integer. One of the basic laws of logic, called existential instantiation, says, in effect, that if you know something exists, you can give it a name. However, you cannot use the same name to refer to two different things, both of which are currently under discussion.

Existential Instantiation

If the existence of a certain kind of object is assumed or has been deduced then it can be given a name, as long as that name is not currently being used to denote something else.

! Caution! Because m and n are arbitrarily chosen, they could be any pair of even integers whatsoever. Once r is introduced to satisfy m = 2r , then r is not available to represent something else. If you had set m = 2r , and n = 2r , then m would equal n, which need not be the case.

Thus since m equals twice some integer, you can give that integer a name, and since n equals twice some integer, you can also give that integer a name:

m = 2r, for some integer r and n = 2s, for some integer s. Now what you want to show is that m + n is even. In other words, you want to show

that m + n equals 2 · (some integer). Having just found alternative representations for m (as 2r ) and n (as 2s), it seems reasonable to substitute these representations in place of m and n:

m + n = 2r + 2s. Your goal is to show that m + n is even. By definition of even, this means that m + n can be written in the form

2 · (some integer). This analysis narrows the gap between the starting point and what is to be shown to showing that

2r + 2s = 2 · (some integer). Why is this true? First, because of the distributive law from algebra, which says that

2r + 2s = 2(r + s), and, second, because the sum of any two integers is an integer, which implies that r + s is an integer.

This discussion is summarized by rewriting the statement as a theorem and giving a formal proof of it. (In mathematics, the word theorem refers to a statement that is known to be true because it has been proved.) The formal proof, as well as many others in this text, includes explanatory notes to make its logical flow apparent. Such comments are purely a convenience for the reader and could be omitted entirely. For this reason they are italicized and enclosed in italic square brackets: [ ].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

154 Chapter 4 Elementary Number Theory and Methods of Proof

Donald Knuth, one of the pioneers of the science of computing, has compared con- structing a computer program from a set of specifications to writing a mathematical proof based on a set of axioms.∗ In keeping with this analogy, the bracketed comments can be thought of as similar to the explanatory documentation provided by a good programmer. Documentation is not necessary for a program to run, but it helps a human reader under- stand what is going on.

Theorem 4.1.1

The sum of any two even integers is even.

Proof:

Suppose m and n are [particular but arbitrarily chosen] even integers. [We must show that m + n is even.] By definition of even, m = 2r and n = 2s for some integers r and s. Then

m + n = 2r + 2s by substitution = 2(r + s) by factoring out a 2.

Let t = r + s. Note that t is an integer because it is a sum of integers. Hence m + n = 2t where t is an integer.

It follows by definition of even that m + n is even. [This is what we needed to show.]†

Note Introducing t to equal r + s is another use of existential instantiation.

Most theorems, like the one above, can be analyzed to a point where you realize that as soon as a certain thing is shown, the theorem will be proved. When that thing has been shown, it is natural to end the proof with the words “this is what we needed to show.” The Latin words for this are quod erat demonstrandum, or Q.E.D. for short. Proofs in older mathematics books end with these initials.

Note that both the if and the only if parts of the definition of even were used in the proof of Theorem 4.1.1. Since m and n were known to be even, the only if (⇒) part of the definition was used to deduce that m and n had a certain general form. Then, after some algebraic substitution and manipulation, the if (⇐) part of the definition was used to deduce that m + n was even.

Directions for Writing Proofs of Universal Statements Think of a proof as a way to communicate a convincing argument for the truth of a mathematical statement. When you write a proof, imagine that you will be sending it to a capable classmate who has had to miss the last week or two of your course. Try to be clear and complete. Keep in mind that your classmate will see only what you actually write down, not any unexpressed thoughts behind it. Ideally, your proof will lead your classmate to understand why the given statement is true.

∗Donald E. Knuth, The Art of Computer Programming, 2nd ed., Vol. I (Reading, MA: Addison- Wesley, 1973), p. ix. †See page 134 for a discussion of the role of universal modus ponens in this proof.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 155

Over the years, the following rules of style have become fairly standard for writing the final versions of proofs:

1. Copy the statement of the theorem to be proved on your paper.

2. Clearly mark the beginning of your proof with the word Proof.

3. Make your proof self-contained. This means that you should explain the meaning of each variable used in your

proof in the body of the proof. Thus you will begin proofs by introducing the initial variables and stating what kind of objects they are. The first sentence of your proof would be something like “Suppose m and n are any even integers” or “Let x be a real number such that x is greater than 2.” This is similar to declaring variables and their data types at the beginning of a computer program.

At a later point in your proof, you may introduce a new variable to represent a quantity that is known at that point to exist. For example, if you have assumed that a particular integer n is even, then you know that n equals 2 times some integer, and you can give this integer a name so that you can work with it concretely later in the proof. Thus if you decide to call the integer, say, s, you would write, “Since n is even, n = 2s for some integer s,” or “since n is even, there exists an integer s such that n = 2s.”

4. Write your proof in complete, gramatically correct sentences. This does not mean that you should avoid using symbols and shorthand abbrevia-

tions, just that you should incorporate them into sentences. For example, the proof of Theorem 4.1.1 contains the sentence

Then m + n = 2r + 2s = 2(r + s).

To read such text as a sentence, read the first equals sign as “equals” and each subse- quent equals sign as “which equals.”

5. Keep your reader informed about the status of each statement in your proof. Your reader should never be in doubt about whether something in your proof has

been assumed or established or is still to be deduced. If something is assumed, preface it with a word like Suppose or Assume. If it is still to be shown, preface it with words like, We must show that or In other words, we must show that. This is especially impor- tant if you introduce a variable in rephrasing what you need to show. (See Common Mistakes on the next page.)

6. Give a reason for each assertion in your proof. Each assertion in a proof should come directly from the hypothesis of the theorem,

or follow from the definition of one of the terms in the theorem, or be a result obtained earlier in the proof, or be a mathematical result that has previously been established or is agreed to be assumed. Indicate the reason for each step of your proof using phrases such as by hypothesis, by definition of . . . , and by theorem . . . .

7. Include the “little words and phrases” that make the logic of your arguments clear.

When writing a mathematical argument, especially a proof, indicate how each sentence is related to the previous one. Does it follow from the previous sentence or from a combination of the previous sentence and earlier ones? If so, start the sentence by stating the reason why it follows or by writing Then, or Thus, or So, or Hence, or Therefore, or Consequently, or It follows that, and include the reason at the end of the sentence. For instance, in the proof of Theorem 4.1.1, once you know that m is even, you can write: “By definition of even, m = 2r for some integer r ,” or you can write, “Then m = 2r for some integer r by definition of even.”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

156 Chapter 4 Elementary Number Theory and Methods of Proof

If a sentence expresses a new thought or fact that does not follow as an immedi- ate consequence of the preceding statement but is needed for a later part of a proof, introduce it by writing Observe that, or Note that, or But, or Now.

Sometimes in a proof it is desirable to define a new variable in terms of previous variables. In such a case, introduce the new variable with the word Let. For instance, in the proof of Theorem 4.1.1, once it is known that m + n = 2(r + s), where r and s are integers, a new variable t is introduced to represent r + s. The proof goes on to say, “Let t = r + s. Then t is an integer because it is a sum of two integers.”

8. Display equations and inequalities. The convention is to display equations and inequalities on separate lines to increase

readability, both for other people and for ourselves so that we can more easily check our work for accuracy. We follow the convention in the text of this book, but in order to save space, we violate it in a few of the exercises and in many of the solutions con- tained in Appendix B. So you may need to copy out some parts of solutions on scratch paper to understand them fully. Please follow the convention in your own work. Leave plenty of empty space, and don’t be stingy with paper!

Variations among Proofs It is rare that two proofs of a given statement, written by two different people, are identi- cal. Even when the basic mathematical steps are the same, the two people may use differ- ent notation or may give differing amounts of explanation for their steps, or may choose different words to link the steps together into paragraph form. An important question is how detailed to make the explanations for the steps of a proof. This must ultimately be worked out between the writer of a proof and the intended reader, whether they be stu- dent and teacher, teacher and student, student and fellow student, or mathematician and colleague. Your teacher may provide explicit guidelines for you to use in your course. Or you may follow the example of the proofs in this book (which are generally explained rather fully in order to be understood by students at various stages of mathematical devel- opment). Remember that the phrases written inside brackets [ ] are intended to elucidate the logical flow or underlying assumptions of the proof and need not be written down at all. It is entirely your decision whether to include such phrases in your own proofs.

Common Mistakes The following are some of the most common mistakes people make when writing math- ematical proofs.

1. Arguing from examples. Looking at examples is one of the most helpful practices a problem solver can

engage in and is encouraged by all good mathematics teachers. However, it is a mistake to think that a general statement can be proved by showing it to be true for some special cases. A property referred to in a universal statement may be true in many instances without being true in general.

Here is an example of this mistake. It is an incorrect “proof” of the fact that the sum of any two even integers is even. (Theorem 4.1.1).

This is true because if m = 14 and n = 6, which are both even, then m + n = 20, which is also even.

Some people find this kind of argument convincing because it does, after all, consist of evidence in support of a true conclusion. But remember that when we discussed valid arguments, we pointed out that an argument may be invalid and yet have a true

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 157

conclusion. In the same way, an argument from examples may be mistakenly used to “prove” a true statement. In the previous example, it is not sufficient to show that the conclusion “m + n is even” is true for m = 14 and n = 6. You must give an argument to show that the conclusion is true for any even integers m and n.

2. Using the same letter to mean two different things. Some beginning theorem provers give a new variable quantity the same letter name

as a previously introduced variable. Consider the following “proof” fragment:

Suppose m and n are any odd integers. Then by definition of odd, m = 2k + 1 and n = 2k + 1 for some integer k.

This is incorrect. Using the same symbol, k, in the expressions for both m and n implies that m = 2k + 1 = n. It follows that the rest of the proof applies only to inte- gers m and n that equal each other. This is inconsistent with the supposition that m and n are arbitrarily chosen odd integers. For instance, the proof would not show that the sum of 3 and 5 is even.

3. Jumping to a conclusion. To jump to a conclusion means to allege the truth of something without giving an

adequate reason. Consider the following “proof” that the sum of any two even integers is even.

Suppose m and n are any even integers. By definition of even, m = 2r and n = 2s for some integers r and s. Then m + n = 2r + 2s. So m + n is even.

The problem with this “proof” is that the crucial calculation

2r + 2s = 2(r + s) is missing. The author of the “proof” has jumped prematurely to a conclusion.

4. Circular reasoning. To engage in circular reasoning means to assume what is to be proved; it is a

variation of jumping to a conclusion. As an example, consider the following “proof” of the fact that the product of any two odd integers is odd:

Suppose m and n are any odd integers. When any odd integers are multiplied, their product is odd. Hence mn is odd.

5. Confusion between what is known and what is still to be shown. A more subtle way to engage in circular reasoning occurs when the conclusion to

be shown is restated using a variable. Here is an example in a “proof” that the product of any two odd integers is odd:

Suppose m and n are any odd integers. We must show that mn is odd. This means that there exists an integer s such that

mn = 2s + 1. Also by definition of odd, there exist integers a and b such that

m = 2a + 1 and n = 2b + 1. Then

mn = (2a + 1)(2b + 1) = 2s + 1. So, since s is an integer, mn is odd by definition of odd. In this example, when the author restated the conclusion to be shown (that mn is

odd), the author wrote “there exists an integer s such that mn = 2s + 1.” Later the author jumped to an unjustified conclusion by assuming the existence of this s when

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

158 Chapter 4 Elementary Number Theory and Methods of Proof

that had not, in fact, been established. This mistake might have been avoided if the author had written “This means that we must show that there exists an integer s such that

mn = 2s + 1. An even better way to avoid this kind of error is not to introduce a variable into a proof unless it is either part of the hypothesis or deducible from it.

6. Use of any rather than some. There are a few situations in which the words any and some can be used inter-

changeably. For instance, in starting a proof that the square of any odd integer is odd, one could correctly write “Suppose m is any odd integer” or “Suppose m is some odd integer.” In most situations, however, the words any and some are not interchangeable. Here is the start of a “proof” that the square of any odd integer is odd, which uses any when the correct word is some:

Suppose m is a particular but arbitrarily chosen odd integer. By definition of odd, m = 2a + 1 for any integer a.

In the second sentence it is incorrect to say that “m = 2a + 1 for any integer a” because a cannot be just “any” integer; in fact, solving m = 2a + 1 for a shows that the only possible value for a is (m − 1)/2. The correct way to finish the sec- ond sentence is, “m = 2a + 1 for some integer a” or “there exists an integer a such that m = 2a + 1.”

7. Misuse of the word if. Another common error is not serious in itself, but it reflects imprecise think-

ing that sometimes leads to problems later in a proof. This error involves using the word if when the word because is really meant. Consider the following proof fragment:

Suppose p is a prime number. If p is prime, then p cannot be written as a product of two smaller positive integers.

The use of the word if in the second sentence is inappropriate. It suggests that the primeness of p is in doubt. But p is known to be prime by the first sentence. It cannot be written as a product of two smaller positive integers because it is prime. Here is a correct version of the fragment:

Suppose p is a prime number. Because p is prime, p cannot be written as a product of two smaller positive integers.

Getting Proofs Started Believe it or not, once you understand the idea of generalizing from the generic particular and the method of direct proof, you can write the beginnings of proofs even for theorems you do not understand. The reason is that the starting point and what is to be shown in a proof depend only on the linguistic form of the statement to be proved, not on the content of the statement.

Note You are not expected to know anything about complete, bipartite graphs.

Example 4.1.8 Identifying the “Starting Point” and the “Conclusion to Be Shown”

Write the first sentence of a proof (the “starting point”) and the last sentence of a proof (the “conclusion to be shown”) for the following statement:

Every complete, bipartite graph is connected.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 159

Solution It is helpful to rewrite the statement formally using a quantifier and a variable:

︷ ︸︸ ︷ ︷ ︸︸ ︷ ︷ ︸︸ ︷domain hypothesis conclusion Formal Restatement: ∀ graphs G, if G is complete and bipartite, then G is connected.

The first sentence, or starting point, of a proof supposes the existence of an object (in this case G) in the domain (in this case the set of all graphs) that satisfies the hypothesis of the if-then part of the statement (in this case that G is complete and bipartite). The conclusion to be shown is just the conclusion of the if-then part of the statement (in this case that G is connected).

Starting Point: Suppose G is a [particular but arbitrarily chosen] graph such that G is complete and bipartite.

Conclusion to Be Shown: G is connected. Thus the proof has the following shape:

Proof: Suppose G is a [particular but arbitrarily chosen] graph such that G is complete and bipartite. ...

Therefore, G is connected. ■

Showing That an Existential Statement Is False Recall that the negation of an existential statement is universal. It follows that to prove an existential statement is false, you must prove a universal statement (its negation) is true.

Example 4.1.9 Disproving an Existential Statement

Show that the following statement is false:

There is a positive integer n such that n2 + 3n + 2 is prime. Solution Proving that the given statement is false is equivalent to proving its negation is

true. The negation is

For all positive integers n, n2 + 3n + 2 is not prime. Because the negation is universal, it is proved by generalizing from the generic particular.

Claim: The statement “There is a positive integer n such that n2 + 3n + 2 is prime” is false.

Proof: Suppose n is any [particular but arbitrarily chosen] positive integer. [We will show that n2 + 3n + 2 is not prime.] We can factor n2 + 3n + 2 to obtain n2 + 3n + 2 = (n + 1)(n + 2). We also note that n + 1 and n + 2 are integers (because they are sums of integers) and that both n + 1 > 1 and n + 2 > 1 (because n ≥ 1). Thus n2 + 3n + 2 is a product of two integers each greater than 1, and so n2 + 3n + 2 is not prime. ■

Conjecture, Proof, and Disproof More than 350 years ago, the French mathematician Pierre de Fermat claimed that it is impossible to find positive integers x, y, and z with xn + yn = zn if n is an integer that is at least 3. (For n = 2, the equation has many integer solutions, such as 32 + 42 = 52 and 52 + 122 = 132.) Fermat wrote his claim in the margin of a book, along with the comment “I have discovered a truly remarkable PROOF of this theorem which this margin

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

160 Chapter 4 Elementary Number Theory and Methods of Proof

is too small to contain.” No proof, however, was found among his papers, and over the years some of the greatest mathematical minds tried and failed to discover a proof or a counterexample, for what came to be known as Fermat’s last theorem.

In 1986 Kenneth Ribet of the University of California at Berkeley showed that if a cer- tain other statement, the Taniyama–Shimura conjecture, could be proved, then Fermat’s theorem would follow. Andrew Wiles, an English mathematician and faculty member at Princeton University, had become intrigued by Fermat’s claim while still a child and, as an adult, had come to work in the branch of mathematics to which the Taniyama–Shimura conjecture belonged. As soon as he heard of Ribet’s result, Wiles immediately set to work to prove the conjecture. In June of 1993, after 7 years of concentrated effort, he presented a proof to worldwide acclaim.

B et

tm an

n/ CO

R B

IS

Pierre de Fermat (1601–1665)

An dr

ew W

ile s/

Pr in

ce to

n U

ni ve

rs ity

Andrew Wiles (born 1953)

During the summer of 1993, however, while every part of the proof was being care- fully checked to prepare for formal publication, Wiles found that he could not justify one step and that that step might actually be wrong. He worked unceasingly for another year to resolve the problem, finally realizing that the gap in the proof was a genuine error but that an approach he had worked on years earlier and abandoned provided a way around the difficulty. By the end of 1994, the revised proof had been thoroughly checked and pronounced correct in every detail by experts in the field. It was published in the Annals of Mathematics in 1995. Several books and an excellent documentary television show have been produced that convey the drama and excitement of Wiles’s discovery.∗

One of the oldest problems in mathematics that remains unsolved is the Goldbach conjecture. In Example 4.1.5 it was shown that every even integer from 4 to 26 can be represented as a sum of two prime numbers. More than 250 years ago, Christian Goldbach (1690–1764) conjectured that every even integer greater than 2 can be so represented. Explicit computer-aided calculations have shown the conjecture to be true up to at least 1018. But there is a huge chasm between 1018 and infinity. As pointed out by James Gleick of the New York Times, many other plausible conjectures in number theory have proved false. Leonhard Euler (1707–1783), for example, proposed in the eighteenth century that a4 + b4 + c4 = d4 had no nontrivial whole number solutions. In other words, no three perfect fourth powers add up to another perfect fourth power. For small numbers, Euler’s conjecture looked good. But in 1987 a Harvard mathematician, Noam Elkies, proved it wrong. One counterexample, found by Roger Frye of Thinking Machines Corporation in a long computer search, is 95,8004 + 217,5194 + 414,5604 = 422,4814.†

In May 2000, “to celebrate mathematics in the new millennium,” the Clay Mathe- matics Institute of Cambridge, Massachusetts, announced that it would award prizes of $1 million each for the solutions to seven longstanding, classical mathematical ques- tions. One of them, “P vs. NP,” asks whether problems belonging to a certain class can be solved on a computer using more efficient methods than the very inefficient methods that are presently known to work for them. This question is discussed briefly at the end of Chapter 11.

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. An integer is even if, and only if, _____.

2. An integer is odd if, and only if, _____.

3. An integer n is prime if, and only if, _____.

4. The most common way to disprove a universal statement is to find _____.

∗“The Proof,” produced in 1997, for the series Nova on the Public Broadcasting System; Fermat’s Enigma: The Epic Quest to Solve the World’s Greatest Mathematical Problem, by Simon Singh and John Lynch (New York: Bantam Books, 1998); Fermat’s Last Theorem: Unlocking the Secret of an Ancient Mathematical Problem by Amir D. Aczel (New York: Delacorte Press, 1997). †James Gleick, “Fermat’s Last Theorem Still Has Zero Solutions,” New York Times, 17 April 1988.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Direct Proof and Counterexample I: Introduction 161

5. According to the method of generalizing from the generic particular, to show that every element of a set satisfies a cer- tain property, suppose x is a _____, and show that _____.

6. To use the method of direct proof to prove a statement of the form, “For all x in a set D, if P(x) then Q(x),” one supposes that _____ and one shows that _____.

Exercise Set 4.1* In 1–3, use the definitions of even, odd, prime, and composite to justify each of your answers.

1. Assume that k is a particular integer. a. Is −17 an odd integer? b. Is 0 an even integer? c. Is 2k − 1 odd?

2. Assume that m and n are particular integers. a. Is 6m + 8n even? b. Is 10mn + 7 odd? c. If m > n > 0, is m2 − n2 composite?

3. Assume that r and s are particular integers. a. Is 4rs even? b. Is 6r + 4s2 + 3 odd? c. If r and s are both positive, is r 2 + 2rs + s2 composite?

Prove the statements in 4–10.

4. There are integers m and n such that m > 1 and n > 1 and 1 m +

1 n is an integer.

5. There are distinct integers m and n such that 1m + 1 n is an

integer.

6. There are real numbers a and b such that √

a + b = √a + √

b.

7. There is an integer n > 5 such that 2n − 1 is prime. 8. There is a real number x such that x > 1 and 2x > x10.

Definition: An integer n is called a perfect square if, and only if, n = k2 for some integer k.

9. There is a perfect square that can be written as a sum of two other perfect squares.

10. There is an integer n such that 2n2 − 5n + 2 is prime. Disprove the statements in 11–13 by giving a counterexample.

11. For all real numbers a and b, if a < b then a2 < b2.

12. For all integers n, if n is odd then n−12 is odd.

13. For all integers m and n, if 2m + n is odd then m and n are both odd.

In 14–16, determine whether the property is true for all integers, true for no integers, or true for some integers and false for other integers. Justify your answers.

14. (a + b)2 = a2 + b2 15.H −an = (−a)n

16. The average of any two odd integers is odd.

Prove the statements in 17 and 18 by the method of exhaustion.

17. Every positive even integer less than 26 can be expressed as a sum of three or fewer perfect squares. (For instance, 10 = 12 + 32 and 16 = 42.)

18. For each integer n with 1 ≤ n ≤ 10, n2 − n + 11 is a prime number.

19. a. Rewrite the following theorem in three different ways: as ∀ , if _____ then _____, as ∀ _____, _____ (with- out using the words if or then), and as If _____, then _____ (without using an explicit universal quantifier). b. Fill in the blanks in the proof of the theorem.

Theorem: The sum of any even integer and any odd inte- ger is odd.

Proof: Suppose m is any even integer and n is (a) . By definition of even, m = 2r for some (b) , and by defini- tion of odd, n = 2s + 1 for some integer s. By substitution and algebra,

m + n = (c) = 2(r + s) + 1. Since r and s are both integers, so is their sum r + s. Hence m + n has the form twice some integer plus one, and so (d) by definition of odd.

Each of the statements in 20–23 is true. For each, (a) rewrite the statement with the quantification implicit as If _____, then _____, and (b) write the first sentence of a proof (the “starting point”) and the last sentence of a proof (the “conclusion to be shown”). Note that you do not need to understand the statements in order to be able to do these exercises.

20. For all integers m, if m > 1 then 0 < 1m < 1.

21. For all real numbers x , if x > 1 then x2 > x .

22. For all integers m and n, if mn = 1 then m = n = 1 or m = n = −1.

23. For all real numbers x , if 0 < x < 1 then x2 < x .

∗For exercises with blue numbers, solutions are given in Appendix B. The symbol H indicates that only a hint or partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

162 Chapter 4 Elementary Number Theory and Methods of Proof

Prove the statements in 24–34. In each case use only the defini- tions of the terms and the Assumptions listed on page 146, not any previously established properties of odd and even integers. Follow the directions given in this section for writing proofs of universal statements.

24. The negative of any even integer is even.

25. The difference of any even integer minus any odd integer is odd.

26.H The difference between any odd integer and any even inte- ger is odd. (Note: The “proof” shown in exericse 39 con- tains an error. Can you spot it?)

27. The sum of any two odd integers is even.

28. For all integers n, if n is odd then n2 is odd.

29. For all integers n, if n is odd then 3n + 5 is even. 30. For all integers m, if m is even then 3m + 5 is odd. 31. If k is any odd integer and m is any even integer, then,

k2 + m2 is odd. 32. If a is any odd integer and b is any even integer, then,

2a + 3b is even. 33. If n is any even integer, then (−1)n = 1. 34. If n is any odd integer, then (−1)n = −1. Prove that the statements in 35–37 are false.

35. There exists an integer m ≥ 3 such that m2 − 1 is prime. 36. There exists an integer n such that 6n2 + 27 is prime. 37. There exists an integer k ≥ 4 such that 2k2 − 5k + 2 is

prime.

Find the mistakes in the “proofs” shown in 38–42.

38. Theorem: For all integers k, if k > 0 then k2 + 2k + 1 is composite. “Proof: For k = 2, k2 + 2k + 1 = 22 + 2 ·2 + 1 = 9. But 9 = 3 ·3, and so 9 is composite. Hence the theorem is true.”

39. Theorem: The difference between any odd integer and any even integer is odd. “Proof: Suppose n is any odd integer, and m is any even integer. By definition of odd, n = 2k + 1 where k is an integer, and by definition of even, m = 2k where k is an integer. Then

n − m = (2k + 1)− 2k = 1. But 1 is odd. Therefore, the difference between any odd integer and any even integer is odd.”

40. Theorem: For all integers k, if k > 0 then k2 + 2k + 1 is composite. “Proof: Suppose k is any integer such that k > 0. If k2 + 2k + 1 is composite, then k2 + 2k + 1 = rs for some integers r and s such that

1 < r < (k2 + 2k + 1) and 1 < s < (k2 + 2k + 1). Since k2 + 2k + 1 = rs and both r and s are strictly between 1 and k2 + 2k + 1, then k2 + 2k + 1 is not prime. Hence k2 + 2k + 1 is com- posite as was to be shown.”

41. Theorem: The product of an even integer and an odd inte- ger is even.

“Proof: Suppose m is an even integer and n is an odd inte- ger. If m ·n is even, then by definition of even there exists an integer r such that m ·n = 2r . Also since m is even, there exists an integer p such that m = 2p, and since n is odd there exists an integer q such that n = 2q + 1. Thus

mn = (2p)(2q + 1) = 2r, where r is an integer. By definition of even, then, m ·n is even, as was to be shown.”

42. Theorem: The sum of any two even integers equals 4k for some integer k.

“Proof: Suppose m and n are any two even integers. By definition of even, m = 2k for some integer k and n = 2k for some integer k. By substitution,

m + n = 2k + 2k = 4k. This is what was to be shown.”

In 43–60 determine whether the statement is true or false. Jus- tify your answer with a proof or a counterexample, as appropri- ate. In each case use only the definitions of the terms and the Assumptions listed on page 146 not any previously established properties.

43. The product of any two odd integers is odd.

44. The negative of any odd integer is odd.

45. The difference of any two odd integers is odd.

46. The product of any even integer and any integer is even.

47. If a sum of two integers is even, then one of the sum- mands is even. (In the expression a + b, a and b are called summands.)

48. The difference of any two even integers is even.

49. The difference of any two odd integers is even.

50. For all integers n and m, if n − m is even then n3 − m3 is even.

51. For all integers n, if n is prime then (−1)n = −1. 52. For all integers m, if m > 2 then m2 − 4 is composite. 53. For all integers n, n2 − n + 11 is a prime number. 54. For all integers n, 4(n2 + n + 1)− 3n2 is a perfect square.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.2 Direct Proof and Counterexample II: Rational Numbers 163

55. Every positive integer can be expressed as a sum of three or fewer perfect squares.

56.✶H (Two integers are consecutive if, and only if, one is one more than the other.) Any product of four consecutive inte- gers is one less than a perfect square.

57. If m and n are positive integers and mn is a perfect square, then m and n are perfect squares.

58. The difference of the squares of any two consecutive inte- gers is odd.

59. For all nonnegative real numbers a and b, √

ab = √a √

b. (Note that if x is a nonnegative real number, then there is a

unique nonnegative real number y, denoted √

x , such that y2 = x .)

60. For all nonnegative real numbers a and b, √

a + b = √a + √

b.

61. Suppose that integers m and n are perfect squares. Then m + n + 2√mn is also a perfect square. Why?

62.✶H If p is a prime number, must 2p − 1 also be prime? Prove or give a counterexample.

63.✶ If n is a nonnegative integer, must 22n + 1 be prime? Prove or give a counterexample.

Answers for Test Yourself 1. it equals twice some integer 2. it equals twice some integer plus 1 3. n is greater than 1 and if n equals the product of any two positive integers, then one of the integers equals 1 and the other equals n. 4. a counterexample 5. particular but arbitrarily chosen element of the set; x satisfies the given property 6. x is a particular but arbitrarily chosen element of the set D that makes the hypothesis P(x) true; x makes the conclusion Q(x) true.

4.2 Direct Proof and Counterexample II: Rational Numbers

Such, then, is the whole art of convincing. It is contained in two principles: to define all notations used, and to prove everything by replacing mentally the defined terms by their definitions. — Blaise Pascal, 1623–1662

Sums, differences, and products of integers are integers. But most quotients of integers are not integers. Quotients of integers are, however, important; they are known as rational numbers.

• Definition A real number r is rational if, and only if, it can be expressed as a quotient of two integers with a nonzero denominator. A real number that is not rational is irrational. More formally, if r is a real number, then

r is rational ⇔ ∃ integers a and b such that r = a b

and b ̸= 0.

The word rational contains the word ratio, which is another word for quotient. A rational number can be written as a ratio of integers.

Example 4.2.1 Determining Whether Numbers Are Rational or Irrational

a. Is 10/3 a rational number?

b. Is − 539 a rational number? c. Is 0.281 a rational number?

d. Is 7 a rational number?

e. Is 0 a rational number?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

164 Chapter 4 Elementary Number Theory and Methods of Proof

f. Is 2/0 a rational number?

g. Is 2/0 an irrational number?

h. Is 0.12121212 . . . a rational number (where the digits 12 are assumed to repeat forever)?

i. If m and n are integers and neither m nor n is zero, is (m + n)/mn a rational number? Solution

a. Yes, 10/3 is a quotient of the integers 10 and 3 and hence is rational.

b. Yes, − 539 = −5 39 , which is a quotient of the integers −5 and 39 and hence is rational.

c. Yes, 0.281 = 281/1000. Note that the real numbers represented on a typical calculator display are all finite decimals. An explanation similar to the one in this example shows that any such number is rational. It follows that a calculator with such a display can represent only rational numbers.

d. Yes, 7 = 7/1. e. Yes, 0 = 0/1. f. No, 2/0 is not a number (division by 0 is not allowed).

g. No, because every irrational number is a number, and 2/0 is not a number. We discuss additional techniques for determining whether numbers are irrational in Sections 4.6, 4.7, and 9.4.

h. Yes. Let x = 0.12121212 . . . . Then 100x = 12.12121212 . . . . Thus 100x − x = 12.12121212 . . .− 0.12121212 . . . = 12.

But also 100x − x = 99x by basic algebra

Hence 99x = 12,

and so x = 12 99

.

Therefore, 0.12121212 . . . = 12/99, which is a ratio of two nonzero integers and thus is a rational number.

Note that you can use an argument similar to this one to show that any repeating decimal is a rational number. In Section 9.4 we show that any rational number can be written as a repeating or terminating decimal.

i. Yes, since m and n are integers, so are m + n and mn (because sums and products of integers are integers). Also mn ̸= 0 by the zero product property. One version of this property says the following:

Zero Product Property

If neither of two real numbers is zero, then their product is also not zero.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.2 Direct Proof and Counterexample II: Rational Numbers 165

(See Theorem T11 in Appendix A and exercise 8 at the end of this section.) It follows that (m + n)/mn is a quotient of two integers with a nonzero denominator and hence is a rational number. ■

More on Generalizing from the Generic Particular Some people like to think of the method of generalizing from the generic particular as a challenge process. If you claim a property holds for all elements in a domain, then someone can challenge your claim by picking any element in the domain whatsoever and asking you to prove that that element satisfies the property. To prove your claim, you must be able to meet all such challenges. That is, you must have a way to convince the challenger that the property is true for an arbitrarily chosen element in the domain.

For example, suppose “A” claims that every integer is a rational number. “B” chal- lenges this claim by asking “A” to prove it for n = 7. “A” observes that

7 = 7 1

which is a quotient of integers and hence rational.

“B” accepts this explanation but challenges again with n = −12. “A” responds that

−12 = −12 1

which is a quotient of integers and hence rational.

Next “B” tries to trip up “A” by challenging with n = 0, but “A” answers that

0 = 0 1

which is a quotient of integers and hence rational.

As you can see, “A” is able to respond effectively to all “B”s challenges because “A” has a general procedure for putting integers into the form of rational numbers: “A” just divides whatever integer “B” gives by 1. That is, no matter what integer n “B” gives “A”, “A” writes

n = n 1

which is a quotient of integers and hence rational.

This discussion proves the following theorem.

Theorem 4.2.1

Every integer is a rational number.

In exercise 11 at the end of this section you are asked to condense the above discussion into a formal proof.

Proving Properties of Rational Numbers The next example shows how to use the method of generalizing from the generic partic- ular to prove a property of rational numbers.

Example 4.2.2 A Sum of Rationals Is Rational

Prove that the sum of any two rational numbers is rational.

Solution Begin by mentally or explicitly rewriting the statement to be proved in the form “∀ , if then .”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

166 Chapter 4 Elementary Number Theory and Methods of Proof

Formal Restatement: ∀ real numbers r and s, if r and s are rational then r + s is rational. Next ask yourself, “Where am I starting from?” or “What am I supposing?” The answer gives you the starting point, or first sentence, of the proof.

Starting Point: Suppose r and s are particular but arbitrarily chosen real numbers such that r and s are rational; or, more simply,

Suppose r and s are rational numbers.

Then ask yourself, “What must I show to complete the proof?”

To Show: r + s is rational. Finally ask, “How do I get from the starting point to the conclusion?” or “Why must r + s be rational if both r and s are rational?” The answer depends in an essential way on the definition of rational.

Rational numbers are quotients of integers, so to say that r and s are rational means that

r = a b

and s = c d

for some integers a, b, c, and d where b ̸= 0 and d ̸= 0.

It follows by substitution that

r + s = a b

+ c d

.

You need to show that r + s is rational, which means that r + s can be written as a single fraction or ratio of two integers with a nonzero denominator. But the right-hand side of equation (4.2.1) in

a b

+ c d

= ad bd

+ bc bd

rewriting the fraction with a common denominator

= ad + bc bd

adding fractions with a common denominator.

Is this fraction a ratio of integers? Yes. Because products and sums of integers are inte- gers, ad + bc and bd are both integers. Is the denominator bd ̸= 0? Yes, by the zero product property (since b ̸= 0 and d ̸= 0). Thus r + s is a rational number.

This discussion is summarized as follows:

Theorem 4.2.2

The sum of any two rational numbers is rational.

Proof:

Suppose r and s are rational numbers. [We must show that r + s is rational.] Then, by definition of rational, r = a/b and s = c/d for some integers a, b, c, and d with b ̸= 0 and d ̸= 0. Thus

r + s = a b

+ c d

by substitution

= ad + bc bd

by basic algebra.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.2 Direct Proof and Counterexample II: Rational Numbers 167

Let p = ad + bc and q = bd. Then p and q are integers because products and sums of integers are integers and because a, b, c, and d are all integers. Also q ̸= 0 by the zero product property. Thus

r + s = p q

where p and q are integers and q ̸= 0.

Therefore, r + s is rational by definition of a rational number. [This is what was to be shown.]

Deriving New Mathematics from Old Section 4.1 focused on establishing truth and falsity of mathematical theorems using only the basic algebra normally taught in secondary school; the fact that the integers are closed under addition, subtraction, and multiplication; and the definitions of the terms in the theorems themselves. In the future, when we ask you to prove something directly from the definitions, we will mean that you should restrict yourself to this approach. However, once a collection of statements has been proved directly from the definitions, another method of proof becomes possible. The statements in the collection can be used to derive additional results.

Example 4.2.3 Deriving Additional Results about Even and Odd Integers

Suppose that you have already proved the following properties of even and odd integers:

1. The sum, product, and difference of any two even integers are even.

2. The sum and difference of any two odd integers are even.

3. The product of any two odd integers is odd.

4. The product of any even integer and any odd integer is even.

5. The sum of any odd integer and any even integer is odd.

6. The difference of any odd integer minus any even integer is odd.

7. The difference of any even integer minus any odd integer is odd.

Use the properties listed above to prove that if a is any even integer and b is any odd

integer, then a 2+b2+1

2 is an integer.

Solution Suppose a is any even integer and b is any odd integer. By property 3, b2 is odd, and by property 1, a2 is even. Then by property 5, a2 + b2 is odd, and because 1 is also odd, the sum (a2 + b2) + 1 = a2 + b2 + 1 is even by property 2. Hence, by definition of even, there exists an integer k such that a2 + b2 + 1 = 2k. Dividing both sides by 2 gives a

2+b2+1 2 = k, which is an integer. Thus

a2+b2+1 2 is an integer [as was to be

shown]. ■

A corollary is a statement whose truth can be immediately deduced from a theorem that has already been proved.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

168 Chapter 4 Elementary Number Theory and Methods of Proof

Example 4.2.4 The Double of a Rational Number

Derive the following as a corollary of Theorem 4.2.2.

Corollary 4.2.3

The double of a rational number is rational.

Solution The double of a number is just its sum with itself. But since the sum of any two rational numbers is rational (Theorem 4.2.2), the sum of a rational number with itself is rational. Hence the double of a rational number is rational. Here is a formal version of this argument:

Proof:

Suppose r is any rational number. Then 2r = r + r is a sum of two rational numbers. So, by Theorem 4.2.2, 2r is rational. ■

Test Yourself 1. To show that a real number is rational, we must show that

we can write it as _____. 2. An irrational number is a _____ that is _____.

3. Zero is a rational number because _____.

Exercise Set 4.2 The numbers in 1–7 are all rational. Write each number as a ratio of two integers.

1. −35 6

2. 4.6037 3. 4 5

+ 2 9

4. 0.37373737 . . .

5. 0.56565656 . . .

6. 320.5492492492 . . .

7. 52.4672167216721 . . .

8. The zero product property, says that if a product of two real numbers is 0, then one of the numbers must be 0. a. Write this property formally using quantifiers and

variables. b. Write the contrapositive of your answer to part (a). c. Write an informal version (without quantifier symbols

or variables) for your answer to part (b).

9. Assume that a and b are both integers and that a ̸= 0 and b ̸= 0. Explain why (b − a)/(ab2) must be a rational number.

10. Assume that m and n are both integers and that n ̸= 0. Explain why (5m + 12n)/(4n) must be a rational number.

11. Prove that every integer is a rational number.

12. Fill in the blanks in the following proof that the square of any rational number is rational:

Proof: Suppose that r is (a) . By definition of rational, r = a/b for some (b) with b ̸= 0. By substitution,

r 2 = (c) = a2/b2. Since a and b are both integers, so are the products a2 and (d) . Also b2 ̸= 0 by the (e) . Hence r 2 is a ratio of two

integers with a nonzero denominator, and so (f ) by defi- nition of rational.

13. Consider the statement: The negative of any rational num- ber is rational. a. Write the statement formally using a quantifier and a

variable. b. Determine whether the statement is true or false and jus-

tify your answer.

14. Consider the statement: The square of any rational number is a rational number. a. Write the statement formally using a quantifier and a

variable. b. Determine whether the statement is true or false and jus-

tify your answer.

Determine which of the statements in 15–20 are true and which are false. Prove each true statement directly from the defi- nitions, and give a counterexample for each false statement.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.2 Direct Proof and Counterexample II: Rational Numbers 169

In case the statement is false, determine whether a small change would make it true. If so, make the change and prove the new statement. Follow the directions for writing proofs on page 154.

15. The product of any two rational numbers is a rational number.

16.H The quotient of any two rational numbers is a rational number.

17.H The difference of any two rational numbers is a rational number.

18.H If r and s are any two rational numbers, then r+s2 is rational.

19.H For all real numbers a and b, if a < b then a < a+b2 < b. (You may use the properties of inequalities in T17–T27 of Appendix A.)

20. Given any two rational numbers r and s with r < s, there is another rational number between r and s. (Hint: Use the results of exercises 18 and 19.)

Use the properties of even and odd integers that are listed in Example 4.2.3 to do exercises 21–23. Indicate which properties you use to justify your reasoning.

21. True or false? If m is any even integer and n is any odd integer, then m2 + 3n is odd. Explain.

22. True or false? If a is any odd integer, then a2 + a is even. Explain.

23. True or false? If k is any even integer and m is any odd integer, then (k + 2)2 − (m − 1)2 is even. Explain.

Derive the statements in 24–26 as corollaries of Theorems 4.2.1, 4.2.2, and the results of exercises 12, 13, 14, 15, and 17.

24. For any rational numbers r and s, 2r + 3s is rational. 25. If r is any rational number, then 3r 2 − 2r + 4 is rational. 26. For any rational number s, 5s3 + 8s2 − 7 is rational. 27. It is a fact that if n is any nonnegative integer, then

1 + 1 2

+ 1 22

+ 1 23

+ · · · + 1 2n

= 1− (1/2 n+1)

1− (1/2) .

(A more general form of this statement is proved in Section 5.2). Is the right-hand side of this equation rational? If so, express it as a ratio of two integers.

28. Suppose a, b, c, and d are integers and a ̸= c. Suppose also that x is a real number that satisfies the equation

ax + b cx + d = 1.

Must x be rational? If so, express x as a ratio of two integers.

29.✶ Suppose a, b, and c are integers and x, y, and z are nonzero real numbers that satisfy the following equations:

xy x + y = a and

xz x + z = b and

yz y + z = c.

Is x rational? If so, express it as a ratio of two integers.

30. Prove that if one solution for a quadratic equation of the form x2 + bx + c = 0 is rational (where b and c are ratio- nal), then the other solution is also rational. (Use the fact that if the solutions of the equation are r and s, then x2 + bx + c = (x − r)(x − s).)

31. Prove that if a real number c satisfies a polynomial equation of the form

r3x3 + r2x2 + r1x + r0 = 0, where r0, r1, r2, and r3 are rational numbers, then c satisfies an equation of the form

n3x3 + n2x2 + n1x + n0 = 0, where n0, n1, n2, and n3 are integers.

Definition: A number c is called a root of a polynomial p(x) if, and only if, p(c) = 0.

32.✶ Prove that for all real numbers c, if c is a root of a polyno- mial with rational coefficients, then c is a root of a polyno- mial with integer coefficients.

Use the properties of even and odd integers that are listed in Example 4.2.3 to do exercises 33 and 34.

33. When expressions of the form (x − r)(x − s) are multi- plied out, a quadratic polynomial is obtained. For instance, (x − 2)(x − (−7)) = (x − 2)(x + 7) = x2 + 5x − 14. a.H What can be said about the coefficients of the polyno-

mial obtained by multiplying out (x − r)(x − s) when both r and s are odd integers? when both r and s are even integers? when one of r and s is even and the other is odd?

b. It follows from part (a) that x2 − 1253x + 255 cannot be written as a product of two polynomials with integer coefficients. Explain why this is so.

34.✶ Observe that (x − r)(x − s)(x − t) = x3 − (r + s + t)x2 + (rs + r t + st)x − rst.

a. Derive a result for cubic polynomials similar to the result in part (a) of exercise 33 for quadratic polynomials.

b. Can x3 + 7x2 − 8x − 27 be written as a product of three polynomials with integer coefficients? Explain.

In 35–39 find the mistakes in the “proofs” that the sum of any two rational numbers is a rational number.

35. “Proof: Any two rational numbers produce a rational number when added together. So if r and s are particu- lar but arbitrarily chosen rational numbers, then r + s is rational.”

36. “Proof: Let rational numbers r = 14 and s = 1 2 be given.

Then r + s = 14 + 1 2 =

3 4 , which is a rational number. This

is what was to be shown.”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

170 Chapter 4 Elementary Number Theory and Methods of Proof

37. “Proof: Suppose r and s are rational numbers. By defini- tion of rational, r = a/b for some integers a and b with b ̸= 0, and s = a/b for some integers a and b with b ̸= 0. Then

r + s = a b

+ a b

= 2a b

.

Let p = 2a. Then p is an integer since it is a product of integers. Hence r + s = p/b, where p and b are integers and b ̸= 0. Thus r + s is a rational number by definition of rational. This is what was to be shown.”

38. “Proof: Suppose r and s are rational numbers. Then r = a/b and s = c/d for some integers a, b, c, and d with b ̸= 0 and d ̸= 0 (by definition of rational). Then

r + s = a b

+ c d

.

But this is a sum of two fractions, which is a fraction. So r + s is a rational number since a rational number is a fraction.”

39. “Proof: Suppose r and s are rational numbers. If r + s is rational, then by definition of rational r + s = a/b for some integers a and b with b ̸= 0. Also since r and s are rational, r = i/j and s = m/n for some integers i, j, m, and n with j ̸= 0 and n ̸= 0. It follows that

r + s = i j

+ m n

= a b

,

which is a quotient of two integers with a nonzero denomi- nator. Hence it is a rational number. This is what was to be shown.”

Answers for Test Yourself 1. a ratio of integers with a nonzero denominator 2. real number; not rational 3. 0 = 0

1

4.3 Direct Proof and Counterexample III: Divisibility

The essential quality of a proof is to compel belief. — Pierre de Fermat

When you were first introduced to the concept of division in elementary school, you were probably taught that 12 divided by 3 is 4 because if you separate 12 objects into groups of 3, you get 4 groups with nothing left over.

xxx xxx xxx xxx

You may also have been taught to describe this fact by saying that “12 is evenly divisible by 3” or “3 divides 12 evenly.”

The notion of divisibility is the central concept of one of the most beautiful subjects in advanced mathematics: number theory, the study of properties of integers.

• Definition If n and d are integers and d ̸= 0 then

n is divisible by d if, and only if, n equals d times some integer.

Instead of “n is divisible by d,” we can say that

n is a multiple of d, or d is a factor of n, or d is a divisor of n, or d divides n.

The notation d | n is read “d divides n.” Symbolically, if n and d are integers and d ̸= 0:

d | n ⇔ ∃ an integer k such that n = dk.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Direct Proof and Counterexample III: Divisibility 171

Example 4.3.1 Divisibility

a. Is 21 divisible by 3? b. Does 5 divide 40? c. Does 7 | 42? d. Is 32 a multiple of −16? e. Is 6 a factor of 54? f. Is 7 a factor of −7?

Solution

a. Yes, 21 = 3 ·7. b. Yes, 40 = 5 ·8. c. Yes, 42 = 7 ·6. d. Yes, 32 = (−16) ·(−2). e. Yes, 54 = 6 ·9. f. Yes, −7 = 7 ·(−1). ■

Example 4.3.2 Divisors of Zero

If k is any nonzero integer, does k divide 0?

Solution Yes, because 0 = k ·0. ■

Two useful properties of divisibility are (1) that if one positive integer divides a sec- ond positive integer, then the first is less than or equal to the second, and (2) that the only divisors of 1 are 1 and −1.

Theorem 4.3.1 A Positive Divisor of a Positive Integer

For all integers a and b, if a and b are positive and a divides b, then a ≤ b.

Proof:

Suppose a and b are positive integers and a divides b. [We must show that a ≤ b.] Then there exists an integer k so that b = ak. By property T25 of Appendix A, k must be positive because both a and b are positive. It follows that

1 ≤ k because every positive integer is greater than or equal to 1. Multiplying both sides by a gives

a ≤ ka = b because multiplying both sides of an inequality by a positive number preserves the inequality by property T20 of Appendix A. Thus a ≤ b [as was to be shown].

Theorem 4.3.2 Divisors of 1

The only divisors of 1 are 1 and −1.

Proof:

Since 1 ·1 = 1 and (−1)(−1) = 1, both 1 and −1 are divisors of 1. Now suppose m is any integer that divides 1. Then there exists an integer n such that 1 = mn. By Theorem T25 in Appendix A, either both m and n are positive or both m and n are negative. If both m and n are positive, then m is a positive integer divisor of 1. By Theorem 4.3.1, m ≤ 1, and, since the only positive integer that is less than or equal

continued on page 172

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

172 Chapter 4 Elementary Number Theory and Methods of Proof

to 1 is 1 itself, it follows that m = 1. On the other hand, if both m and n are negative, then, by Theorem T12 in Appendix A, (−m)(−n) = mn = 1. In this case −m is a positive integer divisor of 1, and so, by the same reasoning, −m = 1 and thus m = −1. Therefore there are only two possibilities: either m = 1 or m = −1. So the only divisors of 1 are 1 and −1.

Example 4.3.3 Divisibility of Algebraic Expressions

a. If a and b are integers, is 3a + 3b divisible by 3? b. If k and m are integers, is 10km divisible by 5?

Solution

a. Yes. By the distributive law of algebra, 3a + 3b = 3(a + b) and a + b is an integer because it is a sum of two integers.

b. Yes. By the associative law of algebra, 10km = 5 ·(2km) and 2km is an integer because it is a product of three integers. ■

When the definition of divides is rewritten formally using the existential quantifier, the result is

d | n ⇔ ∃ an integer k such that n = dk. Since the negation of an existential statement is universal, it follows that d does not divide n (denoted d ̸ | n) if, and only if, ∀ integers k, n ̸= dk, or, in other words, the quotient n/d is not an integer.

For all integers n and d, d ̸ | n ⇔ n d

is not an integer.

Example 4.3.4 Checking Nondivisibility

Does 4 | 15? Solution No, 154 = 3.75, which is not an integer. ■

! Caution! a | b denotes the sentence “a divides b,” whereas a/b denotes the number a divided by b.

Be careful to distinguish between the notation a | b and the notation a/b. The notation a | b stands for the sentence “a divides b,” which means that there is an integer k such that b = ak. Dividing both sides by a gives b/a = k, an integer. Thus, when a ̸= 0, a | b if, and only if, b/a is an integer. On the other hand, the notation a/b stands for the number a/b which is the result of dividing a by b and which may or may not be an integer. In particular, be sure to avoid writing things like

✘✘✘ ✘✘✘

✘❳❳❳❳❳❳❳ 4 | (3 + 5)= 4 | 8.

If read out loud, this becomes, “4 divides the quantity 3 plus 5 equals 4 divides 8,” which is nonsense.

Example 4.3.5 Prime Numbers and Divisibility

An alternative way to define a prime number is to say that an integer n > 1 is prime if, and only if, its only positive integer divisors are 1 and itself. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Direct Proof and Counterexample III: Divisibility 173

Proving Properties of Divisibility One of the most useful properties of divisibility is that it is transitive. If one number divides a second and the second number divides a third, then the first number divides the third.

Example 4.3.6 Transitivity of Divisibility

Prove that for all integers a, b, and c, if a | b and b | c, then a | c. Solution Since the statement to be proved is already written formally, you can immediately

pick out the starting point, or first sentence of the proof, and the conclusion that must be shown.

Starting Point: Suppose a, b, and c are particular but arbitrarily chosen integers such that a | b and b | c.

To Show: a | c. You need to show that a | c, or, in other words, that

c = a · (some integer). But since a | b,

b = ar for some integer r. 4.3.1 And since b | c,

c = bs for some integer s. 4.3.2 Equation 4.3.2 expresses c in terms of b, and equation 4.3.1 expresses b in terms of a. Thus if you substitute 4.3.1 into 4.3.2, you will have an equation that expresses c in terms of a.

c = bs by equation 4.3.2 = (ar)s by equation 4.3.1.

But (ar)s = a(rs) by the associative law for multiplication. Hence c = a(rs).

Now you are almost finished. You have expressed c as a · (something). It remains only to verify that that something is an integer. But of course it is, because it is a product of two integers.

This discussion is summarized as follows:

Theorem 4.3.3 Transitivity of Divisibility

For all integers a, b, and c, if a divides b and b divides c, then a divides c.

Proof:

Suppose a, b, and c are [particular but arbitrarily chosen] integers such that a divides b and b divides c. [We must show that a divides c.] By definition of divisibility,

b = ar and c = bs for some integers r and s. continued on page 174

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

174 Chapter 4 Elementary Number Theory and Methods of Proof

By substitution

c = bs = (ar)s = a(rs) by basic algebra.

Let k = rs. Then k is an integer since it is a product of integers, and therefore c = ak where k is an integer.

Thus a divides c by definition of divisibility. [This is what was to be shown.]

It would appear from the definition of prime that to show that an integer is prime you would need to show that it is not divisible by any integer greater than 1 and less than itself. In fact, you need only check whether it is divisible by a prime number less than or equal to itself. This follows from Theorems 4.3.1, 4.3.3, and the following the- orem, which says that any integer greater than 1 is divisible by a prime number. The idea of the proof is quite simple. You start with a positive integer. If it is prime, you are done; if not, it is a product of two smaller positive factors. If one of these is prime, you are done; if not, you can pick one of the factors and write it as a product of still smaller positive factors. You can continue in this way, factoring the factors of the number you started with, until one of them turns out to be prime. This must happen eventually because all the factors can be chosen to be positive and each is smaller than the preced- ing one.

Theorem 4.3.4 Divisibility by a Prime

Any integer n > 1 is divisible by a prime number.

Proof:

Suppose n is a [particular but arbitrarily chosen] integer that is greater than 1. [We must show that there is a prime number that divides n.] If n is prime, then n is divisible by a prime number (namely itself), and we are done. If n is not prime, then, as discussed in Example 4.1.2b,

n = r0s0 where r0 and s0 are integers and 1 < r0 < n and 1 < s0 < n.

It follows by definition of divisibility that r0 | n. If r0 is prime, then r0 is a prime number that divides n, and we are done. If r0 is

not prime, then

r0 = r1s1 where r1 and s1 are integers and 1 < r1 < r0 and 1 < s1 < r0.

It follows by the definition of divisibility that r1 | r0. But we already know that r0 | n. Consequently, by transitivity of divisibility, r1 | n.

If r1 is prime, then r1 is a prime number that divides n, and we are done. If r1 is not prime, then

r1 = r2s2 where r2 and s2 are integers and 1 < r2 < r1 and 1 < s2 < r1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Direct Proof and Counterexample III: Divisibility 175

It follows by definition of divisibility that r2 | r1. But we already know that r1 | n. Consequently, by transitivity of divisibility, r2 | n.

If r2 is prime, then r2 is a prime number that divides n, and we are done. If r2 is not prime, then we may repeat the previous process by factoring r2 as r3s3.

We may continue in this way, factoring successive factors of n until we find a prime factor. We must succeed in a finite number of steps because each new factor is both less than the previous one (which is less than n) and greater than 1, and there are fewer than n integers strictly between 1 and n.∗ Thus we obtain a sequence

r0, r1, r2, . . . , rk,

where k ≥ 0, 1 < rk < rk−1 < · · · < r2 < r1 < r0 < n, and ri | n for each i = 0, 1, 2, . . . , k. The condition for termination is that rk should be prime. Hence rk is a prime number that divides n. [This is what we were to show.]

Counterexamples and Divisibility To show that a proposed divisibility property is not universally true, you need only find one pair of integers for which it is false.

Example 4.3.7 Checking a Proposed Divisibility Property

Is the following statement true or false? For all integers a and b, if a | b and b | a then a = b.

Solution This statement is false. Can you think of a counterexample just by concentrating for a minute or so?

The following discussion describes a mental process that may take just a few seconds. It is helpful to be able to use it consciously, however, to solve more difficult problems.

To discover the truth or falsity of a statement such as the one given above, start off much as you would if you were trying to prove it.

Starting Point: Suppose a and b are integers such that a | b and b | a. Ask yourself, “Must it follow that a = b, or could it happen that a ̸= b for some a and b?” Focus on the supposition. What does it mean? By definition of divisibility, the conditions a | b and b | a mean that

b = ka and a = lb for some integers k and l. Must it follow that a = b, or can you find integers a and b that satisfy these equations for which a ̸= b? The equations imply that

b = ka = k(lb) = (kl)b. Since b | a, b ̸= 0, and so you can cancel b from the extreme left and right sides to obtain

1 = kl. In other words, k and l are divisors of 1. But, by Theorem 4.3.2, the only divisors of 1 are 1 and −1. Thus k and l are both 1 or are both −1. If k = l = 1, then b = a. But

∗Strictly speaking, this statement is justified by an axiom for the integers called the well-ordering principle, which is discussed in Section 5.4. Theorem 4.3.4 can also be proved using strong math- ematical induction, as shown in Example 5.4.1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

176 Chapter 4 Elementary Number Theory and Methods of Proof

if k = l = −1, then b = −a and so a ̸= b. This analysis suggests that you can find a counterexample by taking b = −a. Here is a formal answer:

Proposed Divisibility Property: For all integers a and b, if a | b and b | a then a = b. Counterexample: Let a = 2 and b = −2. Then

a | b since 2 | (−2) and b | a since (−2) | 2, but a ̸= b since 2 ̸= −2. Therefore, the statement is false.

The search for a proof will frequently help you discover a counterexample (provided the statement you are trying to prove is, in fact, false). Conversely, in trying to find a counterexample for a statement, you may come to realize the reason why it is true (if it is, in fact, true). The important thing is to keep an open mind until you are convinced by the evidence of your own careful reasoning.

The Unique Factorization of Integers Theorem The most comprehensive statement about divisibility of integers is contained in the unique factorization of integers theorem. Because of its importance, this theorem is also called the fundamental theorem of arithmetic. Although Euclid, who lived about 300 B.C., seems to have been acquainted with the theorem, it was first stated precisely by the great German mathematician Carl Friedrich Gauss (rhymes with house) in 1801.

The unique factorization of integers theorem says that any integer greater than 1 either is prime or can be written as a product of prime numbers in a way that is unique except, perhaps, for the order in which the primes are written. For example,

72 = 2 ·2 ·2 ·3 ·3 = 2 ·3 ·3 ·2 ·2 = 3 ·2 ·2 ·3 ·2 and so forth. The three 2’s and two 3’s may be written in any order, but any factorization of 72 as a product of primes must contain exactly three 2’s and two 3’s—no other collection of prime numbers besides three 2’s and two 3’s multiplies out to 72.

Note This theorem is the reason the number 1 is not allowed to be prime. If 1 were prime, then factorizations would not be unique. For example, 6 = 2 ·3 = 1 ·2 ·3, and so forth.

Theorem 4.3.5 Unique Factorization of Integers Theorem (Fundamental Theorem of Arithmetic)

Given any integer n > 1, there exist a positive integer k, distinct prime numbers p1, p2, . . . , pk , and positive integers e1, e2, . . . , ek such that

n = pe11 pe22 pe33 . . . pekk , and any other expression for n as a product of prime numbers is identical to this except, perhaps, for the order in which the factors are written.

The proof of the unique factorization theorem is outlined in the exercises for Sec- tions 5.4 and 8.4.

Because of the unique factorization theorem, any integer n > 1 can be put into a standard factored form in which the prime factors are written in ascending order from left to right.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Direct Proof and Counterexample III: Divisibility 177

• Definition Given any integer n > 1, the standard factored form of n is an expression of the form

n = pe11 pe22 pe33 · · · pekk , where k is a positive integer; p1, p2, . . . , pk are prime numbers; e1, e2, . . . , ek are positive integers; and p1 < p2 < · · · < pk .

Example 4.3.8 Writing Integers in Standard Factored Form

Write 3,300 in standard factored form.

Solution First find all the factors of 3,300. Then write them in ascending order:

3,300 = 100 ·33 = 4 ·25 ·3 ·11 = 2 ·2 ·5 ·5 ·3 ·11 = 22 ·31 ·52 ·111. ■

Example 4.3.9 Using Unique Factorization to Solve a Problem

Suppose m is an integer such that

8 ·7 ·6 ·5 ·4 ·3 ·2 ·m = 17 ·16 ·15 ·14 ·13 ·12 ·11 ·10.

Does 17 | m? Solution Since 17 is one of the prime factors of the right-hand side of the equation, it is

also a prime factor of the left-hand side (by the unique factorization of integers theorem). But 17 does not equal any prime factor of 8, 7, 6, 5, 4, 3, or 2 (because it is too large). Hence 17 must occur as one of the prime factors of m, and so 17 | m. ■

Test Yourself 1. To show that a nonzero integer d divides an integer n, we

must show that _____.

2. To say that d divides n means the same as saying that _____ is divisible by _____.

3. If a and b are positive integers and a | b, then _____ is less than or equal to _____.

4. For all integers n and d , d ̸ | n if, and only if, _____. 5. If a and b are integers, the notation a | b denotes _____ and

the notation a/b denotes _____.

6. The transitivity of divisibility theorem says that for all inte- gers a, b, and c, if _____ then _____.

7. The divisibility by a prime theorem says that every integer greater than 1 is _____.

8. The unique factorization of integers theorem says that any integer greater than 1 is either _____ or can be written as _____ in a way that is unique except possibly for the _____ in which the numbers are written.

Exercise Set 4.3 Give a reason for your answer in each of 1–13. Assume that all variables represent integers.

1. Is 52 divisible by 13? 2. Does 7 | 56? 3. Does 5 | 0?

4. Does 3 divide (3k + 1)(3k + 2)(3k + 3)? 5. Is 6m(2m + 10) divisible by 4? 6. Is 29 a multiple of 3? 7. Is −3 a factor of 66? 8. Is 6a(a + b) a multiple of 3a?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

178 Chapter 4 Elementary Number Theory and Methods of Proof

9. Is 4 a factor of 2a ·34b? 10. Does 7 | 34? 11. Does 13 | 73? 12. If n = 4k + 1, does 8 divide n2 − 1? 13. If n = 4k + 3, does 8 divide n2 − 1? 14. Fill in the blanks in the following proof that for all integers

a and b, if a | b then a | (−b). Proof: Suppose a and b are any integers such that (a) . By definition of divisibility, there exists an integer r such that (b) . By substitution.

−b = −ar = a(−r).

Let t = (c) . Then t is an integer because t = (−1) ·r , and both−1 and r are integers. Thus, by substitution,−b = at , where r is an integer, and so by definition of divisibility, (d) , as was to be shown.

Prove statements 15 and 16 directly from the definition of divis- ibility.

15. For all integers a, b, and c, if a | b and a | c then a | (b + c). 16.H For all integers a, b, and c, if a | b and a | c then a | (b − c). 17. Consider the following statement: The negative of any mul-

tiple of 3 is a multiple of 3. a. Write the statement formally using a quantifier and a

variable. b. Determine whether the statement is true or false and jus-

tify your answer.

18. Show that the following statement is false: For all integers a and b, if 3 | (a + b) then 3 | (a − b).

For each statement in 19–31, determine whether the statement is true or false. Prove the statement directly from the definitions if it is true, and give a counterexample if it is false.

19.H For all integers a, b, and c, if a divides b then a divides bc.

20. The sum of any three consecutive integers is divisible by 3. (Two integers are consecutive if, and only if, one is one more than the other.)

21. The product of any two even integers is a multiple of 4.

22.H A necessary condition for an integer to be divisible by 6 is that it be divisible by 2.

23. A sufficient condition for an integer to be divisible by 8 is that it be divisible by 16.

24. For all integers a, b, and c, if a | b and a | c then a | (2b − 3c).

25. For all integers a, b, and c, if a is a factor of c then ab is a factor of c.

26.H For all integers a, b, and c, if ab | c then a | c and b | c. 27.H For all integers a, b, and c, if a | (b + c) then a | b or a | c.

28. For all integers a, b, and c, if a | bc then a | b or a | c. 29. For all integers a and b, if a | b then a2 | b2. 30. For all integers a and n, if a | n2 and a ≤ n then a | n. 31. For all integers a and b, if a | 10b then a | 10 or a | b. 32. A fast-food chain has a contest in which a card with num-

bers on it is given to each customer who makes a purchase. If some of the numbers on the card add up to 100, then the customer wins $100. A certain customer receives a card containing the numbers

72, 21, 15, 36, 69, 81, 9, 27, 42, and 63.

Will the customer win $100? Why or why not?

33. Is it possible to have a combination of nickels, dimes, and quarters that add up to $4.72? Explain.

34. Is it possible to have 50 coins, made up of pennies, dimes, and quarters, that add up to $3? Explain.

35. Two athletes run a circular track at a steady pace so that the first completes one round in 8 minutes and the second in 10 minutes. If they both start from the same spot at 4 P.M., when will be the first time they return to the start together?

36. It can be shown (see exercises 44–48) that an integer is divisible by 3 if, and only if, the sum of its digits is divisible by 3. An integer is divisible by 9 if, and only if, the sum of its digits is divisible by 9. An integer is divisible by 5 if, and only if, its right-most digit is a 5 or a 0. And an integer is divisible by 4 if, and only if, the number formed by its right-most two digits is divisible by 4. Check the following integers for divisibility by 3, 4, 5 and 9. a. 637,425,403,705,125 b. 12,858,306,120,312 c. 517,924,440,926,512 d. 14,328,083,360,232

37. Use the unique factorization theorem to write the following integers in standard factored form. a. 1,176 b. 5,733 c. 3,675

38. Suppose that in standard factored form a = pe11 pe22 · · · pekk , where k is a positive integer; p1, p2, . . . , pk are prime num- bers; and e1, e2, . . . , ek are positive integers. a. What is the standard factored form for a2? b. Find the least positive integer n such that 25 ·3 ·52 ·73 ·n

is a perfect square. Write the resulting product as a per- fect square.

c. Find the least positive integer m such that 22 ·35 ·7 ·11 ·m is a perfect square. Write the resulting product as a perfect square.

39. Suppose that in standard factored form a = pe11 pe22 · · · pekk , where k is a positive integer; p1, p2, . . . , pk are prime num- bers; and e1, e2, . . . , ek are positive integers. a. What is the standard factored form for a3? b. Find the least positive integer k such that 24 ·35 ·7 ·112 ·k

is a perfect cube (i.e., equals an integer to the third power). Write the resulting product as a perfect cube.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Direct Proof and Counterexample III: Divisibility 179

40. a. If a and b are integers and 12a = 25b, does 12 | b? does 25 | a? Explain.

b. If x and y are integers and 10x = 9y, does 10 | y? does 9 | x? Explain.

41.H How many zeros are at the end of 458 ·885? Explain how you can answer this question without actually computing the number. (Hint: 10 = 2 ·5.)

42. If n is an integer and n > 1, then n! is the product of n and every other positive integer that is less than n. For example, 5! = 5 ·4 ·3 ·2 ·1. a. Write 6! in standard factored form. b. Write 20! in standard factored form. c. Without computing the value of (20!)2 determine how

many zeros are at the end of this number when it is writ- ten in decimal form. Justify your answer.

43.✶ In a certain town 2/3 of the adult men are married to 3/5 of the adult women. Assume that all marriages are monog- amous (no one is married to more than one other person). Also assume that there are at least 100 adult men in the town. What is the least possible number of adult men in the town? of adult women in the town?

Definition: Given any nonnegative integer n, the decimal representation of n is an expression of the form

dkdk−1 · · · d2d1d0, where k is a nonnegative integer; d0, d1, d2, . . . , dk (called the decimal digits of n) are integers from 0 to 9 inclusive; dk ̸= 0 unless n = 0 and k = 0; and

n = dk ·10k + dk−1 ·10k−1 + · · · + d2 ·102 + d1 ·10 + d0. (For example, 2,503 = 2 ·103 + 5 ·102 + 0 ·10 + 3.)

44. Prove that if n is any nonnegative integer whose decimal representation ends in 0, then 5 | n. (Hint: If the decimal representation of a nonnegative integer n ends in d0, then n = 10m + d0 for some integer m.)

45. Prove that if n is any nonnegative integer whose decimal representation ends in 5, then 5 | n.

46. Prove that if the decimal representation of a nonnegative integer n ends in d1d0 and if 4 | (10d1 + d0), then 4 | n. (Hint: If the decimal representation of a nonnegative inte- ger n ends in d1d0, then there is an integer s such that n = 100s + 10d1 + d0.)

47.✶H Observe that 7524 = 7 ·1000 + 5 ·100 + 2 ·10 + 4

= 7(999 + 1) + 5(99 + 1) + 2(9 + 1) + 4 = (7 ·999 + 7) + (5 ·99 + 5) + (2 ·9 + 2) + 4 = (7 ·999 + 5 ·99 + 2 ·9) + (7 + 5 + 2 + 4) = (7 ·111 ·9 + 5 ·11 ·9 + 2 ·9) + (7 + 5 + 2 + 4) = (7 ·111 + 5 ·11 + 2) ·9 + (7 + 5 + 2 + 4) = (an integer divisible by 9)

+ (the sum of the digits of 7524). Since the sum of the digits of 7524 is divisible by 9, 7524 can be written as a sum of two integers each of which is divisible by 9. It follows from exercise 15 that 7524 is divis- ible by 9.

Generalize the argument given in this example to any nonnegative integer n. In other words, prove that for any nonnegative integer n, if the sum of the digits of n is divis- ible by 9, then n is divisible by 9.

48.✶ Prove that for any nonnegative integer n, if the sum of the digits of n is divisible by 3, then n is divisible by 3.

49.✶ Given a positive integer n written in decimal form, the alter- nating sum of the digits of n is obtained by starting with the right-most digit, subtracting the digit immediately to its left, adding the next digit to the left, subtracting the next digit, and so forth. For example, the alternating sum of the digits of 180,928 is 8− 2 + 9− 0 + 8− 1 = 22. Justify the fact that for any nonnegative integer n, if the alternating sum of the digits of n is divisible by 11, then n is divisible by 11.

Answers for Test Yourself 1. n equals d times some integer (Or: there is an integer r such that n = dr ) 2. n; d 3. a; b 4. nd is not an integer 5. the sentence “a divides b”; the number obtained when a is divided by b 6. a divides b and b divides c; a divides c 7. divisible by some prime number 8. prime; a product of prime numbers; order

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

180 Chapter 4 Elementary Number Theory and Methods of Proof

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem

Be especially critical of any statement following the word “obviously.” — Anna Pell Wheeler 1883–1966

When you divide 11 by 4, you get a quotient of 2 and a remainder of 3.

2 ← quotient 4 11

8 3 ← remainder

Another way to say this is that 11 equals 2 groups of 4 with 3 left over:

xxxx xxxx xxx ↑ ↑

2 groups of 4 3 left over

Or,

11 = 2 ·4 + 3. ↑ ↑

2 groups of 4 3 left over

Of course, the number left over (3) is less than the size of the groups (4) because if 4 or more were left over, another group of 4 could be separated off.

The quotient-remainder theorem says that when any integer n is divided by any pos- itive integer d, the result is a quotient q and a nonnegative remainder r that is smaller than d.

Theorem 4.4.1 The Quotient-Remainder Theorem

Given any integer n and positive integer d, there exist unique integers q and r such that

n = dq + r and 0 ≤ r < d.

The proof that there exist integers q and r with the given properties is in Section 5.4; the proof that q and r are unique is outlined in exercise 18 in Section 4.7.

If n is positive, the quotient-remainder theorem can be illustrated on the number line as follows:

0 2d 3dd qd n

r

If n is negative, the picture changes. Since n = dq + r , where r is nonnegative, d must be multiplied by a negative integer q to go below n. Then the nonnegative integer r is added to come back up to n. This is illustrated as follows:

0–2d–3d –dqd n

r

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 181

Example 4.4.1 The Quotient-Remainder Theorem

For each of the following values of n and d , find integers q and r such that n = dq + r and 0 ≤ r < d. a. n = 54, d = 4 b. n = −54, d = 4 c. n = 54, d = 70

Solution

a. 54 = 4 ·13 + 2; hence q = 13 and r = 2. b. −54 = 4 ·(−14) + 2; hence q = −14 and r = 2. c. 54 = 70 ·0 + 54; hence q = 0 and r = 54. ■

div and mod A number of computer languages have built-in functions that enable you to compute many values of q and r for the quotient-remainder theorem. These functions are called div and mod in Pascal, are called / and % in C and C++, are called / and % in Java, and are called / (or \) and mod in .NET. The functions give the values that satisfy the quotient-remainder theorem when a nonnegative integer n is divided by a positive integer d and the result is assigned to an integer variable. However, they do not give the values that satisfy the quotient-remainder theorem when a negative integer n is divided by a positive integer d .

• Definition Given an integer n and a positive integer d ,

n div d = the integer quotient obtained when n is divided by d, and

n mod d = the nonnegative integer remainder obtained when n is divided by d .

Symbolically, if n and d are integers and d > 0, then

n div d = q and n mod d = r ⇔ n = dq + r where q and r are integers and 0 ≤ r < d .

Note that it follows from the quotient-remainder theorem that n mod d equals one of the integers from 0 through d − 1 (since the remainder of the division of n by d must be one of these integers). Note also that a necessary and sufficient condition for an integer n to be divisible by an integer d is that n mod d = 0. You are asked to prove this in the exercises at the end of this section.

You can also use a calculator to compute values of div and mod. For instance, to compute n div d for a nonnegative integer n and a positive integer d , you just divide n by d and ignore the part of the answer to the right of the decimal point. To find n mod d, you can use the fact that if n = dq + r , then r = n − dq. Thus n = d · (n div d) + n mod d, and so

n mod d = n − d · (n div d ). Hence, to find n mod d compute n div d, multiply by d, and subtract the result from n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

182 Chapter 4 Elementary Number Theory and Methods of Proof

Example 4.4.2 Computing div and mod

Compute 32 div 9 and 32 mod 9 by hand and with a calculator.

Solution Performing the division by hand gives the following results:

3 ← 32 div 9 9 32

27 5 ← 32 mod 9

If you use a four-function calculator to divide 32 by 9, you obtain an expression like 3.555555556. Discarding the fractional part gives 32 div 9 = 3, and so

32 mod 9 = 32− 9 ·(32 div 9) = 32− 27 = 5. A calculator with a built-in integer-part function iPart allows you to input a single expres- sion for each computation:

32 div 9 = iPart(32/9) and 32 mod 9 = 32− 9 · iPart (32/9) = 5. ■

Example 4.4.3 Computing the Day of the Week

Suppose today is Tuesday, and neither this year nor next year is a leap year. What day of the week will it be 1 year from today?

Solution There are 365 days in a year that is not a leap year, and each week has 7 days. Now

365 div 7 = 52 and 365 mod 7 = 1 because 365 = 52 ·7 + 1. Thus 52 weeks, or 364 days, from today will be a Tuesday, and so 365 days from today will be 1 day later, namely Wednesday.

More generally, if DayT is the day of the week today and DayN is the day of the week in N days, then

DayN = (DayT + N ) mod 7, 4.4.1 where Sunday = 0, Monday = 1, . . . , Saturday = 6. ■

Example 4.4.4 Solving a Problem about mod

Suppose m is an integer. If m mod 11 = 6, what is 4m mod 11? Solution Because m mod 11 = 6, the remainder obtained when m is divided by 11 is 6.

This means that there is some integer q so that

m = 11q + 6. Thus 4m = 44q + 24 = 44q + 22 + 2 = 11(4q + 2) + 2. Since 4q + 2 is an integer (because products and sums of integers are integers) and since 2 < 11, the remainder obtained when 4m is divided by 11 is 2. Therefore,

4m mod 11 = 2. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 183

Representations of Integers In Section 4.1 we defined an even integer to have the form twice some integer. At that time we could have defined an odd integer to be one that was not even. Instead, because it was more useful for proving theorems, we specified that an odd integer has the form twice some integer plus one. The quotient-remainder theorem brings these two ways of describing odd integers together by guaranteeing that any integer is either even or odd. To see why, let n be any integer, and consider what happens when n is divided by 2. By the quotient-remainder theorem (with d = 2), there exist unique integers q and r such that

n = 2q + r and 0 ≤ r < 2.

But the only integers that satisfy 0 ≤ r < 2 are r = 0 and r = 1. It follows that given any integer n, there exists an integer q with

n = 2q + 0 or n = 2q + 1.

In the case that n = 2q + 0 = 2q, n is even. In the case that n = 2q + 1, n is odd. Hence n is either even or odd, and, because of the uniqueness of q and r, n cannot be both even and odd.

The parity of an integer refers to whether the integer is even or odd. For instance, 5 has odd parity and 28 has even parity. We call the fact that any integer is either even or odd the parity property.

Example 4.4.5 Consecutive Integers Have Opposite Parity

Prove that given any two consecutive integers, one is even and the other is odd.

Solution Two integers are called consecutive if, and only if, one is one more than the other. So if one integer is m, the next consecutive integer is m + 1.

To prove the given statement, start by supposing that you have two particular but arbitrarily chosen consecutive integers. If the smaller is m, then the larger will be m + 1. How do you know for sure that one of these is even and the other is odd? You might imagine some examples: 4, 5; 12, 13; 1,073, 1,074. In the first two examples, the smaller of the two integers is even and the larger is odd; in the last example, it is the reverse. These observations suggest dividing the analysis into two cases.

Case 1: The smaller of the two integers is even. Case 2: The smaller of the two integers is odd.

In the first case, when m is even, it appears that the next consecutive integer is odd. Is this always true? If an integer m is even, must m + 1 necessarily be odd? Of course the answer is yes. Because if m is even, then m = 2k for some integer k, and so m + 1 = 2k + 1, which is odd.

In the second case, when m is odd, it appears that the next consecutive integer is even. Is this always true? If an integer m is odd, must m + 1 necessarily be even? Again, the answer is yes. For if m is odd, then m = 2k + 1 for some integer k, and so m + 1 = (2k + 1) + 1 = 2k + 2 = 2(k + 1), which is even.

This discussion is summarized on the following page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

184 Chapter 4 Elementary Number Theory and Methods of Proof

Theorem 4.4.2 The Parity Property

Any two consecutive integers have opposite parity.

Proof:

Suppose that two [particular but arbitrarily chosen] consecutive integers are given; call them m and m + 1. [We must show that one of m and m + 1 is even and that the other is odd.] By the parity property, either m is even or m is odd. [We break the proof into two cases depending on whether m is even or odd.]

Case 1 (m is even): In this case, m = 2k for some integer k, and so m + 1 = 2k + 1, which is odd [by definition of odd]. Hence in this case, one of m and m + 1 is even and the other is odd.

Case 2 (m is odd): In this case, m = 2k + 1 for some integer k, and so m + 1 = (2k + 1) + 1 = 2k + 2 = 2(k + 1). But k + 1 is an integer because it is a sum of two integers. Therefore, m + 1 equals twice some integer, and thus m + 1 is even. Hence in this case also, one of m and m + 1 is even and the other is odd. It follows that regardless of which case actually occurs for the particular m and m + 1 that are chosen, one of m and m + 1 is even and the other is odd. [This is what was to be shown.]

The division into cases in a proof is like the transfer of control for an if-then-else statement in a computer program. If m is even, control transfers to case 1; if not, control transfers to case 2. For any given integer, only one of the cases will apply. You must consider both cases, however, to obtain a proof that is valid for an arbitrarily given integer whether even or not.

There are times when division into more than two cases is called for. Suppose that at some stage of developing a proof, you know that a statement of the form

A1 or A2 or A3 or . . . or An

is true, and suppose you want to deduce a conclusion C . By definition of or, you know that at least one of the statements Ai is true (although you may not know which). In this situation, you should use the method of division into cases. First assume A1 is true and deduce C ; next assume A2 is true and deduce C ; and so forth until you have assumed An is true and deduced C . At that point, you can conclude that regardless of which statement Ai happens to be true, the truth of C follows.

Method of Proof by Division into Cases

To prove a statement of the form “If A1 or A2 or . . . or An , then C ,” prove all of the following:

If A1, then C,

If A2, then C, ...

If An, then C.

This process shows that C is true regardless of which of A1, A2, . . . , An happens to be the case.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 185

Proof by division into cases is a generalization of the argument form shown in Exam- ple 2.3.7, whose validity you were asked to establish in exercise 21 of Section 2.3. This method of proof was combined with the quotient-remainder theorem for d = 2 to prove Theorem 4.4.2. Allowing d to take on additional values makes it possible to obtain a variety of other results. We begin by showing what happens when a = 4.

Example 4.4.6 Representations of Integers Modulo 4

Show that any integer can be written in one of the four forms

n = 4q or n = 4q + 1 or n = 4q + 2 or n = 4q + 3

for some integer q.

Solution Given any integer n, apply the quotient-remainder theorem to n with d = 4. This implies that there exist an integer quotient q and a remainder r such that

n = 4q + r and 0 ≤ r < 4.

But the only nonnegative remainders r that are less than 4 are 0, 1, 2, and 3. Hence

n = 4q or n = 4q + 1 or n = 4q + 2 or n = 4q + 3

for some integer q. ■

The next example illustrates how the alternative representations for integers modulo 4 can help establish a result in number theory. The solution is broken into two parts: a dis- cussion and a formal proof. These correspond to the stages of actual proof development. Very few people, when asked to prove an unfamiliar theorem, immediately write down the kind of formal proof you find in a mathematics text. Most need to experiment with several possible approaches before they find one that works. A formal proof is much like the ending of a mystery story—the part in which the action of the story is systematically reviewed and all the loose ends are carefully tied together.

Note Another way to state this fact is that if you square an odd integer and divide by 8, you will always get a remainder of 1. Try a few examples!

Example 4.4.7 The Square of an Odd Integer

Prove: The square of any odd integer has the form 8m + 1 for some integer m. Solution Begin by asking yourself, “Where am I starting from?” and “What do I need to

show?” To help answer these questions, introduce variables to represent the quantities in the statement to be proved.

Formal Restatement: ∀ odd integers n, ∃ an integer m such that n2 = 8m + 1. From this, you can immediately identify the starting point and what is to be shown.

Starting Point: Suppose n is a particular but arbitrarily chosen odd integer. To Show: ∃ an integer m such that n2 = 8m + 1. This looks tough. Why should there be an integer m with the property that n2 = 8m + 1? That would say that (n2 − 1)/8 is an integer, or that 8 divides n2 − 1. Perhaps you could make use of the fact that n2 − 1 = (n − 1)(n + 1). Does 8 divide (n − 1)(n + 1)? Since n is odd, both (n − 1) and (n + 1) are even. That means that their product is divisible by 4. But that’s not enough. You need to show that the product is divisible by 8. This seems to be a blind alley.

You could try another tack. Since n is odd, you could represent n as 2q + 1 for some integer q . Then n2 = (2q + 1)2 = 4q2 + 4q + 1 = 4(q2 + q) + 1. It is clear from this

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

186 Chapter 4 Elementary Number Theory and Methods of Proof

analysis that n2 can be written in the form 4m + 1, but it may not be clear that it can be written as 8m + 1. This also seems to be a blind alley.∗

Yet another possibility is to use the result of Example 4.4.6. That example showed that any integer can be written in one of the four forms 4q, 4q + 1, 4q + 2, or 4q + 3. Two of these, 4q + 1 and 4q + 3, are odd. Thus any odd integer can be written in the form 4q + 1 or 4q + 3 for some integer q. You could try breaking into cases based on these two different forms.

Note Desperation can spur creativity. When you have tried all the obvious approaches without success and you really care about solving a problem, you reach into the odd corners of your memory for anything that may help.

It turns out that this last possibility works! In each of the two cases, the conclu- sion follows readily by direct calculation. The details are shown in the following formal proof:

Theorem 4.4.3

The square of any odd integer has the form 8m + 1 for some integer m.

Proof:

Suppose n is a [particular but arbitrarily chosen] odd integer. By the quotient-remainder theorem, n can be written in one of the forms

4q or 4q + 1 or 4q + 2 or 4q + 3 for some integer q. In fact, since n is odd and 4q and 4q + 2 are even, n must have one of the forms

4q + 1 or 4q + 3. Case 1 (n = 4q + 1 for some integer q): [We must find an integer m such that n2 = 8m + 1.] Since n = 4q + 1,

n2 = (4q + 1)2 by substitution = (4q + 1)(4q + 1) by definition of square = 16q2 + 8q + 1 = 8(2q2 + q) + 1 by the laws of algebra.

Let m = 2q2 + q . Then m is an integer since 2 and q are integers and sums and products of integers are integers. Thus, substituting,

n2 = 8m + 1 where m is an integer. Case 2 (n = 4q + 3 for some integer q): [We must find an integer m such that n2 = 8m + 1.] Since n = 4q + 3,

n2 = (4q + 3)2 by substitution = (4q + 3)(4q + 3) by definition of square = 16q2 + 24q + 9 = 16q2 + 24q + (8 + 1) = 8(2q2 + 3q + 1) + 1 by the laws of algebra.

[The motivation for the choice of algebra steps was the desire to write the expression in the form 8 · (some integer) + 1.]

∗See exercise 18 for a different perspective.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 187

Let m = 2q2 + 3q + 1. Then m is an integer since 1, 2, 3, and q are integers and sums and products of integers are integers. Thus, substituting,

n2 = 8m + 1 where m is an integer. Cases 1 and 2 show that given any odd integer, whether of the form 4q + 1 or 4q + 3, n2 = 8m + 1 for some integer m. [This is what we needed to show.]

Note that the result of Theorem 4.4.3 can also be written, “For any odd integer n, n2 mod 8 = 1.”

In general, according to the quotient-remainder theorem, if an integer n is divided by an integer d, the possible remainders are 0, 1, 2, . . ., (d − 1). This implies that n can be written in one of the forms

dq, dq + 1, dq + 2, , . . . , dq + (d − 1) for some integer q. Many properties of integers can be obtained by giving d a variety of different values and analyzing the cases that result.

Absolute Value and the Triangle Inequality The triangle inequality is one of the most important results involving absolute value. It has applications in many areas of mathematics.

• Definition For any real number x , the absolute value of x, denoted |x |, is defined as follows:

|x | = {

x if x ≥ 0 −x if x < 0 .

The triangle inequality says that the absolute value of the sum of two numbers is less than or equal to the sum of their absolute values. We give a proof based on the following two facts, both of which are derived using division into cases. We state both as lemmas. A lemma is a statement that does not have much intrinsic interest but is helpful in deriving other results.

Lemma 4.4.4

For all real numbers r,−|r | ≤ r ≤ |r |.

Proof:

Suppose r is any real number. We divide into cases according to whether r ≥ 0 or r < 0. Case 1 (r ≥ 0): In this case, by definition of absolute value, |r | = r . Also, since r is positive and −|r | is negative, −|r | < r . Thus it is true that

−|r | ≤ r ≤ |r |. continued on page 188

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

188 Chapter 4 Elementary Number Theory and Methods of Proof

Case 2 (r < 0): In this case, by definition of absolute value, |r | = −r . Multiplying both sides by −1 gives that −|r | = r . Also, since r is negative and |r | is positive, r < |r |. Thus it is also true in this case that

−|r | ≤ r ≤ |r |. Hence, in either case,

−|r | ≤ r ≤ |r | [as was to be shown].

Lemma 4.4.5

For all real numbers r, |− r | = |r |.

Proof:

Suppose r is any real number. By Theorem T23 in Appendix A, if r > 0, then −r < 0, and if r < 0, then −r > 0. Thus

|− r | =

⎧ ⎪⎨

⎪⎩

−r if − r > 0 0 if − r = 0 by definition of absolute value

−(−r) if − r < 0

=

⎧ ⎪⎨

⎪⎩

−r if − r > 0 0 if − r = 0 r if − r < 0

because −(−r) = r by Theorem T4 in Appendix A

=

⎧ ⎪⎨

⎪⎩

−r if r < 0 0 if − r = 0 r if r > 0

because, by Theorem T24 in Appendix A, when

−r > 0, then r < 0, when − r < 0, then r > 0, and when −r = 0, then r = 0

= {

r if r ≥ 0 −r if r < 0 by reformatting the previous result

= |r | by definition of absolute value.

Lemmas 4.4.4 and 4.4.5 now provide a basis for proving the triangle inequlity.

Theorem 4.4.6 The Triangle Inequality

For all real numbers x and y, |x + y| ≤ |x | + |y|.

Proof:

Suppose x and y, are any real numbers.

Case 1 (x + y ≥ 0): In this case, |x + y| = x + y, and so, by Lemma 4.4.4, x ≤ |x | and y ≤ |y|.

Hence, by Theorem T26 of Appendix A,

|x + y| = x + y ≤ |x | + |y|.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.4 Direct Proof and Counterexample IV: Division into Cases and the Quotient-Remainder Theorem 189

Case 2 (x + y < 0): In this case, |x + y| = −(x + y) = (−x) + (−y), and so, by Lemmas 4.4.4 and 4.4.5,

−x ≤ |− x | = |x | and − y ≤ |− y| = |y|. It follows, by Theorem T26 of Appendix A, that

|x + y| = (−x) + (−y) ≤ |x | + |y|. Hence in both cases |x + y| ≤ |x | + |y| [as was to be shown].

Test Yourself 1. The quotient-remainder theorem says that for all integers n

and d with d ≥ 0, there exist _____ q and r such that _____ and _____.

2. If n and d are integers with d > 0, n div d is _____ and n mod d is _____.

3. The parity of an integer indicates whether the integer is _____.

4. According to the quotient-remainder theorem, if an integer n is divided by a positive integer d, the possible remainders are _____. This implies that n can be written in one of the forms _____ for some integer q .

5. To prove a statement of the form “If A1 or A2 or A3, then C ,” prove _____ and _____ and _____.

6. The triangle inequality says that for all real numbers x and y, _____.

Exercise Set 4.4 For each of the values of n and d given in 1–6, find integers q and r such that n = dq + r and 0 ≤ r < d.

1. n = 70, d = 9 2. n = 62, d = 7 3. n = 36, d = 40 4. n = 3, d = 11 5. n = −45, d = 11 6. n = −27, d = 8

Evaluate the expressions in 7–10.

7. a. 43 div 9 b. 43 mod 9

8. a. 50 div 7 b. 50 mod 7

9. a. 28 div 5 b. 28 mod 5

10. a. 30 div 2 b. 30 mod 2

11. Check the correctness of formula (4.4.1) given in Example 4.4.3 for the following values of DayT and N . a. DayT = 6 (Saturday) and N = 15 b. DayT = 0 (Sunday) and N = 7 c. DayT = 4 (Thursday) and N = 12

12.✶ Justify formula (4.4.1) for general values of DayT and N .

13. On a Monday a friend says he will meet you again in 30 days. What day of the week will that be?

14.H If today is Tuesday, what day of the week will it be 1,000 days from today?

15. January 1, 2000, was a Saturday, and 2000 was a leap year. What day of the week will January 1, 2050, be?

16. Suppose d is a positive integer and n is any integer. If d | n, what is the remainder obtained when the quotient- remainder theorem is applied to n with divisor d?

17. Prove that the product of any two consecutive integers is even.

18. The result of exercise 17 suggests that the second apparent blind alley in the discussion of Example 4.4.7 might not be a blind alley after all. Write a new proof of Theorem 4.4.3 based on this observation.

19. Prove that for all integers n, n2 − n + 3 is odd. 20. Suppose a is an integer. If a mod 7 = 4, what is 5a mod 7?

In other words, if division of a by 7 gives a remainder of 4, what is the remainder when 5a is divided by 7?

21. Suppose b is an integer. If b mod 12 = 5, what is 8b mod 12? In other words, if division of b by 12 gives a remainder of 5, what is the remainder when 8b is divided by 12?

22. Suppose c is an integer. If c mod 15 = 3, what is 10c mod 15? In other words, if division of c by 15 gives a remainder of 3, what is the remainder when 10c is divided by 15?

23. Prove that for all integers n, if n mod 5 = 3 then n2 mod 5 = 4.

24. Prove that for all integers m and n, if m mod 5 = 2 and n mod 3 = 6 then mn mod 5 = 1.

25. Prove that for all integers a and b, if a mod 7 = 5 and b mod 7 = 6 then ab mod 7 = 2.

26.H Prove that a necessary and sufficient condition for a non- negative integer n to be divisible by a positive integer d is that n mod d = 0.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

190 Chapter 4 Elementary Number Theory and Methods of Proof

27. Show that any integer n can be written in one of the three forms

n = 3q or n = 3q + 1 or n = 3q + 2 for some integer q.

28. a. Use the quotient-remainder theorem with d = 3 to prove that the product of any three consecutive integers is divisible by 3.

b. Use the mod notation to rewrite the result of part (a).

29.H a. Use the quotient-remainder theorem with d = 3 to prove that the square of any integer has the form 3k or 3k + 1 for some integer k.

b. Use the mod notation to rewrite the result of part (a).

30. a. Use the quotient-remainder theorem with d = 3 to prove that the product of any two consecutive integers has the form 3k or 3k + 2 for some integer k.

b. Use the mod notation to rewrite the result of part (a).

In 31–33, you may use the properties listed in Example 4.2.3.

31. a. Prove that for all integers m and n, m + n and m − n are either both odd or both even.

b. Find all solutions to the equation m2 − n2 = 56 for which both m and n are positive integers.

c. Find all solutions to the equation m2 − n2 = 88 for which both m and n are positive integers.

32. Given any integers a, b, and c, if a − b is even and b − c is even, what can you say about the parity of 2a − (b + c)? Prove your answer.

33. Given any integers a, b, and c, if a − b is odd and b − c is even, what can you say about the parity of a − c? Prove your answer.

34.H Given any integer n, if n > 3, could n, n + 2, and n + 4 all be prime? Prove or give a counterexample.

Prove each of the statements in 35–46.

35. The fourth power of any integer has the form 8m or 8m + 1 for some integer m.

36.H The product of any four consecutive integers is divisible by 8.

37. The square of any integer has the form 4k or 4k + 1 for some integer k.

38.H For any integer n, n2 + 5 is not divisible by 4. 39.H The sum of any four consecutive integers has the form

4k + 2 for some integer k. 40. For any integer n, n(n2 − 1)(n + 2) is divisible by 4.

41. For all integers m, m2 = 5k, or m2 = 5k + 1, or m2 = 5k + 4 for some integer k.

42.H Every prime number except 2 and 3 has the form 6q + 1 or 6q + 5 for some integer q.

43. If n is an odd integer, then n4 mod 16 = 1. 44.H For all real numbers x and y, |x | · |y| = |xy|. 45. For all real numbers r and c with c ≥ 0, if−c ≤ r ≤ c, then

|r | ≤ c. 46. For all real numbers r and c with c ≥ 0, if |r | ≤ c, then

−c ≤ r ≤ c. 47. A matrix M has 3 rows and 4 columns.

⎣ a11 a12 a13 a14 a21 a22 a23 a24 a31 a32 a33 a34

The 12 entries in the matrix are to be stored in row major form in locations 7,609 to 7,620 in a computer’s memory. This means that the entries in the first row (reading left to right) are stored first, then the entries in the second row, and finally the entries in the third row. a. Which location will a22 be stored in? b. Write a formula (in i and j) that gives the integer n so

that ai j is stored in location 7,609 + n. c. Find formulas (in n) for r and s so that ars is stored in

location 7,609 + n. 48. Let M be a matrix with m rows and n columns, and

suppose that the entries of M are stored in a computer’s memory in row major form (see exercise 47) in locations N , N + 1, N + 2, . . . , N + mn − 1. Find formulas in k for r and s so that ars is stored in location N + k.

49.✶ If m, n, and d are integers, d > 0, and m mod d = n mod d, does it necessarily follow that m = n? That m − n is divis- ible by d? Prove your answers.

50.✶ If m, n, and d are integers, d > 0, and d | (m − n), what is the relation between m mod d and n mod d? Prove your answer.

51.✶ If m, n, a, b, and d are integers, d > 0, and m mod d = a and n mod d = b, is (m + n) mod d = a + b? Is (m + n) mod d = (a + b) mod d? Prove your answers.

52.✶ If m, n, a, b, and d are integers, d > 0, and m mod d = a and n mod d = b, is (mn) mod d = ab? Is (mn) mod d = ab mod d? Prove your answers.

53. Prove that if m, d , and k are integers and d > 0, then (m + dk) mod d = m mod d .

Answers for Test Yourself 1. integers; n = dq + r; 0 ≤ r < d 2. the quotient obtained when n is divided by d; the nonnegative remainder obtained when n is divided by d 3. odd or even 4. 0, 1, 2, . . . , (d − 1); dq, dq + 1, dq + 2, . . . , dq + (d − 1) 5. If A1, then C ; If A2, then C ; If A3, then C 6. |x + y| ≤ |x | + |y|

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.5 Direct Proof and Counterexample V: Floor and Ceiling 191

4.5 Direct Proof and Counterexample V: Floor and Ceiling

Proof serves many purposes simultaneously. In being exposed to the scrutiny and judgment of a new audience, [a] proof is subject to a constant process of criticism and revalidation. Errors, ambiguities, and misunderstandings are cleared up by constant exposure. Proof is respectability. Proof is the seal of authority.

Proof, in its best instances, increases understanding by revealing the heart of the matter. Proof suggests new mathematics. The novice who studies proofs gets closer to the creation of new mathematics. Proof is mathematical power, the electric voltage of the subject which vitalizes the static assertions of the theorems.

Finally, proof is ritual, and a celebration of the power of pure reason. — Philip J. Davis and Reuben Hersh, The Mathematical Experience, 1981

Imagine a real number sitting on a number line. The floor and ceiling of the number are the integers to the immediate left and to the immediate right of the number (unless the number is, itself, an integer, in which case its floor and ceiling both equal the number itself ). Many computer languages have built-in functions that compute floor and ceiling automatically. These functions are very convenient to use when writing certain kinds of computer programs. In addition, the concepts of floor and ceiling are important in analyzing the efficiency of many computer algorithms.

• Definition Given any real number x , the floor of x, denoted ⌊x⌋, is defined as follows:

⌊x⌋ = that unique integer n such that n ≤ x < n + 1. Symbolically, if x is a real number and n is an integer, then

⌊x⌋ = n ⇔ n ≤ x < n + 1.

n n + 1

x

floor of x = ⌊x⌋

• Definition Given any real number x , the ceiling of x, denoted ⌈x⌉, is defined as follows:

⌈x⌉ = that unique integer n such that n − 1 < x ≤ n. Symbolically, if x is a real number and n is an integer, then

⌈x⌉ = n ⇔ n − 1 < x ≤ n.

nn – 1

x

ceiling of x = ⌈x⌉

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

192 Chapter 4 Elementary Number Theory and Methods of Proof

Example 4.5.1 Computing Floors and Ceilings

Compute ⌊x⌋ and ⌈x⌉ for each of the following values of x : a. 25/4 b. 0.999 c. −2.01

Solution

a. 25/4 = 6.25 and 6 < 6.25 < 7; hence ⌊25/4⌋ = 6 and ⌈25/4⌉ = 7. b. 0 < 0.999 < 1; hence ⌊0.999⌋ = 0 and ⌈0.999⌉ = 1. c. −3 < −2.01 < −2; hence ⌊−2.01⌋ = −3 and ⌈−2.01⌉ = −2. Note that on some calculators ⌊x⌋ is denoted INT (x). ■

Example 4.5.2 An Application

The 1,370 students at a college are given the opportunity to take buses to an out-of-town game. Each bus holds a maximum of 40 passengers.

a. For reasons of economy, the athletic director will send only full buses. What is the maximum number of buses the athletic director will send?

b. If the athletic director is willing to send one partially filled bus, how many buses will be needed to allow all the students to take the trip?

Solution

a. ⌊1370/40⌋ = ⌊34.25⌋ = 34 b. ⌈1370/40⌉ = ⌈34.25⌉ = 35 ■

Example 4.5.3 Some General Values of Floor

If k is an integer, what are ⌊k⌋ and ⌊k + 1/2⌋? Why?

Solution Suppose k is an integer. Then

⌊k⌋ = k because k is an integer and k ≤ k < k + 1, and

⌊ k + 1

2

⌋ = k because k is an integer and k ≤ k + 1

2 < k + 1. ■

Example 4.5.4 Disproving an Alleged Property of Floor

Is the following statement true or false?

For all real numbers x and y, ⌊x + y⌋ = ⌊x⌋+ ⌊y⌋. Solution The statement is false. As a counterexample, take x = y = 12 . Then

⌊x⌋+ ⌊y⌋ = ⌊

1 2

⌋ + ⌊

1 2

⌋ = 0 + 0 = 0,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.5 Direct Proof and Counterexample V: Floor and Ceiling 193

whereas

⌊x + y⌋ = ⌊

1 2

+ 1 2

⌋ = ⌊1⌋ = 1.

Hence ⌊x + y⌋ ̸= ⌊x⌋+ ⌊y⌋. To arrive at this counterexample, you could have reasoned as follows: Suppose x and

y are real numbers. Must it necessarily be the case that ⌊x + y⌋ = ⌊x⌋+ ⌊y⌋, or could x and y be such that ⌊x + y⌋ ̸= ⌊x⌋+ ⌊y⌋? Imagine values that the various quantities could take. For instance, if both x and y are positive, then ⌊x⌋ and ⌊y⌋ are the integer parts of ⌊x⌋ and ⌊y⌋ respectively; just as

2 3 5

= 2 + 3 5→

integer part

fractional part

so is

x = ⌊x⌋+ fractional part of x and

y = ⌊y⌋+ fractional part of y. where the term fractional part is understood here to mean the part of the number to the right of the decimal point when the number is written in decimal notation. Thus if x and y are positive,

x + y = ⌊x⌋+ ⌊y⌋+ the sum of the fractional parts of x and y. But also

x + y = ⌊x + y⌋+ the fractional part of (x + y). These equations show that if there exist numbers x and y such that the sum of the frac- tional parts of x and y is at least 1, then a counterexample can be found. But there do exist such x and y; for instance, x = 12 and y =

1 2 as before. ■

The analysis of Example 4.5.4 indicates that if x and y are positive and the sum of their fractional parts is less than 1, then ⌊x + y⌋ = ⌊x⌋+ ⌊y⌋. In particular, if x is posi- tive and m is a positive integer, then ⌊x + m⌋ = ⌊x⌋+ ⌊m⌋ = ⌊x⌋+ m. (The fractional part of m is 0; hence the sum of the fractional parts of x and m equals the fractional part of x , which is less than 1.) It turns out that you can use the definition of floor to show that this equation holds for all real numbers x and for all integers m.

Example 4.5.5 Proving a Property of Floor

Prove that for all real numbers x and for all integers m, ⌊x + m⌋ = ⌊x⌋+ m. Solution Begin by supposing that x is a particular but arbitrarily chosen real number and

that m is a particular but arbitrarily chosen integer. You must show that ⌊x + m⌋ = ⌊x⌋+ m. Since this is an equation involving ⌊x⌋ and ⌊x + m⌋, it is reasonable to give one of these quantities a name: Let n = ⌊x⌋. By definition of floor,

n is an integer and n ≤ x < n + 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

194 Chapter 4 Elementary Number Theory and Methods of Proof

This double inequality enables you to compute the value of ⌊x + m⌋ in terms of n by adding m to all sides:

n + m ≤ x + m < n + m + 1.

Thus the left-hand side of the equation to be shown is

⌊x + m⌋ = n + m.

On the other hand, since n = ⌊x⌋, the right-hand side of the equation to be shown is

⌊x⌋+ m = n + m

also. Thus ⌊x + m⌋ = ⌊x⌋+ m. This discussion is summarized as follows:

Theorem 4.5.1

For all real numbers x and all integers m, ⌊x + m⌋ = ⌊x⌋+ m.

Proof:

Suppose a real number x and an integer m are given. [We must show that ⌊x + m⌋ = ⌊x⌋+ m.] Let n = ⌊x⌋. By definition of floor, n is an integer and

n ≤ x < n + 1.

Add m to all three parts to obtain

n + m ≤ x + m < n + m + 1

[since adding a number to both sides of an inequality does not change the direction of the inequality].

Now n + m is an integer [since n and m are integers and a sum of integers is an integer], and so, by definition of floor, the left-hand side of the equation to be shown is

⌊x + m⌋ = n + m.

But n = ⌊x⌋. Hence, by substitution,

n + m = ⌊x⌋+ m,

which is the right-hand side of the equation to be shown. Thus ⌊x + m⌋ = ⌊x⌋+ m [as was to be shown].

The analysis of a number of computer algorithms, such as the binary search and merge sort algorithms, requires that you know the value of ⌊n/2⌋, where n is an integer. The formula for computing this value depends on whether n is even or odd.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.5 Direct Proof and Counterexample V: Floor and Ceiling 195

Theorem 4.5.2 The Floor of n/2

For any integer n,

⌊ n 2

⌋ =

⎧ ⎪⎪⎨

⎪⎪⎩

n 2

if n is even

n − 1 2

if n is odd.

Proof:

Suppose n is a [particular but arbitrarily chosen] integer. By the quotient-remainder theorem, either n is odd or n is even.

Case 1 (n is odd): In this case, n = 2k + 1 for some integer k. [We must show that ⌊n/2⌋ = (n − 1)/2.] But the left-hand side of the equation to be shown is

⌊ n 2

⌋ = ⌊

2k + 1 2

⌋ = ⌊

2k 2

+ 1 2

⌋ = ⌊

k + 1 2

⌋ = k

because k is an integer and k ≤ k + 1/2 < k + 1. And the right-hand side of the equation to be shown is

n − 1 2

= (2k + 1)− 1 2

= 2k 2

= k

also. So since both the left-hand and right-hand sides equal k, they are equal to each

other. That is, ⌊

n 2

⌋ = n − 1

2 [as was to be shown].

Case 2 (n is even): In this case, n = 2k for some integer k. [We must show that ⌊n/2⌋ = n/2.] The rest of the proof of this case is left as an exercise.

Given any integer n and a positive integer d, the quotient-remainder theorem guaran- tees the existence of unique integers q and r such that

n = dq + r and 0 ≤ r < d.

The following theorem states that the floor notation can be used to describe q and r as follows:

q = ⌊

n d

⌋ and r = n − d

⌊ n d

⌋ .

Thus if, on a calculator or in a computer language, floor is built in but div and mod are not, div and mod can be defined as follows: For a nonnegative integer n and a positive integer d,

n div d = ⌊

n d

⌋ and n mod d = n − d

⌊ n d

⌋ . 4.5.1

Note that d divides n if, and only if, n mod d = 0, or, in other words, n = d⌊n/d⌋. You are asked to prove this in exercise 13.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

196 Chapter 4 Elementary Number Theory and Methods of Proof

Theorem 4.5.3

If n is any integer and d is a positive integer, and if q = ⌊n/d⌋ and r = n − d⌊n/d⌋, then

n = dq + r and 0 ≤ r < d.

Proof:

Suppose n is any integer, d is a positive integer, q = ⌊n/d⌋, and r = n − d⌊n/d⌋. [We must show that n = dq + r and 0 ≤ r < d.] By substitution,

dq + r = d ⌊

n d

⌋ + (

n − d ⌊

n d

⌋) = n.

So it remains only to show that 0 ≤ r < d. But q = ⌊n/d⌋. Thus, by definition of floor,

q ≤ n d

< q + 1.

Then

dq ≤ n < dq + d by multiplying all parts by d and so

0 ≤ n − dq < d by subtracting dq from all parts But

r = n − d ⌊

n d

⌋ = n − dq.

Hence

0 ≤ r < d by substitution. [This is what was to be shown.]

Example 4.5.6 Computing div and mod

Use the floor notation to compute 3850 div 17 and 3850 mod 17.

Solution By formula (4.5.1),

3850 div 17 = ⌊3850/17⌋ = ⌊226.4705882 . . .⌋ = 226 3850 mod 17 = 3850− 17 ·⌊3850/17⌋

= 3850− 17 ·226 = 3850− 3842 = 8. ■

Test Yourself 1. Given any real number x , the floor of x is the unique integer

n such that _____. 2. Given any real number x , the ceiling of x is the unique inte-

ger n such that _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.5 Direct Proof and Counterexample V: Floor and Ceiling 197

Exercise Set 4.5 Compute ⌊x⌋ and ⌈x⌉ for each of the values of x in 1–4.

1. 37.999 2. 17/4

3. −14.00001 4. −32/5 5. Use the floor notation to express 259 div 11 and

259 mod 11.

6. If k is an integer, what is ⌈k⌉? Why? 7. If k is an integer, what is

⌈ k + 12 ⌉

? Why?

8. Seven pounds of raw material are needed to manufacture each unit of a certain product. Express the number of units that can be produced from n pounds of raw material using either the floor or the ceiling notation. Which notation is more appropriate?

9. Boxes, each capable of holding 36 units, are used to ship a product from the manufacturer to a wholesaler. Express the number of boxes that would be required to ship n units of the product using either the floor or the ceiling notation. Which notation is more appropriate?

10. If 0 = Sunday, 1 = Monday, 2 = Tuesday, . . . , 6 = Satur- day, then January 1 of year n occurs on the day of the week given by the following formula: (

n + ⌊

n − 1 4

⌋ − ⌊

n − 1 100

⌋ + ⌊

n − 1 400

⌋) mod 7.

a. Use this formula to find January 1 of i. 2050 ii. 2100 iii. the year of your birth.

b.H Interpret the different components of this formula.

11. State a necessary and sufficient condition for the floor of a real number to equal that number.

12. Prove that if n is any even integer, then ⌊n/2⌋ = n/2. 13. Suppose n and d are integers and d ̸= 0. Prove each of the

following. a. If d | n, then n = ⌊n/d⌋ ·d. b. If n = ⌊n/d⌋ ·d , then d | n. c. Use the floor notation to state a necessary and sufficient

condition for an integer n to be divisible by an integer d.

Some of the statements in 14–22 are true and some are false. Prove each true statement and find a counterexample for each false statement, but do not use Theorem 4.5.1. in your proofs.

14. For all real numbers x and y, ⌊x − y⌋ = ⌊x⌋ − ⌊y⌋.

15. For all real numbers x, ⌊x − 1⌋ = ⌊x⌋ − 1. 16. For all real numbers x, ⌊x2⌋ = ⌊x⌋2. 17.H For all integers n,

⌊n/3⌋ =

⎧ ⎪⎨

⎪⎩

n/3 if n mod 3 = 0 (n − 1)/3 if n mod 3 = 1 (n − 2)/3 if n mod 3 = 2

.

18.H For all real numbers x and y, ⌈x + y⌉ = ⌈x⌉+ ⌈y⌉. 19.H For all real numbers x, ⌈x − 1⌉ = ⌈x⌉ − 1. 20. For all real numbers x and y, ⌈xy⌉ = ⌈x⌉ ·⌈y⌉. 21. For all odd integers n, ⌈n/2⌉ = (n + 1)/2. 22. For all real numbers x and y, ⌈xy⌉ = ⌈x⌉ ·⌊y⌋. Prove each of the statements in 23–29.

23. For any real number x , if x is not an integer, then ⌊x⌋+ ⌊−x⌋ = −1.

24. For any integer m and any real number x , if x is not an integer, then ⌊x⌋+ ⌊m − x⌋ = m − 1.

25.H For all real numbers x, ⌊⌊x/2⌋/2⌋ = ⌊x/4⌋. 26. For all real numbers x , if x − ⌊x⌋ < 1/2 then

⌊2x⌋ = 2⌊x⌋. 27. For all real numbers x , if x − ⌊x⌋ ≥ 1/2 then

⌊2x⌋ = 2⌊x⌋+ 1. 28. For any odd integer n,

⌊ n2

4

⌋ = (

n − 1 2

)( n + 1

2

) .

29. For any odd integer n, ⌈

n2

4

⌉ = n

2 + 3 4

.

30. Find the mistake in the following “proof” that ⌊n/2⌋ = (n − 1)/2 if n is an odd integer. “Proof: Suppose n is any odd integer. Then n = 2k + 1 for some integer k. Consequently,

⌊ 2k + 1

2

⌋ = (2k + 1)− 1

2 = 2k

2 = k.

But n = 2k + 1. Solving for k gives k = (n − 1)/2. Hence, by substitution, ⌊n/2⌋ = (n − 1)/2.”

Answers for Test Yourself 1. n ≤ x < n + 1 2. n − 1 < x ≤ n

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

198 Chapter 4 Elementary Number Theory and Methods of Proof

4.6 Indirect Argument: Contradiction and Contraposition

Reductio ad absurdum is one of a mathematician’s finest weapons. It is a far finer gambit than any chess gambit: a chess player may offer the sacrifice of a pawn or even a piece, but the mathematician offers the game. — G. H. Hardy, 1877–1947

In a direct proof you start with the hypothesis of a statement and make one deduction after another until you reach the conclusion. Indirect proofs are more roundabout. One kind of indirect proof, argument by contradiction, is based on the fact that either a statement is true or it is false but not both. So if you can show that the assumption that a given statement is not true leads logically to a contradiction, impossibility, or absurdity, then that assumption must be false: and, hence, the given statement must be true. This method of proof is also known as reductio ad impossible or reductio ad absurdum because it relies on reducing a given assumption to an impossibility or absurdity.

Argument by contradiction occurs in many different settings. For example, if a man accused of holding up a bank can prove that he was some place else at the time the crime was committed, he will certainly be acquitted. The logic of his defense is as follows:

Suppose I did commit the crime. Then at the time of the crime, I would have had to be at the scene of the crime. In fact, at the time of the crime I was in a meeting with 20 people far from the crime scene, as they will testify. This contradicts the assumption that I committed the crime since it is impossible to be in two places at one time. Hence that assumption is false.

Another example occurs in debate. One technique of debate is to say, “Suppose for a moment that what my opponent says is correct.” Starting from this supposition, the debater then deduces one statement after another until finally arriving at a statement that is completely ridiculous and unacceptable to the audience. By this means the debater shows the opponent’s statement to be false.

The point of departure for a proof by contradiction is the supposition that the state- ment to be proved is false. The goal is to reason to a contradiction. Thus proof by contra- diction has the following outline:

Method of Proof by Contradiction

1. Suppose the statement to be proved is false. That is, suppose that the negation of the statement is true.

2. Show that this supposition leads logically to a contradiction.

3. Conclude that the statement to be proved is true.

Note Be very careful when writing the negation!

There are no clear-cut rules for when to try a direct proof and when to try a proof by contradiction, but there are some general guidelines. Proof by contradiction is indicated if you want to show that there is no object with a certain property, or if you want to show that a certain object does not have a certain property. The next two examples illustrate these situations.

Example 4.6.1 There Is No Greatest Integer

Use proof by contradiction to show that there is no greatest integer.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.6 Indirect Argument: Contradiction and Contraposition 199

Solution Most small children believe there is a greatest integer—they often call it a “zil- lion.” But with age and experience, they change their belief. At some point they realize that if there were a greatest integer, they could add 1 to it to obtain an integer that was greater still. Since that is a contradiction, no greatest integer can exist. This line of rea- soning is the heart of the formal proof.

For the proof, the “certain property” is the property of being the greatest integer. To prove that there is no object with this property, begin by supposing the negation: that there is an object with the property.

Starting Point: Suppose not. Suppose there is a greatest integer; call it N . This means that N ≥ n for all integers n. To Show: This supposition leads logically to a contradiction.

Theorem 4.6.1

There is no greatest integer.

Proof:

[We take the negation of the theorem and suppose it to be true.] Suppose not. That is, suppose there is a greatest integer N . [We must deduce a contradiction.] Then N ≥ n for every integer n. Let M = N + 1. Now M is an integer since it is a sum of integers. Also M > N since M = N + 1. Thus M is an integer that is greater than N . So N is the greatest integer and N is not the greatest integer, which is a contradiction. [This contradiction shows that the supposition is false and, hence, that the theorem is true.]

After a contradiction has been reached, the logic of the argument is always the same: “This is a contradiction. Hence the supposition is false and the theorem is true.” Because of this, most mathematics texts end proofs by contradiction at the point at which the contradiction has been obtained.

The contradiction in the next example is based on the fact that 1/2 is not an integer.

Example 4.6.2 No Integer Can Be Both Even and Odd

The fact that no integer can be both even and odd follows from the uniqueness part of the quotient-remainder theorem. A full proof of this port of the theorem is outlined in exercise 18 of section 4.7. This example shows how to use proof by contradiction to prove one specific case.

Theorem 4.6.2

There is no integer that is both even and odd.

Proof:

[We take the negation of the theorem and suppose it to be true.] Suppose not. That is, suppose there is at least one integer n that is both even and odd. [We must deduce a contradiction.] By definition of even, n = 2a for some integer a, and by definition of odd, n = 2b + 1 for some integer b. Consequently,

2a = 2b + 1 by equating the two expressions for n continued on page 200

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

200 Chapter 4 Elementary Number Theory and Methods of Proof

and so

2a − 2b = 1 2(a − b) = 1

a − b = 1/2 by algebra.

Now since a and b are integers, the difference a − b must also be an integer. But a − b = 1/2, and 1/2 is not an integer. Thus a − b is an integer and a − b is not an integer, which is a contradiction. [This contradiction shows that the supposition is false and, hence, that the theorem is true.]

The next example asks you to show that the sum of any rational number and any irrational number is irrational. One way to think of this is in terms of a certain object (the sum of a rational and an irrational) not having a certain property (the property of being rational). This suggests trying a proof by contradiction: suppose the object has the property and deduce a contradiction.

Example 4.6.3 The Sum of a Rational Number and an Irrational Number

Use proof by contradiction to show that the sum of any rational number and any irrational number is irrational.

! Caution! The negation of “The sum of any irrational number and any rational number is irrational” is NOT “The sum of any irrational number and any rational number is rational.”

Solution Begin by supposing the negation of what you are to prove. Be very careful when writing down what this means. If you take the negation incorrectly, the entire rest of the proof will be flawed. In this example, the statement to be proved can be written formally as

∀ real numbers r and s, if r is rational and s is irrational, then r + s is irrational.

From this you can see that the negation is

∃ a rational number r and an irrational number s such that r + s is rational.

It follows that the starting point and what is to be shown are as follows:

Starting Point: Suppose not. That is, suppose there is a rational number r and an irrational number s such that r + s is rational.

To Show: This supposition leads to a contradiction. To derive a contradiction, you need to understand what you are supposing: that there are numbers r and s such that r is rational, s is irrational, and r + s is rational. By definition of rational and irrational, this means that s cannot be written as a quotient of any two integers but that r and r + s can:

r = a b

for some integers a and b with b ̸= 0, and 4.6.1

r + s = c d

for some integers c and d with d ̸= 0. 4.6.2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.6 Indirect Argument: Contradiction and Contraposition 201

If you substitute (4.6.1) into (4.6.2), you obtain a b

+ s = c d

.

Subtracting a/b from both sides gives

s = c d − a

b

= bc bd − ad

bd by rewriting c/d and a/b as equivalent fractions

= bc − ad bd

by the rule for subtracting fractions

with the same denominator.

But both bc − ad and bd are integers because products and differences of integers are integers, and bd ̸= 0 by the zero product property. Hence s can be expressed as a quotient of two integers with a nonzero denominator, and so s is rational, which contradicts the supposition that it is irrational.

This discussion is summarized in a formal proof.

Theorem 4.6.3

The sum of any rational number and any irrational number is irrational.

Proof:

[We take the negation of the theorem and suppose it to be true.] Suppose not. That is, suppose there is a rational number r and an irrational number s such that r + s is rational. [We must deduce a contradiction.] By definition of rational, r = a/b and r + s = c/d for some integers a, b, c, and d with b ̸= 0 and d ̸= 0. By substitution,

a b

+ s = c d

,

and so

s = c d − a

b by subtracting a/b from both sides

= bc − ad bd

by the laws of algebra.

Now bc − ad and bd are both integers [since a, b, c, and d are integers and since prod- ucts and differences of integers are integers], and bd ̸= 0 [by the zero product property]. Hence s is a quotient of the two integers bc − ad and bd with bd ̸= 0. Thus, by def- inition of rational, s is rational, which contradicts the supposition that s is irrational. [Hence the supposition is false and the theorem is true.]

Argument by Contraposition A second form of indirect argument, argument by contraposition, is based on the logical equivalence between a statement and its contrapositive. To prove a statement by con- traposition, you take the contrapositive of the statement, prove the contrapositive by a direct proof, and conclude that the original statement is true. The underlying reasoning

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

202 Chapter 4 Elementary Number Theory and Methods of Proof

is that since a conditional statement is logically equivalent to its contrapositive, if the contrapositive is true then the statement must also be true.

Method of Proof by Contraposition

1. Express the statement to be proved in the form

∀x in D, if P(x) then Q(x). (This step may be done mentally.)

2. Rewrite this statement in the contrapositive form

∀x in D, if Q(x) is false then P(x) is false. (This step may also be done mentally.)

3. Prove the contrapositive by a direct proof.

a. Suppose x is a (particular but arbitrarily chosen) element of D such that Q(x) is false.

b. Show that P(x) is false.

Example 4.6.4 If the Square of an Integer Is Even, Then the Integer Is Even

Prove that for all integers n, if n2 is even then n is even.

Solution First form the contrapositive of the statement to be proved.

Contrapositive: For all integers n, if n is not even then n2 is not even.

By the quotient-remainder theorem with d = 2, any integer is even or odd, so any integer that is not even is odd. Also by Theorem 4.6.2, no integer can be both even and odd. So if an integer is odd, then it is not even. Thus the contrapositive can be restated as follows:

Contrapositive: For all integers n, if n is odd then n2 is odd.

A straightforward computation is the heart of a direct proof for this statement, as shown below.

Proposition 4.6.4

For all integers n, if n2 is even then n is even.

Proof (by contraposition):

Suppose n is any odd integer. [We must show that n2 is odd.] By definition of odd, n = 2k + 1 for some integer k. By substitution and algebra,

n2 = (2k + 1)2 = 4k2 + 4k + 1 = 2(2k2 + 2k) + 1. But 2k2 + 2k is an integer because products and sums of integers are integers.

So n2 = 2 · (an integer) + 1, and thus, by definition of odd, n2 is odd [as was to be shown].

We used the word proposition here rather than theorem because although the word theorem can refer to any statement that has been proved, mathematicians often restrict it to

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.6 Indirect Argument: Contradiction and Contraposition 203

especially important statements that have many and varied consequences. Then they use the word proposition to refer to a statement that is somewhat less consequential but nonetheless worth writing down. We will use Proposition 4.6.4 in Section 4.7 to prove that

√ 2 is irrational. ■

Relation between Proof by Contradiction and Proof by Contraposition

Observe that any proof by contraposition can be recast in the language of proof by con- tradiction. In a proof by contraposition, the statement

∀x in D, if P(x) then Q(x) is proved by giving a direct proof of the equivalent statement

∀x in D, if ∼Q(x) then ∼P(x). To do this, you suppose you are given an arbitrary element x of D such that ∼Q(x). You then show that ∼P(x). This is illustrated in Figure 4.6.1.

Suppose x is an arbitrary element of D such that ∼Q(x).

sequence of steps ∼P(x)

Figure 4.6.1 Proof by Contraposition

Exactly the same sequence of steps can be used as the heart of a proof by contradiction for the given statement. The only thing that changes is the context in which the steps are written down.

To rewrite the proof as a proof by contradiction, you suppose there is an x in D such that P(x) and ∼Q(x). You then follow the steps of the proof by contraposition to deduce the statement ∼P(x). But ∼P(x) is a contradiction to the supposition that P(x) and ∼Q(x). (Because to contradict a conjunction of two statements, it is only necessary to contradict one of them.) This process is illustrated in Figure 4.6.2.

Suppose ∃x in D such that P(x) and ∼Q(x).

Contradiction: P(x) and ∼P(x)

same sequence of steps

Figure 4.6.2 Proof by Contradiction

As an example, here is a proof by contradiction of Proposition 4.6.4, namely that for any integer n, if n2 is even then n is even.

Proposition 4.6.4

For all integers n, if n2 is even then n is even.

Proof (by contradiction):

[We take the negation of the theorem and suppose it to be true.] Suppose not. That is, suppose there is an integer n such that n2 is even and n is not even. [We must deduce a contradiction.] By the quotient-remainder theorem with d = 2, any integer

continued on page 204

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

204 Chapter 4 Elementary Number Theory and Methods of Proof

is even or odd. Hence, since n is not even it is odd, and thus, by definition of odd, n = 2k + 1 for some integer k. By substitution and algebra:

n2 = (2k + 1)2 = 4k2 + 4k + 1 = 2(2k2 + 2k) + 1. But 2k2 + 2k is an integer because products and sums of integers are integers. So n2 = 2 · (an integer) + 1, and thus, by definition of odd, n2 is odd. Therefore, n2 is both even and odd. This contradicts Theorem 4.6.2, which states that no integer can be both even and odd. [This contradiction shows that the supposition is false and, hence, that the proposition is true.]

Note that when you use proof by contraposition, you know exactly what conclusion you need to show, namely the negation of the hypothesis; whereas in proof by contra- diction, it may be difficult to know what contradiction to head for. On the other hand, when you use proof by contradiction, once you have deduced any contradiction whatso- ever, you are done. The main advantage of contraposition over contradiction is that you avoid having to take (possibly incorrectly) the negation of a complicated statement. The disadvantage of contraposition as compared with contradiction is that you can use contra- position only for a specific class of statements—those that are universal and conditional. The previous discussion shows that any statement that can be proved by contraposition can be proved by contradiction. But the converse is not true. Statements such as “

√ 2

is irrational” (discussed in the next section) can be proved by contradiction but not by contraposition.

Proof as a Problem-Solving Tool Direct proof, disproof by counterexample, proof by contradiction, and proof by contra- position are all tools that may be used to help determine whether statements are true or false. Given a statement of the form

For all elements in a domain, if (hypothesis) then (conclusion),

imagine elements in the domain that satisfy the hypothesis. Ask yourself: Must they sat- isfy the conclusion? If you can see that the answer is “yes” in all cases, then the statement is true and your insight will form the basis for a direct proof. If after some thought it is not clear that the answer is “yes,” ask yourself whether there are elements of the domain that satisfy the hypothesis and not the conclusion. If you are successful in finding some, then the statement is false and you have a counterexample. On the other hand, if you are not successful in finding such elements, perhaps none exist. Perhaps you can show that assuming the existence of elements in the domain that satisfy the hypothesis and not the conclusion leads logically to a contradiction. If so, then the given statement is true and you have the basis for a proof by contradiction. Alternatively, you could imagine elements of the domain for which the conclusion is false and ask whether such elements also fail to satisfy the hypothesis. If the answer in all cases is “yes,” then you have a basis for a proof by contraposition.

Solving problems, especially difficult problems, is rarely a straightforward process. At any stage of following the guidelines above, you might want to try the method of a previous stage again. If, for example, you fail to find a counterexample for a certain statement, your experience in trying to find it might help you decide to reattempt a direct argument rather than trying an indirect one. Psychologists who have studied problem solving have found that the most successful problem solvers are those who are flexible and willing to use a variety of approaches without getting stuck in any one of them for

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.6 Indirect Argument: Contradiction and Contraposition 205

very long. Mathematicians sometimes work for months (or longer) on difficult problems. Don’t be discouraged if some problems in this book take you quite a while to solve.

Learning the skills of proof and disproof is much like learning other skills, such as those used in swimming, tennis, or playing a musical instrument. When you first start out, you may feel bewildered by all the rules, and you may not feel confident as you attempt new things. But with practice the rules become internalized and you can use them in conjunction with all your other powers—of balance, coordination, judgment, aesthetic sense—to concentrate on winning a meet, winning a match, or playing a concert successfully.

Now that you have worked through the first five sections of this chapter, return to the idea that, above all, a proof or disproof should be a convincing argument. You need to know how direct and indirect proofs and counterexamples are structured. But to use this knowledge effectively, you must use it in conjunction with your imaginative powers, your intuition, and especially your common sense.

Test Yourself 1. To prove a statement by contradiction, you suppose that

_____ and you show that _____.

2. A proof by contraposition of a statement of the form “∀x ∈ D, if P(x) then Q(x)” is a direct proof of _____.

3. To prove a statement of the form “∀x ∈ D, if P(x) then Q(x)” by contraposition, you suppose that _____ and you show that _____.

Exercise Set 4.6 1. Fill in the blanks in the following proof by contradiction

that there is no least positive real number.

Proof: Suppose not. That is, suppose that there is a least positive real number x . [We must deduce (a) ] Consider the number x/2. Since x is a positive real number, x/2 is also (b) . In addition, we can deduce that x/2 < x by multiply-

ing both sides of the inequality 1 < 2 by (c) and dividing (d) . Hence x/2 is a positive real number that is less than

the least positive real number. This is a (e) [Thus the sup- position is false, and so there is no least positive real number.]

2. Is 1 0

an irrational number? Explain.

3. Use proof by contradiction to show that for all integers n, 3n + 2 is not divisible by 3.

4. Use proof by contradiction to show that for all integers m, 7m + 4 is not divisible by 7.

Carefully formulate the negations of each of the statements in 5–7. Then prove each statement by contradiction.

5. There is no greatest even integer.

6. There is no greatest negative real number.

7. There is no least positive rational number.

8. Fill in the blanks for the following proof that the difference of any rational number and any irrational number is irra- tional. Proof: Suppose not. That is, suppose that there exist (a)

x and (b) y such that x − y is rational. By definition of

rational, there exist integers a, b, c, and d with b ̸= 0 and d ̸= 0 so that x = (c) and x − y = (d) . By substitution,

a b − y = c

d

Adding y and subtracting c d

on both sides gives

y = (e)

= ad bd − bc

bd

= ad − bc bd

by algebra.

Now both ad − bc and bd are integers because products and differences of (f) are (g) . And bd ̸= 0 by the (h) . Hence y is a ratio of integers with a nonzero denominator, and thus y is (i) by definition of rational. We therefore have both that y is irrational and that y is rational, which is a contradiction. [Thus the supposition is false and the state- ment to be proved is true.]

9. a. When asked to prove that the difference of any irra- tional number and any rational number is irrational, a student began, “Suppose not. That is, suppose the differ- ence of any irrational number and any rational number is rational.” What is wrong with beginning the proof in this way? (Hint: Review the answer to exercise 11 in Section 3.2.)

b. Prove that the difference of any irrational number and any rational number is irrational.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

206 Chapter 4 Elementary Number Theory and Methods of Proof

Prove each statement in 10–17 by contradiction.

10. The square root of any irrational number is irrational.

11. The product of any nonzero rational number and any irra- tional number is irrational.

12. If a and b are rational numbers, b ̸= 0, and r is an irrational number, then a + br is irrational.

13.H For any integer n, n2 − 2 is not divisible by 4. 14.H For all prime numbers a, b, and c, a2 + b2 ̸= c2. 15.H If a, b, and c are integers and a2 + b2 = c2, then at least

one of a and b is even.

16.✶H For all odd integers a, b, and c, if z is a solution of ax2 + bx + c = 0 then z is irrational. (In the proof, use the properties of even and odd integers that are listed in Example 4.2.3.)

17. For all integers a, if a mod 6 = 3, then a mod 3 ̸= 2. 18. Fill in the blanks in the following proof by contraposition

that for all integers n, if 5 ̸ | n2 then 5 ̸ | n. Proof (by contraposition): [The contrapositive is: For all integers n, if 5 | n then 5 | n2.] Suppose n is any integer such that (a) . [We must show that (b) .] By definition of divisibility, n = (c) for some integer k. By substitu- tion, n2 = (d) = 5(5k2). But 5k2 is an integer because it is a product of integers. Hence n2 = 5 · (an integer), and so (e) [as was to be shown].

Prove the statements in 19 and 20 by contraposition.

19. If a product of two positive real numbers is greater than 100, then at least one of the numbers is greater than 10.

20. If a sum of two real numbers is less than 50, then at least one of the numbers is less than 25.

21. Consider the statement “For all integers n, if n2 is odd then n is odd.” a. Write what you would suppose and what you would

need to show to prove this statement by contradiction. b. Write what you would suppose and what you would

need to show to prove this statement by contraposition.

22. Consider the statement “For all real numbers r , if r 2 is irra- tional then r is irrational.” a. Write what you would suppose and what you would

need to show to prove this statement by contradiction. b. Write what you would suppose and what you would

need to show to prove this statement by contraposition.

Prove each of the statements in 23–29 in two ways: (a) by con- traposition and (b) by contradiction.

23. The negative of any irrational number is irrational.

24. The reciprocal of any irrational number is irrational. (The reciprocal of a nonzero real number x is 1/x .)

25.H For all integers n, if n2 is odd then n is odd.

26. For all integers a, b, and c, if a ̸ | bc then a ̸ | b. (Recall that the symbol ̸ | means “does not divide.”)

27.H For all integers m and n, if m + n is even then m and n are both even or m and n are both odd.

28. For all integers m and n, if mn is even then m is even or n is even.

29. For all integers a, b, and c, if a | b and a ̸ | c, then a ̸ | (b + c). (Hint: To prove p → q ∨ r, it suffices to prove either p ∧ ∼q → r or p ∧ ∼r → q. See exercise 14 in Section 2.2.)

30. The following “proof” that every integer is rational is incor- rect. Find the mistake.

“Proof (by contradiction): Suppose not. Suppose every integer is irrational. Then the integer 1 is irrational. But 1 = 1/1, which is rational. This is a contradiction. [Hence the supposition is false and the theorem is true.] ”

31. a. Prove by contraposition: For all positive integers n, r , and s, if rs ≤ n, then r ≤ √n or s ≤ √n.

b. Prove: For all integers n > 1, if n is not prime, then there exists a prime number p such that p ≤ √n and n is divisible by p. (Hints: Use the result of part (a), Theorems 4.3.1, 4.3.3, and 4.3.4, and the transitive prop- erty of order.)

c. State the contrapositive of the result of part (b). The results of exercise 31 provide a way to test whether an integer is prime.

Test for Primality Given an integer n > 1, to test whether n is prime check to see if it is divisible by a prime number less than or equal to its square root. If it is not divisible by any of these numbers, then it is prime.

32. Use the test for primality to determine whether the follow- ing numbers are prime or not. a. 667 b. 557 c. 527 d. 613

33. The sieve of Eratosthenes, named after its inventor, the Greek scholar Eratosthenes (276–194 B.C.E.), provides a way to find all prime numbers less than or equal to some fixed number n. To construct it, write out all the integers from 2 to n. Cross out all multiples of 2 except 2 itself, then all multiples of 3 except 3 itself, then all multiples of 5 except 5 itself, and so forth. Continue crossing out the

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.7 Indirect Argument: Two Classical Theorems 207

multiples of each successive prime number up to √

n. The numbers that are not crossed out are all the prime numbers from 2 to n. Here is a sieve of Eratosthenes that includes the numbers from 2 to 27. The multiples of 2 are crossed out with a /, the multiples of 3 with a \, and the multiples of 5 with a —.

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Use the sieve of Eratosthenes to find all prime numbers less than 100.

34. Use the test for primality and the result of exercise 33 to determine whether the following numbers are prime. a. 9,269 b. 9,103 c. 8,623 d. 7,917

35.✶H Use proof by contradiction to show that every integer greater than 11 is a sum of two composite numbers.

Answers for Test Yourself 1. the statement is false; this supposition leads to a contradiction 2. the contrapositive of the statement, namely, ∀x ∈ D, if ∼Q(x) then ∼P(x) 3. x is any [particular but arbitrarily chosen] element of D for which Q(x) is false; P(x) is false

4.7 Indirect Argument: Two Classical Theorems

He is unworthy of the name of man who does not know that the diagonal of a square is incommensurable with its side.—Plato (ca. 428–347 B.C.E.)

This section contains proofs of two of the most famous theorems in mathematics: that √

2 is irrational and that there are infinitely many prime numbers. Both proofs are examples of indirect arguments and were well known more than 2,000 years ago, but they remain exemplary models of mathematical argument to this day.

The Irrationality of √

2 When mathematics flourished at the time of the ancient Greeks, mathematicians believed that given any two line segments, say A: and B: , a certain unit of length could be found so that segment A was exactly a units long and segment B was exactly b units long. (The segments were said to be commensurable with respect to this special unit of length.) Then the ratio of the lengths of A and B would be in the same proportion as the ratio of the integers a and b. Symbolically:

length A length B

= a b .

Now it is easy to find a line segment of length √

2; just take the diagonal of the unit square:

c

1

1

By the Pythagorean theorem, c2 = 12 + 12 = 2, and so c = √

2. If the belief of the ancient Greeks were correct, there would be integers a and b such that

length (diagonal) length (side)

= a b .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

208 Chapter 4 Elementary Number Theory and Methods of Proof

And this would imply that

c 1

= √

2 1

= √

2 = a b .

But then √

2 would be a ratio of two integers, or, in other words, √

2 would be rational. B

et tm

an n/

CO R

B IS

Euclid (fl. 300 B.C.E.)

In the fourth or fifth century B.C.E., the followers of the Greek mathematician and philosopher Pythagoras discovered that

√ 2 was not rational. This discovery was very

upsetting to them, for it undermined their deep, quasi-religious belief in the power of whole numbers to describe phenomena.

The following proof of the irrationality of √

2 was known to Aristotle and is similar to that in the tenth book of Euclid’s Elements of Geometry. The Greek mathematician Euclid is best known as a geometer. In fact, knowledge of the geometry in the first six books of his Elements has been considered an essential part of a liberal education for more than 2,000 years. Books 7–10 of his Elements, however, contain much that we would now call number theory.

The proof begins by supposing the negation: √

2 is rational. This means that there exist integers m and n such that

√ 2 = m/n. Now if m and n have any common factors,

these may be factored out to obtain a new fraction, equal to m/n, in which the numerator and denominator have no common factors. (For example, 18/12 = (6 ·3)/(6 ·2) = 3/2, which is a fraction whose numerator and denominator have no common factors.) Thus, without loss of generality, we may assume that m and n had no common factors in the first place. We will then derive the contradiction that m and n do have a common factor of 2. The argument makes use of Proposition 4.6.4. If the square of an integer is even, then that integer is even.

Note Strictly speaking, being able to assume that m and n have no common factors is a consequence of the “well-ordering principle for the integers,” which is discussed in Section 5.4.

Theorem 4.7.1 Irrationality of √

2 √

2 is irrational.

Proof:

[We take the negation and suppose it to be true.] Suppose not. That is, suppose √

2 is rational. Then there are integers m and n with no common factors such that

√ 2 = m

n 4.7.1

[by dividing m and n by any common factors if necessary]. [We must derive a contradic- tion.] Squaring both sides of equation (4.7.1) gives

2 = m 2

n2 .

Or, equivalently,

m2 = 2n2. 4.7.2 Note that equation (4.7.2) implies that m2 is even (by definition of even). It follows that m is even (by Proposition 4.6.4). We file this fact away for future reference and also deduce (by definition of even) that

m = 2k for some integer k. 4.7.3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.7 Indirect Argument: Two Classical Theorems 209

Substituting equation (4.7.3) into equation (4.7.2), we see that

m2 = (2k)2 = 4k2 = 2n2. Dividing both sides of the right-most equation by 2 gives

n2 = 2k2. Consequently, n2 is even, and so n is even (by Proposition 4.6.4). But we also know that m is even. [This is the fact we filed away.] Hence both m and n have a com- mon factor of 2. But this contradicts the supposition that m and n have no common factors. [Hence the supposition is false and so the theorem is true.]

Now that you have seen the proof that √

2 is irrational, you can use the irrationality of √

2 to derive the irrationality of certain other real numbers.

Example 4.7.1 Irrationality of 1 + 3 √

2

Prove by contradiction that 1 + 3 √

2 is irrational.

Solution The essence of the argument is the observation that if 1 + 3 √

2 could be written as a ratio of integers, then so could

√ 2. But by Theorem 4.7.1, we know that to be

impossible.

Proposition 4.7.2

1 + 3 √

2 is irrational.

Proof:

Suppose not. Suppose 1 + 3 √

2 is rational. [We must derive a contradiction.] Then by definition of rational,

1 + 3 √

2 = a b

for some integers a and b with b ̸= 0.

It follows that

3 √

2 = a b − 1 by subtracting 1 from both sides

= a b − b

b by substitution

= a − b b

by the rule for subtracting fractions

with a common denominator.

Hence √

2 = a − b 3b

by dividing both sides by 3.

But a − b and 3b are integers (since a and b are integers and differences and products of integers are integers), and 3b ̸= 0 by the zero product property. Hence

√ 2 is a quotient

of the two integers a − b and 3b with 3b ̸= 0, and so √

2 is rational (by definition of rational.) This contradicts the fact that

√ 2 is irrational. [This contradiction shows that

the supposition is false.] Hence 1 + 3 √

2 is irrational.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

210 Chapter 4 Elementary Number Theory and Methods of Proof

Are There Infinitely Many Prime Numbers? You know that a prime number is a positive integer that cannot be factored as a product of two smaller positive integers. Is the set of all such numbers infinite, or is there a largest prime number? The answer was known to Euclid, and a proof that the set of all prime numbers is infinite appears in Book 9 of his Elements of Geometry.

Euclid’s proof requires one additional fact we have not yet established: If a prime number divides an integer, then it does not divide the next successive integer.

Proposition 4.7.3

For any integer a and any prime number p, if p | a then p ̸ | (a + 1).

Proof:

Suppose not. That is, suppose there exists an integer a and a prime number p such that p | a and p | (a + 1). Then, by definition of divisibility, there exist integers r and s such that a = pr and a + 1 = ps. It follows that

1 = (a + 1)− a = ps − pr = p(s − r), and so (since s − r is an integer) p | 1. But, by Theorem 4.3.2, the only integer divisors of 1 are 1 and −1, and p > 1 because p is prime. Thus p ≤ 1 and p > 1, which is a contradiction. [Hence the supposition is false, and the proposition is true.]

The idea of Euclid’s proof is this: Suppose the set of prime numbers were finite. Then you could take the product of all the prime numbers and add one. By Theorem 4.3.4 this number must be divisible by some prime number. But by Proposition 4.7.3, this number is not divisible by any of the prime numbers in the set. Hence there must be a prime number that is not in the set of all prime numbers, which is impossible.

The following formal proof fills in the details of this outline.

Theorem 4.7.4 Infinitude of the Primes

The set of prime numbers is infinite.

Proof (by contradiction):

Suppose not. That is, suppose the set of prime numbers is finite. [We must deduce a contradiction.] Then some prime number p is the largest of all the prime numbers, and hence we can list the prime numbers in ascending order:

2, 3, 5, 7, 11,. . . ,p.

Let N be the product of all the prime numbers plus 1:

N = (2 ·3 ·5 ·7 ·11· · ·p) + 1 Then N > 1, and so, by Theorem 4.3.4, N is divisible by some prime number q. Because q is prime, q must equal one of the prime numbers 2, 3, 5, 7, 11, . . . , p.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.7 Indirect Argument: Two Classical Theorems 211

Thus, by definition of divisibility, q divides 2 ·3 ·5 ·7 ·11· · ·p, and so, by Proposition 4.7.3, q does not divide (2 ·3 ·5 ·7 ·11· · ·p) + 1, which equals N . Hence N is divisible by q and N is not divisible by q, and we have reached a contradiction. [Therefore, the supposition is false and the theorem is true.]

The proof of Theorem 4.7.4 shows that if you form the product of all prime numbers up to a certain point and add one, the result, N , is divisible by a prime number not on the list. The proof does not show that N is, itself, prime. In the exercises at the end of this section you are asked to find an example of an integer N constructed in this way that is not prime.

When to Use Indirect Proof The examples in this section and Section 4.6 have not provided a definitive answer to the question of when to prove a statement directly and when to prove it indirectly. Many theorems can be proved either way. Usually, however, when both types of proof are pos- sible, indirect proof is clumsier than direct proof. In the absence of obvious clues sug- gesting indirect argument, try first to prove a statement directly. Then, if that does not succeed, look for a counterexample. If the search for a counterexample is unsuccessful, look for a proof by contradiction or contraposition.

Open Questions in Number Theory In this section we proved that there are infinitely many prime numbers. There is no known formula for obtaining primes, but a few formulas have been found to be more successful at producing them than other formulas. One such is due to Marin Mersenne, a French monk who lived from 1588–1648. Mersenne primes have the form 2p − 1, where p is prime. Not all numbers of this form are prime, but because Mersenne primes are easier to test for primality than are other numbers, most of the largest known prime numbers are Mersenne primes.

An interesting question is whether there are infinitely many Mersenne primes. As of the date of publication of this book, the answer is not known, but new mathematical discoveries are being made every day and by the time you read this someone may have discovered the answer. Another formula that seems to produce a relatively large number of prime numbers is due to Fermat. Fermat primes are prime numbers of the form 22

n + 1, where n is a positive integer. Are there infinitely many Fermat primes? Again, as of now, no one knows. Similarly unknown are whether there are infinitely many primes of the form n2 + 1, where n is a positive integer, and whether there is always a prime number between integers n2 and (n + 1)2.

Co ur

te sy

B en

Jo se

ph G

re en

Ben Joseph Green (born 1977)

U CL

A

Terence Chi-Shen Tao (born 1975)

Another famous open question involving primes is the twin primes conjecture, which states that there are infinitely many pairs of prime numbers of the form p and p + 2. As with other well-known problems in number theory, this conjecture has withstood com- puter testing up to extremely large numbers, and some progress has been made toward a proof. In 2004, Ben Green and Terence Tao showed that for any integer m > 1, there is a sequence of m equally spaced integers all of which are prime. In other words, there are are positive integers n and k so that the following numbers are all prime:

n, n + k, n + 2k, n + 3k, . . . , n + (m − 1)k. Related to the twin primes conjecture is a conjecture made by Sophie Germain, a

French mathematician born in 1776, who made significant progress toward a proof of Fermat’s Last Theorem. Germain conjectured that there are infinitely many prime number

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

212 Chapter 4 Elementary Number Theory and Methods of Proof

pairs of the form p and 2p + 1. Initial values of p with this property are 2, 3, 5, 11, 23, 29, 41, and 53, and computer testing has verified the conjecture for many additional values. In fact, as of the writing of this book, the largest prime p for which 2p + 1 is also known to be prime is 183027 ·2265440 − 1. This is a number with 79911 decimal digits! But compared with infinity, any number, no matter how large, is less than a drop in the bucket.

In 1844, the Belgian mathematician Eugène Catalan conjectured that the only solu- tions to the equation xn − ym = 1, where x , y, n, and m are all integers greater than 1, is 32 − 23 = 1. This conjecture also remains unresolved to this day.

In 1993, while trying to prove Fermat’s last theorem, an amateur number theorist, Andrew Beal, became intrigued by the equation xm + yn = zk , where no two of x , y, or z have any common factor other than ±1. When diligent effort, first by hand and then by computer, failed to reveal any solutions, Beal conjectured that no solutions exist. His conjecture has become known as Beal’s conjecture, and he has offered a prize of $100,000 to anyone who can either prove or disprove it.

These are just a few of a large number of open questions in number theory. Many people believe that mathematics is a fixed subject that changes very little from one century to the next. In fact, more mathematical questions are being raised and more results are being discovered now than ever before in history.

Th e

Ar t

G al

le ry

Co lle

ct io

n/ Al

am y

Marie-Sophie Germain (1776–1831)

Test Yourself 1. The ancient Greeks discovered that in a right triangle where

both legs have length 1, the ratio of the length of the hypotenuse to the length of one of the legs is not equal to a ratio of _____.

2. One way to prove that √

2 is an irrational number is to assume that

√ 2 = a/b for some integers a and b that have

no common factor greater than 1, use the lemma that says

that if the square of an integer is even then _____, and even- tually show that a and b _____.

3. One way to prove that there are infinitely many prime num- bers is to assume that there is a largest prime number p, construct the number _____, and then show that this num- ber has to be divisible by a prime number that is greater than _____.

Exercise Set 4.7 1. A calculator display shows that

√ 2 = 1.414213562, and

1.414213562 = 1414213562 1000000000

. This suggests that √

2 is a

rational number, which contradicts Theorem 4.7.1. Explain the discrepancy.

2. Example 4.2.1(h) illustrates a technique for showing that any repeating decimal number is rational. A calcula- tor display shows the result of a certain calculation as 40.72727272727. Can you be sure that the result of the cal- culation is a rational number? Explain.

Determine which statements in 3–13 are true and which are false. Prove those that are true and disprove those that are false.

3. 6− 7 √

2 is irrational. 4. 3 √

2− 7 is irrational. 5. √

4 is irrational. 6. √

2/6 is rational.

7. The sum of any two irrational numbers is irrational.

8. The difference of any two irrational numbers is irrational.

9. The positive square root of a positive irrational number is irrational.

10. If r is any rational number and s is any irrational number, then r/s is irrational.

11. The sum of any two positive irrational numbers is irrational.

12. The product of any two irrational numbers is irrational.

13.H If an integer greater than 1 is a perfect square, then its cube root is irrational.

14. Consider the following sentence: If x is rational then √

x is irrational. Is this sentence always true, sometimes true and sometimes false, or always false? Justify your answer.

15. a. Prove that for all integers a, if a3 is even then a is even. b. Prove that 3

√ 2 is irrational.

16. a. Use proof by contradiction to show that for any inte- ger n, it is impossible for n to equal both 3q1 + r1 and 3q2 + r2, where q1, q2, r1, and r2, are integers, 0 ≤ r1 < 3, 0 ≤ r2 < 3, and r1 ̸= r2.

b. Use proof by contradiction, the quotient-remainder theorem, division into cases, and the result of part (a) to prove that for all integers n, if n2 is divisible by 3 then n is divisible by 3.

c. Prove that √

3 is irrational.

17. Give an example to show that if d is not prime and n2 is divisible by d, then n need not be divisible by d .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.7 Indirect Argument: Two Classical Theorems 213

18.H The quotient-remainder theorem says not only that there exist quotients and remainders but also that the quotient and remainder of a division are unique. Prove the uniqueness. That is, prove that if a and d are integers with d > 0 and if q1, r1, q2, and r2 are integers such that

a = dq1 + r1 where 0 ≤ r1 < d and

a = dq2 + r2 where 0 ≤ r2 < d, then

q1 = q2 and r1 = r2. 19.H Prove that

√ 5 is irrational.

20.H Prove that for any integer a, 9 ̸ | (a2 − 3). 21. An alternative proof of the irrationality of

√ 2 counts the

number of 2’s on the two sides of the equation 2n2 = m2 and uses the unique factorization of integers theorem to deduce a contradiction. Write a proof that uses this approach.

22. Use the proof technique illustrated in exercise 21 to prove that if n is any integer that is not a perfect square, then

√ n

is irrational.

23.H Prove that √

2 + √

3 is irrational.

24.✶ Prove that log5(2) is irrational. (Hint: Use the unique fac- torisation of integers theorem.)

25.H Let N = 2 ·3 ·5 ·7 + 1. What remainder is obtained when N is divided by 2? 3? 5? 7? Is N prime? Justify your answer.

26.H Suppose a is an integer and p is a prime number such that p | a and p | (a + 3). What can you deduce about p? Why?

27. Let p1, p2, p3, . . . be a list of all prime numbers in ascend- ing order. Here is a table of the first six:

p1 p2 p3 p4 p5 p6

2 3 5 7 11 13

a.H For each i = 1, 2, 3, 4, 5, 6, let Ni = p1 p2 · · · pi + 1. Calculate N1, N2, N3, N4, N5, and N6.

b. For each i = 1, 2, 3, 4, 5, 6, find the smallest prime number qi such that qi divides Ni . (Hint: Use the test for primality from exercise 31 in Section 4.6 to determine your answers.)

For exercises 28 and 29, use the fact that for all integers n,

n! = n(n − 1) . . . 3 ·2 ·1.

28. An alternative proof of the infinitude of the prime numbers begins as follows:

Proof: Suppose there are only finitely many prime num- bers. Then one is the largest. Call it p. Let M = p! + 1. We will show that there is a prime number q such that q > p. Complete this proof.

29.✶H Prove that for all integers n, if n > 2 then there is a prime number p such that n < p < n!.

30.✶H Prove that if p1, p2, . . . , and pn are distinct prime numbers with p1 = 2 and n > 1, then p1 p2 · · · pn + 1 can be written in the form 4k + 3 for some integer k.

31.H a. Fermat’s last theorem says that for all integers n > 2, the equation xn + yn = zn has no positive integer solu- tion (solution for which x, y, and z are positive integers). Prove the following: If for all prime numbers p > 2, x p + y p = z p has no positive integer solution, then for any integer n > 2 that is not a power of 2, xn + yn = zn has no positive integer solution.

b. Fermat proved that there are no integers x, y, and z such that x4 + y4 = z4. Use this result to remove the restric- tion in part (a) that n not be a power of 2. That is, prove that if n is a power of 2 and n > 4, then xn + yn = zn has no positive integer solution.

For exercises 32–35 note that to show there is a unique object with a certain property, show that (1) there is an object with the property and (2) if objects A and B have the property, then A = B.

32. Prove that there exists a unique prime number of the form n2 − 1, where n is an integer that is greater than or equal to 2.

33. Prove that there exists a unique prime number of the form n2 + 2n − 3, where n is a positive integer.

34. Prove that there is at most one real number a with the prop- erty that a + r = r for all real numbers r . (Such a number is called an additive identity.)

35. Prove that there is at most one real number b with the prop- erty that br = r for all real numbers r . (Such a number is called a multiplicative identity.)

Answers for Test Yourself 1. two integers 2. the integer is even; have a common factor greater than 1 3. 2 ·3 ·5 ·7 ·11 · · · p + 1; p

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

214 Chapter 4 Elementary Number Theory and Methods of Proof

4.8 Application: Algorithms

Begin at the beginning . . . and go on till you come to the end: then stop. — Lewis Carroll, Alice’s Adventures in Wonderland, 1865

In this section we will show how the number theory facts developed in this chapter form the basis for some useful computer algorithms.

The word algorithm refers to a step-by-step method for performing some action. Some examples of algorithms in everyday life are food preparation recipes, directions for assembling equipment or hobby kits, sewing pattern instructions, and instructions for filling out income tax forms. Much of elementary school mathematics is devoted to learn- ing algorithms for doing arithmetic such as multidigit addition and subtraction, multidigit (or long) multiplication, and long division.

The idea of a computer algorithm is credited to Ada Augusta, Countess of Lovelace. Trained as a mathematician, she became very interested in Charles Babbage’s design for an “Analytical Engine,” a machine similar in concept to a modern computer. Lady Lovelace extended Babbage’s explorations of how such a machine would operate, recog- nizing that its importance lay “in the possibility of using a given sequence of instructions repeatedly, the number of times being either preassigned or dependent on the results of the computation.” This is the essence of a modern computer algorithm.

H ul

to n

Ar ch

iv e/

G et

ty Im

ag es

Lady Lovelace (1815–1852)

An Algorithmic Language The algorithmic language used in this book is a kind of pseudocode, combining elements of Pascal, C, Java, and VB.NET, and ordinary, but fairly precise, English. We will use some of the formal constructs of computer languages—such as assignment statements, loops, and so forth—but we will ignore the more technical details, such as the require- ment for explicit end-of-statement delimiters, the range of integer values available on a particular installation, and so forth. The algorithms presented in this text are intended to be precise enough to be easily translated into virtually any high-level computer language.

In high-level computer languages, the term variable is used to refer to a specific storage location in a computer’s memory. To say that the variable x has the value 3 means that the memory location corresponding to x contains the number 3. A given storage location can hold only one value at a time. So if a variable is given a new value during program execution, then the old value is erased. The data type of a variable indicates the set in which the variable takes its values, whether the set of integers, or real numbers, or character strings, or the set {0, 1} (for a Boolean variable), and so forth.

An assignment statement gives a value to a variable. It has the form

x := e, where x is a variable and e is an expression. This is read “x is assigned the value e” or “let x be e.” When an assignment statement is executed, the expression e is evaluated (using the current values of all the variables in the expression), and then its value is placed in the memory location corresponding to x (replacing any previous contents of this location).

Ordinarily, algorithm statements are executed one after another in the order in which they are written. Conditional statements allow this natural order to be overridden by using the current values of program variables to determine which algorithm statement will be executed next. Conditional statements are denoted either

a. if (condition) or b. if (condition) then s1 then s1 else s2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 215

where condition is a predicate involving algorithm variables and where s1 and s2 are algorithm statements or groups of algorithm statements. We generally use indentation to indicate that statements belong together as a unit. When ambiguity is possible, however, we may explicitly bind a group of statements together into a unit by preceding the group with the word do and following it with the words end do.

Execution of an if-then-else statement occurs as follows:

1. The condition is evaluated by substituting the current values of all algorithm variables appearing in it and evaluating the truth or falsity of the resulting statement.

2. If condition is true, then s1 is executed and execution moves to the next algorithm statement following the if-then-else statement.

3. If condition is false, then s2 is executed and execution moves to the next algorithm statement following the if-then-else statement.

Execution of an if-then statement is similar to execution of an if-then-else statement, except that if condition is false, execution passes immediately to the next algorithm state- ment following the if-then statement.

Often condition is called a guard because it is stationed before s1 and s2 and restricts access to them.

Example 4.8.1 Execution of if-then-else and if-then Statements

Consider the following algorithm segments:

a. if x > 2 b. y := 0 then y := x + 1 if x > 2 then y := 2x else do x := x − 1

y := 3 ·x end do What is the value of y after execution of these segments for the following values of x?

i. x = 5 ii. x = 2 Solution

a. (i) Because the value of x is 5 before execution, the guard condition x > 2 is true at the time it is evaluated. Hence the statement following then is executed, and so the value of x + 1 = 5 + 1 is computed and placed in the storage location corresponding to y. So after execution, y = 6.

(ii) Because the value of x is 2 before execution, the guard condition x > 2 is false at the time it is evaluated. Hence the statement following else is executed. The value of x − 1 = 2 − 1 is computed and placed in the storage location corresponding to x , and the value of 3 ·x = 3 ·1 is computed and placed in the storage location corresponding to y. So after execution, y = 3.

b. (i) Since x = 5 initially, the condition x > 2 is true at the time it is evaluated. So the statement following then is executed, and y obtains the value 25 = 32.

(ii) Since x = 2 initially, the condition x > 2 is false at the time it is evaluated. Exe- cution, therefore, moves to the next statement following the if-then statement, and the value of y does not change from its initial value of 0. ■

Iterative statements are used when a sequence of algorithm statements is to be exe- cuted over and over again. We will use two types of iterative statements: while loops and for-next loops.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

216 Chapter 4 Elementary Number Theory and Methods of Proof

A while loop has the form

while (condition) [statements that make up the body of the loop]

end while

where condition is a predicate involving algorithm variables. The word while marks the beginning of the loop, and the words end while mark its end. Execution of a while loop occurs as follows:

1. The condition is evaluated by substituting the current values of all the algorithm vari- ables and evaluating the truth or falsity of the resulting statement.

2. If condition is true, all the statements in the body of the loop are executed in order. Then execution moves back to the beginning of the loop and the process repeats.

3. If condition is false, execution passes to the next algorithm statement following the loop.

The loop is said to be iterated (IT-a-rate-ed) each time the statements in the body of the loop are executed. Each execution of the body of the loop is called an iteration (it-er-AY- shun) of the loop.

Example 4.8.2 Tracing Execution of a whilewhilewhile Loop

Trace the execution of the following algorithm segment by finding the values of all the algorithm variables each time they are changed during execution:

i := 1, s := 0 while (i ≤ 2)

s := s + i i := i + 1

end while

Solution Since i is given an initial value of 1, the condition i ≤ 2 is true when the while loop is entered. So the statements within the loop are executed in order:

s = 0 + 1 = 1 and i = 1 + 1 = 2. Then execution passes back to the beginning of the loop.

The condition i ≤ 2 is evaluated using the current value of i , which is 2. The condition is true, and so the statements within the loop are executed again:

s = 1 + 2 = 3 and i = 2 + 1 = 3. Then execution passes back to the beginning of the loop.

The condition i ≤ 2 is evaluated using the current value of i , which is 3. This time the condition is false, and so execution passes beyond the loop to the next statement of the algorithm.

This discussion can be summarized in a table, called a trace table, that shows the current values of algorithm variables at various points during execution. The trace table for a while loop generally gives all values immediately following each iteration of the loop. (“After the zeroth iteration” means the same as “before the first iteration.”)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 217

Trace Table

Iteration Number 0 1 2

Variable Name i 1 2 3

s 0 1 3 ■

The second form of iteration we will use is a for-next loop. A for-next loop has the following form:

for variable := initial expression to final expression [statements that make up the body of the loop]

next (same) variable

A for-next loop is executed as follows:

1. The for-next loop variable is set equal to the value of initial expression.

2. A check is made to determine whether the value of variable is less than or equal to the value of final expression.

3. If the value of variable is less than or equal to the value of final expression, then the statements in the body of the loop are executed in order, variable is increased by 1, and execution returns back to step 2.

4. If the value of variable is greater than the value of final expression, then execution passes to the next algorithm statement following the loop.

Example 4.8.3 Trace Table for a for-nextfor-nextfor-next Loop

Convert the for-next loop shown below into a while loop. Construct a trace table for the loop.

for i := 1 to 4 x := i2

next i

Solution The given for-next loop is equivalent to the following:

i := 1 while (i ≤ 4)

x := i2 i := i + 1

end while

Its trace table is as follows:

Trace Table

Iteration Number 0 1 2 3 4

Variable Name x 1 4 9 16

i 1 2 3 4 5 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

218 Chapter 4 Elementary Number Theory and Methods of Proof

A Notation for Algorithms We will express algorithms as subroutines that can be called upon by other algorithms as needed and used to transform a set of input variables with given values into a set of output variables with specific values. The output variables and their values are assumed to be returned to the calling algorithm. For example, the division algorithm specifies a procedure for taking any two positive integers as input and producing the quotient and remainder of the division of one number by the other as output. Whenever an algorithm requires such a computation, the algorithm can just “call” the division algorithm to do the job.

We generally include the following information when describing algorithms formally:

1. The name of the algorithm, together with a list of input and output variables.

2. A brief description of how the algorithm works.

3. The input variable names, labeled by data type (whether integer, real number, and so forth).

4. The statements that make up the body of the algorithm, possibly with explanatory comments.

5. The output variable names, labeled by data type.

Su le

ym an

iy e

K ut

up ha

ne si

al-Khowârizmî (ca. 780–850)

You may wonder where the word algorithm came from. It evolved from the last part of the name of the Persian mathematician Abu Ja’far Mohammed ibn Mûsâ al-Khowârizmî. During Europe’s Dark Ages, the Arabic world enjoyed a period of intense intellectual activity. One of the great mathematical works of that period was a book written by al-Khowârizmî that contained foundational ideas for the subject of algebra. The trans- lation of this book into Latin in the thirteenth century had a profound influence on the development of mathematics during the European Renaissance.

The Division Algorithm For an integer a and a positive integer d, the quotient-remainder theorem guarantees the existence of integers q and r such that

a = dq + r and 0 ≤ r < d.

In this section, we give an algorithm to calculate q and r for given a and d where a is nonnegative. (The extension to negative a is left to the exercises at the end of this sec- tion.) The following example illustrates the idea behind the algorithm. Consider trying to find the quotient and the remainder of the division of 32 by 9, but suppose that you do not remember your multiplication table and have to figure out the answer from basic princi- ples. The quotient represents that number of 9’s that are contained in 32. The remainder is the number left over when all possible groups of 9 are subtracted. Thus you can calculate the quotient and remainder by repeatedly subtracting 9 from 32 until you obtain a number less than 9:

32− 9 = 23 ≥ 9, and 32− 9− 9 = 14 ≥ 9, and

32− 9− 9− 9 = 5 < 9.

This shows that 3 groups of 9 can be subtracted from 32 with 5 left over. Thus the quotient is 3 and the remainder is 5.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 219

Algorithm 4.8.1 Division Algorithm

[Given a nonnegative integer a and a positive integer d, the aim of the algorithm is to find integers q and r that satisfy the conditions a = dq + r and 0 ≤ r < d. This is done by subtracting d repeatedly from a until the result is less than d but is still nonnegative.

0 ≤ a − d − d − d − · · ·− d = a − dq < d. The total number of d’s that are subtracted is the quotient q. The quantity a − dq equals the remainder r .]

Input: a [a nonnegative integer], d [a positive integer] Algorithm Body:

r := a, q := 0 [Repeatedly subtract d from r until a number less than d is obtained. Add 1 to q each time d is subtracted.]

while (r ≥ d) r := r − d q := q + 1

end while [After execution of the while loop, a = dq + r .]

Output: q, r [nonnegative integers]

Note that the values of q and r obtained from the division algorithm are the same as those computed by the div and mod functions built into a number of computer languages. That is, if q and r are the quotient and remainder obtained from the division algorithm with input a and d , then the output variables q and r satisfy

q = a div d and r = a mod d. The next example asks for a trace of the division algorithm.

Example 4.8.4 Tracing the Division Algorithm

Trace the action of Algorithm 4.8.1 on the input variables a = 19 and d = 4. Solution Make a trace table as shown below. The column under the kth iteration gives the

states of the variables after the kth iteration of the loop.

Iteration Number 0 1 2 3 4

a 19

Variable Name d 4

r 19 15 11 7 3

q 0 1 2 3 4 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

220 Chapter 4 Elementary Number Theory and Methods of Proof

The Euclidean Algorithm The greatest common divisor of two integers a and b is the largest integer that divides both a and b. For example, the greatest common divisor of 12 and 30 is 6. The Euclidean algorithm provides a very efficient way to compute the greatest common divisor of two integers.

• Definition Let a and b be integers that are not both zero. The greatest common divisor of a and b, denoted gcd(a, b), is that integer d with the following properties:

1. d is a common divisor of both a and b. In other words,

d | a and d | b. 2. For all integers c, if c is a common divisor of both a and b, then c is less than or

equal to d. In other words,

for all integers c, if c | a and c | b, then c ≤ d.

Example 4.8.5 Calculating Some gcd’s

a. Find gcd(72, 63).

b. Find gcd(1020, 630).

c. In the definition of greatest common divisor, gcd(0, 0) is not allowed. Why not? What would gcd(0, 0) equal if it were found in the same way as the greatest common divisors for other pairs of numbers?

Solution

a. 72 = 9 ·8 and 63 = 9 ·7. So 9 | 72 and 9 | 63, and no integer larger than 9 divides both 72 and 63. Hence gcd(72, 63) = 9.

b. By the laws of exponents, 1020 = 220 ·520 and 630 = 230 ·330 = 220 ·210 ·330. It follows that

220 | 1020 and 220 | 630, and by the unique factorization of integers theorem, no integer larger than 220 divides both 1020 and 630 (because no more than twenty 2’s divide 1020, no 3’s divide 1020, and no 5’s divide 630). Hence gcd(1020, 630) = 220.

c. Suppose gcd(0, 0) were defined to be the largest common factor that divides 0 and 0. The problem is that every positive integer divides 0 and there is no largest integer. So there is no largest common divisor! ■

Calculating gcd’s using the approach illustrated in Example 4.8.5 works only when the numbers can be factored completely. By the unique factorization of integers theorem, all numbers can, in principle, be factored completely. But, in practice, even using the highest-speed computers, the process is unfeasibly long for very large integers. Over 2,000 years ago, Euclid devised a method for finding greatest common divisors that is easy to use and is much more efficient than either factoring the numbers or repeatedly testing both numbers for divisibility by successively larger integers.

The Euclidean algorithm is based on the following two facts, which are stated as lemmas.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 221

Lemma 4.8.1

If r is a positive integer, then gcd(r, 0) = r .

Proof:

Suppose r is a positive integer. [We must show that the greatest common divisor of both r and 0 is r .] Certainly, r is a common divisor of both r and 0 because r divides itself and also r divides 0 (since every positive integer divides 0). Also no integer larger than r can be a common divisor of r and 0 (since no integer larger than r can divide r ). Hence r is the greatest common divisor of r and 0.

The proof of the second lemma is based on a clever pattern of argument that is used in many different areas of mathematics: To prove that A = B, prove that A ≤ B and that B ≤ A.

Lemma 4.8.2

If a and b are any integers not both zero, and if q and r are any integers such that

a = bq + r, then

gcd(a, b) = gcd(b, r).

Proof:

[The proof is divided into two sections: (1) proof that gcd(a, b) ≤ gcd(b, r), and (2) proof that gcd(b, r) ≤ gcd(a, b). Since each gcd is less than or equal to the other, the two must be equal.]

1. gcd (a, b) ≤ gcd (b, r): a. [We will first show that any common divisor of a and b is also a common divisor

of b and r.] Let a and b be integers, not both zero, and let c be a common divisor of

a and b. Then c | a and c | b, and so, by definition of divisibility, a = nc and b = mc, for some integers n and m. Now substitute into the equation

a = bq + r to obtain

nc = (mc)q + r. Then solve for r :

r = nc − (mc)q = (n − mq)c. But n − mq is an integer, and so, by definition of divisibility, c | r . Because we already know that c | b, we can conclude that c is a common divisor of b and r [as was to be shown].

continued on page 222

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

222 Chapter 4 Elementary Number Theory and Methods of Proof

b. [Next we show that gcd(a, b) ≤ gcd(b, r).] By part (a), every common divisor of a and b is a common divisor of b and

r . It follows that the greatest common divisor of a and b is defined because a and b are not both zero, and it is a common divisor of b and r . But then gcd(a, b) (being one of the common divisors of b and r ) is less than or equal to the greatest common divisor of b and r :

gcd(a, b) ≤ gcd(b, r).

2. gcd (b, r) ≤ gcd (a, b): The second part of the proof is very similar to the first part. It is left as an

exercise.

The Euclidean algorithm can be described as follows:

1. Let A and B be integers with A > B ≥ 0. 2. To find the greatest common divisor of A and B, first check whether B = 0. If it

is, then gcd(A, B) = A by Lemma 4.8.1. If it isn’t, then B > 0 and the quotient- remainder theorem can be used to divide A by B to obtain a quotient q and a remainder r :

A = Bq + r where 0 ≤ r < B.

By Lemma 4.8.2, gcd(A, B) = gcd(B, r). Thus the problem of finding the greatest common divisor of A and B is reduced to the problem of finding the greatest common divisor of B and r .

What makes this piece of information useful is that B and r are smaller numbers than A and B. To see this, recall that we assumed

A > B ≥ 0.

Also the r found by the quotient-remainder theorem satisfies

0 ≤ r < B.

Putting these two inequalities together gives

0 ≤ r < B < A.

So the larger number of the pair (B, r) is smaller than the larger number of the pair (A, B).

3. Now just repeat the process, starting again at (2), but use B instead of A and r instead of B. The repetitions are guaranteed to terminate eventually with r = 0 because each new remainder is less than the preceding one and all are nonnegative.

Note Strictly speaking, the fact that the repetitions eventually terminate is justified by the well-ordering principle for the integers, which is discussed in Section 5.4.

By the way, it is always the case that the number of steps required in the Euclidean algorithm is at most five times the number of digits in the smaller integer. This was proved by the French mathematician Gabriel Lamé (1795–1870).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 223

The following example illustrates how to use the Euclidean algorithm.

Example 4.8.6 Hand-Calculation of gcd’s Using the Euclidean Algorithm

Use the Euclidean algorithm to find gcd(330, 156).

Solution

1. Divide 330 by 156:

2 ← quotient 156 330

312 18 ← remainder

Thus 330 = 156 ·2 + 18 and hence gcd(330, 156) = gcd(156, 18) by Lemma 4.8.2. 2. Divide 156 by 18:

8 ← quotient 18 156

144 12 ← remainder

Thus 156 = 18 ·8 + 12 and hence gcd(156, 18) = gcd(18, 12) by Lemma 4.8.2. 3. Divide 18 by 12:

1 ← quotient 12 18

12 6 ← remainder

Thus 18 = 12 ·1 + 6 and hence gcd(18, 12) = gcd(12, 6) by Lemma 4.8.2. 4. Divide 12 by 6:

2 ← quotient 6 12

12 0 ← remainder

Thus 12 = 6 ·2 + 0 and hence gcd(12, 6) = gcd(6, 0) by Lemma 4.8.2. Putting all the equations above together gives

gcd(330, 156) = gcd(156, 18) = gcd(18, 12) = gcd(12, 6) = gcd(6, 0) = 6 by Lemma 4.8.1.

Therefore, gcd(330, 156) = 6. ■

The following is a version of the Euclidean algorithm written using formal algorithm notation.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

224 Chapter 4 Elementary Number Theory and Methods of Proof

Algorithm 4.8.2 Euclidean Algorithm

[Given two integers A and B with A > B ≥ 0, this algorithm computes gcd(A, B). It is based on two facts:

1. gcd(a, b) = gcd(b, r) if a, b, q, and r are integers with a = b ·q + r and 0 ≤ r < b. 2. gcd(a, 0) = a.] Input: A, B [integers with A > B ≥ 0] Algorithm Body:

a := A, b := B, r := B [If b ̸= 0, compute a mod b, the remainder of the integer division of a by b, and set r equal to this value. Then repeat the process using b in place of a and r in place of b.]

while (b ̸= 0) r := a mod b

[The value of a mod b can be obtained by calling the division algorithm.]

a := b b := r

end while [After execution of the while loop, gcd(A, B) = a.] gcd := a

Output: gcd [a positive integer]

Test Yourself 1. When an algorithm statement of the form x := e is exe-

cuted, _____.

2. Consider an algorithm statement of the following form.

if (condition) then s1 else s2 When such a statement is executed, the truth or falsity

of the condition is evaluated. If condition is true, _____. If condition is false, _____.

3. Consider an algorithm statement of the following form.

while (condition) [statements that make up the body of the loop] end while

When such a statement is executed, the truth or falsity of the condition is evaluated. If condition is true, _____. If condition is false, _____.

4. Consider an algorithm statement of the following form.

for variable := initial expression to final expression. [statements that make up the body of the loop] next (same) variable

When such a statement is executed, variable is set equal to the value of the initial expression, and a check is made to determine whether the value of variable is less than or equal to the value of final expression. If so, _____. If not, _____.

5. Given a nonnegative integer a and a positive integer d the division algorithm computes _____.

6. Given integers a and b, not both zero, gcd(a, b) is the inte- ger d that satisfies the following two conditions: _____ and _____.

7. If r is a positive integer, then gcd(r, 0) = _____.

8. If a and b are integers not both zero and if q and r are nonnegative integers such that a = bq + r then gcd(a, b) = _____.

9. Given positive integers A and B with A > B, the Euclidean algorithm computes _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.8 Application: Algorithms 225

Exercise Set 4.8 Find the value of z when each of the algorithm segments in 1 and 2 is executed.

1. i := 2 if (i > 3 or i ≤ 0)

then z := 1 else z := 0

2. i := 3 if (i ≤ 3 or i > 6)

then z := 2 else z := 0

3. Consider the following algorithm segment:

if x · y > 0 then do y := 3 · x x := x + 1 end do

z := x · y Find the value of z if prior to execution x and y have the values given below. a. x = 2, y = 3 b. x = 1, y = 1

Find the values of a and e after execution of the loops in 4 and 5:

4. a := 2 for i := 1 to 2

a := a 2

+ 1 a

next i

5. e := 0, f := 2 for j := 1 to 4

f := f · j

e := e + 1 f

next j

Make a trace table to trace the action of Algorithm 4.8.1 for the input variables given in 6 and 7.

6. a = 26, d = 7 7. a = 59, d = 13 8. The following algorithm segment makes change; given an

amount of money A between 1c/ and 99c/, it determines a breakdown of A into quarters (q), dimes (d), nickels (n), and pennies (p).

q : = A div 25 A : = A mod 25 d : = A div 10 A : = A mod 10 n : = A div 5 p : = A mod 5

a. Trace this algorithm segment for A = 69. b. Trace this algorithm segment for A = 87.

Find the greatest common divisor of each of the pairs of integers in 9–12. (Use any method you wish.)

9. 27 and 72 10. 5 and 9

11. 7 and 21 12. 48 and 54

Use the Euclidean algorithm to hand-calculate the greatest com- mon divisors of each of the pairs of integers in 13–16.

13. 1,188 and 385 14. 509 and 1,177

15. 832 and 10,933 16. 4,131 and 2,431

Make a trace table to trace the action of Algorithm 4.8.2 for the input variables given in 17 and 18.

17. 1,001 and 871 18. 5,859 and 1,232

19.H Prove that for all positive integers a and b, a | b if, and only if, gcd(a, b) = a. (Note that to prove “A if, and only if, B,” you need to prove “if A then B” and “if B then A.”)

20. a. Prove that if a and b are integers, not both zero, and d = gcd(a, b), then a/d and b/d are integers with no common divisor that is greater than one.

b. Write an algorithm that accepts the numerator and denominator of a fraction as input and produces as out- put the numerator and denominator of that fraction writ- ten in lowest terms. (The algorithm may call upon the Euclidean algorithm as needed.)

21. Complete the proof of Lemma 4.8.2 by proving the follow- ing: If a and b are any integers with b ̸= 0 and q and r are any integers such that

a = bq + r. then gcd(b, r) ≤ gcd(a, b).

22.H a. Prove: If a and d are positive integers and q and r are integers such that a = dq + r and 0 < r < d, then

−a = d(−(q + 1)) + (d − r) and 0 < d − r < d.

b. Indicate how to modify Algorithm 4.8.1 to allow for the input a to be negative.

23. a. Prove that if a, d, q, and r are integers such that a = dq + r and 0 ≤ r < d, then

q = ⌊a/d⌋ and r = a − ⌊a/d⌋ ·d. b. In a computer language with a built-in-floor function,

div and mod can be calculated as follows:

a div d = ⌊a/d⌋ and a mod d = a − ⌊a/d⌋ ·d. Rewrite the steps of Algorithm 4.8.2 for a computer lan- guage with a built-in floor function but without div and mod.

24. An alternative to the Euclidean algorithm uses subtraction rather than division to compute greatest common divisors. (After all, division is repeated subtraction.) It is based on the following lemma:

Lemma 4.8.3

If a ≥ b > 0, then gcd(a, b) = gcd(b, a − b).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

226 Chapter 4 Elementary Number Theory and Methods of Proof

Algorithm 4.8.3 Computing gcd’s by Subtraction [Given two positive integers A and B, variables a and b are set equal to A and B. Then a repetitive process begins. If a ̸= 0, and b ̸= 0, then the larger of a and b is set equal to a − b (if a ≥ b) or to b − a (if a < b), and the smaller of a and b is left unchanged. This process is repeated over and over until eventu- ally a or b becomes 0. By Lemma 4.8.3, after each repetition of the process,

gcd(A, B) = gcd(a, b).

After the last repetition,

gcd(A, B) = gcd(a, 0) or gcd(A, B) = gcd(0, b)

depending on whether a or b is nonzero. But by Lemma 4.8.1,

gcd(a, 0) = a and gcd(0, b) = b. Hence, after the last repetition,

gcd(A, B) = a if a ̸= 0 or gcd(A, B) = b if b ̸= 0.]

Input: A, B [positive integers]

Algorithm Body:

a := A, b := B while (a ̸= 0 and b ̸= 0)

if a ≥ b then a := a − b else b := b − a

end while

if a = 0 then gcd := b else gcd := a [After execution of the if-then-else statement, gcd = gcd(A, B).]

Output: gcd [a positive integer]

a. Prove Lemma 4.8.3. b. Trace the execution of Algorithm 4.8.3 for A = 630 and

B = 336. c. Trace the execution of Algorithm 4.8.3 for A = 768 and

B = 348. Exercises 25–29 refer to the following definition.

Definition: The least common multiple of two nonzero inte- gers a and b, denoted lcm(a, b), is the positive integer c such that a. a | c and b | c b. for all positive integers m, if a | m and b | m, then c ≤ m.

25. Find a. lcm(12, 18) b. lcm(22 ·3 ·5, 23 ·32) c. lcm(2800, 6125)

26. Prove that for all positive integers a and b, gcd(a, b) = lcm(a, b) if, and only if, a = b.

27. Prove that for all positive integers a and b, a | b if, and only if, lcm(a, b) = b.

28. Prove that for all integers a and b, gcd(a, b) | lcm(a, b). 29.H Prove that for all positive integers a and b,

gcd(a, b) · lcm(a, b) = ab.

Answers for Test Yourself 1. the expression e is evaluated (using the current values of all the variables in the expression), and this value is placed in the memory location corresponding to x (replacing any previous contents of the location) 2. statement s1 is executed; statement s2 is executed 3. all statements in the body of the loop are executed in order and then execution moves back to the beginning of the loop and the process repeats; execution passes to the next algorithm statement following the loop 4. the statements in the body of the loop are executed in order, variable is increased by 1, and execution returns to the top of the loop; execution passes to the next algorithm statement following the loop 5. integers q and r with the property that n = dq + r and 0 ≤ r < d 6. d divides both a and b; if c is a common divisor of both a and b, then c ≤ d 7. r 8. gcd(b, r) 9. the greatest common divisor of A and B (Or: gcd(A,B))

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

227

CHAPTER 5

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

One of the most important tasks of mathematics is to discover and characterize regular patterns, such as those associated with processes that are repeated. The main mathemati- cal structure used in the study of repeated processes is the sequence, and the main mathe- matical tool used to verify conjectures about sequences is mathematical induction. In this chapter we introduce the notation and terminology of sequences, show how to use both ordinary and strong mathematical induction to prove properties about them, illustrate the various ways recursively defined sequences arise, describe a method for obtaining an explicit formula for a recursively defined sequence, and explain how to verify the cor- rectness of such a formula. We also discuss a principle—the well-ordering principle for the integers—that is logically equivalent to the two forms of mathematical induction, and we show how to adapt mathematical induction to prove the correctness of computer algo- rithms. In the final section we discuss more general recursive definitions, such as the one used for the careful formulation of the concept of Boolean expression, and the idea of recursive function.

5.1 Sequences

A mathematician, like a painter or poet, is a maker of patterns. — G. H. Hardy, A Mathematician’s Apology, 1940

Imagine that a person decides to count his ancestors. He has two parents, four grandpar- ents, eight great-grandparents, and so forth, These numbers can be written in a row as

2, 4, 8, 16, 32, 64, 128, . . .

The symbol “. . .” is called an ellipsis. It is shorthand for “and so forth.” To express the pattern of the numbers, suppose that each is labeled by an integer

giving its position in the row.

Position in the row 1 2 3 4 5 6 7 . . .

Number of ancestors 2 4 8 16 32 64 128 . . .

The number corresponding to position 1 is 2, which equals 21. The number corresponding to position 2 is 4, which equals 22. For positions 3, 4, 5, 6, and 7, the corresponding

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

228 Chapter 5 Sequences, Mathematical Induction, and Recursion

numbers are 8, 16, 32, 64, and 128, which equal 23, 24, 25, 26, and 27, respectively. For a general value of k, let Ak be the number of ancestors in the kth generation back. The pattern of computed values strongly suggests the following for each k:

Ak = 2k .

Note Strictly speaking, the true value of Ak is less than 2k when k is large, because ancestors from one branch of the family tree may also appear on other branches of the tree. • Definition

A sequence is a function whose domain is either all the integers between two given integers or all the integers greater than or equal to a given integer.

We typically represent a sequence as a set of elements written in a row. In the sequence denoted

am, am+1, am+2, . . . , an,

each individual element ak (read “a sub k”) is called a term. The k in ak is called a subscript or index, m (which may be any integer) is the subscript of the initial term, and n (which must be greater than or equal to m) is the subscript of the final term. The notation

am, am+1, am+2, . . .

denotes an infinite sequence. An explicit formula or general formula for a sequence is a rule that shows how the values of ak depend on k.

The following example shows that it is possible for two different formulas to give sequences with the same terms.

Example 5.1.1 Finding Terms of Sequences Given by Explicit Formulas

Define sequences a1, a2, a3, . . . and b2, b3, b4, . . . by the following explicit formulas:

ak = k

k + 1 for all integers k ≥ 1,

bi = i − 1

i for all integers i ≥ 2.

Compute the first five terms of both sequences.

Solution a1 =

1 1 + 1 =

1 2

b2 = 2− 1

2 = 1

2

a2 = 2

2 + 1 = 2 3

b3 = 3− 1

3 = 2

3

a3 = 3

3 + 1 = 3 4

b4 = 4− 1

4 = 3

4

a4 = 4

4 + 1 = 4 5

b5 = 5− 1

5 = 4

5

a5 = 5

5 + 1 = 5 6

b6 = 6− 1

6 = 5

6

As you can see, the first terms of both sequences are 12 , 2 3 ,

3 4 ,

4 5 ,

5 6 ; in fact, it can be

shown that all terms of both sequences are identical. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 229

The next example shows that an infinite sequence may have a finite number of values.

Example 5.1.2 An Alternating Sequence

Compute the first six terms of the sequence c0, c1, c2, . . . defined as follows:

c j = (−1) j for all integers j ≥ 0. Solution c0 = (−1)0 = 1

c1 = (−1)1 = −1 c2 = (−1)2 = 1 c3 = (−1)3 = −1 c4 = (−1)4 = 1 c5 = (−1)5 = −1

Thus the first six terms are 1,−1, 1,−1, 1,−1. By exercises 33 and 34 of Section 4.1, even powers of −1 equal 1 and odd powers of −1 equal −1. It follows that the sequence oscillates endlessly between 1 and −1. ■

In Examples 5.1.1 and 5.1.2 the task was to compute the first few values of a sequence given by an explicit formula. The next example treats the question of how to find an explicit formula for a sequence with given initial terms. Any such formula is a guess, but it is very useful to be able to make such guesses.

Example 5.1.3 Finding an Explicit Formula to Fit Given Initial Terms

Find an explicit formula for a sequence that has the following initial terms:

1, −1 4 ,

1 9 , − 1

16 ,

1 25

, − 1 36

, . . . .

Solution Denote the general term of the sequence by ak and suppose the first term is a1. Then observe that the denominator of each term is a perfect square. Thus the terms can be rewritten as

1 12

, (−1)

22 ,

1 32

, (−1)

42 ,

1 52

, (−1)

62 .

↕ ↕ ↕ ↕ ↕ ↕ a1 a2 a3 a4 a5 a6

Note that the denominator of each term equals the square of the subscript of that term, and that the numerator equals ±1. Hence

ak = ±1 k2

.

Also the numerator oscillates back and forth between +1 and −1; it is +1 when k is odd and−1 when k is even. To achieve this oscillation, insert a factor of (−1)k+1 (or (−1)k−1) into the formula for ak . [For when k is odd, k + 1 is even and thus (−1)k+1 = +1; and when k is even, k + 1 is odd and thus (−1)k+1 = −1.] Consequently, an explicit formula that gives the correct first six terms is

ak = (−1)k+1

k2 for all integers k ≥ 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

230 Chapter 5 Sequences, Mathematical Induction, and Recursion

! Caution! It is also possible for two sequences to start off with the same initial values but diverge later on. See exercise 5 at the end of this section.

Note that making the first term a0 would have led to the alternative formula

ak = (−1)k

(k + 1)2 for all integers k ≥ 0.

You should check that this formula also gives the correct first six terms. ■

Summation Notation Consider again the example in which Ak = 2k represents the number of ancestors a per- son has in the kth generation back. What is the total number of ancestors for the past six generations? The answer is

A1 + A2 + A3 + A4 + A5 + A6 = 21 + 22 + 23 + 24 + 25 + 26 = 126.

CO R

B IS

Joseph Louis Lagrange (1736–1813)

It is convenient to use a shorthand notation to write such sums. In 1772 the French mathematician Joseph Louis Lagrange introduced the capital Greek letter sigma, %, to denote the word sum (or summation), and defined the summation notation as follows:

• Definition

If m and n are integers and m ≤ n, the symbol n∑

k=m ak , read the summation from

k equals m to n of a-sub-k, is the sum of all the terms am, am+1, am+2, . . . , an . We say that am + am+1 + am+2 + . . . + an is the expanded form of the sum, and we write

n∑

k=m ak = am + am+1 + am+2 + · · · + an.

We call k the index of the summation, m the lower limit of the summation, and n the upper limit of the summation.

Example 5.1.4 Computing Summations

Let a1 = −2, a2 = −1, a3 = 0, a4 = 1, and a5 = 2. Compute the following:

a. 5∑

k=1 ak b.

2∑

k=2 ak c.

2∑

k=1 a2k

Solution

a. 5∑

k=1 ak = a1 + a2 + a3 + a4 + a5 = (−2) + (−1) + 0 + 1 + 2 = 0

b. 2∑

k=2 ak = a2 = −1

c. 2∑

k=1 a2k = a2 ·1 + a2 ·2 = a2 + a4 = −1 + 1 = 0 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 231

Oftentimes, the terms of a summation are expressed using an explicit formula. For instance, it is common to see summations such as

5∑

k=1 k2 or

8∑

i=0

(−1)i i + 1 .

Example 5.1.5 When the Terms of a Summation Are Given by a Formula

Compute the following summation:

5∑

k=1 k2.

Solution 5∑

k=1 k2 = 12 + 22 + 32 + 42 + 52 = 55. ■

When the upper limit of a summation is a variable, an ellipsis is used to write the summation in expanded form.

Example 5.1.6 Changing from Summation Notation to Expanded Form

Write the following summation in expanded form:

n∑

i=0

(−1)i i + 1 .

Solution n∑

i=0

(−1)i i + 1 =

(−1)0 0 + 1 +

(−1)1 1 + 1 +

(−1)2 2 + 1 +

(−1)3 3 + 1 + · · · +

(−1)n n + 1

= 1 1

+ (−1) 2

+ 1 3

+ (−1) 4

+ · · · + (−1) n

n + 1

= 1− 1 2

+ 1 3 − 1

4 + · · · + (−1)

n

n + 1 ■

Example 5.1.7 Changing from Expanded Form to Summation Notation

Express the following using summation notation:

1 n

+ 2 n + 1 +

3 n + 2 + · · · +

n + 1 2n

.

Solution The general term of this summation can be expressed as k + 1 n + k for integers k from

0 to n. Hence

1 n

+ 2 n + 1 +

3 n + 2 + · · · +

n + 1 2n

= n∑

k=0

k + 1 n + k . ■

For small values of n, the expanded form of a sum may appear ambiguous. For instance, consider

12 + 22 + 32 + · · · + n2. This expression is intended to represent the sum of squares of consecutive integers start- ing with 12 and ending with n2. Thus, if n = 1 the sum is just 12, if n = 2 the sum is 12 + 22, and if n = 3 the sum is 12 + 22 + 32.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

232 Chapter 5 Sequences, Mathematical Induction, and Recursion

Example 5.1.8 Evaluating a1, a2, a3, . . . , an for Small n

What is the value of the expression 1

1 ·2 + 1

2 ·3 + 1

3 ·4 + · · · + 1

n ·(n + 1) when n = 1? n = 2? n = 3?

! Caution! Do not write that for n = 1, the sum is

1 1 ·2 +

1 2 ·3 +

1 3 ·4 + · · · +

1 1 ·2 .

This is crossed out because it is incorrect.

Solution

When n = 1, the expression equals 1 1 ·2 =

1 2

.

When n = 2, it equals 1 1 ·2 +

1 2 ·3 =

1 2

+ 1 6

= 2 3 .

When n = 3, it is 1 1 ·2 +

1 2 ·3 +

1 3 ·4 =

1 2

+ 1 6

+ 1 12

= 3 4 .

A more mathematically precise definition of summation, called a recursive definition, is the following:∗ If m is any integer, then

m∑

k=m ak = am and

n∑

k=m ak =

n−1∑

k=m ak + an for all integers n > m.

When solving problems, it is often useful to rewrite a summation using the recursive form of the definition, either by separating off the final term of a summation or by adding a final term to a summation.

Example 5.1.9 Separating Off a Final Term and Adding On a Final Term

a. Rewrite n+1∑

i=1

1 i2

by separating off the final term.

b. Write n∑

k=0 2k + 2n+1 as a single summation.

Solution

a. n+1∑

i=1

1 i2

= n∑

i=1

1 i2

+ 1 (n + 1)2 b.

n∑

k=0 2k + 2n+1 =

n+1∑

k=0 2k ■

In certain sums each term is a difference of two quantities. When you write such sums in expanded form, you sometimes see that all the terms cancel except the first and the last. Successive cancellation of terms collapses the sum like a telescope.

Example 5.1.10 A Telescoping Sum

Some sums can be transformed into telescoping sums, which then can be rewritten as a simple expression. For instance, observe that

1 k − 1

k + 1 = (k + 1)− k

k(k + 1) = 1

k(k + 1) .

Use this identity to find a simple expression for n∑

k=1

1 k(k + 1) .

∗Other recursively defined sequences are discussed later in this section and, in greater detail, in Section 5.6.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 233

Solution n∑

k=1

1 k(k + 1) =

n∑

k=1

( 1 k − 1

k + 1

)

= (

1 1 − 1

2

) + (

1 2 − 1

3

) + (

1 3 − 1

4

) + · · · +

( 1

n − 1 − 1 n

) + (

1 n − 1

n + 1

)

= 1− 1 n + 1 . ■

Product Notation The notation for the product of a sequence of numbers is analogous to the notation for their sum. The Greek capital letter pi, &, denotes a product. For example,

5∏

k=1 ak = a1a2a3a4a5.

• Definition

If m and n are integers and m ≤ n, the symbol n∏

k=m ak , read the product from k

equals m to n of a-sub-k, is the product of all the terms am, am+1, am+2, . . . , an .

We write n∏

k=m ak = am ·am+1 ·am+2 · · · an.

A recursive definition for the product notation is the following: If m is any integer, then

m∏

k=m ak = am and

n∏

k=m ak = (

n−1∏

k=m ak

)

·an for all integers n > m.

Example 5.1.11 Computing Products

Compute the following products:

a. 5∏

k=1 k b.

1∏

k=1

k k + 1

Solution

a. 5∏

k=1 k = 1 ·2 ·3 ·4 ·5 = 120 b.

1∏

k=1

k k + 1 =

1 1 + 1 =

1 2

Properties of Summations and Products The following theorem states general properties of summations and products. The proof of the theorem is discussed in Section 5.6.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

234 Chapter 5 Sequences, Mathematical Induction, and Recursion

Theorem 5.1.1

If am, am+1, am+2, . . . and bm, bm+1, bm+2, . . . are sequences of real numbers and c is any real number, then the following equations hold for any integer n ≥ m:

1. n∑

k=m ak +

n∑

k=m bk =

n∑

k=m (ak + bk)

2. c · n∑

k=m ak =

n∑

k=m c ·ak generalized distributive law

3.

( n∏

k=m ak

)

· (

n∏

k=m bk

)

= n∏

k=m (ak ·bk).

Example 5.1.12 Using Properties of Summation and Product

Let ak = k + 1 and bk = k − 1 for all integers k. Write each of the following expressions as a single summation or product:

a. n∑

k=m ak + 2 ·

n∑

k=m bk b.

( n∏

k=m ak

)

· (

n∏

k=m bk

)

Solution

a. n∑

k=m ak + 2 ·

n∑

k=m bk =

n∑

k=m (k + 1) + 2 ·

n∑

k=m (k − 1) by substitution

= n∑

k=m (k + 1) +

n∑

k=m 2 ·(k − 1) by Theorem 5.1.1 (2)

= n∑

k=m ((k + 1) + 2 ·(k − 1)) by Theorem 5.1.1 (1)

= n∑

k=m (3k − 1) by algebraic

simplification

b. ( n∏

k=m ak

)

· (

n∏

k=m bk

)

= (

n∏

k=m (k + 1)

)

· (

n∏

k=m (k − 1)

)

by substitution

= n∏

k=m (k + 1) ·(k − 1) by Theorem 5.1.1 (3)

= n∏

k=m (k2 − 1) by algebraic

simplification ■

Change of Variable Observe that

3∑

k=1 k2 = 12 + 22 + 32

and also that 3∑

i=1 i2 = 12 + 22 + 32.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 235

Hence

3∑

k=1 k2 =

3∑

i=1 i2.

This equation illustrates the fact that the symbol used to represent the index of a sum- mation can be replaced by any other symbol as long as the replacement is made in each location where the symbol occurs. As a consequence, the index of a summation is called a dummy variable. A dummy variable is a symbol that derives its entire meaning from its local context. Outside of that context (both before and after), the symbol may have another meaning entirely.

The appearance of a summation can be altered by more complicated changes of variable as well. For example, observe that

4∑

j=2 ( j − 1)2 = (2− 1)2 + (3− 1)2 + (4− 1)2

= 12 + 22 + 32

= 3∑

k=1 k2.

A general procedure to transform the first summation into the second is illustrated in Example 5.1.13.

Example 5.1.13 Transforming a Sum by a Change of Variable

Transform the following summation by making the specified change of variable.

summation: 6∑

k=0

1 k + 1 change of variable: j = k + 1

Solution First calculate the lower and upper limits of the new summation:

When k = 0, j = k + 1 = 0 + 1 = 1. When k = 6, j = k + 1 = 6 + 1 = 7.

Thus the new sum goes from j = 1 to j = 7. Next calculate the general term of the new summation. You will need to replace each

occurrence of k by an expression in j :

Since j = k + 1, then k = j − 1.

Hence 1

k + 1 = 1

( j − 1) + 1 = 1 j .

Finally, put the steps together to obtain

6∑

k=0

1 k + 1 =

7∑

j=1

1 j .

■ 5.1.1

Equation (5.1.1) can be given an additional twist by noting that because the j in the right-hand summation is a dummy variable, it may be replaced by any other variable

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

236 Chapter 5 Sequences, Mathematical Induction, and Recursion

name, as long as the substitution is made in every location where j occurs. In particular, it is legal to substitute k in place of j to obtain

7∑

j=1

1 j

= 7∑

k=1

1 k . 5.1.2

Putting equations (5.1.1) and (5.1.2) together gives

6∑

k=0

1 k + 1 =

7∑

k=1

1 k .

Sometimes it is necessary to shift the limits of one summation in order to add it to another. An example is the algebraic proof of the binomial theorem, given in Section 9.7. A general procedure for making such a shift when the upper limit is part of the summand is illustrated in the next example.

Example 5.1.14 When the Upper Limit Appears in the Expression to Be Summed

a. Transform the following summation by making the specified change of variable.

summation: n+1∑

k=1

( k

n + k

) change of variable: j = k − 1

b. Transform the summation obtained in part (a) by changing all j’s to k’s.

Solution

a. When k = 1, then j = k − 1 = 1− 1 = 0. (So the new lower limit is 0.) When k = n + 1, then j = k − 1 = (n + 1)− 1 = n. (So the new upper limit is n.)

Since j = k − 1, then k = j + 1. Also note that n is a constant as far as the terms of the sum are concerned. It follows that

k n + k =

j + 1 n + ( j + 1)

and so the general term of the new summation is

j + 1 n + ( j + 1) .

Therefore,

n+1∑

k=1

k n + k =

n∑

j=0

j + 1 n + ( j + 1) . 5.1.3

b. Changing all the j’s to k’s in the right-hand side of equation (5.1.3) gives

n∑

j=0

j + 1 n + ( j + 1) =

n∑

k=0

k + 1 n + (k + 1) 5.1.4

Combining equations (5.1.3) and (5.1.4) results in

n+1∑

k=1

k n + k =

n∑

k=0

k + 1 n + (k + 1) . ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 237

Factorial and “n Choose r” Notation The product of all consecutive integers up to a given integer occurs so often in mathemat- ics that it is given a special notation—factorial notation.

• Definition For each positive integer n, the quantity n factorial denoted n!, is defined to be the product of all the integers from 1 to n:

n! = n ·(n − 1) · · · 3 ·2 ·1. Zero factorial, denoted 0!, is defined to be 1:

0! = 1.

The definition of zero factorial as 1 may seem odd, but, as you will see when you read Chapter 9, it is convenient for many mathematical formulas.

Example 5.1.15 The First Ten Factorials

0! = 1 1! = 1 2! = 2 ·1 = 2 3! = 3 ·2 ·1 = 6 4! = 4 ·3 ·2 ·1 = 24 5! = 5 ·4 ·3 ·2 ·1 = 120 6! = 6 ·5 ·4 ·3 ·2 ·1 = 720 7! = 7 ·6 ·5 ·4 ·3 ·2 ·1 = 5,040 8! = 8 ·7 ·6 ·5 ·4 ·3 ·2 ·1 9! = 9 ·8 ·7 ·6 ·5 ·4 ·3 ·2 ·1

= 40,320 = 362,880 ■

As you can see from the example above, the values of n! grow very rapidly. For instance, 40! ∼= 8.16× 1047, which is a number that is too large to be computed exactly using the standard integer arithmetic of the machine-specific implementations of many computer languages. (The symbol ∼= means “is approximately equal to.”)

A recursive definition for factorial is the following: Given any nonnegative integer n,

n! = {

1 if n = 0 n ·(n − 1)! if n ≥ 1.

The next example illustrates the usefulness of the recursive definition for making computations.

! Caution! Note that n · (n − 1)! is to be interpreted as n · [(n − 1)!].

Example 5.1.16 Computing with Factorials

Simplify the following expressions:

a. 8! 7! b.

5! 2! ·3! c.

1 2! ·4! +

1 3! ·3! d.

(n + 1)! n! e.

n! (n − 3)!

Solution

a. 8! 7! =

8 ·7! 7! = 8

b. 5!

2! ·3! = 5 ·4 ·3! 2! ·3! =

5 ·4 2 ·1 = 10

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

238 Chapter 5 Sequences, Mathematical Induction, and Recursion

c. 1 2! ·4! +

1 3! ·3! =

1 2! ·4! ·

3 3

+ 1 3! ·3! ·

4 4

by multiplying each numerator and denominator by just what is necessary to obtain a common denominator

= 3 3 ·2! ·4! +

4 3! ·4 ·3! by rearranging factors

= 3 3! ·4! +

4 3! ·4! because 3 ·2! = 3! and 4 ·3! = 4!

= 7 3! ·4!

by the rule for adding fractions with a common denominator

= 7 144

d. (n + 1)!

n! = (n + 1) ·n!

n! = n + 1

e. n!

(n − 3)! = n ·(n − 1) ·(n − 2) ·(n − 3)!

(n − 3)! = n ·(n − 1) ·(n − 2)

= n3 − 3n2 + 2n ■

An important use for the factorial notation is in calculating values of quantities, called n choose r, that occur in many branches of mathematics, especially those connected with the study of counting techniques and probability.

• Definition Let n and r be integers with 0 ≤ r ≤ n. The symbol

( n r

)

is read “n choose r” and represents the number of subsets of size r that can be chosen from a set with n elements.

Observe that the definition implies that (n

r

) will always be an integer because it

is a number of subsets. In Section 9.5 we will explore many uses of n choose r for solving problems involving counting, and we will prove the following computational formula:

• Formula for Computing (n

r

)

For all integers n and r with 0 ≤ r ≤ n, (

n r

) = n!

r !(n − r)! .

In the meantime, we will provide a few experiences with using it. Because n choose r is always an integer, you can be sure that all the factors in the denominator of the formula will be canceled out by factors in the numerator. Many electronic calculators have keys for computing values of

(n r

) . These are denoted in various ways such as nCr, C(n, r), nCr ,

and Cn,r . The letter C is used because the quantities (n

r

) are also called combinations.

Sometimes they are referred to as binomial coefficients because of the connection with the binomial theorem discussed in Section 9.7.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 239

Example 5.1.17 Computing (

n r

) by Hand

Use the formula for computing (

n r

) to evaluate the following expressions:

a. (

8 5

) b. (

4 0

) c. (

n + 1 n

)

Solution

a. (

8 5

) = 8!

5!(8− 5)!

= 8 ·7 ·6 ·5 ·4 ·3 ·2 ·1 (5 ·4 ·3 ·2 ·1) ·( ·3 ·2 ·1)

= 56.

always cancel common factors before multiplying

b. (

4 4

) = 4!

4!(4− 4)! = 4!

4!0! = 4 ·3 ·2 ·1

(4 ·3 ·2 ·1)(1) = 1

The fact that 0! = 1 makes this formula computable. It gives the correct value because a set of size 4 has exactly one subset of size 4, namely itself.

c. (

n + 1 n

) = (n + 1)!

n!((n + 1)− n)! = (n + 1)!

n!1! = (n + 1) ·n!

n! = n + 1 ■

Sequences in Computer Programming An important data type in computer programming consists of finite sequences. In com- puter programming contexts, these are usually referred to as one-dimensional arrays. For example, consider a program that analyzes the wages paid to a sample of 50 workers. Such a program might compute the average wage and the difference between each indi- vidual wage and the average. This would require that each wage be stored in memory for retrieval later in the calculation. To avoid the use of entirely separate variable names for all of the 50 wages, each is written as a term of a one-dimensional array:

W[1], W[2], W[3], . . . , W[50]. Note that the subscript labels are written inside square brackets. The reason is that until relatively recently, it was impossible to type actual dropped subscripts on most computer keyboards.

The main difficulty programmers have when using one-dimensional arrays is keeping the labels straight.

Example 5.1.18 Dummy Variable in a Loop

The index variable for a for-next loop is a dummy variable. For example, the following three algorithm segments all produce the same output:

1. for i := 1 to n 2. for j := 0 to n − 1 3. for k := 2 to n + 1 print a[i] print a[ j + 1] print a[k − 1]

next i next j next k ■

The recursive definitions for summation, product, and factorial lead naturally to com- putational algorithms. For instance, here are two sets of pseudocode to find the sum of a[1], a[2], . . . , a[n]. The one on the left exactly mimics the recursive definition by

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

240 Chapter 5 Sequences, Mathematical Induction, and Recursion

initializing the sum to equal a[1]; the one on the right initializes the sum to equal 0. In both cases the output is

∑n k=1 a[k].

s := a[1] s := 0 for k := 2 to n for k := 1 to n

s := s + a[k] s := s + a[k] next k next k

Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2

Section 2.5 contains some examples of converting integers from decimal to binary notation. The method shown there, however, is only convenient to use with small num- bers. A systematic algorithm to convert any nonnegative integer to binary notation uses repeated division by 2.

Suppose a is a nonnegative integer. Divide a by 2 using the quotient-remainder theorem to obtain a quotient q[0] and a remainder r [0]. If the quotient is nonzero, divide by 2 again to obtain a quotient q[1] and a remainder r [1]. Continue this process until a quotient of 0 is obtained. At each stage, the remainder must be less than the divisor, which is 2. Thus each remainder is either 0 or 1. The process is illustrated below for a = 38. (Read the divisions from the bottom up.)

0 remainder = 1 = r [5] 2 1 remainder = 0 = r [4]

2 2 remainder = 0 = r [3] 2 4 remainder = 1 = r [2]

2 9 remainder = 1 = r [1] 2 19 remainder = 0 = r [0]

2 38

The results of all these divisions can be written as a sequence of equations:

38 = 19 ·2 + 0, 19 = 9 ·2 + 1,

9 = 4 ·2 + 1, 4 = 2 ·2 + 0, 2 = 1 ·2 + 0, 1 = 0 ·2 + 1.

By repeated substitution, then,

38 = 19 ·2 + 0 = (9 ·2 + 1) ·2 + 0 = 9 ·22 + 1 ·2 + 0 = (4 ·2 + 1) ·22 + 1 ·2 + 0 = 4 ·23 + 1 ·22 + 1 ·2 + 0 = (2 ·2 + 0) ·23 + 1 ·22 + 1 ·2 + 0 = 2 ·24 + 0 ·23 + 1 ·22 + 1 ·2 + 0 = (1 ·2 + 0) ·24 + 0 ·23 + 1 ·22 + 1 ·2 + 0 = 1 ·25 + 0 ·24 + 0 ·23 + 1 ·22 + 1 ·2 + 0.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 241

Note that each coefficient of a power of 2 on the right-hand side of the previous page is one of the remainders obtained in the repeated division of 38 by 2. This is true for the left-most 1 as well, because 1 = 0 ·2 + 1. Thus

3810 = 1001102 = (r [5]r [4]r [3]r [2]r [1]r [0])2.

In general, if a nonnegative integer a is repeatedly divided by 2 until a quotient of zero is obtained and the remainders are found to be r [0], r [1], . . . , r [k], then by the quotient- remainder theorem each r [i] equals 0 or 1, and by repeated substitution from the theorem,

a = 2k ·r [k] + 2k−1·r [k − 1] + · · · + 22·r [2] + 21·r [1] + 20·r [0]. 5.1.5

Thus the binary representation for a can be read from equation (5.1.5):

a10 = (r [k]r [k − 1] · · · r [2]r [1]r [0])2.

Example 5.1.19 Converting from Decimal to Binary Notation Using Repeated Division by 2

Use repeated division by 2 to write the number 2910 in binary notation.

Solution

0 remainder = r [4] = 1 2 1 remainder = r [3] = 1

2 3 remainder = r [2] = 1 2 7 remainder = r [1] = 0

2 14 remainder = r [0] = 1 2 29

Hence 2910 = (r [4]r [3]r [2]r [1]r [0])2 = 111012. ■

The procedure we have described for converting from base 10 to base 2 is formalized in the following algorithm:

Algorithm 5.1.1 Decimal to Binary Conversion Using Repeated Division by 2

[In Algorithm 5.1.1 the input is a nonnegative integer n. The aim of the algorithm is to produce a sequence of binary digits r [0], r [1], r [2], . . . , r [k] so that the binary representation of a is

(r [k]r [k − 1] · · · r [2]r [1]r [0])2.

That is,

n = 2k ·r [k] + 2k−1·r [k − 1] + · · · + 22·r [2] + 21·r [1] + 20·r [0].]

continued on page 242

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

242 Chapter 5 Sequences, Mathematical Induction, and Recursion

Input: n [a nonnegative integer] Algorithm Body:

q := n, i := 0 [Repeatedly perform the integer division of q by 2 until q becomes 0. Store successive remainders in a one-dimensional array r [0], r [1], r [2], . . . , r [k]. Even if the initial- value of q equals 0, the loop should execute one time (so that r [0] is computed ). Thus the guard condition for the while loop is i = 0 or q ̸= 0.] while (i = 0 or q ̸= 0)

r [i] := q mod 2 q := q div 2 [r [i] and q can be obtained by calling the division algorithm.] i := i + 1

end while

[After execution of this step, the values of r [0], r [1], . . . , r [i − 1] are all 0’s and 1’s, and a = (r [i − 1]r [i − 2] · · · r [2]r [1]r [0])2.]

Output: r [0], r [1], r [2], . . . , r [i − 1] [a sequence of integers]

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. The notation n∑

k=m ak is read “_____.”

2. The expanded form of n∑

k=m ak is _____.

3. The value of a1 + a2 + a3 + · · · + an when n = 2 is “_____.”

4. The notation n∏

k=m ak is read “_____.”

5. If n is a positive integer, then n! = _____.

6. n∑

k=m ak + c

n∑

k=m bk = _____.

7.

( n∏

k=m ak

)( n∏

k=m bk

)

= _____.

Exercise Set 5.1* Write the first four terms of the sequences defined by the formulas in 1–6.

1. ak = k

10 + k , for all integers k ≥ 1.

2. b j = 5− j 5 + j , for all integers j ≥ 1.

3. ci = (−1)i

3i , for all integers i ≥ 0.

4. dm = 1 + (

1 2

)m for all integers m ≥ 0.

5. en = ⌊n

2

⌋ ·2, for all integers n ≥ 0.

6. fn = ⌊n

4

⌋ ·4, for all integers n ≥ 1.

7. Let ak = 2k + 1 and bk = (k − 1)3 + k + 2 for all integers k ≥ 0. Show that the first three terms of these sequences are identical but that their fourth terms differ.

Compute the first fifteen terms of each of the sequences in 8 and 9, and describe the general behavior of these sequences in words. (A definition of logarithm is given in Section 7.1.)

8. gn = ⌊log2 n⌋ for all integers n ≥ 1. 9. hn = n⌊log2 n⌋ for all integers n ≥ 1.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Sequences 243

Find explicit formulas for sequences of the form a1, a2, a3, . . . with the initial terms given in 10–16.

10. −1, 1,−1, 1,−1, 1 11. 0, 1,−2, 3,−4, 5

12. 1 4

, 2 9

, 3 16

, 4 25

, 5 36

, 6 49

13. 1− 1 2 ,

1 2 − 1

3 ,

1 3 − 1

4 ,

1 4 − 1

5 ,

1 5 − 1

6 ,

1 6 − 1

7

14. 1 3 ,

4 9 ,

9 27

, 16 81

, 25

243 ,

36 729

15. 0,−1 2 ,

2 3 ,−3

4 ,

4 5 ,−5

6 ,

6 7

16. 3, 6, 12, 24, 48, 96

17.✶ Consider the sequence defined by an = 2n + (−1)n − 1

4 for all integers n ≥ 0. Find an alternative explicit formula for an that uses the floor notation.

18. Let a0 = 2, a1 = 3, a2 = −2, a3 = 1, a4 = 0, a5 = −1, and a6 = −2. Compute each of the summations and products below.

a. 6∑

i=0 ai b.

0∑

i=0 ai c.

3∑

j=1 a2 j d.

6∏

k=0 ak e.

2∏

k=2 ak

Compute the summations and products in 19–28.

19. 5∑

k=1 (k + 1) 20.

4∏

k=2 k2 21.

3∑

m=0

1 2m

22. 4∏

j=0 (−1) j 23.

1∑

i=1 i(i + 1) 24.

0∑

j=0 ( j + 1) ·2 j

25. 2∏

k=2

( 1− 1

k

) 26.

1∑

k=−1 (k2 + 3)

27. 10∑

n=1

( 1 n − 1

n + 1

) 28.

5∏

i=2

i(i + 2) (i − 1) ·(i + 1)

Write the summations in 29–32 in expanded form.

29. n∑

i=1 (−2)i 30.

n∑

j=1 j ( j + 1) 31.

n+1∑

k=0

1 k! 32.

k+1∑

i=1 i(i !)

Evaluate the summations and products in 33–36 for the indi- cated values of the variable.

33. 1 12

+ 1 22

+ 1 32

+ . . . + 1 n2

; n = 1

34. 1(1!) + 2(2!) + 3(3!) + . . . + m(m!); m = 2

35. (

1 1 + 1

)( 2

2 + 1

)( 3

3 + 1

) . . .

( k

k + 1

) ; k = 3

36. (

1 ·2 3 ·4

)( 4 ·5 6 ·7

)( 6 ·7 8 ·9

) . . .

( m ·(m + 1)

(m + 2) ·(m + 3)

) ; m = 1

Rewrite 37–39 by separating off the final term.

37. k+1∑

i=1 i(i !) 38.

m+1∑

k=1 k2 39.

n+1∑

m=1 m(m + 1)

Write each of 40–42 as a single summation.

40. k∑

i=1 i3 + (k + 1)3 41.

m∑

k=1

k k + 1 +

m + 1 m + 2

42. n∑

m=0 (m + 1)2m + (n + 2)2n+1

Write each of 43–52 using summation or product notation.

43. 12 − 22 + 32 − 42 + 52 − 62 + 72

44. (13 − 1)− (23 − 1) + (33 − 1)− (43 − 1) + (53 − 1) 45. (22 − 1) ·(32 − 1) ·(42 − 1)

46. 2

3 ·4 − 3

4 ·5 + 4

5 ·6 − 5

6 ·7 + 6

7 ·8 47. 1− r + r 2 − r 3 + r 4 − r 5

48. (1− t) ·(1− t2) ·(1− t3) ·(1− t4) 49. 13 + 23 + 33 + · · · + n3

50. 1 2! +

2 3! +

3 4! + · · · +

n (n + 1)!

51. n + (n − 1) + (n − 2) + · · · + 1

52. n + n − 1 2! +

n − 2 3! +

n − 3 4! + · · · +

1 n!

Transform each of 53 and 54 by making the change of variable i = k + 1.

53. 5∑

k=0 k(k − 1) 54.

n∏

k=1

k k2 + 4

Transform each of 55–58 by making the change of variable j = i − 1.

55. n+1∑

i=1

(i − 1)2 i ·n 56.

n∑

i=3

i i + n − 1

57. n−1∑

i=1

i (n − i)2 58.

2n∏

i=n

n − i + 1 n + i

Write each of 59–61 as a single summation or product.

59. 3 · n∑

k=1 (2k − 3) +

n∑

k=1 (4− 5k)

60. 2 · n∑

k=1 (3k2 + 4) + 5 ·

n∑

k=1 (2k2 − 1)

61.

( n∏

k=1

k k + 1

)

· (

n∏

k=1

k + 1 k + 2

)

Compute each of 62–76. Assume the values of the variables are restricted so that the expressions are defined.

62. 4! 3! 63.

6! 8! 64.

4! 0!

65. n!

(n − 1)! 66. (n − 1)! (n + 1)! 67.

n! (n − 2)!

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

244 Chapter 5 Sequences, Mathematical Induction, and Recursion

68. ((n + 1)!)2

(n!)2 69. n!

(n − k)! 70. n!

(n − k + 1)!

71. (

5 3

) 72. (

7 4

) 73. (

3 0

)

74. (

5 5

) 75. (

n n − 1

) 76. (

n + 1 n − 1

)

77. a. Prove that n! + 2 is divisible by 2, for all integers n ≥ 2. b. Prove that n! + k is divisible by k, for all integers n ≥ 2

and k = 2, 3, . . . , n. c.H Given any integer m ≥ 2, is it possible to find a sequence

of m − 1 consecutive positive integers none of which is prime? Explain your answer.

78. Prove that for all nonnegative integers n and r with

r + 1 ≤ n, (

n r + 1

) = n − r

r + 1

( n r

) .

79. Prove that if p is a prime number and r is an integer with

0 < r < p, then (

p r

) is divisible by p.

80. Suppose a[1], a[2], a[3], . . . , a[m] is a one-dimensional array and consider the following algorithm segment:

sum := 0 for k := 1 to m

sum := sum + a[k] next k

Fill in the blanks below so that each algorithm segment per- forms the same job as the one given previously. a. sum := 0

for i := 0 to sum :=

next i

b. sum := 0 for j := 2 to

sum := next j

Use repeated division by 2 to convert (by hand) the integers in 81–83 from base 10 to base 2.

81. 90 82. 98 83. 205

Make a trace table to trace the action of Algorithm 5.1.1 on the input in 84–86.

84. 23 85. 28 86. 44

87. Write an informal description of an algorithm (using repeated division by 16) to convert a nonnegative inte- ger from decimal notation to hexadecimal notation (base 16).

Use the algorithm you developed for exercise 87 to convert the integers in 88–90 to hexadecimal notation.

88. 287 89. 693 90. 2,301

91. Write a formal version of the algorithm you developed for exercise 87.

Answers for Test Yourself 1. the summation from k equals m to n of a-sub-k 2. am + am+1 + am+2 + · · · + an 3. a1 + a2 4. the product from k equals m to n of a-sub-k 5. n · (n − 1) · · · 3 ·2 ·1 (Or: n ·(n − 1)!) 6.

n∑ k=m

(ak + cbk) 7. n∏

k=m akbk

5.2 Mathematical Induction I [Mathematical induction is] the standard proof technique in computer science. — Anthony Ralston, 1984

Mathematical induction is one of the more recently developed techniques of proof in the history of mathematics. It is used to check conjectures about the outcomes of processes that occur repeatedly and according to definite patterns. We introduce the technique with an example.

Some people claim that the United States penny is such a small coin that it should be abolished. They point out that frequently a person who drops a penny on the ground does not even bother to pick it up. Other people argue that abolishing the penny would not give enough flexibility for pricing merchandise. What prices could still be paid with exact change if the penny were abolished and another coin worth 3c/ were introduced? The answer is that the only prices that could not be paid with exact change would be 1c/, 2c/, 4c/, and 7c/. In other words,

Any whole number of cents of at least 8c/ can be obtained using 3c/ and 5c/ coins.

More formally:

For all integers n ≥ 8, n cents can be obtained using 3c/ and 5c/ coins.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 245

Even more formally:

For all integers n ≥ 8, P(n) is true, where P(n) is the sentence “n cents can be obtained using 3c/ and 5c/ coins.”

You could check that P(n) is true for a few particular values of n, as is done in the table below.

Number of Cents How to Obtain It

8c/ 3c/ + 5c/ 9c/ 3c/ + 3c/ + 3c/

10c/ 5c/ + 5c/ 11c/ 3c/ + 3c/ + 5c/ 12c/ 3c/ + 3c/ + 3c/ + 3c/ 13c/ 3c/ + 5c/ + 5c/ 14c/ 3c/ + 3c/ + 3c/ + 5c/ 15c/ 5c/ + 5c/ + 5c/ 16c/ 3c/ + 3c/ + 5c/ + 5c/ 17c/ 3c/ + 3c/ + 3c/ + 3c/ + 5c/

The cases shown in the table provide inductive evidence to support the claim that P(n) is true for general n. Indeed, P(n) is true for all n ≥ 8 if, and only if, it is possible to continue filling in the table for arbitrarily large values of n.

The kth line of the table gives information about how to obtain kc/ using 3c/ and 5c/ coins. To continue the table to the next row, directions must be given for how to obtain (k + 1)c/ using 3c/ and 5c/ coins. The secret is to observe first that if kc/ can be obtained using at least one 5c/ coin, then (k + 1)c/ can be obtained by replacing the 5c/ coin by two 3c/ coins, as shown in Figure 5.2.1.

k¢ (k + 1)¢

3¢ 3¢5¢

Replace a 5¢ coin by two 3¢ coins.

Remove Add

Figure 5.2.1

If, on the other hand, kc/ is obtained without using a 5c/ coin, then 3c/ coins are used exclusively. And since the total is at least 8c/, three or more 3c/ coins must be included. Three of the 3c/ coins can be replaced by two 5c/ coins to obtain a total of (k + 1)c/, as shown in Figure 5.2.2.

The structure of the argument above can be summarized as follows: To show that P(n) is true for all integers n ≥ 8, (1) show that P(8) is true, and (2) show that the truth of P(k + 1) follows necessarily from the truth of P(k) for each k ≥ 8.

Any argument of this form is an argument by mathematical induction. In general, mathematical induction is a method for proving that a property defined for integers n is true for all values of n that are greater than or equal to some initial integer.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

246 Chapter 5 Sequences, Mathematical Induction, and Recursion

k¢ (k + 1)¢

Remove Add

k¢ (k + 1)¢

5¢ 3¢ 3¢

Replace three 3¢ coins by two 5¢ coins.

Remove Add

Figure 5.2.2

Principle of Mathematical Induction

Let P(n) be a property that is defined for integers n, and let a be a fixed integer. Suppose the following two statements are true:

1. P(a) is true.

2. For all integers k ≥ a, if P(k) is true then P(k + 1) is true. Then the statement

for all integers n ≥ a, P(n) is true.

The first known use of mathematical induction occurs in the work of the Italian sci- entist Francesco Maurolico in 1575. In the seventeenth century both Pierre de Fermat and Blaise Pascal used the technique, Fermat calling it the “method of infinite descent.” In 1883 Augustus De Morgan (best known for De Morgan’s laws) described the process carefully and gave it the name mathematical induction.

To visualize the idea of mathematical induction, imagine an infinite collection of dominoes positioned one behind the other in such a way that if any given domino falls backward, it makes the one behind it fall backward also. (See Figure 5.2.3) Then imagine that the first domino falls backward. What happens? . . . They all fall down!

1 2

3 4

k k + 1

Figure 5.2.3 If the kth domino falls backward, it pushes the (k + 1)st domino backward also.

To see the connection between this image and the principle of mathematical induction, let P(n) be the sentence “The nth domino falls backward.” It is given that for each k ≥ 1, if P(k) is true (the kth domino falls backward), then P(k + 1) is also true (the (k + 1)st domino falls backward). It is also given that P(1) is true (the first domino falls backward). Thus by the principle of mathematical induction, P(n) (the nth domino falls backward) is true for every integer n ≥ 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 247

The validity of proof by mathematical induction is generally taken as an axiom. That is why it is referred to as the principle of mathematical induction rather than as a theorem. It is equivalent to the following property of the integers, which is easy to accept on intuitive grounds:

Suppose S is any set of integers satisfying (1) a ∈ S, and (2) for all integers k ≥ a, if k ∈ S then k + 1 ∈ S. Then S must contain every integer greater than or equal to a.

To understand the equivalence of this formulation and the one given earlier, just let S be the set of all integers for which P(n) is true.

Proving a statement by mathematical induction is a two-step process. The first step is called the basis step, and the second step is called the inductive step.

Method of Proof by Mathematical Induction

Consider a statement of the form, “For all integers n ≥ a, a property P(n) is true.” To prove such a statement, perform the following two steps: Step 1 (basis step): Show that P(a) is true.

Step 2 (inductive step): Show that for all integers k ≥ a, if P(k) is true then P(k + 1) is true. To perform this step,

suppose that P(k) is true, where k is any particular but arbitrarily chosen integer with k ≥ a.

[This supposition is called the inductive hypothesis.] Then

show that P(k + 1) is true.

Here is a formal version of the proof about coins previously developed informally.

Proposition 5.2.1

For all integers n ≥ 8, nc/ can be obtained using 3c/ and 5c/ coins.

Proof (by mathematical induction):

Let the property P(n) be the sentence

nc/ can be obtained using 3c/ and 5c/ coins. ← P(n)

Show that P(8) is true: P(8) is true because 8c/ can be obtained using one 3c/ coin and one 5c/ coin.

Show that for all integers k ≥ 8, if P(k) is true then P(k+1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 8. That is:] Suppose that k is any integer with k ≥ 8 such that

kc/ can be obtained using 3c/ and 5c/ coins. ← P(k) inductive hypothesis

[We must show that P(k + 1) is true. That is:] We must show that (k + 1)c/ can be obtained using 3c/ and 5c/ coins. ← P(k + 1)

Case 1 (There is a 5c/ coin among those used to make up the kc/.): In this case replace the 5c/ coin by two 3c/ coins; the result will be (k + 1)c/.

continued on page 248

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

248 Chapter 5 Sequences, Mathematical Induction, and Recursion

Case 2 (There is not a 5c/ coin among those used to make up the kc/.): In this case, because k ≥ 8, at least three 3c/ coins must have been used. So remove three 3c/ coins and replace them by two 5c/ coins; the result will be (k + 1)c/. Thus in either case (k + 1)c/ can be obtained using 3c/ and 5c/ coins [as was to be shown].

[Since we have proved the basis step and the inductive step, we conclude that the propo- sition is true.]

The following example shows how to use mathematical induction to prove a formula for the sum of the first n integers.

Example 5.2.1 Sum of the First n Integers

Use mathematical induction to prove that

1 + 2 + · · · + n = n(n + 1) 2

for all integers n ≥ 1.

Solution To construct a proof by induction, you must first identify the property P(n). In this case, P(n) is the equation

1 + 2 + · · · + n = n(n + 1) 2

. ← the property (P(n))

[To see that P(n) is a sentence, note that its subject is “the sum of the integers from 1 to n” and its verb is “equals.”]

In the basis step of the proof, you must show that the property is true for n = 1, or, in other words that P(1) is true. Now P(1) is obtained by substituting 1 in place of n in P(n). The left-hand side of P(1) is the sum of all the successive integers starting at 1 and ending at 1. This is just 1. Thus P(1) is

1 = 1(1 + 1) 2

. ← basis (P(1))

Note To write P(1), just copy P(n) and replace each n by 1.

Of course, this equation is true because the right-hand side is

1(1 + 1) 2

= 1 ·2 2

= 1,

which equals the left-hand side.

Note To write P(k), just copy P(n) and replace each n by k.

In the inductive step, you assume that P(k) is true, for a particular but arbitrarily cho- sen integer k with k ≥ 1. [This assumption is the inductive hypothesis.] You must then show that P(k + 1) is true. What are P(k) and P(k + 1)? P(k) is obtained by substituting k for every n in P(n). Thus P(k) is

1 + 2 + · · · + k = k(k + 1) 2

. ← inductive hypothesis (P(k))

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 249

Similarly, P(k + 1) is obtained by substituting the quantity (k + 1) for every n that appears in P(n). Thus P(k + 1) is

1 + 2 + · · · + (k + 1) = (k + 1)((k + 1) + 1) 2

,

or, equivalently,

1 + 2 + · · · + (k + 1) = (k + 1)(k + 2) 2

. ← to show (P(k + 1))

Note To write P(k + 1), just copy P(n) and replace each n by (k + 1).

Now the inductive hypothesis is the supposition that P(k) is true. How can this sup- position be used to show that P(k + 1) is true? P(k + 1) is an equation, and the truth of an equation can be shown in a variety of ways. One of the most straightforward is to use the inductive hypothesis along with algebra and other known facts to transform separately the left-hand and right-hand sides until you see that they are the same. In this case, the left-hand side of P(k + 1) is

1 + 2 + · · · + (k + 1), which equals

(1 + 2 + · · · + k) + (k + 1) The next-to-last term is k because the terms are successive integers and the last term is k + 1.

But by substitution from the inductive hypothesis,

(1 + 2+· · · + k) + (k + 1)

= k(k + 1) 2

+ (k + 1) since the inductive hypothesis says

that 1 + 2 + · · · + k = k(k + 1) 2

= k(k + 1) 2

+ 2(k + 1) 2

by multiplying the numerator and

denominator of the second term by 2

to obtain a common denominator

= k 2 + k

2 + 2k + 2

2 by multiplying out the two numerators

k2 + 3k + 1 2

by adding fractions with the same

denominator and combining like terms.

So the left-hand side of P(k + 1) is k 2 + 3k + 1

2 . Now the right-hand side of P(k + 1) is

(k + 1)(k + 2) 2

= k 2 + 3k + 1

2 by multiplying out the numerator.

Thus the two sides of P(k + 1) are equal to each other, and so the equation P(k + 1) is true.

This discussion is summarized as follows:

Theorem 5.2.2 Sum of the First n Integers

For all integers n ≥ 1, 1 + 2 + · · · + n = n(n + 1)

2 .

Proof (by mathematical induction):

Let the property P(n) be the equation

1 + 2 + 3 + · · · + n = n(n + 1) 2

. ← P(n)

continued on page 250

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

250 Chapter 5 Sequences, Mathematical Induction, and Recursion

Show that P(1) is true:

To establish P(1), we must show that

1 = 1(1 + 1) 2

← P(1)

But the left-hand side of this equation is 1 and the right-hand side is

1(1 + 1) 2

= 2 2

= 1

also. Hence P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 1. That is:] Suppose that k is any integer with k ≥ 1 such that

1 + 2 + 3 + · · · + k = k(k + 1) 2

← P(k) inductive hypothesis

[We must show that P(k + 1) is true. That is:] We must show that

1 + 2 + 3 + · · · + (k + 1) = (k + 1)[(k + 1) + 1] 2

,

or, equivalently, that

1 + 2 + 3 + · · · + (k + 1) = (k + 1)(k + 2) 2

. ← P(k + 1)

[We will show that the left-hand side and the right-hand side of P(k + 1) are equal to the same quantity and thus are equal to each other.]

The left-hand side of P(k + 1) is 1 + 2 + 3 + · · · + (k + 1)

= 1 + 2 + 3 + · · · + k + (k + 1) by making the next-to-lastterm explicit = k(k + 1)

2 + (k + 1) by substitution from theinductive hypothesis

= k(k + 1) 2

+ 2(k + 1) 2

= k 2 + k

2 + 2k + 2

2

= k 2 + 3k + 1

2 by algebra.

And the right-hand side of P(k + 1) is (k + 1)(k + 2)

2 = k

2 + 3k + 1 2

.

Thus the two sides of P(k + 1) are equal to the same quantity and so they are equal to each other. Therefore the equation P(k + 1) is true [as was to be shown]. [Since we have proved both the basis step and the inductive step, we conclude that the theorem is true.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 251

The story is told that one of the greatest mathematicians of all time, Carl Friedrich Gauss (1777–1855), was given the problem of adding the numbers from 1 to 100 by his teacher when he was a young child. The teacher had asked his students to compute the sum, supposedly to gain himself some time to grade papers. But after just a few moments, Gauss produced the correct answer. Needless to say, the teacher was dumbfounded. How could young Gauss have calculated the quantity so rapidly? In his later years, Gauss explained that he had imagined the numbers paired according to the following schema.

1 2 3 . . . . . . 50 51 . . . . . . 98 99 100

→ →

sum is 101

→ →

sum is 101

→ →

sum is 101

→ →

sum is 101

The sum of the numbers in each pair is 101, and there are 50 pairs in all; hence the total sum is 50 ·101 = 5,050.

• Definition Closed Form If a sum with a variable number of terms is shown to be equal to a formula that does not contain either an ellipsis or a summation symbol, we say that it is written in closed form.

For example, writing 1 + 2 + 3 + · · · + n = n(n + 1) 2

expresses the sum 1 + 2 + 3 + · · · + n in closed form.

Example 5.2.2 Applying the Formula for the Sum of the First n Integers

a. Evaluate 2 + 4 + 6 + · · · + 500. b. Evaluate 5 + 6 + 7 + 8 + · · · + 50. c. For an integer h ≥ 2, write 1 + 2 + 3 + · · · + (h − 1) in closed form.

Solution

a. 2 + 4 + 6 + · · · + 500 = 2 ·(1 + 2 + 3 + · · · + 250)

= 2 · (

250 ·251 2

) by applying the formula for the sum of the first n integers with n = 250

= 62,750. b. 5 + 6 + 7 + 8 + · · · + 50 = (1 + 2 + 3 + · · · + 50)− (1 + 2 + 3 + 4)

= 50 ·51 2

− 10 by applying the formula for the sum of the first n integers with n = 50

= 1,265

c. 1 + 2 + 3 + · · · + (h − 1) = (h − 1) · [(h − 1) + 1] 2

by applying the formula for the sum of the first n integers with n = h − 1

= (h − 1) ·h 2

since (h − 1) + 1 = h. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

252 Chapter 5 Sequences, Mathematical Induction, and Recursion

The next example asks for a proof of another famous and important formula in mathematics—the formula for the sum of a geometric sequence. In a geometric sequence, each term is obtained from the preceding one by multiplying by a constant factor. If the first term is 1 and the constant factor is r , then the sequence is 1, r, r2, r3, . . . , rn, . . . . The sum of the first n terms of this sequence is given by the formula

n∑

i = 0 r i = r

n + 1 − 1 r − 1

for all integers n ≥ 0 and real numbers r not equal to 1. The expanded form of the formula is

r0 + r1 + r2 + · · · + rn = r n+1 − 1 r − 1 ,

and because r0 = 1 and r1 = r , the formula for n ≥ 1 can be rewritten as

1 + r + r2 + · · · + rn = r n+1 − 1 r − 1 .

Example 5.2.3 Sum of a Geometric Sequence

Prove that n∑

i=0 r i = r

n+1 − 1 r − 1 , for all integers n ≥ 0 and all real numbers r except 1.

Solution In this example the property P(n) is again an equation, although in this case it contains a real variable r :.

n∑

i=0 r i = r

n+1 − 1 r − 1 . ← the property (P(n))

Because r can be any real number other than 1, the proof begins by supposing that r is a particular but arbitrarily chosen real number not equal to 1. Then the proof continues by mathematical induction on n, starting with n = 0. In the basis step, you must show that P(0) is true; that is, you show the property is true for n = 0. So you substitute 0 for each n in P(n):

0∑

i=0 r i = r

0+1 − 1 r − 1 .

← basis (P(0))

In the inductive step, you suppose k is any integer with k ≥ 0 for which P(k) is true; that is, you suppose the property is true for n = k. So you substitute k for each n in P(n):

k∑

i=0 r i = r

k+1 − 1 r − 1 .

← inductive hypothesis (P(k))

Then you show that P(k + 1) is true; that is, you show the property is true for n = k + 1. So you substitute k + 1 for each n in P(n):

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 253

k+1∑

i=0 r i = r

(k+1)+1 − 1 r − 1 ,

or, equivalently,

k+1∑

i=0 r i = r

k+2 − 1 r − 1 ·

← to show (P(k + 1))

In the inductive step for this proof we use another common technique for showing that an equation is true: We start with the left-hand side and transform it step-by-step into the right-hand side using the inductive hypothesis together with algebra and other known facts.

Theorem 5.2.3 Sum of a Geometric Sequence

For any real number r except 1, and any integer n ≥ 0, n∑

i=0 r i = r

n+1 − 1 r − 1 .

Proof (by mathematical induction):

Suppose r is a particular but arbitrarily chosen real number that is not equal to 1, and let the property P(n) be the equation

n∑

i = 0 r i = r

i+1 − 1 r − 1

← P(n)

We must show that P(n) is true for all integers n ≥ 0. We do this by mathematical induction on n.

Show that P(0) is true:

To establish P(0), we must show that

0∑

i = 0 r i = r

0 + 1 − 1 r − 1

← P(0)

The left-hand side of this equation is r0 = 1 and the right-hand side is r0 + 1 − 1

r − 1 = r − 1 r − 1 = 1

also because r1 = r and r ̸= 1. Hence P(0) is true. Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 0. That is:] Let k be any integer with k ≥ 0, and suppose that

k∑

i = 0 r i = r

k + 1 − 1 r − 1

← P(k) inductive hypothesis

continued on page 254

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

254 Chapter 5 Sequences, Mathematical Induction, and Recursion

[We must show that P(k + 1) is true. That is:] We must show that k+1∑

i= 0 r i = r

(k + 1)+ 1 − 1 r − 1 ,

or, equivalently, that

k + 1∑

i = 0 r i = r

k + 2 − 1 r − 1 .

← P(k + 1)

[We will show that the left-hand side of P(k + 1) equals the right-hand side.] The left-hand side of P(k + 1) is

k+1∑

i= 0 r i =

k∑

i= 0 r i + rk+1 by writing the (k + 1)st term

separately from the first k terms

= r k+1 − 1 r − 1 + r

k+1 by substitution from the inductive hypothesis

= r k+1 − 1 r − 1 +

rk+1(r − 1) r − 1

by multiplying the numerator and denominator of the second term by (r − 1) to obtain a common denominator

= (r k+1 − 1) + rk+1(r − 1)

r − 1 by adding fractions

= r k+1 − 1 + rk+2 − rk+1

r − 1 by multiplying out and using the fact that rk+1 ·r = rk+1 ·r1 = rk+2

= r k+2 − 1 r − 1 by canceling the r

k+1’s.

which is the right-hand side of P(k + 1) [as was to be shown.] [Since we have proved the basis step and the inductive step, we conclude that the theorem is true.]

Proving an Equality The proofs of the basis and inductive steps in Examples 5.2.1 and 5.2.3 illustrate two different ways to show that an equation is true: (1) transforming the left-hand side and the right-hand side independently until they are seen to be equal, and (2) transforming one side of the equation until it is seen to be the same as the other side of the equation.

Sometimes people use a method that they believe proves equality but that is actually invalid. For example, to prove the basis step for Theorem 5.2.3, they perform the following steps:

! Caution! Don’t do this!

0∑

i = 0 r i = r

0 + 1 − 1 r − 1

r0 = r 1 − 1

r − 1 1 = r − 1

r − 1 1 = 1

The problem with this method is that starting from a statement and deducing a true con- clusion does not prove that the statement is true. A true conclusion can also be deduced

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 255

from a false statement. For instance, the steps below show how to deduce the true con- clusion that 1 = 1 from the false statement that 1 = 0:

1 = 0 ← false 0 = 1

1 + 0 = 0 + 1 1 = 1 ← true

When using mathematical induction to prove formulas, be sure to use a method that avoids invalid reasoning, both for the basis step and for the inductive step.

Deducing Additional Formulas The formula for the sum of a geometric sequence can be thought of as a family of different formulas in r , one for each real number r except 1.

Example 5.2.4 Applying the Formula for the Sum of a Geometric Sequence

In each of (a) and (b) below, assume that m is an integer that is greater than or equal to 3. Write each of the sums in closed form.

a. 1 + 3 + 32 + · · · + 3m−2

b. 32 + 33 + 34 + · · · + 3m

Solution

a. 1 + 3 + 32 + · · · + 3m−2 = 3 (m−2)+1 − 1

3− 1 by applying the formula for the sum of a geometric sequence with r = 3 and n = m − 2

= 3 m−1 − 1

2 .

b. 32 + 33 + 34 + · · · + 3m = 32 ·(1 + 3 + 32 + · · · + 3m−2) by factoring out 32

= 9 · (

3m−1 − 1 2

) by part (a). ■

As with the formula for the sum of the first n integers, there is a way to think of the formula for the sum of the terms of a geometric sequence that makes it seem simple and intuitive. Let

Sn = 1 + r + r2 + · · · + rn. Then

r Sn = r + r2 + r3 + · · · + rn+1, and so

r Sn − Sn = (r + r2 + r3 + · · · + rn+1)− (1 + r + r2 + · · · + rn) = rn+1 − 1. 5.2.1

But

r Sn − Sn = (r − 1)Sn. 5.2.2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

256 Chapter 5 Sequences, Mathematical Induction, and Recursion

Equating the right-hand sides of equations (5.2.1) and (5.2.2) and dividing by r − 1 gives

Sn = rn+1 − 1

r − 1 .

This derivation of the formula is attractive and is quite convincing. However, it is not as logically airtight as the proof by mathematical induction. To go from one step to another in the previous calculations, the argument is made that each term among those indicated by the ellipsis (. . .) has such-and-such an appearance and when these are can- celed such-and-such occurs. But it is impossible actually to see each such term and each such calculation, and so the accuracy of these claims cannot be fully checked. With math- ematical induction it is possible to focus exactly on what happens in the middle of the ellipsis and verify without doubt that the calculations are correct.

Test Yourself 1. Mathematical induction is a method for proving that a prop-

erty defined for integers n is true for all values of n that are _____.

2. Let P(n) be a property defined for integers n and consider constructing a proof by mathematical induction for the state- ment “P(n) is true for all n ≥ a.”

(a) In the basis step one must show that _____.

(b) In the inductive step one supposes that _____ for some particular but arbitrarily chosen value of an integer k ≥ a. This supposition is called the _____. One then has to show that _____.

Exercise Set 5.2 1. Use mathematical induction (and the proof of Proposi-

tion 5.2.1 as a model) to show that any amount of money of at least 14c/ can be made up using 3c/ and 8c/ coins.

2. Use mathematical induction to show that any postage of at least 12c/ can be obtained using 3c/ and 7c/ stamps.

3. For each positive integer n, let P(n) be the formula

12 + 22 + · · · + n2 = n(n + 1)(2n + 1) 6

.

a. Write P(1). Is P(1) true? b. Write P(k). c. Write P(k + 1). d. In a proof by mathematical induction that the formula

holds for all integers n ≥ 1, what must be shown in the inductive step?

4. For each integer n with n ≥ 2, let P(n) be the formula n−1∑

i=1 i(i + 1) = n(n − 1)(n + 1)

3 .

a. Write P(2). Is P(2) true? b. Write P(k). c. Write P(k + 1). d. In a proof by mathematical induction that the formula

holds for all integers n ≥ 2, what must be shown in the inductive step?

5. Fill in the missing pieces in the following proof that

1 + 3 + 5 + · · · + (2n − 1) = n2

for all integers n ≥ 1.

Proof: Let the property P(n) be the equation

1 + 3 + 5 + · · · + (2n − 1) = n2. ← P(n) Show that P(1) is true: To establish P(1), we must show that when 1 is substituted in place of n, the left-hand side equals the right-hand side. But when n = 1, the left-hand side is the sum of all the odd integers from 1 to 2 ·1− 1, which is the sum of the odd integers from 1 to 1, which is just 1. The right-hand side is (a) , which also equals 1. So P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 1.

[Suppose P(k) is true. That is:]

Suppose 1 + 3 + 5 + · · · + (2k − 1) = (b) . ← P(k) [This is the inductive hypothesis.]

[We must show that P(k + 1) is true. That is:]

We must show that

(c) = (d) . ← P(k + 1) But the left-hand side of P(k + 1) is 1 + 3 + 5 + · · · + (2(k + 1)− 1)

= 1 + 3 + 5 + · · · + (2k + 1) by algebra = [1 + 3 + 5 + · · · + (2k − 1)] + (2k + 1)

the next-to-last term is 2k − 1 because (e)

= k2 + (2k + 1) by (f) = (k + 1)2 by algebra

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Mathematical Induction I 257

which is the right-hand side of P(k + 1) [as was to be shown.] [Since we have proved the basis step and the inductive step, we conclude that the given statement is true.] The previous proof was annotated to help make its logical flow more obvious. In standard mathematical writing, such annotation is omitted.

Prove each statement in 6–9 using mathematical induction. Do not derive them from Theorem 5.2.2 or Theorem 5.2.3.

6. For all integers n ≥ 1, 2 + 4 + 6 + · · · + 2n = n2 + n. 7. For all integers n ≥ 1,

1 + 6 + 11 + 16 + · · · + (5n − 4) = n(5n − 3) 2

.

8. For all integers n ≥ 0, 1 + 2 + 22 + · · · + 2n = 2n+1 − 1. 9. For all integers n ≥ 3,

43 + 44 + 45 + · · · + 4n = 4(4 n − 16)

3 .

Prove each of the statements in 10–17 by mathematical induction.

10. 12 + 22 + · · · + n2 = n(n + 1)(2n + 1) 6

, for all integers

n ≥ 1.

11. 13 + 23 + · · · + n3 = [

n(n + 1) 2

]2 , for all integers n ≥ 1.

12. 1

1 ·2 + 1

2 ·3 + · · · + 1

n(n + 1) = n

n + 1 , for all integers n ≥ 1.

13. n−1∑

i=1 i(i + 1) = n(n − 1)(n + 1)

3 , for all integers n ≥ 2.

14. n+1∑

i=1 i ·2i = n ·2n+2 + 2, for all integers n ≥ 0.

15.H n∑

i=1 i(i !) = (n + 1)!− 1, for all integers n ≥ 1.

16. (

1− 1 22

)( 1− 1

32

) · · · (

1− 1 n2

) = n + 1

2n , for all inte-

gers n ≥ 2.

17. n∏

i=0

( 1

2i + 1 · 1

2i + 2

) = 1

(2n + 2)! , for all integers n ≥ 0.

18.✶H If x is a real number not divisible by π , then for all integers n ≥ 1, sin x + sin 3x + sin 5x + · · · + sin (2n − 1)x

= 1− cos 2nx 2 sin x

.

19. (For students who have studied calculus) Use mathemati- cal induction, the product rule from calculus, and the facts

that d(x) dx

= 1 and that xk + 1 = x · xk to prove that for all

integers n ≥ 1, d(x n)

dx = nxn− 1.

Use the formula for the sum of the first n integers and/or the for- mula for the sum of a geometric sequence to evaluate the sums in 20–29 or to write them in closed form.

20. 4 + 8 + 12 + 16 + · · · + 200

21. 5 + 10 + 15 + 20 + · · · + 300

22. 3 + 4 + 5 + 6 + · · · + 1000

23. 7 + 8 + 9 + 10 + · · · + 600

24. 1 + 2 + 3 + · · · + (k − 1), where k is an integer and k ≥ 2.

25. a. 1 + 2 + 22 + · · · + 225 b. 2 + 22 + 23 + · · · + 226

26. 3 + 32 + 33 + · · · + 3n , where n is an integer with n ≥ 1

27. 53 + 54 + 55 + · · · + 5k , where k is any integer with k ≥ 3.

28. 1 + 1 2

+ 1 22

+ · · · + 1 2n

, where n is a positive integer

29. 1− 2 + 22 − 23 + · · · + (−1)n2n , where n is a positive integer

30.H Find a formula in n, a, m, and d for the sum (a + md) + (a + (m + 1)d) + (a + (m + 2)d) + · · · + (a + (m + n)d), where m and n are integers, n ≥ 0, and a and d are real numbers. Justify your answer.

31. Find a formula in a, r, m, and n for the sum

ar m + arm+1 + arm+2 + · · · + arm+n

where m and n are integers, n ≥ 0, and a and r are real numbers. Justify your answer.

32. You have two parents, four grandparents, eight great- grandparents, and so forth. a. If all your ancestors were distinct, what would be

the total number of your ancestors for the past 40 generations (counting your parents’ generation as num- ber one)? (Hint: Use the formula for the sum of a geo- metric sequence.)

b. Assuming that each generation represents 25 years, how long is 40 generations?

c. The total number of people who have ever lived is approximately 10 billion, which equals 1010 people. Compare this fact with the answer to part (a). What do you deduce?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

258 Chapter 5 Sequences, Mathematical Induction, and Recursion

Find the mistakes in the proof fragments in 33–35.

33.H Theorem: For any integer n ≥ 1,

12 + 22 + · · · + n2 = n(n + 1)(2n + 1) 6

.

“Proof (by mathematical induction): Certainly the theorem is true for n = 1 because 12 = 1 and 1(1 + 1)(2 ·1 + 1)

6 = 1. So the basis step is true.

For the inductive step, suppose that for some integer k ≥ 1, k2 = k(k + 1)(2k + 1)

6 . We must show that

(k + 1)2 = (k + 1)((k + 1) + 1)(2(k + 1) + 1) 6

.”

34.H Theorem: For any integer n ≥ 0, 1 + 2 + 22 + · · · + 2n = 2n + 1 − 1.

“Proof (by mathematical induction): Let the property P(n) be 1 + 2 + 22 + · · · + 2n = 2n + 1 − 1. Show that P(0) is true: The left-hand side of P(0) is 1 + 2 + 22 + · · · + 20 = 1 and the right-hand side is 20 + 1 − 1 = 2− 1 = 1 also. So P(0) is true.”

35.H Theorem: For any integer n ≥ 1, n∑

i=1 i(i !) = (n + 1)!− 1.

“Proof (by mathematical induction): Let the property

P(n) be n∑

i=1 i(i !) = (n + 1)!− 1.

Show that P(1) is true: When n = 1 1∑

i=1 i(i !) = (1 + 1)!− 1

So 1(1!) = 2!− 1 and 1 = 1 Thus P(1) is true.”

36.✶ Use Theorem 5.2.2 to prove that if m and n are any positive integers and m is odd, then

∑m−1 k=0 (n + k) is divisible by m.

Does the conclusion hold if m is even? Justify your answer.

37.✶H Use Theorem 5.2.2 and the result of exercise 10 to prove that if p is any prime number with p ≥ 5, then the sum of squares of any p consecutive integers is divisible by p.

Answers for Test Yourself 1. greater than or equal to some initial value 2. (a) P(a) is true (b) P(k) is true; inductive hypothesis; P(k + 1) is true

5.3 Mathematical Induction II A good proof is one which makes us wiser. — I. Manin, A Course in Mathematical Logic, 1977

In natural science courses, deduction and induction are presented as alternative modes of thought—deduction being to infer a conclusion from general principles using the laws of logical reasoning, and induction being to enunciate a general principle after observing it to hold in a large number of specific instances. In this sense, then, mathematical induction is not inductive but deductive. Once proved by mathematical induction, a theorem is known just as certainly as if it were proved by any other mathe- matical method. Inductive reasoning, in the natural sciences sense, is used in mathemat- ics, but only to make conjectures, not to prove them. For example, observe that

1− 1 2

= 1 2

( 1− 1

2

)( 1− 1

3

) = 1

3 (

1− 1 2

)( 1− 1

3

)( 1− 1

4

) = 1

4

This pattern seems so unlikely to occur by pure chance that it is reasonable to conjecture (though it is by no means certain) that the pattern holds true in general. In a case like this, a proof by mathematical induction (which you are asked to write in exercise 1 at the end of this section) gets to the essence of why the pattern holds in general. It reveals the mathematical mechanism that necessitates the truth of each successive case from the previous one. For instance, in this example observe that if

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Mathematical Induction II 259

( 1− 1

2

)( 1− 1

3

) · · · (

1− 1 k

) = 1

k ,

then by substitution (

1− 1 2

)( 1− 1

3

) · · · (

1− 1 k

)( 1− 1

k + 1

)

= 1 k

( 1− 1

k + 1

) = 1

k

( k + 1− 1

k + 1

) = 1

k

( k

k + 1

) = 1

k + 1 .

Thus mathematical induction makes knowledge of the general pattern a matter of mathematical certainty rather than vague conjecture.

In the remainder of this section we show how to use mathematical induction to prove additional kinds of statements such as divisibility properties of the integers and inequalities. The basic outlines of the proofs are the same in all cases, but the details of the basis and inductive steps differ from one to another.

Example 5.3.1 Proving a Divisibility Property

Use mathematical induction to prove that for all integers n ≥ 0, 22n − 1 is divisible by 3. Solution As in the previous proofs by mathematical induction, you need to identify the

property P(n). In this example, P(n) is the sentence

22n − 1 is divisible by 3. ← the property (P(n))

By substitution, the statement for the basis step, P(0), is

22 ·0 − 1 is divisible by 3. ← basis (P(0))

The supposition for the inductive step, P(k), is

22k − 1 is divisible by 3, ← inductive hypothesis (P(k))

and the conclusion to be shown, P(k + 1), is

22(k+1) − 1 is divisible by 3. ← to show (P(k + 1))

Recall that an integer m is divisible by 3 if, and only if, m = 3r for some integer r . Now the statement P(0) is true because 22 ·0 − 1 = 20 − 1 = 1− 1 = 0, which is divis- ible by 3 because 0 = 3 ·0.

To prove the inductive step, you suppose that k is any integer greater than or equal to 0 such that P(k) is true. This means that 22k − 1 is divisible by 3. You must then prove the truth of P(k + 1). Or, in other words, you must show that 22(k+1) − 1 is divisible by 3. But

22(k+1) − 1 = 22k+2 − 1 = 22k·22 − 1 by the laws of exponents = 22k·4− 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

260 Chapter 5 Sequences, Mathematical Induction, and Recursion

The aim is to show that this quantity, 22k·4− 1, is divisible by 3. Why should that be so? By the inductive hypothesis, 22k − 1 is divisible by 3, and 22k·4− 1 resembles 22k − 1. Observe what happens, if you subtract 22k − 1 from 22k·4− 1:

22k·4− 1︸ ︷︷ ︸ − (2 2k − 1)︸ ︷︷ ︸ = 2

2k·3.︸ ︷︷ ︸ K⏐ K⏐ K⏐

divisible by 3? divisible by 3 divisible by 3

Adding 22k − 1 to both sides gives

22k·4− 1︸ ︷︷ ︸ = 2 2k ·3︸ ︷︷ ︸ + 2

2k − 1.︸ ︷︷ ︸K⏐ K⏐ K⏐ divisible by 3? divisible by 3 divisible by 3

Both terms of the sum on the right-hand side of this equation are divisible by 3; hence the sum is divisible by 3. (See exercise 15 of Section 4.3.) Therefore, the left-hand side of the equation is also divisible by 3, which is what was to be shown.

This discussion is summarized as follows:

Proposition 5.3.1

For all integers n ≥ 0, 22n − 1 is divisible by 3.

Proof (by mathematical induction):

Let the property P(n) be the sentence “22n − 1 is divisible by 3.”

22n − 1 is divisible by 3. ← P(n)

Show that P(0) is true: To establish P(0), we must show that

22 ·0 − 1 is divisible by 3. ← P(0)

But

22 ·0 − 1 = 20 − 1 = 1− 1 = 0

and 0 is divisible by 3 because 0 = 3 ·0. Hence P(0) is true. Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 0. That is:] Let k be any integer with k ≥ 0, and suppose that

22k − 1 is divisible by 3. ← P(k) inductive hypothesis

By definition of divisibility, this means that

22k − 1 = 3r for some integer r .

[We must show that P(k + 1) is true. That is:] We must show that

22(k + 1) − 1 is divisible by 3. ← P(k + 1)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Mathematical Induction II 261

But

22(k+1) − 1 = 22k + 2 − 1 = 22k ·22 − 1 by the laws of exponents = 22k ·4− 1 = 22k(3 + 1)− 1 = 22k ·3 + (22k − 1) by the laws of algebra = 22k ·3 + 3r by inductive hypothesis = 3(22k + r) by factoring out the 3.

But 22k + r is an integer because it is a sum of products of integers, and so, by definition of divisibility, 22(k+1) − 1 is divisible by 3 [as was to be shown]. [Since we have proved the basis step and the inductive step, we conclude that the propo- sition is true.]

The next example illustrates the use of mathematical induction to prove an inequality.

Example 5.3.2 Proving an Inequality

Use mathematical induction to prove that for all integers n ≥ 3, 2n + 1 < 2n.

Solution In this example the property P(n) is the inequality

2n + 1 < 2n. ← the property (P(n))

By substitution, the statement for the basis step, P(3), is

2 ·3 + 1 < 23. ← basis (P(3))

The supposition for the inductive step, P(k), is

2k + 1 < 2k, ← inductive hypothesis (P(k))

and the conclusion to be shown is

2(k + 1) + 1 < 2k+1. ← to show (P(k + 1))

To prove the basis step, observe that the statement P(3) is true because 2 ·3 + 1 = 7, 23 = 8, and 7 < 8.

To prove the inductive step, suppose the inductive hypothesis, that P(k) is true for an integer k ≥ 3. This means that 2k + 1 < 2k is assumed to be true for a particular but arbi- trarily chosen integer k ≥ 3. Then derive the truth of P(k + 1). Or, in other words, show that the inequality 2(k + 1) + 1 < 2k+1 is true. But by multiplying out and regrouping,

2(k + 1) + 1 = 2k + 3 = (2k + 1) + 2, 5.3.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

262 Chapter 5 Sequences, Mathematical Induction, and Recursion

and by substitution from the inductive hypothesis,

(2k + 1) + 2 < 2k + 2. 5.3.2 Hence

2(k + 1) + 1 < 2k + 2 The left-most part of equation (5.3.1) is less than the right-most part of inequality (5.3.2).

Note Properties of order are listed in Appendix A.

If it can be shown that 2k + 2 is less than 2k+1, then the desired inequality will have been proved. But since the quantity 2k can be added to or subtracted from an inequality without changing its direction,

2k + 2 < 2k+1 ⇔ 2 < 2k+1 − 2k = 2k(2− 1) = 2k . And since multiplying or dividing an inequality by 2 does not change its direction,

2 < 2k ⇔ 1 = 2 2

< 2k

2 = 2k−1 by the laws of exponents.

This last inequality is clearly true for all k ≥ 2. Hence it is true that 2(k + 1) + 1 < 2k+1. This discussion is made more flowing (but less intuitive) in the following formal

proof:

Proposition 5.3.2

For all integers n ≥ 3, 2n + 1 < 2n .

Proof (by mathematical induction):

Let the property P(n) be the inequality

2n + 1 < 2n. ← P(n) Show that P(3) is true: To establish P(3), we must show that

2 ·3 + 1 < 23. ← P(3) But

2 ·3 + 1 = 7 and 23 = 8 and 7 < 8. Hence P(3) is true.

Show that for all integers k ≥ 3, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 3. That is:] Suppose that k is any integer with k ≥ 3 such that

2k + 1 < 2k . ← P(k) inductive hypothesis

[We must show that P(k + 1) is true. That is:] We must show that 2(k + 1) + 1 < 2(k+1),

or, equivalently,

2k + 3 < 2(k+1). ← P(k + 1)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Mathematical Induction II 263

But

2k + 3 = (2k + 1) + 2 by algebra < 2k + 2k because 2k + 1 < 2k by the inductive hypothesis

and because 2 < 2k for all integers k ≥ 2 ∴ 2k + 3 < 2 ·2k = 2k+1 by the laws of exponents.

[This is what we needed to show.] [Since we have proved the basis step and the inductive step, we conclude that the propo- sition is true.]

The next example demonstrates how to use mathematical induction to show that the terms of a sequence satisfy a certain explicit formula.

Example 5.3.3 Proving a Property of a Sequence

Define a sequence a1, a2, a3, . . . as follows.∗

a1 = 2 ak = 5ak−1 for all integers k ≥ 2.

a. Write the first four terms of the sequence.

b. It is claimed that for each integer n ≥ 0, the nth term of the sequence has the same value as that given by the formula 2 ·5n− 1. In other words, the claim is that the terms of the sequence satisfy the equation an = 2 ·5n− 1. Prove that this is true.

Solution

a. a1 = 2. a2 = 5a2−1 = 5a1 = 5 ·2 = 10 a3 = 5a3−1 = 5a2 = 5 ·10 = 50 a4 = 5a4−1 = 5a3 = 5 ·50 = 250.

b. To use mathematical induction to show that every term of the sequence satisfies the equation, begin by showing that the first term of the sequence satisfies the equation. Then suppose that an arbitrarily chosen term ak satisfies the equation and prove that the next term ak + 1 also satisfies the equation.

Proof:

Let a1, a2, a3, . . . be the sequence defined by specifying that a1 = 2 and ak = 5ak−1 for all integers k ≥ 2, and let the property P(n) be the equation

an = 2 ·5n−1. ← P(n) We will use mathematical induction to prove that for all integers n ≥ 1, P(n) is true. Show that P(1) is true: To establish P(1), we must show that

a1 = 2 ·51−1. ← P(1)

∗This is another example of a recursive definition. The general subject of recursion is discussed in Section 5.6.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

264 Chapter 5 Sequences, Mathematical Induction, and Recursion

But the left-hand side of P(1) is

a1 = 2 by definition of a1, a2, a3, . . ., and the right-hand side of P(1) is

2 ·51−1 = 2 ·50 = 2 ·1 = 2. Thus the two sides of P(1) are equal to the same quantity, and hence P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 1. That is:] Let k be any integer with k ≥ 0, and suppose that

ak = 2 ·5k−1. ← P(k) inductive hypothesis

By definition of divisibility, this means that

ak = 2 ·5k−1. [We must show that P(k + 1) is true. That is:] We must show that

ak+1 = 2 ·5(k+1)−1, or, equivalently,

ak+1 = 2 ·5k . ← P(k + 1) But the left-hand side of P(k + 1) is

ak+1 = 5a(k+1)−1 by definition of a1, a2, a3, . . . = 5ak since (k + 1)− 1 = k = 5 ·(2 ·5k−1) by inductive hypothesis = 2 ·(5 ·5k−1) by regrouping = 2 ·5k by the laws of exponents

which is the right-hand side of the equation [as was to be shown.]

[Since we have proved the basis step and the inductive step, we conclude that the formula holds for all terms of the sequence.] ■

A Problem with Trominoes The word polyomino, a generalization of domino, was introduced by Solomon Golomb in 1954 when he was a 22-year-old student at Harvard. Subsequently, he and others proved many interesting properties about them, and they became the basis for the popular com- puter game Tetris. A particular type of polyomino, called a tromino, is made up of three attached squares, which can be of two types:

straight and L-shaped

Call a checkerboard that is formed using m squares on a side an m × m (“m by m”) checkerboard. Observe that if one square is removed from a 4× 4 checkerboard, the remaining squares can be completely covered by L-shaped trominoes. For instance, a covering for one such board is illustrated in the figure to the left.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Mathematical Induction II 265

In his first article about polyominoes, Golomb included a proof of the following theorem. It is a beautiful example of an argument by mathematical induction.

Theorem Covering a Board with Trominoes

For any integer n ≥ 1, if one square is removed from a 2n × 2n checkerboard, the remaining squares can be completely covered by L-shaped trominoes.

The main insight leading to a proof of this theorem is the observation that because 2k + 1 = 2 ·2k , when a 2k + 1 × 2k + 1 board is split in half both vertically and hori- zontally, each half side will have length 2k and so each resulting quadrant will be a 2k × 2k checkerboard. Proof (by mathematical induction):

Let the property P(n) be the sentence

If any square is removed from a 2n × 2n checkerboard, then the remaining squares can be completely covered. by L-shaped trominoes

← P(n)

Show that P(1) is true: A 21 × 21 checkerboard just consists of four squares. If one square is removed, the remaining squares form an L, which can be covered by a single L-shaped tromino, as illustrated in the figure to the left. Hence P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 3. That is:] Let k be any integer such that k ≥ 1, and suppose that

If any square is removed from a 2k × 2kcheckerboard, then the remaining squares can be completely covered by L-shaped trominoes.

← P(k)

P(k) is the inductive hypothesis. [We must show that P (k + 1) is true. That is:] We must show that

If any square is removed from a 2k+1 × 2k+1 checkerboard, then the remaining squares can be completely covered by L-shaped trominoes.

← P(k + 1)

2k 2k

2k + 2k = 2k + 1 Consider a 2 k + 1 × 2k + 1 checkerboard with one square removed. Divide it into four

equal quadrants: Each will consist of a 2k × 2k checkerboard. In one of the quad- rants, one square will have been removed, and so, by inductive hypothesis, all the remaining squares in this quadrant can be completely covered by L-shaped tromi- noes. The other three quadrants meet at the center of the checkerboard, and the center of the checkerboard serves as a corner of a square from each of those quad- rants. An L-shaped tromino can, therefore, be placed on those three central squares. This situation is illustrated in the figure to the left. By inductive hypothesis, the remaining squares in each of the three quadrants can be completely covered by L- shaped trominoes. Thus every square in the 2k + 1 × 2k + 1 checkerboard except the one that was removed can be completely covered by L-shaped trominoes [as was to be shown].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

266 Chapter 5 Sequences, Mathematical Induction, and Recursion

Test Yourself 1. Mathematical induction differs from the kind of induction

used in the natural sciences because it is actually a form of ____ reasoning.

2. Mathematical induction can be used to _____ conjectures that have been made using inductive reasoning.

Exercise Set 5.3 1. Based on the discussion of the product

( 1− 12 ) (

1− 13 )

( 1− 14 ) · · · ( 1− 1n )

at the beginning of this section, con- jecture a formula for general n. Prove your conjecture by mathematical induction.

2. Experiment with computing values of the product( 1 + 11 ) (

1 + 12 ) (

1 + 13 ) · · · ( 1 + 1n )

for small values of n to conjecture a formula for this product for general n. Prove your conjecture by mathematical induction.

3. Observe that

1 1 ·3 =

1 3

1 1 ·3 +

1 3 ·5 =

2 5

1 1 ·3 +

1 3 ·5 +

1 5 ·7 =

3 7

1 1 ·3 +

1 3 ·5 +

1 5 ·7 +

1 7 ·9 =

4 9

Guess a general formula and prove it by mathematical induction.

4.H Observe that

1 = 1, 1− 4 = −(1 + 2),

1− 4 + 9 = 1 + 2 + 3, 1− 4 + 9− 16 = −(1 + 2 + 3 + 4),

1− 4 + 9− 16 + 25 = 1 + 2 + 3 + 4 + 5. Guess a general formula and prove it by mathematical induction.

5. Evaluate the sum n∑

k=1

k (k + 1)! for n = 1, 2, 3, 4, and 5.

Make a conjecture about a formula for this sum for general n, and prove your conjecture by mathematical induction.

6. For each positive integer n, let P(n) be the property

5n − 1 is divisible by 4. a. Write P(0). Is P(0) true? b. Write P(k). c. Write P(k + 1). d. In a proof by mathematical induction that this divisibil-

ity property holds for all integers n ≥ 0, what must be shown in the inductive step?

7. For each positive integer n, let P(n) be the property

2n < (n + 1)!.

a. Write P(2). Is P(2) true? b. Write P(k). c. Write P(k + 1). d. In a proof by mathematical induction that this inequality

holds for all integers n ≥ 2, what must be shown in the inductive step?

Prove each statement in 8–23 by mathematical induction.

8. 5n − 1 is divisible by 4, for each integer n ≥ 0. 9. 7n − 1 is divisible by 6, for each integer n ≥ 0.

10. n3 − 7n + 3 is divisible by 3, for each integer n ≥ 0.

11. 32n − 1 is divisible by 8, for each integer n ≥ 0.

12. For any integer n ≥ 0, 7n − 2n is divisible by 5.

13.H For any integer n ≥ 0, xn − yn is divisible by x − y, where x and y are any integers with x ̸= y.

14.H n3 − n is divisible by 6, for each integer n ≥ 0. 15. n(n2 + 5) is divisible by 6, for each integer n ≥ 0.

16. 2n < (n + 1)!, for all integers n ≥ 2. 17. 1 + 3n ≤ 4n , for every integer n ≥ 0. 18. 5n + 9 < 6n , for all integers n ≥ 2.

19. n2 < 2n , for all integers n ≥ 5. 20. 2n < (n + 2)!, for all integers n ≥ 0.

21. √

n < 1√ 1

+ 1√ 2

+ · · · + 1√ n

, for all integers n ≥ 2.

22. 1 + nx ≤ (1 + x)n , for all real numbers x > −1 and integers n ≥ 2.

23. a. n3 > 2n + 1, for all integers n ≥ 2. b. n! > n2, for all integers n ≥ 4.

24. A sequence a1, a2, a3, . . . is defined by letting a1 = 3 and ak = 7ak−1 for all integers k ≥ 2. Show that an = 3 ·7n−1 for all integers n ≥ 1.

25. A sequence b0, b1, b2, . . . is defined by letting b0 = 5 and bk = 4 + bk−1 for all integers k ≥ 1. Show that bn > 4n for all integers n ≥ 0.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Mathematical Induction II 267

26. A sequence c0, c1, c2, . . . is defined by letting c0 = 3 and ck = (ck−1)2 for all integers k ≥ 1. Show that cn = 32n for all integers n ≥ 0.

27. A sequence d1, d2, d3, . . . is defined by letting d1 = 2 and dk =

dk−1 k

for all integers k ≥ 2. Show that for all integers

n ≥ 1, dn = 2 n! .

28. Prove that for all integers n ≥ 1,

1 3

= 1 + 3 5 + 7 =

1 + 3 + 5 7 + 9 + 11 = · · ·

= 1 + 3 + · · · + (2n − 1) (2n + 1) + · · · + (4n − 1) .

29. As each of a group of businesspeople arrives at a meeting, each shakes hands with all the other people present. Use mathematical induction to show that if n people come to the meeting then [n(n − 1)]/2 handshakes occur.

In order for a proof by mathematical induction to be valid, the basis statement must be true for n = a and the argument of the inductive step must be correct for every integer k ≥ a. In 30 and 31 find the mistakes in the “proofs” by mathematical induction.

30. “Theorem:” For any integer n ≥ 1, all the numbers in a set of n numbers are equal to each other. “Proof (by mathematical induction): It is obviously true that all the numbers in a set consisting of just one number are equal to each other, so the basis step is true. For the inductive step, let A = {a1, a2, . . . , ak, ak+1} be any set of k + 1 numbers. Form two subsets each of size k:

B = {a1, a2, a3, . . . , ak} and C = {a1, a3, a4, . . . , ak+1}.

(B consists of all the numbers in A except ak+1, and C consists of all the numbers in A except a2.) By induc- tive hypothesis, all the numbers in B equal a1 and all the numbers in C equal a1 (since both sets have only k numbers). But every number in A is in B or C , so all the numbers in A equal a1; hence all are equal to each other.”

31.H “Theorem:” For all integers n ≥ 1, 3n − 2 is even. “Proof (by mathematical induction): Suppose the theorem is true for an integer k, where k ≥ 1. That is, suppose that 3k − 2 is even. We must show that 3k+1 − 2 is even. But

3k+1 − 2 = 3k ·3− 2 = 3k(1 + 2)− 2 = (3k − 2) + 3k ·2.

Now 3k − 2 is even by inductive hypothesis and 3k ·2 is even by inspection. Hence the sum of the two quantities is even (by Theorem 4.1.1). It follows that 3k+1 − 2 is even, which is what we needed to show.”

32.H Some 5× 5 checkerboards with one square removed can be completely covered by L-shaped trominoes, whereas other 5× 5 checkerboards cannot. Find examples of both kinds of checkerboards. Justify your answers.

33. Consider a 4× 6 checkerboard. Draw a covering of the board by L-shaped trominoes.

34.H a. Use mathematical induction to prove that any checker- board with dimensions 3× 2n can be completely covered with L-shaped trominoes for any integer n ≥ 1.

b. Let n be any integer greater than or equal to 1. Use the result of part (a) to prove by mathematical induction that for all integers m, any checkerboard with dimen- sions 2m × 3n can be completely covered with L-shaped trominoes.

35. Let m and n be any integers that are greater than or equal to 1. a. Prove that a necessary condition for an m × n checker-

board to be completely coverable by L-shaped trominoes is that mn be divisible by 3.

H b. Prove that having mn be divisible by 3 is not a sufficient condition for an m × n checkerboard to be completely coverable by L-shaped trominoes.

36. In a round-robin tournament each team plays every other team exactly once. If the teams are labeled T1, T2, . . . , Tn, then the outcome of such a tournament can be represented by a drawing, called a directed graph, in which the teams are represented as dots and an arrow is drawn from one dot to another if, and only if, the team represented by the first dot beats the team represented by the second dot. For example, the directed graph below shows one outcome of a round-robin tournament involving five teams, A, B, C, D, and E.

A B

C

D E

Use mathematical induction to show that in any round- robin tournament involving n teams, where n ≥ 2, it is possible to label the teams T1, T2, . . . , Tn so that Ti beats Ti+1 for all i = 1, 2, . . . , n − 1. (For instance, one such labeling in the example above is T1 = A, T2 = B, T3 = C, T4 = E, T5 = D.) (Hint: Given k + 1 teams, pick one— say T ′—and apply the inductive hypothesis to the remain- ing teams to obtain an ordering T1, T2, . . . , Tk . Consider three cases: T

′ beats T1, T

′ loses to the first m teams (where

1 ≤ m ≤ k − 1) and beats the (m + 1)st team, and T ′ loses to all the other teams.)

37.✶H On the outside rim of a circular disk the integers from 1 through 30 are painted in random order. Show that no matter what this order is, there must be three successive integers whose sum is at least 45.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

268 Chapter 5 Sequences, Mathematical Induction, and Recursion

38.H Suppose that n a’s and n b’s are distributed around the out- side of a circle. Use mathematical induction to prove that for all integers n ≥ 1, given any such arrangement, it is possible to find a starting point so that if one travels around the circle in a clockwise direction, the number of a’s one has passed is never less than the number of b’s one has passed. For example, in the diagram shown below, one could start at the a with an asterisk.

a a

a

b

b

b b

b

a*

a

a

b

39. For a polygon to be convex means that all of its inte- rior angles are less than 180 degrees. Use mathematical induction to prove that for all integers n ≥ 3, the angles of any n-sided convex polygon add up to 180(n − 2) degrees.

40. a. Prove that in an 8× 8 checkerboard with alternating black and white squares, if the squares in the top right and bottom left corners are removed the remaining board cannot be covered with dominoes. (Hint: Mathematical induction is not needed for this proof.)

b. Use mathematical induction to prove that for all integers n, if a 2n × 2n checkerboard with alternat- ing black and white squares has one white square and one black square removed anywhere on the board, the remaining squares can be covered with dominoes.

Answers for Test Yourself 1. deductive 2. prove

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers Mathematics takes us still further from what is human into the region of absolute necessity, to which not only the actual world, but every possible world, must conform. — Bertrand Russell, 1902

Strong mathematical induction is similar to ordinary mathematical induction in that it is a technique for establishing the truth of a sequence of statements about integers. Also, a proof by strong mathematical induction consists of a basis step and an inductive step. However, the basis step may contain proofs for several initial values, and in the inductive step the truth of the predicate P(n) is assumed not just for one value of n but for all values through k, and then the truth of P(k + 1) is proved.

Principle of Strong Mathematical Induction

Let P(n) be a property that is defined for integers n, and let a and b be fixed integers with a ≤ b. Suppose the following two statements are true: 1. P(a), P(a + 1), . . . , and P(b) are all true. (basis step) 2. For any integer k ≥ b, if P(i) is true for all integers i from a through k, then

P(k + 1) is true. (inductive step) Then the statement

for all integers n ≥ a, P(n) is true. (The supposition that P(i) is true for all integers i from a through k is called the inductive hypothesis. Another way to state the inductive hypothesis is to say that P(a), P(a + 1), . . . , P(k) are all true.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 269

Any statement that can be proved with ordinary mathematical induction can be proved with strong mathematical induction. The reason is that given any integer k ≥ b, if the truth of P(k) alone implies the truth of P(k + 1), then certainly the truth of P(a), P(a + 1), . . . , and P(k) implies the truth of P(k + 1). It is also the case that any statement that can be proved with strong mathematical induction can be proved with ordinary mathematical induction. A proof is sketched in exercise 27 at the end of this section.

Strictly speaking, the principle of strong mathematical induction can be written with- out a basis step if the inductive step is changed to “∀k ≥ a − 1, if P(i) is true for all integers i from a through k, then P(k + 1) is true.” The reason for this is that the state- ment “P(i) is true for all integers i from a through k” is vacuously true for k = a−1. Hence, if the implication in the inductive step is true, then the conclusion P(a) must also be true,∗ which proves the basis step. However, in many cases the proof of the implica- tion for k > b does not work for a ≤ k ≤ b. So it is a good idea to get into the habit of thinking separately about the cases where a ≤ k ≤ b by explicitly including a basis step.

The principle of strong mathematical induction is known under a variety of different names including the second principle of induction, the second principle of finite induc- tion, and the principle of complete induction.

Applying Strong Mathematical Induction The divisibility-by-a-prime theorem states that any integer greater than 1 is divisible by a prime number. We prove this theorem using strong mathematical induction.

Example 5.4.1 Divisibility by a Prime

Prove Theorem 4.3.4: Any integer greater than 1 is divisible by a prime number.

Solution The idea for the inductive step is this: If a given integer greater than 1 is not itself prime, then it is a product of two smaller positive integers, each of which is greater than 1. Since you are assuming that each of these smaller integers is divisible by a prime number, by transitivity of divisibility, those prime numbers also divide the integer you started with.

Proof (by strong mathematical induction):

Let the property P(n) be the sentence

n is divisible by a prime number. ← P(n)

Show that P(2) is true: To establish P(2), we must show that

2 is divisible by a prime number. ← P(2)

But this is true because 2 is divisible by 2 and 2 is a prime number.

Show that for all integers k ≥ 2, if P(i) is true for all integers i from 2 through k, then P(k + 1) is also true:

continued on page 270

∗If you have proved that a certain if-then statement is true and if you also know that the hypothesis is true, then the conclusion must be true.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

270 Chapter 5 Sequences, Mathematical Induction, and Recursion

Let k be any integer with k ≥ 2 and suppose that i is divisible by a prime number for all integers i from 2 through k. ← inductive hypothesis

We must show that

k + 1 is divisible by a prime number. ← P(k + 1) Case 1 (k + 1 is prime): In this case k + 1 is divisible by a prime number, namely itself.

Case 2 (k + 1 is not prime): In this case k + 1 = ab where a and b are inte- gers with 1 < a < k + 1 and 1 < b < k + 1. Thus, in particular, 2 ≤ a ≤ k, and so by inductive hypothesis, a is divisible by a prime number p. In addition because k + 1 = ab, we have that k + 1 is divisible by a. Hence, since k + 1 is divisible by a and a is divisible by p, by transitivity of divisibility, k + 1 is divisible by the prime number p.

Therefore, regardless of whether k + 1 is prime or not, it is divisible by a prime number [as was to be shown]. [Since we have proved both the basis and the inductive step of the strong mathematical induction, we conclude that the given statement is true.]

Both ordinary and strong mathematical induction can be used to show that the terms of certain sequences satisfy certain properties. The next example shows how this is done using strong induction.

Example 5.4.2 Proving a Property of a Sequence with Strong Induction

Define a sequence s0, s1, s2, . . . as follows:

s0 = 0, s1 = 4, sk = 6ak−1 − 5ak−2 for all integers k ≥ 2. a. Find the first four terms of this sequence.

b. It is claimed that for each integer n ≥ 0, the nth term of the sequence has the same value as that given by the formula 5n − 1. In other words, the claim is that all the terms of the sequence satisfy the equation sn = 5n − 1. Prove that this is true.

Solution

a. s0 = 0, s1 = 4, s2 = 6s1 − 5s0 = 6 ·4− 5 ·0 = 24, s3 = 6s2 − 5s1 = 6 ·24− 5 ·4 = 144− 20 = 124

b. To use strong mathematical induction to show that every term of the sequence satis- fies the equation, the basis step must show that the first two terms satisfy it. This is necessary because, according to the definition of the sequence, computing values of later terms requires knowing the values of the two previous terms. So if the basis step only shows that the first term satisfies the equation, it would not be possible to use the inductive step to deduce that the second term satisfies the equation. In the induc- tive step you suppose that for an arbitrarily chosen integer k ≥ 1, all the terms of the sequence from s0 through sk satisfy the given equation and you then deduce that sk+1 must also satisfy the equation.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 271

Proof: Let s0, s1, s2, . . . be the sequence defined by specifying that s0 = 0, s1 = 4, and sk = 6ak−1 − 5ak−2 for all integers k ≥ 2, and let the property P(n) be the formula

sn = 5n − 1 ← P(n) We will use strong mathematical induction to prove that for all integers n ≥ 0, P(n) is true.

Show that P(0) and P(1) are true: To establish P(0) and P(1), we must show that

s0 = 50 − 1 and s1 = 51 − 1. ← P(0) and P(1) But, by definition of s0, s1, s2, . . ., we have that s0 = 0 and s1 = 4. Since 50 − 1 = 1− 1 = 0 and 51 − 1 = 5− 1 = 4, the values of s0 and s1 agree with the values given by the formula.

Show that for all integers k ≥ 1, if P(i) is true for all integers i from 0 through k, then P(k + 1) is also true: Let k be any integer with k ≥ 1 and suppose that

si = 5i − 1 for all integers i with 0 ≤ i ≤ k. ← inductive hypothesis We must show that

sk+1 = 5k+1 − 1. ← P(k + 1) But since k ≥ 1, we have that k + 1 ≥ 2, and so

sk+1 = 6sk − 5sk−1 by definition of s0, s1, s2, . . . = 6(5k − 1)− 5(5k−1 − 1) by definition hypothesis = 6 ·5k − 6− 5k + 5 by multiplying out and applying

a law of exponents

= (6− 1)5k − 1 by factoring out 6 and arithmetic = 5 ·5k − 1 by arithmetic = 5k+1 − 1 by applying a law of exponents,

[as was to be shown].

[Since we have proved both the basis and the inductive step of the strong mathematical induction, we conclude that the given statement is true.]

Another use of strong induction concerns the computation of products. A product of four numbers may be computed in a variety of different ways as indicated by the placement of parentheses. For instance,

((x1x2)x3)x4 means multiply x1 and x2, multiply the result by x3, and then multiply that number by x4.

And

(x1x2)(x3x4) means multiply x1 and x2, multiply x3 and x4, and then take the product of the two.

Note that in both examples above, although the factors are multiplied in a different order, the number of multiplications—three—is the same. Strong mathematical induction is used to prove a generalization of this fact.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

272 Chapter 5 Sequences, Mathematical Induction, and Recursion

Note Like many definitions, for extreme cases this may look strange but it makes things work out nicely.

Convention

Let us agree to say that a single number x1 is a product with one factor and can be computed with zero multiplications.

Example 5.4.3 The Number of Multiplications Needed to Multiply n Numbers

Prove that for any integer n ≥ 1, if x1, x2, . . . , xn are n numbers, then no matter how the parentheses are inserted into their product, the number of multiplications used to compute the product is n − 1.

Solution The truth of the basis step follows immediately from the convention about a prod- uct with one factor. The inductive step is based on the fact that when several numbers are multiplied together, each step of the process involves multiplying two individual quanti- ties. For instance, the final step for computing ((x1x2)x3)(x4x5) is to multiply (x1x2)x3 and x4x5. In general, if k + 1 numbers are multiplied, the two quantities in the final step each consist of fewer than k + 1 factors. This is what makes it possible to use the induc- tive hypothesis.

Proof (by strong mathematical induction):

Let the property P(n) be the sentence

If x1, x2, . . . , xn are n numbers, then no matter how parentheses are inserted into their product, the number of multiplications used to ← P(n) compute the product is n − 1.

Show that P(1) is true: To establish P(1), we must show that

The number of multiplications needed to compute the product of x1 is 1− 1. ← P(1)

This is true because, by convention, x1 is a product that can be computed with 0 multiplications, and 0 = 1− 1. Show that for all integers k ≥ 1, if P(i) is true for all integers i from 1 through k, then P(k + 1) is also true: Let k by any integer with k ≥ 1 and suppose that

For all integers i from 1 through k, if x1, x2, . . . , xi are numbers, then no matter how parentheses are inserted into their product, the number of multiplications used to compute the product is i − 1.

← inductive hypothesis

We must show that

If x1, x2, . . . , xk + 1 are k + 1 numbers, then no matter how parentheses are inserted into their product, the number of multiplications used to compute the product is (k + 1)− 1 = k.

← P(k + 1)

Consider a product of k + 1 factors: x1, x2 . . . , xk + 1. When parentheses are inserted in order to compute the product, some multiplication is the final one and each of

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 273

the two factors making up the final multiplication is a product of fewer than k + 1 factors. Let L be the product of the left-hand factors and R be the product of the right-hand factors, and suppose that L is composed of l factors and R is composed of r factors. Then l + r = k + 1, the total number of factors in the product, and

1 ≤ l ≤ k and 1 ≤ r ≤ k.

By inductive hypothesis, evaluating L takes l − 1 multiplications and evaluating R takes r − 1 multiplications. Because one final multiplication is needed to evaluate L · R, the number of multiplications needed to evaluate the product of all k + 1 fac- tors is

(l − 1) + (r − 1) + 1 = (l + r)− 1 = (k + 1)− 1 = k.

[This is what was to be shown.] [Since we have proved the basis step and the inductive step of the strong mathematical induction, we conclude that the given statement is true.]

Strong mathematical induction makes possible a proof of the fact used frequently in com- puter science that every positive integer n has a unique binary integer representation. The proof looks complicated because of all the notation needed to write down the various steps. But the idea of the proof is simple. It is that if smaller integers than n have unique representations as sums of powers of 2, then the unique representation for n as a sum of powers of 2 can be found by taking the representation for n/2 (or for (n − 1)/2 if n is odd) and multiplying it by 2.

Theorem 5.4.1 Existence and Uniqueness of Binary Integer Representations

Given any positive integer n, n has a unique representation in the form

n = cr ·2r + cr−1 ·2r−1 + · · · + c2 ·22 + c1 ·2 + c0, where r is a nonnegative integer, cr = 1, and c j = 1 or 0 for all j = 0, 1, 2, . . . , r − 1.

Proof:

We give separate proofs by strong mathematical induction to show first the existence and second the uniqueness of the binary representation.

Existence (proof by strong mathematical induction): Let the property P(n) be the equation

n = cr ·2r + cr−1 ·2r−1 + · · · + c2 ·22 + c1 ·2 + c0, ← P(n) where r is a nonnegative integer, cr = 1, and c j = 1 or 0 for all j = 0, 1, 2, . . . , r − 1.

Show that P(1) is true: Let r = 0 and c0 = 1. Then 1 = cr ·2r , and so n = 1 can be written in the required form.

Show that for all integers k ≥ 1, if P(i) is true for all integers i from 1 through k, then P(k + 1) is also true:

continued on page 274

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

274 Chapter 5 Sequences, Mathematical Induction, and Recursion

Let k be an integer with k ≥ 1. Suppose that for all integers i from 1 through k, i = cr ·2r + cr−1 ·2r−1 + · · · + c2 ·22 + c1 ·2 + c0, ← inductive hypothesis

where r is a nonnegative integer, cr = 1, and c j = 1 or 0 for all j = 0, 1, 2, . . . , r − 1. We must show that k + 1 can be written as a sum of powers of 2 in the required form.

Case 1 (k + 1 is even): In this case (k + 1)/2 is an integer, and by inductive hypoth- esis, since 1 ≤ (k + 1)/2 ≤ k, then,

k + 1 2

= cr ·2r + cr−1 ·2r−1 + · · · + c2 ·22 + c1 ·2 + c0,

where r is a nonnegative integer, cr = 1, and c j = 1 or 0 for all j = 0, 1, 2, . . . , r − 1. Multiplying both sides of the equation by 2 gives

k + 1 = cr ·2r+1 + cr−1 ·2r + · · · + c2 ·23 + c1 ·22 + c0 ·2, which is a sum of powers of 2 of the required form.

Case 2 (k + 1 is odd): In this case k/2 is an integer, and by inductive hypothesis, since 1 ≤ k/2 ≤ k, then

k 2

= cr ·2r + cr−1 ·2r−1 + · · · + c2 ·22 + c1 ·2 + c0,

where r is a nonnegative integer, cr = 1, and c j = 1 or 0 for all j = 0, 1, 2, . . . , r − 1. Multiplying both sides of the equation by 2 and adding 1 gives

k + 1 = cr ·2r+1 + cr−1 ·2r + · · · + c2 ·23 + c1 ·22 + c0 ·2 + 1, which is also a sum of powers of 2 of the required form.

The preceding arguments show that regardless of whether k + 1 is even or odd, k + 1 has a representation of the required form. [Or, in other words, P(k + 1) is true as was to be shown.]

[Since we have proved the basis step and the inductive step of the strong mathematical induction, the existence half of the theorem is true.]

Uniqueness: To prove uniqueness, suppose that there is an integer n with two dif- ferent representations as a sum of nonnegative integer powers of 2. Equating the two representations and canceling all identical terms gives

2r + cr−1 ·2r−1 + · · · + c1 ·2 + c0 = 2s + ds−1 ·2s−1 + · · · + d1 ·2 + d0 5.4.1 where r and s are nonnegative integers, and each ci and each di equal 0 or 1. Without loss of generality, we may assume that r < s. But by the formula for the sum of a geometric sequence (Theorem 5.2.3) and because r < s,

2r + cr−1 ·2r−1 + · · · + c1 ·2 + c0 ≤ 2r + 2r−1 + · · · + 2 + 1 = 2r+1 − 1 < 2s .

Thus

2r + cr−1 ·2r−1 + · · · + c1 ·2 + c0 < 2s + ds−1 ·2s−1 + · · · + d1 ·2 + d0, which contradicts equation (5.4.1). Hence the supposition is false, so any integer n has only one representation as a sum of nonnegative integer powers of 2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 275

The Well-Ordering Principle for the Integers The well-ordering principle for the integers looks very different from both the ordinary and the strong principles of mathematical induction, but it can be shown that all three principles are equivalent. That is, if any one of the three is true, then so are both of the others.

Well-Ordering Principle for the Integers

Let S be a set of integers containing one or more integers all of which are greater than some fixed integer. Then S has a least element.

Note that when the context makes the reference clear, we will write simply “the well- ordering principle” rather than “the well-ordering principle for the integers.”

Example 5.4.4 Finding Least Elements

In each case, if the set has a least element, state what it is. If not, explain why the well- ordering principle is not violated.

a. The set of all positive real numbers.

b. The set of all nonnegative integers n such that n2 < n.

c. The set of all nonnegative integers of the form 46− 7k, where k is an integer.

Solution

a. There is no least positive real number. For if x is any positive real number, then x/2 is a positive real number that is less than x . No violation of the well-ordering principle occurs because the well-ordering principle refers only to sets of integers, and this set is not a set of integers.

b. There is no least nonnegative integer n such that n2 < n because there is no nonneg- ative integer that satisfies this inequality. The well-ordering principle is not violated because the well-ordering principle refers only to sets that contain at least one element.

c. The following table shows values of 46− 7k for various values of k.

k 0 1 2 3 4 5 6 7 · · · −1 −2 −3 · · · 46 − 7k 46 39 32 25 18 11 4 −3 · · · 53 60 67 · · ·

The table suggests, and you can easily confirm, that 46− 7k < 0 for k ≥ 7 and that 46− 7k ≥ 46 for k ≤ 0. Therefore, from the other values in the table it is clear that 4 is the least nonnegative integer of the form 46− 7k. This corresponds to k = 6. ■

Another way to look at the analysis of Example 5.4.4(c) is to observe that subtracting six 7’s from 46 leaves 4 left over and this is the least nonnegative integer obtained by repeated subtraction of 7’s from 46. In other words, 6 is the quotient and 4 is the remainder for the division of 46 by 7. More generally, in the division of any integer n by any positive integer d , the remainder r is the least nonnegative integer of the form n − dk. This is the heart of the following proof of the existence part of the quotient-remainder theorem (the part that guarantees the existence of a quotient and a remainder of the division of an

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

276 Chapter 5 Sequences, Mathematical Induction, and Recursion

integer by a positive integer). For a proof of the uniqueness of the quotient and remainder, see exercise 18 of Section 4.6.

Quotient-Remainder Theorem (Existence Part)

Given any integer n and any positive integer d, there exist integers q and r such that

n = dq + r and 0 ≤ r < d.

Proof:

Let S be the set of all nonnegative integers of the form

n − dk, where k is an integer. This set has at least one element. [For if n is nonnegative, then

n − 0 ·d = n ≥ 0, and so n − 0 ·d is in S. And if n is negative, then

n − nd = n(1− d)︸ ︷︷ ︸ ≥ 0,K⏐ →

<0 ≤0 since d is a positive integer

and so n − nd is in S.] It follows by the well-ordering principle for the integers that S contains a least element r . Then, for some specific integer k = q,

n − dq = r [because every integer in S can be written in this form]. Adding dq to both sides gives

n = dq + r. Furthermore, r < d. [For suppose r ≥ d. Then

n − d(q + 1) = n − dq − d = r − d ≥ 0, and so n − d(q + 1) would be a nonnegative integer in S that would be smaller than r. But r is the smallest integer in S. This contradiction shows that the supposition r ≥ d must be false.] The preceding arguments prove that there exist integers r and q for which

n = dq + r and 0 ≤ r < d. [This is what was to be shown.]

Another consequence of the well-ordering principle is the fact that any strictly decreas- ing sequence of nonnegative integers is finite. That is, if r1, r2, r3, . . . is a sequence of nonnegative integers satisfying

ri > ri+1

for all i ≥ 1, then r1, r2, r3, . . . is a finite sequence. [For by the well-ordering principle such a sequence would have to have a least element rk . It follows that rk must be the final term of the sequence because if there were a term rk+1, then since the sequence is strictly decreasing, rk+1 < rk , which would be a contradiction.] This fact is frequently used in computer science to prove that algorithms terminate after a finite number of steps.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Strong Mathematical Induction and the Well-Ordering Principle for the Integers 277

Test Yourself 1. In a proof by strong mathematical induction the basis step

may require checking a property P(n) for more _____ value of n.

2. Suppose that in the basis step for a proof by strong math- ematical induction the property P(n) was checked for all integers n from a through b. Then in the inductive step one

assumes that for any integer k ≥ b, the property P(n) is true for all values of i from _____ through _____ and one shows that _____ is true.

3. According to the well-ordering principle for the integers, if a set S of integers contains at least _____ and if there is some integer that is less than or equal to every _____, then _____.

Exercise Set 5.4 1. Suppose a1, a2, a3, . . . is a sequence defined as follows:

a1 = 1, a2 = 3, ak = ak−2 + 2ak−1 for all integers k ≥ 3.

Prove that an is odd for all integers n ≥ 1.

2. Suppose b1, b2, b3, . . . is a sequence defined as follows:

b1 = 4, b2 = 12 bk = bk−2 + bk−1 for all integers k ≥ 3.

Prove that bn is divisible by 4 for all integers n ≥ 1. 3. Suppose that c0, c1, c2, . . . is a sequence defined as follows:

c0 = 2, c1 = 2, c2 = 6, ck = 3ck−3 for all integers k ≥ 3.

Prove that cn is even for all integers n ≥ 0. 4. Suppose that d1, d2, d3, . . . is a sequence defined as follows:

d1 = 9 10

, d2 = 10 11

,

dk = dk−1 ·dk−2 for all integers k ≥ 3. Prove that 0 < dn ≤ 1 for all integers n ≥ 0.

5. Suppose that e0, e1, e2, . . . is a sequence defined as follows:

e0 = 12, e1 = 29 ek = 5ek−1 − 6ek−2 for all integers k ≥ 2.

Prove that en = 5 ·3n + 7 ·2n for all integers n ≥ 0. 6. Suppose that f0, f1, f2, . . . is a sequence defined as fol-

lows:

f0 = 5, f1 = 16 fk = 7 fk−1 − 10 fk−2 for all integers k ≥ 2.

Prove that fn = 3 ·2n + 2 ·5n for all integers n ≥ 0. 7. Suppose that g1, g2, g3, . . . is a sequence defined as fol-

lows:

g1 = 3, g2 = 5 gk = 3gk−1 − 2gk−2 for all integers k ≥ 3.

Prove that gn = 2n + 1 for all integers n ≥ 1.

8. Suppose that h0, h1, h2, . . . is a sequence defined as fol- lows:

h0 = 1, h1 = 2, h2 = 3, hk = hk−1 + hk−2 + hk−3 for all integers k ≥ 3.

a. Prove that hn ≤ 3n for all integers n ≥ 0. b. Suppose that s is any real number such that

s3 ≥ s2 + s + 1. (This implies that s > 1.83.) Prove that hn ≤ sn for all n ≥ 2.

9. Define a sequence a1, a2, a3, . . . as follows: a1 = 1, a2 = 3, and ak = ak−1 + ak−2 for all integers k ≥ 3. (This sequence is known as the Lucas sequence.) Use strong mathematical

induction to prove that an ≤ (

7 4

)n for all integers n ≥ 1.

10.H The problem that was used to introduce ordinary mathe- matical induction in Section 5.2 can also be solved using strong mathematical induction. Let P(n) be “any collec- tion of n coins can be obtained using a combination of 3c/ and 5c/ coins.” Use strong mathematical induction to prove that P(n) is true for all integers n ≥ 14.

11. You begin solving a jigsaw puzzle by finding two pieces that match and fitting them together. Each subsequent step of the solution consists of fitting together two blocks made up of one or more pieces that have previously been assem- bled. Use strong mathematical induction to prove that the number of steps required to put together all n pieces of a jigsaw puzzle is n − 1.

12.H The sides of a circular track contain a sequence of cans of gasoline. The total amount in the cans is sufficient to enable a certain car to make one complete circuit of the track, and it could all fit into the car’s gas tank at one time. Use mathe- matical induction to prove that it is possible to find an initial location for placing the car so that it will be able to traverse the entire track by using the various amounts of gasoline in the cans that it encounters along the way.

13.H Use strong mathematical induction to prove the existence part of the unique factorization of integers (Theorem 4.3.5): Every integer greater than 1 is either a prime number or a product of prime numbers.

14. Any product of two or more integers is a result of succes- sive multiplications of two integers at a time. For instance,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

278 Chapter 5 Sequences, Mathematical Induction, and Recursion

here are a few of the ways in which a1a2a3a4 might be com- puted: (a1a2)(a3a4) or ((a1a2)a3)a4) or a1((a2a3)a4). Use strong mathematical induction to prove that any product of two or more odd integers is odd.

15. Any sum of two or more integers is a result of successive additions of two integers at a time. For instance, here are a few of the ways in which a1 + a2 + a3 + a4 might be com- puted: (a1 + a2) + (a3 + a4) or ((a1 + a2) + a3) + a4) or a1 + ((a2 + a3) + a4). Use strong mathematical induction to prove that any sum of two or more even integers is even.

16.H Use strong mathematical induction to prove that for any integer n ≥ 2, if n is even, then any sum of n odd integers is even, and if n is odd, then any sum of n odd integers is odd.

17. Compute 41, 42, 43, 44, 45, 46, 47, and 48. Make a conjec- ture about the units digit of 4n where n is a positive integer. Use strong mathematical induction to prove your conjecture.

18. Compute 90, 91, 92, 93, 94, and 95. Make a conjecture about the units digit of 9n where n is a positive integer. Use strong mathematical induction to prove your conjecture.

19. Find the mistake in the following “proof” that purports to show that every nonnegative integer power of every nonzero real number is 1.

“Proof: Let r be any nonzero real number and let the prop- erty P(n) be the equation rn = 1. Show that P(0) is true: P(0) is true because r 0 = 1 by def- inition of zeroth power. Show that for all integers k ≥ 0, if P(i) is true for all inte- gers i from 0 through k, then P(k + 1) is also true: Let k be any integer with k ≥ 0 and suppose that r i = 1 for all integers i from 0 through k. This is the inductive hypothe- sis. We must show that rk+1 = 1. Now

rk+1 = rk+k−(k−1) because k + k − (k − 1)= k + k − k + 1 = k + 1 = r

k ·rk r k−1

by the laws of exponents

= 1 ·1 1

by inductive hypothesis

= 1. Thus rk+1 = 1 [as was to be shown].

[Since we have proved the basis step and the inductive step of the strong mathematical induction, we conclude that the given statement is true.]”

20. Use the well-ordering principle for the integers to prove Theorem 4.3.4: Every integer greater than 1 is divisible by a prime number.

21. Use the well-ordering principle for the integers to prove the existence part of the unique factorization of integers theo- rem: Every integer greater than 1 is either prime or a prod- uct of prime numbers.

22. a. The Archimedean property for the rational numbers states that for all rational numbers r , there is an integer n such that n > r . Prove this property.

b. Prove that given any rational number r , the number −r is also rational.

c. Use the results of parts (a) and (b) to prove that given any rational number r , there is an integer m such that m < r .

23.H Use the results of exercise 22 and the well-ordering prin- ciple for the integers to show that given any rational num- ber r , there is an integer m such that m ≤ r < m + 1.

24. Use the well-ordering principle to prove that given any inte- ger n ≥ 1, there exists an odd integer m and a nonnegative integer k such that n = 2k ·m.

25. Imagine a situation in which eight people, numbered con- secutively 1–8, are arranged in a circle. Starting from per- son #1, every second person in the circle is eliminated. The elimination process continues until only one person remains. In the first round the people numbered 2, 4, 6, and 8 are eliminated, in the second round the people numbered 3 and 7 are eliminated, and in the third round person #5 is eliminated. So after the third round only person #1 remains, as shown below.

1

Initial State After the 1st Round After the 2nd Round After the 3rd Round

2

3

4 5

6

7

8 1

3

5

7

1

5

1

a. Given a set of sixteen people arranged in a circle and numbered, consecutively 1–16, list the numbers of the people who are eliminated in each round if every second person is eliminated and the elimination process contin- ues until only one person remains. Assume that the start- ing point is person #1.

b. Use mathematical induction to prove that for all integers n ≥ 1, given any set of 2n people arranged in a circle and numbered consecutively 1 through 2n , if one starts from person #1 and goes repeatedly around the circle succes- sively eliminating every second person, eventually only person #1 will remain.

c. Use the result of part (b) to prove that for any non- negative integers n and m with 2n ≤ 2n + m < 2n+1, if r = 2n + m, then given any set of r people arranged in a circle and numbered consecutively 1 through r , if one starts from person #1 and goes repeatedly around the circle successively eliminating every second person, eventually only person #(2m + 1) will remain.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 279

26. Suppose P(n) is a property such that 1. P(0), P(1), P(2) are all true, 2. for all integers k ≥ 0, if P(k) is true, then P(3k) is true.

Must it follow that P(n) is true for all integers n ≥ 0? If yes, explain why; if no, give a counterexample.

27. Prove that if a statement can be proved by strong mathe- matical induction, then it can be proved by ordinary mathe- matical induction. To do this, let P(n) be a property that is defined for integers n, and suppose the following two state- ments are true: 1. P(a), P(a + 1), P(a + 2), . . . , P(b). 2. For any integer k ≥ b, if P(i) is true for all integers i

from a through k, then P(k + 1) is true. The principle of strong mathematical induction would allow us to conclude immediately that P(n) is true for all integers n ≥ a. Can we reach the same conclusion using the principle of ordinary mathematical induction? Yes! To see this, let Q(n) be the property

P( j) is true for all integers j with a ≤ j ≤ n.

Then use ordinary mathematical induction to show that Q(n) is true for all integers n ≥ b. That is, prove 1. Q(b) is true. 2. For any integer k ≥ b, if Q(k) is true then Q(k + 1) is

true.

28. Give examples to illustrate the proof of Theorem 5.4.1.

29.H It is a fact that every integer n ≥ 1 can be written in the form

cr ·3r + cr−1 ·3r−1 + · · · + c2 ·32 + c1 ·3 + c0, where cr = 1 or 2 and ci = 0, 1, or 2 for all integers i = 0, 1, 2, . . . , r − 1. Sketch a proof of this fact.

30.✶H Use mathematical induction to prove the existence part of the quotient-remainder theorem for integers n ≥ 0.

31.✶H Prove that if a statement can be proved by ordinary math- ematical induction, then it can be proved by the well- ordering principle.

32.H Use the principle of ordinary mathematical induction to prove the well-ordering principle for the integers.

Answers for Test Yourself 1. than one 2. a; k; P(k + 1) 3. one integer; integer in S; S contains a least element

5.5 Application: Correctness of Algorithms [P]rogramming reliably—must be an activity of an undeniably mathematical nature . . . . You see, mathematics is about thinking, and doing mathematics is always trying to think as well as possible. — Edsger W. Dijkstra (1981)

Th e

U ni

ve rs

ity of

Te xa

s at

Au st

in

Edsger W. Dijkstra (1930–2002)

What does it mean for a computer program to be correct? Each program is designed to do a specific task—calculate the mean or median of a set of numbers, compute the size of the paychecks for a company payroll, rearrange names in alphabetical order, and so forth. We will say that a program is correct if it produces the output specified in its accompanying documentation for each set of input data of the type specified in the documentation.∗

Most computer programmers write their programs using a combination of logical analysis and trial and error. In order to get a program to run at all, the programmer must first fix all syntax errors (such as writing ik instead of if, failing to declare a variable, or using a restricted keyword for a variable name). When the syntax errors have been removed, however, the program may still contain logical errors that prevent it from pro- ducing correct output. Frequently, programs are tested using sets of sample data for which the correct output is known in advance. And often the sample data are deliberately cho- sen to test the correctness of the program under extreme circumstances. But for most programs the number of possible sets of input data is either infinite or unmanageably large, and so no amount of program testing can give perfect confidence that the program will be correct for all possible sets of legal input data.

∗Consumers of computer programs want an even more stringent definition of correctness. If a user puts in data of the wrong type, the user wants a decent error message, not a system crash.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

280 Chapter 5 Sequences, Mathematical Induction, and Recursion

Co ur

te sy

of Ch

ris tia

ne Fl

oy d

Robert W. Floyd (1936–2002)

Since 1967, with the publication of a paper by Robert W. Floyd,∗ considerable effort has gone into developing methods for proving programs correct at the time they are com- posed. One of the pioneers in this effort, Edsger W. Dijkstra, asserted that “we now take the position that it is not only the programmer’s task to produce a correct program but also to demonstrate its correctness in a convincing manner.”† Another leader in the field, David Gries, went so far as to say that “a program and its proof should be developed hand-in-hand, with the proof usually leading the way.”∗∗ If such methods can eventually be used to write large scientific and commercial programs, the benefits to society will be enormous.

As with most techniques that are still in the process of development, methods for proving program correctness are somewhat awkward and unwieldy. In this section we give an overview of the general format of correctness proofs and the details of one crucial technique, the loop invariant procedure. At this point, we switch from using the term program, which refers to a particular programming language, to the more general term algorithm.

Assertions Consider an algorithm that is designed to produce a certain final state from a certain initial state. Both the initial and final states can be expressed as predicates involving the input and output variables. Often the predicate describing the initial state is called the pre-condition for the algorithm, and the predicate describing the final state is called the post-condition for the algorithm.

Example 5.5.1 Algorithm Pre-Conditions and Post-Conditions

Here are pre- and post-conditions for some typical algorithms.

a. Algorithm to compute a product of nonnegative integers

Pre-condition: The input variables m and n are nonnegative integers.

Post-condition: The output variable p equals mn.

b. Algorithm to find quotient and remainder of the division of one positive integer by another

Pre-condition: The input variables a and b are positive integers.

Post-condition: The output variables q and r are integers such that a = bq + r and 0 ≤ r < b.

c. Algorithm to sort a one-dimensional array of real numbers

Pre-condition: The input variable A[1], A[2], . . . , A[n] is a one-dimensional array of real numbers.

Post-condition: The output variable B[1], B[2], . . . , B[n] is a one-dimensional array of real numbers with same elements as A[1], A[2], . . . , A[n] but with the property that B[i] ≤ B[ j] whenever i ≤ j. ■

∗R. W. Floyd, “Assigning meanings to programs,” Proc. Symp. Appl. Math., Amer. Math. Soc. 19 (1967), 19–32. †Edsger Dijkstra in O. J. Dahl, E. W. Dijkstra, and C. A. R. Hoare, Structured Programming (London: Academic Press, 1972), p. 5. ∗∗David Gries, The Science of Programming (New York: Springer-Verlag, 1981), p. 164.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 281

A proof of algorithm correctness consists of showing that if the pre-condition for the algorithm is true for a collection of values for the input variables and if the statements of the algorithms are executed, then the post-condition is also true.

The divide-and-conquer principle has been useful in many aspects of computer pro- gramming, and proving algorithm correctness is no exception. The steps of an algorithm are divided into sections with assertions about the current state of algorithm variables inserted at strategically chosen points:

[Assertion 1: pre-condition for the algorithm] {Algorithm statements} [Assertion 2] {Algorithm statements}

...

[Assertion k − 1] {Algorithm statements} [Assertion k: post-condition for the algorithm]

Successive pairs of assertions are then treated as pre- and post-conditions for the algo- rithm statements between them. For each i = 1, 2, . . . , k − 1, one proves that if Asser- tion i is true and all the algorithm statements between Assertion i and Assertion (i + 1) are executed, then Assertion (i + 1) is true. Once all these individual proofs have been completed, one knows that Assertion k is true. And since Assertion 1 is the same as the pre-condition for the algorithm and Assertion k is the same as the post-condition for the algorithm, one concludes that the entire algorithm is correct with respect to its pre- and post-conditions.

Loop Invariants The method of loop invariants is used to prove correctness of a loop with respect to certain pre- and post-conditions. It is based on the principle of mathematical induction. Suppose that an algorithm contains a while loop and that entry to this loop is restricted by a condition G, called the guard. Suppose also that assertions describing the current states of algorithm variables have been placed immediately preceding and immediately following the loop. The assertion just preceding the loop is called the pre-condition for the loop and the one just following is called the post-condition for the loop. The annotated loop has the following appearance:

[Pre-condition for the loop] while (G)

[Statements in the body of the loop. None contain branching statements that lead outside the loop.]

end while [Post-condition for the loop]

• Definition A loop is defined as correct with respect to its pre- and post-conditions if, and only if, whenever the algorithm variables satisfy the pre-condition for the loop and the loop terminates after a finite number of steps, the algorithm variables satisfy the post-condition for the loop.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

282 Chapter 5 Sequences, Mathematical Induction, and Recursion

Co ur

te sy

of To

ny H

oa re

C. A. R. Hoare (born 1934)

Establishing the correctness of a loop uses the concept of loop invariant. A loop invariant is a predicate with domain a set of integers, which satisfies the condition: For each iteration of the loop, if the predicate is true before the iteration, the it is true after the iteration. Furthermore, if the predicate satisfies the following two additional conditions, the loop will be correct with respect to it pre- and post-conditions:

1. It is true before the first iteration of the loop.

2. If the loop terminates after a finite number of iterations, the truth of the loop invariant ensures the truth of the post-condition of the loop.

The following theorem, called the loop invariant theorem, formalizes these ideas. It was first developed by C. A. R. Hoare in 1969.

Theorem 5.5.1 Loop Invariant Theorem

Let a while loop with guard G be given, together with pre- and post-conditions that are predicates in the algorithm variables. Also let a predicate I (n), called the loop invariant, be given. If the following four properties are true, then the loop is correct with respect to its pre- and post-conditions.

I. Basis Property: The pre-condition for the loop implies that I (0) is true before the first iteration of the loop.

II. Inductive Property: For all integers k ≥ 0, if the guard G and the loop invari- ant I (k) are both true before an iteration of the loop, then I (k + 1) is true after iteration of the loop.

III. Eventual Falsity of Guard: After a finite number of iterations of the loop, the guard G becomes false.

IV. Correctness of the Post-Condition: If N is the least number of iterations after which G is false and I (N ) is true, then the values of the algorithm variables will be as specified in the post-condition of the loop.

Proof: The loop invariant theorem follows easily from the principle of mathematical induction. Assume that I (n) is a predicate that satisfies properties I–IV of the loop invariant theorem. [We will prove that the loop is correct with respect to its pre- and post-conditions.] Properties I and II are the basis and inductive steps needed to prove the truth of the following statement:

For all integers n ≥ 0, if the while loop iterates n times, then I (n) is true. 5.5.1

Thus, by the principle of mathematical induction, since both I and II are true, state- ment (5.5.1) is also true.

Property III says that the guard G eventually becomes false. At that point the loop will have been iterated some number, say N , of times. Since I (n) is true after the nth iteration for every n ≥ 0, then I (n) is true after the N th iteration. That is, after the N th iteration the guard is false and I (N ) is true. But this is the hypothesis of property IV, which is an if-then statement. Since statement IV is true (by assumption) and its hypothesis is true (by the argument just given), it follows (by modus ponens) that its conclusion is also true. That is, the values of all algorithm variables after execution of the loop are as specified in the post-condition for the loop.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 283

The loop invariant in the procedure for proving loop correctness may seem like a rabbit in a hat. Where does it come from? The fact is that developing a good loop invariant is a tricky process. Although learning how to do it is beyond the scope of this book, it is worth pursuing in a more advanced course. People who have become good at the process claim it has significantly altered their outlook on programming and has greatly improved their ability to write good code.

Another tricky aspect of handling correctness proofs arises from the fact that execu- tion of an algorithm is a dynamic process—it takes place in time. As execution progresses, the values of variables keep changing, yet often their names stay the same. In the follow- ing discussion, when we need to make a distinction between the values of a variable just before execution of an algorithm statement and just after execution of the statement, we will attach the subscripts old and new to the variable name.

Example 5.5.2 Correctness of a Loop to Compute a Product

The following loop is designed to compute the product mx for a nonnegative integer m and a real number x , without using a built-in multiplication operation. Prior to the loop, variables i and product have been introduced and given initial values i = 0 and product = 0.

[Pre-condition: m is a nonnegative integer, x is a real number, i = 0, and product = 0.]

while (i ̸= m) 1. product := product + x 2. i := i + 1

end while [Post-condition: product = mx]

Let the loop invariant be

I (n): i = n and product = nx

The guard condition G of the while loop is

G: i ̸= m

Use the loop invariant theorem to prove that the while loop is correct with respect to the given pre- and post-conditions.

Solution

I. Basis Property: [I (0) is true before the first iteration of the loop.] I (0) is “i = 0 and product = 0 ·x”, which is true before the first iteration of the

loop because 0 ·x = 0. II. Inductive Property: [If G ∧ I (k) is true before a loop iteration (where k ≥ 0), then

I (k + 1) is true after the loop iteration.] Suppose k is a nonnegative integer such that G ∧ I (k) is true before an iteration

of the loop. Then as execution reaches the top of the loop, i ̸= m, product = kx , and i = k. Since i ̸= m, the guard is passed and statement 1 is executed. Before execution of statement 1,

productold = kx .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

284 Chapter 5 Sequences, Mathematical Induction, and Recursion

Thus execution of statement 1 has the following effect:

productnew = productold + x = kx + x = (k + 1)x . Similarly, before statement 2 is executed,

iold = k, so after execution of statement 2,

inew = iold + 1 = k + 1. Hence after the loop iteration, the statement I (k + 1) , namely, (i = k + 1 and

product = (k + 1)x), is true. This is what we needed to show. III. Eventual Falsity of Guard: [After a finite number of iterations of the loop, G becomes

false.] The guard G is the condition i ̸= m, and m is a nonnegative integer. By I and II,

it is known that

for all integers n ≥ 0, if the loop is iterated n times, then i = n and product = nx .

So after m iterations of the loop, i = m. Thus G becomes false after m iterations of the loop.

IV. Correctness of the Post-Condition: [If N is the least number of iterations after which G is false and I (N ) is true, then the value of the algorithm variables will be as specified in the post-condition of the loop.]

According to the post-condition, the value of product after execution of the loop should be mx . But if G becomes false after N iterations, i = m. And if I (N ) is true, i = N and product = N x . Since both conditions (G false and I (N ) true) are satisfied, m = i = N and product = mx as required. ■

In the remainder of this section, we present proofs of the correctness of the crucial loops in the division algorithm and the Euclidean algorithm. (These algorithms were given in Section 4.8.)

Correctness of the Division Algorithm The division algorithm is supposed to take a nonnegative integer a and a positive integer d and compute nonnegative integers q and r such that a = dq + r and 0 ≤ r < d. Initially, the variables r and q are introduced and given the values r = a and q = 0. The crucial loop, annotated with pre- and post-conditions, is the following:

[Pre-condition: a is a nonnegative integer and d is a positive integer, r = a, and q = 0.]

while (r ≥ d) 1. r := r − d 2. q := q + 1

end while [Post-condition: q and r are nonnegative integers with the property that a = qd + r and 0 ≤ r < d.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 285

Proof:

To prove the correctness of the loop, let the loop invariant be

I (n): r = a − nd ≥ 0 and n = q.

The guard of the while loop is

G: r ≥ d

I. Basis property: [I (0) is true before the first iteration of the loop.] I (0) is “r = a − 0 ·d ≥ 0 and q = 0.” But by the pre-condition, r = a, a ≥ 0,

and q = 0. So since a = a − 0 ·d , then r = a − 0 ·d and I (0) is true before the first iteration of the loop.

II. Inductive Property: [If G ∧ I (k) is true before an iteration of the loop (where k ≥ 0), then I (k + 1) is true after iteration of the loop.]

Suppose k is a nonnegative integer such that G ∧ I (k) is true before an iteration of the loop. Since G is true, r ≥ d and the loop is entered. Also since I (k) is true, r = a − kd ≥ 0 and k = q. Hence, before execution of statements 1 and 2,

rold ≥ d and rold = a − kd and qold = k. When statements 1 and 2 are executed, then,

rnew = rold − d = (a − kd)− d = a − (k + 1)d 5.5.2 and qnew = qold + 1 = k + 1 5.5.3 In addition, since rold ≥ d before execution of statements 1 and 2, after execution of these statements,

rnew = rold − d ≥ d − d ≥ 0. 5.5.4 Putting equations (5.5.2), (5.5.3), and (5.5.4) together shows that after iteration of the loop,

rnew ≥ 0 and rnew = a − (k + 1)d and qnew = k + 1. Hence I (k + 1) is true.

III. Eventual Falsity of the Guard: [After a finite number of iterations of the loop, G becomes false.]

The guard G is the condition r ≥ d . Each iteration of the loop reduces the value of r by d and yet leaves r nonnegative. Thus the values of r form a decreasing sequence of nonnegative integers, and so (by the well-ordering principle) there must be a smallest such r , say rmin. Then rmin < d. [If rmin were greater than d, the loop would iterate another time, and a new value of r equal to rmin − d would be obtained. But this new value would be smaller than rmin which would contradict the fact that rmin is the smallest remainder obtained by repeated iteration of the loop.] Hence as soon as the value r = rmin is computed, the value of r becomes less than d, and so the guard G is false.

IV. Correctness of the Post-Condition: [If N is the least number of iterations after which G is false and I (N ) is true, then the values of the algorithm variables will be as specified in the post-condition of the loop.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

286 Chapter 5 Sequences, Mathematical Induction, and Recursion

Suppose that for some nonnegative integer N , G is false and I (N ) is true. Then r < d, r = a − Nd, r ≥ 0, and q = N . Since q = N , by substitution,

r = a − qd. Or, adding qd to both sides,

a = qd + r. Combining the two inequalities involving r gives

0 ≤ r < d. But these are the values of q and r specified in the post-condition, so the proof is complete. ■

Correctness of the Euclidean Theorem The Euclidean algorithm is supposed to take integers A and B with A > B ≥ 0 and com- pute their greatest common divisor. Just before the crucial loop, variables a, b, and r have been introduced with a = A, b = B, and r = B. The crucial loop, annotated with pre- and post-conditions, is the following:

[Pre-condition: A and B are integers with A > B ≥ 0, a = A, b = B, r = B.]

while (b ̸= 0) 1. r := a mod b 2. a := b 3. b := r

end while [Post-condition: a = gcd(A, B)]

Proof:

To prove the correctness of the loop, let the invariant be

I (n): gcd(a, b) = gcd(A, B) and 0 ≤ b < a.

The guard of the while loop is

G: b ̸= 0.

I. Basis Property: [I (0) is true before the first iteration of the loop.] I (0) is

gcd(A, B) = gcd(a, b) and 0 ≤ b < a. According to the pre-condition,

a = A, b = B, r = B, and 0 ≤ B < A. Hence gcd(A, B) = gcd(a, b). Since 0 ≤ B < A, b = B, and a = A then 0 ≤ b < a. Hence I (0) is true.

II. Inductive Property: [If G ∧ I (k) is true before an iteration of the loop (where k ≥ 0), then I (k + 1) is true after iteration of the loop.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 287

Suppose k is a nonnegative integer such that G ∧ I (k) is true before an iteration of the loop. [We must show that I (k + 1) is true after iteration of the loop.] Since G is true, bold ̸= 0 and the loop is entered. And since I (k) is true, immediately before statement 1 is executed,

gcd(aold, bold) = gcd(A, B) and 0 ≤ bold < aold. 5.5.5 After execution of statement 1,

rnew = aold mod bold. Thus, by the quotient-remainder theorem,

aold = bold ·q + rnew for some integer q and rnew has the property that

0 ≤ rnew < bold. 5.5.6 By Lemma 4.8.2,

gcd(aold, bold) = gcd(bold, rnew). So by the equation of (5.5.5),

gcd(bold, rnew) = gcd(A, B). 5.5.7 When statements 2 and 3 are executed,

anew = bold and bnew = rnew. 5.5.8 Substituting equations (5.5.8) into equation (5.5.7) yields

gcd(anew, bnew) = gcd(A, B). 5.5.9 And substituting the values from the equations in (5.5.8) into inequality (5.5.6) gives

0 ≤ bnew < anew. 5.5.10 Hence after the iteration of the loop, by equation (5.5.9) and inequality (5.5.10),

gcd(a, b) = gcd(A, B) and 0 ≤ b < a, which is I (k + 1). [This is what we needed to show.]

III. Eventual Falsity of the Guard: [After a finite number of iterations of the loop, G becomes false.]

Each value of b obtained by repeated iteration of the loop is nonnegative and less than the previous value of b. Thus, by the well-ordering principle, there is a least value bmin. The fact is that bmin = 0. [If bmin is not 0, then the guard is true, and so the loop is iterated another time. In this iteration a value of r is calculated that is less than the previous value of b, bmin. Then the value of b is changed to r , which is less than bmin. This contradicts the fact that bmin is the least value of b obtained by repeated iteration of the loop. Hence bmin = 0.] Since bmin = 0, the guard is false immediately following the loop iteration in which bmin is calculated.

IV. Correctness of the Post-Condition: [If N is the least number of iterations after which G is false and I (N ) is true, then the values of the algorithm variables will be as specified in the post-condition.]

Suppose that for some nonnegative integer N , G is false and I (N ) is true. [We must show the truth of the post-condition: a = gcd(A, B).] Since G is false, b = 0, and since I (N ) is true,

gcd(a, b) = gcd(A, B). 5.5.11

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

288 Chapter 5 Sequences, Mathematical Induction, and Recursion

Substituting b = 0 into equation (5.5.11) gives gcd(a, 0) = gcd(A, B).

But by Lemma 4.8.1,

gcd(a, 0) = a. Hence a = gcd(A, B) [as was to be shown].

Test Yourself 1. A pre-condition for an algorithm is _____ and a post-

condition for an algorithm is _____.

2. A loop is defined as correct with respect to its pre- and post- conditions if, and only if, whenever the algorithm variables satisfy the pre-condition for the loop and the loop terminates after a finite number of steps, then _____.

3. For each iteration of a loop, if a loop invariant is true before iteration of the loop, then _____.

4. Given a while loop with guard G and a predicate I (n) if the following four properties are true, then the loop is correct

with respect to its pre- and post-conditions:

(a) The pre-condition for the loop implies that _____ before the first iteration of the loop;

(b) For all integers k ≥ 0, if the guard G and the predicate I (k) are both true before an iteration of the loop, then _____;

(c) After a finite number of iterations of the loop, _____;

(d) If N is the least number of iterations after which G is false and I (N ) is true, then the values of the algorithm variables will be as specified _____.

Exercise Set 5.5 Exercises 1–5 contain a while loop and a predicate. In each case show that if the predicate is true before entry to the loop, then it is also true after exit from the loop.

1. loop: while (m ≥ 0 and m ≤ 100) m := m + 1 n := n − 1

end while

predicate: m + n = 100 2. loop: while (m ≥ 0 and m ≤ 100)

m := m + 4 n := n − 2

end while

predicate: m + n is odd 3. loop: while (m ≥ 0 and m ≤ 100)

m := 3 ·m n := 5 ·n

end while

predicate: m3 > n2

4. loop: while (n ≥ 0 and n ≤ 100) n := n + 1

end while

predicate: 2n < (n + 2)!

5. loop: while (n ≥ 3 and n ≤ 100) n := n + 1

end while

predicate: 2n + 1 ≤ 2n

Exercises 6–9 each contain a while loop annotated with a pre- and a post-condition and also a loop invariant. In each case, use the loop invariant theorem to prove the correctness of the loop with respect to the pre- and post-conditions.

6. [Pre-condition: m is a nonnegative integer, x is a real number, i = 0, and exp = 1.]

while (i ̸= m) 1. exp := exp · x 2. i := i + 1

end while

[Post-condition: exp = xm] loop invariant: I (n) is “exp = xn and i = n.”

7. [Pre-condition: largest = A[1] and i = 1]

while (i ̸= m) 1. i := i + 1 2. ifA[i] > largest then largest := A[i]

end while

[Post-condition: largest = maximum value of A[1], A[2], . . . , A[m]]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.5 Application: Correctness of Algorithms 289

loop invariant: I (n) is “largest = maximum value of A[1], A[2], . . . , A[n + 1] and i = n + 1.”

8. [Pre-condition: sum = A[1] and i = 1]

while (i ̸= m) 1. i := i + 1 2. sum: = sum + A[i]

end while

[Post-condition: sum = A[1] + A[2] + · · · + A[m]] loop invariant: I (n) is “i = n + 1 and sum = A[1] + A[2] + · · · + A[n + 1].”

9. [Pre-condition: a = A and A is a positive integer.]

while (a > 0)

1. a := a − 2 end while

[Post-condition: a = 0 if A is even and a = −1 if A is odd.] loop invariant: I (n) is “Both a and A are even integers or both are odd integers and a ≥ −1.”

10.✶H Prove correctness of the while loop of Algorithm 4.8.3 (in exercise 24 of Exercise Set 4.8) with respect to the follow- ing pre- and post-conditions:

Pre-condition: A and B are positive integers, a = A, and b = B.

Post-condition: One of a or b is zero and the other is nonzero. Whichever is nonzero equals gcd(A, B).

Use the loop invariant

I (n) “(1) a and b are nonnegative integers with gcd(a, b) = gcd(A, B).

(2) at most one of a and b equals 0, (3) 0 ≤ a + b ≤ A + B − n.”

11. The following while loop implements a way to multiply two numbers that was developed by the ancient Egyptians.

[Pre-condition: A and B are positive integers, x = A, y = B, and product = 0.]

while (y ̸= 0) r := y mod 2 if r = 0

then do x := 2 · x y := y div 2

end do

if r = 1 then do product := product + x

y := y − 1 end do

end while

[Post-condition: product = A · B] Prove the correctness of this loop with respect to its pre- and post-conditions by using the loop invariant

I (n): “xy + product = A · B.” 12.✶ The following sentence could be added to the loop invariant

for the Euclidean algorithm:

There exist integers u, v, s, and t such that a = u A + vB and b = s A + t B. 5.5.12

a. Show that this sentence is a loop invariant for

while (b ̸= 0) r := a mod b a := b b := r

end while

b. Show that if initially a = A and b = B, then sentence (5.5.12) is true before the first iteration of the loop.

c. Explain how the correctness proof for the Euclidean algorithm together with the results of (a) and (b) above allow you to conclude that given any integers A and B with A > B ≥ 0, there exist integers u and v so that gcd(A, B) = u A + vB.

d. By actually calculating u, v, s, and t at each stage of exe- cution of the Euclidean algorithm, find integers u and v so that gcd(330, 156) = 330u + 156v.

Answers for Test Yourself 1. a predicate that describes the initial state of the input variables for the algorithm; a predicate that describes the final state of the output variables for the algorithm 2. the algorithm variables satisfy the post-condition for the loop 3. it is true after iteration of the loop 4. (a) I (0) is true (b) I (k + 1) is true after the iteration of the loop (c) the guard G becomes false (d) in the post-condition of the loop

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

290 Chapter 5 Sequences, Mathematical Induction, and Recursion

5.6 Defining Sequences Recursively

So, Nat’ralists observe, a Flea/Hath smaller Fleas that on him prey,/And these have smaller Fleas to bite ’em,/And so proceed ad infinitum. — Jonathan Swift, 1733

A sequence can be defined in a variety of different ways. One informal way is to write the first few terms with the expectation that the general pattern will be obvious. We might say, for instance, “consider the sequence 3, 5, 7, . . ..” Unfortunately, misunderstandings can occur when this approach is used. The next term of the sequence could be 9 if we mean a sequence of odd integers, or it could be 11 if we mean the sequence of odd prime numbers.

The second way to define a sequence is to give an explicit formula for its nth term. For example, a sequence a0, a1, a2 . . . can be specified by writing

an = (−1)n n + 1 for all integers n ≥ 0.

The advantage of defining a sequence by such an explicit formula is that each term of the sequence is uniquely determined and can be computed in a fixed, finite number of steps, by substitution.

The third way to define a sequence is to use recursion, as was done in Examples 5.3.3 and 5.4.2. This requires giving both an equation, called a recurrence relation, that defines each later term in the sequence by reference to earlier terms and also one or more initial values for the sequence.

Sometimes it is very difficult or impossible to find an explicit formula for a sequence, but it is possible to define the sequence using recursion. Note that defining sequences recursively is similar to proving theorems by mathematical induction. The recurrence relation is like the inductive step and the initial conditions are like the basis step. Indeed, the fact that sequences can be defined recursively is equivalent to the fact that mathemat- ical induction works as a method of proof.

• Definition A recurrence relation for a sequence a0, a1, a2, . . . is a formula that relates each term ak to certain of its predecessors ak−1, ak−2, . . . , ak−i , where i is an integer with k − i ≥ 0. The initial conditions for such a recurrence relation specify the values of a0, a1, a2, . . . , ai−1, if i is a fixed integer, or a0, a1, . . . , am , where m is an integer with m ≥ 0, if i depends on k.

Example 5.6.1 Computing Terms of a Recursively Defined Sequence

Define a sequence c0, c1, c2, . . . recursively as follows: For all integers k ≥ 2, (1) ck = ck−1 + kck−2 + 1 recurrence relation (2) c0 = 1 and c1 = 2 initial conditions.

Find c2, c3, and c4.

Solution c2 = c1 + 2c0 + 1 = 2 + 2 ·1 + 1

by substituting k = 2 into (1) since c1 = 2 and c0 = 1 by (2)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 291

(3) ∴ c2 = 5 c3 = c2 + 3c1 + 1

= 5 + 3 ·2 + 1 by substituting k = 3 into (1) since c2 = 5 by (3) and c1 = 2 by (2)

(4) ∴ c3 = 12 c4 = c3 + 4c2 + 1

= 12 + 4 ·5 + 1 (5) ∴ c4 = 33

by substituting k = 4 into (1) since c3 = 12 by (4) and c2 = 5 by (3)

A given recurrence relation may be expressed in several different ways.

Example 5.6.2 Writing a Recurrence Relation in More Than One Way

Let s0, s1, s2, . . . be a sequence that satisfies the following recurrence relation:

for all integers k ≥ 1, sk = 3sk−1 − 1. Explain why the following statement is true:

for all integers k ≥ 0, sk+1 = 3sk − 1.

Note Think of the recurrence relation as s!= 3s!−1 − 1, where any positive integer expression may be placed in the box.

Solution In informal language, the recurrence relation says that any term of the sequence equals 3 times the previous term minus 1. Now for any integer k ≥ 0, the term previous to sk+1 is sk . Thus for any integer k ≥ 0, sk+1 = 3sk − 1. ■

A sequence defined recursively need not start with a subscript of zero. Also, a given recurrence relation may be satisfied by many different sequences; the actual values of the sequence are determined by the initial conditions.

Example 5.6.3 Sequences That Satisfy the Same Recurrence Relation

Let a1, a2, a3, . . . and b1, b2, b3, . . . satisfy the recurrence relation that the kth term equals 3 times the (k − 1)st term for all integers k ≥ 2:

(1) ak = 3ak−1 and bk = 3bk−1. But suppose that the initial conditions for the sequences are different:

(2) a1 = 2 and b1 = 1. Find (a) a2, a3, a4 and (b) b2, b3, b4.

Solution

a. a2 = 3a1 = 3 ·2 = 6 a3 = 3a2 = 3 ·6 = 18 a4 = 3a3 = 3 ·18 = 54

b. b2 = 3b1 = 3 ·1 = 3 b3 = 3b2 = 3 ·3 = 9 b4 = 3b3 = 3 ·9 = 27

Thus a1, a2, a3, . . . begins 2, 6, 18, 54, . . . and

b1, b2, b3, . . . begins 1, 3, 9, 27, . . . .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

292 Chapter 5 Sequences, Mathematical Induction, and Recursion

Example 5.6.4 Showing That a Sequence Given by an Explicit Formula Satisfies a Certain Recurrence Relation

The sequence of Catalan numbers, named after the Belgian mathematician Eugène Catalan (1814–1894), arises in a remarkable variety of different contexts in discrete math- ematics. It can be defined as follows: For each integer n ≥ 1,

Cn = 1

n + 1

( 2n n

) .

a. Find C1, C2, and C3.

b. Show that this sequence satisfies the recurrence relation Ck = 4k − 2 k + 1 Ck−1 for all

integers k ≥ 2

Ac ad

em ie

R oy

al e

de B

el gi

qu e

Eugène Catalan (1814–1894)

Solution

a. C1 = 1 2

( 2 1

) = 1

2 ·2 = 1, C2 =

1 3

( 4 2

) = 1

3 ·6 = 2, C3 =

1 4

( 6 3

) = 1

4 ·20 = 5

b. To obtain the kth and (k − 1)st terms of the sequence, just substitute k and k − 1 in place of n in the explicit formula for C1, C2, C3, . . . .

Ck = 1

k + 1

( 2k k

)

Ck+1 = 1

(k − 1) + 1

( 2(k − 1)

k − 1 )

= 1 k

( 2k − 2) k − 1 )

.

Then start with the right-hand side of the recurrence relation and transform it into the left-hand side: For each integer k ≥ 2,

4k − 2 k + 1 Ck−1 =

4k − 2 k + 1

[ 1 k

( 2k − 2) k − 1 )]

by substituting

= 2(2k − 1) k + 1 ·

1 k

· (2k − 2)! (k − 1)!(2k − 2− (k − 1))! by the formula for n choose r

= 1 k + 1 ·(2(2k − 1)) ·

(2k − 2)! (k(k − 1)!)(k − 1)! by rearranging the factors

= 1 k + 1 ·(2(2k − 1)) ·

1 k!(k − 1)! ·(2k − 2)! ·

1 2

· 1 k

·2k. because 12 · 1k ·2k = 1

= 1 k + 1 ·

2 2

· 1 k! ·

1 (k − 1)! ·

1 k

·(2k) ·(2k − 1) ·(2k − 2)! by rearranging the factors

= 1 k + 1 ·

(2k)! k!k!

because k(k − 1)! = k!, 2 2 = 1, and 2k · (2k − 1) · (2k − 2)! = (2k)!

= 1 k + 1

( 2k k

) by the formula for n choose r

= Ck by defintion of C1, C2, C3, . . . . ■

Examples of Recursively Defined Sequences Recursion is one of the central ideas of computer science. To solve a problem recursively means to find a way to break it down into smaller subproblems each having the same form as the original problem—and to do this in such a way that when the process is repeated

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 293

many times, the last of the subproblems are small and easy to solve and the solutions of the subproblems can be woven together to form a solution to the original problem.

Probably the most difficult part of solving problems recursively is to figure out how knowing the solution to smaller subproblems of the same type as the original problem will give you a solution to the problem as a whole. You suppose you know the solutions to smaller subproblems and ask yourself how you would best make use of that knowledge to solve the larger problem. The supposition that the smaller subproblems have already been solved has been called the recursive paradigm or the recursive leap of faith. Once you take this leap, you are right in the middle of the most difficult part of the prob- lem, but generally, the path to a solution from this point, though difficult, is short. The recursive leap of faith is similar to the inductive hypothesis in a proof by mathematical induction.

Example 5.6.5 The Tower of Hanoi

In 1883 a French mathematician, Édouard Lucas, invented a puzzle that he called The Tower of Hanoi (La Tour D’Hanoï). The puzzle consisted of eight disks of wood with holes in their centers, which were piled in order of decreasing size on one pole in a row of three. A facsimile of the cover of the box is shown in Figure 5.6.1. Those who played the game were supposed to move all the disks one by one from one pole to another, never placing a larger disk on top of a smaller one. The directions to the puzzle claimed it was based on an old Indian legend:

Co ur

te sy

of Fr

an ci

s Lu

ca s

Édouard Lucas (1842–1891)

On the steps of the altar in the temple of Benares, for many, many years Brahmins have been moving a tower of 64 golden disks from one pole to another; one by one, never placing a larger on top of a smaller. When all the disks have been transferred the Tower and the Brahmins will fall, and it will be the end of the world.

Figure 5.6.1

Co ur

te sy

of Pa

ul St

oc km

ey er

The puzzle offered a prize of ten thousand francs (about $34,000 US today) to anyone who could move a tower of 64 disks by hand while following the rules of the game. (See Figure 5.6.2 on the following page.) Assuming that you transferred the disks as efficiently as possible, how many moves would be required to win the prize?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

294 Chapter 5 Sequences, Mathematical Induction, and Recursion

64 golden disks

B CA

Figure 5.6.2

Solution An elegant and efficient way to solve this problem is to think recursively. Suppose that you, somehow or other, have found the most efficient way possible to transfer a tower of k − 1 disks one by one from one pole to another, obeying the restriction that you never place a larger disk on top of a smaller one. What is the most efficient way to transfer a tower of k disks from one pole to another? The answer is sketched in Figure 5.6.3, where pole A is the initial pole and pole C is the target pole, and is described as follows:

Step 1 : Transfer the top k − 1 disks from pole A to pole B. If k > 2, execution of this step will require a number of moves of individual disks among the three poles. But the point of thinking recursively is not to get caught up in imagining the details of how those moves will occur.

Step 2 : Move the bottom disk from pole A to pole C .

Step 3 : Transfer the top k − 1 disks from pole B to pole C . (Again, if k > 2, execution of this step will require more than one move.)

To see that this sequence of moves is most efficient, observe that to move the bottom disk of a stack of k disks from one pole to another, you must first transfer the top k − 1 disks to a third pole to get them out of the way. Thus transferring the stack of k disks from pole A to pole C requires at least two transfers of the top k − 1 disks: one to transfer them off the bottom disk to free the bottom disk so that it can be moved and another to transfer them back on top of the bottom disk after the bottom disk has been moved to pole C . If the bottom disk were not moved directly from pole A to pole C but were moved to pole B first, at least two additional transfers of the top k − 1 disks would be necessary: one to move them from pole A to pole C so that the bottom disk could be moved from pole A to pole B and another to move them off pole C so that the bottom disk could be moved onto pole C . This would increase the total number of moves and result in a less efficient transfer.

Thus the minimum sequence of moves must include going from the initial position (a) to position (b) to position (c) to position (d). It follows that

⎢⎢⎢⎢⎢⎢⎣

the minimum number of moves needed to transfer a tower of k disks from pole A to pole C

⎥⎥⎥⎥⎥⎥⎦ =

⎢⎢⎢⎢⎢⎢⎣

the minimum number of moves needed to go from position (a) to position (b)

⎥⎥⎥⎥⎥⎥⎦ +

⎢⎢⎢⎢⎢⎢⎣

The minimum number of moves needed to go from position (b) to position (c)

⎥⎥⎥⎥⎥⎥⎦ +

⎢⎢⎢⎢⎢⎢⎣

the minimum number of moves needed to go from position (c) to position (d)

⎥⎥⎥⎥⎥⎥⎦ 5.6.1

Note Defining the sequence is a crucial step in solving the problem. The recurrence relation and initial conditions are specified in terms of the sequence.

For each integer n ≥ 1, let

mn = [

the minimum number of moves needed to transfer a tower of n disks from one pole to another

]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 295

Tower of k disks

B Position after Transferring k – 1 Disks from B to C

(d)

CA

Tower of k – 1 disks

B Position after Moving the Bottom Disk from A to C

(c)

CA

Tower of k – 1 disks

Bottom disk

B Position after Transferring k – 1 Disks from A to B

(b)

CA

Bottom disk

Tower of k disks

B Initial Position

(a)

CA

Figure 5.6.3 Moves for the Tower of Hanoi

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

296 Chapter 5 Sequences, Mathematical Induction, and Recursion

Note that the numbers mn are independent of the labeling of the poles; it takes the same minimum number of moves to transfer n disks from pole A to pole C as to transfer n disks from pole A to pole B, for example. Also the values of mn are independent of the number of larger disks that may lie below the top n, provided these remain stationary while the top n are moved. Because the disks on the bottom are all larger than the ones on the top, the top disks can be moved from pole to pole as though the bottom disks were not present.

Going from position (a) to position (b) requires mk−1 moves, going from position (b) to position (c) requires just one move, and going from position (c) to position (d) requires mk−1 moves. By substitution into equation (5.6.1), therefore,

mk = mk−1 + 1 + mk−1 = 2mk−1 + 1 for all integers k ≥ 2.

The initial condition, or base, of this recursion is found by using the definition of the sequence. Because just one move is needed to move one disk from one pole to another,

m1 = [

the minimum number of moves needed to move a tower of one disk from one pole to another

] = 1.

Hence the complete recursive specification of the sequence m1, m2, m3, . . . is as follows: For all integers k ≥ 2,

(1) mk = 2mk−1 + 1 recurrence relation (2) m1 = 1 initial conditions

Here is a computation of the next five terms of the sequence:

(3) m2 = 2m1 + 1 = 2 ·1 + 1 = 3 by (1) and (2) (4) m3 = 2m2 + 1 = 2 ·3 + 1 = 7 by (1) and (3) (5) m4 = 2m3 + 1 = 2 ·7 + 1 = 15 by (1) and (4) (6) m5 = 2m4 + 1 = 2 ·15 + 1 = 31 by (1) and (5) (7) m6 = 2m5 + 1 = 2 ·31 + 1 = 63 by (1) and (6)

Going back to the legend, suppose the priests work rapidly and move one disk every second. Then the time from the beginning of creation to the end of the world would be m64 seconds. In the next section we derive an explicit formula for mn . Meanwhile, we can compute m64 on a calculator or a computer by continuing the process started above (Try it!). The approximate result is

1.844674× 1019 seconds ∼= 5.84542× 1011 years ∼= 584.5 billion years,

which is obtained by the estimate of

60 · 60 · 24 · (365.25) = 31, 557, 600 ↑ ↑ ↖ ↖ ↑

seconds per

minute

minutes

per

hour

hours

per

day

days

per

year

seconds

per

year

seconds in a year (figuring 365.25 days in a year to take leap years into account). Surpris- ingly, this figure is close to some scientific estimates of the life of the universe! ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 297

Example 5.6.6 The Fibonacci Numbers

One of the earliest examples of a recursively defined sequence arises in the writings of Leonardo of Pisa, commonly known as Fibonacci, who was the greatest European mathematician of the Middle Ages. In 1202 Fibonacci posed the following problem:

A single pair of rabbits (male and female) is born at the beginning of a year. Assume the following conditions:

1. Rabbit pairs are not fertile during their first month of life but thereafter give birth to one new male/female pair at the end of every month.

2. No rabbits die.

How many rabbits will there be at the end of the year?

B et

tm an

n/ CO

R B

IS

Fibonacci (Leonardo of Pisa) (ca. 1175–1250)

Solution One way to solve this problem is to plunge right into the middle of it using recur- sion. Suppose you know how many rabbit pairs there were at the ends of previous months. How many will there be at the end of the current month?

The crucial observation is that the number of rabbit pairs born at the end of month k is the same as the number of pairs alive at the end of month k − 2. Why? Because it is exactly the rabbit pairs that were alive at the end of month k − 2 that were fertile during month k. The rabbits born at the end of month k − 1 were not.

month k − 2 k − 1 k ———————|———————-|—————–

Each pair alive here ↑ gives birth to a pair here ↑

Now the number of rabbit pairs alive at the end of month k equals the ones alive at the end of month k − 1 plus the pairs newly born at the end of the month. Thus

⎢⎢⎢⎢⎣

the number of rabbit pairs alive at the end of month k

⎥⎥⎥⎥⎦ =

⎢⎢⎢⎢⎣

the number of rabbit pairs alive at the end of month k − 1

⎥⎥⎥⎥⎦ +

⎢⎢⎢⎢⎣

the number of rabbit pairs born at the end of month k

⎥⎥⎥⎥⎦

=

⎢⎢⎢⎢⎣

the number of rabbit pairs alive at the end of month k − 1

⎥⎥⎥⎥⎦ +

⎢⎢⎢⎢⎣

the number of rabbit pairs alive at the end of month k − 2

⎥⎥⎥⎥⎦ 5.6.2

Note It is essential to rephrase this observation in terms of a sequence.

For each integer n ≥ 1, let

Fn = [

the number of rabbit pairs alive at the end of month n

]

and let

F0 = the initial number of rabbit pairs = 1.

Then by substitution into equation (5.6.2), for all integers k ≥ 2, Fk = Fk−1 + Fk−2.

Now F0 = 1, as already noted, and F1 = 1 also, because the first pair of rabbits is not fertile until the second month. Hence the complete specification of the Fibonacci sequence is as follows: For all integers k ≥ 2,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

298 Chapter 5 Sequences, Mathematical Induction, and Recursion

(1) Fk = Fk−1 + Fk−2 recurrence relation (2) F0 = 1, F1 = 1 initial conditions.

To answer Fibonacci’s question, compute F2, F3, and so forth through F12:

(3) F2 = F1 +F0 = 1 + 1 = 2 by (1) and (2) (4) F3 = F2 +F1 = 2 + 1 = 3 by (1), (2) and (3) (5) F4 = F3 +F2 = 3 + 2 = 5 by (1), (3) and (4) (6) F5 = F4 +F3 = 5 + 3 = 8 by (1), (4) and (5) (7) F6 = F5 +F4 = 8 + 5 = 13 by (1), (5) and (6) (8) F7 = F6 +F5 = 13 + 8 = 21 by (1), (6) and (7) (9) F8 = F7 +F6 = 21 + 13 = 34 by (1), (7) and (8)

(10) F9 = F8 +F7 = 34 + 21 = 55 by (1), (8) and (9) (11) F10 = F9 +F8 = 55 + 34 = 89 by (1), (9) and (10) (12) F11 = F10 +F9 = 89 + 55 = 144 by (1), (10) and (11) (13) F12 = F11 +F10 = 144 + 89 = 233 by (1), (11) and (12)

At the end of the twelfth month there are 233 rabbit pairs, or 466 rabbits in all. ■

Example 5.6.7 Compound Interest

On your twenty-first birthday you get a letter informing you that on the day you were born an eccentric rich aunt deposited $100,000 in a bank account earning 4% interest compounded annually and she now intends to turn the account over to you, provided you can figure out how much it is worth. What is the amount currently in the account?

Solution To approach this problem recursively, observe that ⎡

⎢⎢⎣

the amount in the account at the end of any particular year

⎥⎥⎦ =

⎢⎢⎣

the amount in the account at the end of the previous year

⎥⎥⎦+

⎢⎢⎣

the interest earned on the account during the year

⎥⎥⎦.

Now the interest earned during the year equals the interest rate, 4% = 0.04 times the amount in the account at the end of the previous year. Thus ⎡

⎢⎢⎣

the amount in the account at the end of any particular year

⎥⎥⎦ =

⎢⎢⎣

the amount in the account at the end of the previous year

⎥⎥⎦+ (0.04) ·

⎢⎢⎣

the amount in the account at the end of the previous year

⎥⎥⎦. 5.6.3

For each positive integer n, let

An = [

the amount in the account at the end of year n

]

and let

Note Again, a crucial step is to define the sequence explicitly.

A0 = [

the initial amount in the account

] = $100, 000.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 299

Then for any particular year k, substitution into equation (5.6.3) gives

Ak = Ak−1 + (0.04) · Ak−1 = (1 + 0.04) · Ak−1 = (1.04) · Ak−1 by factoring out Ak−1.

Consequently, the values of the sequence A0, A1, A2, . . . are completely specified as follows: for all integers k ≥ 1,

(1) Ak = (1.04) · Ak−1 recurrence relation (2) A0 = $100, 000 initial condition.

The number 1.04 is called the growth factor of the sequence. In the next section we derive an explicit formula for the value of the account in any

year n. The value on your twenty-first birthday can also be computed by repeated substi- tution as follows:

(3) A1 = 1.04 · A0 = (1.04) ·$100, 000 = $104, 000 by (1) and (2) (4) A2 = 1.04 · A1 = (1.04) ·$104, 000 = $108, 160 by (1) and (3) (5) A3 = 1.04 · A2 = (1.04) ·$108, 160 = $112, 486.40 by (1) and (4)

... ...

(22) A20 = 1.04 · A19 ∼= (1.04) ·$210, 684.92 ∼= $219, 112.31 by (1) and (21) (23) A21 = 1.04 · A20 ∼= (1.04) ·$219, 112.31 ∼= $227, 876.81 by (1) and (22)

The amount in the account is $227,876.81 (to the nearest cent). Fill in the dots (to check the arithmetic) and collect your money! ■

Example 5.6.8 Compound Interest with Compounding Several Times a Year

When an annual interest rate of i is compounded m times per year, the interest rate paid per period is i/m. For instance, if 3% = 0.03 annual interest is compounded quarterly, then the interest rate paid per quarter is 0.03/4 = 0.0075.

For each integer k ≥ 1, let Pk = the amount on deposit at the end of the kth period, assuming no additional deposits or withdrawals. Then the interest earned during the kth period equals the amount on deposit at the end of the (k − 1)st period times the interest rate for the period:

interest earned during kth period = Pk−1 (

i m

) .

The amount on deposit at the end of the kth period, Pk , equals the amount at the end of the (k − 1)st period, Pk−1, plus the interest earned during the kth period:

Pk = Pk−1 + Pk−1 (

i m

) = Pk−1

( 1 + i

m

) . 5.6.4

Suppose $10,000 is left on deposit at 3% compounded quarterly.

a. How much will the account be worth at the end of one year, assuming no additional deposits or withdrawals?

b. The annual percentage rate (APR) is the percentage increase in the value of the account over a one-year period. What is the APR for this account?

Solution

a. For each integer n ≥ 1, let Pn = the amount on deposit after n consecutive quarters, assuming no additional deposits or withdrawals, and let P0 be the initial $10,000. Then

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

300 Chapter 5 Sequences, Mathematical Induction, and Recursion

by equation (5.6.4) with i = 0.03 and m = 4, a recurrence relation for the sequence P0, P1, P2, . . . is

(1) Pk = Pk−1(1 + 0.0075) = (1.0075) · Pk−1 for all integers k≥ 1. The amount on deposit at the end of one year (four quarters), P4, can be found by

successive substitution:

(2) P0 = $10, 000 (3) P1 = 1.0075 · P0 = (1.0075) ·$10, 000.00 = $10, 075.00 by (1) and (2) (4) P2 = 1.0075 · P1 = (1.0075) ·$10, 075.00 = $10, 150.56 by (1) and (3) (5) P3 = 1.0075 · P2 ∼= (1.0075) ·$10, 150.56 = $10, 226.69 by (1) and (4) (6) P4 = 1.0075 · P3 ∼= (1.0075) ·$10, 226.69 = $10, 303.39 by (1) and (5)

Hence after one year there is $10,303.39 (to the nearest cent) in the account.

b. The percentage increase in the value of the account, or APR, is

10303.39− 10000 10000

= 0.03034 = 3.034%. ■

Recursive Definitions of Sum and Product Addition and multiplication are called binary operations because only two numbers can be added or multiplied at a time. Careful definitions of sums and products of more than two numbers use recursion.

• Definition Given numbers a1, a2, . . . , an , where n is a positive integer, the summation from i = 1 to n of the ai, denoted

∑n i=1 ai , is defined as follows:

1∑

i=1 ai = a1 and

n∑

i=1 ai = (

n−1∑

i=1 ai

)

+ an, if n > 1.

The product from i = 1 to n of the ai, denoted ∏n

i=1 ai , is defined by

1∏

i=1 ai = a1 and

n∏

i=1 ai = (

n−1∏

i=1 ai

)

·an, if n > 1.

The effect of these definitions is to specify an order in which sums and products of more than two numbers are computed. For example,

4∑

i=1 ai = (

3∑

i=1 ai

)

+ a4 = ((

2∑

i=1 ai

)

+ a3 )

+ a4 = ((a1 + a2) + a3) + a4.

The recursive definitions are used with mathematical induction to establish various properties of general finite sums and products.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 301

Example 5.6.9 A Sum of Sums

Prove that for any positive integer n, if a1, a2, . . . , an and b1, b2, . . . , bn are real numbers, then

n∑

i=1 (ai + bi ) =

n∑

i=1 ai +

n∑

i=1 bi .

Solution The proof is by mathematical induction. Let the property P(n) be the equation n∑

i = 1 (ai + bi ) =

n∑

i = 1 ai +

n∑

i = 1 bi . ← P(n)

We must show that P(n) is true for all integers n ≥ 0. We do this by mathematical induc- tion on n.

Show that P(1) is true: To establish P(1), we must show that 1∑

i = 1 (ai + bi ) =

1∑

i = 1 ai +

1∑

i = 1 bi . ← P(1)

But 1∑

i=1 (ai + bi ) = a1 + b1 by definition of %

= 1∑

i=1 ai +

1∑

i=1 bi also by definition of %.

Hence P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is also true: Suppose a1, a2, . . . , ak, ak+1 and b1, b2, . . . , bk, bk+1 are real numbers and that for some k ≥ 1

k∑

i=1 (ai + bi ) =

k∑

i=1 ai +

k∑

i=1 bi .

← P(k) inductive hypothesis

We must show that k+1∑

i=1 (ai + bi ) =

k+1∑

i=1 ai +

k+1∑

i=1 bi . ← P(k + 1)

[We will show that the left-hand side of this equation equals the right-hand side.]

But the left-hand side of the equation is

k+1∑ i=1

(ai + bi ) = k∑

i=1 (ai + bi ) + (ak+1 + bk+1) by definition of %

= (

k∑ i=1

ai + k∑

i=1 bi

) + (ak+1 + bk+1) by inductive hypothesis

= (

k∑ i=1

ai + ak+1 )

+ (

k∑ i=1

bi + bk+1 )

by the associative and cummutative laws of algebra

= k+1∑ i=1

ai + k+1∑ i=1

bi by definition of %

which equals the right-hand side of the equation. [This is what was to be shown.] ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

302 Chapter 5 Sequences, Mathematical Induction, and Recursion

Test Yourself 1. A recursive definition for a sequence consists of a

_____ and _____.

2. A recurrence relation is an equation that defines each later term of a sequence by reference to _____ in the sequence.

3. Initial conditions for a recursive definition of a sequence con- sist of one or more of the _____ of the sequence.

4. To solve a problem recursively means to divide the prob- lem into smaller subproblems of the same type as the initial problem, to suppose _____, and to figure out how to use the supposition to _____.

5. A crucial step for solving a problem recursively is to define a _____ in terms of which the recurrence relation and initial conditions can be specified.

Exercise Set 5.6 Find the first four terms of each of the recursively defined sequences in 1–8.

1. ak = 2ak−1 + k, for all integers k ≥ 2 a1 = 1

2. bk = bk−1 + 3k, for all integers k ≥ 2 b1 = 1

3. ck = k(ck−1)2, for all integers k ≥ 1 c0 = 1

4. dk = k(dk−1)2, for all integers k ≥ 1 d0 = 3

5. sk = sk−1 + 2sk−2, for all integers k ≥ 2 s0 = 1, s1 = 1

6. tk = tk−1 + 2tk−2, for all integers k ≥ 2 t0 = −1, t1 = 2

7. uk = kuk−1 − uk−2, for all integers k ≥ 3 u1 = 1, u2 = 1

8. vk = vk−1 + vk−2 + 1, for all integers k ≥ 3 v1 = 1, v2 = 3

9. Let a0, a1, a2, . . . be defined by the formula an = 3n + 1, for all integers n ≥ 0. Show that this sequence satisfies the recurrence relation ak = ak−1 + 3, for all integers k ≥ 1.

10. Let b0, b1, b2, . . . be defined by the formula bn = 4n , for all integers n ≥ 0. Show that this sequence satisfies the recur- rence relation bk = 4bk−1, for all integers k ≥ 1.

11. Let c0, c1, c2, . . . be defined by the formula cn = 2n − 1 for all integers n ≥ 0. Show that this sequence satisfies the recurrence relation

ck = 2ck−1 + 1.

12. Let s0, s1, s2, . . . be defined by the formula sn = (−1)n

n! for all integers n ≥ 0. Show that this sequence satisfies the recurrence relation

sk = −sk−1

k .

13. Let t0, t1, t2, . . . be defined by the formula tn = 2 + n for all integers n ≥ 0. Show that this sequence satisfies the recurrence relation

tk = 2tk−1 − tk−2. 14. Let d0, d1, d2, . . . be defined by the formula dn = 3n − 2n

for all integers n ≥ 0. Show that this sequence satisfies the recurrence relation

dk = 5dk−1 − 6dk−2.

15.H For the sequence of Catalan numbers defined in Example 5.6.4, prove that for all integers n ≥ 1,

Cn = 1

4n + 2

( 2n + 2 n + 1

) .

16. Use the recurrence relation and values for the Tower of Hanoi sequence m1, m2, m3, . . . discussed in Exam- ple 5.6.5 to compute m7 and m8.

17. Tower of Hanoi with Adjacency Requirement: Suppose that in addition to the requirement that they never move a larger disk on top of a smaller one, the priests who move the disks of the Tower of Hanoi are also allowed only to move disks one by one from one pole to an adjacent pole. Assume poles A and C are at the two ends of the row and pole B is in the middle. Let

an =

⎣ the minimum number of moves needed to transfer a tower of n disks from pole A to pole C

⎦ .

a. Find a1, a2, and a3. b. Find a4. c. Find a recurrence relation for a1, a2, a3, . . . .

18. Tower of Hanoi with Adjacency Requirement: Suppose the same situation as in exercise 17. Let

bn =

⎣ the minimum number of moves needed to transfer a tower of n disks from pole A to pole B

⎦ .

a. Find b1, b2, and b3. b. Find b4.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Defining Sequences Recursively 303

c. Show that bk = ak−1 + 1 + bk−1 for all integers k ≥ 2, where a1, a2, a3, . . . is the sequence defined in exercise 17.

d. Show that bk ≤ 3bk−1 + 1 for all integers k ≥ 2. e.✶H Show that bk = 3bk−1 + 1 for all integers k ≥ 2.

19. Four-Pole Tower of Hanoi: Suppose that the Tower of Hanoi problem has four poles in a row instead of three. Disks can be transferred one by one from one pole to any other pole, but at no time may a larger disk be placed on top of a smaller disk. Let sn be the minimum number of moves needed to transfer the entire tower of n disks from the left-most to the right-most pole. a. Find s1, s2, and s3. b. Find s4. c. Show that sk ≤ 2sk−2 + 3 for all integers k ≥ 3.

20. Tower of Hanoi Poles in a Circle: Suppose that instead of being lined up in a row, the three poles for the original Tower of Hanoi are placed in a circle. The monks move the disks one by one from one pole to another, but they may only move disks one over in a clockwise direction and they may never move a larger disk on top of a smaller one. Let cn be the minimum number of moves needed to transfer a pile of n disks from one pole to the next adjacent pole in the clockwise direction. a. Justify the inequality ck ≤ 4ck−1 + 1 for all integers

k ≥ 2. b. The expression 4ck−1 + 1 is not the minimum number

of moves needed to transfer a pile of k disks from one pole to another. Explain, for example, why c3 ̸= 4c2 + 1.

21. Double Tower of Hanoi: In this variation of the Tower of Hanoi there are three poles in a row and 2n disks, two of each of n different sizes, where n is any positive integer. Initially one of the poles contains all the disks placed on top of each other in pairs of decreasing size. Disks are transferred one by one from one pole to another, but at no time may a larger disk be placed on top of a smaller disk. However, a disk may be placed on top of one of the same size. Let tn be the minimum number of moves needed to transfer a tower of 2n disks from one pole to another. a. Find t1 and t2. b. Find t3. c. Find a recurrence relation for t1, t2, t3, . . . .

22. Fibonacci Variation: A single pair of rabbits (male and female) is born at the beginning of a year. Assume the following conditions (which are more realistic than Fibonacci’s): (1) Rabbit pairs are not fertile during their first month of

life but thereafter give birth to four new male/female pairs at the end of every month.

(2) No rabbits die. a. Let rn = the number of pairs of rabbits alive at the end

of month n, for each integer n ≥ 1, and let r0 = 1. Find a recurrence relation for r0, r1, r2, . . . .

b. Compute r0, r1, r2, r3, r4, r5, and r6. c. How many rabbits will there be at the end of the year?

23. Fibonacci Variation: A single pair of rabbits (male and female) is born at the beginning of a year. Assume the fol- lowing conditions: (1) Rabbit pairs are not fertile during their first two

months of life, but thereafter give birth to three new male/female pairs at the end of every month.

(2) No rabbits die. a. Let sn = the number of pairs of rabbits alive at the end

of month n, for each integer n ≥ 1, and let s0 = 1. Find a recurrence relation for s0, s1, s2, . . . .

b. Compute s0, s1, s2, s3, s4, and s5. c. How many rabbits will there be at the end of the year?

In 24–34, F0, F1, F2, . . . is the Fibonacci sequence.

24. Use the recurrence relation and values for F0, F1, F2, . . . given in Example 5.6.6 to compute F13 and F14.

25. The Fibonacci sequence satisfies the recurrence relation Fk = Fk−1 + Fk−2, for all integers k ≥ 2. a. Explain why the following is true:

Fk+1 = Fk + Fk−1 for all integers k ≥ 1.

b. Write an equation expressing Fk+2 in terms of Fk+1 and Fk .

c. Write an equation expressing Fk+3 in terms of Fk+2 and Fk+1

26. Prove that Fk = 3Fk−3 + 2Fk−4 for all integers k ≥ 4.

27. Prove that F2k − F2k−1 = Fk Fk−1 − Fk+1 Fk−1, for all integers k ≥ 1.

28. Prove that F2k+1 − F2k − F2k−1 = 2Fk Fk−1, for all integers k ≥ 1.

29. Prove that F2k+1 − F2k = Fk−1 Fk+2, for all integers k ≥ 1. 30. Use mathematical induction to prove that for all integers

n ≥ 0, Fn+2 Fn − F2n+1 = (−1)n . 31.✶ Use strong mathematical induction to prove that Fn < 2n

for all integers n ≥ 1. 32.✶H Let F0, F1, F2, . . . be the Fibonacci sequence defined

in Section 5.6. Prove that for all integers n ≥ 0, gcd (Fn+1, Fn) = 1.

33. It turns out that the Fibonacci sequence satisfies the fol- lowing explicit formula: For all integers Fn ≥ 0,

Fn = 1√ 5

⎣ (

1 + √

5 2

)n+1 − (

1− √

5 2

)n+1⎤

Verify that the sequence defined by this formula satisfies the recurrence relation Fk = Fk−1 + Fk−2 for all integers k ≥ 2.

34.H (For students who have studied calculus) Find

lim n→∞

( Fn+1 Fn

) , assuming that the limit exists.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

304 Chapter 5 Sequences, Mathematical Induction, and Recursion

35.✶H (For students who have studied calculus) Prove that

lim n→∞

( Fn+1 Fn

) exists.

36. (For students who have studied calculus) Define x0, x1, x2, . . . as follows:

xk = √

2 + xk−1 for all integers k ≥ 1 x0 = 0

Find limn→∞ xn . (Assume that the limit exists.)

37. Compound Interest: Suppose a certain amount of money is deposited in an account paying 4% annual interest compounded quarterly. For each positive integer n, let Rn = the amount on deposit at the end of the nth quarter, assuming no additional deposits or withdrawals, and let R0 be the initial amount deposited. a. Find a recurrence relation for R0, R1, R2, . . . . b. If R0 = $5000, find the amount of money on deposit at

the end of one year. c. Find the APR for the account.

38. Compound Interest: Suppose a certain amount of money is deposited in an account paying 3% annual interest com- pounded monthly. For each positive integer n, let Sn = the amount on deposit at the end of the nth month, and let S0 be the initial amount deposited. a. Find a recurrence relation for S0, S1, S2, . . ., assum-

ing no additional deposits or withdrawals during the year.

b. If S0 = $10, 000, find the amount of money on deposit at the end of one year.

c. Find the APR for the account.

39. With each step you take when climbing a staircase, you can move up either one stair or two stairs. As a result, you can climb the entire staircase taking one stair at a time, taking two at a time, or taking a combination of one- and two-stair increments. For each integer n ≥ 1, if the staircase consists of n stairs, let cn be the number of different ways to climb the staircase. Find a recurrence relation for c1, c2, c3, . . . .

40. A set of blocks contains blocks of heights 1, 2, and 4 cen- timeters. Imagine constructing towers by piling blocks of different heights directly on top of one another. (A tower of height 6 cm could be obtained using six 1-cm blocks, three 2-cm blocks one 2-cm block with one 4-cm block on top, one 4-cm block with one 2-cm block on top, and so forth.) Let t be the number of ways to construct a tower of height n cm using blocks from the set. (Assume an unlimited sup- ply of blocks of each size.) Find a recurrence relation for t1, t2, t3, . . ..

41. Use the recursive definition of summation, together with mathematical induction, to prove the generalized distribu- tive law that for all positive integers n, if a1, a2, . . . , an and c are real numbers, then

n∑

i=1 cai = c

( n∑

i=1 ai

)

.

42. Use the recursive definition of product, together with math- ematical induction, to prove that for all positive integers n, if a1, a2, . . . , an and b1, b2, . . . , bn are real numbers, then

n∏

i=1 (ai bi ) =

( n∏

i=1 ai

)( n∏

i=1 bi

)

.

43. Use the recursive definition of product, together with math- ematical induction, to prove that for all positive integers n, if a1, a2, . . . , an and c are real numbers, then

n∏

i=1 (cai ) = cn

( n∏

i=1 ai

)

.

44.H The triangle inequality for absolute value states that for all real numbers a and b, |a + b| ≤ |a| + |b|. Use the recur- sive definition of summation, the triangle inequality, the definition of absolute value, and mathematical induction to prove that for all positive integers n, if a1, a2, . . . , an are real numbers, then

∣∣∣∣∣

n∑

i=1 ai

∣∣∣∣∣ ≤ n∑

i=1 |ai |.

Answers for Test Yourself 1. recurrence relation; initial conditions 2. earlier terms 3. values of the first few terms 4. that the smaller subproblems have already been solved; solve the initial problem 5. sequence

5.7 Solving Recurrence Relations by Iteration

The keener one’s sense of logical deduction, the less often one makes hard and fast inferences. — Bertrand Russell, 1872–1970

Suppose you have a sequence that satisfies a certain recurrence relation and initial conditions. It is often helpful to know an explicit formula for the sequence, especially if

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 305

you need to compute terms with very large subscripts or if you need to examine general properties of the sequence. Such an explicit formula is called a solution to the recur- rence relation. In this section, we discuss methods for solving recurrence relations. For example, in the text and exercises of this section, we will show that the Tower of Hanoi sequence of Example 5.6.5 satisfies the formula

mn = 2n − 1, and that the compound interest sequence of Example 5.6.7 satisfies

An = (1.04)n ·$100, 000.

The Method of Iteration The most basic method for finding an explicit formula for a recursively defined sequence is iteration. Iteration works as follows: Given a sequence a0, a1, a2, . . . defined by a recurrence relation and initial conditions, you start from the initial conditions and calcu- late successive terms of the sequence until you see a pattern developing. At that point you guess an explicit formula.

Example 5.7.1 Finding an Explicit Formula

Let a0, a1, a2, . . . be the sequence defined recursively as follows: For all integers k ≥ 1, (1) ak = ak−1 + 2 recurrence relation (2) a0 = 1 initial condition.

Use iteration to guess an explicit formula for the sequence.

Solution Recall that to say

ak = ak−1 + 2 for all integers k ≥ 1 means

a! = a!−1 + 2 no matter what positive integer isplaced into the box !. In particular,

a1 = a0 + 2, a2 = a1 + 2, a3 = a2 + 2,

and so forth. Now use the initial condition to begin a process of successive substitutions into these equations, not just of numbers (as was done in Section 5.6) but of numerical expressions.

The reason for using numerical expressions rather than numbers is that in these prob- lems you are seeking a numerical pattern that underlies a general formula. The secret of success is to leave most of the arithmetic undone. However, you do need to eliminate parentheses as you go from one step to the next. Otherwise, you will soon end up with a bewilderingly large nest of parentheses. Also, it is nearly always helpful to use short- hand notations for regrouping additions, subtractions, and multiplications of numbers that repeat. Thus, for instance, you would write

5 ·2 instead of 2 + 2 + 2 + 2 + 2

and 25 instead of 2 ·2 ·2 ·2 ·2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

306 Chapter 5 Sequences, Mathematical Induction, and Recursion

Notice that you don’t lose any information about the number patterns when you use these shorthand notations.

Here’s how the process works for the given sequence:

a0 = 1 the initial condition

a1 = a0 + 2 = 1 + 2︸ ︷︷ ︸ by substitution

a2 = a1 + 2 = ︷ ︸︸ ︷ (1 + 2)+ 2 = 1 + 2 + 2︸ ︷︷ ︸ eliminate parentheses

a3 = a2 + 2 = ︷ ︸︸ ︷ (1 + 2 + 2)+ 2 = 1 + 2 + 2 + 2︸ ︷︷ ︸ eliminate parentheses again; write

3 ·2 instead of 2 + 2 + 2?

a4 = a3 + 2 = ︷ ︸︸ ︷ (1 + 2 + 2 + 2) + 2 = 1 + 2 + 2 + 2 + 2 eliminate parentheses again;

definitely write 4 ·2 instead of 2 + 2 + 2 + 2—the length of the string of 2’s is getting out of hand.

Tip Do no arithmetic except

• replace n ·1 and 1 ·n by n

• reformat repeated numbers

• get rid of parentheses

Since it appears helpful to use the shorthand k ·2 in place of 2 + 2 + · · · + 2 (k times), we do so, starting again from a0.

a0 = 1 = 1 + 0 ·2 the initial condition

a1 = a0 + 2 = 1 + 2︸ ︷︷ ︸ = 1 + 1 ·2 by substitution

a2 = a1 + 2 = ︷ ︸︸ ︷ (1 + 2) + 2 = 1 + 2 ·2︸ ︷︷ ︸

a3 = a2 + 2 = ︷ ︸︸ ︷ (1 + 2 ·2)+ 2 = 1 + 3 ·2︸ ︷︷ ︸

a4 = a3 + 2 = ︷ ︸︸ ︷ (1 + 3 ·2)+ 2 = 1 + 4 ·2︸ ︷︷ ︸ At this point it certainly seems likely that

the general pattern is 1 + n ·2; check whether the next calculation supports this.

a5 = a4 + 2 = ︷ ︸︸ ︷ (1 + 4 ·2)+ 2 = 1 + 5 ·2 It does! So go ahead and write an answer.

It’s only a guess, after all. ...

Guess: an = 1 + n ·2 = 1 + 2n

The answer obtained for this problem is just a guess. To be sure of the correctness of this guess, you will need to check it by mathematical induction. Later in this section, we will show how to do this. ■

A sequence like the one in Example 5.7.1, in which each term equals the previous term plus a fixed constant, is called an arithmetic sequence. In the exercises at the end of this section you are asked to show that the nth term of an arithmetic sequence always equals the initial value of the sequence plus n times the fixed constant.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 307

• Definition A sequence a0, a1, a2, . . . is called an arithmetic sequence if, and only if, there is a constant d such that

ak = ak−1 + d for all integers k ≥ 1. It follows that,

an = a0 + dn for all integers n ≥ 0.

Example 5.7.2 An Arithmetic Sequence

Under the force of gravity, an object falling in a vacuum falls about 9.8 meters per second (m/sec) faster each second than it fell the second before. Thus, neglecting air resistance, a skydiver’s speed upon leaving an airplane is approximately 9.8 m/sec one second after departure, 9.8 + 9.8 = 19.6 m/sec two seconds after departure, and so forth. If air resis- tance is neglected, how fast would the skydiver be falling 60 seconds after leaving the airplane?

Solution Let sn be the skydiver’s speed in m/sec n seconds after exiting the airplane if there were no air resistance. Thus s0 is the initial speed, and since the diver would travel 9.8 m/sec faster each second than the second before,

sk = sk−1 + 9.8 m/sec for all integers k ≥ 1. It follows that s0, s1, s2, . . . is an arithmetic sequence with a fixed constant of 9.8, and thus

sn = s0 + (9.8)n for each integer n ≥ 0. Hence sixty seconds after exiting and neglecting air resistance, the skydiver would travel at a speed of

s60 = 0 + (9.8)(60) = 588 m/sec. Note that 588 m/sec is over half a kilometer per second or over a third of a mile per second, which is very fast for a human being to travel. Happily for the skydiver, taking air resistance into account cuts the speed considerably. ■

In an arithmetic sequence, each term equals the previous term plus a fixed constant. In a geometric sequence, each term equals the previous term times a fixed constant. Geomet- ric sequences arise in a large variety of applications, such as compound interest certain models of population growth, radioactive decay, and the number of operations needed to execute certain computer algorithms.

Example 5.7.3 The Explicit Formula for a Geometric Sequence

Let r be a fixed nonzero constant, and suppose a sequence a0, a1, a2, . . . is defined recursively as follows:

ak = rak−1 for all integers k ≥ 1, a0 = a.

Use iteration to guess an explicit formula for this sequence.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

308 Chapter 5 Sequences, Mathematical Induction, and Recursion

In the exercises at the end of this section, you are asked to prove that this formula is correct. ■

• Definition A sequence a0, a1, a2, . . . is called a geometric sequence if, and only if, there is a constant r such that

ak = rak−1 for all integers k ≥ 1. It follows that,

an = a0r ′′ for all integers n ≥ 0.

Example 5.7.4 A Geometric Sequence

As shown in Example 5.6.7, if a bank pays interest at a rate of 4% per year compounded annually and An denotes the amount in the account at the end of year n, then Ak = (1.04)Ak−1, for all integers k ≥ 1, assuming no deposits or withdrawals during the year. Suppose the initial amount deposited is $100,000, and assume that no additional deposits or withdrawals are made.

a. How much will the account be worth at the end of 21 years?

b. In how many years will the account be worth $1,000,000?

Solution

a. A0, A1, A2, . . . is a geometric sequence with initial value 100,000 and constant multiplier 1.04. Hence,

An = $100,000 ·(1.04)n for all integers n ≥ 0. After 21 years, the amount in the account will be

A21 = $100,000 ·(1.04)21 ∼= $227, 876.81. This is the same answer as that obtained in Example 5.6.7 but is computed much more easily (at least if a calculator with a powering key, such as ∧ or x y , is used).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 309

b. Let t be the number of years needed for the account to grow to $1,000,000. Then

$1,000,000 = $100,000 ·(1.04)t . Dividing both sides by 100,000 gives

10 = (1.04)t , and taking natural logarithms of both sides results in

ln(10) = ln(1.04)t .Note Properties of logarithms are reviewed in Section 7.2. Then

ln(10) ∼= t ln(1.04) because logb(x a) = a logb(x)

(see exercise 35 of Section 7.2)

and so

t = ln(10) ln(1.04)

∼= 58.7

Hence the account will grow to $1,000,000 in approximately 58.7 years. ■

An important property of a geometric sequence with constant multiplier greater than 1 is that its terms increase very rapidly in size as the subscripts get larger and larger. For instance, the first ten terms of a geometric sequence with a constant multiplier of 10 are

1, 10, 102, 103, 104, 105, 106, 107, 108, 109.

Thus, by its tenth term, the sequence already has the value 109 = 1,000,000,000 = 1 billion. The following box indicates some quantities that are approximately equal to cer- tain powers of 10.

107 ∼= number of seconds in a year 109 ∼= number of bytes of memory in a personal computer

1011 ∼= number of neurons in a human brain 1017 ∼= age of the universe in seconds (according to one theory) 1031 ∼= number of seconds to process all possible positions of a checkers game if

moves are processed at a rate of 1 per billionth of a second

1081 ∼= number of atoms in the universe 10111 ∼= number of seconds to process all possible positions of a chess game if moves

are processed at a rate of 1 per billionth of a second

Using Formulas to Simplify Solutions Obtained by Iteration Explicit formulas obtained by iteration can often be simplified by using formulas such as those developed in Section 5.2. For instance, according to the formula for the sum of a geometric sequence with initial term 1 (Theorem 5.2.3), for each real number r except r = 1,

1 + r + r2 + · · · + rn = r n+1 − 1 r − 1 for all integers n ≥ 0.

And according to the formula for the sum of the first n integers (Theorem 5.2.2),

1 + 2 + 3 + · · · + n = n(n + 1) 2

for all integers n ≥ 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

310 Chapter 5 Sequences, Mathematical Induction, and Recursion

Example 5.7.5 An Explicit Formula for the Tower of Hanoi Sequence

Recall that the Tower of Hanoi sequence m1, m2, m3, . . . of Example 5.6.5 satisfies the recurrence relation

mk = 2mk−1 + 1 for all integers k ≥ 2 and has the initial condition

m1 = 1. Use iteration to guess an explicit formula for this sequence, and make use of a formula from Section 5.2 to simplify the answer.

Solution By iteration

m1 = 1

m 2⃝ = 2m1 + 1 = 2 ·1 + 1 = 2 1⃝ + 1︸ ︷︷ ︸,

m 3⃝ = 2m2 + 1 = 2 ︷ ︸︸ ︷ (2 + 1) + 1 = 2 2⃝ + 2 + 1︸ ︷︷ ︸,

m 4⃝ = 2m3 + 1 = 2 ︷ ︸︸ ︷ (22 + 2 + 1) + 1 = 2 3⃝ + 22 + 2 + 1︸ ︷︷ ︸,

m 5⃝ = 2m4 + 1 = 2 ︷ ︸︸ ︷ (23 + 22 + 2 + 1) + 1 = 2 4⃝ + 23 + 22 + 2 + 1.

These calculations show that each term up to m5 is a sum of successive powers of 2, starting with 20 = 1 and going up to 2k , where k is 1 less than the subscript of the term. The pattern would seem to continue to higher terms because each term is obtained from the preceding one by multiplying by 2 and adding 1; multiplying by 2 raises the exponent of each component of the sum by 1, and adding 1 adds back the 1 that was lost when the previous 1 was multiplied by 2. For instance, for n = 6,

m6 = 2m5 + 1 = 2(24 + 23 + 22 + 2 + 1) + 1 = 25 + 24 + 23 + 22 + 2 + 1. Thus it seems that, in general,

mn = 2n−1 + 2n−2 + · · · + 22 + 2 + 1. By the formula for the sum of a geometric sequence (Theorem 5.2.3),

2n−1 + 2n−2 + · · · + 22 + 2 + 1 = 2 n − 1

2− 1 = 2 n − 1.

Hence the explicit formula seems to be

mn = 2n − 1 for all integers n ≥ 1. ■

! Caution! It is not true that

2 · (2 + 1) + 1 = 22 + 1 + 1. This is crossed out because it is false.

A common mistake people make when doing problems such as this is to misuse the laws of algebra. For instance, by the distributive law,

a ·(b + c) = a ·b + a ·c for all real numbers a, b, and c. Thus, in particular, for a = 2, b = 2, and c = 1,

2 ·(2 + 1) = 2 ·2 + 2 ·1 = 22 + 2. It follows that

2 ·(2 + 1) + 1 = (22 + 2) + 1 = 22 + 2 + 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 311

Example 5.7.6 Using the Formula for the Sum of the First n Positive Integers

Let Kn be the picture obtained by drawing n dots (which we call vertices) and join- ing each pair of vertices by a line segment (which we call an edge). (In Chapter 10 we discuss these objects in a more general context.) Then K1, K2, K3, and K4 are as follows:

K1 K2 K3 K4

Observe that K5 may be obtained from K4 by adding one vertex and drawing edges between this new vertex and all the vertices of K4 (the old vertices). The reason this procedure gives the correct result is that each pair of old vertices is already joined by an edge, and adding the new edges joins each pair of vertices consisting of an old one and the new one.

New vertex

K5

Thus the number of edges of K5 = 4 + the number of edges of K4.

By the same reasoning, for all integers k ≥ 2, the number of edges of Kk is k − 1 more than the number of edges of Kk−1. That is, if for each integer n ≥ 1

sn = the number of edges of Kn,

then sk = sk−1 + (k − 1) for all integers k ≥ 2. Note that s1, is the number of edges in K1, which is 0, and use iteration to find an explicit formula for s1, s2, s3, . . . .

Solution Because

sk = sk−1 + (k − 1) for all integers k ≥ 2 and

s 1⃝ = ✞✝☎✆0 → 1 − 1

then, in particular,

s 2⃝ = s1 + 1 = 0 + ✞✝☎✆1︸ ︷︷ ︸ , → 2 − 1

s 3⃝ = s2 + 2 = ︷ ︸︸ ︷ (0 + 1)+ 2 = 0 + 1 + ✞✝☎✆2︸ ︷︷ ︸ , → 3 − 1

s 4⃝ = s3 + 3 = ︷ ︸︸ ︷ (0 + 1 + 2)+ 3 = 0 + 1 + 2 + ✞✝☎✆3︸ ︷︷ ︸ , → 4 − 1

s 5⃝ = s4 + 4 = ︷ ︸︸ ︷ (0 + 1 + 2 + 3)+ 4 = 0 + 1 + 2 + 3 + ✞✝☎✆4 , → 5 − 1

...

Guess: s n⃝ = 0 + 1 + 2 + · · · + (n − 1) .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

312 Chapter 5 Sequences, Mathematical Induction, and Recursion

But by Theorem 5.2.2,

0 + 1 + 2 + 3 + · · · + (n − 1) = (n − 1)n 2

= n(n − 1) 2

.

Hence it appears that

sn = n(n − 1)

2 .

Checking the Correctness of a Formula by Mathematical Induction

As you can see from some of the previous examples, the process of solving a recurrence relation by iteration can involve complicated calculations. It is all too easy to make a mistake and come up with the wrong formula. That is why it is important to confirm your calculations by checking the correctness of your formula. The most common way to do this is to use mathematical induction.

Example 5.7.7 Using Mathematical Induction to Verify the Correctness of a Solution to a Recurrence Relation

In Example 5.6.5 we obtained a formula for the Tower of Hanoi sequence. Use mathematical induction to show that this formula is correct.

Solution What does it mean to show the correctness of a formula for a recursively defined sequence? Given a sequence of numbers that satisfies a certain recurrence relation and initial condition, your job is to show that each term of the sequence satisfies the proposed explicit formula. In this case, you need to prove the following statement:

If m1, m2, m3, . . . is the sequence defined by

mk = 2mk−1 + 1 for all integers k ≥ 2, and m1 = 1,

then mn = 2n − 1 for all integers n ≥ 1.

Proof of Correctness:

Let m1, m2, m3, . . . be the sequence defined by specifying that m1 = 1 and mk = 2mk+1 + 1 for all integers k ≥ 2, and let the property P(n) be the equation

mn = 2n − 1 ← P(n) We will use mathematical induction to prove that for all integers n ≥ 1, P(n) is true. Show that P(1) is true: To establish P(1), we must show that

m1 = 21 − 1. ← P(1) But the left-hand side of P(1) is

m1 = 1 by definition of m1, m2, m3, . . ., and the right-hand side of P(1) is

21 − 1 = 2− 1 = 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 313

Thus the two sides of P(1) equal the same quantity, and hence P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P (k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 1. That is:] Suppose that k is any integer with k ≥ 1 such that

mk = 2k − 1. ← P(k) inductive hypothesis

[We must show that P(k + 1) is true. That is:] We must show that

mk+1 = 2k+1 − 1. ← P(k + 1)

But the left-hand side of P(k + 1) is

mk+1 = 2m(k+1)−1 + 1 by definition of m1, m2, m3, . . . = 2mk + 1 = 2(2k − 1) + 1 by substitution from the inductive hypothesis = 2k+1 − 2 + 1 by the distributive law and the fact that 2 ·2k = 2k−1 = 2k+1 − 1 by basic algebra

which equals the right-hand side of P(k + 1). [Since the basis and inductive steps have been proved, it follows by mathematical induction that the given formula holds for all integers n ≥ 1.] ■

Discovering That an Explicit Formula Is Incorrect The following example shows how the process of trying to verify a formula by mathematical induction may reveal a mistake.

Example 5.7.8 Using Verification by Mathematical Induction to Find a Mistake

Let c0, c1, c2, . . . be the sequence defined as follows:

ck = 2ck−1 + k for all integers k ≥ 1, c0 = 1.

Suppose your calculations suggest that c0, c1, c2, . . . satisfies the following explicit formula:

cn = 2n + n for all integers n ≥ 0.

Is this formula correct?

Solution Start to prove the statement by mathematical induction and see what develops. The proposed formula passes the basis step of the inductive proof with no trouble, for on the one hand, c0 = 1 by definition and on the other hand, 20 + 0 = 1 + 0 = 1 also.

In the inductive step, you suppose

ck = 2k + k for some integer k ≥ 0 This is the inductive hypothesis.

and then you must show that

ck+1 = 2k+1 + (k + 1).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

314 Chapter 5 Sequences, Mathematical Induction, and Recursion

To do this, you start with ck+1, substitute from the recurrence relation, and then use the inductive hypothesis as follows:

ck+1= 2ck + (k + 1) by the recurrence relation = 2(2k + k) + (k + 1) by substitution from the inductive hypothesis = 2(k+1) + 3k + 1 by basic algebra

To finish the verification, therefore, you need to show that

2k+1 + 3k + 1 = 2k+1 + (k + 1). Now this equation is equivalent to

2k = 0 by subtracting 2k+1 + k + 1 from both sides. which is equivalent to

k = 0 by dividing both sides by 2. But this is false since k may be any nonnegative integer.

Observe that when k = 0, then k + 1 = 1, and c1 = 2 ·1 + 1 = 3 and 21 + 1 = 3.

Thus the formula gives the correct value for c1. However, when k = 1, then k + 1 = 2, and c2 = 2 ·3 + 2 = 8 whereas 22 + 2 = 4 + 2 = 6.

So the formula does not give the correct value for c2. Hence the sequence c0, c1, c2, . . . does not satisfy the proposed formula. ■

Once you have foud a proposed formula to be false, you should look back at your calculations to see where you made a mistake, correct it, and try again.

Test Yourself 1. To use iteration to find an explicit formula for a recursively

defined sequence, start with the _____ and use successive substitution into the _____ to look for a numerical pattern.

2. At every step of the iteration process, it is important to eliminate _____.

3. If a single number, say a, is added to itself k times in one of the steps of the iteration, replace the sum by the expression _____.

4. If a single number, say a, is multiplied by itself k times in one of the steps of the iteration, replace the product by the expression _____.

5. A general arithmetic sequence a0, a1, a2, . . . with initial value a0 and fixed constant d satisfies the recurrence rela- tion _____ and has the explicit formula _____.

6. A general geometric sequence a0, a1, a2, . . . with initial value a0 and fixed constant r satisfies the recurrence rela- tion _____ and has the explicit formula _____.

7. When an explicit formula for a recursively defined sequence has been obtained by iteration, its correctness can be checked by _____.

Exercise Set 5.7 1. The formula

1 + 2 + 3 + · · · + n = n(n + 1) 2

is true for all integers n ≥ 1. Use this fact to solve each of the following problems: a. If k is an integer and k ≥ 2, find a formula for the

expression 1 + 2 + 3 + · · · + (k − 1).

b. If n is an integer and n ≥ 1, find a formula for the expression 3 + 2 + 4 + 6 + 8 + · · · + 2n.

c. If n is an integer and n ≥ 1, find a formula for the expression 3 + 3 ·2 + 3 ·3 + · · · + 3 ·n + n.

2. The formula

1 + r + r2 + · · · + rn = r n+1 − 1 r − 1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solving Recurrence Relations by Iteration 315

is true for all real numbers r except r = 1 and for all inte- gers n ≥ 0. Use this fact to solve each of the following problems: a. If i is an integer and i ≥ 1, find a formula for the

expression 1 + 2 + 22 + · · · + 2i−1. b. If n is an integer and n ≥ 1, find a formula for the

expression 3n−1 + 3n−2 + · · · + 32 + 3 + 1. c. If n is an integer and n ≥ 2, find a formula for the expres-

sion 2n + 2n−2 ·3 + 2n−3 ·3 + · · · + 22 ·3 + 2 ·3 + 3 d. If n is an integer and n ≥ 1, find a formula for the

expression

2n − 2n−1 + 2n−2 − 2n−3 + · · · + (−1)n−1 ·2 + (−1)n .

In each of 3–15 a sequence is defined recursively. Use iteration to guess an explicit formula for the sequence. Use the formulas from Section 5.2 to simplify your answers whenever possible.

3. ak = kak−1, for all integers k ≥ 1 a0 = 1

4. bk = bk−1

1 + bk−1 , for all integers k ≥ 1

b0 = 1 5. ck = 3ck−1 + 1, for all integers k ≥ 2

c1 = 1 6.H dk = 2dk−1 + 3, for all integers k ≥ 2

dt = 2 7. ek = 4ek−1 + 5, for all integers k ≥ 1

e0 = 2 8. fk = fk−1 + 2k , for all integers k ≥ 2

f1 = 1

9.H gk = gk−1

gk−1 + 2 , for all integers k ≥ 2

g1 = 1 10. hk = 2k − hk−1, for all integers k ≥ 1

h0 = 1 11. pk = pk−1 + 2 ·3k

p1 = 2 12. sk = sk−1 + 2k, for all integers k ≥ 1

s0 = 3 13. tk = tk−1 + 3k + 1, for all integers k ≥ 1

t0 = 0 14.✶ xk = 3xk−1 + k, for all integers k ≥ 2

x1 = 1 15. yk = yk−1 + k2, for all integers k ≥ 2

y1 = 1 16. Solve the recurrence relation obtained as the answer to

exercise 18(c) of Section 5.6.

17. Solve the recurrence relation obtained as the answer to exercise 21(c) of Section 5.6.

18. Suppose d is a fixed constant and a0, a1, a2, . . . is a sequence that satisfies the recurrence relation ak = ak−1 + d , for all integers k ≥ 1. Use mathematical induction to prove that an = a0 + nd, for all integers n ≥ 0.

19. A worker is promised a bonus if he can increase his produc- tivity by 2 units a day every day for a period of 30 days. If on day 0 he produces 170 units, how many units must he produce on day 30 to qualify for the bonus?

20. A runner targets herself to improve her time on a certain course by 3 seconds a day. If on day 0 she runs the course in 3 minutes, how fast must she run it on day 14 to stay on target?

21. Suppose r is a fixed constant and a0, a1, a2 . . . is a sequence that satisfies the recurrence relation ak = rak−1, for all integers k ≥ 1 and a0 = a. Use mathematical induction to prove that an = arn , for all integers n ≥ 0.

22. As shown in Example 5.6.8, if a bank pays interest at a rate of i compounded m times a year, then the amount of money Pk at the end of k time periods (where one time period = 1/mth of a year) satisfies the recurrence relation Pk = [1 + (i/m)]Pk−1 with initial condition P0 = the initial amount deposited. Find an explicit formula for Pn .

23. Suppose the population of a country increases at a steady rate of 3% per year. If the population is 50 million at a certain time, what will it be 25 years later?

24. A chain letter works as follows: One person sends a copy of the letter to five friends, each of whom sends a copy to five friends, each of whom sends a copy to five friends, and so forth. How many people will have received copies of the let- ter after the twentieth repetition of this process, assuming no person receives more than one copy?

25. A certain computer algorithm executes twice as many oper- ations when it is run with an input of size k as when it is run with an input of size k − 1 (where k is an integer that is greater than 1). When the algorithm is run with an input of size 1, it executes seven operations. How many operations does it execute when it is run with an input of size 25?

26. A person saving for retirement makes an initial deposit of $1,000 to a bank account earning interest at a rate of 3% per year compounded monthly, and each month she adds an additional $200 to the account. a. For each nonnegative integer n, let An be the amount in

the account at the end of n months. Find a recurrence rela- tion relating Ak to Ak−1.

b.H Use iteration to find an explicit formula for An . c. Use mathematical induction to prove the correctness of

the formula you obtained in part (b). d. How much will the account be worth at the end of 20

years? At the end of 40 years? e.H In how many years will the account be worth $10,000?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

316 Chapter 5 Sequences, Mathematical Induction, and Recursion

27. A person borrows $3,000 on a bank credit card at a nominal rate of 18% per year, which is actually charged at a rate of 1.5% per month. a.H What is the annual percentage rate (APR) for the card?

(See Example 5.6.8 for a definition of APR.) b. Assume that the person does not place any additional

charges on the card and pays the bank $150 each month to pay off the loan. Let Bn be the balance owed on the card after n months. Find an explicit formula for Bn .

c.H How long will be required to pay off the debt? d. What is the total amount of money the person will have

paid for the loan?

In 28–42 use mathematical induction to verify the correctness of the formula you obtained in the referenced exercise.

28. Exercise 3 29. Exercise 4 30. Exercise 5

31. Exercise 6 32. Exercise 7 33. Exercise 8

34. Exercise 9 35.H Exercise 10 36. Exercise 11

37.H Exercise 12 38. Exercise 13 39. Exercise 14

40. Exercise 15 41. Exercise 16 42. Exercise 17

In each of 43–49 a sequence is defined recursively. (a) Use itera- tion to guess an explicit formula for the sequence. (b) Use strong mathematical induction to verify that the formula of part (a) is correct.

43. ak = ak−1

2ak−1 − 1 , for all integers k ≥ 1

a0 = 2

44. bk = 2

bk−1 , for all integers k ≥ 2

b1 = 1 45. vk = v⌊k/2⌋ + v⌊(k+1)/2⌋ + 2, for all integers k ≥ 2,

v1 = 1. 46.H sk = 2sk−2, for all integers k ≥ 2,

s0 = 1, s1 = 2. 47. tk = k − tk−1, for all integers k ≥ 1,

t0 = 0. 48.H wk = wk−2 + k, for all integers k ≥ 3,

w1 = 1, w2 = 2. 49.H uk = uk−2 ·uk−1, for all integers k ≥ 2,

u0 = u1 = 2. In 50 and 51 determine whether the given recursively defined sequence satisfies the explicit formula an = (n − 1)2, for all integers n ≥ 1.

50. ak = 2ak−1 + k − 1, for all integers k ≥ 2 a1 = 0

51. ak = (ak−1 + 1)2, for all integers k ≥ 2 a1 = 0

52. A single line divides a plane into two regions. Two lines (by crossing) can divide a plane into four regions; three lines can divide it into seven regions (see the figure). Let Pn be the maximum number of regions into which n lines divide a plane, where n is a positive integer.

Line 3

Line 2

Line 1

5 1 2

3 4

6

7

a. Derive a recurrence relation for Pk in terms of Pk−1, for all integers k ≥ 2.

b. Use iteration to guess an explicit formula for Pn .

53. Compute [

1 1 1 0

]n for small values of n (up to about 5 or 6).

Conjecture explicit formulas for the entries in this matrix, and prove your conjecture using mathematical induction.

54. In economics the behavior of an economy from one period to another is often modeled by recurrence relations. Let Yk be the income in period k and Ck be the consumption in period k. In one economic model, income in any period is assumed to be the sum of consumption in that period plus investment and government expenditures (which are assumed to be con- stant from period to period), and consumption in each period is assumed to be a linear function of the income of the pre- ceding period. That is,

Yk = Ck + E where E is the sum of investment plus government expenditures

Ck = c + mYk−1 where c and m are constants. Substituting the second equation into the first gives Yk = E + c + mYk−1. a. Use iteration on the above recurrence relation to obtain

Yn = (E + c) (

mn − 1 m − 1

) + mnY0

for all integers n≥1. b. (For students who have studied calculus) Show that if

0 < m < 1, then lim n→∞

Yn = E + c 1− m .

Answers for Test Yourself 1. initial conditions; recurrence relation 2. parentheses 3. k·a 4. ak 5. ak = ak−1 + d; an = a0 + dn 6. ak = rak−1; an = a0rn 7. mathematical induction

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 317

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients

Genius is 1% inspiration and 99% perspiration. — Thomas Alva Edison, 1932

In section 5.7 we discussed finding explicit formulas for recursively defined sequences using iteration. This is a basic technique that does not require any special tools beyond the ability to discern patterns. In many cases, however, a pattern is not readily discernible and other methods must be used. A variety of techniques are available for finding explicit formulas for special classes of recursively defined sequences. The method explained in this section is one that works for the Fibonacci and other similarly defined sequences.

• Definition A second-order linear homogeneous recurrence relation with constant coeffi- cients is a recurrence relation of the form

ak = Aak−1 + Bak−2 for all integers k ≥ some fixed integer, where A and B are fixed real numbers with B ̸= 0.

“Second-order” refers to the fact that the expression for ak contains the two previous terms ak−1 and ak−2, “linear” to the fact that ak−1 and ak−2 appear in separate terms and to the first power, “homogeneous” to the fact that the total degree of each term is the same (thus there is no constant term), and “constant coefficients” to the fact that A and B are fixed real numbers that do not depend on k.

Example 5.8.1 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients

State whether each of the following is a second-order linear homogeneous recurrence relation with constant coefficients:

a. ak = 3ak−1 + 2ak−2 b. bk = bk−1 + bk−2 + bk−3 c. ck = 12 ck−1 −

3 7 ck−2 d. dk = d2k−1 + dk−1 ·dk−2

e. ek = 2ek−2 f. fk = 2 fk−1 + 1 g. gk = gk−1 + gk−2 h. hk = (−1)hk−1 + (k − 1)hk−2

Solution

a. Yes; A = 3 and B = 2 b. No; not second-order

c. Yes; A = 12 and B = − 3 7

d. No; not linear

e. Yes; A = 0 and B = 2 f. No; not homogeneous

g. Yes; A = 1 and B = 1 h. No; nonconstant coefficients ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

318 Chapter 5 Sequences, Mathematical Induction, and Recursion

The Distinct-Roots Case Consider a second-order linear homogeneous recurrence relation with constant coefficients:

ak = Aak−1 + Bak−2 for all integers k ≥ 2, 5.8.1 where A and B are fixed real numbers. Relation (5.8.1) is satisfied when all the ai = 0, but it has nonzero solutions as well. Suppose that for some number t with t ̸= 0, the sequence

1, t, t2, t3, . . . , tn, . . .

satisfies relation (5.8.1). This means that each term of the sequence equals A times the previous term plus B times the term before that. So for all integers k ≥ 2,

t k = Atk−1 + Btk−2. In particular, when k = 2, the equation becomes

t2 = At + B, or, equivalently,

t2 − At − B = 0. 5.8.2 This is a quadratic equation, and the values of t that make it true can be found either by factoring or by using the quadratic formula.

Now work backward. Suppose t is any number that satisfies equation (5.8.2). Does the sequence 1, t, t2, t3, . . . , tn, . . . satisfy relation (5.8.1)? To answer this question, multiply equation (5.8.2) by t k−2 to obtain

t k−2· t2 − t k−2· At − t k−2· B = 0. This is equivalent to

t k − Atk−1 − Btk−2 = 0 or

t k = Atk−1 + Btk−2. Hence the answer is yes: 1, t, t2, t3, . . . , tn, . . . satisfies relation (5.8.1).

This discussion proves the following lemma.

Lemma 5.8.1

Let A and B be real numbers. A recurrence relation of the form

ak = Aak−1 + Bak−2 for all integers k ≥ 2 5.8.1 is satisfied by the sequence

1, t, t2, t3, . . . , tn, . . . ,

where t is a nonzero real number, if, and only if, t satisfies the equation

t2 − At − B = 0 5.8.2

Equation (5.8.2) is called the characteristic equation of the recurrence relation.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 319

• Definition Given a second-order linear homogeneous recurrence relation with constant coeffi- cients:

ak = Aak−1 + Bak−2 for all integers k ≥ 2, 5.8.1 the characteristic equation of the relation is

t2 − At − B = 0. 5.8.2

Example 5.8.2 Using the Characteristic Equation to Find Solutions to a Recurrence Relation

Consider the recurrence relation that specifies that the kth term of a sequence equals the sum of the (k − 1)st term plus twice the (k − 2)nd term. That is,

ak = ak−1 + 2ak−2 for all integers k ≥ 2. 5.8.3 Find all sequences that satisfy relation (5.8.3) and have the form

1, t, t2, t3, . . . , tn, . . . ,

where t is nonzero.

Solution By Lemma 5.8.1, relation (5.8.3) is satisfied by a sequence 1, t, t2, t3, . . . , tn, . . . if, and only if, t satisfies the characteristic equation

t2 − t − 2 = 0. Since

t2 − t − 2 = (t − 2)(t + 1), the only possible values of t are 2 and −1. It follows that the sequences

1, 2, 22, 23, . . . , 2n, . . . and 1, −1, (−1)2, (−1)3, . . . , (−1)n, . . . . are both solutions for relation (5.8.3) and there are no other solutions of this form. Note that these sequences can be rewritten more simply as

1, 2, 22, 23, . . . , 2n, . . . and 1, −1, 1,−1, . . . , (−1)n, . . . . ■

The example above shows how to find two distinct sequences that satisfy a given second-order linear homogeneous recurrence relation with constant coefficients. It turns out that any linear combination of such sequences produces another sequence that also satisfies the relation.

Lemma 5.8.2

If r0, r1, r2, . . . and s0, s1, s2, . . . are sequences that satisfy the same second-order linear homogeneous recurrence relation with constant coefficients, and if C and D are any numbers, then the sequence a0, a1, a2, . . . defined by the formula

an = Crn + Dsn for all integers n ≥ 0 also satisfies the same recurrence relation.

continued on page 320

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

320 Chapter 5 Sequences, Mathematical Induction, and Recursion

Proof: Suppose r0, r1, r2, . . . and s0, s1, s2, . . . are sequences that satisfy the same second-order linear homogeneous recurrence relation with constant coefficients. In other words, suppose that for some real numbers A and B,

rk = Ark−1 + Brk−2 and sk = Ask−1 + Bsk−2 5.8.4 for all integers k ≥ 2. Suppose also that C and D are any numbers. Let a0, a1, a2, . . . be the sequence defined by

an = Crn + Dsn for all integers n ≥ 0. 5.8.5 [We must show that a0, a1, a2, . . . satisfies the same recurrence relation as r0, r1, r2, . . . and s0, s1, s2, . . .. That is, we must show that ak = Aak−1 + Bak−2, for all integers] k ≥ 2. For all integers k ≥ 2,

Aak−1 + Bak−2 = A(Crk−1 + Dsk−1) + B(Crk−2 + Dsk−2) by substitutionfrom (5.8.5) = C(Ark−1 + Brk−2) + D(Ask−1 + Bsk−2) by basic algebra = Crk + Dsk by substitutionfrom (5.8.4) = ak by substitutionfrom (5.8.5)

Hence a0, a1, a2, . . . satisfies the same recurrence relation as r0, r1, r2, . . . and s0, s1, s2, . . . [as was to be shown].

Given a second-order linear homogeneous recurrence relation with constant coeffi- cients, if the characteristic equation has two distinct roots, then Lemmas 5.8.1 and 5.8.2 can be used together to find a particular sequence that satisfies both the recurrence relation and two specific initial conditions.

Example 5.8.3 Finding the Linear Combination That Satisfies the Initial Conditions

Find a sequence that satisfies the recurrence relation of Example 5.8.2,

ak = ak−1 + 2ak−2 for all integers k ≥ 2, 5.8.3 and that also satisfies the initial conditions

a0 = 1 and a1 = 8.

Solution Example 5.8.2, the sequences

1, 2, 22, 23, . . . , 2n, . . . and 1, −1, 1,−1, . . . , (−1)n, . . . both satisfy relation (5.8.3) (though neither satisfies the given initial conditions). By Lemma 5.8.2, therefore, any sequence a0, a1, a2, . . . that satisfies an explicit formula of the form

an = C ·2n + D(−1)n 5.8.6 where C and D are numbers, also satisfies relation (5.8.3). You can find C and D so that a0, a1, a2, . . . satisfies the specified initial conditions by substituting n = 0 and n = 1 into equation (5.8.6) and solving for C and D:

a0 = 1 = C ·20 + D(−1)0, a1 = 8 = C ·21 + D(−1)1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 321

When you simplify, you obtain the system

1 = C + D 8 = 2C − D,

which can be solved in various ways. For instance, if you add the two equations, you get

9 = 3C,

and so C = 3.

Then, by substituting into 1 = C + D, you get

D = −2.

It follows that the sequence a0, a1, a2, . . . given by

an = 3 ·2n + (−2)(−1)n = 3 ·2n − 2(−1)n,

for integers n ≥ 0, satisfies both the recurrence relation and the given initial conditions. ■

The techniques of Examples 5.8.2 and 5.8.3 can be used to find an explicit formula for any sequence that satisfies a second-order linear homogeneous recurrence relation with constant coefficients for which the characteristic equation has distinct roots, provided that the first two terms of the sequence are known. This is made precise in the next theorem.

Theorem 5.8.3 Distinct-Roots Theorem

Suppose a sequence a0, a1, a2, . . . satisfies a recurrence relation

ak = Aak−1 + Bak−2 5.8.1 for some real numbers A and B with B ̸= 0 and all integers k ≥ 2. If the character- istic equation

t2 − At − B = 0 5.8.2 has two distinct roots r and s, then a0, a1, a2, . . . is given by the explicit formula

an = Crn + Dsn, where C and D are the numbers whose values are determined by the values a0 and a1.

Note: To say “C and D are determined by the values of a0 and a1” means that C and D are the solutions to the system of simultaneous equations

a0 = Cr0 + Ds0 and a1 = Cr1 + Ds1,

or, equivalently,

a0 = C + D and a1 = Cr + Ds.

In exercise 19 at the end of this section you are asked to verify that this system always has a solution when r ̸= s.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

322 Chapter 5 Sequences, Mathematical Induction, and Recursion

Proof: Suppose that for some real numbers A and B, a sequence a0, a1, a2, . . . satis- fies the recurrence relation ak = Aak−1 + Bak−2, for all integers k ≥ 2, and suppose the characteristic equation t2 − At − B = 0 has two distinct roots r and s. We will show that

for all integers n ≥ 0, an = Crn + Dsn, where C and D are numbers such that

a0 = Cr0 + Ds0 and a1 = Cr1 + Ds1. Let P(n) be the equation

an = Crn + Dsn. ← P(n)

We use strong mathematical induction to prove that P(n) is true for all integers n ≥ 0. In the basis step, we prove that P(0) and P(1) are true. We do this because in the inductive step we need the equation to hold for n = 0 and n = 1 in order to prove that it holds for n = 2. Show that P(0) and P(1) are true: The truth of P(0) and P(1) is automatic because C and D are exactly those numbers that make the following equations true:

a0 = Cr0 + Ds0 and a1 = Cr1 + Ds1. Show that for all integers k ≥ 1, if P(i) is true for all integers i from 0 through k, then P(k + 1) is also true: Suppose that k ≥ 1 and for all integers i from 0 through k,

ai = Cri + Dsi . inductive hypothesis

We must show that

ak+1 = Crk+1 + Dsk+1. ← P(k + 1) Now by the inductive hypothesis,

ak = Crk + Dsk and ak−1 = Crk−1 + Dsk−1, so

ak+1 = Aak + Bak−1 by definition of a0, a1, a2, . . . = A(Crk + Dsk) + B(Crk−1 + Dsk−1) by inductive hypothesis = C(Ark + Brk−1) + D(Ask + Bsk−1) by combining like terms = Crk+1 + Dsk+1 by Lemma 5.8.1.

This is what was to be shown.

[The reason the last equality follows from Lemma 5.8.1 is that since r and s satisfy the characteristic equation (5.8.2), the sequences r0, r1, r2, . . . and s0, s1, s2, . . . satisfy the recurrence relation (5.8.1).]

Remark The t of Lemma 5.8.1 and the C and D of Lemma 5.8.2 and Theorem 5.8.3 are referred to simply as numbers. This is to allow for the possibility of complex as well as real number values. If both roots of the characteristic equation of the recurrence relation are real numbers, then C and D will be real. But if the roots are nonreal complex numbers, then C and D will be nonreal complex numbers.

The next example shows how to use the distinct-roots theorem to find an explicit formula for the Fibonacci sequence.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 323

Example 5.8.4 A Formula for the Fibonacci Sequence

The Fibonacci sequence F0, F1, F2, . . . satisfies the recurrence relation

Fk = Fk−1 + Fk−2 for all integers k ≥ 2 with initial conditions

F0 = F1 = 1. Find an explicit formula for this sequence.

Solution The Fibonacci sequence satisfies part of the hypothesis of the distinct-roots theorem since the Fibonacci relation is a second-order linear homogeneous recurrence relation with constant coefficients (A = 1 and B = 1). Is the second part of the hypothe- sis also satisfied? Does the characteristic equation

t2 − t − 1 = 0 have distinct roots? By the quadratic formula, the roots are

t = 1 ± √

1− 4(−1) 2

=

⎧ ⎪⎪⎨

⎪⎪⎩

1 + √

5 2

1− √

5 2

and so the answer is yes. It follows from the distinct-roots theorem that the Fibonacci sequence is given by the explicit formula

Fn = C (

1 + √

5 2

)n + D (

1− √

5 2

)n for all integers n ≥ 0, 5.8.7

where C and D are the numbers whose values are determined by the fact that F0 = F1 = 1. To find C and D, write

F0 = 1 = C (

1 + √

5 2

)0 + D (

1− √

5 2

)0 = C ·1 + D ·1 = C + D

and

F1 = 1 = C (

1 + √

5 2

)1 + D (

1− √

5 2

)1

= C (

1 + √

5 2

)

+ D (

1− √

5 2

)

Thus the problem is to find numbers C and D such that

C + D = 1 and

C

( 1 +

√ 5

2

)

+ D (

1− √

5 2

)

= 1.

This may look complicated, but in fact it is just a system of two equations in two unknowns. In exercise 7 at the end of this section, you are asked to show that

C = 1 + √

5

2 √

5 and D = −(1−

√ 5)

2 √

5 .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

324 Chapter 5 Sequences, Mathematical Induction, and Recursion

Substituting these values for C and D into formula (5.8.7) gives

Fn = (

1 + √

5

2 √

5

)( 1 +

√ 5

2

)n + ( −(1−

√ 5)

2 √

5

)( 1−

√ 5

2

)n ,

or, simplifying,

Fn = 1√ 5

( 1 +

√ 5

2

)n+1 − 1√

5

( 1−

√ 5

2

)n+1 5.8.8

for all integers n ≥ 0. Remarkably, even though the formula for Fn involves √

5, all of the values of the Fibonacci sequence are integers. ■

Note The numbers (1 +

√ 5)/2 and

(1− √

5)/2 are related to the golden ratio of Greek mathematics. See exercise 24 at the end of this section.

The Single-Root Case Consider again the recurrence relation

ak = Aak−1 + Bak−2 for all integers k ≥ 2, 5.8.1 where A and B are real numbers, but suppose now that the characteristic equation

t2 − At − B = 0 5.8.2 has a single real root r . By Lemma 5.8.1, one sequence that satisfies the recurrence relation is

1, r, r2, r3, . . . , rn, . . .

But another sequence that also satisfies the relation is

0, r, 2r2, 3r3, . . . , nrn, . . .

To see why this is so, observe that since r is the unique root of t2 − At − B = 0, the left-hand side of the equation can be factored as (t − r)2, and so

t2 − At − B = (t − r)2 = t2 = t2 − 2r t + r2. 5.8.9 Equating coefficients in equation (5.8.9) gives

A = 2r and B = −r2. 5.8.10 Let s0, s1, s2, . . . be the sequence defined by the formula

Sn = nrn for all integers n ≥ 0. Then

Ask−1 + Bsk−2 = A(k − 1)rk−1 + B(k − 2)rk−2 by definition = 2r(k − 1)rk−1 − r2(k − 2)rk−2 by substitution from 5.8.10 = 2(k − 1)rk − (k − 2)rk = (2k − 2− k + 2)rk = krk by basic algebra = sk by definition.

Thus s0, s1, s2, . . . satisfies the recurrence relation. This argument proves the follow- ing lemma.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 325

Lemma 5.8.4

Let A and B be real numbers and suppose the characteristic equation

t2 − At − B = 0 has a single root r . Then the sequences 1, r1, r2, r3, . . . , rn, . . . and 0, r, 2r2, 3r3, . . . , nrn, . . . both satisfy the recurrence relation

ak = Aak−1 + Bak−2 for all integers k ≥ 2.

Lemmas 5.8.2 and 5.8.4 can be used to establish the single-root theorem, which tells how to find an explicit formula for any recursively defined sequence satisfying a second- order linear homogeneous recurrence relation with constant coefficients for which the characteristic equation has just one root. Taken together, the distinct-roots and single-root theorems cover all second-order linear homogeneous recurrence relations with constant coefficients. The proof of the single-root theorem is very similar to that of the distinct- roots theorem and is left as an exercise.

Theorem 5.8.5 Single-Root Theorem

Suppose a sequence a0, a1, a2, . . . satisfies a recurrence relation

ak = Aak−1 + Bak−2 for some real numbers A and B with B ̸= 0 and for all integers k ≥ 2. If the char- acteristic equation t2 − At − B = 0 has a single (real) root r , then a0, a1, a2, . . . is given by the explicit formula

an = Crn + Dnrn, where C and D are the real numbers whose values are determined by the values of a0 and any other known value of the sequence.

Example 5.8.5 Single-Root Case

Suppose a sequence b0, b1, b2, . . . satisfies the recurrence relation

bk = 4bk−1 − 4bk−2 for all integers k ≥ 2, 5.8.11

with initial conditions

b0 = 1 and b1 = 3.

Find an explicit formula for b0, b1, b2, . . ..

Solution This sequence satisfies part of the hypothesis of the single-root theorem because it satisfies a second-order linear homogeneous recurrence relation with constant coefficients (A = 4 and B = −4). The single-root condition is also met because the characteristic equation

t2 − 4t + 4 = 0

has the unique root r = 2 [since t2 − 4t + 4 = (t − 2)2].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

326 Chapter 5 Sequences, Mathematical Induction, and Recursion

It follows from the single-root theorem that b0, b1, b2, . . . is given by the explicit formula

bn = C ·2n + Dn2n for all integers n ≥ 0, 5.8.12 where C and D are the real numbers whose values are determined by the fact that b0 = 1 and b1 = 3. To find C and D, write

b0 = 1 = C ·20 + D ·0 ·20 = C and b1 = 3 = C ·21 + D ·1 ·21 = 2C + 2D. Hence the problem is to find numbers C and D such that

C = 1 and 2C + 2D = 3. Substitute C = 1 into the second equation to obtain

2 + 2D = 3, and so D =

1 2 .

Now substitute C = 1 and D = 12 into formula (5.8.12) to conclude that

bn = 2n + 1 2

n2n = 2n (

1 + n 2

) for all integers n ≥ 0. ■

Test Yourself 1. A second-order linear homogeneous recurrence relation

with constant coefficients is a recurrence relation of the form _____ for all integers k ≥ _____, where _____.

2. Given a recurrence relation of the form ak = Aak−1 + Bak−2 for all integers k ≥ 2, the characteristic equation of the relation is _____.

3. If a sequence a1, a2, a3, . . . is defined by a second-order lin- ear homogeneous recurrence relation with constant coeffi-

cients and the characteristic equation for the relation has two distinct roots r and s (which could be complex num- bers), then the sequence is given by an explicit formula of the form _____.

4. If a sequence a1, a2, a3, . . . is defined by a second-order lin- ear homogeneous recurrence relation with constant coeffi- cients and the characteristic equation for the relation has only a single root r , then the sequence is given by an explicit formula of the form _____.

Exercise Set 5.8 1. Which of the following are second-order linear homoge-

neous recurrence relations with constant coefficients? a. ak = 2ak−1 − 5ak−2 b. bk = kbk−1 + bk−2 c. ck = 3ck−1 ·c2k−2 d. dk = 3dk−1 + dk−2 e. rk = rk−1 − rk−2 − 2 f. sk = 10sk−2

2. Which of the following are second-order linear homoge- neous recurrence relations with constant coefficients? a. ak = (k − 1)ak−1 + 2kak−2 b. bk = −bk−1 + 7bk−2 c. ck = 3ck−1 + 1 d. dk = 3d2k−1 + dk−2 e. rk = rk−1 − 6rk−3 f. sk = sk−1 + 10sk−2

3. Let a0, a1, a2, . . . be the sequence defined by the explicit formula

an = C ·2n + D for all integers n ≥ 0, where C and D are real numbers. a. Find C and D so that a0 = 1 and a1 = 3. What is a2 in

this case? b. Find C and D so that a0 = 0 and a1 = 2. What is a2 in

this case?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Second-Order Linear Homogeneous Recurrence Relations with Constant Coefficients 327

4. Let b0, b1, b2, . . . be the sequence defined by the explicit formula

bn = C ·3n + D(−2)n for all integers n ≥ 0, where C and D are real numbers. a. Find C and D so that b0 = 0 and b1 = 5. What is b2 in

this case? b. Find C and D so that b0 = 3 and b1 = 4. What is b2 in

this case?

5. Let a0, a1, a2, . . . be the sequence defined by the explicit formula

an = C ·2n + D for all integers n ≥ 0, where C and D are real numbers. Show that for any choice of C and D,

ak = 3ak−1 − 2ak−2 for all integers k ≥ 2. 6. Let b0, b1, b2, . . . be the sequence defined by the explicit

formula

bn = C ·3n + D(−2)n for all integers n ≥ 0, where C and D are real numbers. Show that for any choice of C and D,

bk = bk−1 + 6bk−2 for all integers k ≥ 2. 7. Solve the system of equations in Example 5.8.4 to obtain

C = 1 + √

5

2 √

5 and D = −(1−

√ 5)

2 √

5 .

In each of 8–10: (a) suppose a sequence of the form 1.t.t2.t3 . . . tn . . . where t ̸= 0, satisfies the given recurrence relation (but not necessarily the initial conditions), and find all possible values of t : (b) suppose a sequence satisfies the given initial conditions as well as the recurrence relation, and find an explicit formula for the sequence.

8. ak = 2ak−1 + 3ak−2, for all integers k ≥ 2 a0 = 1, a1 = 2

9. bk = 7bk−1 − 10bk−2, for all integers k ≥ 2 b0 = 2, b1 = 2

10. ck = ck−1 + 6ck−2, for all integers k ≥ 2 c0 = 0, c1 = 3

In each of 11–16 suppose a sequence satisfies the given recur- rence relation and initial conditions. Find an explicit formula for the sequence.

11. dk = 4dk−2, for all integers k ≥ 2 d0 = 1, d1 = −1

12. ek = 9ek−2, for all integers k ≥ 2 e0 = 0, e1 = 2

13. rk = 2rk−1 − rk−2, for all integers k ≥ 2 r0 = 1, r1 = 4

14. sk = −4sk−1 − 4sk−2, for all integers k ≥ 2 s0 = 0, s1 = −1

15. tk = 6tk−1 − 9tk−2, for all integers k ≥ 2 t0 = 1, t1 = 3

16.H sk = 2sk−1 + 2sk−2, for all integers k ≥ 2 s0 = 1, s1 = 3

17. Find an explicit formula for the sequence of exercise 39 in Section 5.6

18. Suppose that the sequences s0, s1, s2, . . . and t0, t1, t2, . . . both satisfy the same second-order linear homogeneous recurrence relation with constant coefficients:

sk = 5sk−1 − 4sk−2 for all integers k ≥ 2, tk = 5tk−1 − 4tk−2 for all integers k ≥ 2.

Show that the sequence 2s0 + 3t0, 2s1 + 3t1, 2s2 + 3t2, . . . also satisfies the same relation. In other words, show that

2sk + 3tk = 5(2sk−1 + 3tk−1)− 4(2sk−2 + 3tk−2)

for all integers k ≥ 2. Do not use Lemma 5.8.2. 19. Show that if r, s, a0, and a1 are numbers with r ̸= s, then

there exist unique numbers C and D so that

C + D = a0 Cr + Ds = a1.

20. Show that if r is a nonzero real number, k and m are dis- tinct integers, and ak and am are any real numbers, then there exist unique real numbers C and D so that

Crk + k Drk = ak Crm + l Drm = am .

21.H Prove Theorem 5.8.5 for the case where the values of C and D are determined by a0 and a1.

Exercises 22 and 23 are intended for students who are familiar with complex numbers.

22. Find an explicit formula for a sequence a0, a1, a2, . . . that satisfies

ak = 2ak−1 − 2ak−2 for all integers k ≥ 2 with initial conditions a0 = 1 and a1 = 2.

23. Find an explicit formula for a sequence b0, b1, b2, . . . that satisfies

bk = 2bk−1 − 5bk−2 for all integers k ≥ 2 with initial conditions b0 = 1 and b1 = 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

328 Chapter 5 Sequences, Mathematical Induction, and Recursion

24. The numbers 1 +

√ 5

2 and

1− √

5 2

that appear in the

explicit formula for the Fibonacci sequence are related to a quantity called the golden ratio in Greek mathematics. Consider a rectangle of length φ units and height 1, where φ > 1.

1

1

– 1

Divide the rectangle into a rectangle and a square as shown in the preceding diagram. The square is 1 unit on each side, and the rectangle has sides of lengths 1 and φ − 1.

The ancient Greeks considered the outer rectangle to be perfectly proportioned (saying that the lengths of its sides were in a golden ratio to each other) if the ratio of the length to the width of the outer rectangle equaled the ratio of the length to the width of the inner rectangle. That is,

φ

1 = 1

φ − 1 .

a. Show that φ satisfies the following quadratic equation: t2 − t − 1 = 0.

b. Find the two solutions of t2 − t − 1 = 0 and call them φ1 and φ2.

c. Express the explicit formula for the Fibonacci sequence in terms of φ1 and φ2.

Answers for Test Yourself 1. ak = Aak−1 + Bak−2; 2; A and B are fixed real numbers with B ̸= 0 2. t2 − At − B = 0 3. an = Crn + Dsn , where C and D are real or complex numbers 4. an = Crn + Dnrn , where C and D are real numbers

5.9 General Recursive Definitions and Structural Induction

GENTE: Oh, aren’t you acquainted with recursive acronyms? I thought everybody knew about them. You see, “GOD” stands for “GOD Over Djinn”—which can be expanded as “GOD Over Djinn, Over Djinn”—and that can, in turn, be expanded to “GOD Over Djinn, Over Djinn, Over Djinn”—which can, in its turn, be further expanded.. . . You can go as far as you like. ACHILLES: But I’ll never finish! GENIE: Of course not. You can never totally expand GOD. —Douglas Hofstadter, Gödel, Escher, Bach, 1979

Sequences of numbers are not the only objects that can be defined recursively. In this sec- tion we discuss recursive definitions for sets and functions. We also introduce structural induction, which is a version of mathematical induction that is used to prove properties of recursively defined sets.

Recursively Defined Sets To define a set of objects recursively, you identify a few core objects as belonging to the set and give rules showing how to build new set elements from old. More formally, a recursive definition for a set consists of the following three components:

I. BASE: A statement that certain objects belong to the set.

II. RECURSION: A collection of rules indicating how to form new set objects from those already known to be in the set.

III. RESTRICTION: A statement that no objects belong to the set other than those com- ing from I and II.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.9 General Recursive Definitions and Structural Induction 329

Note An example of “legal” expression is p ∧ (q∨ ∼r), and an example of an “illegal” one is ∧ ∼pqr∨.

Example 5.9.1 Recursive Definition of Boolean Expressions

The set of Boolean expressions was introduced in Section 2.4 as “legal” expressions involving letters from the alphabet such as p, q, and r , and the symbols ∧, ∨, and ∼. To make precise which expressions are legal, the set of Boolean expressions over a general alphabet is defined recursively.

I. BASE: Each symbol of the alphabet is a Boolean expression.

II. RECURSION: If P and Q are Boolean expressions, then so are

(a) (P ∧ Q) and (b) (P ∨ Q) and (c) ∼P. III. RESTRICTION: There are no Boolean expressions over the alphabet other than

those obtained from I and II.

Derive the fact that the following is a Boolean expression over the English alphabet {a, b, c, . . . , x, y, z}:

(∼(p ∧ q) ∨ (∼r ∧ p)).

Solution (1) By I, p, q , and r are Boolean expressions.

(2) By (1) and II(a) and (c), (p ∧ q) and ∼r are Boolean expressions. (3) By (2) and II(c) and (a), ∼(p ∧ q) and (∼r ∧ p) are Boolean expressions. (4) By (3) and II(b), (∼(p ∧ q) ∨ (∼r ∧ p)) is a Boolean expression. ■

• Definition Let S be a finite set with at least one element. A string over S is a finite sequence of elements from S. The elements of S are called characters of the string, and the length of a string is the number of characters it contains. The null string over S is defined to be the “string” with no characters. It is usually denoted ϵ and is said to have length 0.

Example 5.9.2 The Set of Strings over an Alphabet

Consider the set S of all strings in a’s and b’s. S is defined recursively as follows:

I. BASE: ϵ is in S, where ϵ is the null string.

II. RECURSION: If s ∈ S, then (a) sa ∈ S and (b) sb ∈ S,

where sa and sb are the concatenations of s with a and b respectively.

III. RESTRICTION: Nothing is in S other than objects defined in I and II above. Derive the fact that ab ∈ S.

Solution (1) By I, ϵ ∈ S. (2) By (1) and II(a), ϵa ∈ S. But ϵa is the concatenation of the null string and a,

which equals a. So a ∈ S. (3) By (2) and II(b), ab ∈ S. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

330 Chapter 5 Sequences, Mathematical Induction, and Recursion

Example 5.9.3 Sets of Strings with Certain Properties

In Gödel, Escher, Bach, Douglas Hofstadter introduces the following recursively defined set of strings of M’s, I ’s, and U ’s, which he calls the M I U-system.∗

I. BASE: M I is in the M I U-system.

II. RECURSION:

a. If x I is in the M I U-system, where x is a string, then x I U is in the M I U-system. (In other words, you can add a U to any string that ends in I . For example, since M I is in the system, so is M I U.)

b. If M x is in the M I U-system, where x is a string, then M x x is in the M I U- system. (In other words, you can repeat all the characters in a string that follow an initial M . For example, if M U I is in the system, so is M U I U I.)

c. If x I I I y is in the M I U-system, where x and y are strings (possibly null), then x U y is also in the M I U-system. (In other words, you can replace I I I by U . For example, if M I I I I is in the system, so are M I U and M U I.)

d. If x U U y is in the M I U-system, where x and y are strings (possibly null), then x U y is also in the M I U-system. (In other words, you can replace U U by U . For example, if M I I U U is in the system, so is M I I U.)

III. RESTRICTION: No strings other than those derived from I and II are in the M I U- system.

Derive the fact that M U I U is in the M I U-system.

Solution (1) By I, M I is in the M I U-system.

(2) By (1) and II(b), M I I is in the M I U-system.

(3) By (2) and II(b), M I I I I is in the M I U-system.

(4) By (3) and II(c), M U I is in the M I U-system.

(5) By (4) and II(a), M U I U is in the M I U-system. ■

Example 5.9.4 Parenthesis Structures

Certain configurations of parentheses in algebraic expressions are “legal” [such as(())() and()()()], whereas others are not [such as)())) and()))(((]. Here is a recursive definition to generate the set P of legal configurations of parentheses.

I. BASE: () is in P.

II. RECURSION:

a. If E is in P , so is (E).

b. If E and F are in P , so is EF.

III. RESTRICTION: No configurations of parentheses are in P other than those derived from I and II above.

Derive the fact that (())() is in P .

Solution (1) By I, () is in P .

(2) By (1) and II(a), (()) is in P .

(3) By (2), (1), and II(b), (())() is in P . ■

∗Douglas Hofstadter, Gödel, Escher, Bach (New York: Basic Books), pp. 33–35.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.9 General Recursive Definitions and Structural Induction 331

Proving Properties about Recursively Defined Sets When a set has been defined recursively, a version of mathematical induction, called structural induction, can be used to prove that every object in the set satisfies a given property.

Structural Introduction for Recursively Defined Sets

Let S be a set that has been defined recursively, and consider a property that objects in S may or may not satisfy. To prove that every object in S satisfies the property:

1. Show that each object in the BASE for S satisfies the property;

2. Show that for each rule in the RECURSION, if the rule is applied to objects in S that satisfy the property, then the objects defined by the rule also satisfy the property.

Because no objects other than those obtained through the BASE and RECURSION conditions are contained in S, it must be the case that every object in S satisfies the property.

Example 5.9.5 A Property of the Set of Parenthesis Structures

Consider the set P of all grammatical configurations of parentheses defined in Example 5.9.4. Prove that every configuration in P contains an equal number of left and right parentheses.

Solution

Proof (by structural induction): Given any parenthesis configuration, let the property be the claim that it has an equal number of left and right parentheses.

Show that each object in the BASE for P satisfies the property: The only object in the base for P is (), which has one left parenthesis and one right parenthesis, so it has an equal number of left and right parentheses.

Show that for each rule in the RECURSION for P, if the rule is applied to an object in P that satisfies the property, then the object defined by the rule also satisfies the property: The recursion for P consists of two rules denoted II(a) and II(b).

Suppose E is a parenthesis configuration that has an equal number of left and right parentheses. When rule II(a) is applied to E , the result is (E), so both the number of left parentheses and the number of right parentheses are increased by one. Since these numbers were equal to start with, they remain equal when each is increased by one.

Suppose E and F are parenthesis configurations with equal numbers of left and right parentheses. Say E has m left and right parentheses, and F has n left and right paren- theses. When rule II(b) is applied, the result is E F , which has an equal number, namely m + n, of left and right parentheses.

Thus when each rule in the RECURSION is applied to a configuration of parentheses in P with an equal number of left and right parentheses, the result is a configuration with an equal number of left and right parentheses.

Therefore, every structure in P has an equal number of left and right parentheses. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

332 Chapter 5 Sequences, Mathematical Induction, and Recursion

Recursive Functions A function is said to be defined recursively or to be a recursive function if its rule of definition refers to itself. Because of this self-reference, it is sometimes difficult to tell whether a given recursive function is well defined. Recursive functions are of great importance in the theory of computation in computer science.

Example 5.9.6 McCarthy’s 91 Function

The following function M : Z+ → Z was defined by John McCarthy, a pioneer in the theory of computation and in the study of artificial intelligence:

M(n) = {

n − 10 if n > 100 M(M(n + 11)) if n ≤ 100

for all positive integers n. Find M(99).

R og

er R

es sm

ey er

/C O

R B

IS

John McCarthy (born 1927)

Solution By repeated use of the definition of M ,

M(99) = M(M(110)) since 99 ≤ 100 = M(100) since 110 > 100 = M(M(111)) since 100 ≤ 100 = M(101) since 111 > 100 = 91 since 101 > 100

The remarkable thing about this function is that it takes the value 91 for all positive integers less than or equal to 101. (You are asked to show this in exercise 20 at the end of this section.) Of course, for n > 101, M(n) is well defined because it equals n − 10. ■

Example 5.9.7 The Ackermann Function

In the 1920s the German logician and mathematician Wilhelm Ackermann first defined a version of the function that now bears his name. This function is important in com- puter science because it helps answer the question of what can and what cannot be computed on a computer. It is defined on the set of all pairs of nonnegative integers as follows:

A(0, n) = n + 1 for all nonnegative integers n 5.9.1 A(m, 0) = A(m − 1, 1) for all positive integers m 5.9.2 A(m, n) = A(m − 1, A(m, n − 1)) for all positive integers m and n 5.9.3

Find A(1, 2). Wilhelm Ackermann (1896–1962) Solution

A(1, 2) = A(0, A(1, 1)) by (5.9.3) with m = 1 and n = 2 = A(0, A(0, A(1, 0))) by (5.9.3) with m = 1 and n = 1 = A(0, A(0, A(0, 1))) by (5.9.2) with m = 1 = A(0, A(0, 2)) by (5.9.1) with n = 1 = A(0, 3) by (5.9.1) with n = 2 = 4 by (5.9.1) with n = 3.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.9 General Recursive Definitions and Structural Induction 333

The special properties of the Ackermann function are a consequence of its phenomenal rate of growth. While the values of A(0, 0) = 1, A(1, 1) = 3, A(2, 2) = 7, and A(3, 3) = 61 are not especially impressive,

A(4, 4) ∼= 222 65536

and the values of A(n, n) continue to increase with extraordinary rapidity thereafter. ■

The argument is somewhat technical, but it is not difficult to show that the Ackermann function is well defined. The following is an example of a recursive “definition” that does not define a function.

Example 5.9.8 A Recursive “Function” That Is Not Well Defined

Consider the following attempt to define a recursive function G from Z+ to Z. For all integers n ≥ 1,

G(n) =

⎧ ⎪⎪⎨

⎪⎪⎩

1 if n is 1

1 + G (n

2

) if n is even

G(3n − 1) if n is odd and n > 1. Is G well defined? Why?

Solution Suppose G is a function. Then by definition of G,

G(1) = 1, G(2) = 1 + G(1) = 1 + 1 = 2, G(3) = G(8) = 1 + G(4) = 1 + (1 + G(2)) = 1 + (1 + 2) = 4, G(4) = 1 + G(2) = 1 + 2 = 3.

However, G(5) = G(14) = 1 + G(7) = 1 + G(20)

= 1 + (1 + G(10)) = 1 + (1 + (1 + G(5))) = 3 + G(5). Subtracting G(5) from both sides gives 0 = 3, which is false. Since the supposition that G is a function leads logically to a false statement, it follows that G is not a function. ■

A slight modification of the formula of Example 5.9.8 produces a “function” whose status of definition is unknown. Consider the following formula: For all integers n ≥ 1,

T (n) =

⎧ ⎪⎪⎨

⎪⎪⎩

1 if n is 1

T (n

2

) if n is even

T (3n + 1) if n is odd.

In the 1930s, a student, Luther Collatz, became interested in the behavior of a related function g, which is defined as follows: g(n) = n/2 if n is even, and g(n) = 3n + 1 if n is odd. Collatz conjectured that for any initial positive number n, computation of suc- cessive values of g(n), g2(n), g3(n), . . . would eventually produce the number 1. Deter- mining whether this conjecture is true or false is called the 3n + 1 problem (or the 3x + 1 problem). If Collatz’s conjecture is true, the formula for T defines a function; if the conjecture is false, T is not well defined. As of the publication of this book the answer is not known, although computer calculation has established that it holds for extremely large values of n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

334 Chapter 5 Sequences, Mathematical Induction, and Recursion

Test Yourself 1. The BASE for a recursive definition of a set is _____.

2. The RECURSION for a recursive definition of a set is _____.

3. The RESTRICTION for a recursive definition of a set is _____.

4. One way to show that a given element is in a recursively defined set is to start with an element or elements in the _____ and apply the rules from the _____ until you obtain the given element.

5. Another way to show that a given element is in a recursively defined set is to use _____ to characterize all the elements of the set and then observe that the given element satisfies the characterization.

6. To prove that every element in a recursively defined set S satisfies a certain property, you show that _____ and that, for each rule in the RECURSION, if _____ then _____.

7. A function is said to be defined recursively if, and only if, _____.

Exercise Set 5.9 1. Consider the set of Boolean expressions defined in Exam-

ple 5.9.1. Give derivations showing that each of the fol- lowing is a Boolean expression over the English alphabet {a, b, c, . . . , x, y, z}. a. (∼p ∨ (q ∧ (r∨ ∼s))) b. ((p ∨ q)∨ ∼((p∧ ∼s) ∧ r))

2. Let S be defined as in Example 5.9.2. Give derivations showing that each of the following is in S. a. aab b. bb

3. Consider the M I U-system discussed in Example 5.9.3. Give derivations showing that each of the following is in the M I U-system. a. M I U I b. M U I I U

4. The set of arithmetic expressions over the real numbers can be defined recursively as follows:

I. BASE: Each real number r is an arithmetic expression. II. RECURSION: If u and v are arithmetic expressions,

then the following are also arithmetic expressions: a. (+u) b. (−u) c. (u + v) d. (u − v) e. (u ·v) f.

(u v

)

III. RESTRICTION: There are no arithmetic expressions over the real numbers other than those obtained from I and II.

(Note that the expression (u

v

) is legal even though the

value of v may be 0.) Give derivations showing that each of the following is an arithmetic expression.

a. ((2 ·(0.3–4.2)) + (−7)) b. (

(9 ·(6.1 + 2)) ((4–7) ·6)

)

5. Define a set S recursively as follows: I. BASE: 1 ∈ S

II. RECURSION: If s ∈ S, then a. 0s ∈ S b. 1s ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every string in S ends in a 1.

6. Define a set S recursively as follows: I. BASE: a ∈ S

II. RECURSION: If s ∈ S, then, a. sa ∈ S b. sb ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every string in S begins with an a.

7. Define a set S recursively as follows: I. BASE: ϵ ∈ S

II. RECURSION: If s ∈ S, then a. bs ∈ S b. sb ∈ S c. saa ∈ S d. aas ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every string in S con- tains an even number of a’s.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.9 General Recursive Definitions and Structural Induction 335

8. Define a set S recursively as follows: I. BASE: 1 ∈ S, 2 ∈ S, 3 ∈ S, 4 ∈ S, 5 ∈ S, 6 ∈

S, 7 ∈ S, 8 ∈ S, 9 ∈ S II. RECURSION: If s ∈ S and t ∈ S, then

a. s0 ∈ S b. st ∈ S III. RESTRICTION: Nothing is in S other than objects

defined in I and II above. Use structural induction to prove that no string in S repre- sents an integer with a leading zero.

9.H Define a set S recursively as follows: I. BASE: 1 ∈ S, 3 ∈ S, 5 ∈ S, 7 ∈ S, 9 ∈ S

II. RECURSION: If s ∈ S and t ∈ S then a. st ∈ S b. 2s ∈ S c. 4s ∈ S d. 6s ∈ S e. 8s ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every string in S rep- resents an odd integer.

10.H Define a set S recursively as follows: I. BASE: 0 ∈ S, 5 ∈ S

II. RECURSION: If s ∈ S and t ∈ S then a. s + t ∈ S b. s − t ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every integer in S is divisible by 5.

11. Define a set S recursively as follows: I. BASE: 0 ∈ S

II. RECURSION: If s ∈ S, then a. s + 3 ∈ S b. s − 3 ∈ S

III. RESTRICTION: Nothing is in S other than objects defined in I and II above.

Use structural induction to prove that every integer in S is divisible by 3.

12.✶H Is the string M U in the M I U-system? Use structural induc- tion to prove your answer.

13. Consider the set P of parenthesis structures defined in Example 5.9.4. Give derivations showing that each of the following is in P . a. ()(()) b. (())(())

14.✶ Determine whether either of the following parenthesis structures is in the set P defined in Example 5.9.4. Use structural induction to prove your answers. a. ()(() b. (()()))(()

15. Give a recursive definition for the set of all strings of 0’s and 1’s that have the same number of 0’s as 1’s.

16. Give a recursive definition for the set of all strings of 0’s and 1’s for which all the 0’s precede all the 1’s.

17. Give a recursive definition for the set of all strings of a’s and b’s that contain an odd number of a’s.

18. Give a recursive definition for the set of all strings of a’s and b’s that contain exactly one a.

19. Use the definition of McCarthy’s 91 function in Example 5.9.6 to show the following: a. M(86) = M(91) b. M(91) = 91

20.✶ Prove that McCarthy’s 91 function equals 91 for all positive integers less than or equal to 101.

21. Use the definition of the Ackermann function in Example 5.9.7 to compute the following: a. A(1, 1) b. A(2, 1)

22. Use the definition of the Ackermann function to show the following: a. A(1, n) = n + 2, for all nonnegative integers n. b. A(2, n) = 3 + 2n, for all nonnegative integers n. c. A(3, n) = 8 ·2n − 3, for all nonnegative integers n.

23. Compute T (2), T (3), T (4), T (5), T (6), and T (7) for the “function” T defined after Example 5.9.8.

24. Student A tries to define a function F : Z+ → Z by the rule

F(n) =

⎧ ⎪⎪⎨

⎪⎪⎩

1 if n is 1

F (n

2

) if n is even

1 + F(5n − 9) if n is odd and n > 1 for all integers n ≥ 1. Student B claims that F is not well defined. Justify student B’s claim.

25. Student C tries to define a function G : Z+ → Z by the rule

G(n) =

⎧ ⎪⎪⎨

⎪⎪⎩

1 if n is 1

G (n

2

) if n is even

2 + G(3n − 5) if n is odd and n > 1 for all integers n ≥ 1. Student D claims that G is not well defined. Justify student D’s claim.

Answers for Test Yourself 1. a statement that certain objects belong to the set 2. a collection of rules indicating how to form new set objects from those already known to be in the set 3. a statement that no objects belong to the set other than those coming from either the BASE or the RECURSION 4. BASE; RECURSION 5. structural induction 6. each object in the BASE satisfies the property; the rule is applied to objects in the BASE; the objects defined by the rule also satisfy the property 7. its rule of definition refers to itself

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

336

CHAPTER 6

SET THEORY D

av id

Eu ge

ne Sm

ith Co

lle ct

io n,

Co lu

m bi

a U

ni ve

rs ity

Georg Cantor (1845–1918)

In the late nineteenth century, Georg Cantor was the first to realize the potential usefulness of investigating properties of sets in general as distinct from properties of the elements that comprise them. Many mathematicians of his time resisted accepting the validity of Cantor’s work. Now, however, abstract set theory is regarded as the foundation of math- ematical thought. All mathematical objects (even numbers!) can be defined in terms of sets, and the language of set theory is used in every mathematical subject.

In this chapter we add to the basic definitions and notation of set theory introduced in Chapter 1 and show how to establish properties of sets through the use of proofs and coun- terexamples. We also introduce the notion of a Boolean algebra, explain how to derive its properties, and discuss their relationships to logical equivalencies and set identities. The chapter ends with a discussion of a famous “paradox” of set theory and its relation to computer science.

6.1 Set Theory: Definitions and the Element Method of Proof The introduction of suitable abstractions is our only mental aid to organize and master complexity. —E. W. Dijkstra, 1930–2002

The words set and element are undefined terms of set theory just as sentence, true, and false are undefined terms of logic. The founder of set theory, Georg Cantor, suggested imagining a set as a “collection into a whole M of definite and separate objects of our intuition or our thought. These objects are called the elements of M.” Cantor used the letter M because it is the first letter of the German word for set: Menge.

! Caution! Don’t forget to include the words “the set of all.”

Following the spirit of Cantor’s notation (though not the letter), let S denote a set and a an element of S. Then, as indicated in Section 1.2, a ∈ S means that a is an element of S, a /∈ S means that a is not an element of S, {1, 2, 3} refers to the set whose elements are 1, 2, and 3, and {1, 2, 3, . . .} refers to the set of all positive integers. If S is a set and P(x) is a property that elements of S may or may not satisfy, then a set A may be defined by writing

A = {x ∈ S | P(x)}, ↗ ↖

the set of all such that

which is read “the set of all x in S such that P of x .”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 337

Subsets: Proof and Disproof We begin by rewriting what it means for a set A to be a subset of a set B as a formal universal conditional statement:

A ⊆ B ⇔ ∀x, if x ∈ A then x ∈ B.

The negation is, therefore, existential:

A ! B ⇔ ∃x such that x ∈ A and x ̸∈ B.

A proper subset of a set is a subset that is not equal to its containing set. Thus

A is a proper subset of B ⇔ (1) A⊆ B, and (2) there is at least one element in B that is not in A.

Example 6.1.1 Testing Whether One Set Is a Subset of Another

Let A = {1} and B = {1, {1}}. a. Is A ⊆ B? b. If so, is A a proper subset of B?

Solution

a. Because A = {1}, A has only one element, namely the symbol 1. This element is also one of the elements in set B. Hence every element in A is in B, and so A ⊆ B.

b. B has two distinct elements, the symbol 1 and the set {1} whose only element is 1. Since 1 ̸= {1}, the set {1} is not an element of A, and so there is an element of B that is not an element of A. Hence A is a proper subset of B. ■

Note A set like {1}, with just one element, is called a singleton set.

Because we define what it means for one set to be a subset of another by means of a universal conditional statement, we can use the method of direct proof to establish a subset relationship. Such a proof is called an element argument and is the fundamental proof technique of set theory.

Element Argument: The Basic Method for Proving That One Set Is a Subset of Another

Let sets X and Y be given. To prove that X ⊆ Y , 1. suppose that x is a particular but arbitrarily chosen element of X ,

2. show that x is an element of Y .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

338 Chapter 6 Set Theory

Example 6.1.2 Proving and Disproving Subset Relations

Define sets A and B as follows:

A = {m ∈ Z | m = 6r + 12 for some r ∈ Z} B = {n ∈ Z | n = 3s for some s ∈ Z}.

a. Outline a proof that A ⊆ B. b. Prove that A ⊆ B. c. Disprove that B ⊆ A. Solution

a. Proof Outline: Suppose x is a particular but arbitrarily chosen element of A.

.

.

.

Therefore, x is an element of B.

b. Proof: Suppose x is a particular but arbitrarily chosen element of A.

[We must show that x ∈ B. By definition of B, this means we must show that x = 3 · (some integer).]

By definition of A, there is an integer r such that x = 6r + 12. [Given that x = 6r + 12, can we express x as 3 ·(some integer)? I.e., does 6r + 12 = 3 ·(some integer)? Yes, 6r + 12 = 3 ·(2r + 4).]

Let s = 2r + 4. [We must check that s is an integer.]

Then s is an integer because products and sums of integers are integers. [Now we must check that x = 3s.]

Also 3s = 3(2r + 4) = 6r + 12 = x , Thus, by definition of B, x is an element of B,

[which is what was to be shown].

c. To disprove a statement means to show that it is false, and to show it is false that B ⊆ A, you must find an element of B that is not an element of A. By the definitions of A and B, this means that you must find an integer x of the form 3 · (some integer) that cannot be written in the form 6 · (some integer) + 12. A little experimentation reveals that various numbers do the job. For instance, you could let x = 3. Then x ∈ B because 3 = 3·1, but x ̸∈ A because there is no integer r such that 3 = 6r + 12. For if there were such an integer, then

Note Recall that the notation P(x)⇒ Q(x) means that every element that makes P(x) true also makes Q(x) true.

⇒ ⇒ ⇒

6r + 12 = 3 2r + 4 = 1

2r = 3 r = 3/2

by assumption

by dividing both sides by 3

by subtracting 4 from both sides

by dividing both sides by 2,

but 3/2 is not an integer. Thus 3 ∈ B but 3∈/ A, and so B ! A. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 339

Set Equality Recall that by the axiom of extension, sets A and B are equal if, and only if, they have exactly the same elements. We restate this as a definition that uses the language of subsets.

• Definition Given sets A and B, A equals B, written A = B, if, and only if, every element of A is in B and every element of B is in A.

Symbolically:

A = B ⇔ A ⊆ B and B ⊆ A.

This version of the definition of equality implies the following:

To know that a set A equals a set B, you must know that A ⊆ B and you must also know that B ⊆ A.

Example 6.1.3 Set Equality

Define sets A and B as follows:

A = {m ∈ Z | m = 2a for some integer a} B = {n ∈ Z | n = 2b − 2 for some integer b}

Is A = B?

Solution Yes. To prove this, both subset relations A ⊆ B and B ⊆ A must be proved. Part 1, Proof That A ⊆ B:

Suppose x is a particular but arbitrarily chosen element of A. [We must show that x ∈ B. By definition of B, this means we must show that x = 2 · (some integer)− 2.]

By definition of A, there is an integer a such that x = 2a. [Given that x = 2a, can x also be expressed as 2 · (some integer)− 2? I.e., is there an integer, say b, such that 2a = 2b − 2? Solve for b to obtain b = (2a + 2)/2 = a + 1. Check to see if this works.]

Let b = a + 1. [First check that b is an integer.]

Then b is an integer because it is a sum of integers. [Then check that x= 2b − 2.]

Also 2b − 2 = 2(a + 1)− 2 = 2a + 2− 2 = 2a = x , Thus, by definition of B, x is an element of B

[which is what was to be shown].

Part 2, Proof That B ⊆ A: This part of the proof is left as exercise 2 at the end of this section. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

340 Chapter 6 Set Theory

Venn Diagrams If sets A and B are represented as regions in the plane, relationships between A and B can be represented by pictures, called Venn diagrams, that were introduced by the British mathematician John Venn in 1881. For instance, the relationship A ⊆ B can be pictured in one of two ways, as shown in Figure 6.1.1.

R oy

al So

ci et

y of

Lo nd

on

John Venn (1834–1923)

A B A = B

(a) (b)

Figure 6.1.1 A ⊆ B

The relationship A ! B can be represented in three different ways with Venn diagrams, as shown in Figure 6.1.2.

A B

(a)

A B

(b)

A

B

(c)

Figure 6.1.2 A ̸⊆ B

If we allow the possibility that some subregions of Venn diagrams do not contain any points, then in Figure 6.1.1 diagram (b) can be viewed as a special case of diagram (a) by imagining that the part of B outside A does not contain any points. Similarly, diagrams (a) and (c) of Figure 6.1.2 can be viewed as special cases of diagram (b). To obtain (a) from (b), imagine that the region of overlap between A and B does not contain any points. To obtain (c), imagine that the part of B that lies outside A does not contain any points. However, in all three diagrams it would be necessary to specify that there is a point in A that is not in B.

Example 6.1.4 Relations among Sets of Numbers

Since Z, Q, and R denote the sets of integers, rational numbers, and real numbers, respec- tively, Z is a subset of Q because every integer is rational (any integer n can be written in the form n1 ), and Q is a subset of R because every rational number is real (any ratio- nal number can be represented as a length on the number line). Z is a proper subset of Q because there are rational numbers that are not integers (for example, 12 ), and Q is a proper subset of R because there are real numbers that are not rational (for example,

√ 2).

This is shown diagrammatically in Figure 6.1.3. ■

Z Q R

Figure 6.1.3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 341

Operations on Sets Most mathematical discussions are carried on within some context. For example, in a cer- tain situation all sets being considered might be sets of real numbers. In such a situation, the set of real numbers would be called a universal set or a universe of discourse for the discussion.

• Definition Let A and B be subsets of a universal set U .

1. The union of A and B, denoted A ∪ B, is the set of all elements that are in at least one of A or B.

2. The intersection of A and B, denoted A ∩ B, is the set of all elements that are common to both A and B.

3. The difference of B minus A (or relative complement of A in B), denoted B − A, is the set of all elements that are in B and not A.

4. The complement of A, denoted Ac, is the set of all elements in U that are not in A.

Symbolically: A ∪ B = {x ∈ U | x ∈ A or x ∈ B}, A ∩ B = {x ∈ U | x ∈ A and x ∈ B}, B − A = {x ∈ U | x ∈ B and x /∈ A},

Ac = {x ∈ U | x /∈ A}.

The symbols ∈,∪, and ∩ were introduced in 1889 by the Italian mathematician Giuseppe Peano.

St oc

k M

on ta

ge

Giuseppe Peano (1858–1932)

Venn diagram representations for union, intersection, difference, and complement are shown in Figure 6.1.4.

U U

A B A B

Shaded region represents B – A.

Shaded region represents Ac.

U U

A B A B

Shaded region represents A ! B.

Shaded region represents A " B.

Figure 6.1.4

Example 6.1.5 Unions, Intersections, Differences, and Complements

Let the universal set be the set U = {a, b, c, d, e, f, g} and let A = {a, c, e, g} and B = {d, e, f, g}. Find A ∪ B, A ∩ B, B − A, and Ac.

Solution A ∪ B = {a, c, d, e, f, g} A ∩ B = {e, g} B − A = {d, f } Ac = {b, d, f } ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

342 Chapter 6 Set Theory

There is a convenient notation for subsets of real numbers that are intervals.

• Notation Given real numbers a and b with a ≤ b:

(a, b) = {x ∈ R | a < x < b} [a, b] = {x ∈ R | a ≤ x ≤ b} (a, b] = {x ∈ R | a < x ≤ b} [a, b) = {x ∈ R | a ≤ x < b}.

The symbols∞ and −∞ are used to indicate intervals that are unbounded either on the right or on the left:

(a,∞) = {x ∈ R | x > a} [a,∞) = {x ∈ R | x ≥ a} (−∞, b) = {x ∈ R | x < b} [−∞, b) = {x ∈ R | x ≤ b}.

Note The symbol∞ does not represent a number. It just indicates the unboundedness of the interval.

Observe that the notation for the interval (a, b) is identical to the notation for the ordered pair (a, b). However, context makes it unlikely that the two will be confused.

Example 6.1.6 An Example with Intervals

Let the universal set be the set R of all real numbers and let

A = (−1, 0] = {x ∈ R |−1 < x ≤ 0} and B = [0, 1) = {x ∈ R | 0 ≤ x < 1}. These sets are shown on the number lines below.

–2 –1 0 1 2

A

–2 –1 0 1 2

B

Find A ∪ B, A ∩ B, B − A, and Ac. Solution

A ∪ B = {x ∈ R | x ∈ (−1, 0] or x ∈ [0, 1)} = {x ∈ R | x ∈ (−1, 1)} = (−1, 1).–2 –1 0 1 2 A ! B

A ∩ B = {x ∈ R | x ∈ (−1, 0] and x ∈ [0, 1)} = {0}.–2 –1 0 1 2 A " B

–2 –1 0 1 2

B # A B − A = {x ∈ R | x ∈ [0, 1) and x ̸∈ (−1, 0]} = {x ∈ R | 0 < x < 1} = (0, 1)

Ac = {x ∈ R | it is not the case that x ∈ (−1, 0]} = {x ∈ R | it is not the case that (−1 < x and x ≤ 0)}

by definition of the double inequality

by De Morgan’s law

= {x ∈ R | x ≤ −1 or x > 0} = (−∞, −1] ∪ (0, ∞)–2 –1 0 1 2

Ac ■

The definitions of unions and intersections for more than two sets are very similar to the definitions for two sets.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 343

• Definition Unions and Intersections of an Indexed Collection of Sets Given sets A0, A1, A2, . . . that are subsets of a universal set U and given a nonneg- ative integer n,

n⋃

i=0 Ai = {x ∈ U | x ∈ Ai for at least one i = 0, 1, 2, . . . , n}

∞⋃

i=0 Ai = {x ∈ U | x ∈ Ai for at least one nonnegative integer i}

n⋂

i=0 Ai = {x ∈ U | x ∈ Ai for all i = 0, 1, 2, . . . , n}

∞⋂

i=0 Ai = {x ∈ U | x ∈ Ai for all nonnegative integers i}.

Note n⋃

i=0 Ai is read “the

union of the A-sub-i from i equals zero to n.”

An alternative notation for n⋃

i=0 Ai is A0 ∪ A1 ∪ . . . ∪ An , and an alternative notation for

n⋂ i=0

Ai is A0 ∩ A1 ∩ . . . ∩ An .

Example 6.1.7 Finding Unions and Intersections of More than Two Sets

For each positive integer i , let Ai = {

x ∈ R |− 1i < x < 1 i

} = Ai =

( −1i ,

1 i

) .

a. Find A1 ∪ A2 ∪ A3 and A1 ∩ A2 ∩ A3. b. Find ∞⋃

i=1 Ai and

∞⋂ i=1

Ai .

Solution

a. A1 ∪ A2 ∪ A3 = {x ∈ R | x is in at least one of the intervals (−1, 1), or ( −12 ,

1 2

) , or ( −13 ,

1 3

)}

= {x ∈ R |− 1 < x < 1} because all the elements in ( − 12 ,

1 2

)

and ( −13 ,

1 3

) are in (−1, 1)= (−1, 1)

A1 ∩ A2 ∩ A3 = {x ∈ R | x is in all of the intervals (−1, 1), and ( −12 ,

1 2

) , and ( −13 ,

1 3

)}

= {

x ∈ R |− 13 < x < 1 3

} because

( −13 ,

1 3

) ⊆ ( −12 ,

1 2

) ⊆ (−1, 1)

= ( −13 ,

1 3

)

b. ∞⋃

i=1 Ai = {x ∈ R | x is in at least one of the intervals

( − 1i ,

1 i

) ,

where i is a positive integer} = {x ∈ R |− 1 < x < 1} because all the elements in every interval(

−1i , 1 i

) are in (−1, 1)= (−1, 1)

∞⋂ i=1

Ai = {x ∈ R | x is in all of the intervals ( −1i ,

1 i

) , where i is a positive integer}

= {0} because the only element in every interval is 0 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

344 Chapter 6 Set Theory

The Empty Set We have stated that a set is defined by the elements that compose it. This being so, can there be a set that has no elements? It turns out that it is convenient to allow such a set. Otherwise, every time we wanted to take the intersection of two sets or to define a set by specifying a property, we would have to check that the result had elements and hence qualified for “sethood.” For example, if A = {1, 3} and B = {2, 4}, then A ∩ B has no elements. Neither does {x ∈ R | x2 = −1} because no real numbers have negative squares.

It is somewhat unsettling to talk about a set with no elements, but it often happens in mathematics that the definitions formulated to fit one set of circumstances are satisfied by some extreme cases not originally anticipated. Yet changing the definitions to exclude those cases would seriously undermine the simplicity and elegance of the theory taken as a whole.

In Section 6.2 we will show that there is only one set with no elements. Because it is unique, we can give it a special name. We call it the empty set (or null set) and denote it by the symbol ∅. Thus {1, 3} ∩ {2, 4} = ∅ and {x ∈ R | x2 = −1} = ∅.

Example 6.1.8 A Set with No Elements

Describe the set D = {x ∈ R | 3 < x < 2}.

Solution Recall that a < x < b means that a < x and x < b. So D consists of all real numbers that are both greater than 3 and less than 2. Since there are no such numbers, D has no elements and so D = ∅. ■

Partitions of Sets In many applications of set theory, sets are divided up into nonoverlapping (or disjoint) pieces. Such a division is called a partition.

• Definition Two sets are called disjoint if, and only if, they have no elements in common.

Symbolically:

A and B are disjoint ⇔ A ∩ B = ∅.

Example 6.1.9 Disjoint Sets

Let A = {1, 3, 5} and B = {2, 4, 6}. Are A and B disjoint? Solution Yes. By inspection A and B have no elements in common, or, in other words,

{1, 3, 5} ∩ {2, 4, 6} = ∅. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 345

• Definition Sets A1, A2, A3 . . . are mutually disjoint (or pairwise disjoint or nonoverlapping) if, and only if, no two sets Ai and A j with distinct subscripts have any elements in common. More precisely, for all i, j = 1, 2, 3, . . .

Ai ∩ A j = ∅ whenever i ̸= j.

Example 6.1.10 Mutually Disjoint Sets

a. Let A1 = {3, 5}, A2 = {1, 4, 6}, and A3 = {2}. Are A1, A2, and A3 mutually disjoint? b. Let B1 = {2, 4, 6}, B2 = {3, 7}, and B3 = {4, 5}. Are B1, B2, and B3 mutually

disjoint?

Solution

a. Yes. A1 and A2 have no elements in common, A1 and A3 have no elements in common, and A2 and A3 have no elements in common.

A

A2

A4A3

A1

Figure 6.1.5 A Partition of a Set

b. No. B1 and B3 both contain 4. ■

Suppose A, A1, A2, A3, and A4 are the sets of points represented by the regions shown in Figure 6.1.5. Then A1, A2, A3, and A4 are subsets of A, and A = A1 ∪ A2 ∪ A3 ∪ A4. Suppose further that boundaries are assigned to the regions representing A2, A3, and A4 in such a way that these sets are mutually disjoint. Then A is called a union of mutually disjoint subsets, and the collection of sets {A1, A2, A3, A4} is said to be a partition of A.

• Definition A finite or infinite collection of nonempty sets {A1, A2, A3 . . .} is a partition of a set A if, and only if,

1. A is the union of all the Ai

2. The sets A1, A2, A3, . . . are mutually disjoint.

Example 6.1.11 Partitions of Sets

a. Let A = {1, 2, 3, 4, 5, 6}, A1 = {1, 2}, A2 = {3, 4}, and A3 = {5, 6}. Is {A1, A2, A3} a partition of A?

b. Let Z be the set of all integers and let

T0 = {n ∈ Z | n = 3k, for some integer k}, T1 = {n ∈ Z | n = 3k + 1, for some integer k}, and T2 = {n ∈ Z | n = 3k + 2, for some integer k}.

Is {T0, T1, T2} a partition of Z?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

346 Chapter 6 Set Theory

Solution

a. Yes. By inspection, A = A1 ∪ A2 ∪ A3 and the sets A1, A2, and A3 are mutually disjoint.

b. Yes. By the quotient-remainder theorem, every integer n can be represented in exactly one of the three forms

n = 3k or n = 3k + 1 or n = 3k + 2, for some integer k. This implies that no integer can be in any two of the sets T0, T1, or T2. So T0, T1, and T2 are mutually disjoint. It also implies that every integer is in one of the sets T0, T1, or T2. So Z = T0 ∪ T1 ∪ T2. ■

Power Sets There are various situations in which it is useful to consider the set of all subsets of a particular set. The power set axiom guarantees that this is a set.

• Definition Given a set A, the power set of A, denoted PP (A), is the set of all subsets of A.

Example 6.1.12 Power Set of a Set

Find the power set of the set {x, y}. That is, find P({x, y}). Solution P({x, y}) is the set of all subsets of {x, y}. In Section 6.2 we will show that

∅ is a subset of every set, and so ∅ ∈P({x, y}). Also any set is a subset of itself, so {x, y} ∈P({x, y}). The only other subsets of {x, y} are {x} and {y}, so

P({x, y}) = {∅, {x}, {y}, {x, y}}. ■

Cartesian Products Recall that the definition of a set is unaffected by the order in which its elements are listed or the fact that some elements may be listed more than once. Thus {a, b}, {b, a}, and {a, a, b} all represent the same set. The notation for an ordered n-tuple is a generalization of the notation for an ordered pair. (See Section 1.2.) It takes both order and multiplicity into account.

• Definition Let n be a positive integer and let x1, x2, . . . , xn be (not necessarily distinct) elements. The ordered n-tuple, (x1, x2, . . . , xn), consists of x1, x2, . . . , xn together with the ordering: first x1, then x2, and so forth up to xn . An ordered 2-tuple is called an ordered pair, and an ordered 3-tuple is called an ordered triple.

Two ordered n-tuples (x1, x2, . . . , xn) and (y1, y2, . . . , yn) are equal if, and only if, x1 = y1, x2 = y2, . . . , xn = yn .

Symbolically:

(x1, x2, . . . , xn) = (y1, y2, . . . , yn) ⇔ x1 = y1, x2 = y2, . . . , xn = yn. In particular,

(a, b) = (c, d) ⇔ a = c and b = d.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 347

Example 6.1.13 Ordered n-tuples

a. Is (1, 2, 3, 4) = (1, 2, 4, 3)?

b. Is (

3, (−2)2, 12 )

= (√

9, 4, 36 ) ?

Solution

a. No. By definition of equality of ordered 4-tuples,

(1, 2, 3, 4) = (1, 2, 4, 3)⇔ 1 = 1, 2 = 2, 3 = 4, and 4 = 3

But 3 ̸= 4, and so the ordered 4-tuples are not equal. b. Yes. By definition of equality of ordered triples,

( 3, (−2)2, 12

) = (√

9, 4, 36

) ⇔ 3 =

√ 9 and (−2)2 = 4 and 12 =

3 6 .

Because these equations are all true, the two ordered triples are equal. ■

• Definition Given sets A1, A2, . . . , An , the Cartesian product of A1, A2, . . . , An denoted A1 × A2 × . . .× An, is the set of all ordered n-tuples (a1, a2, . . . , an) where a1 ∈ A1, a2 ∈ A2, . . . , an ∈ An .

Symbolically:

A1 × A2 × · · ·× An = {(a1, a2, . . . , an) | a1 ∈ A1, a2 ∈ A2, . . . , an ∈ An}. In particular,

A1 × A2 = {(a1, a2) | a1 ∈ A1 and a2 ∈ A2} is the Cartesian product of A1 and A2.

Example 6.1.14 Cartesian Products

Let A1 = {x, y}, A2 = {1, 2, 3}, and A3 = {a, b}. a. Find A1 × A2. b. Find (A1 × A2)× A3. c. Find A1 × A2 × A3.

Solution

a. A1 × A2 = {(x, 1), (x, 2), (x, 3), (y, 1), (y, 2), (y, 3)} b. The Cartesian product of A1 and A2 is a set, so it may be used as one of the sets

making up another Cartesian product. This is the case for (A1 × A2)× A3.

(A1 × A2)× A3 = {(u, v) | u ∈ A1 × A2 and v ∈ A3} by definition of Cartesian product = {((x, 1), a), ((x, 2), a), ((x, 3), a), ((y, 1), a),

((y, 2), a), ((y, 3), a), ((x, 1), b), ((x, 2), b), ((x, 3), b),

((y, 1), b), ((y, 2), b), ((y, 3), b)}

c. The Cartesian product A1 × A2 × A3 is superficially similar to, but is not quite the same mathematical object as, (A1 × A2)× A3. (A1 × A2)× A3 is a set of ordered

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

348 Chapter 6 Set Theory

pairs of which one element is itself an ordered pair, whereas A1 × A2 × A3 is a set of ordered triples. By definition of Cartesian product,

A1 × A2 × A3 = {(u, v, w) | u ∈ A1, v ∈ A2, and w ∈ A3} = {(x, 1, a), (x, 2, a), (x, 3, a), (y, 1, a), (y, 2, a),

(y, 3, a), (x, 1, b), (x, 2, b), (x, 3, b), (y, 1, b),

(y, 2, b), (y, 3, b)}. ■

An Algorithm to Check Whether One Set Is a Subset of Another (Optional)

You may get some additional insight into the concept of subset by considering an algo- rithm for checking whether one finite set is a subset of another. Order the elements of both sets and successively compare each element of the first set with each element of the second set. If some element of the first set is not found to equal any element of the second, then the first set is not a subset of the second. But if each element of the first set is found to equal an element of the second set, then the first set is a subset of the second. The following algorithm formalizes this reasoning.

Algorithm 6.1.1 Testing Whether A ⊆ B

[Input sets A and B are represented as one-dimensional arrays a[1], a[2], . . . , a[m] and b[1], b[2], . . . , b[n], respectively. Starting with a[1] and for each successive a[i] in A, a check is made to see whether a[i] is in B. To do this, a[i] is compared to successive elements of B. If a[i] is not equal to any element of B, then answer is given the value “A ! B.” If a[i] equals some element of B, the next successive element in A is checked to see whether it is in B. If every successive element of A is found to be in B, then answer never changes from its initial value “A ⊆ B.”] Input: m [a positive integer], a[1], a[2], . . . , a[m] [a one-dimensional array representing the set A], n [a positive integer], b[1], b[2], . . . , b[n] [a one-dimensional array representing the set B]

Algorithm Body: i := 1, answer := “A ⊆ B” while (i ≤ m and answer = “A ⊆ B”)

j := 1, found := “no” while ( j ≤ n and found = “no”)

if a[i] = b[ j] then found := “yes” j := j + 1

end while [If found has not been given the value “yes” when execution reaches this point, then a[i] /∈ B.] if found = “no” then answer := “A ! B” i := i + 1

end while Output: answer [a string]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 349

Example 6.1.15 Tracing Algorithm 6.1.1

Trace the action of Algorithm 6.1.1 on the variables i, j , found, and answer for m = 3, n = 4, and sets A and B represented as the arrays a[1] = u, a[2] = v, a[3] = w, b[1] = w, b[2] = x, b[3] = y, and b[4] = u.

Solution

i 1 2 3

j 1 2 3 4 5 1 2 3 4 5

found no yes no

answer A ⊆ B A ! B

In the exercises at the end of this section, you are asked to write an algorithm to check whether a given element is in a given set. To do this, you can represent the set as a one- dimensional array and compare the given element with successive elements of the array to determine whether the two elements are equal. If they are, then the element is in the set; if the given element does not equal any element of the array, then the element is not in the set.

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. The notation A ⊆ B is read “_____” and means that _____. 2. To use an element argument for proving that a set X is a

subset of a set Y , you suppose that _____ and show that _____.

3. To disprove that a set X is a subset of a set Y , you show that there is _____.

4. An element x is in A ∪ B if, and only if, _____. 5. An element x is in A ∩ B if, and only if, _____. 6. An element x is in B − A if, and only if, _____.

7. An element x is in Ac if, and only if, _____.

8. The empty set is a set with _____.

9. The power set of a set A is _____.

10. Sets A and B are disjoint if, and only if, _____.

11. A collection of nonempty sets A1, A2, A3, . . . is a partition of a set A if, and only if, _____.

12. Given sets A1, A2, . . . , An , the Cartesian product A1 × A2 × . . .× An is _____.

Exercise Set 6.1* 1. In each of (a)–(f), answer the following questions: Is

A ⊆ B? Is B ⊆ A? Is either A or B a proper subset of the other?

a. A = {2, {2}, ( √

2)2}, B = {2, {2}, {{2}}} b. A = {3,

√ 52 − 42, 24 mod 7}, B = {8 mod 5}

c. A = {{1, 2}, {2, 3}}, B = {1, 2, 3} d. A = {a, b, c}, B = {{a}, {b}, {c}} e. A = {

√ 16, {4}}, B = {4}

f. A = {x ∈ R | cos x ∈ Z}, B = {x ∈ R | sin x ∈ Z}

2. Complete the proof from Example 6.1.3: Prove that B ⊆ A where

A = {m ∈ Z | m = 2a for some integer a} and

B = {n ∈ Z | n = 2b − 2 for some integer b}

∗ For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

350 Chapter 6 Set Theory

3. Let sets R, S, and T be defined as follows: R = {x ∈ Z | x is divisible by 2} S = {y ∈ Z | y is divisible by 3} T = {z ∈ Z | z is divisible by 6}

a. Is R ⊆ T ? Explain. b. Is T ⊆ R? Explain. c. Is T ⊆ S? Explain.

4. Let A = {n ∈ Z | n = 5r for some integer r} and B = {m ∈ Z | m = 20s for some integer s}. a. Is A ⊆ B? Explain. b. Is B ⊆ A? Explain.

5. Let C = {n ∈ Z | n = 6r − 5 for some integer r} and D = {m ∈ Z | m = 3s + 1 for some integer s}. Prove or disprove each of the following statements. a. C ⊆ D b. D ⊆ C

6. Let A = {x ∈ Z | x = 5a + 2 for some integer a}, B = {y ∈ Z | y = 10b − 3 for some integer b}, and C = {z ∈ Z | z = 10c + 7 for some integer c}. Prove or disprove each of the following statements. a. A ⊆ B b. B ⊆ A H c. B = C

7. Let A = {x ∈ Z | x = 6a + 4 for some integer a}, B = {y ∈ Z | y = 18b − 2 for some integer b}, and C = {z ∈ Z | z = 18c + 16 for some integer c}. Prove or disprove each of the following statements. a. A ⊆ B b. B ⊆ A c. B = C

8. Write in words how to read each of the following out loud. Then write the shorthand notation for each set. a. {x ∈ U | x ∈ A and x ∈ B} b. {x ∈ U | x ∈ A or x ∈ B} c. {x ∈ U | x ∈ A and x /∈ B} d. {x ∈ U | x /∈ A}

9. Complete the following sentences without using the symbols ∪, ∩, or −. a. x /∈ A ∪ B if, and only if, _____. b. x /∈ A ∩ B if, and only if, _____. c. x /∈ A − B if, and only if, _____.

10. Let A = {1, 3, 5, 7, 9}, B = {3, 6, 9}, and C = {2, 4, 6, 8}. Find each of the following: a. A ∪ B b. A ∩ B c. A ∪ C d. A ∩ C e. A − B f. B − A g. B ∪ C h. B ∩ C

11. Let the universal set be the set R of all real numbers and let A = {x ∈ R | 0 < x ≤ 2}, B = {x ∈ R | 1 ≤ x < 4}, and C = {x ∈ R | 3 ≤ x < 9}. Find each of the following: a. A ∪ B b. A ∩ B c. Ac d. A ∪ C e. A ∩ C f. Bc g. Ac ∩ Bc h. Ac ∪ Bc i. (A ∩ B)c j. (A ∪ B)c

12. Let the universal set be the set R of all real numbers and let A = {x ∈ R |−3 ≤ x ≤ 0}, B = {x ∈ R |−1 < x < 2}, and C = {x ∈ R | 6 < x ≤ 8}. Find each of the following: a. A ∪ B b. A ∩ B c. Ac d. A ∪ C e. A ∩ C f. Bc g. Ac ∩ Bc h. Ac ∪ Bc i. (A ∩ B)c j. (A ∪ B)c

13. Indicate which of the following relationships are true and which are false: a. Z+ ⊆ Q b. R− ⊆ Q c. Q ⊆ Z d. Z− ∪ Z+ = Z e. Z− ∩ Z+ = ∅ f. Q ∩ R = Q g. Q ∪ Z = Q h. Z+ ∩ R = Z+ i. Z ∪Q = Z

14. In each of the following, draw a Venn diagram for sets A, B, and C that satisfy the given conditions: a. A ⊆ B; C ⊆ B; A ∩ C = ∅ b. C ⊆ A; B ∩ C = ∅

15. Draw Venn diagrams to describe sets A, B, and C that satisfy the given conditions. a. A ∩ B = ∅, A ⊆ C, C ∩ B ̸= ∅ b. A ⊆ B, C ⊆ B, A ∩ C ̸= ∅ c. A ∩ B ̸= ∅, B ∩ C ̸= ∅, A ∩ C = ∅, A ! B, C ! B

16. Let A = {a, b, c}, B = {b, c, d}, and C = {b, c, e}. a. Find A ∪ (B ∩ C), (A ∪ B) ∩ C , and

(A ∪ B) ∩ (A ∪ C). Which of these sets are equal? b. Find A ∩ (B ∪ C), (A ∩ B) ∪ C , and

(A ∩ B) ∪ (A ∩ C). Which of these sets are equal? c. Find (A − B)− C and A − (B − C). Are these sets

equal?

17. Consider the Venn diagram shown below. For each of (a)–(f), copy the diagram and shade the region corresponding to the indicated set. a. A ∩ B b. B ∪ C c. Ac d. A − (B ∪ C) e. (A ∪ B)c f. Ac ∩ Bc

A B

C

U

18. a. Is the number 0 in ∅? Why? b. Is ∅ = {∅}? Why? c. Is ∅ ∈ {∅}? Why? d. Is ∅ ∈ ∅? Why?

19. Let Ai = {i, i2} for all integers i = 1, 2, 3, 4. a. A1 ∪ A2 ∪ A3 ∪ A4 =? b. A1 ∩ A2 ∩ A3 ∩ A4 =? c. Are A1, A2, A3, and A4 mutually disjoint? Explain.

20. Let Bi = {x ∈ R | 0 ≤ x ≤ i} for all integers i = 1, 2, 3, 4. a. B1 ∪ B2 ∪ B3 ∪ B4 =? b. B1 ∩ B2 ∩ B3 ∩ B4 =? c. Are B1, B2, B3, and B4 mutually disjoint? Explain.

21. Let Ci = {i,−i} for all nonnegative integers i . a.

4⋃ i=0

Ci =? b. 4⋂

i=0 Ci =?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Set Theory: Definitions and the Element Method of Proof 351

c. Are C0, C1, C2, . . . mutually disjoint? Explain.

d. n⋃

i=0 Ci =? e.

n⋂ i=0

Ci =?

f. ∞⋃

i=0 Ci =? g.

∞⋂ i=0

Ci =?

22. Let Di = {x ∈ R | − i ≤ x ≤ i} = [−i, i] for all nonnega- tive integers i .

a. 4⋃

i=0 Di =? b.

4⋂ i=0

Di =?

c. Are D0, D1, D2, . . . mutually disjoint? Explain.

d. n⋃

i=0 Di =? e.

n⋂ i=0

Di =?

f. ∞⋃

i=0 Di =? g.

∞⋂ i=0

Di =?

23. Let Vi = {

x ∈ R | − 1i ≤ x ≤ 1 i

} = [ −1i ,

1 i

] for all pos-

itive integers i .

a. 4⋃

i=1 Vi =? b.

4⋂ i=1

Vi =?

c. Are V1, V2, V3, . . . mutually disjoint? Explain.

d. n⋃

i=1 Vi =? e.

n⋂ i=1

Vi =?

f. ∞⋃

i=1 Vi =? g.

∞⋂ i=1

Vi =?

24. Let Wi = {x ∈ R | x > i} = (i,∞) for all nonnegative integers i .

a. 4⋃

i=0 Wi =? b.

4⋂ i=0

Wi =?

c. Are W0, W1, W2, . . . mutually disjoint? Explain.

d. n⋃

i=0 Wi =? e.

n⋂ i=0

Wi =?

f. ∞⋃

i=0 Wi =? g.

∞⋂ i=0

Wi =?

25. Let Ri = {

x ∈ R | 1 ≤ x ≤ 1 + 1i }

= [ 1, 1 + 1i

] for all

positive integers i .

a. 4⋃

i=1 Ri =? b.

4⋂ i=1

Ri =?

c. Are R1, R2, R3, . . . mutually disjoint? Explain.

d. n⋃

i=1 Ri =? e.

n⋂ i=1

Ri =?

f. ∞⋃

i=1 Ri =? g.

∞⋂ i=1

Ri =?

26. Let Si = {

x ∈ R | 1 < x < 1 + 1i }

= (

1, 1 + 1i )

for all positive integers i .

a. 4⋃

i=1 Si =? b.

4⋂ i=1

Si =?

c. Are S1, S2, S3, . . . mutually disjoint? Explain.

d. n⋃

i=1 Si =? e.

n⋂ i=1

Si =?

f. ∞⋃

i=1 Si =? g.

∞⋂ i=1

Si =?

27. a. Is {{a, d, e}, {b, c}, {d, f }} a partition of {a, b, c, d, e, f }?

b. Is {{w, x, v}, {u, y, q}, {p, z}} a partition of {p, q, u, v, w, x, y, z}?

c. Is {{5, 4}, {7, 2}, {1, 3, 4}, {6, 8}} a partition of {1, 2, 3, 4, 5, 6, 7, 8}?

d. Is {{3, 7, 8}, {2, 9}, {1, 4, 5}} a partition of {1, 2, 3, 4, 5, 6, 7, 8, 9}?

e. Is {{1, 5}, {4, 7}, {2, 8, 6, 3}} a partition of {1, 2, 3, 4, 5, 6, 7, 8}?

28. Let E be the set of all even integers and O the set of all odd integers. Is {E, O} a partition of Z, the set of all integers? Explain your answer.

29. Let R be the set of all real numbers. Is {R+, R−, {0}} a par- tition of R? Explain your answer.

30. Let Z be the set of all integers and let

A0 = {n ∈ Z | n = 4k, for some integer k}, A1 = {n ∈ Z | n = 4k + 1, for some integer k}, A2 = {n ∈ Z | n = 4k + 2, for some integer k}, and A3 = {n ∈ Z | n = 4k + 3, for some integer k}.

Is {A0, A1, A2, A3} a partition of Z? Explain your answer. 31. Suppose A = {1, 2} and B = {2, 3}. Find each of the

following: a. P(A ∩ B) b.P(A) c. P(A ∪ B) d.P(A × B)

32. a. Suppose A = {1} and B = {u, v}. Find P(A × B). b. Suppose X = {a, b} and Y = {x, y}. Find P(X × Y ).

33. a. Find P(∅). b. Find P(P(∅)). c. Find P(P(P(∅))).

34. Let A1 = {1, 2, 3}, A2 = {u, v}, and A3 = {m, n}. Find each of the following sets: a. A1 × (A2 × A3) b. (A1 × A2)× A3 c. A1 × A2 × A3

35. Let A = {a, b}, B = {1, 2}, and C = {2, 3}. Find each of the following sets. a. A × (B ∪ C) b. (A × B) ∪ (A × C) c. A × (B ∩ C) d. (A × B) ∩ (A × C)

36. Trace the action of Algorithm 6.1.1 on the variables i, j , found, and answer for m = 3, n = 3, and sets A and B represented as the arrays a[1] = u, a[2] = v, a[3] = w, b[1] = w, b[2] = u, and b[3] = v.

37. Trace the action of Algorithm 6.1.1 on the variables i, j , found, and answer for m = 4, n = 4, and sets A and B represented as the arrays a[1] = u, a[2] = v, a[3] = w, a[4] = x, b[1] = r , b[2] = u, b[3] = y, b[4] = z.

38. Write an algorithm to determine whether a given element x belongs to a given set, which is represented as an array a[1], a[2], . . . , a[n].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

352 Chapter 6 Set Theory

Answers for Test Yourself 1. the set A is a subset of the set B; for all x , if x ∈ A then x ∈ B (Or : every element of A is also an element of B) 2. x is any [particular but arbitrarily chosen] element of X; x is an element of Y 3. an element in X that is not in Y 4. x is in A or x is in B (Or : x is in at least one of the sets A and B) 5. x is in A and x is in B (Or : x is in both A and B) 6. x is in B and x is not in A 7. x is in the universal set and is not in A 8. no elements 9. the set of all subsets of A 10. A ∩ B = ∅ (Or : A and B have no elements in common) 11. A is the union of all the sets A1, A2, A3, . . . and Ai ∩ A j = ∅ whenever i ̸= j. 12. the set of all ordered n-tuples (a1, a2, . . . , an), where ai is in Ai for all i = 1, 2, . . . , n

6.2 Properties of Sets

. . . only the last line is a genuine theorem here—everything else is in the fantasy. —Douglas Hofstadter, Gödel, Escher, Bach, 1979

It is possible to list many relations involving unions, intersections, complements, and differences of sets. Some of these are true for all sets, whereas others fail to hold in some cases. In this section we show how to establish basic set properties using element arguments, and we discuss a variation used to prove that a set is empty. In the next section we will show how to disprove a proposed set property by constructing a counterexample and how to use an algebraic technique to derive new set properties from set properties already known to be true.

We begin by listing some set properties that involve subset relations. As you read them, keep in mind that the operations of union, intersection, and difference take prece- dence over set inclusion. Thus, for example, A ∩ B ⊆ C means (A ∩ B) ⊆ C .

Theorem 6.2.1 Some Subset Relations

1. Inclusion of Intersection: For all sets A and B,

(a) A ∩ B ⊆ A and (b) A ∩ B ⊆ B. 2. Inclusion in Union: For all sets A and B,

(a) A ⊆ A ∪ B and (b) B ⊆ A ∪ B. 3. Transitive Property of Subsets: For all sets A, B, and C ,

if A ⊆ B and B ⊆ C, then A ⊆ C.

The conclusion of each part of Theorem 6.2.1 states that one set x is a subset of another set Y and so to prove them, you suppose that x is any [particular but arbitrarily chosen] element of X and you show that x is an element of Y .

In most proofs of set properties, the secret of getting from the assumption that x is in X to the conclusion that x is in Y is to think of the definitions of basic set operations in procedural terms. For example, the union of sets X and Y , X ∪ Y , is defined as

X ∪ Y = {x | x ∈ X or x ∈ Y }. This means that any time you know an element x is in X ∪ Y , you can conclude that x must be in X or x must be in Y . Conversely, any time you know that a particular x is in some set X or is in some set Y , you can conclude that x is in X ∪ Y . Thus, for any sets X and Y and any element x ,

x ∈ X ∪ Y if, and only if, x ∈ X or x ∈ Y.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 353

Procedural versions of the definitions of the other set operations are derived similarly and are summarized below.

Procedural Versions of Set Definitions

Let X and Y be subsets of a universal set U and suppose x and y are elements of U .

1. x ∈ X ∪ Y ⇔ x ∈ X or x ∈ Y 2. x ∈ X ∩ Y ⇔ x ∈ X and x ∈ Y 3. x ∈ X − Y ⇔ x ∈ X and x /∈ Y 4. x ∈ Xc ⇔ x /∈ X 5. (x, y) ∈ X × Y ⇔ x ∈ X and y ∈ Y

Example 6.2.1 Proof of a Subset Relation

Prove Theorem 6.2.1(1)(a): For all sets A and B, A ∩ B ⊆ A.

Solution We start by giving a proof of the statement and then explain how you can obtain such a proof yourself.

Proof:

Suppose A and B are any sets and suppose x is any element of A ∩ B. Then x ∈ A and x ∈ B by definition of intersection. In particular, x ∈ A. Thus A ∩ B ⊆ A.

The underlying structure of this proof is not difficult, but it is more complicated than the brevity of the proof suggests. The first important thing to realize is that the state- ment to be proved is universal (it says that for all sets A and B, A ∩ B ⊆ A). The proof, therefore, has the following outline:

Starting Point: Suppose A and B are any (particular but arbitrarily chosen) sets. To Show: A ∩ B ⊆ A Now to prove that A ∩ B ⊆ A, you must show that

∀x, if x ∈ A ∩ B then x ∈ A. But this statement also is universal. So to prove it, you

suppose x is an element in A ∩ B and then you

show that x is in A.

Filling in the gap between the “suppose” and the “show” is easy if you use the procedural version of the definition of intersection: To say that x is in A ∩ B means that

x is in A and x is in B.

This allows you to complete the proof by deducing that, in particular,

x is in A,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

354 Chapter 6 Set Theory

as was to be shown. Note that this deduction is just a special case of the valid argument form

p ∧ q ∴ p. ■

In his book Gödel, Escher, Bach,∗ Douglas Hofstadter introduces the fantasy rule for mathematical proof. Hofstadter points out that when you start a mathematical argument with if, let, or suppose, you are stepping into a fantasy world where not only are all the facts of the real world true but whatever you are supposing is also true. Once you are in that world, you can suppose something else. That sends you into a subfantasy world where not only is everything in the fantasy world true but also the new thing you are supposing. Of course you can continue stepping into new subfantasy worlds in this way indefinitely. You return one level closer to the real world each time you derive a conclusion that makes a whole if-then or universal statement true. Your aim in a proof is to continue deriving such conclusions until you return to the world from which you made your first supposition.

Occasionally, mathematical problems are stated in the following form:

Suppose (statement 1). Prove that (statement 2).

When this phrasing is used, the author intends the reader to add statement 1 to his or her general mathematical knowledge and not to make explicit reference to it in the proof. In Hofstadter’s terms, the author invites the reader to enter a fantasy world where statement 1 is known to be true and to prove statement 2 in this fantasy world. Thus the solver of such a problem would begin a proof with the starting point for a proof of statement 2. Consider, for instance, the following restatement of Example 6.2.1:

Suppose A and B are arbitrarily chosen sets. Prove that A ∩ B ⊆ A.

The proof would begin “Suppose x ∈ A ∩ B,” it being understood that sets A and B have already been chosen arbitrarily.

The proof of Example 6.2.1 is called an element argument because it shows one set to be a subset of another by demonstrating that every element in the one set is also an element in the other. In higher mathematics, element arguments are the standard method of establishing relations among sets. High school students are often allowed to justify set properties by using Venn diagrams. This method is appealing, but for it to be mathematically rigorous may be more complicated than you might expect. Appropriate Venn diagrams can be drawn for two or three sets, but the verbal explanations needed to justify conclusions inferred from them are normally as long as a straightforward element proof.

In general, Venn diagrams are not very helpful when the number of sets is four or more. For instance, if the requirement is made that a Venn diagram must show every possible intersection of the sets, it is impossible to draw a symmetric Venn diagram for four sets, or, in fact, for any nonprime number of sets. In 2002, computer scien- tists/mathematicians Carla Savage and Jerrold Griggs and undergraduate student Charles Killian solved a longstanding open problem by proving that it is possible to draw such a symmetric Venn diagram for any prime number of sets. For n > 5, however, the resulting pictures are very complicated! The existence of such symmetric diagrams has applica- tions in the area of computer science called coding theory.

∗Gödel, Escher, Bach: An Eternal Golden Braid (New York: Basic Books, 1979).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 355

Set Identities An identity is an equation that is universally true for all elements in some set. For exam- ple, the equation a + b = b + a is an identity for real numbers because it is true for all real numbers a and b. The collection of set properties in the next theorem consists entirely of set identities. That is, they are equations that are true for all sets in some universal set.

Theorem 6.2.2 Set Identities

Let all sets referred to below be subsets of a universal set U .

1. Commutative Laws: For all sets A and B,

(a) A ∪ B = B ∪ A and (b) A ∩ B = B ∩ A. 2. Associative Laws: For all sets A, B, and C ,

(a) (A ∪ B) ∪ C = A ∪ (B ∪ C) and (b) (A ∩ B) ∩ C = A ∩ (B ∩ C).

3. Distributive Laws: For all sets, A, B, and C ,

(a) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) and (b) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).

4. Identity Laws: For all sets A,

(a) A ∪ ∅ = A and (b) A ∩U = A. 5. Complement Laws:

(a) A ∪ Ac = U and (b) A ∩ Ac = ∅. 6. Double Complement Law: For all sets A,

(Ac)c = A. 7. Idempotent Laws: For all sets A,

(a) A ∪ A = A and (b) A ∩ A = A. 8. Universal Bound Laws: For all sets A,

(a) A ∪U = U and (b) A ∩ ∅ = ∅. 9. De Morgan’s Laws: For all sets A and B,

(a) (A ∪ B)c = Ac ∩ Bc and (b) (A ∩ B)c = Ac ∪ Bc. 10. Absorption Laws: For all sets A and B,

(a) A ∪ (A ∩ B) = A and (b) A ∩ (A ∪ B) = A. 11. Complements of U and ∅:

(a) U c = ∅ and (b) ∅c = U. 12. Set Difference Law: For all sets A and B,

A − B = A ∩ Bc.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

356 Chapter 6 Set Theory

Proving Set Identities The conclusion of each part of Theorem 6.2.2 is that one set equals another set. As we noted in Section 6.1,

Two sets are equal ⇔ each is a subset of the other. The method derived from this fact is the most basic way to prove equality of sets.

Basic Method for Proving That Sets Are Equal

Let sets X and Y be given. To prove that X = Y : 1. Prove that X ⊆ Y . 2. Prove that Y ⊆ X .

Example 6.2.2 Proof of a Distributive Law

Prove that for all sets A, B, and C ,

A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).

Solution The proof of this fact is somewhat more complicated than the proof in Example 6.2.1, so we first derive its logical structure, then find the core arguments, and end with a formal proof as a summary. As in Example 6.2.1, the statement to be proved is universal, and so, by the method of generalizing from the generic particular, the proof has the following outline:

Starting Point: Suppose A, B, and C are arbitrarily chosen sets. To Show: A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C). Now two sets are equal if, and only if, each is a subset of the other. Hence, the following two statements must be proved:

A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C) and (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C). Showing the first containment requires showing that

∀x, if x ∈ A ∪ (B ∩ C) then x ∈ (A ∪ B) ∩ (A ∪ C). Showing the second containment requires showing that

∀x, if x ∈ (A ∪ B) ∩ (A ∪ C) then x ∈ A ∪ (B ∩ C). Note that both of these statements are universal. So to prove the first containment, you

suppose you have any element x in A ∪ (B ∩ C), and then you show that x ∈ (A ∪ B) ∩ (A ∪ C). And to prove the second containment, you

suppose you have any element x in (A ∪ B) ∩ (A ∪ C), and then you show that x ∈ A ∪ (B ∩ C).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 357

In Figure 6.2.1, the structure of the proof is illustrated by the kind of diagram that is often used in connection with structured programs. The analysis in the diagram reduces the proof to two concrete tasks: filling in the steps indicated by dots in the two center boxes of Figure 6.2.1.

Suppose A, B, and C are sets. [Show A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C). That is, show A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C) and (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C).]

Show A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C). [That is, show ∀x, if x ∈ A ∪ (B ∩ C) then x ∈ (A ∪ B) ∩ (A ∪ C).]

Suppose x ∈ A ∪ (B ∩ C). [Show x ∈ (A ∪ B) ∩ (A ∪ C).] ...

Thus x ∈ (A ∪ B) ∩ (A ∪ C).

Hence A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C).

Show (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C). [That is, show ∀x, if x ∈ (A ∪ B) ∩ (A ∪ C) then x ∈ A ∪ (B ∩ C).]

Suppose x ∈ (A ∪ B) ∩ (A ∪ C). [Show x ∈ A ∪ (B ∩ C).] ...

Thus x ∈ A ∪ (B ∩ C).

Hence (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C).

Thus (A ∪ B) ∩ (A ∪ C) = A ∪ (B ∩ C).

Figure 6.2.1

Filling in the missing steps in the top box: To fill in these steps, you go from the supposition that x ∈ A ∪ (B ∩ C) to the con-

clusion that x ∈ (A ∪ B) ∩ (A ∪ C). Now when x ∈ A ∪ (B ∩ C), then by definition of union, x ∈ A or x ∈ B ∩ C . But

either of these possibilities might be the case because x is assumed to be chosen arbi- trarily from the set A ∪ (B ∩ C). So you have to show you can reach the conclusion that x ∈ (A ∪ B) ∩ (A ∪ C) regardless of whether x happens to be in A or x happens to be in B ∩ C . This leads you to break your analysis into two cases: x ∈ A and x ∈ B ∩ C .

In case x ∈ A, your goal is to show that x ∈ (A ∪ B) ∩ (A ∪ C), which means that x ∈ A ∪ B and x ∈ A ∪ C (by definition of intersection). But when x ∈ A, both statements x ∈ A ∪ B and x ∈ A ∪ C are true by virtue of x’s being in A.

Similarly, in case x ∈ B ∩ C , your goal is also to show that x ∈ (A ∪ B) ∩ (A ∪ C), which means that x ∈ A ∪ B and x ∈ A ∪ C . But when x ∈ B ∩ C , then x ∈ B and x ∈ C (by definition of intersection), and so x ∈ A ∪ B (by virtue of being in B) and x ∈ A ∪ C (by virtue of being in C).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

358 Chapter 6 Set Theory

This analysis shows that regardless of whether x ∈ A or x ∈ B ∩ C , the conclusion x ∈ (A ∪ B) ∩ (A ∪ C) follows. So you can fill in the steps in the top inner box. Filling in the missing steps in the bottom box:

To fill in these steps, you need to go from the supposition that x ∈ (A ∪ B) ∩ (A ∪ C) to the conclusion that x ∈ A ∪ (B ∩ C).

When x ∈ (A ∪ B) ∩ (A ∪ C) it is natural to consider the two cases x ∈ A and x ̸∈ A because when x happens to be in A, then the statement “x ∈ A or x ∈ B ∩ C” is certainly true, and so x is in A ∪ (B ∩ C) by definition of union. Thus it remains only to show that even in the case when x is not in A, and x ∈ (A ∪ B) ∩ (A ∪ C), then x ∈ A ∪ (B ∩ C).

So suppose x is not in A. Now to say that x ∈ (A ∪ B) ∩ (A ∪ C) means that x ∈ A ∪ B and x ∈ A ∪ C (by definition of intersection). But when x ∈ A ∪ B, then x is in at least one of A or B, so since x is not in A, then x must be in B. Similarly, when x ∈ A ∪ C , then x is in at least one of A or C , so since x is not in A, then x must be in C . Thus, when x is not in A and x ∈ (A ∪ B) ∩ (A ∪ C), then x is in both B and C , which means that x ∈ B ∩ C . It follows that the statement “x ∈ A or x ∈ B ∩ C” is true, and so x ∈ A ∪ (B ∩ C) by definition of union.

This analysis shows that if x ∈ (A ∪ B) ∩ (A ∪ C), then regardless of whether x ∈ A or x /∈ A, you can conclude that x ∈ A ∪ (B ∩ C). Hence you can fill in the steps of the bottom inner box.

A formal proof is shown below.

Theorem 6.2.2(3)(a) A Distributive Law for Sets

For all sets A, B, and C ,

A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).

Proof:

Suppose A and B are sets.

Proof that A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C): Suppose x ∈ A ∪ (B ∩ C). By definition of union, x ∈ A or x ∈ B ∩ C . Case 1 (x ∈ A): Since x ∈ A, then x ∈ A ∪ B by definition of union and also x ∈ A ∪ C by definition of union. Hence x ∈ (A ∪ B) ∩ (A ∪ C) by definition of intersection.

Case 2 (x ∈ B ∩ C): Since x ∈ B ∩ C , then x ∈ B and x ∈ C by definition of inter- section. Since x ∈ B, x ∈ A ∪ B and since x ∈ C, x ∈ A ∪ C , both by definition of union. Hence x ∈ (A ∪ B) ∩ (A ∪ C) by definition of intersection. In both cases, x ∈ (A ∪ B) ∩ (A ∪ C). Hence A ∪ (B ∩ C) ⊆ (A ∪ B) ∩ (A ∪ C) by definition of subset.

Proof that (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C): Suppose x ∈ (A ∪ B) ∩ (A ∪ C). By definition of intersection, x ∈ A ∪ B and x ∈ A ∪ C . Consider the two cases x ∈ A and x /∈ A. Case 1 (x ∈ A): Since x ∈ A, we can immediately conclude that x ∈ A ∪ (B ∩ C) by definition of union.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 359

Case 2 (x /∈ A): Since x ∈ A ∪ B, x is in at least one of A or B. But x is not in A; hence x is in B. Similarly, since x ∈ A ∪ C, x is in at least one of A or C . But x is not in A; hence x is in C . We have shown that both x ∈ B and x ∈ C , and so by definition of intersection, x ∈ B ∩ C . It follows by definition of union that x ∈ A ∪ (B ∩ C). In both cases x ∈ A ∪ (B ∩ C). Hence, by definition of subset, (A ∪ B) ∩ (A ∪ C) ⊆ A ∪ (B ∩ C). Conclusion: Since both subset relations have been proved, it follows by definition of set equality that A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).

In the study of artificial intelligence, the types of reasoning used previously to derive the proof of the distributive law are called forward chaining and backward chaining. First what is to be shown is viewed as a goal to be reached starting from a certain initial position: the starting point. Analysis of this goal leads to the realization that if a certain job is accomplished, then the goal will be reached. Call this job subgoal 1: SG1. (For instance, if the goal is to show that A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C), then SG1 would be to show that each set is a subset of the other.) Analysis of SG1 shows that when yet another job is completed, SG1 will be reached. Call this job subgoal 2: SG2. Continuing in this way, a chain of argument leading backward from the goal is constructed.

starting point → SG3 → SG2 → SG1 → goal

At a certain point, backward chaining becomes difficult, but analysis of the current subgoal suggests it may be reachable by a direct line of argument, called forward chain- ing, beginning at the starting point. Using the information contained in the starting point, another piece of information, I1, is deduced; from that another piece of information, I2, is deduced; and so forth until finally one of the subgoals is reached. This completes the chain and proves the theorem. A completed chain is illustrated below.

starting point → I1 → I2 → I3 → I4 → SG3 → SG2 → SG1 → goal

Since set complement is defined in terms of not, and since unions and intersections are defined in terms of or and and, it is not surprising that there are analogues of De Morgan’s laws of logic for sets.

Example 6.2.3 Proof of a De Morgan’s Law for Sets

Prove that for all sets A and B, (A ∪ B)c = Ac ∩ Bc.

Solution As in previous examples, the statement to be proved is universal, and so the start- ing point of the proof and the conclusion to be shown are as follows:

Starting Point: Suppose A and B are arbitrarily chosen sets. To Show: (A ∪ B)c = Ac ∩ Bc To do this, you must show that (A ∪ B)c ⊆ Ac ∩ Bc and that Ac ∩ Bc ⊆ (A ∪ B)c. To show the first containment means to show that

∀x, if x ∈ (A ∪ B)c then x ∈ Ac ∩ Bc.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

360 Chapter 6 Set Theory

And to show the second containment means to show that

∀x, if x ∈ Ac ∩ Bc then x ∈ (A ∪ B)c.

Since each of these statements is universal and conditional, for the first containment, you

suppose x ∈ (A ∪ B)c,

and then you show that x ∈ Ac ∩ Bc.

And for the second containment, you

suppose x ∈ Ac ∩ Bc,

and then you show that x ∈ (A ∪ B)c.

To fill in the steps of these arguments, you use the procedural versions of the definitions of complement, union, and intersection, and at crucial points you use De Morgan’s laws of logic.

Theorem 6.2.2(9)(a) A De Morgan’s Law for Sets

For all sets A and B, (A ∪ B)c = Ac ∩ Bc.

Proof: Suppose A and B are sets.

Proof that (A ∪ B)c ⊆ Ac ∩ Bc: [We must show that ∀x, if x ∈ (A ∪ B)c then x ∈ Ac ∩ Bc.]

Suppose x ∈ (A ∪ B)c. [We must show that x ∈ Ac ∩ Bc.] By definition of complement,

x /∈ A ∪ B.

But to say that x /∈ A ∪ B means that

it is false that (x is in A or x is in B).

By De Morgan’s laws of logic, this implies that

x is not in A and x is not in B,

which can be written x /∈ A and x /∈ B.

Hence x ∈ Ac and x ∈ Bc by definition of complement. It follows, by definition of intersection, that x ∈ Ac ∩ Bc [as was to be shown]. So (A ∪ B)c ⊆ Ac ∩ Bc by definition of subset.

Proof that Ac ∩ Bc ⊆ (A ∪ B)c: [We must show that ∀x, if x ∈ Ac ∩ Bc then x ∈ (A ∪ B)c.]

Suppose x ∈ Ac ∩ Bc. [We must show that x ∈ (A ∪ B)c.] By definition of intersection, x ∈ Ac and x ∈ Bc, and by definition of complement,

x /∈ A and x /∈ B.

In other words, x is not in A and x is not in B.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 361

By De Morgan’s laws of logic this implies that

it is false that (x is in A or x is in B),

which can be written x /∈ A ∪ B by definition of union. Hence, by definition of complement, x ∈ (A ∪ B)c [as was to be shown]. It follows that Ac ∩ Bc ⊆ (A ∪ B)c by definition of subset. Conclusion: Since both set containments have been proved, (A ∪ B)c = Ac ∩ Bc by definition of set equality.

The set property given in the next theorem says that if one set is a subset of another, then their intersection is the smaller of the two sets and their union is the larger of the two sets.

Theorem 6.2.3 Intersection and Union with a Subset

For any sets A and B, if A ⊆ B, then (a) A ∩ B = A and (b) A ∪ B = B.

Proof:

Part (a): Suppose A and B are sets with A ⊆ B. To show part (a) we must show both that A ∩ B ⊆ A and that A ⊆ A ∩ B. We already know that A ∩ B ⊆ A by the inclusion of intersection property. To show that A ⊆ A ∩ B, let x ∈ A. [We must show that x ∈ A ∩ B.] Since A ⊆ B, then x ∈ B also. Hence

x ∈ A and x ∈ B, and thus x ∈ A ∩ B by definition of intersection [as was to be shown].

Proof:

Part (b): The proof of part (b) is left as an exercise.

The Empty Set In Section 6.1 we introduced the concept of a set with no elements and promised that in this section we would show that there is only one such set. To do so, we start with the most basic—and strangest—property of a set with no elements: It is a subset of every set. To see why this is true, just ask yourself, “Could it possibly be false? Could there be a set without elements that is not a subset of some given set?” The crucial fact is that the negation of a universal statement is existential: If a set B is not a subset of a set A, then there exists an element in B that is not in A. But if B has no elements, then no such element can exist.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

362 Chapter 6 Set Theory

Theorem 6.2.4 A Set with No Elements Is a Subset of Every Set

If E is a set with no elements and A is any set, then E ⊆ A.

Proof (by contradiction):

Suppose not. [We take the negation of the theorem and suppose it to be true.] Suppose there exists a set E with no elements and a set A such that E ! A. [We must deduce a contradiction.] Then there would be an element of E that is not an element of A [by definition of subset]. But there can be no such element since E has no elements. This is a contradiction. [Hence the supposition that there are sets E and A, where E has no elements and E ! A, is false, and so the theorem is true.]

The truth of Theorem 6.2.4 can also be understood by appeal to the notion of vacuous truth. If E is a set with no elements and A is any set, then to say that E ⊆ A is the same as saying that

∀x, if x ∈ E, then x ∈ A. But since E has no elements, this conditional statement is vacuously true.

How many sets with no elements are there? Only one.

Corollary 6.2.5 Uniqueness of the Empty Set

There is only one set with no elements.

Proof:

Suppose E1 and E2 are both sets with no elements. By Theorem 6.2.4, E1 ⊆ E2 since E1 has no elements. Also E2 ⊆ E1 since E2 has no elements. Thus E1 = E2 by definition of set equality.

It follows from Corollary 6.2.5 that the set of pink elephants is equal to the set of all real numbers whose square is −1 because each set has no elements! Since there is only one set with no elements, we are justified in calling it by a special name, the empty set (or null set) and in denoting it by the special symbol ∅.

Note that whereas ∅ is the set with no elements, the set {∅} has one element, the empty set. This is similar to the convention in the computer programming languages LISP and Scheme, in which ( ) denotes the empty list and (( )) denotes the list whose one element is the empty list.

Suppose you need to show that a certain set equals the empty set. By Corollary 6.2.5 it suffices to show that the set has no elements. For since there is only one set with no elements (namely ∅), if the given set has no elements, then it must equal ∅.

Element Method for Proving a Set Equals the Empty Set

To prove that a set X is equal to the empty set ∅, prove that X has no elements. To do this, suppose X has an element and derive a contradiction.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 363

Example 6.2.4 Proving That a Set Is Empty

Prove Theorem 6.2.2(8)(b). That is, prove that for any set A, A ∩ ∅ = ∅. Solution Let A be a [particular, but arbitrarily chosen] set. To show that A ∩ ∅ = ∅, it suf-

fices to show that A ∩ ∅ has no elements [by the element method for proving a set equals the empty set]. Suppose not. That is, suppose there is an element x such that x ∈ A ∩ ∅. Then, by definition of intersection, x ∈ A and x ∈ ∅. In particular, x ∈ ∅. But this is impossible since ∅ has no elements. [This contradiction shows that the supposition that there is an element x in A ∩ ∅ is false. So A ∩ ∅ has no elements, as was to be shown.] Thus A ∩ ∅ = ∅. ■

Example 6.2.5 A Proof for a Conditional Statement

Prove that for all sets A, B, and C , if A ⊆ B and B ⊆ Cc, then A ∩ C = ∅.

Solution Since the statement to be proved is both universal and conditional, you start with the method of direct proof:

Suppose A, B, and C are arbitrarily chosen sets that satisfy the condition: A ⊆ B and B ⊆ Cc.

Show that A ∩ C = ∅. Since the conclusion to be shown is that a certain set is empty, you can use the principle for proving that a set equals the empty set. A complete proof is shown below.

Proposition 6.2.6

For all sets A, B, and C , if A ⊆ B and B ⊆ Cc, then A ∩ C = ∅.

Proof:

Suppose A, B, and C are any sets such that A ⊆ B and B ⊆ Cc. We must show that A ∩ C = ∅. Suppose not. That is, suppose there is an element x in A ∩ C . By definition of intersection, x ∈ A and x ∈ C . Then, since A ⊆ B, x ∈ B by definition of subset. Also, since B ⊆ Cc, then x ∈ Cc by definition of subset again. It follows by definition of complement that x /∈ C . Thus x ∈ C and x /∈ C , which is a con- tradiction. So the supposition that there is an element x in A ∩ C is false, and thus A ∩ C = ∅ [as was to be shown].

Example 6.2.6 A Generalized Distributive Law

Prove that for all sets A and B1, B2, B3, . . . , Bn ,

A ∪ (

n⋂ i=1

Bi

) =

n⋂ i=1

(A ∪ Bi ).

Solution Compare this proof to the one given in Example 6.2.2. Although the notation is more complex, the basic ideas are the same.

Proof:

Suppose A and B1, B2, B3, . . . , Bn are any sets.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

364 Chapter 6 Set Theory

Part 1, Proof that A ∪ (

n⋂ i=1

Bi

) ⊆

n⋂ i=1

(A ∪ Bi):

Suppose x is any element in A ∪ (

n⋂ i=1

Bi

) . [We must show that x is in

n⋂ i=1

(A ∪ Bi ).]

By definition of union, x ∈ A or x ∈ n⋂

i=1 Bi .

Case 1, x ∈ A: In this case, it is true by definition of union that for all i = 1, 2, . . . , n, x ∈ A ∪ Bi . Hence x ∈

n⋂ i=1

(A ∪ Bi ).

Case 2, x ∈ n⋂

i=1 Bi: In this case, by definition of the general intersection, we have that for

all integers i = 1, 2, . . . , n, x ∈ Bi . Hence, by definition of union, for all integers i = 1, 2, . . . , n, x ∈ A ∪ Bi , and so, by definition of general intersection, x ∈

n⋂ i=1

(A∪ Bi ).

Thus, in either case, x ∈ n⋂

i=1 (A ∪ Bi ) [as was to be shown].

Part 2, Proof that n⋂

i=1 (A ∪ Bi ) ⊆ A ∪

( n⋂

i=1 Bi

) :

Suppose x is any element in n⋂

i=1 (A ∪ Bi ). [We must show that x is in A ∪

( n⋂

i=1 Bi

) .]

By definition of intersection, x ∈ A ∪ Bi for all integers i = 1, 2, . . . , n. Either x ∈ A or x ̸∈ A. Case 1, x ∈ A: In this case, x ∈ A ∪

( n⋂

i=1 Bi

) by definition of union.

Case 2, x ̸∈ A: By definition of intersection, x ∈ A ∪ Bi for all integers i = 1, 2, . . . , n. Since x ̸∈ A, x must be in each Bi for every integer i = 1, 2, . . . , n. Hence, by definition of intersection, x ∈

n⋂ i=1

Bi , and so, by definition of union, x ∈ A ∪ (

n⋂ i=1

Bi

) .

Conclusion: Since both set containments have been proved, it follows by definition of set

equality that A ∪ (

n⋂ i=1

Bi

) =

n⋂ i=1

(A ∪ Bi ). ■

Test Yourself 1. To prove that a set X is a subset of a set A ∩ B, you suppose

that x is any element of X and you show that x ∈ A _____ x ∈ B.

2. To prove that a set X is a subset of a set A ∪ B, you suppose that x is any element of X and you show that x ∈ A _____ x ∈ B.

3. To prove that a set A ∪ B is a subset of a set X , you start with any element x in A ∪ B and consider the two cases _____ and _____. You then show that in either case _____.

4. To prove that a set A ∩ B is a subset of a set X , you suppose that _____ and you show that _____.

5. To prove that a set X equals a set Y , you prove that _____ and that _____.

6. To prove that a set X does not equal a set Y , you need to find an element that is in _____ and not _____ or that is in _____ and not _____.

Exercise Set 6.2 1. a. To say that an element is in A ∩ (B ∪ C) means that it is

in (1) and in (2) . b. To say that an element is in (A ∩ B) ∪ C means that it is

in (1) or in (2) . c. To say that an element is in A − (B ∩ C) means that it

is in (1) and not in (2) .

2. The following are two proofs that for all sets A and B, A − B ⊆ A. The first is less formal, and the second is more formal. Fill in the blanks.

a. Proof: Suppose A and B are any sets. To show that A − B ⊆ A, we must show that every element in (1) is in (2) . But any element in A − B is in (3) and not

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.2 Properties of Sets 365

in (4) (by definition of A − B). In particular, such an element is in A.

b. Proof: Suppose A and B are any sets and x ∈ A − B. [We must show that (1) .] By definition of set difference, x ∈ (2) and x /∈ (3) . In particular, x ∈ (4) [which is what was to be shown].

3. The following is a proof that for all sets A, B, and C , if A ⊆ B and B ⊆ C , then A ⊆ C . Fill in the blanks. Proof: Suppose A, B, and C are sets and A ⊆ B and B ⊆ C . To show that A ⊆ C , we must show that every ele- ment in (a) is in (b) . But given any element in A, that element is in (c) (because A ⊆ B), and so that element is also in (d) (because (e) ). Hence A ⊆ C .

4. The following is a proof that for all sets A and B, if A ⊆ B, then A ∪ B ⊆ B. Fill in the blanks. Proof: Suppose A and B are any sets and A ⊆ B. [We must show that (a) .] Let x ∈ (b) . [We must show that (c) .] By definition of union, x ∈ (d) (e) x ∈ (f ) . In

case x ∈ (g) , then since A ⊆ B, x ∈ (h) . In case x ∈ B, then clearly x ∈ B. So in either case, x ∈ (i) [as was to be shown].

5. Prove that for all sets A and B, (B − A) = B ∩ Ac. 6.H The following is a proof that for any sets A, B, and C ,

A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C). Fill in the blanks. Proof: Suppose A, B, and C are any sets.

(1) Proof that A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C): Let x ∈ A ∩ (B ∪ C). [We must show that x ∈ (a) .] By definition of intersection, x ∈ (b) and x ∈ (c) . Thus x ∈ A and, by definition of union, x ∈ B or (d) . Case 1 (x ∈ A and x ∈ B): In this case, by definition of intersection, x ∈ (e) , and so, by definition of union, x ∈ (A ∩ B) ∪ (A ∩ C). Case 2 (x ∈ A and x ∈ C): In this case, (f ) . Hence in either case, x ∈ (A ∩ B) ∪ (A ∩ C) [as was to be shown]. [So A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) by definition of subset.]

(2) (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C): Let x ∈ (A ∩ B) ∪ (A ∩ C). [We must show that (a) .] By definition of union, x ∈ A ∩ B (b ) x ∈ A ∩ C . Case 1 (x ∈ A ∩ B): In this case, by definition of intersec- tion, x ∈ A (c ) x ∈ B. Since x ∈ B, then by definition of union, x ∈ B ∪ C . Hence x ∈ A and x ∈ B ∪ C , and so, by definition of intersection, x ∈ (d ) . Case 2 (x ∈ A ∩ C): In this case, (e) . In either case, x ∈ A ∩ (B ∪ C) [as was to be shown]. [Thus (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C) by definition of subset.] (3) Conclusion: [Since both subset relations have been proved, it follows, by definition of set equality, that (a) .]

Use an element argument to prove each statement in 7–19. Assume that all sets are subsets of a universal set U .

7.H For all sets A and B, (A ∩ B)c = Ac ∪ Bc. 8. For all sets A and B, (A ∩ B) ∪ (A ∩ Bc) = A. 9.H For all sets A, B, and C ,

(A − B) ∪ (C − B) = (A ∪ C)− B. 10. For all sets A, B, and C ,

(A − B) ∩ (C − B) = (A ∩ C)− B.

11.H For all sets A and B, A ∪ (A ∩ B) = A. 12. For all sets A, A ∪ ∅ = A. 13. For all sets A, B, and C , if A ⊆ B then A ∩ C ⊆ B ∩ C . 14. For all sets A, B, and C , if A ⊆ B then A ∪ C ⊆ B ∪ C . 15. For all sets A and B, if A ⊆ B then Bc ⊆ Ac. 16.H For all sets A, B, and C , if A ⊆ B and A ⊆ C then

A ⊆ B ∩ C. 17. For all sets A, B, and C , if A ⊆ C and B ⊆ C then

A ∪ B ⊆ C . 18. For all sets A, B, and C ,

A × (B ∪ C) = (A × B) ∪ (A × C). 19. For all sets A, B, and C ,

A × (B ∩ C) = (A × B) ∩ (A × C). 20. Find the mistake in the following “proof” that for all sets

A, B, and C , if A ⊆ B and B ⊆ C then A ⊆ C . “Proof: Suppose A, B, and C are sets such that A ⊆ B and B ⊆ C . Since A ⊆ B, there is an element x such that x ∈ A and x ∈ B. Since B ⊆ C , there is an element x such that x ∈ B and x ∈ C . Hence there is an element x such that x ∈ A and x ∈ C and so A ⊆ C .”

21.H Find the mistake in the following “proof.”

“Theorem:” For all sets A and B, Ac ∪ Bc ⊆ (A ∪ B)c. “Proof: Suppose A and B are sets, and x ∈ Ac ∪ Bc. Then x ∈ Ac or x ∈ Bc by definition of union. It follows that x /∈ A or x /∈ B by definition of complement, and so x /∈ A ∪ B by definition of union. Thus x ∈ (A ∪ B)c by definition of complement, and hence Ac ∪ Bc ⊆ (A ∪ B)c.”

22. Find the mistake in the following “proof” that for all sets A and B, (A − B) ∪ (A ∩ B) ⊆ A. “Proof: Suppose A and B are sets, and suppose x ∈ (A − B) ∪ (A ∩ B). If x ∈ A then x ∈ A − B. Then, by definition of difference, x ∈ A and x /∈ B. Hence x ∈ A, and so (A − B) ∪ (A ∩ B) ⊆ A by definition of subset.”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

366 Chapter 6 Set Theory

23. Consider the Venn diagram below.

A B

C

U

a. Illustrate one of the distributive laws by shading in the region corresponding to A ∪ (B ∩ C) on one copy of the diagram and (A ∪ B) ∩ (A ∪ C) on another.

b. Illustrate the other distributive law by shading in the region corresponding to A ∩ (B ∪ C) on one copy of the diagram and (A ∩ B) ∪ (A ∩ C) on another.

c. Illustrate one of De Morgan’s laws by shading in the region corresponding to (A ∪ B)c on one copy of the diagram and Ac ∩ Bc on the other. (Leave the set C out of your diagrams.)

d. Illustrate the other De Morgan’s law by shading in the region corresponding to (A ∩ B)c on one copy of the diagram and Ac ∪ Bc on the other. (Leave the set C out of your diagrams.)

24. Fill in the blanks in the following proof that for all sets A and B, (A − B) ∩ (B − A) = ∅. Proof: Let A and B be any sets and supppose (A − B) ∩ (B − A) ̸= ∅. That is, suppose there were an element x in (a) . By definition of (b) , x ∈ A − B and x ∈ (c) . Then by definition of set difference, x ∈ A and x /∈ B and x ∈ (d) and x /∈ (e) . In particular x ∈ A and x /∈ (f ) , which is a contradiction. Hence [the supposition that (A − B) ∩ (B − A) ̸= ∅ is false, and so] (g) .

Use the element method for proving a set equals the empty set to prove each statement in 25–35. Assume that all sets are subsets of a universal set U .

25. For all sets A and B, (A ∩ B) ∩ (A ∩ Bc) = ∅. 26. For all sets A, B, and C,

(A − C) ∩ (B − C) ∩ (A − B) = ∅.

27. For all subsets A of a universal set U, A ∩ Ac = ∅.

28. If U denotes a universal set, then U c = ∅. 29. For all sets A, A × ∅ = ∅. 30. For all sets A and B, if A ⊆ B then A ∩ Bc = ∅. 31. For all sets A and B, if B ⊆ Ac then A ∩ B = ∅. 32. For all sets A, B, and C , if A ⊆ B and B ∩ C = ∅ then

A ∩ C = ∅. 33. For all sets A, B, and C , if C ⊆ B − A, then A ∩ C = ∅. 34. For all sets A, B, and C ,

if B ∩ C ⊆ A, then (C − A) ∩ (B − A) = ∅. 35. For all sets A, B, C , and D,

if A ∩ C = ∅ then (A × B) ∩ (C × D) = ∅. Prove each statement in 36–41.

36.H For all sets A and B, a. (A − B) ∪ (B − A) ∪ (A ∩ B) = A ∪ B b. The sets (A − B), (B − A), and (A ∩ B) are mutually

disjoint.

37. For all integers n ≥ 1, if A and B1, B2, B3, . . . are any sets, then

A ∩ (

n⋃ i=1

Bi

) =

n⋃ i=1

(A ∩ Bi ).

38.H For all integers n ≥ 1, if A1, A2, A3, . . . and B are any sets, then

n⋃ i=1

(Ai − B) = (

n⋃ i=1

Ai

) − B.

39. For all integers n ≥ 1, if A1, A2, A3, . . . and B are any sets, then

n⋂ i=1

(Ai − B) = (

n⋂ i=1

Ai

) − B.

40. For all integers n ≥ 1, if A and B1, B2, B3, . . . are any sets, then

n⋃ i=1

(A × Bi ) = A × (

n⋃ i=1

Bi

) .

41. For all integers n ≥ 1, if A and B1, B2, B3, . . . are any sets, then

n⋂ i=1

(A × Bi ) = A × (

n⋂ i=1

Bi

) .

Answers for Test Yourself 1. and 2. or 3. x ∈ A; x ∈ B; x ∈ X 4. x ∈ A ∩ B (Or: x is an element of both A and B); x ∈ X 5. X ⊆ Y ; Y ⊆ X 6. X; in Y ; Y ; in X

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras 367

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras If a fact goes against common sense, and we are nevertheless compelled to accept and deal with this fact, we learn to alter our notion of common sense. —Phillip J. Davis and Reuben Hersh, The Mathematical Experience, 1981

In Section 6.2 we gave examples only of set properties that were true. Occasionally, however, a proposed set property is false. We begin this section by discussing how to disprove such a proposed property. Then we prove an important theorem about the power set of a set and go on to discuss an “algebraic” method for deriving new set properties from set properties already known to be true. We finish the section with an introduction to Boolean algebras.

Disproving an Alleged Set Property Recall that to show a universal statement is false, it suffices to find one example (called a counterexample) for which it is false.

Example 6.3.1 Finding a Counterexample for a Set Identity

Is the following set property true?

For all sets A, B, and C, (A − B) ∪ (B − C) = A − C. Solution Observe that the property is true if, and only if,

the given equality holds for all sets A, B, and C.

So it is false if, and only if,

there are sets A, B, and C for which the equality does not hold.

One way to solve this problem is to picture sets A, B, and C by drawing a Venn diagram such as that shown in Figure 6.3.1. If you assume that any of the eight regions of the diagram may be empty of points, then the diagram is quite general.

U

A B

C

Figure 6.3.1

Find and shade the region corresponding to (A − B) ∪ (B − C). Then shade the region corresponding to A − C . These are shown in Figure 6.3.2 on the next page.

Comparing the shaded regions seems to indicate that the property is false. For instance, if there is an element in B that is not in either A or C then this element would be in (A − B) ∪ (B − C) (because of being in B and not C) but it would not be in A − C since A − C contains nothing outside A. Similarly, an element that is in both A and C but not B would be in (A − B) ∪ (B − C) (because of being in A and not B), but it would not be in A − C (because of being in both A and C).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

368 Chapter 6 Set Theory

U U

A B

C

A B

C

Figure 6.3.2

Construct a concrete counterexample in order to confirm your answer and make sure that you did not make a mistake either in drawing or analyzing your diagrams. One way is to put one of the integers from 1–7 into each of the seven subregions enclosed by the circles representing A, B, and C . If the proposed set property had involved set comple- ments, it would also be helpful to label the region outside the circles, and so we place the number 8 there. (See Figure 6.3.3.) Then define discrete sets A, B, and C to consist of all the numbers in their respective subregions.

1 2 3

4 6 5

7 8

U

A B

C

Figure 6.3.3

Counterexample 1: Let A = {1, 2, 4, 5}, B = {2, 3, 5, 6}, and C = {4, 5, 6, 7}. Then

A − B = {1, 4}, B − C = {2, 3}, and A − C = {1, 2}. Hence

(A − B) ∪ (B − C) = {1, 4} ∪ {2, 3} = {1, 2, 3, 4}, whereas A − C = {1, 2}. Since {1, 2, 3, 4} ̸= {1, 2}, we have that (A − B) ∪ (B − C) ̸= A − C .

A more economical counterexample can be obtained by observing that as long as the set B contains an element, such as 3, that is not in A, then regardless of whether B contains any other elements and regardless of whether A and C contain any elements at all, (A − B) ∪ (B − C) ̸= A − C .

Counterexample 2: Let A = ∅, B = {3}, and C = ∅. Then A − B = ∅, B − C = {3}, and A − C = ∅.

Hence (A − B) ∪ (B − C) = ∅ ∪ {3} = {3}, whereas A − C = ∅. Since {3} ̸= ∅, we have that (A − B) ∪ (B − C) ̸= A − C .

Note Check that when A = C = {4} and B = ∅, (A − B) ∪ (B − C) ̸= A − C .

Another economical counterexample requires only that A = C = a singleton set, such as {4}, while B is the empty set.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras 369

Problem-Solving Strategy How can you discover whether a given universal statement about sets is true or false?

There are two basic approaches: the optimistic and the pessimistic. In the optimistic approach, you simply plunge in and start trying to prove the statement, asking yourself, “What do I need to show?” and “How do I show it?” In the pessimistic approach, you start by searching your mind for a set of conditions that must be fulfilled to construct a counterexample. With either approach you may have clear sailing and be immediately successful or you may run into difficulty. The trick is to be ready to switch to the other approach if the one you are trying does not look promising. For more difficult questions, you may alternate several times between the two approaches before arriving at the correct answer.

The Number of Subsets of a Set The following theorem states the important fact that if a set has n elements, then its power set has 2n elements. The proof uses mathematical induction and is based on the following observations. Suppose X is a set and z is an element of X .

1. The subsets of X can be split into two groups: those that do not contain z and those that do contain z.

2. The subsets of X that do not contain z are the same as the subsets of X − {z}. 3. The subsets of X that do not contain z can be matched up one for one with the subsets

of X that do contain z by matching each subset A that does not contain z to the subset A ∪ {z} that contains z. Thus there are as many subsets of X that contain z as there are subsets of X that do not contain z. For instance, if X = {x, y, z}, the following table shows the correspondence between subsets of X that do not contain z and subsets of X that contain z.

Subsets of X That Subsets of X That Do Not Contain z Contain z

∅ ←→ ∅ ∪ {z} = {z} {x} ←→ {x} ∪ {z} = {x, z} {y} ←→ {y} ∪ {z} = {y, z}

{x, y} ←→ {x, y} ∪ {z} = {x, y, z}

Theorem 6.3.1

For all integers n ≥ 0, if a set X has n elements, then P(X) has 2n elements.

Proof (by mathematical induction):

Let the property P(n) be the sentence

Any set with n elements has 2n subsets. ← P(n)

Show that P(0) is true: To establish P(0), we must show that

Any set with 0 elements has 20 subsets. ← P(0)

continued on page 370

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

370 Chapter 6 Set Theory

But the only set with zero elements is the empty set, and the only subset of the empty set is itself. Thus a set with zero elements has one subset. Since 1 = 20, we have that P(0) is true.

Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is also true: [Suppose that P(k) is true for a particular but arbitrarily chosen integer k ≥ 0. That is:] Suppose that k is any integer with k ≥ 0 such that

Any set with k elements has 2k subsets. ← P(k) inductive hypothesis

[We must show that P(k + 1) is true. That is:] We must show that

Any set with k + 1 elements has 2k+1 subsets. ← P(k + 1)

Let X be a set with k + 1 elements. Since k + 1 ≥ 1, we may pick an element z in X . Observe that any subset of X either contains z or not. Furthermore, any subset of X that does not contain z is a subset of X − {z}. And any subset A of X − {z} can be matched up with a subset B, equal to A ∪ {z}, of X that contains z. Consequently, there are as many subsets of X that contain z as do not, and thus there are twice as many subsets of X as there are subsets of X − {z}. But X − {z} has k elements, and so

the number of subsets of X − {z} = 2k by inductive hypothesis.

Therefore,

the number of subsets of X = 2 ·(the number of subsets of X − {z}) = 2 ·(2k) by substitution = 2k+1 by basic algebra.

[This is what was to be shown.] [Since we have proved both the basis step and the inductive step, we conclude that the theorem is true.]

“Algebraic” Proofs of Set Identities Let U be a universal set and consider the power set of U,P(U ). The set identities given in Theorem 6.2.2 hold for all elements of P(U ). Once a certain number of identities and other properties have been established, new properties can be derived from them alge- braically without having to use element method arguments. It turns out that only identi- ties (1–5) of Theorem 6.2.2 are needed to prove any other identity involving only unions, intersections, and complements. With the addition of identity (12), the set difference law, any set identity involving unions, intersections, complements, and set differences can be established.

To use known properties to derive new ones, you need to use the fact that such properties are universal statements. Like the laws of algebra for real numbers, they apply to a wide variety of different situations. Assume that all sets are subsets of P(U ), then, for instance, one of the distributive laws states that

for all sets A, B, and C, A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras 371

This law can be viewed as a general template into which any three particular sets can be placed. Thus, for example, if A1, A2, and A3 represent particular sets, then

A1︸︷︷︸ ∩ ( A2︸︷︷︸∪ A3︸︷︷︸)=( A1︸︷︷︸∩ A2︸︷︷︸) ∪ ( A1︸︷︷︸∩ A3︸︷︷︸), A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

where A1 plays the role of A, A2 plays the role of B, and A3 plays the role of C . Similarly, if W, X, Y , and Z are any particular sets, then, by the distributive law,

(W ∩ X︸ ︷︷ ︸) ∩ (Y ∪ Z) = ((W ∩ X︸ ︷︷ ︸) ∩ Y ) ∪ ((W ∩ X︸ ︷︷ ︸) ∩ Z), ↕ ↕ ↕ ↕ ↕ ↕ ↕ A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

where W ∩ X plays the role of A, Y plays the role of B, and Z plays the role of C .

Example 6.3.2 Deriving a Set Difference Property

Construct an algebraic proof that for all sets A, B, and C ,

(A ∪ B)− C = (A − C) ∪ (B − C). Cite a property from Theorem 6.2.2 for every step of the proof.

Solution Let A, B, and C be any sets. Then

(A ∪ B)− C = (A ∪ B) ∩ Cc by the set difference law = Cc ∩ (A ∪ B) by the commutative law for ∩ = (Cc ∩ A) ∪ (Cc ∩ B) by the distributive law = (A ∩ Cc) ∪ (B ∩ Cc) by the commutative law for ∩ = (A − C) ∪ (B − C) by the set difference law. ■

Example 6.3.3 Deriving a Set Identity Using Properties of ∅ Construct an algebraic proof that for all sets A and B,

A − (A ∩ B) = A − B. Cite a property from Theorem 6.2.2 for every step of the proof.

Solution Suppose A and B are any sets. Then

A − (A ∩ B) = A ∩ (A ∩ B)c by the set difference law = A ∩ (Ac ∪ Bc) by De Morgan’s laws = (A ∩ Ac) ∪ (A ∩ Bc) by the distributive law = ∅ ∪ (A ∩ Bc) by the complement law = (A ∩ Bc) ∪ ∅ by the commutative law for ∪ = A ∩ Bc by the identity law for ∪ = A − B by the set difference law. ■

To many people an algebraic proof seems more attractive than an element proof, but often an element proof is actually simpler. For instance, in Example 6.3.3 above, you could see immediately that A − (A ∩ B) = A − B because for an element to be in A − (A ∩ B) means that it is in A and not in both A and B, and this is equivalent to saying that it is in A and not in B.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

372 Chapter 6 Set Theory

Example 6.3.4 Deriving a Generalized Associative Law

Prove that for any sets A1, A2, A3, and A4,

((A1 ∪ A2) ∪ A3) ∪ A4 = A1 ∪ ((A2 ∪ A3) ∪ A4). Cite a property from Theorem 6.2.2 for every step of the proof.

! Caution! When doing problems similar to Examples 6.3.2–6.3.4, be sure to use the set properties exactly as they are stated. Solution Let A1, A2, A3, and A4 be any sets. Then

((A1 ∪ A2) ∪ A3) ∪ A4 = (A1 ∪ (A2 ∪ A3)) ∪ A4 by the associative law for ∪ with A1 playing the role of A, A2 playing the role of B, and A3 playing the role of C

= A1 ∪ ((A2 ∪ A3) ∪ A4) by the associative law for ∪ with A1 playing the role of A, A2 ∪ A3 playing the role of B, and A4 playing the role of C .

Test Yourself 1. Given a proposed set identity involving set variables A, B,

and C , the most common way to show that the equation does not hold in general is to find concrete sets A, B, and C that, when substituted for the set variables in the equation, _____.

2. When using the algebraic method for proving a set identity, it is important to _____ for every step.

3. When applying a property from Theorem 6.2.2, it must be used _____ as it is stated.

Exercise Set 6.3 For each of 1–4 find a counterexample to show that the state- ment is false. Assume all sets are subsets of a universal set U .

1. For all sets A, B, and C, (A ∩ B) ∪ C = A ∩ (B ∪ C). 2. For all sets A and B, (A ∪ B)c = Ac ∪ Bc. 3. For all sets A, B, and C , if A ! B and B ! C then A ! C .

4. For all sets A, B, and C , if B ∩ C ⊆ A then (A − B) ∩ (A − C) = ∅.

For each of 5–21 prove each statement that is true and find a counterexample for each statement that is false. Assume all sets are subsets of a universal set U .

5. For all sets A, B, and C, A − (B − C) = (A − B)− C . 6. For all sets A and B, A ∩ (A ∪ B) = A. 7. For all sets A, B, and C ,

(A − B) ∩ (C − B) = A − (B ∪ C). 8. For all sets A and B, if Ac ⊆ B then A ∪ B = U . 9. For all sets A, B, and C , if A ⊆ C and B ⊆ C then

A ∪ B ⊆ C . 10. For all sets A and B, if A ⊆ B then A ∩ Bc = ∅. 11.H For all sets A, B, and C , if A ⊆ B then A ∩ (B ∩ C)c = ∅. 12.H For all sets A, B, and C ,

A ∩ (B − C) = (A ∩ B)− (A ∩ C). 13. For all sets A, B, and C ,

A ∪ (B − C) = (A ∪ B)− (A ∪ C).

14.H For all sets A, B, and C , if A ∩ C ⊆ B ∩ C and A ∪ C ⊆ B ∪ C , then A ⊆ B.

15.H For all sets A, B, and C , if A ∩ C = B ∩ C and A ∪ C = B ∪ C , then A = B.

16. For all sets A and B, if A ∩ B = ∅ then A × B = ∅. 17. For all sets A and B, if A ⊆ B then P(A) ⊆P(B). 18. For all sets A and B, P(A ∪ B) ⊆P(A) ∪P(B). 19.H For all sets A and B, P(A) ∪P(B) ⊆P(A ∪ B). 20. For all sets A and B, P(A ∩ B) = P(A) ∩P(B). 21. For all sets A and B, P(A × B) = P(A)×P(B). 22. Write a negation for each of the following statements. Indi-

cate which is true, the statement or its negation. Justify your answers. a. ∀ sets S, ∃ a set T such that S ∩ T = ∅. b. ∃ a set S such that ∀ sets T, S ∪ T = ∅.

23.H Let S = {a, b, c} and for each integer i = 0, 1, 2, 3, let Si be the set of all subsets of S that have i elements. List the elements in S0, S1, S2, and S3. Is {S0, S1, S2, S3} a partition of P(S)?

24. Let S = {a, b, c} and let Sa be the set of all subsets of S that contain a, let Sb be the set of all subsets of S that contain b, let Sc be the set of all subsets of S that contain c, and let S∅ be the set whose only element is ∅. Is {Sa, Sb, Sc, S∅} a partition of P(S)?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.3 Disproofs, Algebraic Proofs, and Boolean Algebras 373

25. Let A = {t, u, v, w} and let S1 be the set of all subsets of A that do not contain w and S2 the set of all subsets of A that contain w. a. Find S1. b. Find S2. c. Are S1 and S2 disjoint? d. Compare the sizes of S1 and S2. e. How many elements are in S1 ∪ S2? f. What is the relation between S1 ∪ S2 and P(A)?

26.✶H The following problem, devised by Ginger Bolton, appeared in the January 1989 issue of the College Math- ematics Journal (Vol. 20, No. 1, p. 68): Given a positive integer n ≥ 2, let S be the set of all nonempty subsets of {2, 3, . . . , n}. For each Si ∈ S, let Pi be the product of the elements of Si . Prove or disprove that

2n−1−1∑

i=1 Pi =

(n + 1)! 2

− 1.

In 27 and 28 supply a reason for each step in the derivation.

27. For all sets A, B, and C ,

(A ∪ B) ∩ C = (A ∩ C) ∪ (B ∩ C). Proof: Suppose A, B, and C are any sets. Then

(A ∪ B) ∩ C = C ∩ (A ∪ B) by (a) = (C ∩ A) ∪ (C ∩ B) by (b) = (A ∩ C) ∪ (B ∩ C) by (c) .

28.H For all sets A, B, and C, (A ∪ B)− (C − A) = A ∪ (B − C). Proof: Suppose A, B, and C are any sets. Then

(A ∪ B)− (C − A) = (A ∪ B) ∩ (C − A)c by (a) = (A ∪ B) ∩ (C ∩ Ac)c by (b) = (A ∪ B) ∩ (Ac ∩ C)c by (c) = (A ∪ B) ∩ ((Ac)c ∪ Cc) by (d) = (A ∪ B) ∩ (A ∪ Cc) by (e) = A ∪ (B ∩ Cc) by (f ) = A ∪ (B − C) by (g) .

29.H Some steps are missing from the following proof that for all sets (A ∪ B)− C = (A − C) ∪ (B − C). Indicate what they are, and then write the proof correctly.

Proof: Let A, B, and C be any sets. Then

(A ∪ B)− C = (A ∪ B) ∩ Cc by the set difference law = (A ∩ Cc) ∪ (B ∩ Cc) by the distributive law = (A − C) ∪ (B − C) by the set difference law

In 30–40, construct an algebraic proof for the given statement. Cite a property from Theorem 6.2.2 for every step.

30. For all sets A, B, and C ,

(A ∩ B) ∪ C = (A ∪ C) ∩ (B ∪ C). 31. For all sets A and B, A ∪ (B − A) = A ∪ B.

32. For all sets A and B, (A − B) ∪ (A ∩ B) = A. 33. For all sets A and B, (A − B) ∩ (A ∩ B) = ∅. 34. For all sets A, B, and C ,

(A − B)− C = A − (B ∪ C). 35. For all sets A and B, A − (A − B) = A ∩ B. 36. For all sets A and B, ((Ac ∪ Bc)− A)c = A. 37. For all sets A and B, (Bc ∪ (Bc − A))c = B. 38. For all sets A and B, A − (A ∩ B) = A − B. 39.H For all sets A and B,

(A − B) ∪ (B − A) = (A ∪ B)− (A ∩ B). 40. For all sets A, B, and C ,

(A − B)− (B − C) = A − B. In 41–43 simplify the given expression. Cite a property from Theorem 6.2.2 for every step.

41.H A ∩ ((B ∪ Ac) ∩ Bc) 42. (A − (A ∩ B)) ∩ (B − (A ∩ B)) 43. ((A ∩ (B ∪ C)) ∩ (A − B)) ∩ (B ∪ Cc) 44. Consider the following set property: For all sets A and B,

A − B and B are disjoint. a. Use an element argument to derive the property. b. Use an algebraic argument to derive the property (by

applying properties from Theorem 6.2.2). c. Comment on which method you found easier.

45. Consider the following set property: For all sets A, B, and C, (A − B) ∪ (B − C) = (A ∪ B)− (B ∩ C). a. Use an element argument to derive the property. b. Use an algebraic argument to derive the property (by

applying properties from Theorem 6.2.2). c. Comment on which method you found easier.

Definition: Given sets A and B, the symmetric difference of A and B, denoted A△ B, is

A△ B = (A − B) ∪ (B − A).

46. Let A = {1, 2, 3, 4}, B = {3, 4, 5, 6}, and C = {5, 6, 7, 8}. Find each of the following sets: a. A△ B b. B△C c. A△C d. (A△ B)△C

Refer to the definition of symmetric difference given above. Prove each of 47–52, assuming that A, B, and C are all sub- sets of a universal set U .

47. A△ B = B△ A 48. A△∅ = A 49. A△ Ac = U 50. A△ A = ∅ 51.H If A△C = B△C , then A = B.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

374 Chapter 6 Set Theory

52.H (A△ B)△C = A△ (B△C). 53.H Derive the set identity A ∪ (A ∩ B) = A from the

properties listed in Theorem 6.2.2(1)–(9). Start by show- ing that for all subsets B of a universal set U , U ∪ B = U . Then intersect both sides with A and deduce the identity.

54. Derive the set identity A ∩ (A ∪ B) = A from the prop- erties listed in Theorem 6.2.2(1)–(9). Start by showing that for all subsets B of a universal set U, ∅ = ∅ ∩ B. Then take the union of both sides with A and deduce the identity.

Answers for Test Yourself 1. make the left-hand side unequal to the right-hand side (Or: result in different values on the two sides of the equation) 2. cite one of the properties from Theorem 6.2.2 (Or: give a reason) 3. exactly

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem From the paradise created for us by Cantor, no one will drive us out. — David Hilbert (1862–1943)

Table 6.4.1 summarizes the main features of the logical equivalences from Theorem 2.1.1 and the set properties from Theorem 6.2.2. Notice how similar the entries in the two columns are.

Logical Equivalences Set Properties

For all statement variables p, q, and r : For all sets A, B, and C :

a. p ∨ q ≡ q ∨ p a. A ∪ B = B ∪ A b. p ∧ q ≡ q ∧ p b. A ∩ B = B ∩ A

a. p ∧ (q ∧ r) ≡ p ∧ (q ∧ r) a. A ∪ (B ∪ C) ≡ A ∪ (B ∪ C) b. p ∨ (q ∨ r) ≡ p ∨ (q ∨ r) b. A ∩ (B ∩ C) ≡ A ∩ (B ∩ C)

a. p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) a. A ∩ (B ∪ C) ≡ (A ∩ B) ∪ (A ∩ C) b. p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) b. A ∪ (B ∩ C) ≡ (A ∪ B) ∩ (A ∪ C)

a. p ∨ c ≡ p a. A ∪ ∅ = A b. p ∧ t ≡ p b. A ∩U = A

a. p∨ ∼p ≡ t a. A ∪ Ac = U b. p∧ ∼p ≡ c b. A ∩ Ac = ∅

∼(∼p) ≡ p (Ac)c = A

a. p ∨ p ≡ p a. A ∪ A = A b. p ∧ p ≡ p b. A ∩ A = A

a. p ∨ t ≡ t a. A ∪U = U b. p ∧ c ≡ c b. A ∩ ∅ = ∅

a. ∼(p ∨ q) ≡∼p∧ ∼q a. (A ∪ B)c = Ac ∩ Bc b. ∼(p ∧ q) ≡∼p∨ ∼q b. (A ∩ B)c = Ac ∪ Bc

a. p ∨ (p ∧ q) ≡ p a. A ∪ (A ∩ B) ≡ A b. p ∧ (p ∨ q) ≡ p b. A ∩ (A ∪ B) ≡ A

a. ∼t ≡ c a. U c = ∅ b. ∼c ≡ t b. ∅c = U

Table 6.4.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem 375

If you let ∨ (or) correspond to ∪ (union), ∧ (and) correspond to ∩ (intersection), t (a tautology) correspond to U (a universal set), c (a contradiction) correspond to ∅ (the empty set), and ∼ (negation) correspond to c (complementation), then you can see that the structure of the set of statement forms with operations ∨ and ∧ is essentially iden- tical to the structure of the set of subsets of a universal set with operations ∪ and ∩. In fact, both are special cases of the same general structure, known as a Boolean algebra. The essential idea of a Boolean algebra was introduced by the self-taught English math- ematician/logician George Boole in 1847 in a book entitled The Mathematical Analysis of Logic. During the remainder of the nineteenth century, Boole and others amplified and clarified the concept until it reached the form in which we use it today.

In this section we show how to derive the various properties associated with a Boolean algebra from a set of just five axioms.

• Definition: Boolean Algebra A Boolean algebra is a set B together with two operations, generally denoted + and ·, such that for all a and b in B both a + b and a ·b are in B and the following properties hold:

1. Commutative Laws: For all a and b in B,

(a) a + b = b + a and (b) a ·b = b ·a. 2. Associative Laws: For all a, b, and c in B,

(a) (a + b) + c = a + (b + c) and (b) (a ·b) ·c = a ·(b ·c). 3. Distributive Laws: For all a, b, and c in B,

(a) a + (b ·c) = (a + b) ·(a + c) and (b) a ·(b + c) = (a ·b) + (a ·c). 4. Identity Laws: There exist distinct elements 0 and 1 in B such that for all a in B,

(a) a + 0 = a and (b) a ·1 = a. 5. Complement Laws: For each a in B, there exists an element in B, denoted a and

called the complement or negation of a, such that

(a) a + a = 1 and (b) a ·a = 0.

In any Boolean algebra, the complement of each element is unique, the quantities 0 and 1 are unique, and identities analogous to those in Theorem 2.1.1 and Theorem 6.2.2 can be deduced.

Theorem 6.4.1 Properties of a Boolean Algebra

Let B be any Boolean algebra.

1. Uniqueness of the Complement Law: For all a and x in B, if a + x = 1 and a ·x = 0 then x = a.

2. Uniqueness of 0 and 1: If there exists x in B such that a + x = a for all a in B, then x = 0, and if there exists y in B such that a · y = a for all a in B, then y = 1.

3. Double Complement Law: For all a ∈ B, (a) = a. continued on page 376

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

376 Chapter 6 Set Theory

4. Idempotent Law: For all a ∈ B, (a) a + a = a and (b) a ·a = a.

5. Universal Bound Law: For all a ∈ B, (a) a + 1 = 1 and (b) a ·0 = 0.

6. De Morgan’s Laws: For all a and b ∈ B, (a) a + b = a ·b and (b) a ·b = a + b.

7. Absorption Laws: For all a and b ∈ B, (a) (a + b) ·a = a and (b) (a ·b) + a = a.

8. Complements of 0 and 1:

(a) 0 = 1 and (b) 1 = 0.

Proof:

Part 1: Uniqueness of the Complement Law Suppose a and x are particular, but arbitrarily chosen, elements of B that satisfy the following hypothesis: a + x = 1 and a ·x = 0. Then

x = x ·1 because 1 is an identity for · = x ·(a + a) by the complement law for + = x ·a + x ·a by the distributive law for · over + = a ·x + x ·a by the commutative law for · = 0 + x ·a by hypothesis = a ·a + x ·a by the complement law for · = (a ·a) + (a ·x) by the commutative law for · = a ·(a + x) by the distributive law for · over + = a ·1 by hypothesis = a because 1 is an identity for ·.

Proofs of the other parts of the theorem are discussed in the examples that follow and in the exercises.

You may notice that all parts of the definition of a Boolean algebra and most parts of Theorem 6.4.1 contain paired statements. For instance, the distributive laws state that for all a, b, and c in B,

(a) a + (b ·c) = (a + b) ·(a + c) and (b) a ·(b + c) = (a ·b) + (a ·c), and the identity laws state that for all a in B,

(a) a + 0 = a and (b) a ·1 = a. Note that each of the paired statements can be obtained from the other by interchanging all the + and · signs and interchanging 1 and 0. Such interchanges transform any Boolean identity into its dual identity. It can be proved that the dual of any Boolean identity is also an identity. This fact is often called the duality principle for a Boolean algebra.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem 377

Example 6.4.1 Proof of the Double Complement Law

Prove that for all elements a in a Boolean algebra B, (a) = a.

Solution Start by supposing that B is a Boolean algebra and a is any element of B. The basis for the proof is the uniqueness of the complement law: that each element in B has a unique complement that satisfies certain equations with respect to it. So if a can be shown to satisfy those equations with respect to a, then a must be the complement of a.

Theorem 6.4.1(3) Double Complement Law

For all elements a in a Boolean algebra B, (a) = a.

Proof:

Suppose B is a Boolean algebra and a is any element of B. Then

a + a = a + a by the commutative law = 1 by the complement law for 1

and

a ·a = a ·a by the commutative law = 0 by the complement law for 0.

Thus a satisfies the two equations with respect to a that are satisfied by the complement of a. From the fact that the complement of a is unique, we conclude that (a) = a.

Example 6.4.2 Proof of an Idempotent Law

Fill in the blanks in the following proof that for all elements a in a Boolean algebra B, a + a = a. Proof:

Suppose B is a Boolean algebra and a is any element of B. Then

a = a + 0 (a) = a + (a ·a) (b) = (a + a) ·(a + a) (c) = (a + a) ·1 (d) = a + a (e) .

Solution

a. because 0 is an identity for + b. by the complement law for · c. by the distributive law for + over · d. by the complement law for + e. because 1 is an identity for · ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

378 Chapter 6 Set Theory

Russell’s Paradox By the beginning of the twentieth century, abstract set theory had gained such wide accep-

Sy lv

ia Sa

lm i

Bertrand Russell (1872–1970)

tance that a number of mathematicians were working hard to show that all of mathematics could be built upon a foundation of set theory. In the midst of this activity, the English mathematician and philosopher Bertrand Russell discovered a “paradox” (really a gen- uine contradiction) that seemed to shake the very core of the foundation. The paradox assumes Cantor’s definition of set as “any collection into a whole of definite and separate objects of our intuition or our thought.”

Russell’s Paradox: Most sets are not elements of themselves. For instance, the set of all integers is not an integer and the set of all horses is not a horse. However, we can imagine the possibility of a set’s being an element of itself. For instance, the set of all abstract ideas might be considered an abstract idea. If we are allowed to use any description of a property as the defining property of a set, we can let S be the set of all sets that are not elements of themselves:

S = {A | A is a set and A /∈ A}. Is S an element of itself?

The answer is neither yes nor no. For if S ∈ S, then S satisfies the defining property for S, and hence S /∈ S. But if S /∈ S, then S is a set such that S /∈ S and so S satisfies the defining property for S, which implies that S ∈ S. Thus neither is S ∈ S nor is S /∈ S, which is a contradiction.

To help explain his discovery to laypeople, Russell devised a puzzle, the barber puzzle, whose solution exhibits the same logic as his paradox.

Example 6.4.3 The Barber Puzzle

In a certain town there is a male barber who shaves all those men, and only those men, who do not shave themselves. Question: Does the barber shave himself?

Solution Neither yes nor no. If the barber shaves himself, he is a member of the class of men who shave themselves. But no member of this class is shaved by the barber, and so the barber does not shave himself. On the other hand, if the barber does not shave himself, he belongs to the class of men who do not shave themselves. But the barber shaves every man in this class, so the barber does shave himself. ■

But how can the answer be neither yes nor no? Surely any barber either does or does not shave himself. You might try to think of circumstances that would make the paradox disappear. For instance, maybe the barber happens to have no beard and never shaves. But a condition of the puzzle is that the barber is a man who shaves all those men who do not shave themselves. If he does not shave, then he does not shave himself, in which case he is shaved by the barber and the contradiction is as present as ever. Other attempts at resolving the paradox by considering details of the barber’s situation are similarly doomed to failure.

So let’s accept the fact that the paradox has no easy resolution and see where that thought leads. Since the barber neither shaves himself nor doesn’t shave himself, the sentence “The barber shaves himself” is neither true nor false. But the sentence arose in a natural way from a description of a situation. If the situation actually existed, then the sentence would have to be true or false. Thus we are forced to conclude that the situation described in the puzzle simply cannot exist in the world as we know it.

In a similar way, the conclusion to be drawn from Russell’s paradox itself is that the object S is not a set. Because if it actually were a set, in the sense of satisfying the general

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem 379

properties of sets that we have been assuming, then it either would be an element of itself or not.

In the years following Russell’s discovery, several ways were found to define the basic concepts of set theory so as to avoid his contradiction. The way used in this text requires that, except for the power set whose existence is guaranteed by an axiom, whenever a set is defined using a predicate as a defining property, the stipulation must also be made that the set is a subset of a known set. This method does not allow us to talk about “the set of all sets that are not elements of themselves.” We can speak only of “the set of all sets that are subsets of some known set and that are not elements of themselves.” When this restriction is made, Russell’s paradox ceases to be contradictory. Here is what happens:

Let U be a universal set and suppose that all sets under discussion are subsets of U . Let

S = {A | A ⊆ U and A /∈ A}. In Russell’s paradox, both implications

S ∈ S → S /∈ S and S /∈ S → S ∈ S are proved, and the contradictory conclusion

neither S ∈ S nor S /∈ S is therefore deduced. In the situation in which all sets under discussion are subsets of U , the implication S ∈ S → S /∈ S is proved in almost the same way as it is for Russell’s paradox: (Suppose S ∈ S. Then by definition of S, S ⊆ U and S /∈ S. In particular, S /∈ S.) On the other hand, from the supposition that S /∈ S we can only deduce that the statement “S ⊆ U and S /∈ S” is false. By one of De Morgan’s laws, this means that “S ! U or S ∈ S.” Since S ∈ S would contradict the supposition that S /∈ S, we eliminate it and conclude that S ! U . In other words, the only conclusion we can draw is that the seeming “definition” of S is faulty—that is, that S is not a set in U .

Russell’s discovery had a profound impact on mathematics because even though his

Kurt Gödel (1906–1978)

contradiction could be made to disappear by more careful definitions, its existence caused people to wonder whether other contradictions remained. In 1931 Kurt Gödel showed that it is not possible to prove, in a mathematically rigorous way, that mathematics is free of contradictions. You might think that Gödel’s result would have caused mathematicians to give up their work in despair, but that has not happened. On the contrary, there has been more mathematical activity since 1931 than in any other period in history.

The Halting Problem Well before the actual construction of an electronic computer, Alan M. Turing (1912– 1954) deduced a profound theorem about how such computers would have to work. The argument he used is similar to that in Russell’s paradox. It is also related to those used by Gödel to prove his theorem and by Cantor to prove that it is impossible to write all the real numbers in an infinitely long list, even given an infinitely long period of time (see Section 7.4 and Chapter 12).

If you have some experience programming computers, you know how badly an infi- nite loop can tie up a computer system. It would be useful to be able to preprocess a pro- gram and its data set by running it through a checking program that determines whether execution of the given program with the given data set would result in an infinite loop. Can an algorithm for such a program be written? In other words, can an algorithm be written that will accept any algorithm X and any data set D as input and will then print “halts” or “loops forever” to indicate whether X terminates in a finite number of steps or

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

380 Chapter 6 Set Theory

loops forever when run with data set D? In the 1930s, Turing proved that the answer to this question is no.

Theorem 6.4.2

There is no computer algorithm that will accept any algorithm X and data set D as input and then will output “halts” or “loops forever” to indicate whether or not X terminates in a finite number of steps when X is run with data set D.

Proof (by contradiction):

Suppose there is an algorithm, CheckHalt, such that if an algorithm X and a data set D are input, then

CheckHalt(X, D) prints

“halts” if X terminates in a finite number of steps when run with data set D

or

“loops forever” if X does not terminate in a finite number of steps when run with data set D.

[To show that no algorithm such as CheckHalt can exist, we will deduce a contradiction.]

Observe that the sequence of characters making up an algorithm X can be regarded as a data set itself. Thus it is possible to consider running CheckHalt with input (X, X). Define a new algorithm, Test, as follows: For any input algorithm X ,

Test(X)

loops forever if CheckHalt(X, X) prints “halts”

or

stops if CheckHalt(X, X) prints “loops forever”.

Now run algorithm Test with input Test. If Test(Test) terminates after a finite number of steps, then the value of CheckHalt(Test, Test) is “halts” and so Test(Test) loops forever.

On the other hand, if Test(Test) does not terminate after a finite number of steps, then CheckHalt(Test, Test) prints “loops forever” and so Test(Test) terminates.

The two paragraphs above show that Test(Test) loops forever and also that it terminates. This is a contradiction. But the existence of Test follows logically from the supposition of the existence of an algorithm CheckHalt that can check any algo- rithm and data set for termination. [Hence the supposition must be false, and there is no such algorithm.]

In recent years, the axioms for set theory that guarantee that Russell’s paradox will not arise have been found inadequate to deal with the full range of recursively defined objects in computer science, and a new theory of “non-well-founded” sets has been developed. In addition, computer scientists and logicians working on programs to enable computers to process natural language have seen the importance of exploring further the kinds of semantic issues raised by the barber puzzle and are developing new theories of logic to deal with them.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.4 Boolean Algebras, Russell’s Paradox, and the Halting Problem 381

Test Yourself 1. In the comparison between the structure of the set of state-

ment forms and the set of subsets of a universal set, the or operation ∨ corresponds to _____, the and operation ∧ cor- responds to _____, a tautology t corresponds to _____, a contradiction c corresponds to _____, and the negation oper- ation, denoted ∼ , corresponds to _____.

2. The operations of + and · in a Boolean algebra are general-

izations of the operations of _____ and _____ in the set of all statement forms in a given finite number of variables and the operations of _____ and _____ in the set of all subsets of a given set.

3. Russell showed that the following proposed “set definition” could not actually define a set: _____.

Exercise Set 6.4 In 1–3 assume that B is a Boolean algebra with operations + and ·. Give the reasons needed to fill in the blanks in the proofs, but do not use any parts of Theorem 6.4.1 unless they have already been proved. You may use any part of the definition of a Boolean algebra and the results of previous exercises, however.

1. For all a in B, a ·a = a. Proof: Let a be any element of B. Then

a = a ·1 (a) = a ·(a + a) (b) = (a ·a) + (a ·a) (c) = (a ·a) + 0 (d) = a ·a (e) .

2. For all a in B, a + 1 = 1. Proof: Let a be any element of B. Then

a + 1 = a + (a + a) (a) = (a + a) + a (b) = a + a by Example 6.4.2 = 1 (c) .

3. For all a and b in B, (a + b) ·a = a. Proof: Let a and b be any elements of B. Then

(a + b) ·a = a · (a + b) (a) = a ·a + a ·b (b) = a + a ·b (c) = a ·1 + a ·b (d) = a · (1 + b) (e) = a · (b + 1) (f) = a ·1 by exercise 2 = a (g ) .

In 4–10 assume that B is a Boolean algebra with operations + and ·. Prove each statement without using any parts of Theo- rem 6.4.1 unless they have already been proved. You may use any part of the definition of a Boolean algebra and the results of previous exercises, however.

4. For all a in B, a ·0 = 0. 5. For all a and b in B, (a ·b) + a = a.

6. a. 0 = 1. b. 1 = 0

7. a. There is only one element of B that is an identity for +. b.H There is only one element of B that is an identity for · .

8. For all a and b in B, a ·b = a + b. (Hint: Prove that (a ·b) + (a + b) = 1 and that (a ·b) ·(a + b) = 0, and use the fact that a ·b has a unique complement.)

9. For all a and b in B, a + b = a · b. 10.H For all x, y, and z in B, if x + y = x + z and x · y = x · z,

then y = z. 11. Let S = {0, 1}, and define operations + and · on S by the

following tables:

+ 0 1 0 0 1 1 1 1

· 0 1 0 0 0 1 0 1

a. Show that the elements of S satisfy the following properties: (i) the commutative law for +

(ii) the commutative law for · (iii) the associative law for + (iv) the associative law for · (v)H the distributive law for + over ·

(vi) the distributive law for · over + b.H Show that 0 is an identity element for + and that 1 is an

identity element for ·. c. Define 0 = 1 and 1 = 0. Show that for all a in S,

a + a = 1 and a ·a = 0. It follows from parts (a)–(c) that S is a Boolean algebra with the operations + and ·.

12.✶H Prove that the associative laws for a Boolean algebra can be omitted from the definition. That is, prove that the asso- ciative laws can be derived from the other laws in the definition.

In 13–18 determine whether each sentence is a statement. Explain your answers.

13. This sentence is false.

14. If 1 + 1 = 3, then 1 = 0. 15. The sentence in this box is a lie.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

382 Chapter 6 Set Theory

16. All positive integers with negative squares are prime.

17. This sentence is false or 1 + 1 = 3. 18. This sentence is false and 1 + 1 = 2. 19. a. Assuming that the following sentence is a statement,

prove that 1 + 1 = 3: If this sentence is true, then 1 + 1 = 3.

b. What can you deduce from part (a) about the status of “This sentence is true”? Why? (This example is known as Löb’s paradox.)

20.H The following two sentences were devised by the logician Saul Kripke. While not intrinsically paradoxical, they could be paradoxical under certain circumstances. Describe such circumstances.

(i) Most of Nixon’s assertions about Watergate are false.

(ii) Everything Jones says about Watergate is true.

(Hint: Suppose Nixon says (ii) and the only utterance Jones makes about Watergate is (i).)

21. Can there exist a computer program that has as output a list of all the computer programs that do not list themselves in their output? Explain your answer.

22. Can there exist a book that refers to all those books and only those books that do not refer to themselves? Explain your answer.

23. Some English adjectives are descriptive of themselves (for instance, the word polysyllabic is polysyllabic) whereas others are not (for instance, the word monosyllabic is not monosyllabic). The word heterological refers to an adjec- tive that does not describe itself. Is heterological heterolog- ical? Explain your answer.

24. As strange as it may seem, it is possible to give a precise- looking verbal definition of an integer that, in fact, is not a definition at all. The following was devised by an English librarian, G. G. Berry, and reported by Bertrand Russell. Explain how it leads to a contradiction. Let n be “the smallest integer not describable in fewer than 12 English words.” (Note that the total number of strings consisting of 11 or fewer English words is finite.)

25.H Is there an algorithm which, for a fixed quantity a and any input algorithm X and data set D, can determine whether X prints a when run with data set D? Explain. (This problem is called the printing problem.)

26. Use a technique similar to that used to derive Russell’s paradox to prove that for any set A, P(A) ! A.

Answers for Test Yourself 1. the operation of union ∪; the operation of intersection ∩; a universal set U ; the empty set ∅; the operation of complementation, denoted c 2. ∨; ∧; ∪; ∩ 3. the set of all sets that are not elements of themselves

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

383

CHAPTER 7

FUNCTIONS

Functions are ubiquitous in mathematics and computer science. That means you can hardly take two steps in these subjects without running into one. In this book we have pre- viously discussed truth tables and input/output tables (which can be regarded as Boolean functions), sequences (which are functions defined on sets of integers), mod and div (which are functions defined on Cartesian products of integers), and floor and ceiling (which are functions from R to Z).

In this chapter we consider an additional wide variety of functions, focusing on those defined on discrete sets (such as finite sets or sets of integers). We then look at properties of functions such as one-to-one and onto, existence of inverse functions, and the interac- tion of composition of functions and the properties of one-to-one and onto. We end the chapter with the surprising result that there are different sizes of infinite sets and give an application to computability.

7.1 Functions Defined on General Sets

The theory that has had the greatest development in recent times is without any doubt the theory of functions. — Vito Volterra, 1888

As used in ordinary language, the word function indicates dependence of one varying quantity on another. If your teacher tells you that your grade in a course will be a function of your performance on the exams, you interpret this to mean that the teacher has some rule for translating exam scores into grades. To each collection of exam scores there corresponds a certain grade.

In Section 1.3 we defined a function as a certain type of relation. In this chapter we focus on the more dynamic way functions are used in mathematics. The following is a restatement of the definition of function that includes additional terminology associated with the concept.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

384 Chapter 7 Functions

• Definition A function f from a set X to a set Y, denoted f : X → Y , is a relation from X , the domain, to Y , the co-domain, that satisfies two properties: (1) every element in X is related to some element in Y , and (2) no element in X is related to more than one element in Y . Thus, given any element x in X , there is a unique element in Y that is related to x by f . If we call this element y, then we say that “ f sends x to y” or

“ f maps x to y” and write x f→ y or f : x → y. The unique element to which f sends

x is denoted

f (x) and is called f of x, or the output of f for the input x, or the value of f at x, or the image of x under f .

The set of all values of f taken together is called the range of f or the image of X under f. Symbolically,

range of f = image of X under f = {y ∈ Y | y = f (x), for some x in X}.

Given an element y in Y , there may exist elements in X with y as their image. If f (x) = y, then x is called a preimage of y or an inverse image of y. The set of all inverse images of y is called the inverse image of y. Symbolically,

the inverse image of y = {x ∈ X | f (x) = y}.

! Caution! Use f (x) to refer to the value of the function f at x . Generally avoid using f (x) to refer to the function f itself.

In some mathematical contexts, the notation f (x) is used to refer both to the value of f at x and to the function f itself. Because using the notation this way can lead to confusion, we avoid it whenever possible. In this book, unless explicitly stated otherwise, the symbol f (x) always refers to the value of the function f at x and not to the function f itself.

St oc

k M

on ta

ge

Johann Peter Gustav Lejeune Dirichlet (1805–1859)

The concept of function was developed over a period of centuries. A definition similar to that given above was first formulated for sets of numbers by the German mathematician Lejeune Dirichlet (DEER-ish-lay) in 1837.

Arrow Diagrams Recall from Section 1.3 that if X and Y are finite sets, you can define a function f from X to Y by drawing an arrow diagram. You make a list of elements in X and a list of elements in Y , and draw an arrow from each element in X to the corresponding element in Y , as shown in Figure 7.1.1.

x1 x2 x3 x4

y1 y2 y3 y4 y5

X Yf

Figure 7.1.1

This arrow diagram does define a function because

1. Every element of X has an arrow coming out of it.

2. No element of X has two arrows coming out of it that point to two different elements of Y .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 385

Example 7.1.1 Functions and Nonfunctions

Which of the arrow diagrams in Figure 7.1.2 define functions from X = {a, b, c} to Y = {1, 2, 3, 4}?

a b c

1 2 3 4

a b c

1 2 3 4

a b c

1 2 3 4

(a) (b) (c)

Figure 7.1.1

Solution Only (c) defines a function. In (a) there is an element of X , namely b, that is not sent to any element of Y ; that is, there is no arrow coming out of b. And in (b) the element c is not sent to a unique element of Y ; that is, there are two arrows coming out of c, one pointing to 2 and the other to 3. ■

Example 7.1.2 A Function Defined by an Arrow Diagram

Let X = {a, b, c} and Y = {1, 2, 3, 4}. Define a function f from X to Y by the arrow diagram in Figure 7.1.3.

a b c

1 2 3 4

X Yf

Figure 7.1.1

a. Write the domain and co-domain of f .

b. Find f (a), f (b), and f (c).

c. What is the range of f ?

d. Is c an inverse image of 2? Is b an inverse image of 3?

e. Find the inverse images of 2, 4, and 1.

f. Represent f as a set of ordered pairs.

Solution

a. domain of f = {a, b, c}, co-domain of f = {1, 2, 3, 4} b. f (a) = 2, f (b) = 4, f (c) = 2 c. range of f = {2, 4} d. Yes, No

e. inverse image of 2 = {a, c} inverse image of 4 = {b} inverse image of 1 = ∅ (since no arrows point to 1)

f. {(a, 2), (b, 4), (c, 2)} ■

In Example 7.1.2 there are no arrows pointing to the 1 or the 3. This illustrates the fact that although each element of the domain of a function must have an arrow pointing out from it, there can be elements of the co-domain to which no arrows point. Note also that there are two arrows pointing to the 2—one coming from a and the other from c.

In Section 1.3 we gave a test for determining whether two functions with the same domain and co-domain are equal, saying that the test results from the definition of a function as a binary relation. We formalize this justification in Theorem 7.1.1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

386 Chapter 7 Functions

Theorem 7.1.1 A Test for Function Equality

If F : X → Y and G: X → Y are functions, then F = G if, and only if, F(x) = G(x) for all x ∈ X .

Proof:

Suppose F : X → Y and G: X → Y are functions, that is, F and G are binary rela- tions from X to Y that satisfy the two additional function properties. Then F and G are subsets of X × Y , and for (x, y) to be in F means that y is the unique element related to x by F , which we denote as F(x). Similarly, for (x, y) to be in G means that y is the unique element related to x by G, which we denote as G(x).

Now suppose that F(x) = G(x) for all x ∈ X . Then if x is any element of X , (x, y) ∈ F ⇔ y = F(x)⇔ y = G(x) ⇔ (x, y) ∈ G because F(x) = G(x)

So F and G consist of exactly the same elements and hence F = G. Conversely, if F = G, then for all x ∈ X ,

y = F(x)⇔ (x, y) ∈ F ⇔ (x, y) ∈ G ⇔ y = G(x) because F and G consist of exactly the same elementsThus, since both F(x) and G(x) equal y, we have that

F(x) = G(x).

Note So (x, y) ∈ F ⇔ y = F(x) and (x, y) ∈ G ⇔ y = G(x).

Example 7.1.3 Equality of Functions

a. Let J3 = {0, 1, 2}, and define functions f and g from J3 to J3 as follows: For all x in J3,

f (x) = (x2 + x + 1) mod 3 and g(x) = (x + 2)2 mod 3. Does f = g?

b. Let F: R → R and G: R → R be functions. Define new functions F + G: R → R and G + F: R → R as follows: For all x ∈ R,

(F + G)(x) = F(x) + G(x) and (G + F)(x) = G(x) + F(x). Does F + G = G + F?

Solution

a. Yes, the table of values shows that f (x) = g(x) for all x in J3.

x x2 + x + 1 f (x) = (x2 + x + 1) mod 3 (x + 2)2 g(x) = (x + 2)2 mod 3 0 1 1 mod 3 = 1 4 4 mod 3 = 1 1 3 3 mod 3 = 0 9 9 mod 3 = 0 2 7 7 mod 3 = 1 16 16 mod 3 = 1

b. Again the answer is yes. For all real numbers x ,

(F + G)(x) = F(x) + G(x) by definition of F + G = G(x) + F(x) by the commutative law for addition of real numbers = (G + F)(x) by definition of G + F

Hence F + G = G + F . ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 387

Examples of Functions The following examples illustrate some of the wide variety of different types of functions.

Example 7.1.4 The Identity Function on a Set

Given a set X , define a function IX from X to X by

IX (x) = x for all x in X. The function IX is called the identity function on X because it sends each element of X to the element that is identical to it. Thus the identity function can be pictured as a machine that sends each piece of input directly to the output chute without changing it in any way.

Let X be any set and suppose that aki j and φ(z) are elements of X . Find IX (

aki j )

and IX (φ(z)).

Solution Whatever is input to the identity function comes out unchanged, so IX (

aki j )

= aki j and IX (φ(z)) = φ(z). ■

Example 7.1.5 Sequences

The formal definition of sequences specifies that an infinite sequence is a function defined on the set of integers that are greater than or equal to a particular integer. For example, the sequence denoted

1,−1 2 ,

1 3 ,−1

4 ,

1 5 , . . . ,

(−1)n n + 1 , . . .

can be thought of as the function f from the nonnegative integers to the real numbers that associates 0 → 1, 1 →−12 , 2 → 13 , 3 →− 14 , 4 → 15 , and, in general, n → (−1)

n

n + 1 . In other words, f : Znonneg → R is the function defined as follows:

Send each integer n ≥ 0 to f (n) = (−1) n

n + 1 .

In fact, there are many functions that can be used to define a given sequence. For instance, express the sequence above as a function from the set of positive integers to the set of real numbers.

Solution Define g: Z+ → R by g(n) = (−1) n+1

n , for each n ∈ Z+. Then g(1) = 1, g(2) = − 12 , g(3) =

1 3 , and in general

g(n + 1) = (−1) n+2

n + 1 = (−1)n n + 1 = f (n). ■

Example 7.1.6 A Function Defined on a Power Set

Recall from Section 6.1 that P(A) denotes the set of all subsets of the set A. Define a function F: P({a, b, c}) → Znonneg as follows: For each X ∈P({a, b, c}),

F(X) = the number of elements in X. Draw an arrow diagram for F .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

388 Chapter 7 Functions

Solution

∅ {a}

{b}

{c}

{a, b}

{a, c}

0

1

2

3

4

5

{b, c}

{a, b, c}

({a, b, c}) Znonneg

Note It is customary to omit one set of parentheses when referring to functions defined on Cartesian products. For example, we write M(a, b) rather than M((a, b)).

Example 7.1.7 Functions Defined on a Cartesian Product

Define functions M : R× R → R and R: R× R → R× R as follows: For all ordered pairs (a, b) of integers,

M(a, b) = ab and R(a, b) = (−a, b).

Then M is the multiplication function that sends each pair of real numbers to the product of the two, and R is the reflection function that sends each point in the plane that corre- sponds to a pair of real numbers to the mirror image of the point across the vertical axis. Find the following:

a. M(−1,−1) b. M (

1 2 ,

1 2

) c. M(

√ 2, √

2) d. R(2, 5) e. R(−2, 5) f. R(3,−4)

Solution

a. (−1)(−1) = 1 b. (1/2)(1/2) = 1/4 c. √

2 · √

2 = 2 d. (−2, 5) e. (−(−2), 5) = (2, 5) f. (−3,−4) ■

• Definition Logarithms and Logarithmic Functions Let b be a positive real number with b ̸= 1. For each positive real number x , the logarithm with base b of x, written logb x, is the exponent to which b must be raised to obtain x . Symbolically,

logb x = y ⇔ by = x . The logarithmic function with base b is the function from R+ to R that takes each positive real number x to logb x .

Note It is not obvious, but it is true, that for any positive real number x there is a unique real number y such that by = x . Most calculus books contain a discussion of this result.

Example 7.1.8 The Logarithmic Function with Base b

Find the following:

a. log3 9 b. log2 (

1 2

) c. log10(1) d. log2(2

m) (m is any real number)

e. 2log2 m(m > 0)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 389

Solution

a. log3 9 = 2 because 32 = 9. b. log2 (

1 2

) = −1 because 2−1 = 12 .

c. log10(1) = 0 because 100 = 1. d. log2(2

m) = m because the exponent to which 2 must be raised to obtain 2m is m. e. 2log2 m = m because log2 m is the exponent to which 2 must be raised to obtain m. ■

Recall from Section 5.9 that if S is a nonempty, finite set of characters, then a string over S is a finite sequence of elements of S. The number of characters in a string is called the length of the string. The null string over S is the “string” with no characters. It is usually denoted ϵ and is said to have length 0.

Example 7.1.9 Encoding and Decoding Functions

Digital messages consist of finite sequences of 0’s and 1’s. When they are communicated across a transmission channel, they are frequently coded in special ways to reduce the possibility that they will be garbled by interfering noise in the transmission lines. For example, suppose a message consists of a sequence of 0’s and 1’s. A simple way to encode the message is to write each bit three times. Thus the message

00101111

would be encoded as

000000111000111111111111.

The receiver of the message decodes it by replacing each section of three identical bits by the one bit to which all three are equal.

Let A be the set of all strings of 0’s and 1’s, and let T be the set of all strings of 0’s and 1’s that consist of consecutive triples of identical bits. The encoding and decoding processes described above are actually functions from A to T and from T to A. The encoding function E is the function from A to T defined as follows: For each string s ∈ A,

E(s) = the string obtained from s by replacing each bit of s by the same bit written three times.

The decoding function D is defined as follows: For each string t ∈ T , D(t) = the string obtained from t by replacing each consecutive

triple of three identical bits of t by a single copy of that bit.

The advantage of this particular coding scheme is that it makes it possible to do a certain amount of error correction when interference in the transmission channels has introduced errors into the stream of bits. If the receiver of the coded message observes that one of the sections of three consecutive bits that should be identical does not consist of identical bits, then one bit differs from the other two. In this case, if errors are rare, it is likely that the single bit that is different is the one in error, and this bit is changed to agree with the other two before decoding. ■

Example 7.1.10 The Hamming Distance Function

The Hamming distance function, named after the computer scientist Richard W. Hamming, is very important in coding theory. It gives a measure of the “difference” between two strings of 0’s and 1’s that have the same length. Let Sn be the set of all strings of 0’s

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

390 Chapter 7 Functions

and 1’s of length n. Define a function H : Sn × Sn → Znonneg as follows: For each pair of strings (s, t) ∈ Sn × Sn ,

H(s, t) = the number of positions in which s and t have different values.

Co ur

te sy

of U

.S .N

av al

Ac ad

em y

Richard Hamming (1915–1998)

Thus, letting n = 5, H(11111, 00000) = 5 because 11111 and 00000 differ in all five positions, whereas

H(11000, 00000) = 2 because 11000 and 00000 differ only in the first two positions.

a. Find H(00101, 01110). b. Find H(10001, 01111).

Solution

a. 3 b. 4 ■

Boolean Functions In Section 2.4 we showed how to find input/output tables for certain digital logic circuits. Any such input/output table defines a function in the following way: The ele- ments in the input column can be regarded as ordered tuples of 0’s and 1’s; the set of all such ordered tuples is the domain of the function. The elements in the output column are all either 0 or 1; thus {0, 1} is taken to be the co-domain of the function. The relation- ship is that which sends each input element to the output element in the same row. Thus, for instance, the input/output table of Figure 7.1.4(a) defines the function with the arrow diagram shown in Figure 7.1.4(b).

More generally, the input/output table corresponding to a circuit with n input wires has n input columns. Such a table defines a function from the set of all n-tuples of 0’s and 1’s to the set {0, 1}.

Input Output

P Q R S

1 1 1 1

1 1 0 1

1 0 1 0

1 0 0 1

0 1 1 0

0 1 0 1

0 0 1 0

0 0 0 0

(a)

(1, 1, 1) (1, 1, 0) (1, 0, 1) (1, 0, 0) (0, 1, 1) (0, 1, 0) (0, 0, 1) (0, 0, 0)

1

0

(b) Figure 7.1.2 Two Representations of a Boolean Function

• Definition An (n-place) Boolean function f is a function whose domain is the set of all ordered n-tuples of 0’s and 1’s and whose co-domain is the set {0, 1}. More formally, the domain of a Boolean function can be described as the Cartesian product of n copies of the set {0, 1}, which is denoted {0, 1}n . Thus f : {0, 1}n → {0, 1}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 391

Example 7.1.11 A Boolean Function

Consider the three-place Boolean function defined from the set of all 3-tuples of 0’s and 1’s to {0, 1} as follows: For each triple (x1, x2, x3) of 0’s and 1’s,

f (x1, x2, x3) = (x1 + x2 + x3) mod 2. Describe f using an input/output table.

Solution f (1, 1, 1) = (1 + 1 + 1) mod 2 = 3 mod 2 = 1 f (1, 1, 0) = (1 + 1 + 0) mod 2 = 2 mod 2 = 0

The rest of the values of f can be calculated similarly to obtain the following table.

Input Output

x1 x2 x3 (x1 + x2 + x3) mod 2 1 1 1 1

1 1 0 0

1 0 1 0

1 0 0 1

0 1 1 0

0 1 0 1

0 0 1 1

0 0 0 0 ■

Checking Whether a Function Is Well Defined It can sometimes happen that what appears to be a function defined by a rule is not really a function at all. To give an example, suppose we wrote, “Define a function f : R → R by specifying that for all real numbers x ,

f (x) is the real number y such that x2 + y2 = 1. There are two distinct reasons why this description does not define a function. For almost all values of x , either (1) there is no y that satisfies the given equation or (2) there are two different values of y that satisfy the equation. For instance, when x = 2, there is no real number y such that 22 + y2 = 1, and when x = 0, both y = −1 and y = 1 satisfy the equation 02 + y2 = 1. In general, we say that a “function” is not well defined if it fails to satisfy at least one of the requirements for being a function.

Example 7.1.12 A Function That Is Not Well Defined

Recall that Q represents the set of all rational numbers. Suppose you read that a function f : Q → Z is to be defined by the formula

f (m

n

) = m for all integers m and n with n ̸= 0.

That is, the integer associated by f to the number mn is m. Is f well defined? Why?

Solution The function f is not well defined. The reason is that fractions have more than one representation as quotients of integers. For instance, 12 =

3 6 . Now if f were a function,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

392 Chapter 7 Functions

then the definition of a function would imply that f (

1 2

) = (

3 6

) since 12 =

3 6 . But applying

the formula for f , you find that

f (

1 2

) = 1 and f

( 3 6

) = 3,

and so

f (

1 2

) ̸= f (

3 6

) .

This contradiction shows that f is not well defined and, therefore, is not a function. ■

Note that the phrase well-defined function is actually redundant; for a function to be well defined really means that it is worthy of being called a function.

Functions Acting on Sets Given a function from a set X to a set Y , you can consider the set of images in Y of all the elements in a subset of X and the set of inverse images in X of all the elements in a subset of Y .

Note For y ∈ Y, f −1(y) = f −1({y}).

• Definition If f : X → Y is a function and A ⊆ X and C ⊆ Y , then

f (A) = {y ∈ Y | y = f (x) for some x in A}

and f −1(C) = {x ∈ X | f (x) ∈ C}.

f (A) is called the image of A, and f −1(C) is called the inverse image of C.

Example 7.1.13 The Action of a Function on Subsets of a Set

Let X = {1, 2, 3, 4} and Y = {a, b, c, d, e}, and define F : X → Y by the following arrow diagram:

a b c d e

1

2

3

4

Let A = {1, 4}, C = {a, b}, and D = {c, e}. Find F(A), F(X), F−1(C), and F−1(D). Solution

F(A) = {b} F(X) = {a, b, d} F−1(C) = {1, 2, 4} F−1(D) = ∅ ■

Example 7.1.14 Interaction of a Function with Union

Let X and Y be sets, let F be a function from X to Y , and let A and B be any subsets of X . Prove that F(A ∪ B) ⊆ F(A) ∪ F(B).

Solution

The fact that X, Y, F, A, and B were formally introduced prior to the word “Prove” allows you to regard their existence and relationships as part of your background knowledge. Thus to prove that F(A ∪ B) ⊆ F(A) ∪ F(B), you only need show that if y is any ele- ment in F(A ∪ B), then y is an element of F(A) ∪ F(B).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 393

Proof:

Suppose y ∈ F(A ∪ B). [We must show that y ∈ F(A) ∪ F(B).] By definition of function, y = F(x) for some x ∈ A ∪ B. By definition of union, x ∈ A or x ∈ B. Case 1, x ∈ A: In this case, y = F(x) for some x in A. Hence y ∈ F(A), and so by definition of union, y ∈ F(A) ∪ F(B). Case 2, x ∈ B: In this case, y = F(x) for some x in B. Hence y ∈ F(B), and so by definition of union, y ∈ F(A) ∪ F(B). Thus in either case y ∈ F(A) ∪ F(B) [as was to be shown]. ■

Exercise 38 asks you to prove the opposite containment from the one in example 7.1.14. Taken together, the example and the solution to the exercise establish the full equality that F(A ∪ B) = F(A) ∪ F(B).

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. Given a function f from a set X to a set Y, f (x) is _____.

2. Given a function f from a set X to a set Y , if f (x) = y, then y is called _____ or _____ or _____.

3. Given a function f from a set X to a set Y , the range of f (or the image of X under f ) is _____.

4. Given a function f from a set X to a set Y , if f (x) = y, then x is called _____ or _____.

5. Given a function f from a set X to a set Y , if y ∈ Y , then f −1(y) = _____ and is called _____.

6. Given functions f and g from a set X to a set Y, f = g if, and only if, _____.

7. Given positive real numbers x and b with b ̸= 1, logb x = _____.

8. Given a function f from a set X to a set Y and a subset A of X, f (A) = _____.

9. Given a function f from a set X to a set Y and a subset C of Y, f −1(C) = _____.

Exercise Set 7.1∗ 1. Let X = {1, 3, 5} and Y = {s, t, u, v}. Define f : X → Y

by the following arrow diagram.

1 3 5

X Y

s t u v

f

a. Write the domain of f and the co-domain of f . b. Find f (1), f (3), and f (5). c. What is the range of f ? d. Is 3 an inverse image of s? Is 1 an inverse image of u? e. What is the inverse image of s? of u? of v? f. Represent f as a set of ordered pairs.

2. Let X = {1, 3, 5} and Y = {a, b, c, d}. Define g: X → Y by the following arrow diagram.

1 3 5

X Y

a b c d

g

a. Write the domain of g and the co-domain of g. b. Find g(1), g(3), and g(5). c. What is the range of g? d. Is 3 an inverse image of a? Is 1 an inverse image

of b? e. What is the inverse image of b? of c? f. Represent g as a set of ordered pairs.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

394 Chapter 7 Functions

3. Indicate whether the statements in parts (a)–(d) are true or false. Justify your answers. a. If two elements in the domain of a function are equal,

then their images in the co-domain are equal. b. If two elements in the co-domain of a function are equal,

then their preimages in the domain are also equal. c. A function can have the same output for more than one

input. d. A function can have the same input for more than one

output.

4. a. Find all functions from X = {a, b} to Y = {u, v}. b. Find all functions from X = {a, b, c} to Y = {u}. c. Find all functions from X = {a, b, c} to Y = {u, v}.

5. Let IZ be the identity function defined on the set of all inte- gers, and suppose that e, b jki , K (t), and ukj all represent integers. Find

a. IZ(e) b. IZ (

b jki )

c. IZ(K (t)) d. IZ(ukj )

6. Find functions defined on the set of nonnegative integers that define the sequences whose first six terms are given below.

a. 1,−1 3 ,

1 5 ,−1

7 ,

1 9 ,− 1

11 b. 0,−2, 4,−6, 8,−10

7. Let A = {1, 2, 3, 4, 5} and define a function F: P(A)→Z as follows: For all sets X in P(A),

F(X) =

⎧ ⎪⎪⎪⎨

⎪⎪⎪⎩

0 if X has an even number of elements

1 if X has an odd number of elements.

Find the following: a. F({1, 3, 4}) b. F(∅) c. F({2, 3}) d. F({2, 3, 4, 5})

8. Let J5 = {0, 1, 2, 3, 4}, and define a function F : J5→ J5 as follows: For each x ∈ J5, F(x) = (x3 + 2x + 4) mod 5. Find the following: a. F(0) b. F(1) c. F(2) d. F(3) e. F(4)

9. Define a function S : Z+ → Z+ as follows: For each positive integer n,

S(n) = the sum of the positive divisors of n. Find the following: a. S(1) b. S(15) c. S(17) d. S(5) e. S(18) f. S(21)

10. Let D be the set of all finite subsets of positive integers. Define a function T : Z+ → D as follows: For each positive integer n, T (n) = the set of positive divisors of n. Find the following: a. T (1) b. T (15) c. T (17) d. T (5) e. T (18) f. T (21)

11. Define F : Z× Z→Z× Z as follows: For all ordered pairs (a, b) of integers, F(a, b) = (2a + 1, 3b − 2). Find the following: a. F(4, 4) b. F(2, 1) c. F(3, 2) d. F(1, 5)

12. Define G : J5 × J5 → J5 × J5 as follows: For all (a, b) ∈ J5 × J5,

G(a, b) = ((2a + 1) mod 5, (3b − 2) mod 5). Find the following: a. G(4, 4) b. G(2, 1) c. G(3, 2) d. G(1, 5)

13. Let J5 = {0, 1, 2, 3, 4}, and define functions f : J5→ J5 and g : J5→ J5 as follows: For each x ∈ J5, f (x)=(x + 4)2 mod 5 and g(x)=(x2 + 3x + 1) mod 5.

Is f = g? Explain. 14. Let J5 = {0, 1, 2, 3, 4}, and define functions h : J5→ J5

and k : J5→ J5 as follows: For each x ∈ J5, h(x)=(x +3)3 mod 5 and k(x)=(x3 +4x2 +2x +2) mod 5. Is h = k? Explain.

15. Let F and G be functions from the set of all real numbers to itself. Define the product functions F ·G: R → R and G · F: R → R as follows: For all x ∈ R,

(F ·G)(x) = F(x) ·G(x) (G · F)(x) = G(x) · F(x)

Does F ·G = G · F? Explain. 16. Let F and G be functions from the set of all real num-

bers to itself. Define new functions F − G: R → R and G − F: R → R as follows: For all x ∈ R,

(F − G)(x) = F(x)− G(x) (G − F)(x) = G(x)− F(x)

Does F − G = G − F? Explain. 17. Use the definition of logarithm to fill in the blanks below.

a. log2 8 = 3 because . b. log5

( 1

25

) = 2 because .

c. log4 4 = 1 because . d. log3(3

n) = n because . e. log4 1 = 0 because .

18. Find exact values for each of the following quantities. Do not use a calculator. a. log3 81 b. log2 1024 c. log3

( 1

27

) d. log2 1

e. log10 (

1 10

) f. log3 3 g. log2(2

k)

19. Use the definition of logarithm to prove that for any positive real number b with b ̸= 1, logb b = 1.

20. Use the definition of logarithm to prove that for any positive real number b with b ̸= 1, logb 1 = 0.

21. If b is any positive real number with b ̸= 1 and x is any real number, b−x is defined as follows: b−x = 1

bx . Use

this definition and the definition of logarithm to prove that

logb

( 1 u

) = − logb(u) for all positive real numbers u and

b, with b ̸= 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.1 Functions Defined on General Sets 395

22.H Use the unique factorization for the integers theorem (Section 4.3) and the definition of logarithm to prove that log3(7) is irrational.

23. If b and y are positive real numbers such that logb y = 3, what is log1/b(y)? Why?

24. If b and y are positive real numbers such that logb y = 2, what is logb2(y)? Why?

25. Let A = {2, 3, 5} and B = {x, y}. Let p1 and p2 be the projections of A × B onto the first and second coordi- nates. That is, for each pair (a, b) ∈ A × B, p1(a, b) = a and p2(a, b) = b. a. Find p1(2, y) and p1(5, x). What is the range of p1? b. Find p2(2, y) and p2(5, x). What is the range of p2?

26. Observe that mod and div can be defined as functions from Znonneg × Z+ to Z. For each ordered pair (n, d) consist- ing of a nonnegative integer n and a positive integer d, let

mod(n, d) = n mod d (the nonnegative remainder obtained when n is divided by d).

div(n, d) = n div d (the integer quotient obtained when n is divided by d).

Find each of the following:

a. mod (67, 10) and div (67, 10) b. mod (59, 8) and div (59, 8) c. mod (30, 5) and div (30, 5)

27. Let S be the set of all strings of a’s and b’s.

a. Define f : S → Z as follows: For each string s in S

f (s)

⎧ ⎪⎨

⎪⎩

the number of b’s to the left of the left-most a in s

0 if s contains no a’s.

Find f (aba), f (bbab) and f (b). What is the range of f ?

b. Define g: S → S as follows: For each string s in S, g(s) = the string obtained by writing the characters

of s in reverse order.

Find g(aba), g(bbab), and g(b). What is the range of g?

28. Consider the coding and decoding functions E and D defined in Example 7.1.9.

a. Find E(0110) and D(111111000111). b. Find E(1010) and D(000000111111).

29. Consider the Hamming distance function defined in Example 7.1.10.

a. Find H(10101, 00011) b. Find H(00110, 10111).

30. Draw arrow diagrams for the Boolean functions defined by the following input/output tables.

a. Input Output

P Q R

1 1 0

1 0 1

0 1 0

0 0 1

b. Input Output

P Q R S

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 1

0 1 1 0

0 1 0 0

0 0 1 0

0 0 0 1

31. Fill in the following table to show the values of all possible two-place Boolean functions.

Input f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 1 1

1 0

0 1

0 0

32. Consider the three-place Boolean function f defined by the following rule: For each triple (x1, x2, x3) of 0’s and 1’s,

f (x1, x2, x3) = (4x1 + 3x2 + 2x3) mod 2. a. Find f (1, 1, 1) and f (0, 0, 1). b. Describe f using an input/output table.

33. Student A tries to define a function g: Q → Z by the rule

g (m

n

) = m − n, for all integers m and n with n ̸= 0.

Student B claims that g is not well defined. Justify student B’s claim.

34. Student C tries to define a function h: Q → Q by the rule

h (m

n

) = m

2

n , for all integers m and n with n ̸= 0.

Student D claims that h is not well defined. Justify student D’s claim.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

396 Chapter 7 Functions

35. Let J5 = {0, 1, 2, 3, 4}. Then J5 − {0} = {1, 2, 3, 4}. Student A tries to define a function R : J5 − {0}→ J5 − {0} as follows: For each x ∈ J5 − {0},

R(x) is the number y so that (xy) mod 5 = 1. Student B claims that R is not well defined. Who is right: student A or student B? Justify your answer.

36. Let J4 = {0, 1, 2, 3}. Then J4 − {0} = {1, 2, 3}. Student C tries to define a function S : J4 − {0}→ J4 − {0} as fol- lows: For each x ∈ J4 − {0},

S(x) is the number y so that (xy) mod 4 = 1.

Student F claims that S is not well defined. Who is right: student C or student D? Justify your answer.

37. On certain computers the integer data type goes from −2, 147, 483, 648 through 2, 147, 483, 647. Let S be the set of all integers from −2, 147, 483, 648 through 2, 147, 483, 647. Try to define a function f : S → S by the rule f (n) = n2 for each n in S. Is f well defined? Why?

38. Let X = {a, b, c} and Y = {r, s, t, u, v, w}. Define f : X → Y as follows: f (a) = v, f (b) = v, and f (c) = t . a. Draw an arrow diagram for f . b. Let A = {a, b}, C = {t}, D = {u, v}, and E = {r, s}.

Find f (A), f (X), f −1(C), f −1(D), f −1(E), and f −1(Y ).

39. Let X = {1, 2, 3, 4} and Y = {a, b, c, d, e}. Define g: X → Y as follows: g(1) = a, g(2) = a, g(3) = a, and g(4) = d . a. Draw an arrow diagram for g. b. Let A = {2, 3}, C = {a}, and D = {b, c}. Find g(A),

g(X), g−1(C), g−1(D), and g−1(Y ).

40.H Let X and Y be sets, let A and B be any subsets of X , and let F be a function from X to Y . Fill in the blanks in the following proof that F(A) ∪ F(B) ⊆ F(A ∪ B). Proof: Let y be any element in F(A) ∪ F(B). [We must show that y is in F(A ∪ B).] By definition of union, (a).

Case 1, y ∈ F(A): In this case, by definition of F(A), y = F(x) for (b) x ∈ A. Since A ⊆ A ∪ B, it follows from the definition of union that x ∈ (c). Hence, y = F(x) for some x ∈ A ∪ B, and thus, by definition of F(A ∪ B), y ∈ (d). Case 2, y ∈ F(B): In this case, by definition of F(B), (e) x ∈ B. Since B ⊆ A ∪ B it follows from the definition of union that ( f ).

Therefore, regardless of whether y ∈ F(A) or y ∈ F(B), we have that y ∈ F(A ∪ B) [as was to be shown].

In 41–49 let X and Y be sets, let A and B be any subsets of X , and let C and D be any subsets of Y . Determine which of the properties are true for all functions F from X to Y and which are false for at least one function F from X to Y . Justify your answers.

41. If A ⊆ B then F(A) ⊆ F(B). 42. F(A ∩ B) ⊆ F(A) ∩ F(B) 43. F(A) ∩ F(B) ⊆ F(A ∩ B) 44. For all subsets A and B of X, F(A − B) = F(A)− F(B). 45. For all subsets C and D of Y , if C ⊆ D, then

F−1(C) ⊆ F−1(D). 46.H For all subsets C and D of Y ,

F−1(C ∪ D) = F−1(C) ∪ F−1(D). 47. For all subsets C and D of Y ,

F−1(C ∩ D) = F−1(C) ∩ F−1(D). 48. For all subsets C and D of Y ,

F−1(C − D) = F−1(C)− F−1(D). 49. F(F−1(C)) ⊆ C 50. Given a set S and a subset A, the characteristic function

of A, denoted χA, is the function defined from S to Z with the property that for all u ∈ S,

χA(u) = {

1 if u ∈ A 0 if u /∈ A.

Show that each of the following holds for all subsets A and B of S and all u ∈ S. a. χA∩B(u) = χA(u) ·χB(u) b. χA∪B(u) = χA(u) + χB(u)− χA(u) ·χB(u)

Each of exercises 51–53 refers to the Euler phi function, denoted φ, which is defined as follows: For each integer n ≥ 1, φ(n) is the number of positive integers less than or equal to n that have no common factors with n except ±1. For exam- ple, φ(10) = 4 because there are four positive integers less than or equal to 10 that have no common factors with 10 except ±1; namely, 1, 3, 7, and 9.

51. Find each of the following: a. φ(15) b.φ(2) c. φ(5) d. φ(12) e. φ(11) f. φ(1)

52.✶ Prove that if p is a prime number and n is an integer with n ≥ 1, then φ(pn) = pn − pn−1.

53.H Prove that there are infinitely many integers n for which φ(n) is a perfect square.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 397

Answers for Test Yourself 1. the unique output element in Y that is related to x by f 2. the value of f at x ; the image of x under f ; the out- put of f for the input x 3. the set of all y in Y such that f (x) = y 4. an inverse image of y under f ; a preimage of y 5. {x ∈ X | f (x) = y}; the inverse image of y 6. f (x) = g(x) for all x ∈ X 7. the exponent to which b must be raised to obtain x (Or: the real number y such that x = by) 8. {y ∈ Y | y = f (x) for some x ∈ A} (Or: { f (x) | x ∈ A}) 9. {x ∈ X | f (x) ∈ C}

7.2 One-to-One and Onto, Inverse Functions Don’t accept a statement just because it is printed. — Anna Pell Wheeler, 1883–1966

In this section we discuss two important properties that functions may satisfy: the property of being one-to-one and the property of being onto. Functions that satisfy both properties are called one-to-one correspondences or one-to-one onto functions. When a function is a one-to-one correspondence, the elements of its domain and co-domain match up perfectly, and we can define an inverse function from the co-domain to the domain that “undoes” the action of the function.

One-to-One Functions In Section 7.1 we noted that a function may send several elements of its domain to the same element of its co-domain. In terms of arrow diagrams, this means that two or more arrows that start in the domain can point to the same element in the co-domain. On the other hand, if no two arrows that start in the domain point to the same element of the co-domain then the function is called one-to-one or injective. For a one-to-one func- tion, each element of the range is the image of at most one element of the domain.

• Definition Let F be a function from a set X to a set Y . F is one-to-one (or injective) if, and only if, for all elements x1 and x2 in X ,

if F(x1) = F(x2), then x1 = x2,

or, equivalently, if x1 ̸= x2, then F(x1) ̸= F(x2).

Symbolically,

F: X → Y is one-to-one ⇔ ∀x1, x2 ∈ X, if F(x1) = F(x2) then x1 = x2.

To obtain a precise statement of what it means for a function not to be one-to-one, take the negation of one of the equivalent versions of the definition above. Thus:

A function F: X → Y is not one-to-one ⇔ ∃ elements x1 and x2 in X with F(x1) = F(x2) and x1 ̸= x2.

That is, if elements x1 and x2 can be found that have the same function value but are not equal, then F is not one-to-one.

In terms of arrow diagrams, a one-to-one function can be thought of as a function that separates points. That is, it takes distinct points of the domain to distinct points of the co-domain. A function that is not one-to-one fails to separate points. That is, at least two points of the domain are taken to the same point of the co-domain. This is illustrated in Figure 7.2.1 on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

398 Chapter 7 Functions

x1

x2

F(x1)

F(x2)

Any two distinct elements of X are sent to two distinct elements of Y.

X = domain of F Y = co-domain of FF

Figure 7.2.1(a) A One-to-One Function Separates Points

x1

x2 F(x1) = F(x2)

Two distinct elements of X are sent to the same element of Y.

X = domain of F Y = co-domain of FF

Figure 7.2.1(b) A Function That Is Not One-to-One Collapses Points Together

Example 7.2.1 Identifying One-to-One Functions Defined on Finite Sets

a. Do either of the arrow diagrams in Figure 7.2.2 define one-to-one functions?

a b c d

F u v w x y

Domain of F Co-domain of F X Y

a b c d

G u v w x y

Domain of G Co-domain of G X Y

Figure 7.2.2

b. Let X = {1, 2, 3} and Y = {a, b, c, d}. Define H : X → Y as follows: H(1) = c, H(2) = a, and H(3) = d . Define K : X → Y as follows: K (1) = d, K (2) = b, and K (3) = d . Is either H or K one-to-one?

Solution

a. F is one-to-one but G is not. F is one-to-one because no two different elements of X are sent by F to the same element of Y . G is not one-to-one because the elements a and c are both sent by G to the same element of Y : G(a) = G(c) = w but a ̸= c.

b. H is one-to-one but K is not. H is one-to-one because each of the three elements of the domain of H is sent by H to a different element of the co-domain: H(1) ̸= H(2), H(1) ̸= H(3), and H(2) ̸= H(3). K , however, is not one-to-one because K (1) = K (3) = d but 1 ̸= 3. ■

Consider the problem of writing a computer algorithm to check whether a function F is one-to-one. If F is defined on a finite set and there is an independent algorithm to compute values of F , then an algorithm to check whether F is one-to-one can be written as follows: Represent the domain of F as a one-dimensional array a[1], a[2], . . . , a[n] and use a nested loop to examine all possible pairs (a[i], a[ j]), where i < j . If there is a pair (a[i], a[ j]) for which F(a[i]) = F(a[ j]) and a[i] ̸= a[ j], then F is not one- to-one. If, however, all pairs have been examined without finding such a pair, then F is one-to-one. You are asked to write such an algorithm in exercise 57 at the end of this section.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 399

One-to-One Functions on Infinite Sets Now suppose f is a function defined on an infinite set X . By definition, f is one-to-one if, and only if, the following universal statement is true:

∀x1, x2 ∈ X, if f (x1) = f (x2) then x1 = x2.

Thus, to prove f is one-to-one, you will generally use the method of direct proof:

suppose x1 and x2 are elements of X such that f (x1) = f (x2)

and show that x1 = x2.

To show that f is not one-to-one, you will ordinarily

find elements x1 and x2 in X so that f (x1) = f (x2) but x1 ̸= x2.

Example 7.2.2 Proving or Disproving That Functions Are One-to-One

Define f : R → R and g: Z → Z by the rules

f (x) = 4x − 1 for all x ∈ R

and g(n) = n2 for all n ∈ Z.

a. Is f one-to-one? Prove or give a counterexample.

b. Is g one-to-one? Prove or give a counterexample.

Solution It is usually best to start by taking a positive approach to answering questions like these. Try to prove the given functions are one-to-one and see whether you run into difficulty. If you finish without running into any problems, then you have a proof. If you do encounter a problem, then analyzing the problem may lead you to discover a counterexample.

a. The function f : R → R is defined by the rule

f (x) = 4x − 1 for all real numbers x .

To prove that f is one-to-one, you need to prove that

∀ real numbers x1 and x2, if f (x1) = f (x2) then x1 = x2.

Substituting the definition of f into the outline of a direct proof, you

suppose x1 and x2 are any real numbers such that 4x1 − 1 = 4x2 − 1,

and show that x1 = x2.

Can you reach what is to be shown from the supposition? Of course. Just add 1 to both sides of the equation in the supposition and then divide both sides by 4.

This discussion is summarized in the following formal answer.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

400 Chapter 7 Functions

Answer to (a):

If the function f : R → R is defined by the rule f (x) = 4x − 1, for all real numbers x , then f is one-to-one.

Proof:

Suppose x1 and x2 are real numbers such that f (x1) = f (x2). [We must show that x1 = x2.] By definition of f ,

4x1 − 1 = 4x2 − 1. Adding 1 to both sides gives

4x1 = 4x2, and dividing both sides by 4 gives

x1 = x2, which is what was to be shown.

b. The function g: Z → Z is defined by the rule

g(n) = n2 for all integers n.

As above, you start as though you were going to prove that g is one-to-one. Substitut- ing the definition of g into the outline of a direct proof, you

suppose n1 and n2 are integers such that n21 = n22, and try to show that n1 = n2.

Can you reach what is to be shown from the supposition? No! It is quite pos- sible for two numbers to have the same squares and yet be different. For example, 22 = (−2)2 but 2 ̸= −2.

Thus, in trying to prove that g is one-to-one, you run into difficulty. But analyzing this difficulty leads to the discovery of a counterexample, which shows that g is not one-to-one.

This discussion is summarized as follows:

Answer to (b):

If the function g: Z → Z is defined by the rule g(n) = n2, for all n ∈ Z, then g is not one-to-one.

Counterexample:

Let n1 = 2 and n2 = −2. Then by definition of g, g(n1) = g(2) = 22 = 4 and also g(n2) = g(−2) = (−2)2 = 4.

Hence g(n1) = g(n2) but n1 ̸= n2, and so g is not one-to-one.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 401

Application: Hash Functions Imagine a set of student records, each of which includes the student’s social security number, and suppose the records are to be stored in a table in which a record can be located if the social security number is known. One way to do this would be to place the record with social security number n into position n of the table. However, since social security numbers have nine digits, this method would require a table with 999,999,999 positions. The problem is that creating such a table for a small set of records would be very wasteful of computer memory space. Hash functions are functions defined from larger to smaller sets of integers, frequently using the mod function, which provide part of the solution to this problem. We illustrate how to define and use a hash function with a very simple example.

Example 7.2.3 A Hash Function

Suppose there are no more than seven student records. Define a function Hash from the set of all social security numbers (ignoring hyphens) to the set {0, 1, 2, 3, 4, 5, 6} as follows:

Hash(n) = n mod 7 for all social security numbers n. To use your calculator to find n mod 7, use the formula n mod 7 = n − 7 · (n div 7). (See Section 4.4.) In other words, divide n by 7, multiply the integer part of the result by 7, and subtract that number from n. For instance, since 328343419/7 = 46906202.71 . . . ,

Hash(328-34-3419) = 328343419− (7 ·46906202) = 5. As a first approximation to solving the problem of storing the records, try to place the

record with social security number n in position Hash(n). For instance, if the social security numbers are 328-34-3419, 356-63-3102, 223-79-9061, and 513-40-8716, the positions of the records are as shown in Table 7.2.1.

Table 7.2.1

0 356-63-3102

1

2 513-40-8716

3 223-79-9061

4

5 328-34-3419

6

The problem with this approach is that Hash may not be one-to one; Hash might assign the same position in the table to records with different social security numbers. Such an assignment is called a collision. When collisions occur, various collision res- olution methods are used. One of the simplest is the following: If, when the record with social security number n is to be placed, position Hash(n) is already occupied, start from that position and search downward to place the record in the first empty posi- tion that occurs, going back up to the beginning of the table if necessary. To locate a record in the table from its social security number, n, you compute Hash(n) and search downward from that position to find the record with social security number n. If there are not too many collisions, this is a very efficient way to store and locate records.

Suppose the social security number for another record to be stored is 908-37-1011. Find the position in Table 7.2.1 into which this record would be placed.

Solution When you compute Hash you find that Hash(908-37-1011) = 2, which is already occupied by the record with social security number 513-40-8716. Searching downward from position 2, you find that position 3 is also occupied but position 4 is free.

Hash 908-37-1011 −→ 2 → 3 → 4

↑ ↑ ↑ occupied occupied free

Therefore, you place the record with social security number n into position 4. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

402 Chapter 7 Functions

Onto Functions It was noted in Section 7.1 that there may be an element of the co-domain of a function that is not the image of any element in the domain. On the other hand, every element of a function’s co-domain may be the image of some element of its domain. Such a function is called onto or surjective. When a function is onto, its range is equal to its co-domain.

• Definition Let F be a function from a set X to a set Y . F is onto (or surjective) if, and only if, given any element y in Y , it is possible to find an element x in X with the property that y = F(x).

Symbolically:

F: X → Y is onto ⇔ ∀y ∈ Y, ∃x ∈ X such that F(x) = y.

To obtain a precise statement of what it means for a function not to be onto, take the negation of the definition of onto:

F: X → Y is not onto ⇔ ∃y in Y such that ∀x ∈ X, F(x) ̸= y.

That is, there is some element in Y that is not the image of any element in X . In terms of arrow diagrams, a function is onto if each element of the co-domain has

an arrow pointing to it from some element of the domain. A function is not onto if at least one element in its co-domain does not have an arrow pointing to it. This is illustrated in Figure 7.2.3.

X = domain of F Y = co-domain of FF

y = F(x)

Each element y in Y equals F(x) for at least one x in X.x

Figure 7.2.3(a) A Function That Is Onto

X = domain of F Y = co-domain of FF

At least one element in Y does not equal F(x) for any x in X.

Figure 7.2.3(b) A Function That Is Not Onto

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 403

Example 7.2.4 Identifying Onto Functions Defined on Finite Sets

a. Do either of the arrow diagrams in Figure 7.2.4 define onto functions?

a b c d

1 2 3 4 5

Domain of F Co-domain of F

F a b c d

1 2 3 4 5

Domain of G Co-domain of G X Y X Y

G

Figure 7.2.4

b. Let X = {1, 2, 3, 4} and Y = {a, b, c}. Define H : X → Y as follows: H(1) = c, H(2) = a, H(3) = c, H(4) = b. Define K : X → Y as follows: K (1) = c, K (2) = b, K (3) = b, and K (4) = c. Is either H or K onto?

Solution

a. F is not onto because b ̸= F(x) for any x in X . G is onto because each element of Y equals G(x) for some x in X: a = G(3), b = G(1), c = G(2) = G(4), and d = G(5).

b. H is onto but K is not. H is onto because each of the three elements of the co-domain of H is the image of some element of the domain of H : a = H(2), b = H(4), and c = H(1) = H(3). K , however, is not onto because a ̸= K (x) for any x in {1, 2, 3, 4}.

It is possible to write a computer algorithm to check whether a function F is onto, provided F is defined from a finite set X to a finite set Y and there is an indepen- dent algorithm to compute values of F . Represent X and Y as one-dimensional arrays a[1], a[2], . . . , a[n] and b[1], b[2], . . . , b[m], respectively, and use a nested loop to pick each element y of Y in turn and search through the elements of X to find an x such that y is the image of x . If any search is unsuccessful, then F is not onto. If each such search is successful, then F is onto. You are asked to write such an algorithm in exercise 58 at the end of this section.

Onto Functions on Infinite Sets Now suppose F is a function from a set X to a set Y , and suppose Y is infinite. By definition, F is onto if, and only if, the following universal statement is true:

∀y ∈ Y, ∃x ∈ X such that F(x) = y. Thus to prove F is onto, you will ordinarily use the method of generalizing from the generic particular:

suppose that y is any element of Y and show that there is an element X of X with F(x) = y. To prove F is not onto, you will usually

find an element y of Y such that y ̸= F(x) for any x in X . Example 7.2.5 Proving or Disproving That Functions Are Onto

Define f : R → R and h: Z → Z by the rules f (x) = 4x − 1 for all x ∈ R

and h(n) = 4n − 1 for all n ∈ Z. a. Is f onto? Prove or give a counterexample.

b. Is h onto? Prove or give a counterexample.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

404 Chapter 7 Functions

Solution

a. The best approach is to start trying to prove that f is onto and be alert for difficulties that might indicate that it is not. Now f : R → R is the function defined by the rule

f (x) = 4x − 1 for all real numbers x .

To prove that f is onto, you must prove

∀y ∈ Y, ∃x ∈ X such that f (x) = y. Substituting the definition of f into the outline of a proof by the method of generaliz- ing from the generic particular, you

suppose y is a real number

and show that there exists a real number x such that y = 4x − 1.

Scratch Work: If such a real number x exists, then

4x − 1 = y 4x = y + 1 by adding 1 to both sides

x = y + 1 4

by dividing both sides by 4.

Thus if such a number x exists, it must equal (y + 1)/4. Does such a number exist? Yes. To show this, let x = (y + 1)/4, and then made sure that (1) x is a real number and that (2) f really does send x to y. The following formal answer summarizes this process.

! Caution! This scratch work only proves what x has to be if it exists. The scratch work does not prove that x exists.

Answer to (a):

If f : R → R is the function defined by the rule f (x) = 4x − 1 for all real numbers x , then f is onto.

Proof:

Let y ∈ R. [We must show that ∃x in R such that f (x) = y.] Let x = (y + 1)/4. Then x is a real number since sums and quotients (other than by 0) of real num- bers are real numbers. It follows that

f (x) = f (

y + 1 4

) by substitution

= 4 · (

y + 1 4

) − 1 by definition of f

= (y + 1)− 1 = y by basic algebra. [This is what was to be shown.]

b. The function h: Z → Z is defined by the rule

h(n) = 4n − 1 for all integers n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 405

To prove that h is onto, it would be necessary to prove that

∀ integers m, ∃ an integer n such that h(n) = m. Substituting the definition of h into the outline of a proof by the method of generalizing from the generic particular, you

suppose m is any integer

and try to show that there is an integer n with 4n − 1 = m.

Can you reach what is to be shown from the supposition? No! If 4n − 1 = m, then

n = m + 1 4

by adding 1 and dividing by 4.

But n must be an integer. And when, for example, m = 0, then

n = 0 + 1 4

= 1 4 ,

which is not an integer. Thus, in trying to prove that h is onto, you run into difficulty, and this difficulty

reveals a counterexample that shows h is not onto. This discussion is summarized in the following formal answer.

Answer to (b):

If the function h: Z → Z is defined by the rule h(n) = 4n − 1 for all integers n, then h is not onto.

Counterexample:

The co-domain of h is Z and 0 ∈ Z. But h(n) ̸= 0 for any integer n. For if h(n) = 0, then

4n − 1 = 0 by definition of h which implies that

4n = 1 by adding 1 to both sides and so

n = 1 4

by dividing both sides by 4.

But 1/4 is not an integer. Hence there is no integer n for which f (n) = 0, and thus f is not onto.

Note That the quantity bx is a real number for any real number x follows from the least-upper- bound property of the real number system. (See Appendix A.)

Relations between Exponential and Logarithmic Functions For positive numbers b ̸= 1, the exponential function with base b, denoted expb, is the function from R to R+ defined as follows: For all real numbers x ,

expb(x) = bx

where b0 = 1 and b−x = 1/bx .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

406 Chapter 7 Functions

When working with the exponential function, it is useful to recall the laws of expo- nents from elementary algebra.

Laws of Exponents

If b and c are any positive real numbers and u and v are any real numbers, the following laws of exponents hold true:

bubv = bu+v 7.2.1 (bu)v = buv 7.2.2

bu

bv = bu−v 7.2.3

(bc)u = bucu 7.2.4

In Section 7.1 the logarithmic function with base b was defined for any positive num- ber b ̸= 1 to be the function from R+ to R with the property that for each positive real number x ,

logb(x) = the exponent to which b must be raised to obtain x . Or, equivalently, for each positive real number x and real number y,

logb x = y ⇔ by = x . It can be shown using calculus that both the exponential and logarithmic functions are one-to-one and onto. Therefore, by definition of one-to-one, the following properties hold true:

For any positive real number b with b ̸= 1, if bu = bv then u = v for all real numbers u and v, 7.2.5

and

if logb u = logb v then u = v for all positive real numbers u and v. 7.2.6

These properties are used to derive many additional facts about exponents and logarithms. In particular we have the following properties of logarithms.

Theorem 7.2.1 Properties of Logarithms

For any positive real numbers b, c and x with b ̸= 1 and c ̸= 1:

a. logb(xy) = logb x + logb y

b. logb

( x y

) = logb x − logb y

c. logb(x a) = a logb x

d. logc x = logb x logb c

Theorem 7.2.1(d) is proved in the next example. You are asked to prove the remainder of the theorem in exercises 33–35 at the end of this section.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 407

Example 7.2.6 Using the One-to-Oneness of the Exponential Function

Use the definition of logarithm, the laws of exponents, and the one-to-oneness of the exponential function (property 7.2.5) to prove part (d) of Theorem 7.2.1: For any positive real numbers b, c, and x , with b ̸= 1 and c ̸= 1,

logc x = logb x logb c

.

Solution Suppose positive real numbers b, c, and x are given. Let

(1) u = logb c (2) v = logc x (3) w = logb x . Then, by definition of logarithm,

(1′) c = bu (2′) x = cv (3′) x = bw. Substituting (1′) into (2′) and using one of the laws of exponents gives

x = cv = (bu)v = buv by 7.2.2 But by (3), x = bw also. Hence

buv = bw, and so by the one-to-oneness of the exponential function (property 7.2.5),

uv = w. Substituting from (1), (2), and (3) gives that

(logb c)(logc x) = logb x . And dividing both sides by logb c (which is nonzero because c ̸= 1) results in

logc x = logb x logb c

. ■

Example 7.2.7 Computing Logarithms with Base 2 on a Calculator

In computer science it is often necessary to compute logarithms with base 2. Most calcu- lators do not have keys to compute logarithms with base 2 but do have keys to compute logarithms with base 10 (called common logarithms and often denoted simply log) and logarithms with base e (called natural logarithms and usually denoted ln). Suppose your calculator shows that ln 5 ∼= 1.609437912 and ln 2 ∼= 0.6931471806. Use Theorem 7.2.1(d) to find an approximate value for log2 5.

Solution By Theorem 7.2.1(d),

log2 5 = ln 5 ln 2

∼= 1.609437912 0.6931471806

∼= 2.321928095. ■

One-to-One Correspondences Consider a function F: X → Y that is both one-to-one and onto. Given any element x in X , there is a unique corresponding element y = F(x) in Y (since F is a function). Also given any element y in Y , there is an element x in X such that F(x) = y (since F is onto) and there is only one such x (since F is one-to-one). Thus, a function that is one-to-one and onto sets up a pairing between the elements of X and the elements of Y that matches

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

408 Chapter 7 Functions

each element of X with exactly one element of Y and each element of Y with exactly one element of X . Such a pairing is called a one-to-one correspondence or bijection and is illustrated by the arrow diagram in Figure 7.2.5. One-to-one correspondences are often used as aids to counting. The pairing of Figure 7.2.5, for example, shows that there are five elements in the set X .

a b c d e

1 2 3 4 5

X = domain of F Y = co-domain of F F

Figure 7.2.5 An Arrow Diagram for a One-to-One Correspondence

• Definition A one-to-one correspondence (or bijection) from a set X to a set Y is a function F: X → Y that is both one-to-one and onto.

Example 7.2.8 A Function from a Power Set to a Set of Strings

Let P({a, b}) be the set of all subsets of {a, b} and let S be the set of all strings of length 2 made up of 0’s and 1’s. Then P({a, b}) = {∅, {a}, {b}, {a, b}} and S = {00, 01, 10, 11}. Define a function h from P({a, b}) to S as follows: Given any subset A of {a, b}, a is either in A or not in A, and b is either in A or not in A. If a is in A, write a 1 in the first position of the string h(A). If a is not in A, write a 0 in the first position of the string h(A). Similarly, if b is in A, write a 1 in the second position of the string h(A). If b is not in A, write a 0 in the second position of the string h(A). This definition is summarized in the following table.

h

Subset of {a, b} Status of a Status of b String in S ∅ not in not in 00

{a} in not in 10 {b} not in in 01 {a, b} in in 11

Is h a one-to-one correspondence?

Solution The arrow diagram shown in Figure 7.2.6 shows clearly that h is a one-to-one correspondence. It is onto because each element of S has an arrow pointing to it. It is one-to-one because each element of S has no more than one arrow pointing to it.

∅ {a} {b}

{a, b}

00 10 01 11

Sh({a, b})

Figure 7.2.6 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 409

Example 7.2.9 A String-Reversing Function

Let T be the set of all finite strings of x’s and y’s. Define g: T → T by the rule: For all strings s ∈ T ,

g(s) = the string obtained by writing the characters of s in reverse order.

Is g a one-to-one correspondence from T to itself?

Solution The answer is yes. To show that g is a one-to-one correspondence, it is necessary to show that g is one-to-one and onto.

To see that g is one-to-one, suppose that for some strings s1 and s2 in T , g(s1) = g(s2). [We must show that s1 = s2.] Now to say that g(s1) = g(s2) is the same as saying that the string obtained by writing the characters of s1 in reverse order equals the string obtained by writing the characters of s2 in reverse order. But if s1 and s2 are equal when written in reverse order, then they must be equal to start with. In other words, s1 = s2 [as was to be shown].

To show that g is onto, suppose t is a string in T . [We must find a string s in T such that g(s) = t .] Let s = g(t). By definition of g, s = g(t) is the string in T obtained by writing the characters of t in reverse order. But when the order of the characters of a string is reversed once and then reversed again, the original string is recovered. Thus

g(s) = g(g(t)) = the string obtained by writing the characters of t in reverse order and then writing those characters in reverse order again

= t. This is what was to be shown. ■

Example 7.2.10 A Function of Two Variables

Define a function F : R× R → R× R as follows: For all (x, y) ∈ R× R, F(x, y) = (x + y, x − y).

Is F a one-to-one correspondence from R× R to itself?

Solution The answer is yes. To show that F is a one-to-one correspondence, you need to show both that F is one-to-one and that F is onto.

Proof that F is one-to-one: Suppose that (x1, y1) and (x2, y2) are any ordered pairs in R× R such that

F(x1, y1) = F(x2, y2). [We must show that (x1, y1) = (x2, y2).] By definition of F ,

(x1 + y1, x1 − y1) = (x2 + y2, x2 − y2). For two ordered pairs to be equal, both the first and second components must be equal. Thus x1, y1, x2, and y2 satisfy the following system of equations:

x1 + y1 = x2 + y2 (1) x1 − y1 = x2 − y2 (2)

Adding equations (1) and (2) gives that

2x1 = 2x2, and so x1 = x2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

410 Chapter 7 Functions

Substituting x1 = x2 into equation (1) yields x1 + y1 = x1 + y2, and so y1 = y2.

Thus, by definition of equality of ordered pairs, (x1, y1) = (x2, y2) [as was to be shown].! Caution! This scratch work only shows what (r, s) has to be if it exists. The scratch work does not prove that (r, s) exists.

Scratch Work for the Proof that F is onto: To prove that F is onto, you suppose you have any ordered pair in the co-domain R× R, say (u, v), and then you show that there is an ordered pair in the domain that is sent to (u, v) by F . To do this, you suppose temporarily that you have found such an ordered pair, say (r, s). Then

F(r, s) = (u, v) because you are supposing that F sends(r, s) to (u, v),

and F(r, s) = (r + s, r − s) by definition of F .

Equating the right-hand sides gives

(r + s, r − s) = (u, v). By definition of equality of ordered pairs this means that

r + s = u (1) r − s = v (2)

Adding equations (1) and (2) gives

2r = u + v, and so r = u +v2 . Subtracting equation (2) from equation (1) yields

2s = u − v, and so s = u−v2 . Thus, if F sends (r, s) to (u, v), then r = (u + v)/2 and s = (u − v)/2. To turn this scratch work into a proof, you need to make sure that (1)

( u +v

2 , u−v

2

) is in the domain

of F , and (2) that F really does send (

u +v 2 ,

u−v 2

) to (u, v).

Proof that F is onto: Suppose (u, v) is any ordered pair in the co-domain of F . [We will show that there is an ordered pair in the domain of F that is sent to (u, v) by F.] Let

r = u +v2 and s = u−v

2 .

Then (r, s) is an ordered pair of real numbers and so is in the domain of F . In addition:

F(r, s) = F (

u +v 2 ,

u−v 2

) by definition of F

= (

u +v 2 +

u−v 2 ,

u +v 2 −

u−v 2

) by substitution

= (

u +v+u−v 2 ,

u +v−u +v 2

)

= (

2u 2 ,

2v 2

)

= (u, v) by algebra. [This is what was to be shown.] ■

Inverse Functions If F is a one-to-one correspondence from a set X to a set Y , then there is a function from Y to X that “undoes” the action of F; that is, it sends each element of Y back to the element of X that it came from. This function is called the inverse function for F .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 411

Theorem 7.2.2

Suppose F: X → Y is a one-to-one correspondence; that is, suppose F is one-to-one and onto. Then there is a function F−1: Y → X that is defined as follows:

Given any element y in Y,

F−1(y) = that unique element x in X such that F(x) equals y. In other words,

F−1(y) = x ⇔ y = F(x).

The proof of Theorem 7.2.2 follows immediately from the definition of one-to-one and onto. Given an element y in Y , there is an element x in X with F(x) = y because F is onto; x is unique because F is one-to-one.

• Definition The function F−1 of Theorem 7.2.2 is called the inverse function for F .

Note that according to this definition, the logarithmic function with base b > 0 is the inverse of the exponential function with base b.

The diagram that follows illustrates the fact that an inverse function sends each ele- ment back to where it came from.

x = F –1( y) F(x) = y

X = domain of F Y = co-domain of F

F

F –1

Example 7.2.11 Finding an Inverse Function for a Function Given by an Arrow Diagram

Define the inverse function for the one-to-one correspondence h given in Example 7.2.8.

Solution The arrow diagram for h−1 is obtained by tracing the h-arrows back from S to P({a, b}) as shown below.

∅ {a} {b}

{a, b}

00 10 01 11

Sh–1({a, b})

h–1(00) = ∅ h–1(10) = {a} h–1(01) = {b} h–1(11) = {a, b}

Example 7.2.12 Finding an Inverse Function for a Function Given in Words

Define the inverse function for the one-to-one correspondence g given in Example 7.2.9.

Solution The function g: T → T is defined by the rule For all strings t in T ,

g(t) = the string obtained by writing the characters of t in reverse order.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

412 Chapter 7 Functions

Now if the characters of t are written in reverse order and then written in reverse order again, the original string is recovered. Thus given any string t in T ,

g−1(t) = the unique string that, when written in reverse order, equals t

= the string obtained by writing the characters of t in reverse order

= g(t).

Hence g−1: T → T is the same as g, or, in other words, g−1 = g. ■

Example 7.2.13 Finding an Inverse Function for a Function Given by a Formula

The function f : R → R defined by the formula f (x) = 4x − 1 for all real numbers x

was shown to be one-to-one in Example 7.2.2 and onto in Example 7.2.5. Find its inverse function.

Solution For any [particular but arbitrarily chosen] y in R, by definition of f −1,

f −1(y) = that unique real number x such that f (x) = y. But f (x) = y

⇔ 4x − 1 = y by definition of f

⇔ x = y + 1 4

by algebra.

Hence f −1(y) = y + 1 4

. ■

The following theorem follows easily from the definitions.

Theorem 7.2.3

If X and Y are sets and F: X → Y is one-to-one and onto, then F−1: Y → X is also one-to-one and onto.

Proof:

F−1 is one-to-one: Suppose y1 and y2 are elements of Y such that F−1(y1) = F−1(y2). [We must show that y1 = y2.] Let x = F−1(y1) = F−1(y2). Then x ∈ X , and by definition of F−1,

F(x) = y1 since x = F−1(y1) and F(x) = y2 since x = F−1(y2). Consequently, y1 = y2 since each is equal to F(x). This is what was to be shown. F−1 is onto: Suppose x ∈ X . [We must show that there exists an element y in Y such that F−1(y) = x .] Let y = F(x). Then y ∈ Y , and by definition of F−1, F−1(y) = x . This is what was to be shown.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 413

Example 7.2.14 Finding an Inverse Function for a Function of Two Variables

Define the inverse function F−1 : R× R → R× R for the one-to-one correspondence given in Example 7.2.10.

Solution

The solution to Example 7.2.10 shows that F (

u +v 2 ,

u−v 2

) = (u, v). Because F is one-

to-one, this means that (

u +v 2 ,

u−v 2

) is the unique ordered pair in the domain of F that is sent to (u, v) by F.

Thus, F−1 is defined as follows: For all (u, v) ∈ R× R,

F−1(u, v) = (

u + v 2

, u − v

2

) .

Test Yourself 1. If F is a function from a set X to a set Y , then F is one-to-

one if, and only if, _____.

2. If F is a function from a set X to a set Y , then F is not one-to-one if, and only if, _____.

3. If F is a function from a set X to a set Y , then F is onto if, and only if, _____.

4. If F is a function from a set X to a set Y , then F is not onto if, and only if, _____.

5. The following two statements are _____:

∀ u, v ∈ U, if H(u) = H(v) then u = v. ∀ u, v ∈ U, if u ̸= v then H(u) ̸= H(v).

6. Given a function F : X → Y and an infinite set X , to prove that F is one-to-one, you suppose that _____ and then you show that _____.

7. Given a function F : X → Y and an infinite set X , to prove that F is onto, you suppose that _____ and then you show that _____.

8. Given a function F : X → Y , to prove that F is not one-to- one, you _____.

9. Given a function F : X → Y , to prove that F is not onto, you _____.

10. A one-to-one correspondence from a set X to a set Y is a _____ that is _____.

11. If F is a one-to-one correspondence from a set X to a set Y and y is in Y , then F−1(y) is _____.

Exercise Set 7.2 1. The definition of one-to-one is stated in two ways:

∀x1, x2 ∈ X, if F(x1) = F(x2) then x1 = x2 and ∀x1, x2 ∈ X, if x1 ̸= x2 then F(x1) ̸= F(x2). Why are these two statements logically equivalent?

2. Fill in each blank with the word most or least. a. A function F is one-to-one if, and only if, each element

in the co-domain of F is the image of at one element in the domain of F .

b. A function F is onto if, and only if, each element in the co-domain of F is the image of at one element in the domain of F .

3.H When asked to state the definition of one-to-one, a student replies, “A function f is one-to-one if, and only if, every element of X is sent by f to exactly one element of Y .” Give a counterexample to show that the student’s reply is incorrect.

4.H Let f : X → Y be a function. True or false? A sufficient condition for f to be one-to-one is that for all elements y in Y , there is at most one x in X with f (x) = y.

5.H All but two of the following statements are correct ways to express the fact that a function f is onto. Find the two that are incorrect. a. f is onto⇔ every element in its co-domain is the image

of some element in its domain. b. f is onto ⇔ every element in its domain has a corre-

sponding image in its co-domain. c. f is onto⇔ ∀y ∈ Y, ∃x ∈ X such that f (x) = y. d. f is onto⇔ ∀x ∈ X, ∃y ∈ Y such that f (x) = y. e. f is onto⇔ the range of f is the same as the co-domain

of f .

6. Let X = {1, 5, 9} and Y = {3, 4, 7}. a. Define f : X → Y by specifying that

f (1) = 4, f (5) = 7, f (9) = 4. Is f one-to-one? Is f onto? Explain your answers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

414 Chapter 7 Functions

b. Define g: X → Y by specifying that g(1) = 7, g(5) = 3, g(9) = 4.

Is g one-to-one? Is g onto? Explain your answers.

7. Let X = {a, b, c, d} and Y = {e, f, g}. Define functions F and G by the arrow diagrams below.

X Y Domain of F Co-domain of F

F

a b c d

e f g

X Y Domain of G Co-domain of G

G

a b c d

e f g

a. Is F one-to-one? Why or why not? Is it onto? Why or why not?

b. Is G one-to-one? Why or why not? Is it onto? Why or why not?

8. Let X = {a, b, c} and Y = {w, x, y, z}. Define functions H and K by the arrow diagrams below.

X Y Domain of H Co-domain of H

H

w x y z

a b c

X Y Domain of K Co-domain of K

K

w x y z

a b c

a. Is H one-to-one? Why or why not? Is it onto? Why or why not?

b. Is K one-to-one? Why or why not? Is it onto? Why or why not?

9. Let X = {1, 2, 3}, Y = {1, 2, 3, 4}, and Z = {1, 2}. a. Define a function f : X → Y that is one-to-one but not

onto. b. Define a function g: X → Z that is onto but not one-

to-one. c. Define a function h: X → X that is neither one-to-one

nor onto. d. Define a function k: X → X that is one-to-one and onto

but is not the identity function on X .

10. a. Define f : Z → Z by the rule f (n) = 2n, for all integers n. (i) Is f one-to-one? Prove or give a counterexample.

(ii) Is f onto? Prove or give a counterexample. b. Let 2Z denote the set of all even integers. That is,

2Z = {n ∈ Z | n = 2k, for some integer k}. Define h: Z → 2Z by the rule h(n) = 2n, for all integers n. Is h onto? Prove or give a counterexample.

11.H a. Define g: Z → Z by the rule g(n) = 4n − 5, for all integers n. (i) Is g one-to-one? Prove or give a counterexample.

(ii) Is g onto? Prove or give a counterexample. b. Define G: R → R by the rule G(x) = 4x − 5 for all

real numbers x . Is G onto? Prove or give a counterex- ample.

12. a. Define F : Z → Z by the rule F(n) = 2− 3n, for all integers n. (i) Is F one-to-one? Prove or give a counterexample.

(ii) Is F onto? Prove or give a counterexample. b. Define G: R → R by the rule G(x) = 2− 3x for

all real numbers x . Is G onto? Prove or give a counterexample.

13. a. Define H: R → R by the rule H(x) = x2, for all real numbers x . (i) Is H one-to-one? Prove or give a counterexample.

(ii) Is H onto? Prove or give a counterexample. b. Define K: Rnonneg → Rnonneg by the rule K (x) = x2, for

all nonnegative real numbers x . Is K onto? Prove or give a counterexample.

14. Explain the mistake in the following “proof.”

Theorem: The function f : Z → Z defined by the formula f (n) = 4n + 3, for all integers n, is one-to-one. “Proof: Suppose any integer n is given. Then by definition of f , there is only one possible value for f (n), namely, 4n + 3. Hence f is one-to-one.”

In each of 15–18 a function f is defined on a set of real num- bers. Determine whether or not f is one-to-one and justify your answer.

15. f (x) = x + 1 x

, for all real numbers x ̸= 0

16. f (x) = x x2 + 1 , for all real numbers x

17. f (x) = 3x − 1 x

, for all real numbers x ̸= 0

18. f (x) = x + 1 x − 1 , for all real numbers x ̸= 1

19. Referring to Example 7.2.3, assume that records with the following social security numbers are to be placed in sequence into Table 7.2.1. Find the position into which each record is placed. a. 417-30-2072 b. 364-98-1703 c. 283-09-0787

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.2 One-to-One and Onto, Inverse Functions 415

20. Define Floor: R → Z by the formula Floor(x) = ⌊x⌋, for all real numbers x . a. Is Floor one-to-one? Prove or give a counterexample. b. Is Floor onto? Prove or give a counterexample.

21. Let S be the set of all strings of 0’s and 1’s, and define l: S → Znonneg by

l(s) = the length of s, for all strings s in S. a. Is l one-to-one? Prove or give a counterexample. b. Is l onto? Prove or give a counterexample.

22. Let S be the set of all strings of 0’s and 1’s, and define D: S → Z as follows: For all s ∈ S, D(s) = the number of 1’s in s minus the number of 0’s in s. a. Is D one-to-one? Prove or give a counterexample. b. Is D onto? Prove or give a counterexample.

23. Define F: P({a, b, c})→ Z as follows: For all A in P({a, b, c}),

F(A) = the number of elements in A. a. Is F one-to-one? Prove or give a counterexample. b. Is F onto? Prove or give a counterexample.

24. Let S be the set of all strings of a’s and b’s, and define N: S → Z by

N (s) = the number of a’s in s, for all s ∈ S. a. Is N one-to-one? Prove or give a counterexample. b. Is N onto? Prove or give a counterexample.

25. Let S be the set of all strings in a’s and b’s, and define C: S → S by

C(s) = as, for all s ∈ S. (C is called concatenation by a on the left.) a. Is C one-to-one? Prove or give a counterexample. b. Is C onto? Prove or give a counterexample.

26. Define S: Z+ − Z+ by the rule: For all integers n, S(n) = the sum of the positive divisors of n. a. Is S one-to-one? Prove or give a counterexample. b. Is S onto? Prove or give a counterexample.

27.H Let D be the set of all finite subsets of positive integers, and define T : Z+ → D by the rule: For all integers n, T (n) = the set of all of the positive divisors of n. a. Is T one-to-one? Prove or give a counterexample. b. Is T onto? Prove or give a counterexample.

28. Define G: R× R → R× R as follows: G(x, y) = (2y,−x) for all (x, y) ∈ R× R. a. Is G one-to-one? Prove or give a counterexample. b. Is G onto? Prove or give a counterexample.

29. Define H : R× R → R× R as follows: H(x, y) = (x + 1, 2− y) for all (x, y) ∈ R× R. a. Is H one-to-one? Prove or give a counterexample. b. Is H onto? Prove or give a counterexample.

30. Define J : Q×Q → R by the rule J (r, s) = r + √

2s for all (r, s) ∈ Q×Q. a. Is J one-to-one? Prove or give a counterexample. b. Is J onto? Prove or give a counterexample.

31.✶ Define F: Z+ × Z+ → Z+ and G: Z+ × Z+ → Z+ as follows: For all (n, m) ∈ Z+ × Z+,

F(n, m) = 3n5m and G(n, m) = 3n6m .

H a. Is F one-to-one? Prove or give a counterexample. b. Is G one-to-one? Prove or give a counterexample.

32. a. Is log8 27 = log2 3? Why or why not? b. Is log16 9 = log4 3? Why or why not?

The properties of logarithm established in 33–35 are used in Sections 11.4 and 11.5.

33. Prove that for all positive real numbers b, x , and y with b ̸= 1,

logb

( x y

) = logb x − logb y.

34. Prove that for all positive real numbers b, x , and y with b ̸= 1,

logb(xy) = logb x + logb y.

35.H Prove that for all real numbers a, b, and x with b and x positive and b ̸= 1,

logb(x a) = a logb x .

Exercises 36 and 37 use the following definition: If f : R → R and g: R → R are functions, then the function ( f + g): R → R is defined by the formula ( f + g)(x) = f (x) + g(x) for all real numbers x .

36. If f : R → R and g: R → R are both one-to-one, is f + g also one-to-one? Justify your answer.

37. If f : R → R and g: R → R are both onto, is f + g also onto? Justify your answer.

Exercises 38 and 39 use the following definition: If f : R → R is a function and c is a nonzero real number, the function (c · f ): R → R is defined by the formula (c · f )(x) = c · f (x) for all real numbers x .

38. Let f : R → R be a function and c a nonzero real num- ber. If f is one-to-one, is c · f also one-to-one? Justify your answer.

39. Let f : R → R be a function and c a nonzero real number. If f is onto, is c · f also onto? Justify your answer.

40.H Suppose F : X → Y is one-to-one. a. Prove that for all subsets A ⊆ X, F−1(F(A)) = A. b. Prove that for all subsets A1 and A2 in X,

F(A1 ∩ A2) = F(A1) ∩ F(A2).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

416 Chapter 7 Functions

41. Suppose F :X → Y is onto. Prove that for all subsets B ⊆ Y, F(F−1(B)) = B.

Let X = {a, b, c, d, e} and Y = {s, t, u, v, w}. In each of 42 and 43 a one-to-one correspondence F: X → Y is defined by an arrow diagram. In each case draw an arrow diagram for F−1.

42.

a b c d e

X YF

s t u v w

43.

a b c d e

X YF

s t u v w

In 44–55 indicate which of the functions in the referenced exercise are one-to-one correspondences. For each function that is a one-to-one correspondence, find the inverse function.

44. Exercise 10a 45. Exercise 10b

46. Exercise 11a 47. Exercise 11b

48. Exercise 12a 49. Exercise 12b

50. Exercise 21 51. Exercise 22

52. Exercise 15 with the co-domain taken to be the set of all real numbers not equal to 1.

53.H Exercise 16 with the co-domain taken to be the set of all real numbers.

54. Exercise 17 with the co-domain taken to be the set of all real numbers not equal to 3.

55. Exercise 18 with the co-domain taken to be the set of all real numbers not equal to 1.

56. In Example 7.2.8 a one-to-one correspondence was defined from the power set of {a, b} to the set of all strings of 0’s and 1’s that have length 2. Thus the elements of these two sets can be matched up exactly, and so the two sets have the same number of elements. a. Let X = {x1, x2, . . . , xn} be a set with n elements. Use

Example 7.2.8 as a model to define a one-to-one corre- spondence from P(X), the set of all subsets of X , to the set of all strings of 0’s and 1’s that have length n.

b. Use the one-to-one correspondence of part (a) to deduce that a set with n elements has 2n subsets. (This provides an alternative proof of Theorem 6.3.1.)

57.H Write a computer algorithm to check whether a function from one finite set to another is one-to-one. Assume the existence of an independent algorithm to compute values of the function.

58.H Write a computer algorithm to check whether a function from one finite set to another is onto. Assume the exis- tence of an independent algorithm to compute values of the function.

Answers for Test Yourself 1. for all x1 and x2 in X , if F(x1) = F(x2) then x1 = x2 2. there exist elements x1 and x2 in X such that F(x1) = F(x2) and x1 ̸= x2 3. for all y in Y , there exists at least one element x in X such that f (x) = y 4. there exists an element y in Y such that for all elements x in X, f (x) ̸= y 5. logically equivalent ways of expressing what it means for a function H to be one-to-one (The second is the contrapositive of the first.) 6. x1 and x2 are any [particular but arbitrarily chosen] elements in X with the property that F(x1) = F(x2); x1 = x2 7. y is any [particular but arbitrarily chosen] element in Y ; there exists at least one element x in X such that F(x) = y 8. show that there are concrete elements x1 and x2 in X with the property that F(x1) = F(x2) and x1 ̸= x2 9. show that there is a concrete element y in Y with the property that F(x) ̸= y for any element x in X 10. function from X to Y ; both one-to-one and onto 11. the unique element x in X such that F(x) = y (in other words, F−1(y) is the unique preimage of y in X )

7.3 Composition of Functions It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications. — Alfred North Whitehead

Consider two functions, the successor function and the squaring function, defined from Z (the set of integers) to Z, and imagine that each is represented by a machine. If the two machines are hooked up so that the output from the successor function is used as input

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 417

to the squaring function, then they work together to operate as one larger machine. In this larger machine, an integer n is first increased by 1 to obtain n + 1; then the quantity n + 1 is squared to obtain (n + 1)2. This is illustrated in the following drawing.

successor function

n

n + 1

squaring function

(n + 1)2

Combining functions in this way is called composing them; the resulting function is called the composition of the two functions. Note that the composition can be formed only if the output of the first function is acceptable input to the second function. That is, the range of the first function must be contained in the domain of the second function.

Note We put the f first when we say “the composition of f and g” because an element x is acted upon first by f and then by g.

• Definition Let f : X → Y ′ and g: Y → Z be functions with the property that the range of f is a subset of the domain of g. Define a new function g◦ f : X → Z as follows:

(g◦ f )(x) = g( f (x)) for all x ∈ X, where g◦ f is read “g circle f ” and g( f (x)) is read “g of f of x .” The function g◦ f is called the composition of f and g.

This definition is shown schematically below.

Y ZX f

x f (x)

g( f (x)) = (g J f )(x)Y'

g J f

g

! Caution! Be careful not to confuse g ◦ f and g( f (x)): g ◦ f is the name of the function whereas g( f (x)) is the value of the function at x .

Example 7.3.1 Composition of Functions Defined by Formulas

Let f : Z → Z be the successor function and let g: Z → Z be the squaring function. Then f (n)= n + 1 for all n ∈ Z and g(n) = n2 for all n ∈ Z. a. Find the compositions g◦ f and f ◦g. b. Is g◦ f = f ◦g? Explain.

Solution

a. The functions g◦ f and f ◦g are defined as follows: (g◦ f )(n) = g( f (n)) = g(n + 1) = (n + 1)2 for all n ∈ Z,

and

( f ◦g)(n) = f (g(n)) = f (n2) = n2 + 1 for all n ∈ Z.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

418 Chapter 7 Functions

b. Two functions from one set to another are equal if, and only if, they always take the same values. In this case,

(g◦ f )(1) = (1 + 1)2 = 4, whereas ( f ◦g)(1) = 12 + 1 = 2.

Thus the two functions g◦ f and f ◦g are not equal:

g◦ f ̸= f ◦g. ■

Example 7.3.1 illustrates the important fact that composition of functions is not a commutative operation: For general functions F and G, F ◦G need not necessarily equal G ◦F (although the two may be equal).

Example 7.3.2 Composition of Functions Defined on Finite Sets

Let X = {1, 2, 3}, Y ′ = {a, b, c, d}, Y = {a, b, c, d, e}, and Z = {x, y, z}. Define func- tions f : X → Y ′ and g: Y → Z by the arrow diagrams below.

X

1

2

3

a

b

d

c

e

ZY

x

y

zY'

f g

Draw the arrow diagram for g◦ f . What is the range of g◦ f ? Solution To find the arrow diagram for g◦ f , just trace the arrows all the way across from

X to Z through Y . The result is shown below.

X

1

2

3

Z

x

y

z

g J f

(g◦ f )(1) = g( f (1)) = g(c) = z (g◦ f )(2) = g( f (2)) = g(b) = y (g◦ f )(3) = g( f (3)) = g(a) = y

The range of g◦ f is {y, z}. ■

Recall that the identity function on a set X, IX , is the function from X to X defined by the formula

IX (x) = x for all x ∈ X.

That is, the identity function on X sends each element of X to itself. What happens when an identity function is composed with another function?

Example 7.3.3 Composition with the Identity Function

Let X = {a, b, c, d} and Y = {u, v, w}, and suppose f : X → Y is given by the arrow diagram shown on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 419

X Yf

a b c d

u

v

w

Find f ◦ IX and IY ◦ f . Solution The values of f ◦ IX are obtained by tracing through the arrow diagram shown

below.

X Y fIX

a

b

c

d

X

a

b

c

d

u

v

w

( f ◦ IX )(a) = f (IX (a)) = f (a) = u ( f ◦ IX )(b) = f (IX (b)) = f (b) = v ( f ◦ IX )(c) = f (IX (c)) = f (c) = v ( f ◦ IX )(d) = f (IX (d)) = f (d) = u

Note that for all elements x in X ,

( f ◦ IX )(x) = f (x). By definition of equality of functions, this means that f ◦ IX = f .

Similarly, the equality IY ◦ f = f can be verified by tracing through the arrow dia- gram below for each x in X and noting that in each case, (IY ◦ f )(x) = f (x).

Y Y f IY

X

u

v

w

u

v

w

a

b

c

d ■

More generally, the composition of any function with an identity function equals the function.

Theorem 7.3.1 Composition with an Identity Function

If f is a function from a set X to a set Y , and IX is the identity function on X , and IY is the identity function on Y , then

(a) f ◦ IX = f and (b) IY ◦ f = f.

Proof:

Part (a): Suppose f is a function from a set X to a set Y and IX is the identity function on X . Then, for all x in X ,

( f ◦ IX )(x) = f (IX (x)) = f (x). Hence, by definition of equality of functions, f ◦ IX = f , as was to be shown. Part (b): This is exercise 13 at the end of this section.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

420 Chapter 7 Functions

Now let f be a function from a set X to a set Y , and suppose f has an inverse function f −1. Recall that f −1 is the function from Y to X with the property that

f −1(y) = x ⇔ f (x) = y.

What happens when f is composed with f −1? Or when f −1 is composed with f ?

Example 7.3.4 Composing a Function with Its Inverse

Let X = {a, b, c} and Y = {x, y, z}. Define f : X → Y by the following arrow diagram.

X Yf

x y z

a b c

Then f is one-to-one and onto. Thus f −1 exists and is found by tracing the arrows back- wards, as shown below.

Y Xf –1

a b c

x y z

Now f −1 ◦ f is found by following the arrows from X to Y by f and back to X by f −1. If you do this, you will see that

( f −1◦ f )(a) = f −1( f (a)) = f −1(z) = a ( f −1 ◦ f )(b) = f −1( f (b)) = f −1(x) = b

and ( f −1 ◦ f )(c) = f −1( f (c)) = f −1(y) = c. Thus the composition of f and f −1 sends each element to itself. So by definition of the identity function,

f −1◦ f = IX . In a similar way, you can see that

f ◦ f −1 = IY . ■

More generally, the composition of any function with its inverse (if it has one) is an identity function. Intuitively, the function sends an element in its domain to an element in its co-domain and the inverse function sends it back again, so the composition of the two sends each element to itself. This reasoning is formalized in Theorem 7.3.2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 421

Theorem 7.3.2 Composition of a Function with Its Inverse

If f : X → Y is a one-to-one and onto function with inverse function f −1: Y → X , then

(a) f −1◦ f = IX and (b) f ◦ f −1 = IY .

Proof:

Part (a): Suppose f : X → Y is a one-to-one and onto function with inverse func- tion f −1: Y → X . [To show that f −1 ◦ f = IX , we must show that for all x ∈ X, ( f −1 ◦ f )(x) = x .] Let x be any element in X . Then

( f −1 ◦ f )(x) = f −1( f (x)) by definition of composition of functions. Now the inverse function f −1 satisfies the condition

f −1(b) = a ⇔ f (a) = b for all a ∈ X and b ∈ Y. 7.3.1 Let

x ′ = f −1( f (x)). 7.3.2 Apply property (7.3.1) with x ′ playing the role of a and f (x) playing the role of b. Then

f (x ′) = f (x). But since f is one-to-one, this implies that x ′ = x . Substituting x for x ′ in equation (7.3.2) gives

x = f −1( f (x)). Then by definition of composition of functions,

( f −1 ◦ f )(x) = x, as was to be shown.

Part (b): This is exercise 14 at the end of this section.

Composition of One-to-One Functions The composition of functions interacts in interesting ways with the properties of being one-to-one and onto. What happens, for instance, when two one-to-one functions are composed? Must their composition be one-to-one? For example, let X = {a, b, c}, Y = {w, x, y, z}, and Z = {1, 2, 3, 4, 5}, and define one-to-one functions f : X → Y and g: Y → Z as shown in the arrow diagrams of Figure 7.3.1.

X

1

2

4

5

3

ZY

a

b

c

w

x

z

y

f g

Figure 7.3.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

422 Chapter 7 Functions

Then g◦ f is the function with the arrow diagram shown in Figure 7.3.2.

X

1

2

4 5

3

Z

a

b

c

g J f

Figure 7.3.2

From the diagram it is clear that for these particular functions, the composition is one- to-one. This result is no accident. It turns out that the compositions of two one-to-one functions is always one-to-one.

Theorem 7.3.3

If f : X → Y and g: Y → Z are both one-to-one functions, then g◦ f is one-to-one.

By the method of direct proof, the proof of Theorem 7.3.3 has the following starting point and conclusion to be shown.

Starting Point: Suppose f is a one-to-one function from X to Y and g is a one-to-one function from Y to Z .

To Show: g◦ f is a one-to-one function from X to Z . The conclusion to be shown says that a certain function is one-to-one. How do you show that? The crucial step is to realize that if you substitute g◦ f into the definition of one-to- one, you see that

g◦ f is one-to-one ⇔ ∀x1, x2 ∈ X, if (g◦ f )(x1) = (g◦ f )(x2) then x1 = x2.

By the method of direct proof, then, to show g◦ f is one-to-one, you suppose x1 and x2 are elements of X such that (g◦ f )(x1) = (g◦ f )(x2),

and you

show that x1 = x2. Now the heart of the proof begins. To show that x1 = x2, you work forward from the supposition that (g◦ f )(x1) = (g◦ f )(x2), using the fact that f and g are both one-to- one. By definition of composition,

(g◦ f )(x1) = g( f (x1)) and (g◦ f )(x2) = g( f (x2)). Since the left-hand sides of the equations are equal, so are the right-hand sides. Thus

g( f (x1)) = g( f (x2)). Now just stare at the above equation for a moment. It says that

g(something) = g(something else).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 423

Because g is a one-to-one function, any time g of one thing equals g of another thing, those two things are equal. Hence

f (x1) = f (x2). But f is also a one-to-one function. Any time f of one thing equals f of another thing, those two things are equal. Therefore,

x1 = x2. This is what was to be shown!

This discussion is summarized in the following formal proof.

Proof of Theorem 7.3.3:

Suppose f : X → Y and g: Y → Z are both one-to-one functions. [We must show that g◦ f is one-to-one.] Suppose x1 and x2 are elements of X such that

(g◦ f )(x1) = (g◦ f )(x2). [We must show that x1 = x2.] By definition of composition of functions,

g( f (x1)) = g( f (x2)). Since g is one-to-one, f (x1) = f (x2). And since f is one-to-one, x1 = x2. [This is what was to be shown.] Hence g◦ f is one-to-one.

Composition of Onto Functions Now consider what happens when two onto functions are composed. For example, let X = {a, b, c, d, e}, Y = {w, x, y, z}, and Z = {1, 2, 3}. Define onto functions f and g by the following arrow diagrams.

X

a

b

d

e

c

ZY

1

2

3

w

x

z

y

f g

Then g◦ f is the function with the arrow diagram shown below. It is clear from the diagram that g◦ f is onto.

X

a

b

d e

c

Z

1

2

3

g J f

It turns out that the composition of any two onto functions (that can be composed) is onto.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

424 Chapter 7 Functions

Theorem 7.3.4

If f : X → Y and g: Y → Z are both onto functions, then g◦ f is onto.

! Caution! To show that a function is onto, you must start with on arbitrary element of the co-domain and deduce that it is the image of some element in the domain.

A direct proof of Theorem 7.3.4 has the following starting point and conclusion to be shown:

Starting Point: Suppose f is an onto function from X to Y , and g is an onto function from Y to Z .

To Show: g◦ f is an onto function from X to Z . The conclusion to be shown says that a certain function is onto. How do you show that? The crucial step is to realize that if you substitute g◦ f into the definition of onto, you see that

g◦ f : X → Z is onto ⇔ given any element z of Z , it is possible to find an element x of X such that (g◦ f )(x) = z.

Since this statement is universal, to prove it you

suppose z is a [particular but arbitrarily chosen] element of Z

and show that there is an element x in X such that (g◦ f )(x) = z. Hence you must start the proof by supposing you are given a particular but arbitrarily chosen element in Z . Let us call it z. Your job is to find an element x in X such that (g◦ f )(x) = z.

To find x , reason from the supposition that z is in Z , using the fact that both g and f are onto. Imagine arrow diagrams for the functions f and g.

Y Z

z

X

gf

g J f

You have a particular element z in Z , and you need to find an element x in X such that when x is sent over to Z by g◦ f , its image will be z. Since g is onto, z is at the tip of some arrow coming from Y . That is, there is an element y in Y such that

g(y) = z. 7.3.3 This means that the arrow diagrams can be drawn as follows:

Y Z

z

X

y gf

g J f

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 425

But f also is onto, so every element in Y is at the tip of an arrow coming from X . In particular, y is at the tip of some arrow. That is, there is an element x in X such that

f (x) = y. 7.3.4 The diagram, therefore, can be drawn as shown below.

Y Z

z

X

y gf

x

g J f

Now just substitute equation (7.3.4) into equation (7.3.3) to obtain

g( f (x)) = z. But by definition of g◦ f ,

g( f (x)) = (g◦ f )(x). Hence

(g◦ f )(x) = z. Thus x is an element of X that is sent by g◦ f to z, and so x is the element you were supposed to find.

This discussion is summarized in the following formal proof.

Proof of Theorem 7.3.4:

Suppose f : X → Y and g: Y → Z are both onto functions. [We must show that g◦ f is onto.] Let z be a [particular but arbitrarily chosen] element of Z . [We must show the existence of an element x in X such that (g◦ f )(x) = z.] Since g is onto, there is an element y in Y such that g(y) = z. And since f is onto, there is an element x in X such that f (x) = y. Hence there exists an element x in X such that

(g◦ f )(x) = g( f (x)) = g(y) = z [as was to be shown]. It follows that g◦ f is onto.

Example 7.3.5 An Incorrect “Proof” That a Function Is Onto

To prove that a composition of onto functions is onto, a student wrote,

“Suppose f : X → Y and g: Y → Z are both onto. Then ∀y ∈ Y, ∃x ∈ X such that f (x) = y (*)

and

∀z ∈ Z , ∃y ∈ Y such that f (y) = z. So

(g◦ f )(x) = g( f (x)) = g(y) = z, and thus g◦ f is onto.”

Explain the mistakes in this “proof.”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

426 Chapter 7 Functions

Solution To show that g◦ f is onto, you must be able to meet the following challenge: If someone gives you an element z in Z (over which you have no control), you must be able to explain how to find an element x in X such that (g◦ f )(x) = z. Thus a proof that g◦ f is onto must start with the assumption that you have been given a particular but arbitrarily chosen element of Z . This proof does not do that.

Moreover, note that statement (*) simply asserts that f is onto. An informal version of (*) is the following: Given any element in the co-domain of f , there is an element in the domain of f that is sent by f to the given element. Use of the symbols x and y to denote these elements is arbitrary. Any other two symbols could equally well have been used. Thus, if we replace the x and y in (*) by u and v, we obtain a logically equivalent statement, and the “proof” becomes the following:

“Suppose f : X → Y and g: Y → Z are both onto. Then ∀v ∈ Y, ∃u ∈ X such that f (u) = v

and

∀z ∈ Z , ∃y ∈ Y such that f (y) = z. So (??!)

(g◦ f )(x) = g( f (x)) = g(y) = z, and thus g◦ f is onto.”

From this logically equivalent version of the “proof,” you can see that the statements leading up to the word So do not provide a rationale for the statement that follows it. The original reason for writing So was based on a misinterpretation of the meaning of the notation. ■

Test Yourself 1. If f is a function from X to Y ′, g is a function from Y to

Z , and Y ′ ⊆ Y , then g◦ f is a function from _____ to _____, and (g◦ f )(x) = _____ for all x in X .

2. If f is a function from X to Y and Ix and Iy are the identity functions from X to X and Y to Y , respectively, then f ◦ Ix = _____ and Iy ◦ f = _____.

3. If f is a one-to-one correspondence from X to Y , then f −1 ◦ f = _____ and f ◦ f −1 = _____.

4. If f is a one-to-one function from X to Y and g is a one-to- one function from Y to Z , you prove that g◦ f is one-to-one by supposing that _____ and then showing that _____.

5. If f is an onto function from X to Y and g is an onto func- tion from Y to Z , you prove that g◦ f is onto by supposing that _____ and then showing that _____.

Exercise Set 7.3 In each of 1 and 2, functions f and g are defined by arrow diagrams. Find G ◦F and f ◦g and determine whether G ◦F equals f ◦g.

1.

1 3 5

X

1 3 5

X f

1 3 5

X

1 3 5

X g

2.

1 3 5

X

1 3 5

X f

1 3 5

X

1 3 5

X g

In 3 and 4, functions F and G are defined by formulas. Find G ◦F and F ◦G and determine whether G ◦F equals F ◦G.

3. F(x) = x3 and G(x) = x − 1, for all real numbers x . 4. F(x) = x5 and G(x) = x1/5 for all real numbers x .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.3 Composition of Functions 427

5. Define f : R → R by the rule f (x) = −x for all real num- bers x . Find ( f ◦ f )(x).

6. Define F : Z → Z and G: Z → Z by the rules F(a) = 7a and G(a) = a mod 5 for all integers a. Find (G ◦F)(0), (G ◦F)(1), (G ◦F)(2), (G ◦F)(3), and (G ◦F)(4).

7. Define H : Z → Z and K : Z → Z by the rules H(a) = 6a and K (a) = a mod 4 for all integers a. Find (K ◦H)(0), (K ◦H)(1), (K ◦H)(2), and (K ◦H)(3).

8. Define L: Z → Z and M : Z → Z by the rules L(a) = a2 and M(a) = a mod 5 for all integers a. a. Find (L ◦M)(12), (M ◦ L)(12), (L ◦M)(9), and

(M ◦ L)(9). b. Is L ◦M = M ◦L?

The functions of each pair in 9–11 are inverse to each other. For each pair, check that both compositions give the identity func- tion.

9. F: R → R and F−1: R → R are defined by

F(x) = 3x + 2 and F−1(y) = y − 2 3

,

for all y ∈ R. 10. G: R+ → R+ and G−1: R+ → R+ are defined by

G(x) = x2 and G−1(x) = √x,

for all x ∈ R+. 11. H and H−1 are both defined from R− {1} to R− {1} by

the formula

H(x) = H−1(x) = x + 1 x − 1 , for all x ∈ R− {1}.

12. Explain how it follows from the definition of logarithm that a. logb(b

x ) = x , for all real numbers x . b. blogb x = x , for all positive real numbers x .

13.H Prove Theorem 7.3.1(b): If f is any function from a set X to a set Y , then IY ◦ f = f , where IY is the identity function on Y .

14. Prove Theorem 7.3.2(b): If f : X → Y is a one-to-one and onto function with inverse function f −1: Y → X , then f ◦ f −1 = IY , where IY is the identity function on Y .

15. Suppose Y and Z are sets and g: Y → Z is a one-to-one function. This means that if g takes the same value on any two elements of Y , then those elements are equal. Thus, for example, if a and b are elements of Y and g(a) = g(b), then it can be inferred that a = b. What can be inferred in the following situations?

a. sk and sm are elements of Y and g(sk) = g(sm). b. z/2 and t/2 are elements of Y and g(z/2) = g(t/2). c. f (x1) and f (x2) are elements of Y and g( f (x1)) =

g( f (x2)).

16. If f : X → Y and g: Y → Z are functions and g◦ f is one-to-one, must g be one-to-one? Prove or give a counterexample.

17. If f : X → Y and g: Y → Z are functions and g◦ f is onto, must f be onto? Prove or give a counterexample.

18.H If f : X → Y and g: Y → Z are functions and g◦ f is one-to-one, must f be one-to-one? Prove or give a counterexample.

19.H If f : X → Y and g: Y → Z are functions and g◦ f is onto, must g be onto? Prove or give a counterexample.

20. Let f : W → X, g: X → Y , and h: Y → Z be func- tions. Must h ◦(g◦ f ) = (h ◦g)◦ f ? Prove or give a counterexample.

21. True or False? Given any set X and given any functions f : X → X, g: X → X , and h: X → X , if h is one-to-one and h ◦ f = h ◦g, then f = g. Justify your answer.

22. True or False? Given any set X and given any functions f : X → X, g: X → X , and h: X → X , if h is one-to-one and f ◦h = g◦h, then f = g. Justify your answer.

In 23 and 24 find g◦ f, (g◦ f )−1, g−1, f −1, and f −1 ◦g−1, and state how (g◦ f )−1 and f −1 ◦g−1 are related. 23. Let X = {a, c, b}, Y = {x, y, z}, and Z = {u, v, w}. Define

f : X → Y and g: Y → Z by the arrow diagrams below. X

a

b

c

Z

u

v

w

Y

x

y

z

f g

24. Define f : R → R and g: R → R by the formulas f (x) = x + 3 and g(x) = −x for all x ∈ R.

25. Prove or give a counterexample: If f : X → Y and g: Y → X are functions such that g◦ f = IX and f ◦g = IY , then f and g are both one-to-one and onto and g = f −1.

26.H Suppose f : X → Y and g: Y → Z are both one-to-one and onto. Prove that (g◦ f )−1 exists and that (g◦ f )−1 = f −1 ◦g−1.

27. Let f : X → Y and g: Y → Z . Is the following prop- erty true or false? For all subsets C in Z , (g◦ f )−1(C) = ( f −1(g−1(C)). Justify your answer.

Answers for Test Yourself 1. X; Z; g( f (x)) 2. f ; f 3. IX ; IY 4. x1 and x2 are any [particular but arbitrarily chosen] elements in X with the property that (g◦ f )(x1) = (g◦ f )(x2); x1 = x2 5. z is any [particular but arbitrarily chosen] element in Z ; there exists at least one element x in X such that (g◦ f )(x) = z

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

428 Chapter 7 Functions

7.4 Cardinality with Applications to Computability There are as many squares as there are numbers because they are just as numerous as their roots. — Galileo Galilei, 1632

Historically, the term cardinal number was introduced to describe the size of a set (“This set has eight elements”) as distinguished from an ordinal number that refers to the order of an element in a sequence (“This is the eighth element in the row”). The definition of cardinal number derives from the primitive technique of representing numbers by fingers or tally marks. Small children, when asked how old they are, will often answer by holding up a certain number of fingers, each finger being paired with a year of their life. As was discussed in Section 7.2, a pairing of the elements of two sets is called a one-to-one correspondence. We say that two finite sets whose elements can be paired by a one-to-one correspondence have the same size. This is illustrated by the following diagram.

A

a b c d

B

u v

w

x

The elements of set A can be put into one-to-one correspondence with the elements of B.

iS to

ck ph

ot o.

co m

/S te

ve n

W yn

n

Galileo Galilei (1564–1642)

Now a finite set is one that has no elements at all or that can be put into one-to- one correspondence with a set of the form {1, 2, . . . , n} for some positive integer n. By contrast, an infinite set is a nonempty set that cannot be put into one-to-one correspondence with {1, 2, . . . , n} for any positive integer n. Suppose that, as suggested by the quote from Galileo at the beginning of this section, we extend the concept of size to infinite sets by saying that one infinite set has the same size as another if, and only if, the first set can be put into one-to-one correspondence with the second. What consequences follow from such a definition? Do all infinite sets have the same size, or are some infinite sets larger than others? These are the questions we address in this section. The answers are sometimes surprising and have the interesting consequence that there are functions defined on the set of integers whose values cannot be computed on a computer.

• Definition Let A and B be any sets. A has the same cardinality as B if, and only if, there is a one-to-one correspondence from A to B. In other words, A has the same cardinality as B if, and only if, there is a function f from A to B that is one-to-one and onto.

The following theorem gives some basic properties of cardinality, most of which fol- low from statements proved earlier about one-to-one and onto functions.

Theorem 7.4.1 Properties of Cardinality

For all sets A, B, and C :

a. Reflexive property of cardinality: A has the same cardinality as A.

b. Symmetric property of cardinality: If A has the same cardinality as B, then B has the same cardinality as A.

c. Transitive property of cardinality: If A has the same cardinality as B and B has the same cardinality as C , then A has the same cardinality as C .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 429

Proof:

Part (a), Reflexivity: Suppose A is any set. [To show that A has the same cardinality as A, we must show there is a one-to-one correspondence from A to A.] Consider the identity function IA from A to A. This function is one-to-one because if x1 and x2 are any elements in A with IA(x1) = IA(x2), then, by definition of IA, x1 = x2. The identity function is also onto because if y is any element of A, then y = IA(y) by definition of IA. Hence IA is a one-to-one correspondence from A to A. [So there exists a one-to-one correspondence from A to A, as was to be shown.]

Part (b), Symmetry: Suppose A and B are any sets and A has the same cardinality as B. [We must show that B has the same cardinality as A.] Since A has the same cardinality as B, there is a function f from A to B that is one-to-one and onto. But then, by Theorems 7.2.2 and 7.2.3, there is a function f −1 from B to A that is also one-to-one and onto. Hence B has the same cardinality as A [as was to be shown].

Part (c), Transitivity: Suppose A, B, and C are any sets and A has the same cardi- nality as B and B has the same cardinality as C . [We must show that A has the same cardinality as C.] Since A has the same cardinality as B, there is a function f from A to B that is one-to-one and onto, and since B has the same cardinality as C , there is a function g from B to C that is one-to-one and onto. But then, by Theorems 7.3.3 and 7.3.4, g◦ f is a function from A to C that is one-to-one and onto. Hence A has the same cardinality as C [as was to be shown].

Note that Theorem 7.4.1(b) makes it possible to say simply that two sets have the same cardinality instead of always having to say that one set has the same cardinality as another. That is, the following definition can be made.

• Definition A and B have the same cardinality if, and only if, A has the same cardinality as B or B has the same cardinality as A.

The following example illustrates a very important property of infinite sets—namely, that an infinite set can have the same cardinality as a proper subset of itself. This property is sometimes taken as the definition of infinite set. The example shows that even though it may seem reasonable to say that there are twice as many integers as there are even integers, the elements of the two sets can be matched up exactly, and so, according to the definition, the two sets have the same cardinality.

Example 7.4.1 An Infinite Set and a Proper Subset Can Have the Same Cardinality

Let 2Z be the set of all even integers. Prove that 2Z and Z have the same cardinality.

Solution Consider the function H from Z to 2Z defined as follows:

H(n) = 2n for all n ∈ Z.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

430 Chapter 7 Functions

A (partial) arrow diagram for H is shown below.

Z 2Z H

3 2 1 0

–1 –2 –3

6 4 2 0 –2 –4 –6

To show that H is one-to-one, suppose H(n1) = H(n2) for some integers n1 and n2. Then 2n1 = 2n2 by definition of H , and dividing both sides by 2 gives n1 = n2. Hence h is one-to-one.

To show that H is onto, suppose m is any element of 2Z. Then m is an even integer, and so m = 2k for some integer k. It follows that H(k) = 2k = m. Thus there exists k in Z with H(k) = m, and hence H is onto.

Therefore, by definition of cardinality, Z and 2Z have the same cardinality. ■Note So there are “as many” even integers as there are integers!

In Section 9.4 we will show that a function from one finite set to another set of the same size is one-to-one if, and only if, it is onto. This result does not hold for infinite sets. Although it is true that for two infinite sets to have the same cardinality there must exist a function from one to the other that is both one-to-one and onto, it is also always the case that:

If A and B are infinite sets with the same cardinality, then there exist functions from A to B that are one-to-one but not onto and functions from A to B that are onto but not one-to-one.

For instance, since the function H in Example 7.4.1 is one-to-one and onto, Z and 2Z have the same cardinality. But the “inclusion function” I from 2Z to Z, given by I (n) = n for all even integers n, is one-to-one but not onto. And the function J from Z to 2Z defined by J (n) = 2⌊n/2⌋, for all integers n, is onto but not one-to-one. (See exercise 6 at the end of this section.)

Countable Sets The set Z+ of counting numbers {1, 2, 3, 4, . . .} is, in a sense, the most basic of all infinite sets. A set A having the same cardinality as this set is called countably infinite. The reason is that the one-to-one correspondence between the two sets can be used to “count” the elements of A: If F is a one-to-one and onto function from Z+ to A, then F(1) can be designated as the first element of A, F(2) as the second element of A, F(3) as the third element of A, and so forth. This is illustrated graphically in Figure 7.4.1 on the next page. Because F is one-to-one, no element is ever counted twice, and because it is onto, every element of A is counted eventually.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 431

1 2 3

“First” element of A “Second” element of A “Third” element of A

Z+ A F

Figure 7.4.1 “Counting” a Countably Infinite Set

• Definition A set is called countably infinite if, and only if, it has the same cardinality as the set of positive integers Z+. A set is called countable if, and only if, it is finite or countably infinite. A set that is not countable is called uncountable.

Example 7.4.2 Countability of Z, the Set of All Integers

Show that the set Z of all integers is countable.

Solution The set Z of all integers is certainly not finite, so if it is countable, it must be because it is countably infinite. To show that Z is countably infinite, find a function from the positive integers Z+ to Z that is one-to-one and onto. Looked at in one light, this contradicts common sense; judging from the diagram below, there appear to be more than twice as many integers as there are positive integers.

· · ·− 5 − 4 − 3 − 2 − 1 0 positive integers

︷ ︸︸ ︷ 1 2 3 4 5 · · ·︸ ︷︷ ︸

all integers

But you were alerted that results in this section might be surprising. Try to think of a way to “count” the set of all integers anyway.

The trick is to start in the middle and work outward systematically. Let the first integer be 0, the second 1, the third −1, the fourth 2, the fifth −2, and so forth as shown in Figure 7.4.2, starting at 0 and swinging outward in back-and-forth arcs from positive to negative integers and back again, picking up one additional integer at each swing.

11 9 7 5 3 1 2 4 6 8 10 –5 –4 –3 –2 –1 0 1 2 3 4 5Integers:

The “count ” of each integer:

Figure 7.4.2 “Counting” the Set of All Integers

It is clear from the diagram that no integer is counted twice (so the function is one-to- one) and every integer is counted eventually (so the function is onto). Consequently, this diagram defines a function from Z+ to Z that is one-to-one and onto. Even though in one sense there seem to be more integers than positive integers, the elements of the two sets

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

432 Chapter 7 Functions

can be paired up one for one. It follows by definition of cardinality that Z+ has the same cardinality as Z. Thus Z is countably infinite and hence countable.

The diagrammatic description of the previous function is acceptable as given. You can check, however, that the function can also be described by the explicit formula

F(n) =

⎧ ⎪⎪⎨

⎪⎪⎩

n 2

if n is an even positive integer

−n − 1 2

if n is an odd positive integer. ■

Example 7.4.3 Countability of 2Z, the Set of All Even Integers

Show that the set 2Z of all even integers is countable.

Solution Example 7.4.2 showed that Z+ has the same cardinality as Z, and Example 7.4.1 showed that Z has the same cardinality as 2Z. Thus, by the transitive property of cardin- ality, Z+ has the same cardinality as 2Z. It follows by definition of countably infinite that 2Z is countably infinite and hence countable. ■

The Search for Larger Infinities: The Cantor Diagonalization Process

Every infinite set we have discussed so far has been countably infinite. Do any larger infinities exist? Are there uncountable sets? Here is one candidate.

Imagine the number line as shown below.

· · · −4 −3 −2 −1 0 1 2 3 4 · · · ←−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−→

As noted in Section 1.2, the integers are spread along the number line at discrete intervals. The rational numbers, on the other hand, are dense: Between any two rational numbers, no matter how close, lies another rational number (the average of the two numbers, for instance; see exercise 17). This suggests the conjecture that the infinity of the set of rational numbers is larger than the infinity of the set of integers.

Amazingly, this conjecture is false. Despite the fact that the rational numbers are crowded onto the number line whereas the integers are quite separated, the set of all rational numbers can be put into one-to-one correspondence with the set of integers. The next example gives part of a proof of this fact. It shows that the set of all positive rational numbers can be put into one-to-one correspondence with the set of all positive integers. In exercise 16 at the end of this section you are asked to use this result, together with a technique similar to that of Example 7.4.2, to show that the set of all rational numbers is countable.

Example 7.4.4 The Set of All Positive Rational Numbers Is Countable

Show that the set Q+ of all positive rational numbers is countable.

Solution Display the elements of the set Q+ of positive rational numbers in a grid as shown in Figure 7.4.3 on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 433

1 1

1 2

1 3

1 4

1 5

1 6

2 1

2 2

2 3

2 4

2 5

2 6

3 1

3 2

3 3

3 4

3 5

3 6

4 1

4 2

4 3

4 4

4 5

4 6

5 1

5 2

5 3

5 4

5 5

5 6

6 1

6 2

6 3

6 4

6 5

6 6

Figure 7.4.3

Define a function F from Z+ to Q+ by starting to count at 11 and following the arrows as indicated, skipping over any number that has already been counted.

To be specific: Set F(1) = 11 , F(2) = 1 2 , F(3) =

2 1 and F(4) =

3 1 . Then skip

2 2 since

2 2 = 11 , which was counted first. After that, set F(5) = 13 , F(6) = 14 , F(7) = 23 , F(8) = 32 , F(9) =

4 1 , and F(10) =

5 1 . Then skip

4 2 ,

3 3 , and

2 4 (since

4 2 = 21 , 33 = 11 ,

and 24 = 12 ) and set F(11) = 15 . Continue in this way, defining F(n) for each positive integer n.

Note that every positive rational number appears somewhere in the grid, and the counting procedure is set up so that every point in the grid is reached eventually. Thus the function F is onto. Also, skipping numbers that have already been counted ensures that no number is counted twice. Thus F is one-to-one. Consequently, F is a function from Z+ to Q+ that is one-to-one and onto, and so Q+ is countably infinite and hence countable. ■

al-Kashi (1380–1429)

In 1874 the German mathematician Georg Cantor achieved success in the search for a larger infinity by showing that the set of all real numbers is uncountable. His method of proof was somewhat complicated, however. We give a proof of the uncountability of the set of all real numbers between 0 and 1 using a simpler technique introduced by Cantor in 1891 and now called the Cantor diagonalization process. Over the intervening years, this technique and variations on it have been used to establish a number of important results in logic and the theory of computation.

Before stating and proving Cantor’s theorem, we note that every real number, which is a measure of location on a number line, can be represented by a decimal expansion of the form

a0.a1a2a3 . . . ,

where a0 is an integer (positive, negative, or zero) and for each i ≥ 1, ai is an integer from 0 through 9.

B et

tm an

n/ CO

R B

IS

Simon Stevin (1548–1620)

This way of thinking about numbers was developed over several centuries by math- ematicians in the Chinese, Hindu, and Islamic worlds, culminating in the work of Ghiyāth al-Dı̄n Jamshı̄d al-Kashi in 1427. In Europe it was first clearly formulated and successfully promoted by the Flemish mathematician Simon Stevin in 1585. We illustrate the concept with an example.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

434 Chapter 7 Functions

Consider the point P in Figure 7.4.4. Figure 7.4.4(a) shows P located between 1 and 2. When the interval from 1 to 2 is divided into ten equal subintervals (see Figure 7.4.4(b)) P is seen to lie between 1.6 and 1.7. If the interval from 1.6 to 1.7 is itself divided into ten equal subintervals (see Figure 7.4.4(c)), the P is seen to lie between 1.62 and 1.63 but closer to 1.62 than to 1.63. So the first three digits of the decimal expansion for P are 1.62.

–3 –1–2 0 1 2 3

1.0

1.60 1.62 1.63 1.65 1.70

1.5 1.6 1.7 2.0

P

P

P

(b)

(a)

(c)

Figure 7.4.4

Assuming that any interval of real numbers, no matter how small, can be divided into ten equal subintervals, the process of obtaining additional digits in the decimal expansion for P can, in theory, be repeated indefinitely. If at any stage P is seen to be a subdivision point, then all further digits in the expansion may be taken to be 0. If not, then the process gives an expansion with an infinite number of digits.

The resulting decimal representation for P is unique except for numbers that end in infinitely repeating 9’s or infinitely repeating 0’s. For example (see exercise 25 at the end of this section),

0.199999 . . . = 0.200000 . . . . Let us agree to express any such decimal in the form that ends in all 0’s so that we will have a unique representation for every real number.

Theorem 7.4.2 (Cantor)

The set of all real numbers between 0 and 1 is uncountable.

Proof (by contradiction):

Suppose the set of all real numbers between 0 and 1 is countable. Then the decimal representations of these numbers can be written in a list as follows:

0.a11a12a13 · · · a1n · · · 0.a21a22a23 · · · a2n · · · 0.a31a32a33 · · · a3n · · ·

...

0.an1an2an3 · · · ann · · · ...

[We will derive a contradiction by showing that there is a number between 0 and 1 that does not appear on this list.]

For each pair of positive integers i and j , the j th decimal digit of the i th number on the list is ai j . In particular, the first decimal digit of the first number on the list is

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 435

a11, the second decimal digit of the second number on the list is a22, and so forth. As an example, suppose the list of real numbers between 0 and 1 starts out as follows:

0. ✞✝☎✆2 0 1 4 8 8 0 2 . . .

0. 1 ✞✝☎✆1 6 6 6 0 2 1 . . .

0. 0 3 ✞✝☎✆3 5 3 3 2 0 . . .

0. 9 6 7 ✞✝☎✆7 6 8 0 9 . . .

0. 0 0 0 3 ✞✝☎✆1 0 0 2 . . .

...

The diagonal elements are circled: a11 is 2, a22 is 1, a33 is 3, a44 is 7, a55 is 1, and so forth.

Construct a new decimal number d = 0.d1d2d3 · · · dn · · · as follows:

dn = {

1 if ann ̸= 1 2 if ann = 1 .

In the previous example,

d1 is 1 because a11 = 2 ̸= 1, d2 is 2 because a22 = 1, d3 is 1 because a33 = 3 ̸= 1, d4 is 1 because a44 = 7 ̸= 1, d5 is 2 because a55 = 1,

and so forth. Hence d would equal 0.12112 . . . . The crucial observation is that for each integer n, d differs in the nth decimal

position from the nth number on the list. But this implies that d is not on the list! In other words, d is a real number between 0 and 1 that is not on the list of all real numbers between 0 and 1. This contradiction shows the falseness of the supposition that the set of all numbers between 0 and 1 is countable. Hence the set of all real numbers between 0 and 1 is uncountable.

Along with demonstrating the existence of an uncountable set, Cantor developed a whole arithmetic theory of infinite sets of various sizes. One of the most basic theorems of the theory states that any subset of a countable set is countable.

Theorem 7.4.3

Any subset of any countable set is countable.

Proof:

Let A be a particular but arbitrarily chosen countable set and let B be any subset of A. [We must show that B is countable.] Either B is finite or it is infinite. If B is finite, then B is countable by definition of countable, and we are done. So suppose B is infinite. Since A is countable, the distinct elements of A can be represented as a sequence

a1, a2, a3, . . . .

Define a function g: Z+ → B inductively as follows: continued on page 436

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

436 Chapter 7 Functions

1. Search sequentially through elements of a1, a2, a3, . . . until an element of B is found. [This must happen eventually since B ⊆ A and B ̸= ∅.] Call that ele- ment g(1).

2. For each integer k ≥ 2, suppose g(k − 1) has been defined. Then g(k − 1) = ai for some ai in {a1, a2, a3, . . .}. Starting with ai+1, search sequentially through ai+1, ai+2, ai+3, . . . trying to find an element of B. One must be found eventu- ally because B is infinite, and {g(1), g(2), . . . , g(k − 1)} is a finite set. When an element of B is found, define it to be g(k).

By (1) and (2) above, the function g is defined for each positive integer. Since the elements of a1, a2, a3, . . . are all distinct, g is one-to-one. Furthermore,

the searches for elements of B are sequential: Each picks up where the previous one left off. Thus every element of A is reached during some search. But all the elements of B are located somewhere in the sequence a1, a2, a3, . . . , and so every element of B is eventually found and made the image of some integer. Hence g is onto. These remarks show that g is a one-to-one correspondence from Z+ to B. So B is countably infinite and thus countable.

Note If g(k − 1) = ai , then g(k) could also be defined by applying the well-ordering principle for the integers to the set {n ∈ Z | n > i and ai ∈ B}.

An immediate consequence of Theorem 7.4.3 is the following corollary.

Corollary 7.4.4

Any set with an uncountable subset is uncountable.

Proof: Consider the following equivalent phrasing of Theorem 7.4.3: For all sets S and for all subsets A of S, if S is countable, then A is countable. The contrapositive of this statement is logically equivalent to it and states: For all sets S and for all subsets A of S, if A is uncountable then S is uncountable. But this is an equivalent phrasing for the corollary. So the corrollary is proved.

Corollary 7.4.4 implies that the set of all real numbers is uncountable because the subset of numbers between 0 and 1 is uncountable. In fact, as Example 7.4.5 shows, the set of all real numbers has the same cardinality as the set of all real numbers between 0 and 1! This fact is further explored in exercises 13 and 14 at the end of this section.

Example 7.4.5 The Cardinality of the Set of All Real Numbers

Show that the set of all real numbers has the same cardinality as the set of real numbers between 0 and 1.

Solution Let S be the open interval of real numbers between 0 and 1: S = {x ∈ R | 0 < x < 1}.

Imagine picking up S and bending it into a circle as shown below. Since S does not include either endpoint 0 or 1, the top-most point of the circle is omitted from the drawing.

7 8

3 4

1 2

3 8

5 8

1 4

1 8

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 437

Define a function F: S → R as follows: Draw a number line and place the interval, S, somewhat enlarged and bent into a

circle, tangent to the line above the point 0. This is shown below.

Number line

0–1–2–3 1 2 3

x

L

F(x)

For each point x on the circle representing S, draw a straight line L through the top- most point of the circle and x . Let F(x) be the point of intersection of L and the number line. (F(x) is called the projection of x onto the number line.)

It is clear from the geometry of the situation that distinct points on the circle go to distinct points on the number line, so F is one-to-one. In addition, given any point y on the number line, a line can be drawn through y and the top-most point of the circle. This line must intersect the circle at some point x , and, by definition, y = F(x). Thus F is onto. Hence F is a one-to-one correspondence from S to R, and so S and R have the same cardinality. ■

You know that every positive integer is a real number, so putting Example 7.4.5 together with Cantor’s theorem (Theorem 7.4.2) shows that the infinity of the set of all real numbers is “greater” than the infinity of the set of all positive integers. In exercise 35, you are asked to show that any set and its power set have different cardinalities. Because there is a one-to-one function from any set to its power set (the function that takes each element a to the singleton set {a}), this implies that the cardinality of any set is “less than” the cardinality of its power set. As a result, you can create an infinite sequence of larger and larger infinities! For example, you could begin with Z, the set of all integers, and take Z, P(Z), P(P(Z)), P(P(P(Z))), and so forth.

Application: Cardinality and Computability Knowledge of the countability and uncountability of certain sets can be used to answer a question of computability. We begin by showing that a certain set is countable.

Example 7.4.6 Countability of the Set of Computer Programs in a Computer Language

Show that the set of all computer programs in a given computer language is countable.

Solution This result is a consequence of the fact that any computer program in any language can be regarded as a finite string of symbols in the (finite) alphabet of the lan- guage.

Given any computer language, let P be the set of all computer programs in the lan- guage. Either P is finite or P is infinite. If P is finite, then P is countable and we are done. If P is infinite, set up a binary code to translate the symbols of the alphabet of the language into strings of 0’s and 1’s. (For instance, either the seven-bit American Standard Code for Information Interchange, known as ASCII, or the eight-bit Extended Binary-Coded Decimal Interchange Code, known as EBCDIC, might be used.)

For each program in P , use the code to translate all the symbols in the program into 0’s and 1’s. Order these strings by length, putting shorter before longer, and order all

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

438 Chapter 7 Functions

strings of a given length by regarding each string as a binary number and writing the numbers in ascending order.

Define a function F: Z+ → P by specifying that F(n) = the nth program in the list for each n ∈ Z+.

By construction, F is one-to-one and onto, and so P is countably infinite and hence countable. As a simple example, suppose the following are all the programs in P that translate into bit strings of length less than or equal to 5:

10111, 11, 0010, 1011, 01, 00100, 1010, 00010.

Ordering these by length gives

length 2: 11, 01

length 4: 0010, 1011, 1010

length 5: 10111, 00100, 00010

And ordering those of each given length by the size of the binary number they repre- sent gives

01 = F(1) 11 = F(2) 0010 = F(3) 1010 = F(4) 1011 = F(5) 00010 = F(6) 00100 = F(7) 10111 = F(8)

Note that when viewed purely as numbers, ignoring leading zeros, 0010 = 00010. This shows the necessity of first ordering the strings by length before arranging them in ascending numeric order. ■

The final example of this section shows that a certain set is uncountable and hence that there must exist a noncomputable function.

Example 7.4.7 The Cardinality of a Set of Functions and Computability

a. Let T be the set of all functions from the positive integers to the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Show that T is uncountable.

b. Derive the consequence that there are noncomputable functions. Specifically, show that for any computer language there must be a function F from Z+ to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} with the property that no computer program can be written in the language to take arbitrary values as input and output the corresponding function values.

Solution

a. Let S be the set of all real numbers between 0 and 1. As noted before, any number in S can be represented in the form

0.a1a2a3 . . . an . . . ,

where each ai is an integer from 0 to 9. This representation is unique if decimals that end in all 9’s are omitted.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 439

Define a function F from S to a subset of T (the set of all functions from Z+ to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) as follows:

F(0.a1a2a3 . . . an . . .) = the function that sends each positive integer n to an.

Choose the co-domain of F to be exactly that subset of T that makes F onto. That is, define the co-domain of F to equal the image of F . Note that F is one-to-one because if F(x1) = F(x2), then each decimal digit of x1 equals the corresponding decimal digit of x2, and so x1 = x2. Thus F is a one-to-one correspondence from S to a subset of T . But S is uncountable by Theorem 7.4.2. Hence T has an uncountable subset, and so, by Corollary 7.4.4, T is uncountable.

b. Part (a) shows that the set T of all functions from Z+ to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} is uncountable. But Example 7.4.6 shows that given any computer language, the set of all programs in that language is countable. Consequently, in any computer language there are not enough programs to compute values of every function in T . There must exist functions that are not computable! ■

Test Yourself 1. A set is finite if, and only if, _____.

2. To prove that a set A has the same cardinality as a set B you must _____.

3. The reflexive property of cardinality says that given any set A, _____.

4. The symmetric property of cardinality says that given any sets A and B, _____.

5. The transitive property of cardinality says that given any sets A, B, and C , _____.

6. A set is called countably infinite if, and only if, _____.

7. A set is called countable if, and only if, _____.

8. In each of the following, fill in the blank with the word countable or the word uncountable.

(a) The set of all integers is _____.

(b) The set of all rational numbers is _____.

(c) The set of all real numbers between 0 and 1 is _____.

(d) The set of all real numbers is _____.

9. The Cantor diagonalization process is used to prove that _____.

Exercise Set 7.4 1. When asked what it means to say that set A has the same

cardinality as set B, a student replies, “A and B are one-to- one and onto.” What should the student have replied? Why?

2. Show that “there are as many squares as there are num- bers” by exhibiting a one-to-one correspondence from the positive integers, Z+, to the set S of all squares of positive integers:

S = {n ∈ Z+ | n = k2, for some positive integer k}.

3. Let 3Z = {n ∈ Z | n = 3k, for some integer k}. Prove that Z and 3Z have the same cardinality.

4. Let O be the set of all odd integers. Prove that O has the same cardinality as 2Z, the set of all even integers.

5. Let 25Z be the set of all integers that are multiples of 25. Prove that 25Z has the same cardinality as 2Z, the set of all even integers.

6.H Use the functions I and J defined in the paragraph following Example 7.4.1 to show that even though there is a one-to-one correspondence, H , from 2Z to Z, there is also a function from 2Z to Z that is one-to-one but not onto and a function from Z to 2Z that is onto but not one-to-one. In other words, show that I is one-to-one but not onto, and show that J is onto but not one-to-one.

7. a. Check that the formula for F given at the end of Example 7.4.2 produces the correct values for n = 1, 2, 3, and 4.

b. Use the floor function to write a formula for F as a single algebraic expression for all positive integers n.

8. Use the result of exercise 3 to prove that 3Z is countable.

9. Show that the set of all nonnegative integers is countable by exhibiting a one-to-one correspondence between Z+ and Znonneg .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

440 Chapter 7 Functions

In 10–14, S denotes the set of real numbers strictly between 0 and 1. That is, S = {x ∈ R | 0 < x < 1}.

10. Let U = {x ∈ R | 0 < x < 2}. Prove that S and U have the same cardinality.

11.H Let V = {x ∈ R | 2 < x < 5}. Prove that S and V have the same cardinality.

12. Let a and b be real numbers with a < b, and suppose that W = {x ∈ R | a < x < b}. Prove that S and W have the same cardinality.

13. Draw the graph of the function f defined by the following formula:

For all real numbers x with 0 < x < 1,

f (x) = tan ( πx − π

2

) ·

Use the graph to explain why S and R have the same cardinality.

14.✶ Define a function g from the set of real numbers to S by the following formula:

For all real numbers x ,

g(x) = 1 2

· (

x 1 + |x |

) + 1

2 ·

Prove that g is a one-to-one correspondence. (It is possible to prove this statement either with calculus or without it.) What conclusion can you draw from this fact?

15. Show that the set of all bit strings (strings of 0’s and 1’s) is countable.

16. Show that Q, the set of all rational numbers, is countable.

17. Show that the set Q of all rational numbers is dense along the number line by showing that given any two rational numbers r1 and r2 with r1 < r2, there exists a rational num- ber x such that r1 < x < r2.

18.H Must the average of two irrational numbers always be irrational? Prove or give a counterexample.

19.✶H Show that the set of all irrational numbers is dense along the number line by showing that given any two real numbers, there is an irrational number in between.

20. Give two examples of functions from Z to Z that are one- to-one but not onto.

21. Give two examples of functions from Z to Z that are onto but not one-to-one.

22.H Define a function g: Z+ × Z+ → Z+ by the formula g(m, n) = 2m3n for all (m, n) ∈ Z+ × Z+. Show that g is one-to-one and use this result to prove that Z+ × Z+ is countable.

23. a. Explain how to use the following diagram to show that Znonneg × Znonneg and Znonneg have the same cardinality.

(0, 0)

(0, 1)

(0, 2)

(0, 3)

(1, 0)

(1, 1)

(1, 2)

(1, 3)

(1, 4)

(2, 0)

(2, 1)

(2, 2)

(2, 3)

(2, 4)

(3, 0)

(3, 1)

(3, 2)

(3, 3)

(3, 4)

(4, 0)

(4, 1)

(4, 2)

(4, 3)

(4, 4)(0, 4) ...

... ...

... ...

. . .

. . .

. . .

. . .

. . .

b.✶H Define a function H: Znonneg × Znonneg → Znonneg by the formula

H(m, n) = n + (m + n)(m + n + 1) 2

for all nonnegative integers m and n. Interpret the action of H geometrically using the diagram of part (a).

24.✶ Prove that the function H defined analytically in exercise 23b is a one-to-one correspondence.

25.H Prove that 0.1999 . . . = 0.2. 26. Prove that any infinite set contains a countably infinite

subset.

27. If A is any countably infinite set, B is any set, and g: A → B is onto, then B is countable.

28. Prove that a disjoint union of any finite set and any count- ably infinite set is countably infinite.

29.H Prove that a union of any two countably infinite sets is countably infinite.

30.H Use the result of exercise 29 to prove that the set of all irra- tional numbers is uncountable.

31.H Use the results of exercises 28 and 29 to prove that a union of any two countable sets is countable.

32.H Prove that Z × Z, the Cartesian product of the set of inte- gers with itself, is countably infinite.

33. Use the results of exercises 27, 31, and 32 to prove the fol- lowing: If R is the set of all solutions to all equations of the form x2 + bx + c = 0, where b and c are integers, then R is countable.

34.H Let P(S) be the set of all subsets of set S, and let T be the set of all functions from S to {0, 1}. Show that P(S) and T have the same cardinality.

35.H Let S be a set and let P(S) be the set of all subsets of S. Show that S is “smaller than” P(S) in the sense that there is a one-to-one function from S to P(S) but there is no onto function from P(S) to S.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

7.4 Cardinality with Applications to Computability 441

36.✶ The Schroeder–Bernstein theorem states the following: If A and B are any sets with the property that there is a one- to-one function from A to B and a one-to-one function from B to A, then A and B have the same cardinality. Use this theorem to prove that there are as many functions from Z+

to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} as there are functions from Z+ to {0, 1}.

37.H Prove that if A and B are any countably infinite sets, then A × B is countably infinite.

38.✶ Suppose A1, A2, A3, . . . is an infinite sequence of countable sets. Recall that

∞⋃

i=1 Ai = {x | x ∈ Ai for some positive integer i}.

Prove that ⋃∞

i=1 Ai is countable. (In other words, prove that a countably infinite union of countable sets is countable.)

Answers for Test Yourself 1. it is the empty set or there is a one-to-one correspondence from {1, 2, . . . , n} to it, where n is a positive integer 2. show that there exists a function from A to B that is one-to-one and onto (Or: show that there exists a one-to-one correspondence from A to B) 3. A has the same cardinality as A. 4. if A has the same cardinality as B, then B has the same cardinality as A 5. if A has the same cardinality as B and B has the same cardinality as C , then A has the same cardinality as C 6. it has the same cardinality as the set of all positive integers 7. it is finite or countably infinite 8. countable; countable; uncountable; uncountable 9. the set of all real numbers between 0 and 1 is uncountable

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

442

CHAPTER 8

RELATIONS

In this chapter we discuss the mathematics of relations defined on sets, focusing on ways to represent relations and exploring various properties they may have. The concept of equivalence relation is introduced in Section 8.3 and applied in Section 8.4 to modular arithmetic and cryptography. Partial order relations are discussed in Section 8.5, and an application is given showing how to use these relations to help coordinate and guide the flow of individual tasks that must be performed to accomplish a complex, large-scale project.

8.1 Relations on Sets Strange as it may sound, the power of mathematics rests on its evasion of all unnecessary thought and on its wonderful saving of mental operations. — Ernst Mach, 1838–1916

A more formal way to refer to the kind of relation defined in Section 1.3 is to call it a binary relation because it is a subset of a Cartesian product of two sets. At the end of this section we define an n-ary relation to be a subset of a Cartesian product of n sets, where n is any integer greater than or equal to two. Such a relation is the fundamental structure used in relational databases. However, because we focus on binary relations in this text, when we use the term relation by itself, we will mean binary relation.

Example 8.1.1 The Less-than Relation for Real Numbers

Define a relation L from R to R as follows: For all real numbers x and y, x L y ⇔ x < y.

a. Is 57 L 53? b. Is (−17) L (−14)? c. Is 143 L 143? d. Is (−35) L 1? e. Draw the graph of L as a subset of the Cartesian plane R× R

Solution

a. No, 57 > 53 b. Yes, −17 < −14 c. No, 143 = 143 d. Yes, −35 < 1 e. For each value of x , all the points (x, y) with y > x are on the graph. So the graph

consists of all the points above the line x = y.

y

x

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.1 Relations on Sets 443

Example 8.1.2 The Congruence Modulo 2 Relation

Define a relation E from Z to Z as follows: For all (m, n) ∈ Z × Z, m E n ⇔ m − n is even.

a. Is 4 E 0? Is 2 E 6? Is 3 E (−3)? Is 5 E 2? b. List five integers that are related by E to 1.

c. Prove that if n is any odd integer, then n E 1.

Solution

a. Yes, 4 E 0 because 4− 0 = 4 and 4 is even. Yes, 2 E 6 because 2− 6 = −4 and −4 is even. Yes, 3 E (−3) because 3− (−3) = 6 and 6 is even. No, 5 E/ 2 because 5− 2 = 3 and 3 is not even.

b. There are many such lists. One is

1 because 1− 1 = 0 is even, 3 because 3− 1 = 2 is even, 5 because 5− 1 = 4 is even, −1 because −1− 1 = −2 is even, −3 because −3− 1 = −4 is even.

c. Proof: Suppose n is any odd integer. Then n = 2k + 1 for some integer k. Now by definition of E, n E 1 if, and only if, n − 1 is even. But by substitution,

n − 1 = (2k + 1)− 1 = 2k, and since k is an integer, 2k is even. Hence n E 1 [as was to be shown].

It can be shown (see exercise 2 at the end of this section) that integers m and n are related by E if, and only if, m mod 2 = n mod 2 (that is, both are even or both are odd). When this occurs m and n are said to be congruent modulo 2. ■

Example 8.1.3 A Relation on a Power Set

Let X = {a, b, c}. Then P(X) = {∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}. Define a relation S from P(X) to Z as follows: For all sets A and B in P(X) (i.e., for all subsets A and B of X ),

A S B ⇔ A has at least as many elements as B. a. Is {a, b} S {b, c}? b. Is {a} S ∅? c. Is {b, c} S {a, b, c}? d. Is {c} S {a}?

Solution

a. Yes, both sets have two elements.

b. Yes, {a} has one element and ∅ has zero elements, and 1 ≥ 0. c. No, {b, c} has two elements and {a, b, c} has three elements and 2 < 3. d. Yes, both sets have one element. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

444 Chapter 8 Relations

The Inverse of a Relation If R is a relation from A to B, then a relation R−1 from B to A can be defined by interchanging the elements of all the ordered pairs of R.

• Definition Let R be a relation from A to B. Define the inverse relation R−1 from B to A as follows:

R−1 = {(y, x) ∈ B × A | (x, y) ∈ R}.

This definition can be written operationally as follows:

For all x ∈ A and y ∈ B, (y, x) ∈ R−1 ⇔ (x, y) ∈ R.

Example 8.1.4 The Inverse of a Finite Relation

Let A = {2, 3, 4} and B = {2, 6, 8} and let R be the “divides” relation from A to B: For all (x, y) ∈ A × B,

x R y ⇔ x | y x divides y.

a. State explicitly which ordered pairs are in R and R−1, and draw arrow diagrams for R and R−1.

b. Describe R−1 in words.

Solution

a. R = {(2, 2), (2, 6), (2, 8), (3, 6), (4, 8)} R−1 = {(2, 2), (6, 2), (8, 2), (6, 3), (8, 4)}

BR

2

6

8

A

2

3

4

To draw the arrow diagram for R−1, you can copy the arrow diagram for R but reverse the directions of the arrows.

BR–1

2

6

8

A

2

3

4

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.1 Relations on Sets 445

Or you can redraw the diagram so that B is on the left.

AR–1

2

3

4

B

2

6

8

b. R−1 can be described in words as follows: For all (y, x) ∈ B × A, y R−1 x ⇔ y is a multiple of x . ■

Example 8.1.5 The Inverse of an Infinite Relation

Define a relation R from R to R as follows: For all (x, y) ∈ R× R, x R y ⇔ y = 2|x |.

Draw the graphs of R and R−1 in the Cartesian plane. Is R−1 a function?

Solution A point (v, u) is on the graph of R−1 if, and only if, (u, v) is on the graph of R. Note that if x ≥ 0, then the graph of y = 2|x | = 2x is a straight line with slope 2. And if x < 0, then the graph of y = 2|x | = 2(−x) = −2x is a straight line with slope−2. Some sample values are tabulated and the graphs are shown below.

R = {(x, y) | y = 2|x |}

x y

0 0 1 2 −1 2

2 4 −2 4 → →

1st coordinate 2nd coordinate

R−1 = {(y, x) | y = 2|x |}

y x

0 0 2 1 2 −1 4 2 4 −2 → →

1st coordinate 2nd coordinate

Graph of R

u

v

(u, v)

Graph of R–1

u

v

(v, u)

R−1 is not a function because, for instance, both (2, 1) and (2,−1) are in R−1. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

446 Chapter 8 Relations

Directed Graph of a Relation In the remaining sections of this chapter, we discuss important properties of relations that are defined from a set to itself.

Note It is important to distinguish clearly between a relation and the set on which it is defined.

• Definition A relation on a set A is a relation from A to A.

When a relation R is defined on a set A, the arrow diagram of the relation can be modified so that it becomes a directed graph. Instead of representing A as two separate sets of points, represent A only once, and draw an arrow from each point of A to each related point. As with an ordinary arrow diagram,

For all points x and y in A,

there is an arrow from x to y ⇔ x R y ⇔ (x, y) ∈ R.

If a point is related to itself, a loop is drawn that extends out from the point and goes back to it.

Example 8.1.6 Directed Graph of a Relation

Let A = {3, 4, 5, 6, 7, 8} and define a relation R on A as follows: For all x, y ∈ A, x R y ⇔ 2 | (x − y).

Draw the directed graph of R.

Solution Note that 3 R 3 because 3− 3 = 0 and 2 | 0 since 0 = 2 · 0. Thus there is a loop from 3 to itself. Similarly, there is a loop from 4 to itself, from 5 to itself, and so forth, since the difference of each integer with itself is 0, and 2 | 0.

Note also that 3 R 5 because 3− 5 = −2 = 2 · (−1). And 5 R 3 because 5− 3 = 2 = 2 · 1. Hence there is an arrow from 3 to 5 and also an arrow from 5 to 3. The other arrows in the directed graph, as shown below, are obtained by similar reasoning.

5

4

6

7

8 3

N-ary Relations and Relational Databases N -ary relations form the mathematical foundation for relational database theory. A binary relation is a subset of a Cartesian product of two sets, similarly, an n-ary relation is a subset of a Cartesian product of n sets.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.1 Relations on Sets 447

• Definition Given sets A1, A2, . . . , An , an n-ary relation R on A1 × A2 × · · ·× An is a subset of A1 × A2 × · · ·× An . The special cases of 2-ary, 3-ary, and 4-ary relations are called binary, ternary, and quaternary relations, respectively.

Example 8.1.7 A Simple Database

The following is a radically simplified version of a database that might be used in a hospital. Let A1 be a set of positive integers, A2 a set of alphabetic character strings, A3 a set of numeric character strings, and A4 a set of alphabetic character strings. Define a quaternary relation R on A1 × A2 × A3 × A4 as follows:

(a1, a2, a3, a4) ∈ R ⇔ a patient with patient ID number a1, named a2, was admitted on date a3, with primary diagnosis a4.

At a particular hospital, this relation might contain the following 4-tuples:

(011985, John Schmidt, 020710, asthma)

(574329, Tak Kurosawa, 0114910, pneumonia)

(466581, Mary Lazars, 0103910, appendicitis)

(008352, Joan Kaplan, 112409, gastritis)

(011985, John Schmidt, 021710, pneumonia)

(244388, Sarah Wu, 010310, broken leg)

(778400, Jamal Baskers, 122709, appendicitis)

In discussions of relational databases, the tuples are normally thought of as being written in tables. Each row of the table corresponds to one tuple, and the header for each column gives the descriptive attribute for the elements in the column.

Operations within a database allow the data to be manipulated in many different ways. For example, in the database language SQL, if the above database is denoted S, the result of the query

SELECT Patient−ID#, Name FROM S WHERE

Admission−Date = 010310 would be a list of the ID numbers and names of all patients admitted on 01-03-10:

466581 Mary Lazars,

244388 Sarah Wu.

This is obtained by taking the intersection of the set A1 × A2 × {010310}× A4 with the database and then projecting onto the first two coordinates. (See exercise 25 of Section 7.1.) Similarly, SELECT can be used to obtain a list of all admission dates of a given patient. For John Schmidt this list is

02-07-10 and

02-17-10

Individual entries in a database can be added, deleted, or updated, and most databases can sort data entries in various ways. In addition, entire databases can be merged, and the entries common to two databases can be moved to a new database. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

448 Chapter 8 Relations

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. If R is a relation from A to B, x ∈ A, and y ∈ B, the notation x R y means that _____.

2. If R is a relation from A to B, x ∈ A, and y ∈ B, the notation x R y means that _____.

3. If R is a relation from A to B, x ∈ A, and y ∈ B, then (y, x) ∈ R−1 if, and only if, _____.

4. A relation on a set A is a relation from _____ to _____.

5. If R is a relation on a set A, the directed graph of R has an arrow from x to y if, and only if, _____.

Exercise Set 8.1* 1. As in Example 8.1.2, the congruence modulo 2 relation E

is defined from Z to Z as follows: For all integers m and n,

m E n ⇔ m − n is even. a. Is 0 E 0? Is 5 E 2? Is (6, 6) ∈ E? Is (−1, 7) ∈ E? b. Prove that for any even integer n, n E 0.

2.H Prove that for all integers m and n, m − n is even if, and only if, both m and n are even or both m and n are odd.

3. The congruence modulo 3 relation, T , is defined from Z to Z as follows: For all integers m and n,

m T n ⇔ 3 | (m − n). a. Is 10 T 1? Is 1 T 10? Is (2, 2) ∈ T ? Is (8, 1) ∈ T ? b. List five integers n such that n T 0. c. List five integers n such that n T 1. d. List five integers n such that n T 2. e.H Make and prove a conjecture about which integers are

related by T to 0, which integers are related by T to 1, and which integers are related by T to 2.

4. Define a relation P on Z as follows: For all m, n ∈ Z, m P n ⇔ m and n have a common prime factor.

a. Is 15 P 25? b. 22 P 27? c. Is 0 P 5? d. Is 8 P 8?

5. Let X = {a, b, c}. Recall that P(X) is the power set of X . Define a relation R on P(X) as follows: For all A, B ∈P(X),

A R B ⇔ A has the same number of elements as B. a. Is {a, b} R {b, c}? b. Is {a} R {a, b}? c. Is {c} R {b}?

6. Let X = {a, b, c}. Define a relation J on P(X) as follows: For all A, B ∈P(X),

A J B ⇔ A ∩ B ̸= ∅. a. Is {a} J {c}? b. Is {a, b} J {b, c}? c. Is {a, b} J {a, b, c}?

7. Define a relation R on Z as follows: For all integers m and n,

m R n ⇔ 5 | (m2 − n2). a. Is 1 R (−9)? b. Is 2 R 13? c. Is 2 R (−8)? d. Is (−8) R 2?

8. Let A be the set of all strings of a’s and b’s of length 4. Define a relation R on A as follows: For all s, t ∈ A,

s R t ⇔ s has the same first two characters as t .

a. Is abaa R abba? b. Is aabb R bbaa? c. Is aaaa R aaab? d. Is baaa R abaa?

9. Let A be the set of all strings of 0’s, 1’s, and 2’s of length 4. Define a relation R on A as follows: For all s, t ∈ A,

s R t ⇔ the sum of the characters in s equals the sum of the characters in t .

a. Is 0121 R 2200? b. Is 1011 R 2101? c. Is 2212 R 2121? d. Is 1220 R 2111?

10. Let A = {3, 4, 5} and B = {4, 5, 6} and let R be the “less than” relation. That is, for all (x, y) ∈ A × B,

x R y ⇔ x < y. State explicitly which ordered pairs are in R and R−1.

11. Let A = {3, 4, 5} and B = {4, 5, 6} and let S be the “divides” relation. That is, for all (x, y) ∈ A × B,

x S y ⇔ x | y. State explicitly which ordered pairs are in S and S−1.

12. a. Suppose a function F: X → Y is one-to-one but not onto. Is F−1 (the inverse relation for F) a function? Explain your answer.

b. Suppose a function F: X → Y is onto but not one-to- one. Is F−1 (the inverse relation for F) a function? Explain your answer.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.2 Reflexivity, Symmetry, and Transitivity 449

Draw the directed graphs of the relations defined in 13–18.

13. Define a relation R on A = {0, 1, 2, 3} by R = {(0, 0), (1, 2), (2, 2)}.

14. Define a relation S on B = {a, b, c, d} by S = {(a, b), (a, c), (b, c), (d, d)}.

15. Let A = {2, 3, 4, 5, 6, 7, 8} and define a relation R on A as follows: For all x, y ∈ A,

x R y ⇔ x | y.

16.H Let A = {5, 6, 7, 8, 9, 10} and define a relation S on A as follows: For all x, y ∈ A,

x S y ⇔ 2 | (x − y). 17. Let A = {2, 3, 4, 5, 6, 7, 8} and define a relation T on A as

follows: For all x, y ∈ A, x T y ⇔ 3 | (x − y).

18. Let A = {0, 1, 2, 3, 4, 5, 6, 7, 8} and define a relation V on A as follows: For all x, y ∈ A,

x V y ⇔ 5 | (x2 − y2).

Exercises 19–20 refer to unions and intersections of relations. Since relations are subsets of Cartesian products, their unions and intersections can be calculated as for any subsets. Given two relations R and S from A to B,

R ∪ S = {(x, y) ∈ A × B | (x, y) ∈ R or (x, y) ∈ S} R ∩ S = {(x, y) ∈ A × B | (x, y) ∈ R and (x, y) ∈ S}.

19. Let A = {2, 4} and B = {6, 8, 10} and define relations R and S from A to B as follows: For all (x, y) ∈ A × B,

x R y ⇔ x | y and x S y ⇔ y − 4 = x .

State explicitly which ordered pairs are in A × B, R, S, R ∪ S, and R ∩ S.

20. Let A = {−1, 1, 2, 4} and B = {1, 2} and define relations R and S from A to B as follows: For all (x, y) ∈ A × B,

x R y ⇔ |x | = |y| and x S y ⇔ x − y is even.

State explicitly which ordered pairs are in A × B, R, S, R ∪ S, and R ∩ S.

21. Define relations R and S on R as follows:

R = {(x, y) ∈ R× R | x < y} and S = {(x, y) ∈ R× R | x = y}.

That is, R is the “less than” relation and S is the “equals” relation on R. Graph R, S, R ∪ S, and R ∩ S in the Carte- sian plane.

22. Define relations R and S on R as follows:

R = {(x, y) ∈ R× R | x2 + y2 = 4} and S = {(x, y) ∈ R× R | x = y}.

Graph R, S, R ∪ S, and R ∩ S in the Cartesian plane. 23. Define relations R and S on R as follows:

R = {(x, y) ∈ R× R | y = |x |} and S = {(x, y) ∈ R× R | y = 1}.

Graph R, S, R ∪ S, and R ∩ S in the Cartesian plane. 24. In Example 8.1.7 the result of the query SELECT

Patient−ID#, Name FROM S WHERE Primary−Diagnosis = X is the projection onto the first two coordinates of the intersection of the set A1 × A2 × A3 × {X} with the database. a. Find the result of the query SELECT Patient−ID#, Name

FROM S WHERE Primary−Diagnosis = pneumonia. b. Find the result of the query SELECT Patient−ID#, Name

FROM S WHERE Primary−Diagnosis = appendicitis.

Answers for Test Yourself 1. x is related to y by R 2. x is not related to y by R 3. (x, y) ∈ R 4. A; A 5. x is related to y by R

8.2 Reflexivity, Symmetry, and Transitivity Mathematics is the tool specially suited for dealing with abstract concepts of any kind and there is no limit to its power in this field. — P. A. M. Dirac, 1902–1984

Let A = {2, 3, 4, 6, 7, 9} and define a relation R on A as follows: For all x, y ∈ A,

x R y ⇔ 3 | (x − y).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

450 Chapter 8 Relations

Then 2 R 2 because 2− 2 = 0, and 3 | 0. Similarly, 3 R 3, 4 R 4, 6 R 6, 7 R 7, and 9 R 9. Also 6 R 3 because 6− 3 = 3, and 3 | 3. And 3 R 6 because 3− 6 = −(6− 3) = −3, and 3 | (−3). Similarly, 3 R 9, 9 R 3, 6 R 9, 9 R 6, 4 R 7, and 7 R 4. Thus the directed graph for R has the appearance shown below.

3 4

7

2

6 9

Note For reference: x R y ⇔ 3 | (x − y).

This graph has three important properties:

1. Each point of the graph has an arrow looping around from it back to itself.

2. In each case where there is an arrow going from one point to a second, there is an arrow going from the second point back to the first.

3. In each case where there is an arrow going from one point to a second and from the second point to a third, there is an arrow going from the first point to the third. That is, there are no “incomplete directed triangles” in the graph.

Properties (1), (2), and (3) correspond to properties of general relations called reflex- ivity, symmetry, and transitivity.

• Definition Let R be a relation on a set A.

1. R is reflexive if, and only if, for all x ∈ A, x R x . 2. R is symmetric if, and only if, for all x, y ∈ A, if x R y then y R x . 3. R is transitive if, and only if, for all x, y, z ∈ A, if x R y and y R z then x R z.

Because of the equivalence of the expressions x R y and (x, y) ∈ R for all x and y in A, the reflexive, symmetric, and transitive properties can also be written as follows:

! Caution! The definition of symmetric does not say that x is related to y by R; only that if it happens that x is related to y, then y must be related to x .

1. R is reflexive ⇔ for all x in A, (x, x) ∈ R. 2. R is symmetric ⇔ for all x and y in A, if (x, y) ∈ R then (y, x) ∈ R. 3. R is transitive ⇔ for all x, y and z in A, if (x, y) ∈ R and (y, z) ∈ R

then (x, z) ∈ R. !

Caution! The “first,” “second,” and “third” elements in the informal versions need not all be distinct. This is a disadvantage of informality: It may mask nuances that a formal definition makes clear.

In informal terms, properties (1)–(3) say the following:

1. Reflexive: Each element is related to itself.

2. Symmetric: If any one element is related to any other element, then the second ele- ment is related to the first.

3. Transitive: If any one element is related to a second and that second element is related to a third, then the first element is related to the third.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.2 Reflexivity, Symmetry, and Transitivity 451

Note that the definitions of reflexivity, symmetry, and transitivity are universal state- ments. This means that to prove a relation has one of the properties, you use either the method of exhaustion or the method of generalizing from the generic particular.

Now consider what it means for a relation not to have one of the properties defined previously. Recall that the negation of a universal statement is existential. Hence if R is a relation on a set A, then

1. R is not reflexive ⇔ there is an element x in A such that x R x [that is, such that (x, x) /∈ R].

2. R is not symmetric ⇔ there are elements x and y in A such that x R y but y R x [that is, such that (x, y) ∈ R but (y, x) /∈ R].

3. R is not transitive ⇔ there are elements x, y and z in A such that x R y and y R z but x R z [that is, such that (x, y) ∈ R and (y, z) ∈ R but (x, z) /∈ R].

It follows that you can show that a relation does not have one of the properties by finding a counterexample.

Example 8.2.1 Properties of Relations on Finite Sets

Let A = {0, 1, 2, 3} and define relations R, S, and T on A as follows: R = {(0, 0), (0, 1), (0, 3), (1, 0), (1, 1), (2, 2), (3, 0), (3, 3)}, S = {(0, 0), (0, 2), (0, 3), (2, 3)}, T = {(0, 1), (2, 3)}.

a. Is R reflexive? symmetric? transitive?

b. Is S reflexive? symmetric? transitive?

c. Is T reflexive? symmetric? transitive?

Solution

a. The directed graph of R has the appearance shown below.

0

3

1

2

R is reflexive: There is a loop at each point of the directed graph. This means that each element of A is related to itself, so R is reflexive.

R is symmetric: In each case where there is an arrow going from one point of the graph to a second, there is an arrow going from the second point back to the first. This means that whenever one element of A is related by R to a second, then the second is related to the first. Hence R is symmetric.

R is not transitive: There is an arrow going from 1 to 0 and an arrow going from 0 to 3, but there is no arrow going from 1 to 3. This means that there are elements of A—0, 1, and 3—such that 1 R 0 and 0 R 3 but 1 R 3. Hence R is not transitive.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

452 Chapter 8 Relations

b. The directed graph of S has the appearance shown below.

0

3 2

1

S is not reflexive: There is no loop at 1, for example. Thus (1, 1) /∈ S, and so S is not reflexive.

S is not symmetric: There is an arrow from 0 to 2 but not from 2 to 0. Hence (0, 2) ∈ S but (2, 0) /∈ S, and so S is not symmetric. S is transitive: There are three cases for which there is an arrow going from one point of the graph to a second and from the second point to a third: Namely, there are arrows going from 0 to 2 and from 2 to 3; there are arrows going from 0 to 0 and from 0 to 2; and there are arrows going from 0 to 0 and from 0 to 3. In each case there is an arrow going from the first point to the third. (Note again that the “first,” “second,” and “third” points need not be distinct.) This means that whenever (x, y) ∈ S and (y, z) ∈ S, then (x, z) ∈ S, for all x, y, z ∈ {0, 1, 2, 3}, and so S is transitive.

c. The directed graph of T has the appearance shown below.

0 1

3 2

T is not reflexive: There is no loop at 0, for example. Thus (0, 0) /∈ T , so T is not reflexive.

T is not symmetric: There is an arrow from 0 to 1 but not from 1 to 0. Thus (0, 1) ∈ T but (1, 0) /∈ T , and so T is not symmetric.

Note T is transitive by default because it is not not transitive!

T is transitive: The transitivity condition is vacuously true for T . To see this, observe that the transitivity condition says that

For all x, y, z ∈ A, if (x, y) ∈ T and (y, z) ∈ T then (x, z) ∈ T .

The only way for this to be false would be for there to exist elements of A that make the hypothesis true and the conclusion false. That is, there would have to be elements x, y, and z in A such that

(x, y) ∈ T and (y, z) ∈ T and (x, z) /∈ T .

In other words, there would have to be two ordered pairs in T that have the potential to “link up” by having the second element of one pair be the first element of the other pair. But the only elements in T are (0, 1) and (2, 3), and these do not have the potential to link up. Hence the hypothesis is never true. It follows that it is impossible for T not to be transitive, and thus T is transitive. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.2 Reflexivity, Symmetry, and Transitivity 453

When a relation R is defined on a finite set A, it is possible to write computer algo- rithms to check whether R is reflexive, symmetric, and transitive. One way to do this is to represent A as a one-dimensional array, (a[1], a[2], . . . , a[n]) and use a modification of the algorithm of exercise 38 in Section 6.1 to check whether an ordered pair in A × A is in R. Checking whether R is reflexive can be done with a loop that examines each element a[i] of A in turn. If, for some i, (a[i], a[i]) /∈ R, then R is not reflexive. Otherwise, R is reflexive. Checking for symmetry can be done with a nested loop that examines each pair (a[i], a[ j]) of A × A in turn. If, for some i and j, (a[i], a[ j]) ∈ R and (a[ j], a[i]) /∈ R, then R is not symmetric. Otherwise, R is symmetric. Checking whether R is transitive can be done with a triply nested loop that examines each triple (a[i], a[ j], a[k]) of A × A × A in turn. If, for some triple, (a[i], a[ j]) ∈ R, (a[ j], a[k]) ∈ R, and (a[i], a[k]) /∈ R, then R is not transitive. Otherwise, R is transitive. In the exercises for this section, you are asked to formalize these algorithms.

Properties of Relations on Infinite Sets Suppose a relation R is defined on an infinite set A. To prove the relation is reflexive, symmetric, or transitive, first write down what is to be proved. For instance, for symmetry you need to prove that

∀x, y ∈ A, if x R y then y R x . Then use the definitions of A and R to rewrite the statement for the particular case in question. For instance, for the “equality” relation on the set of real numbers, the rewritten statement is

∀x, y ∈ R, if x = y then y = x . Sometimes the truth of the rewritten statement will be immediately obvious (as it is here). At other times you will need to prove it using the method of generalizing from the generic particular. We give examples of both cases in this section. We begin with the relation of equality, one of the simplest and yet most important relations.

Example 8.2.2 Properties of Equality

Define a relation R on R (the set of all real numbers) as follows: For all real numbers x and y.

x R y ⇔ x = y.

a. Is R reflexive? b. Is R symmetric? c, Is R transitive?

Solution

a. R is reflexive: R is reflexive if, and only if, the following statement is true:

For all x ∈ R, x R x . Since x R x just means that x = x , this is the same as saying

For all x ∈ R, x = x . But this statement is certainly true; every real number is equal to itself.

b. R is symmetric: R is symmetric if, and only if, the following statement is true:

For all x, y ∈ R, if x R y then y R x .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

454 Chapter 8 Relations

By definition of R, x R y means that x = y and y R x means that y = x . Hence R is symmetric if, and only if,

For all x, y ∈ R, if x = y then y = x . But this statement is certainly true; if one number is equal to a second, then the second is equal to the first.

c. R is transitive: R is transitive if, and only if, the following statement is true:

For all x, y, z ∈ R, if x R y and y R z then x R z. By definition of R, x R y means that x = y, y R z means that y = z, and x R z means that x = z. Hence R is transitive if, and only if, the following statement is true:

For all x, y, z ∈ R, if x = y and y = z then x = z. But this statement is certainly true: If one real number equals a second and the second equals a third, then the first equals the third. ■

Example 8.2.3 Properties of “Less Than”

Define a relation R on R (the set of all real numbers) as follows: For all x, y ∈ R,

x R y ⇔ x < y.

a. Is R reflexive? b. Is R symmetric? c. Is R transitive?

Solution

a. R is not reflexive: R is reflexive if, and only if, ∀x ∈ R, x R x . By definition of R, this means that ∀x ∈ R, x < x . But this is false: ∃x ∈ R such that x ≮ x . As a counterexample, let x = 0 and note that 0 ≮ 0. Hence R is not reflexive.

b. R is not symmetric: R is symmetric if, and only if, ∀x, y ∈ R, if x R y then y R x . By definition of R, this means that ∀x, y ∈ R, if x < y then y < x . But this is false: ∃x, y ∈ R such that x < y and y ≮ x . As a counterexample, let x = 0 and y = 1 and note that 0 < 1 but 1 ≮ 0. Hence R is not symmetric.

c. R is transitive: R is transitive if, and only if, for all x, y, z ∈ R, if x R y and y R z then x R z. By definition of R, this means that for all x, y, z ∈ R, if x < y and y < z, then x < z. But this statement is true by the transitive law of order for real numbers (Appendix A, T18). Hence R is transitive. ■

Sometimes a property is “universally false” in the sense that it is false for every ele- ment of its domain. It follows immediately, of course, that the property is false for each particular element of the domain and hence counterexamples abound. In such a case, it may seem more natural to prove the universal falseness of the property rather than to give a single counterexample. In the example above, for instance, you might find it natural to answer (a) and (b) as follows:

Alternative Answer to (a): R is not reflexive because x ≮ x for all real numbers x (by the trichotomy law—Appendix A, T17).

Alternative Answer to (b): R is not symmetric because for all x and y in A, if x < y, then y ≮ x (by the trichotomy law).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.2 Reflexivity, Symmetry, and Transitivity 455

Example 8.2.4 Properties of Congruence Modulo 3

Define a relation T on Z (the set of all integers) as follows: For all integers m and n,

m T n ⇔ 3 | (m − n).

This relation is called congruence modulo 3.

a. Is T reflexive? b. Is T symmetric? c. Is T transitive?

Solution

a. T is reflexive: To show that T is reflexive, it is necessary to show that

For all m ∈ Z, m T m. By definition of T , this means that

For all m ∈ Z, 3 | (m − m). Or, since m − m = 0, For all m ∈ Z, 3 | 0. But this is true: 3 | 0 since 0 = 3 · 0. Hence T is reflexive. This reasoning is formalized in the following proof.

Proof of Reflexivity: Suppose m is a particular but arbitrarily chosen integer. [We must show that m T m.] Now m − m = 0. But 3 | 0 since 0 = 3 · 0. Hence 3 | (m − m). Thus, by definition of T, m T m [as was to be shown].

b. T is symmetric: To show that T is symmetric, it is necessary to show that

For all m, n ∈ Z, if m T n then n T m. By definition of T this means that

For all m, n ∈ Z, if 3 | (m − n) then 3 | (n − m). Is this true? Suppose m and n are particular but arbitrarily chosen integers such that 3 | (m − n). Must it follow that 3 | (n − m)? [In other words, can we find an integer so that n − m = 3 · (that integer)?] By definition of “divides,” since

3 | (m − n), then m − n = 3k for some integer k. The crucial observation is that n − m = −(m − n). Hence, you can multiply both sides of this equation by −1 to obtain

−(m − n) = −3k, which is equivalent to n − m = 3(−k). [Thus we have found an integer, namely −k, so that n − m = 3 · (that integer).] Since −k is an integer, this equation shows that

3 | (n − m). It follows that T is symmetric.

The reasoning above is formalized in the following proof.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

456 Chapter 8 Relations

Proof of Symmetry: Suppose m and n are particular but arbitrarily chosen inte- gers that satisfy the condition m T n. [We must show that n T m.] By definition of T , since m T n then 3 | (m − n). By definition of “divides,” this means that m − n = 3k, for some integer k. Multiplying both sides by −1 gives n − m = 3(−k). Since −k is an integer, this equation shows that 3 | (n − m). Hence, by definition of T, n T m [as was to be shown].

c. T is transitive: To show that T is transitive, it is necessary to show that

For all m, n, p ∈ Z, if m T n and n T p then m T p. By definition of T this means that

For all m, n ∈ Z, if 3 | (m − n) and 3 | (n − p) then 3 | (m − p). Is this true? Suppose m, n, and p are particular but arbitrarily chosen integers such that 3 | (m − n) and 3 | (n − p). Must it follow that 3 | (m − p)? [In other words, can we find an integer so that m − p = 3 · (that integer)?] By definition of “divides,” since

3 | (m − n) and 3 | (n − p), then m − n = 3r for some integer r, and n − p = 3s for some integer s. The crucial observation is that (m − n) + (n − p) = m − p. Add these two equations together to obtain

(m − n) + (n − p) = 3r + 3s, which is equivalent to m − p = 3(r + s). [Thus we have found an integer so that m − p = 3 · (that integer).] Since r and s are integers, r + s is an integer. So this equation shows that

3 | (m − p). It follows that T is transitive.

The reasoning above is formalized in the following proof.

Proof of Transitivity: Suppose m, n, and p are particular but arbitrarily chosen integers that satisfy the condition m T n and n T p. [We must show that m T p.] By definition of T , since m T n and n T p, then 3 | (m − n) and 3 | (n − p). By definition of “divides,” this means that m − n = 3r and n − p = 3s, for some inte- gers r and s. Adding the two equations gives (m − n) + (n − p) = 3r + 3s, and simplifying gives that m − p = 3(r + s). Since r + s is an integer, this equation shows that 3 | (m − p). Hence, by definition of T , m T p [as was to be shown].

The Transitive Closure of a Relation Generally speaking, a relation fails to be transitive because it fails to contain certain ordered pairs. For example, if (1, 3) and (3, 4) are in a relation R, then the pair (1, 4) must be in R if R is to be transitive. To obtain a transitive relation from one that is not transitive, it is necessary to add ordered pairs. Roughly speaking, the relation obtained by adding the least number of ordered pairs to ensure transitivity is called the transitive

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.2 Reflexivity, Symmetry, and Transitivity 457

closure of the relation. In a sense made precise by the formal definition, the transitive closure of a relation is the smallest transitive relation that contains the relation.

• Definition Let A be a set and R a relation on A. The transitive closure of R is the relation Rt

on A that satisfies the following three properties:

1. Rt is transitive.

2. R ⊆ Rt . 3. If S is any other transitive relation that contains R, then Rt ⊆ S.

Example 8.2.5 Transitive Closure of a Relation

Let A = {0, 1, 2, 3} and consider the relation R defined on A as follows: R = {(0, 1), (1, 2), (2, 3)}.

Find the transitive closure of R.

Solution Every ordered pair in R is in Rt , so

{(0, 1), (1, 2), (2, 3)} ⊆ Rt . Thus the directed graph of R contains the arrows shown below.

0 1

3 2

Since there are arrows going from 0 to 1 and from 1 to 2, Rt must have an arrow going from 0 to 2. Hence (0, 2) ∈ Rt . Then (0, 2) ∈ Rt and (2, 3) ∈ Rt , so since Rt is transitive, (0, 3) ∈ Rt . Also, since (1, 2) ∈ Rt and (2, 3) ∈ Rt , then (1, 3) ∈ Rt . Thus Rt contains at least the following ordered pairs:

{(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)}. But this relation is transitive; hence it equals Rt . Note that the directed graph of Rt is as shown below.

0 1

3 2 ■

Test Yourself 1. For a relation R on a set A to be reflexive means that _____.

2. For a relation R on a set A to be symmetric means that _____.

3. For a relation R on a set A to be transitive means that _____.

4. To show that a relation R on an infinite set A is reflexive, you suppose that _____ and you show that _____.

5. To show that a relation R on an infinite set A is symmetric, you suppose that _____ and you show that _____.

6. To show that a relation R on an infinite set A is transitive, you suppose that _____ and you show that _____.

7. To show that a relation R on a set A is not reflexive, you _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

458 Chapter 8 Relations

8. To show that a relation R on a set A is not symmetric, you _____.

9. To show that a relation R on a set A is not transitive, you _____.

10. Given a relation R on a set A, the transitive closure of R is the relation Rt on A that satisfies the following three prop- erties: _____, _____, and _____.

Exercise Set 8.2 In 1–8 a number of relations are defined on the set A = {0, 1, 2, 3}. For each relation: a. Draw the directed graph. b. Determine whether the relation is reflexive. c. Determine whether the relation is symmetric. d. Determine whether the relation is transitive. Give a counterexample in each case in which the relation does not satisfy one of the properties.

1. R1 = {(0, 0), (0, 1), (0, 3), (1, 1), (1, 0), (2, 3), (3, 3)} 2. R2 = {(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3)} 3. R3 = {(2, 3), (3, 2)} 4. R4 = {(1, 2), (2, 1), (1, 3), (3, 1)} 5. R5 = {(0, 0), (0, 1), (0, 2), (1, 2)} 6. R6 = {(0, 1), (0, 2)} 7. R7 = {(0, 3), (2, 3)} 8. R8 = {(0, 0), (1, 1)}

In 9–33 determine whether the given relation is reflexive, sym- metric, transitive, or none of these. Justify your answers.

9. R is the “greater than or equal to” relation on the set of real numbers: For all x, y ∈ R, x R y ⇔ x ≥ y.

10. C is the circle relation on the set of real numbers: For all x, y ∈ R, x C y ⇔ x2 + y2 = 1.

11. D is the relation defined on R as follows: For all x, y ∈ R, x D y ⇔ xy ≥ 0.

12. E is the congruence modulo 2 relation on Z: For all m, n ∈ Z, m E n ⇔ 2 | (m − n).

13. F is the congruence modulo 5 relation on Z: For all m, n ∈ Z, m F n ⇔ 5 | (m − n).

14. O is the relation defined on Z as follows: For all m, n ∈ Z, m O n ⇔ m − n is odd.

15. D is the “divides” relation on Z+: For all positive integers m and n, m D n ⇔ m | n.

16. A is the “absolute value” relation on R: For all real num- bers x and y, x A y ⇔ |x | = |y|.

17. Recall that a prime number is an integer that is greater than 1 and has no positive integer divisors other than 1 and itself. (In particular, 1 is not prime.) A relation P is

defined on Z as follows: For all m, n ∈ Z, m P n ⇔ ∃ a prime number p such that p | m and p | n.

18.H Define a relation Q on R as follows: For all real numbers x and y, x Q y ⇔ x − y is rational.

19. Define a relation I on R as follows: For all real numbers x and y, x I y ⇔ x − y is irrational.

20. Let X = {a, b, c} and P(X) be the power set of X (the set of all subsets of X ). A relation E is defined on P(X) as follows: For all A, B ∈P(X), A E B ⇔ the number of elements in A equals the number of elements in B.

21. Let X = {a, b, c} and P(X) be the power set of X . A relation L is defined on P(X) as follows: For all A, B ∈P(X), A L B ⇔ the number of elements in A is less than the number of elements in B.

22. Let X = {a, b, c} and P(X) be the power set of X . A relation N is defined on P(X) as follows: For all A, B ∈P(X), A N B ⇔ the number of elements in A is not equal to the number of elements in B.

23. Let X be a nonempty set and P(X) the power set of X . Define the “subset” relation S on P(X) as follows: For all A, B ∈P(X), A S B ⇔ A ⊆ B.

24. Let X be a nonempty set and P(X) the power set of X . Define the “not equal to” relation U on P(X) as follows: For all A, B ∈P(X), A U B ⇔ A ̸= B.

25. Let A be the set of all strings of a’s and b’s of length 4. Define a relation R on A as follows: For all s, t ∈ A, s R t⇔ s has the same first two characters as t .

26. Let A be the set of all strings of 0’s, 1’s and 2’s of length 4. Define a relation R on A as follows: For all s, t ∈ A, s R t⇔ the sum of the characters in s equals the sum of the characters in t .

27. Let A be the set of all English statements. A relation I is defined on A as follows: For all p, q ∈ A,

p I q ⇔ p → q is true. 28. Let A = R× R. A relation F is defined on A as follows:

For all (x1, y1) and (x2, y2) in A,

(x1, y1) F (x2, y2)⇔ x1 = x2. 29. Let A = R× R. A relation S is defined on A as follows:

For all (x1, y1) and (x2, y2) in A,

(x1, y1) S (x2, y2)⇔ y1 = y2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 459

30. Let A be the “punctured plane”; that is, A is the set of all points in the Cartesian plane except the origin (0, 0). A relation R is defined on A as follows: For all p1 and p2 in A, p1 R p2 ⇔ p1 and p2 lie on the same half line emanating from the origin.

31. Let A be the set of people living in the world today. A relation R is defined on A as follows: For all p, q ∈ A,

p R q ⇔ p lives within 100 miles of q. 32. Let A be the set of all lines in the plane. A relation R is

defined on A as follows: For all l1 and l2 in A, l1 R l2 ⇔ l1 is parallel to l2. (Assume that a line is parallel to itself.)

33. Let A be the set of all lines in the plane. A relation R is defined on A as follows: For all l1 and l2 in A,

l1 R l2 ⇔ l1 is perpendicular to l2.

In 34–36, assume that R is a relation on a set A. Prove or dis- prove each statement.

34. If R is reflexive, then R−1 is reflexive.

35. If R is symmetric, then R−1 is symmetric.

36. If R is transitive, then R−1 is transitive.

In 37–42, assume that R and S are relations on a set A. Prove or disprove each statement.

37. If R and S are reflexive, is R ∩ S reflexive? Why? 38.H If R and S are symmetric, is R ∩ S symmetric? Why? 39. If R and S are transitive, is R ∩ S transitive? Why? 40. If R and S are reflexive, is R ∪ S reflexive? Why? 41. If R and S are symmetric, is R ∪ S symmetric? Why? 42. If R and S are transitive, is R ∪ S transitive? Why?

In 43–50 the following definitions are used: A relation on a set A is defined to be

irreflexive if, and only if, for all x ∈ A, x R x; asymmetric if, and only if, for all x, y ∈ A, if x R y then y R x; intransitive if, and only if, for all x, y, z ∈ A, if x R y and y R z then x R z.

For each of the relations in the referenced exercise, determine whether the relation is irreflexive, asymmetric, intransitive, or none of these.

43. Exercise 1 44. Exercise 2

45. Exercise 3 46. Exercise 4

47. Exercise 5 48. Exercise 6

49. Exercise 7 50. Exercise 8

In 51–53. R. S. and T are relations defined on A = {0, 1, 2, 3}.

51. Let R = {(0, 1), (0, 2), (1, 1), (1, 3), (2, 2), (3, 0)}. Find R′, the transitive closure of R.

52. Let S = {(0, 0), (0, 3), (1, 0), (1, 2), (2, 0), (3, 2)}. Find St , the transitive closure of S.

53. Let T = {(0, 2), (1, 0), (2, 3), (3, 1)}. Find T t , the transi- tive closure of T .

54. Write a computer algorithm to test whether a relation R defined on a finite set A is reflexive, where A = {a[1], a[2], . . . , a[n]}.

55. Write a computer algorithm to test whether a relation R defined on a finite set A is symmetric, where A = {a[1], a[2], . . . , a[n]}.

56. Write a computer algorithm to test whether a relation R defined on a finite set A is transitive, where A = {a[1], a[2], . . . , a[n]}.

Answers for Test Yourself 1. for all x in A, x R x 2. for all x and y in A, if x R y then y R x 3. for all x, y, and z in A, if x R y and y R z then x R z 4. x is any element of A; x R x 5. x and y are any elements of A such that x R y; y R x 6. x, y, and z are any elements of A such that x R y and y R z; x R z 7. show that there is an element x in A such that x R x 8. show that there are elements x and y in A such that x R y but y R x 9. show that there are elements x, y, and z in A such that x R y and y R z but x R z 10. Rt is transitive; R ⊆ Rt ; if S is any other transitive relation that contains R, then Rt ⊆ S

8.3 Equivalence Relations “You are sad” the Knight said in an anxious tone: “let me sing you a song to

comfort you.” “Is it very long?” Alice asked, for she had heard a good deal of poetry that day. “It’s long,” said the Knight, “but it’s very, very beautiful. Everybody that hears me

sing it—either it brings the tears into the eyes, or else—” “Or else what?” said Alice, for the Knight had made a sudden pause. “Or else it doesn’t, you know. The name of the song is called ‘Haddocks’ Eyes.’ ”

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

460 Chapter 8 Relations

“Oh, that’s the name of the song, is it?” Alice said, trying to feel interested. “No, you don’t understand,” the Knight said, looking a little vexed. “That’s what

the name is called. The name really is ‘The Aged Aged Man.’ ” “Then I ought to have said ‘That’s what the song is called’?” Alice corrected

herself. “No, you oughtn’t: that’s quite another thing! The song is called ‘Ways and

Means’: but that’s only what it’s called, you know!” “Well, what is the song, then?” said Alice, who was by this time completely

bewildered. “I was coming to that,” the Knight said. “The song really is ‘A-sitting on a Gate’:

and the tune’s my own invention.” So saying, he stopped his horse and let the reins fall on its neck: then, slowly beating time with one hand, and with a faint smile lighting up his gentle foolish face, as if he enjoyed the music of his song, he began. — Lewis Carroll, Through the Looking Glass, 1872

You know from your early study of fractions that each fraction has many equivalent forms. For example,

1 2 ,

2 4 ,

3 6 , −1 −2 ,

−3 −6 ,

15 30

, . . . , and so on

are all different ways to represent the same number. They may look different; they may be called different names; but they are all equal. The idea of grouping together things that “look different but are really the same” is the central idea of equivalence relations.

The Relation Induced by a Partition A partition of a set A is a finite or infinite collection of nonempty, mutually disjoint subsets whose union is A. The diagram of Figure 8.3.1 illustrates a partition of a set A by subsets A1, A2, . . . , A6.

A2

A4 A5

A6

A3

A1 Ai Aj = ∅, whenever i ≠ j Ai A2 A6 = A

Figure 8.3.1 A Partition of a Set

• Definition Given a partition of a set A, the relation induced by the partition, R, is defined on A as follows: For all x, y ∈ A,

x R y ⇔ there is a subset Ai of the partition such that both x and y are in Ai .

Example 8.3.1 Relation Induced by a Partition

Let A = {0, 1, 2, 3, 4} and consider the following partition of A: {0, 3, 4}, {1}, {2}.

Find the relation R induced by this partition.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 461

Solution Since {0, 3, 4} is a subset of the partition, 0 R 3 because both 0 and 3 are in {0, 3, 4}, 3 R 0 because both 3 and 0 are in {0, 3, 4}, 0 R 4 because both 0 and 4 are in {0, 3, 4}, 4 R 0 because both 4 and 0 are in {0, 3, 4}, 3 R 4 because both 3 and 4 are in {0, 3, 4}, and 4 R 3 because both 4 and 3 are in {0, 3, 4}.

Also, 0 R 0 because both 0 and 0 are in {0, 3, 4} 3 R 3 because both 3 and 3 are in {0, 3, 4}, and 4 R 4 because both 4 and 4 are in {0, 3, 4}.

Since {1} is a subset of the partition,

1 R 1 because both 1 and 1 are in {1}, and since {2} is a subset of the partition,

2 R 2 because both 2 and 2 are in {2}.

Note These statements may seem strange, but, after all, they are not false!

Hence

R = {(0, 0), (0, 3), (0, 4), (1, 1), (2, 2), (3, 0), (3, 3), (3, 4), (4, 0), (4, 3), (4, 4)}. ■

The fact is that a relation induced by a partition of a set satisfies all three properties studied in Section 8.2: reflexivity, symmetry, and transitivity.

Theorem 8.3.1

Let A be a set with a partition and let R be the relation induced by the partition. Then R is reflexive, symmetric, and transitive.

Proof:

Suppose A is a set with a partition. In order to simplify notation, we assume that the partition consists of only a finite number of sets. The proof for an infinite partition is identical except for notation. Denote the partition subsets by

A1, A2, . . . , An .

Then Ai ∩ A j = ∅ whenever i ̸= j, and A1 ∪ A2 ∪ · · · ∪ An = A. The relation R induced by the partition is defined as follows: For all x, y ∈ A,

x R y ⇔ there is a set Ai of the partition such that x ∈ Ai and y ∈ Ai .

[Idea for the proof of reflexivity: For R to be reflexive means that each element of A is related by R to itself. But by definition of R, for an element x to be related to itself means that x is in the same subset of the partition as itself. Well, if x is in some subset of the partition, then it is certainly in the same subset as itself. But x is in some subset of the

continued on page 462

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

462 Chapter 8 Relations

partition because the union of the subsets of the partition is all of A. This reasoning is formalized as follows.]

Proof that R is reflexive: Suppose x ∈ A. Since A1, A2, . . . , An is a partition of A, it follows that x ∈ Ai for some i . But then the statement

there is a set Ai of the partition such that x ∈ Ai and x ∈ Ai is true. Thus, by definition of R, x R x .

[Idea for the proof of symmetry: For R to be symmetric means that any time one element is related to a second, then the second is related to the first. Now for one element x to be related to a second element y means that x and y are in the same subset of the partition. But if this is the case, then y is in the same subset of the partition as x, so y is related to x by definition of R. This reasoning is formalized as follows.]

Proof that R is symmetric: Suppose x and y are elements of A such that x R y. Then

there is a subset Ai of the partition such that x ∈ Ai and y ∈ Ai by definition of R. It follows that the statement

there is a subset Ai of the partition such that y ∈ Ai and x ∈ Ai is also true. Hence, by definition of R, y R x .

[Idea for the proof of transitivity: For R to be transitive means that any time one element of A is related by R to a second and that second is related to a third, then the first element is related to the third. But for one element to be related to another means that there is a subset of the partition that contains both. So suppose x, y, and z are elements such that x is in the same subset as y and y is in the same subset as z. Must x be in the same subset as z? Yes, because the subsets of the partition are mutually disjoint. Since the subset that contains x and y has an element in common with the subset that contains y and z (namely y), the two subsets are equal. But this means that x, y, and z are all in the same subset, and so in particular, x and z are in the same subset. Hence x is related by R to z. This reasoning is formalized as follows.]

Proof that R is transitive: Suppose x, y, and z are in A and x R y and y R z. By definition of R, there are subsets Ai and A j of the partition such that

x and y are in Ai and y and z are in A j .

Suppose Ai ̸= A j . [We will deduce a contradiction.] Then Ai ∩ A j = ∅ since {A1, A2, A3, . . . , An} is a partition of A. But y is in Ai and y is in A j also. Hence Ai ∩ A j ̸= ∅. [This contradicts the fact that Ai ∩ A j = ∅.] Thus Ai = A j . It follows that x, y, and z are all in Ai , and so in particular,

x and z are in Ai .

Thus, by definition of R, x R z.

Note The fact that x ∈ Ai and x ∈ Ai follows from the logical equivalence of the statement forms p and p ∧ p.

Note The fact that y ∈ Ai and x ∈ Ai follows from the logical equivalence of the statement forms p ∧ q and q ∧ p.

Definition of an Equivalence Relation A relation on a set that satisfies the three properties of reflexivity, symmetry, and transi- tivity is called an equivalence relation.

• Definition Let A be a set and R a relation on A. R is an equivalence relation if, and only if, R is reflexive, symmetric, and transitive.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 463

Thus, according to Theorem 8.3.1, the relation induced by a partition is an equiva- lence relation. A variety of additional examples of equivalence relations are given below and in the exercises.

Example 8.3.2 An Equivalence Relation on a Set of Subsets

Let X be the set of all nonempty subsets of {1, 2, 3}. Then

X = {{1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}

Define a relation R on X as follows: For all A and B in X ,

A R B ⇔ the least element of A equals the least element of B.

Prove that R is an equivalence relation on X .

Solution

R is reflexive: Suppose A is a nonempty subset of {1, 2, 3}. [We must show that A R A.] It is true to say that the least element of A equals the least element of A. Thus, by definition of R, A R A.

R is symmetric: Suppose A and B are nonempty subsets of {1, 2, 3} and A R B. [We must show that B R A.] Since A R B, the least element of A equals the least element of B. But this implies that the least element of B equals the least element of A, and so, by definition of R, B R A.

R is transitive: Suppose A, B, and C are nonempty subsets of {1, 2, 3}, A R B, and B R C. [We must show that A R C.] Since A R B, the least element of A equals the least element of B and since B R C, the least element of B equals the least element of C. Thus the least element of A equals the least element of C, and so, by definition of R, A R C. ■

Example 8.3.3 Equivalence of Digital Logic Circuits Is an Equivalence Relation

Let S be the set of all digital logic circuits with a fixed number n of inputs. Define a relation E on S as follows: For all circuits C1 and C2 in S,

C1 E C2 ⇔ C1 has the same input/output table as C2.

If C1 E C2, then circuit C1 is said to be equivalent to circuit C2. Prove that E is an equivalence relation on S.

Solution

E is reflexive: Suppose C is a digital logic circuit in S. [We must show that C E C.] Certainly C has the same input/output table as itself. Thus, by definition of E, C E C [as was to be shown].

E is symmetric: Suppose C1 and C2 are digital logic circuits in S such that C1 E C2. [We must show that C2 E C1.] By definition of E, since C1 E C2, then C1 has the same input/output table as C2. It follows that C2 has the same input/output table as C1. Hence, by definition of E, C2 E C1 [as was to be shown].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

464 Chapter 8 Relations

E is transitive: Suppose C1, C2, and C3 are digital logic circuits in S such that C1 E C2 and C2 E C3. [We must show that C1 E C3.] By definition of E, since C1 E C2 and C2 E C3, then

C1 has the same input/output table as C2

and C2 has the same input/output table as C3.

It follows that C1 has the same input/output table as C3.

Hence, by definition of E, C1 E C3 [as was to be shown].

Since E is reflexive, symmetric, and transitive, E is an equivalence relation on S. ■

Certain implementations of computer languages do not place a limit on the allow- able length of an identifier. This permits a programmer to be as precise as necessary in naming variables without having to worry about exceeding length limitations. However, compilers for such languages often ignore all but some specified number of initial char- acters: As far as the compiler is concerned, two identifiers are the same if they have the same initial characters, even though they may look different to a human reader of the program. For example, to a compiler that ignores all but the first eight characters of an identifier, the following identifiers would be the same:

NumberOfScrews NumberOfBolts.

Obviously, in using such a language, the programmer has to be sure to avoid giving two distinct identifiers the same first eight characters. When a compiler lumps identifiers together in this way, it sets up an equivalence relation on the set of all possible identifiers in the language. Such a relation is described in the next example.

Example 8.3.4 A Relation on a Set of Identifiers

Let L be the set of all allowable identifiers in a certain computer language, and define a relation R on L as follows: For all strings s and t in L ,

s R t ⇔ the first eight characters of s equal the first eight characters of t.

Prove that R is an equivalence relation on L .

Solution

R is reflexive: Let s ∈ L . [We must show that s R s.] Clearly s has the same first eight characters as itself. Thus, by definition of R, s R s [as was to be shown].

R is symmetric: Let s and t be in L and suppose that s R t . [We must show that t R s.] By definition of R, since s R t , the first eight characters of s equal the first eight characters of t . But then the first eight characters of t equal the first eight characters of s. And so, by definition of R, t R s [as was to be shown].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 465

R is transitive: Let s, t, and u be in L and suppose that s R t and t R u. [We must show that s R u.] By definition of R, since s R t and t R u, the first eight characters of s equal the first eight characters of t , and the first eight characters of t equal the first eight characters of u. Hence the first eight characters of s equal the first eight characters of u. Thus, by definition of R, s R u [as was to be shown].

Since R is reflexive, symmetric, and transitive, R is an equivalence relation on L . ■

Equivalence Classes of an Equivalence Relation Suppose there is an equivalence relation on a certain set. If a is any particular element of the set, then one can ask, “What is the subset of all elements that are related to a?” This subset is called the equivalence class of a.

Note Be careful to distinguish among the following: a relation on a set, the (underlying) set itself, and the equivalence class for an element of the (underlying) set.

• Definition Suppose A is a set and R is an equivalence relation on A. For each element a in A, the equivalence class of a, denoted [a] and called the class of a for short, is the set of all elements x in A such that x is related to a by R.

In symbols:

[a] = {x ∈ A | x R a}

When several equivalence relations on a set are under discussion, the notation [a]R is often used to denote the equivalence class of a under R.

The procedural version of this definition is

for all x ∈ A, x ∈ [a] ⇔ x R a.

Example 8.3.5 Equivalence Classes of a Relation Given as a set of Ordered Pairs

Let A = {0, 1, 2, 3, 4} and define a relation R on A as follows: R = {(0, 0), (0, 4), (1, 1), (1, 3), (2, 2), (3, 1), (3, 3), (4, 0), (4, 4)}.

The directed graph for R is as shown below. As can be seen by inspection, R is an equiv- alence relation on A. Find the distinct equivalence classes of R.

0

4 1

3

2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

466 Chapter 8 Relations

Solution First find the equivalence class of every element of A.

[0] = {x ∈ A | x R 0} = {0, 4} [1] = {x ∈ A | x R 1} = {1, 3} [2] = {x ∈ A | x R 2} = {2} [3] = {x ∈ A | x R 3} = {1, 3} [4] = {x ∈ A | x R 4} = {0, 4}

Note that [0] = [4] and [1] = [3]. Thus the distinct equivalence classes of the relation are {0, 4}, {1, 3}, and {2}. ■

When a problem asks you to find the distinct equivalence classes of an equivalence relation, you will generally solve the problem in two steps. In the first step you either explicitly construct (as in Example 8.3.5) or imagine constructing (as in infinite cases) the equivalence class for every element of the domain A of the relation. Usually several of the classes will contain exactly the same elements, so in the second step you must take a careful look at the classes to determine which are the same. You then indicate the distinct equivalence classes by describing them without duplication.

Example 8.3.6 Equivalence Classes of a Relation on a Set of Subsets

In Example 8.3.2 it was shown that the relation R was an equivalence relation, where for nonempty subsets A and B of {1, 2, 3} to be related by R means that they have the same least element. Describe the distinct equivalence classes of R.

Solution The equivalence class of {1} is the set of all the nonempty subsets of {1, 2, 3} whose least element is 1. Thus

[{1}] = {{1}, {1, 2}, {1, 3}, {1, 2, 3}}. The equivalence class of {2} is the set of all the nonempty subsets of {1, 2, 3} whose least element is 2. Thus

[{2}] = {{2}, {2, 3}}. The equivalence class of {3} is the set of all the nonempty subsets of {1, 2, 3} whose least element is 3. There is only one such set, namely {3} itself. Thus

[{3}] = {{3}}. Since all the nonempty subsets of {1, 2, 3} are in one of the equivalence classes, this is a complete listing. Moreover, these classes are all distinct. ■

Example 8.3.7 Equivalence Classes of Identifiers

In Example 8.3.4 it was shown that the relation R of having the same first eight characters is an equivalence relation on the set L of allowable identifiers in a computer language. Describe the distinct equivalence classes of R.

Solution By definition of R, two strings in L are related by R if, and only if, they have the same first eight characters. Given any string s in L ,

[s] = {t ∈ L | t R s} = {t ∈ L | the first eight characters of t equal the first eight characters of s}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 467

Thus the distinct equivalence classes of R are sets of strings such that (1) each class consists entirely of strings all of which have the same first eight characters, and (2) any two distinct classes contain strings that differ somewhere in their first eight characters.

Example 8.3.8 Equivalence Classes of the Identity Relation

Let A be any set and define a relation R on A as follows: For all x and y in A,

x R y ⇔ x = y.

Then R is an equivalence relation. [To prove this, just generalize the argument used in Example 8.2.2.] Describe the distinct equivalence classes of R.

Solution Given any a in A, the class of a is

[a] = {x ∈ A | x R a}. But by definition of R, a R x if, and only if, a = x . So

[a] = {x ∈ A | x = a} = {a} since the only element of A that equals a is a.

Hence, given any a in A,

[a] = {a}, and if x ̸= a, then {x} ̸= {a}. Consequently, all the classes of all the elements of A are distinct, and the distinct equivalence classes of R are all the single-element subsets of A. ■

In each of Examples 8.3.5, 8.3.6, 8.3.7 and 8.3.8, the set of distinct equivalence classes of the relation consists of mutually disjoint subsets whose union is the entire domain A of the relation. This means that the set of equivalence classes of the relation forms a partition of the domain A. In fact, it is always the case that the equivalence classes of an equivalence relation partition the domain of the relation into a union of mutually disjoint subsets. We establish the truth of this statement in stages, first proving two lem- mas and then proving the main theorem.

The first lemma says that if two elements of A are related by an equivalence rela- tion R, then their equivalence classes are the same.

Lemma 8.3.2

Suppose A is a set, R is an equivalence relation on A, and a and b are elements of A. If a R b, then [a] = [b].

This lemma says that if a certain condition is satisfied, then [a] = [b]. Now [a] and [b] are sets, and two sets are equal if, and only if, each is a subset of the other. Hence the proof of the lemma consists of two parts: first, a proof that [a] ⊆ [b] and second, a proof that [b] ⊆ [a]. To show each subset relation, it is necessary to show that every element in the left-hand set is an element of the right-hand set.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

468 Chapter 8 Relations

Proof of Lemma 8.3.2:

Let A be a set, let R be an equivalence relation on A, and suppose

a and b are elements of A such that a R b.

[We must show that [a] = [b].] Proof that [a] ⊆ [b]: Let x ∈ [a]. [We must show that x ∈ [b].] Since

x ∈ [a]

then x R a

by definition of class. But a R b

by hypothesis. Thus, by transitivity of R,

x R b.

Hence x ∈ [b] by definition of class. [This is what was to be shown.]

Proof that [b] ⊆ [a]: Let x ∈ [b]. [We must show that x ∈ [a].] Since x ∈ [b]

then x R b

by definition of class. Now a R b

by hypothesis. Thus, since R is symmetric,

b R a

also. Then, since R is transitive and x R b and b R a,

x R a.

Hence, x ∈ [a] by definition of class. [This is what was to be shown.]

Since [a] ⊆ [b] and [b] ⊆ [a], it follows that [a] = [b] by definition of set equality.

The second lemma says that any two equivalence classes of an equivalence relation are either mutually disjoint or identical.

Lemma 8.3.3

If A is a set, R is an equivalence relation on A, and a and b are elements of A, then

either [a] ∩ [b] = ∅ or [a] = [b].

The statement of Lemma 8.3.3 has the form

if p then (q or r),

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 469

where p is the statement “A is a set, R is an equivalence relation on A, and a and b are elements of A,” q is the statement “[a] ∩ [b] = ∅,” and r is the statement “[a] = [b].” To prove the lemma, we will prove the logically equivalent statement

if (p and not q) then r .

That is, we will prove the following:

If A is a set, R is an equivalence relation on A, a and b are elements of A, and [a] ∩ [b] ̸= ∅, then [a] = [b].

Note You can always prove a statement of the form “if p then (q or r )” by proving one of the logically equivalent statements: “if (p and not q) then r” or “if (p and not r ) then q .”∗

Proof of Lemma 8.3.3:

Suppose A is a set, R is an equivalence relation on A, a and b are elements of A, and

[a] ∩ [b] ̸= ∅. [We must show that [a] = [b].] Since [a] ∩ [b] ̸= ∅, there exists an element x in A such that x ∈ [a] ∩ [b]. By definition of intersection,

x ∈ [a] and x ∈ [b]

and so x R a and x R b

by definition of class. Since R is symmetric [being an equivalence relation] and x R a, then a R x . But R is also transitive [since it is an equivalence relation], and so, since a R x and x R b,

a R b.

Now a and b satisfy the hypothesis of Lemma 8.3.2. Hence, by that lemma,

[a] = [b]. [This is what was to be shown.]

Theorem 8.3.4 The Partition Induced by an Equivalence Relation

If A is a set and R is an equivalence relation on A, then the distinct equivalence classes of R form a partition of A; that is, the union of the equivalence classes is all of A, and the intersection of any two distinct classes is empty.

The proof of Theorem 8.3.4 is divided into two parts: first, a proof that A is the union of the equivalence classes of R and second, a proof that the intersection of any two distinct equivalence classes is empty. The proof of the first part follows from the fact that the relation is reflexive. The proof of the second part follows from Lemma 8.3.3.

Proof of Theorem 8.3.4:

Suppose A is a set and R is an equivalence relation on A. For notational simplicity, we assume that R has only a finite number of distinct equivalence classes, which we denote

A1, A2, . . . , An,

continued on page 470

∗ See exercise 14 in Section 2.2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

470 Chapter 8 Relations

where n is a positive integer. (When the number of classes is infinite, the proof is identical except for notation.)

Proof that A = A1 ∪ A2 ∪ · · · ∪ An: [We must show that A ⊆ A1 ∪ A2 ∪ · · · ∪ An and that A1 ∪ A2 ∪ · · · ∪ An ⊆ A.]

To show that A ⊆ A1 ∪ A2 ∪ · · · ∪ An , suppose x is any element of A. [We must show that x ∈ A1 ∪ A2 ∪ · · · ∪ An .] By reflexivity of R, x R x . But this implies that x ∈ [x] by definition of class. Since x is in some equivalence class, it must be in one of the distinct equivalence classes A1, A2, . . . , or An . Thus x ∈ Ai for some index i , and hence x ∈ A1 ∪ A2 ∪ · · · ∪ An by definition of union [as was to be shown].

To show that A1 ∪ A2 ∪ · · · ∪ An ⊆ A, suppose x ∈ A1 ∪ A2 ∪ · · · ∪ An . [We must show that x ∈ A.] Then x ∈ Ai for some i = 1, 2, . . . , n, by definition of union. But each Ai is an equivalence class of R. And equivalence classes are subsets of A. Hence Ai ⊆ A and so x ∈ A [as was to be shown].

Since A ⊆ A1 ∪ A2 ∪ · · · ∪ An and A1 ∪ A2 ∪ · · · ∪ An ⊆ A, then by definition of set equality, A = A1 ∪ A2 ∪ · · · ∪ An . Proof that the distinct classes of R are mutually disjoint: Suppose that Ai and A j are any two distinct equivalence classes of R. [We must show that Ai and A j are disjoint.] Since Ai and A j are distinct, then Ai ̸= A j . And since Ai and A j are equivalence classes of R, there must exist elements a and b in A such that Ai = [a] and A j = [b]. By Lemma 8.3.3,

either [a] ∩ [b] = ∅ or [a] = [b]. But [a] ̸= [b] because Ai ̸= A j . Hence [a] ∩ [b] = ∅. Thus Ai ∩ A j = ∅, and so Ai and A j are disjoint [as was to be shown].

Example 8.3.9 Equivalence Classes of Digital Logic Circuits

In Example 8.3.3 it was shown that the relation of equivalence among circuits is an equiv- alence relation. Let S be the set of all digital logic circuits with exactly two inputs and one output. The binary relation E is defined on S as follows: For all C1 and C2 in S,

C1 E C2 ⇔ C1 has the same input/output table as C2.

Describe the equivalence classes of this relation. How many distinct equivalence classes are there? Find two different circuits that are in one of the classes.

Solution Given a circuit C , the equivalence class of C is the set of all circuits with two input signals and one output signal that have the same input/output table as C . Now each input/output table has exactly four rows, corresponding to the four possible combinations of inputs: 11, 10, 01, and 00. A typical input/output table is the following:

Input Output

P Q R

1 1 0

1 0 0

0 1 0

0 0 1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 471

There are exactly as many such tables as there are binary strings of length 4. The rea- son is that distinct input/output tables can be formed by changing the pattern of the four 0’s and 1’s in the output column, and there are as many ways to do that as there are strings of four 0’s and 1’s. But the number of binary strings of length 4 is 24 = 16. Hence there are 16 distinct input/output tables.

This implies that there are exactly 16 equivalence classes of circuits, one for each distinct input/output table. However, there are infinitely many circuits that give rise to each table. For instance, two circuits for the previous input/output table are shown below.

AND

NOT

NOTP

Q

R OR NOT P

Q R

Congruence Modulo n Example 8.2.4 showed that the relation of congruence modulo 3 is reflexive, symmetric, and transitive. Therefore, it is an equivalence relation.

Example 8.3.10 Equivalence Classes of Congruence Modulo 3

Let R be the relation of congruence modulo 3 on the set Z of all integers. That is, for all integers m and n,

m R n ⇔ 3 | (m − n) ⇔ m ≡ n (mod 3).

Describe the distinct equivalence classes of R.

Solution For each integer a,

[a] = {x ∈ Z | x R a} = {x ∈ Z | 3 | (x − a)} = {x ∈ Z | x − a = 3k, for some integer k}.

Therefore,

[a] = {x ∈ Z | x = 3k + a, for some integer k}.

In particular, [0] = {x ∈ Z | x = 3k + 0, for some integer k} = {x ∈ Z | x = 3k, for some integer k} = {. . .− 9,−6,−3, 0, 3, 6, 9, . . .},

[1] = {x ∈ Z | x = 3k + 1, for some integer k} = {. . .− 8,−5,−2, 1, 4, 7, 10, . . .},

[2] = {x ∈ Z | x = 3k + 2, for some integer k} = {. . .− 7,−4,−1, 2, 5, 8, 11, . . .}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

472 Chapter 8 Relations

Now since 3 R 0, then by Lemma 8.3.2,

[3] = [0]. More generally, by the same reasoning,

[0] = [3] = [−3] = [6] = [−6] = . . . , and so on.

Similarly,

[1] = [4] = [−2] = [7] = [−5] = . . . , and so on. And

[2] = [5] = ⌈−1⌉ = [8] = [−4] = . . . , and so on. Notice that every integer is in class [0], [1], or [2]. Hence the distinct equivalence classes are

{x ∈ Z | x = 3k, for some integer k}, {x ∈ Z | x = 3k + 1, for some integer k}, and {x ∈ Z | x = 3k + 2, for some integer k}.

In words, the three classes of congruence modulo 3 are (1) the set of all integers that are divisible by 3, (2) the set of all integers that leave a remainder of 1 when divided by 3, and (3) the set of all integers that leave a remainder of 2 when divided by 3. ■

Example 8.3.10 illustrates a very important property of equivalence classes, namely that an equivalence class may have many different names. In Example 8.3.10, for instance, the class of 0, [0], may also be called the class of 3, [3], or the class of−6, [−6]. But what the class is is the set

{x ∈ Z | x = 3k, for some integers k}. (The quote at the beginning of this section refers in a humorous way to the philosophically interesting distinction between what things are called and what they are.)

• Definition Suppose R is an equivalence relation on a set A and S is an equivalence class of R. A representative of the class S is any element a such that [a] = S.

In exercises 36–41 at the end of this section, you are asked to show in effect, that if a is any element of an equivalence class S, then S = [a]. Hence any element of an equivalence class is a representative of that class.

B et

tm an

n/ CO

R B

IS

Carl Friedrich Gauss (1777–1855)

The following notation is used frequently when referring to congruence relations. It was introduced by Carl Friedrich Gauss in the first chapter of his book Disquisitiones Arithmeticae. This work, which was published when Gauss was only 24, laid the founda- tion for modern number theory.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 473

• Definition Let m and n be integers and let d be a positive integer. We say that m is congruent to n modulo d and write

m ≡ n (mod d) if, and only if, d | (m − n).

Symbolically: m ≡ n (mod d) ⇔ d | (m − n)

Exercise 17(b) at the end of this section asks you to show that m ≡ n (mod d) if, and only if, m mod d = n mod d, where m, n, and d are integers and d is positive.

Example 8.3.11 Evaluating Congruences

Determine which of the following congruences are true and which are false.

a. 12 ≡ 7 (mod 5) b. 6 ≡ −8 (mod 4) c. 3 ≡ 3 (mod 7) Solution

a. True. 12− 7 = 5 = 5 · 1. Hence 5 | (12− 7), and so 12 ≡ 7 (mod 5). b. False. 6− (−8) = 14, and 4 |/ 14 because 14 ̸= 4 · k for any integer k. Consequently,

6≡/ −8 (mod 4). c. True. 3− 3 = 0 = 7 · 0. Hence 7 | (3− 3), and so 3 ≡ 3 (mod 7). ■

A Definition for Rational Numbers For a moment, forget what you know about fractional arithmetic and look at the numbers

1 3

and 2 6

as symbols. Considered as symbolic expressions, these appear quite different. In fact, if they were written as ordered pairs

(1, 3) and (2, 6)

they would be different. The fact that we regard them as “the same” is a specific instance of our general agreement to regard any two numbers

a b

and c d

as equal provided the cross products are equal: ad = bc. This can be formalized as fol- lows, using the language of equivalence relations.

Example 8.3.12 Rational Numbers Are Really Equivalence Classes

Let A be the set of all ordered pairs of integers for which the second element of the pair is nonzero. Symbolically,

A = Z× (Z− {0}).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

474 Chapter 8 Relations

Define a relation R on A as follows: For all (a, b), (c, d) ∈ A,

(a, b) R (c, d) ⇔ ad = bc.

The fact is that R is an equivalence relation.

a. Prove that R is transitive. (Proofs that R is reflexive and symmetric are left to exercise 42 at the end of the section.)

b. Describe the distinct equivalence classes of R.

Solution

a. [We must show that for all (a, b), (c, d), (e, f ) ∈ A, if (a, b) R (c, d) and (c, d)R (e, f ), then (a, b) R (e, f ).] Suppose (a, b), (c, d), and (e, f ) are particular but arbitrarily chosen elements of A such that (a, b) R (c, d) and (c, d) R (e, f ). [We must show that (a, b) R (e, f ).] By definition of R,

(1) ad = bc and (2) c f = de. Since the second elements of all ordered pairs in A are nonzero, b ̸= 0, d ̸= 0, and f ̸= 0. Multiply both sides of equation (1) by f and both sides of equation (2) by b to obtain

(1′) ad f = bc f and (2′) bc f = bde. Thus

ad f = bde and, since d ̸= 0, it follows from the cancellation law for multiplication (T7 in Appendix A) that

a f = be. It follows, by definition of R, that (a, b) R (e, f ) [as was to be shown].

b. There is one equivalence class for each distinct rational number. Each equivalence class consists of all ordered pairs (a, b) that, if written as fractions a/b, would equal each other. The reason for this is that the condition for two rational numbers to be equal is the same as the condition for two ordered pairs to be related. For instance, the class of (1, 2) is

[(1, 2)] = {(1, 2), (−1,−2), (2, 4), (−2,−4), (3, 6), (−3,−6), . . .}

since 1 2

= −1−2 = 2 4

= −2−4 = 3 6

= −3−6 and so forth. ■

It is possible to expand the result of Example 8.3.12 to define operations of addition and multiplication on the equivalence classes of R that satisfy all the same properties as the addition and multiplication of rational numbers. (See exercise 43.) It follows that the rational numbers can be defined as equivalence classes of ordered pairs of integers. Similarly (see exercise 44), it can be shown that all integers, negative and zero included, can be defined as equivalence classes of ordered pairs of positive integers. But in the late nineteenth century, F. L. G. Frege and Giuseppe Peano showed that the positive integers can be defined entirely in terms of sets. And just a little earlier, Richard Dedekind (1848–1916) showed that all real numbers can be defined as sets of rational numbers. All together, these results show that the real numbers can be defined using logic and set theory alone.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 475

Test Yourself 1. For a relation on a set to be an equivalence relation, it must

be _____.

2. The notation m ≡ n (mod d) is read “_____” and means that _____.

3. Given an equivalence relation R on a set A and given an ele- ment a in A, the equivalence class of a is denoted _____ and is defined to be _____.

4. If A is a set, R is an equivalence relation on A, and a and b are elements of A, then either [a] = [b] or _____.

5. If A is a set and R is an equivalence relation on A, then the distinct equivalence classes of R form _____.

6. Let A = Z× (Z− {0}), and define a relation R on A by specifying that for all (a, b) and (c, d) in A, (a, b) R (c, d) if, and only if, ad = bc. Then there is exactly one equiva- lence class of R for each _____.

Exercise Set 8.3 1. Suppose that S = {a, b, c, d, e} and R is a relation on S

such that a R b, b R c, and d R e. List all of the following that must be true if R is (a) reflexive (but not symmetric or transitive), (b) symmetric (but not reflexive or transitive), (c) transitive (but not reflexive or symmetric), and (d) an equivalence relation.

c R b c R c a R c b R a a R d e R a e R d c R a

2. Each of the following partitions of {0, 1, 2, 3, 4} induces a relation R on {0, 1, 2, 3, 4}. In each case, find the ordered pairs in R. a. {0, 2}, {1}, {3, 4} b. {0}, {1, 3, 4}, {2} c. {0}, {1, 2, 3, 4}

In each of 3–14, the relation R is an equivalence relation on the set A. Find the distinct equivalence classes of R.

3. A = {0, 1, 2, 3, 4} R = {(0, 0), (0, 4), (1, 1), (1, 3), (2, 2), (3, 1), (3, 3),

(4, 0), (4, 4)}

4. A = {a, b, c, d} R = {(a, a), (b, b), (b, d), (c, c), (d, b), (d, d)}

5. A = {1, 2, 3, 4, . . . , 20}. R is defined on A as follows: For all x, y ∈ A, x R y ⇔ 4 | (x − y).

6. A = {−4,−3,−2,−1, 0, 1, 2, 3, 4, 5}. R is defined on A as follows:

For all x, y ∈ A, x R y ⇔ 3 | (x − y).

7. A = {(1, 3), (2, 4), (−4,−8), (3, 9), (1, 5), (3, 6)}. R is defined on A as follows: For all (a, b), (c, d) ∈ A,

(a, b) R (c, d) ⇔ ad = bc.

8. X = {a, b, c} and A = P(X). R is defined on A as fol- lows: For all sets U and V in P(X),

U R V ⇔ N (U) = N (V). (That is, the number of elements in U equals the number of elements in V.)

9. X = {−1, 0, 1} and A = P(X). R is defined on P(X) as follows: For all sets S and T in P(X),

S R T ⇔ the sum of the elements in S equals the sum of the elements in T.

10. A = {−5,−4,−3,−2,−1, 0, 1, 2, 3, 4, 5}. R is defined on A as follows: For all m, n ∈ Z,

m R n ⇔ 3 | (m2 − n2).

11. A = {−4, −3, −2, −1, 0, 1, 2, 3, 4}. R is defined on A as follows: For all (m, n) ∈ A,

m R n ⇔ 4 | (m2 − n2). 12. A = {−4, −3, −2, −1, 0, 1, 2, 3, 4}. R is defined on

A as follows: For all (m, n) ∈ A, m R n ⇔ 5 | (m2 − n2).

13. A is the set of all strings of length 4 in a’s and b’s. R is defined on A as follows: For all strings s and t in A,

s R t ⇔ s has the same first two characters as t . 14. A is the set of all strings of length 2 in 0’s, 1’s, and 2’s. R

is defined on A as follows: For all strings s and t in A,

s R t ⇔ the sum of the characters in s equals the sum of the characters in t .

15. Determine which of the following congruence relations are true and which are false. a. 17 ≡ 2 (mod 5) b. 4 ≡ −5 (mod 7) c. −2 ≡ −8 (mod 3) d. −6 ≡ 22 (mod 2)

16. a. Let R be the relation of congruence modulo 3. Which of the following equivalence classes are equal?

[7], [−4], [−6], [17], [4], [27], [19] b. Let R be the relation of congruence modulo 7. Which of

the following equivalence classes are equal?

[35], [3], [−7], [12], [0], [−2], [17]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

476 Chapter 8 Relations

17. a. Prove that for all integers m and n, m ≡ n (mod 3) if, and only if, m mod 3 = n mod 3.

b. Prove that for all integers m and n and any positive integer d, m ≡ n (mod d) if, and only if, m mod d = n mod d.

18. a. Give an example of two sets that are distinct but not dis- joint.

b. Find sets A1 and A2 and elements x, y and z such that x and y are in A1 and y and z are in A2 but x and z are not both in either of the sets A1 or A2.

In 19–31, (1) prove that the relation is an equivalence relation, and (2) describe the distinct equivalence classes of each relation.

19. A is the set of all students at your college. a. R is the relation defined on A as follows: For all x and

y in A,

x R y ⇔ x has the same major (or double major) as y.

(Assume “undeclared” is a major.) b. S is the relation defined on A as follows: For all

x, y ∈ A, x S y ⇔ x is the same age as y.

20.H E is the relation defined on Z as follows:

For all m, n ∈ Z, m E n ⇔ 2 | (m − n). 21. F is the relation defined on Z as follows:

For all m, n ∈ Z, m F n ⇔ 4 | (m − n). 22. Let A be the set of all statement forms in three variables

p, q , and r . R is the relation defined on A as follows: For all P and Q in A,

P R Q ⇔ P and Q have the same truth table. 23. Let P be a set of parts shipped to a company from various

suppliers. S is the relation defined on P as follows: For all x, y ∈ P ,

x S y ⇔ x has the same part number and is shipped from the same supplier as y.

24. Let A be the set of identifiers in a computer program. It is common for identifiers to be used for only a short part of the execution time of a program and not to be used again to execute other parts of the program. In such cases, arranging for identifiers to share memory locations makes efficient use of a computer’s memory capacity. Define a relation R on A as follows: For all identifiers x and y,

x R y ⇔ the values of x and y are stored in the same memory location during execution of the program.

25. A is the “absolute value” relation defined on R as follows:

For all x, y ∈ R, x A y ⇔ |x | = |y|.

26.H D is the relation defined on Z as follows: For all m, n ∈ Z, m D n ⇔ 3 | (m2 − n2).

27. R is the relation defined on Z as follows: For all (m, n) ∈ Z, m R n ⇔ 4 | (m2 − n2).

28. I is the relation defined on R as follows:

For all x, y ∈ R, x I y ⇔ x − y is an integer.

29. Define P on the set R× R of ordered pairs of real numbers as follows: For all (w, x), (y, z) ∈ R × R,

(w, x) P (y, z) ⇔ w = y. 30. Define Q on the set R× R as follows: For all

(w, x), (y, z) ∈ R× R, (w, x) Q (y, z) ⇔ x = z.

31. Let P be the set of all points in the Cartesian plane except the origin. R is the relation defined on P as follows: For all p1 and p2 in P ,

p1 R p2 ⇔ p1 and p2 lie on the same half-line emanating from the origin.

32.H Let A be the set of all straight lines in the Cartesian plane. Define a relation || on A as follows:

For all l1 and l2 in A, l1 ∥ l2 ⇔ l1 is parallel to l2. Then ∥ is an equivalence relation on A. Describe the

equivalence classes of this relation.

33. Let A be the set of points in the rectangle with x and y coordinates between 0 and 1. That is,

A = {(x, y) ∈ R× R | 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1}.

Define a relation R on A as follows: For all (x1, y1) and (x2, y2) in A,

(x1, y1) R (x2, y2)⇔ (x1, y1) = (x2, y2); or x1 = 0 and x2 = 1 and y1 = y2; or x1 = 1 and x2 = 0 and y1 = y2; or y1 = 0 and y2 = 1 and x1 = x2; or y1 = 1 and y2 = 0 and x1 = x2.

In other words, all points along the top edge of the rectan- gle are related to the points along the bottom edge directly beneath them, and all points directly opposite each other along the left and right edges are related to each other. The points in the interior of the rectangle are not related to anything other than themselves. Then R is an equivalence relation on A. Imagine gluing together all the points that are in the same equivalence class. Describe the resulting figure.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.3 Equivalence Relations 477

34. The documentation for the computer language Java rec- ommends that when an “equals method” is defined for an object, it be an equivalence relation. That is, if R is defined as follows:

x R y ⇔ x .equals(y) for all objects in the class, then R should be an equivalence relation. Suppose that in trying to optimize some of the mathematics of a graphics application, a programmer creates an object called a point, consisting of two coordinates in the plane. The program- mer defines an equals method as follows: If p and q are any points, then

p.equals(q) ⇔ the distance from p to q is less than or equal to c

where c is a small positive number that depends on the res- olution of the computer display. Is the programmer’s equals method an equivalence relation? Justify your answer.

35. Find an additional representative circuit for the input/output table of Example 8.3.9.

Let R be an equivalence relation on a set A. Prove each of the statements in 36–41 directly from the definitions of equiva- lence relation and equivalence class without using the results of Lemma 8.3.2, Lemma 8.3.3, or Theorem 8.3.4.

36. For all a in A, a ∈ [a]. 37. For all a and b in A, if b ∈ [a] then a R b. 38. For all a, b and c in A, if b R c and c ∈ [a] then b ∈ [a]. 39. For all a and b in A, if [a] = [b] then a R b. 40. For all a, b, and x in A, if a R b and x ∈ [a], then x ∈ [b]. 41.H For all a and b in A, if a ∈ [b] then [a] = [b]. 42. Let R be the relation defined in Example 8.3.12.

a. Prove that R is reflexive. b. Prove that R is symmetric. c. List four distinct elements in [(1, 3)]. d. List four distinct elements in [(2, 5)].

43.✶ In Example 8.3.12, define operations of addition (+) and multiplication (·) as follows: For all (a, b), (c, d) ∈ A,

[(a, b)] + [(c, d)] = [(ad + bc, bd)] [(a, b)] · [(c, d)] = [(ac, bd)].

a. Prove that this addition is well defined. That is, show that if [(a, b)] = [(a′, b′)] and [(c, d)] = [(c′, d ′)], then [(ad + bc, bd)] = [(a′d ′ + b′c′, b′d ′)].

b. Prove that this multiplication is well defined. That is, show that if [(a, b)] = [(a′, b′)] and [(c, d)] = [(c′, d ′)], then [(ac, bd)] = [(a′c′, b′d ′)].

c. Show that [(0, 1)] is an identity element for addition. That is, show that for any (a, b) ∈ A,

[(a, b)] + [(0, 1)] = [(0, 1)] + [(a, b)] = [(a, b)]. d. Find an identity element for multiplication. That is, find

(i, f ) in A so that for all (a, b) in A. [(a, b)] · [(i, j)] = [(i, j)] · [(a, b)] = [(a, b)].

e. For any (a, b) ∈ A, show that [(−a, b)] is an inverse for [(a, b)] for addition. That is, show that [(−a, b)] + [(a, b)] = [(a, b)] + [(−a, b)] = [(0, 1)].

f. Given any (a, b) ∈ A with a ̸= 0, find an inverse for [(a, b)] for multiplication. That is, find (c, d) in A so that [(a, b)] · [(c, d)] = [(c, d)]− [(a, b)] = [(i, j)], where [(i, j)] is the identity element you found in part (d).

44. Let A = Z+× Z+. Define a relation R on A as follows: For all (a, b) and (c, d) in A,

(a, b) R (c, d) ⇔ a + d = c + b. a. Prove that R is reflexive. b. Prove that R is symmetric. c.H Prove that R is transitive. d. List five elements in [(1, 1)]. e. List five elements in [(3, 1)]. f. List five elements in [(1, 2)]. g. Describe the distinct equivalence classes of R.

45. The following argument claims to prove that the require- ment that an equivalence relation be reflexive is redundant. In other words, it claims to show that if a relation is sym- metric and transitive, then it is reflexive. Find the mistake in the argument.

“Proof: Let R be a relation on a set A and suppose R is symmetric and transitive. For any two elements x and y in A, if x R y then y R x since R is symmetric. But then it follows by transitivity that x R x . Hence R is reflexive.”

46. Let R be a relation on a set A and suppose R is symmet- ric and transitive. Prove the following: If for every x in A there is a y in A such that x R y, then R is an equivalence relation.

47. Refer to the quote at the beginning of this section to answer the following questions. a. What is the name of the Knight’s song called? b. What is the name of the Knight’s song? c. What is the Knight’s song called? d. What is the Knight’s song? e. What is your (full, legal) name? f. What are you called? g. What are you? (Do not answer this on paper; just think

about it.)

Answers for Test Yourself 1. reflexive, symmetric, and transitive 2. m is congruent to n modulo d; d divides m − n 3. [a]; the set of all x in A such that x R a 4. [a] ∩ [b] = ∅ 5. a partition of A 6. rational number

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

478 Chapter 8 Relations

8.4 Modular Arithmetic with Applications to Cryptography The “real” mathematics of the “real” mathematicians, the mathematics of Fermat and Euler and Gauss and Abel and Riemann, is almost wholly “useless.” . . . It is not possible to justify the life of any genuine professional mathematician on the ground of the “utility” of his work. — G. H. Hardy, A Mathematician’s Apology, 1941

Cryptography is the study of methods for sending secret messages. It involves encryp- tion, in which a message, called plaintext, is converted into a form, called ciphertext, that may be sent over channels possibly open to view by outside parties. The receiver of the ciphertext uses decryption to convert the ciphertext back into plaintext.

In the past the primary use of cryptography was for government and military intel- ligence, and this use continues to be important. In fact, the National Security Agency, whose main business is cryptography, is the largest employer of mathematicians in the United States. With the rise of electronic communication systems, however, especially the Internet, an extremely important current use of cryptography is to make it possible to send private information, such as credit card numbers, banking data, medical records, and so forth, over electronic channels.

Many systems for sending secret messages require both the sender and the receiver to know both the encryption and the decryption procedures. For instance, an encryption system once used by Julius Caesar, and now called the Caesar cipher, encrypts messages by changing each letter of the alphabet to the one three places farther along, with X wrapping around to A, Y to B, and Z to C. In other words, say each letter of the alphabet is coded by its position relative to the others—so that A = 01, B = 02, . . . , Z = 26. If the numerical version of the plaintext for a letter is denoted M and the numeric version of the ciphertext is denoted C , then

C = (M + 3) mod 26.

The receiver of such a message can easily decrypt it by using the formula

M = (C − 3) mod 26.

For reference, here are the letters of the alphabet, together with their numeric equivalents:

A B C D E F G H I J K L M

01 02 03 04 05 06 07 08 09 10 11 12 13

N O P Q R S T U V W X Y Z

14 15 16 17 18 19 20 21 22 23 24 25 26

Example 8.4.1 Encrypting and Decrypting with the Caesar Cipher

a. Use the Caesar cipher to encrypt the message HOW ARE YOU.

b. Use the Caesar cipher to decrypt the message L DP ILQH.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 479

Solution

a. First translate the letters of HOW ARE YOU into their numeric equivalents:

08 15 23 01 18 05 25 15 21.

Next encrypt the message by adding 3 to each number. The result is

11 18 26 04 21 08 02 18 24.

Finally, substitute the letters that correspond to these numbers. The encrypted message becomes

KRZ DUH BRX.

b. First translate the letters of L DP ILQH into their numeric equivalents:

12 04 16 09 12 17 08.

Next decrypt the message by subtracting 3 from each number:

09 01 13 06 09 14 05.

Then translate back into letters to obtain the original message: I AM FINE. ■

One problem with the Caesar cipher is that given a sufficient amount of ciphertext a person with knowledge of letter frequencies in the language can easily figure out the cipher. Partly for this reason, even Caesar himself did not make extensive use of it. Another problem with a system like the Caesar cipher is that knowledge of how to encrypt a message automatically gives knowledge of how to decrypt it. When a potential recipi- ent of messages passes the encryption information to a potential sender of messages, the channel over which the information is passed may itself be insecure. Thus the information may leak out, enabling an outside party to decrypt messages intended to be kept secret.

With public-key cryptography, a potential recipient of encrypted messages openly dis- tributes a public key containing the encryption information. However, knowledge of the public key provides virtually no clue about how messages are decrypted. Only the recipi- ent has that knowledge. Regardless of how many people learn the encryption information, only the recipient should be able to decrypt messages that are sent.

The first public-key cryptography system was developed in 1976–1977 by three young mathematician/computer scientists working at M.I.T.: Ronald Rivest, Adi Shamir, and

From left to right: Ronald Rivest (born 1948), Adi Shamir (born 1952), and Leonard Adleman (born 1945) Co ur

te sy

of Le

on ar

d Ad

le m

an

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

480 Chapter 8 Relations

Leonard Adleman. In their honor it is called the RSA cipher. In order for you to learn how it works, you need to know some additional properties of congruence modulo n.

Properties of Congruence Modulo n The first theorem in this section brings together a variety of equivalent ways of express- ing the same basic arithmetic fact. Sometimes one way is most convenient; sometimes another way is best. You need to be comfortable moving from one to another, depending on the nature of the problem you are trying to solve.

Theorem 8.4.1 Modular Equivalences

Let a, b, and n be any integers and suppose n > 1. The following statements are all equivalent:

1. n | (a − b) 2. a ≡ b (mod n) 3. a = b + kn for some integer k 4. a and b have the same (nonnegative) remainder when divided by n

5. a mod n = b mod n

Proof:

We will show that (1)⇒ (2)⇒ (3)⇒ (4)⇒ (5)⇒ (1). It will follow by the transitivity of if-then that all five statements are equivalent.

So let a, b, and n be any integers with n > 1.

Proof that (1) ⇒ (2): Suppose that n | (a − b). By definition of congruence modulo n, we can immediately conclude that a ≡ b (mod n). Proof that (2) ⇒ (3): Suppose that a ≡ b (mod n). By definition of congruence modulo n, n | (a − b). Thus, by definition of divisibility, a − b = kn, for some integer k. Adding b to both sides gives that a = b + kn. Proof that (3) ⇒ (4): Suppose that a = b + kn, for some integer k. Use the quotient- remainder theorem to divide a by n to obtain

a = qn + r where q and r are integers and 0 ≤ r < n. Substituting b + kn for a in this equation gives that

b + kn = qn + r and subtracting kn from both sides and factoring out n yields

b = (q − k)n + r. But since 0 ≤ r < n, the uniqueness property of the quotient-remainder theorem

guarantees that r is also the remainder obtained when b is divided by n. Thus a and b have the same remainder when divided by n.

Proof that (4) ⇒ (5): Suppose that a and b have the same remainder when divided by n. It follows immediately from the definition of the mod function that a mod n = b mod n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 481

Proof that (5) ⇒ (1): Suppose that a mod n = b mod n. By definition of the mod function, a and b have the same remainder when divided by n. Thus, by the quotient- remainder theorem, we can write

a = q1n + r and b = q2n + r where q1, q2, and r are integers and 0 ≤ r < n.

It follows that

a − b = (q1n + r)− (q2n + r) = (q1 − q2)n.

Therefore, since q1 − q2 is an integer, n | (a − b).

Another consequence of the quotient-remainder theorem is this: When an integer a is divided by a positive integer n, a unique quotient q and remainder r are obtained with the property that a = nq + r and 0 ≤ r < n. Because there are exactly n integers that satisfy the inequality 0 ≤ r < n (the numbers from 0 through n − 1), there are exactly n possible remainders that can occur. These are called the least nonnegative residues modulo n or simply the residues modulo n.

• Definition Given integers a and n with n > 1, the residue of a modulo n is a mod n, the non- negative remainder obtained when a is divided by n. The numbers 0, 1, 2, . . . , n − 1 are called a complete set of residues modulo n. To reduce a number modulo n means to set it equal to its residue modulo n. If a modulus n > 1 is fixed throughout a discussion and an integer a is given, the words “modulo n” are often dropped and we simply speak of the residue of a.

The following theorem generalizes several examples from Section 8.3.

Theorem 8.4.2 Congruence Modulo n Is an Equivalence Relation

If n is any integer with n > 1, congruence modulo n is an equivalence relation on the set of all integers. The distinct equivalence classes of the relation are the sets [0], [1], [2], . . . , [n − 1], where for each a = 0, 1, 2, . . . , n − 1,

[a] = {m ∈ Z | m ≡ a (mod n)},

or, equivalently,

[a] = {m ∈ Z | m = a + kn for some integer k}.

Proof:

Suppose n is any integer with n > 1. We must show that congruence modulo n is reflexive, symmetric, and transitive.

Proof of reflexivity: Suppose a is any integer. To show that a ≡ a (mod n), we must show that n | (a − a). But a − a = 0, and n | 0 because 0 = n · 0. Therefore a ≡ a (mod n).

continued on page 482

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

482 Chapter 8 Relations

Proof of symmetry: Suppose a and b are any integers such that a ≡ b (mod n). We must show that b ≡ a (mod n). But since a ≡ b (mod n), then n | (a − b). Thus, by definition of divisibility, a − b = nk, for some integer k. Multiply both sides of this equation by −1 to obtain

−(a − b) = −nk, or, equivalently,

b − a = n(−k). Thus, by definition of divisibility n | (b − a), and so, by definition of congruence modulo n, b ≡ a (mod n). Proof of transitivity: This is left as exercise 5 at the end of the section.

Proof that the distinct equivalence classes are [0], [1], [2], . . . , [n − 1]: This is left as exercise 6 at the end of the section.

Observe that there is a one-to-one correspondence between the distinct equivalence classes for congruence modulo n and the elements of a complete set of residues modulo n.

Modular Arithmetic A fundamental fact about congruence modulo n is that if you first perform an addition, subtraction, or multiplication on integers and then reduce the result modulo n, you will obtain the same answer as if you had first reduced each of the numbers modulo n, per- formed the operation, and then reduced the result modulo n. For instance, instead of computing

(5 ·8) = 40 ≡ 1 (mod 3) you will obtain the same answer if you compute

(5 mod 3)(8 mod 3) = 2 ·2 = 4 ≡ 1 (mod 3). The fact that this process works is a result of the following theorem.

Theorem 8.4.3 Modular Arithmetic

Let a, b, c, d, and n be integers with n > 1, and suppose

a ≡ c (mod n) and b ≡ d (mod n). Then

1. (a + b) ≡ (c + d) (mod n)[-2pt] 2. (a − b) ≡ (c − d) (mod n)[-2pt] 3. ab ≡ cd (mod n) 4. am ≡ cm (mod n) for all integers m.

Proof:

Because we will make greatest use of part 3 of this theorem, we prove it here and leave the proofs of the remaining parts of the theorem to exercises 9–11 at the end of the section.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 483

Proof of Part 3: Suppose a, b, c, d, and n are integers with n > 1, and suppose a ≡ b (mod n) and c ≡ d (mod n). By Theorem 8.4.1, there exist integers s and t such that

a = c + sn and b = d + tn. Then

ab = (c + sn)(d + tn) by substitution = cd + ctn + snd + sntn = cd + n(ct + sd + stn) by algebra.

Let k = ct + sd + stn. Then k is an integer and ab = cd + nk. Thus by Theorem 8.4.1, ab ≡ cd (mod n).

Example 8.4.2 Getting Started with Modular Arithmetic

The most practical use of modular arithmetic is to reduce computations involving large integers to computations involving smaller ones. For instance, note that 55 ≡ 3 (mod 4) because 55− 3 = 52, which is divisible by 4, and 26 ≡ 2 (mod 4) because 26− 2 = 24, which is also divisible by 4. Verify the following statements.

a. 55 + 26 ≡ (3 + 2) (mod 4) b. 55− 26 ≡ (3− 2) (mod 4) c. 55 ·26 ≡ (3 ·2) (mod 4) d. 552 ≡ 32 (mod 4)

Solution

a. Compute 55 + 26 = 81 and 3 + 2 = 5. By definition of congruence modulo n, to show that 81 ≡ 5 (mod 4), you need to show that 4 | (81− 5). But this is true because 81− 5 = 76, and 4 | 76 since 76 = 4 ·19.

b. Compute 55− 26 = 29 and 3− 2 = 1. By definition of congruence modulo n, to show that 29 ≡ 1 (mod 4), you need to show that 4 | (29− 1). But this is true because 29− 1 = 28, and 4 | 28 since 28 = 4 ·7.

c. Compute 55 ·26 = 1430 and 3 ·2 = 6. By definition of congruence modulo n, to show that 1430 ≡ 6 (mod 4), you need to show that 4 | (1430− 6). But this is true because 1430− 6 = 1424, and 4 | 1424 since 1424 = 4 ·356.

d. Compute 552 = 3025 and 32 = 9. By definition of congruence modulo n, to show that 3025 ≡ 9 (mod 4), you need to show that 4 | (3025− 9). But this is true because 3025− 9 = 3016, and 4 | 3016 since 3016 = 4 ·754. ■

In order to facilitate the computations performed in this section, it is convenient to express part 3 of Theorem 8.4.3 in a slightly differently form.

Corollary 8.4.4

Let a, b, and n be integers with n > 1. Then

ab ≡ [(a mod n)(b mod n)] (mod n), or, equivalently,

ab mod n = [(a mod n)(b mod n)] mod n. In particular, if m is a positive integer, then

am ≡ [(a mod n)m] (mod n).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

484 Chapter 8 Relations

Example 8.4.3 Computing a Product Modulo n

As in Example 8.4.2, note that 55 ≡ 3 (mod 4) and 26 ≡ 2 (mod 4). Because both 3 and 2 are less than 4, each of these numbers is a least nonnegative residue modulo 4. Therefore, 55 mod 4 = 3 and 26 mod 4 = 2. Use the notation of Corollary 8.4.4 to find the residue of 55 ·26 modulo 4.

Solution Recall that to use a calculator to compute remainders, you can use the formula n mod d = n − d ·⌊n/d⌋. If you are using a hand calculator with an “integer part” feature and both n and d are positive, then ⌊n/d⌋ is the integer part of the division of n by d. When you divide a positive integer n by a positive integer d with a more basic calculator, you can see ⌊n/d⌋ on the calculator display by simply ignoring the digits that follow the decimal point.

By Corollary 8.4.4,

(55 ·26) mod 4 = {(55 mod 4)(26 mod 4)} mod 4 ≡ (3 ·2) mod 4 because 55 mod 4 = 3 and 26 mod 4 = 2 ≡ 6 mod 4 ≡ 2 because 4 | (6− 2) and 2 < 4. ■

When modular arithmetic is performed with very large numbers, as is the case for RSA crytography, computations are facilitated by using two properties of exponents. The first is

x2a = (xa)2 for all real numbers x and a with x ≥ 0. 8.4.1

Thus, for instance, if x is any positive real number, then

x4 mod n = (x2)2 mod n because (x2)2 = x4 = (x2 mod n)2 mod n by Corollary 8.4.4.

Hence you can reduce x4 modulo n by reducing x2 modulo n and then reducing the square of the result modulo n. Because all the residues are less than n, this process limits the size of the computations to numbers that are less than n2, which makes them easier to work with, both for humans (when the numbers are relatively small) and for computers (when the numbers are very large).

A second useful property of exponents is

xa+b = xa xb for all real numbers x , a, and b with x ≥ 0. 8.4.2

For instance, because 7 = 4 + 2 + 1,

x7 = x4x2x1

Thus, by Corollary 8.4.4,

x7 mod n = {(x4 mod n)(x2 mod n)(x1 mod n)} mod n.

We first show an example that illustrates the application of formula (8.4.1) and then an example that uses both (8.4.1) and (8.4.2).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 485

Example 8.4.4 Computing ak mod n When k Is a Power of 2

Find 1444 mod 713.

Solution Use property (8.4.1) to write 1444 = (1442)2. Then 1444 mod 713 = (1442)2 mod 713

= (1442 mod 713)2 mod 713 = (20736 mod 713)2 mod 713 because 1442 = 20736 = 592 mod 713 because 20736 mod 713 = 59 = 3481 mod 713 because 592 = 3481 = 629 because 3481 mod 713 = 629. ■

Example 8.4.5 Computing ak mod n When k Is Not a Power of 2

Find 1243 mod 713.

Solution First write the exponent as a sum of powers of 2:

43 = 25 + 23 + 2 + 1 = 32 + 8 + 2 + 1. Next compute 122

k for k = 1, 2, 3, 4, 5.

12 mod 713 = 12 122 mod 713 = 144 124 mod 713 = 1442 mod 713 = 59 by Example 8.4.4 128 mod 713 = 592 mod 713 = 629 by Example 8.4.4 1216 mod 713 = 6292 mod 713 = 639 by the method of Example 8.4.4 1232 mod 713 = 6392 mod 713 = 485 by the method of Example 8.4.4

By property (8.4.2),

1243 = 1232+8+2+1 = 1232 ·128 ·122 ·121. Thus, by Corollary 8.4.4,

1243 mod 713

= {(1232 mod 713) ·(128 mod 713) ·(122 mod 713) ·(12 mod 713)} mod 713. By substitution,

1243 mod 713 = (485 ·629 ·144 ·12) mod 713 = 527152320 mod 713 = 48. ■

It is important to understand how to do the computations in Example 8.4.5 by hand using only a simple electronic calculator, but if you are computing a lot of residues, especially ones involving large numbers, you may want to write a short computer or calculator program to do the computations for you.

Extending the Euclidean Algorithm An extended version of the Euclidean algorithm can be used to find a concrete expression for the greatest common divisor of integers a and b.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

486 Chapter 8 Relations

• Definition An integer d is said to be a linear combination of integers a and b if, and only if, there exist integers s and t such that as + bt = d.

Theorem 8.4.5 Writing a Greatest Common Divisor as a Linear Combination

For all integers a and b, not both zero, if d = gcd(a, b), then there exist integers s and t such that as + bt = d.

Proof:

Given integers a and b, not both zero, and given d = gcd(a, b), let S = {x | x is a positive integer and x = as + bt for some integers s and t}.

Note that S is a nonempty set because (1) if a > 0 then 1 ·a + 0 ·b ∈ S, (2) if a < 0 then (−1) ·a + 0 ·b ∈ S, and (3) if a = 0, then by assumption b ̸= 0, and hence 0 ·a + 1 ·b ∈ S or 0 ·a + (−1) ·b ∈ S. Thus, because S is a nonempty subset of pos- itive integers, by the well-ordering principle for the integers there is a least element c in S. By definition of S,

c = as + bt for some integers s and t . 8.4.3 We will show that (1) c ≥ d, and (2) c ≤ d , and we will therefore be able to conclude that c = d = gcd(a, b). (1) Proof that c ≥ d: [In this part of the proof, we show that d is a divisor of c and thus that d ≤ c.] Because d = gcd(a, b), by definition of greatest common divisor, d | a and d | b. Hence a = dx and b = dy for some integers x and y. Then

c = as + bt by (8.4.3) = (dx)s + (dy)t by substitution = d(xs + yt) by factoring out the d.

But xs + yt is an integer because it is a sum of products of integers. Thus, by defi- nition of divisibility, d | c. Both c and d are positive, and hence, by Theorem 4.3.1, c ≥ d. (2) Proof that c ≤ d: [In this part of the proof, we show that c is a divisor of both a and b and therefore that c is less than or equal to the greatest common divisor of a and b, which is d.] Apply the quotient-remainder theorem to the division of a by c to obtain

a = cq + r for some integers q and r with 0 ≤ r < c. 8.4.4 Thus for some integers q and r with 0 ≤ r < c,

r = a − cq Now c = as + bt . Therefore, for some integers q and r with 0 ≤ r < c,

r = a − (as + bt)q by substitution = a(1− sq)− btq.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 487

Thus r is a linear combination of a and b. If r > 0, then r would be in S, and so r would be a smaller element of S than c, which would contradict the fact that c is the least element of S. Hence r = 0. By substitution into (8.4.4),

a = cq

and therefore c | a. An almost identical argument establishes that c | b and is left as exercise 30 at

the end of the section. Because c | a and c | b, c is a common divisor of a and b. Hence it is less than or

equal to the greatest common divisor of a and b. In other words, c ≤ d . From (1) and (2), we conclude that c = d . It follows that d, the greatest common

divisor of a and b, is equal to as + bt .

The following example shows a practical method for expressing the greatest common divisor of two integers as a linear combination of the two.

Example 8.4.6 Expressing a Greatest Common Divisor as a Linear Combination

In Example 4.8.6 we showed how to use the Euclidean algorithm to find that the greatest common divisor of 330 and 156 is 6. Use the results of those calculations to express gcd(330, 156) as a linear combination of 330 and 156.

Solution The first four steps of the solution restate and extend results from Example 4.8.6, which were obtained by successive applications of the quotient-remainder theorem. The fifth step shows how to find the coefficients of the linear combination by substituting back through the results of the previous steps.

Step 1: 330 = 156 ·2 + 18, which implies that 18 = 330− 156 ·2. Step 2: 156 = 18 ·8 + 12, which implies that 12 = 156− 18 ·8. Step 3: 18 = 12 ·1 + 6, which implies that 6 = 18− 12 ·1. Step 4: 12 = 6 ·2 + 0, which implies that gcd(330, 156) = 6. Step 5: By substituting back through steps 3 to 1:

6 = 18− 12 ·1 from step 3 = 18− (156− 8 ·18) ·1 by substitution from step 2 = 9 ·18 + (−1) ·156 by algebra = 9 ·(330− 156 ·2) + (−1) ·156 by substitution from step 1 = 9 ·330 + (−19) ·156 by algebra.

Thus gcd(330, 156) = 9 ·330 + (−19) ·156. (It is always a good idea to check the result of a calculation like this to be sure you did not make a mistake. In this case, you find that 9 ·330 + (−19) ·156 does indeed equal 6.) ■

The Euclidean algorithm given in Section 4.8 can be adapted so as to compute the coefficients of the linear combination of the gcd at the same time as it computes the gcd itself. This extended Euclidean algorithm is described in the exercises at the end of the section.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

488 Chapter 8 Relations

Finding an Inverse Modulo n Suppose you want to solve the following congruence for x :

2x ≡ 3 (mod 5) Note that 3 ·2 = 6 ≡ 1 (mod 5). So you can think of 3 as a kind of inverse for 2 modulo 5 and multiply both sides of the congruence to be solved by 3 to obtain

6x = 3 ·2x ≡ 3 ·3 (mod 5) ≡ 9 (mod 5) ≡ 4 (mod 5). But 6 ≡ 1 (mod 5), and so by Theorem 8.4.3(3), 6x ≡ 1x (mod 5) ≡ x (mod 5). Thus, by the symmetric and transitive properties of modular congruence,

x ≡ 4 (mod 5), and hence a solution is x = 4. (You can check that 2 ·4 = 8 ≡ 3 (mod 5).)

Unfortunately, it is not always possible to find an “inverse” modulo an integer n. For instance, observe that

2 ·1 ≡ 2 (mod 4) 2 ·2 ≡ 0 (mod 4) 2 ·3 ≡ 2 (mod 4).

By Theorem 8.4.3, these calculations suffice for us to conclude that the number 2 does not have an inverse modulo 4.

Describing the circumstances in which inverses exist in modular arithmetic requires the concept of relative primeness.

• Definition Integers a and b are relatively prime if, and only if, gcd(a, b) = 1. Integers a1, a2, a3, . . . , an are pairwise relatively prime if, and only if, gcd(ai , a j ) = 1 for all inte- gers i and j with 1 ≤ i, j ≤ n, and i ̸= j .

Given the definition of relatively prime integers, the following corollary is an imme- diate consequence of Theorem 8.4.5.

Corollary 8.4.6

If a and b are relatively prime integers, then there exist integers s and t such that as + bt = 1.

Example 8.4.7 Expressing 1 as a Linear Combination of Relatively Prime Integers

Show that 660 and 43 are relatively prime, and find a linear combination of 660 and 43 that equals 1.

Solution

Step 1: Divide 660 by 43 to obtain 660 = 43 ·15 + 15, which implies that 15 = 660− 43 ·15.

Step 2: Divide 43 by 15 to obtain 43 = 15 ·2 + 13, which implies that 13 = 43− 15 ·2. Step 3: Divide 15 by 13 to obtain 15 = 13 ·1 + 2, which implies that 2 = 15− 13.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 489

Step 4: Divide 13 by 2 to obtain 13 = 2 ·6 + 1, which implies that 1 = 13− 2 ·6. Step 5: Divide 2 by 1 to obtain 2 = 1 ·2 + 0, which implies that gcd(660, 43) = 1 and

so 660 and 43 are relatively prime.

Step 6: To express 1 as a linear combination of 660 and 43, substitute back through steps 4 to 1:

1 = 13− 2 ·6 from step 4 = 13− (15− 13) ·6 by substitution from step 3 = 7 ·13− 6 ·15 by algebra = 7 ·(43− 15 ·2)− 6 ·15 by substitution from step 2 = 7 ·43− 20 ·15 by algebra = 7 ·43− 20 ·(660− 43 ·15) by substitution from step 1 = 307 ·43− 20 ·660 by algebra.

Thus gcd(660, 43) = 1 = 307 ·43− 20 ·660. (And a check by direct computation con- firms that 307 ·43− 20 ·660 does indeed equal 1.) ■

A consequence of Corollary 8.4.6 is that under certain circumstances, it is possible to find an inverse for an integer modulo n.

Corollary 8.4.7 Existence of Inverses Modulo n

For all integers a and n, if gcd(a, n) = 1, then there exists an integer s such that as ≡ 1 (mod n). The integer s is called the inverse of a modulo n.

Proof:

Suppose a and n are integers and gcd(a, n) = 1. By Corollary 8.4.6, there exist integers s and t such that

as + nt = 1. Subtracting nt from both sides gives that

as = 1− nt = 1 + (−t)n. Thus, by definition of congruence modulo n,

as ≡ 1 (mod n).

Example 8.4.8 Finding an Inverse Modulo n

a. Find an inverse for 43 modulo 660. That is, find an integer s such that 43s ≡ 1 (mod 660). b. Find a positive inverse for 3 modulo 40. That is, find a positive integer s such that

3s ≡ 1 (mod 40). Solution

a. By Example 8.4.7,

307 ·43− 20 ·660 = 1. Adding 20 ·660 to both sides gives that

307 ·43 = 1 + 20 ·660.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

490 Chapter 8 Relations

Thus, by definition of congruence modulo 660,

307 ·43 ≡ 1 (mod 660),

so 307 is an inverse for 43 modulo 660.

b. Use the technique of Example 8.4.7 to find a linear combination of 3 and 40 that equals 1.

Step 1: Divide 40 by 3 to obtain 40 = 3 ·13 + 1. This implies that 1 = 40− 3 ·13. Step 2: Divide 3 by 1 to obtain 3 = 3 ·1 + 0. This implies that gcd(3, 40) = 1. Step 3: Use the result of step 1 to write

3 ·(−13) = 1 + (−1)40.

This result implies that −13 is an inverse for 3 modulo 40. In symbols, 3 ·(−13) ≡ 1 (mod 40). To find a positive inverse, compute 40− 13. The result is 27, and

27 ≡ −13 (mod 40)

because 27− (−13) = 40. So, by Theorem 8.4.3(3),

3 ·27 ≡ 3 ·(−13) ≡ 1 (mod 40),

and thus by the transitive property of congruence modulo n, 27 is a positive integer that is an inverse for 3 modulo 40. ■

RSA Cryptography At this point we have developed enough number theory to explain how to encrypt and decrypt messages using the RSA cipher. The effectiveness of the system is based on the fact that although modern computer algorithms make it quite easy to find two distinct large integers p and q—say on the order of several hundred digits each—that are virtu- ally certain to be prime, even the fastest computers are not currently able to factor their product, an integer with approximately twice that many digits. In order to encrypt a mes- sage using the RSA cipher, a person needs to know the value of pq and of another integer e, both of which are made publicly available. But only a person who knows the individual values of p and q can decrypt an encrypted message.

We first give an example to show how the cipher works and then discuss some of the theory to explain why it works. The example is unrealistic in the sense that because p and q are so small, it would be easy to figure out what they are just by knowing their product. But working with small numbers conveys the idea of the system, while keeping the computations in a range that can be performed with a hand calculator.

Suppose Alice decides to set up an RSA cipher. She chooses two prime numbers, say p = 5 and q = 11, and computes pq = 55. She then chooses a positive integer e that is relatively prime to (p − 1)(q − 1). In this case, (p − 1)(q − 1) = 4 · 10 = 40, so she may take e = 3 because 3 is relatively prime to 40. (In practice, taking e to be small could compromise the secrecy of the cipher, so she would take a larger number than 3. However, the mathematics of the cipher works as well for 3 as for a larger number, and the smaller number makes for easier calculations.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 491

The two numbers pq = 55 and e = 3 are the public key, which she may distribute widely. Because the RSA cipher works only on numbers, Alice also informs people how she will interpret the numbers in the messages they send her. Let us suppose that she encodes letters of the alphabet the same way as was done for the Caesar cipher:

A = 1, B = 2, C = 3, . . . , Z = 26. Let us also assume that the messages Alice receives consist of blocks, each of which, for simplicity, is taken to be a single, numerically encoded letter of the alphabet.

Someone who wants to send Alice a message breaks the message into blocks, each consisting of a single letter, and finds the numeric equivalent for each block. The plain- text, M , in a block is converted into ciphertext, C , according to the following formula:

C = Me mod pq. 8.4.5

Note that because both pq and e are public keys, anyone who is given the keys and knows modular arithmetic can encrypt a message to send to Alice.

Example 8.4.9 Encrypting a Message Using RSA Cryptography

Bob wants to send Alice the message HI. What is the ciphertext for his message?

Solution Bob will send his message in two blocks, one for the H and another for the I. Because H is the eighth letter in the alphabet, it is encoded as 08, or 8. The corresponding ciphertext is computed using formula (8.4.5) as follows:

C = 83 mod 55 = 512 mod 55 = 17.

Because I is the ninth letter in the alphabet, it is encoded as 09, or 9. The corresponding ciphertext is

C = 93 mod 55 = 729 mod 55 = 14.

Accordingly, Bob sends Alice the message: 17 14. ■

To decrypt the message, Alice needs to compute the decryption key, a number d that is a positive inverse to e modulo (p − 1)(q − 1). She obtains the plaintext M from the ciphertext C by the formula

M = Cd mod pq. 8.4.6

Note that because M + kpq ≡ M (mod pq), M must be taken to be less than pq, as in the above example, in order for the decryption to be guaranteed to produce the original message. But because p and q are normally taken to be so large, this requirement does not cause problems. Long messages are broken into blocks of symbols to meet the restriction and several symbols are included in each block to present decryption based on knowledge of letter frequencies.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

492 Chapter 8 Relations

Example 8.4.10 Decrypting a Message Using RSA Cryptography

Imagine that Alice has hired you to help her decrypt messages and has shared with you the values of p and q. Decrypt the following ciphertext for her: 17 14.

Solution Because p = 5 and q = 11, (p − 1)(q − 1) = 40, and so you first need to find the decryption key, which is a positive inverse for 3 modulo 40. Knowing that you would be needing this number, we computed it in Example 8.4.8(b) and found it to be 27. Thus you need to compute M = 1727mod 55. To do so, note that 27 = 16 + 8 + 2 + 1 = 24 + 23 + 2 + 1. Thus you will find the residues obtained when 17 is raised to successively higher powers of 2, up to 24 = 16.

17 mod 55 = 17 mod 55 = 17 172 mod 55 = 172 mod 55 = 14 174 mod 55 = (172)2 mod 55 = 142 mod 55 = 31 178 mod 55 = (174)2 mod 55 = 312 mod 55 = 26 1716 mod 55 = (178)2 mod 55 = 262 mod 55 = 16

Then you will use the fact that

1727 = 1716+8+2+1 = 1716 ·178 ·172 ·171

to write

1727 mod 55 = (1716 ·178 ·172 ·17) mod 55 ≡ [(1716 mod 55)(178 mod 55)(172 mod 55)(17 mod 55)] (mod 55)

by Corollary 8.4.4

≡ (16 ·26 ·14 ·17) (mod 55) ≡ 99008 (mod 55) ≡ 8 (mod 55).

Hence 1727 mod 55 = 8, and thus the plaintext of the first part of Bob’s message is 8, or 08. In the last step, you find the letter corresponding to 08, which is H . In exercises 14 and 15 at the end of this section, you are asked to show that when you decrypt 14, the result is 9, which corresponds to the letter I, so you can tell Alice that Bob’s message is HI. ■

Euclid’s Lemma Another consequence of Theorem 8.4.5 is known as Euclid’s lemma. It is the crucial fact behind the unique factorization theorem for the integers and is also of great importance in many other parts of number theory.

Theorem 8.4.8 Euclid’s Lemma

For all integers a, b, and c, if gcd(a, c) = 1 and a | bc, then a | b.

Proof:

Suppose a, b and c are integers, gcd(a, c) = 1, and a | bc. [We must show that a | b.] By Theorem 8.4.5, there exist integers s and t so that

as + ct = 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 493

Multiply both sides of this equation by b to obtain

bas + bct = b. 8.4.7 Since a | bc, by definition of divisibility there exists an integer k such that

bc = ak. 8.4.8 Substituting (8.4.8) into (8.4.7), rewriting, and factoring out an a gives that

b = bas + (ak)t = a(bs + kt). Let r = bs + kt . Then r is an integer (because b, s, k, and t are all integers), and b = ar . Thus a | b by definition of divisibility.

The unique factorization theorem for the integers states that any integer greater than 1 has a unique representation as a product of prime numbers, except possibly for the order in which the numbers are written. The hint for exercise 13 of Section 3.4 outlined a proof of the existence part of the proof, and the uniqueness of the representation follows quickly from Euclid’s lemma. In exercise 41 at the end of this section, we outline a proof for you to complete.

Another application of Euclid’s lemma is a cancellation theorem for congruence modulo n. This theorem allows us—under certain circumstances—to divide out a com- mon factor in a congruence relation.

Theorem 8.4.9 Cancellation Theorem for Modular Congruence

For all integers a, b, c, and n with n>1, if gcd(c, n) = 1 and ac ≡ bc (mod n), then a ≡ b (mod n).

Proof:

Suppose a, b, c, and n are any integers, gcd(c, n) = 1, and ac ≡ bc (mod n). [We must show that a ≡ b (mod n).] By definition of congruence modulo n,

n | (ac − bc). and so, since

ac − bc = (a − b)c, n | (a − b)c.

Because gcd(c, n) = 1, we may apply Euclid’s lemma to obtain n | (a − b),

and so, by definition of congruence modulo n,

a ≡ b (mod n).

An alternative proof for Theorem 8.4.9 uses Corollary 8.4.7. Because gcd(c, n) = 1, the corollary guarantees an inverse for c modulo n. In the proof of Theorem 8.4.9, let d denote an inverse for c. Apply Theorem 8.4.3(3) repeatedly, first to multiply both sides of ac ≡ bc (mod n) by d to obtain (ac)d ≡ (bd)d (mod n), and then to use the fact that cd ≡ 1 (mod n) to simplify the congruence and conclude that a ≡ b (mod n).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

494 Chapter 8 Relations

Fermat’s Little Theorem Fermat’s little theorem was given that name to distinguish it from Fermat’s last theorem, which we discussed in Section 4.1. It provides the theoretical underpinning for RSA cryptography.

Theorem 8.4.10 Fermat’s Little Theorem

If p is any prime number and a is any integer such that p & a, then a p−1 ≡ 1 (mod p).

Proof:

Suppose p is any prime number and a is any integer such that p & a. Note that a ̸= 0 because otherwise p would divide a. Consider the set of integers

S = {a, 2a, 3a, . . . , (p − 1)a}. We claim that no two elements of S are congruent modulo p. For suppose sa ≡ ra (mod p) for some integers s and r with 1 ≤ r < s ≤ p − 1. Then, by definition of congruence modulo p,

p | (sa − ra), or, equivalently, p | (s − r)a. Now p & a by hypothesis, and because p is prime, gcd(a, p) = 1. Thus, by Euclid’s lemma, p | (s − r). But this is impossible because 0 < s − r < p.

Consider the function F from S to the set T = {1, 2, 3, . . . , (p − 1)} that sends each element of S to its residue modulo p. Then F is one-to-one because no two elements of S are congruent modulo p. In Section 9.4 we prove that if a func- tion from one finite set to another is one-to-one, then it is also onto. Hence F is onto, and so the p − 1 residues of the p − 1 elements of S are exactly the numbers 1, 2, 3, . . . , (p − 1).

It follows by Theorem 8.4.3(3) that

a ·2a ·3a · · · (p − 1)a ≡ [1 ·2 ·3 · · · (p − 1)] (mod p), or equivalently,

a p−1(p − 1)! ≡ (p − 1)! (mod p). But because p is prime, p and (p − 1)! are relatively prime. Thus, by the cancellation theorem for modular congruence (Theorem 8.4.9),

a p−1 ≡ 1 (mod p).

Why Does the RSA Cipher Work? For the RSA cryptography method, the formula

M = Cd mod pq is supposed to produce the original plaintext message, M, when the encrypted message is C. How can we be sure that it always does so? Recall that we require that M < pq, and we know that C = Me mod pq. So, by substitution,

Cd mod pq = (Me mod pq)d mod pq. By Theorem 8.4.3(4),

(Me mod pq)d ≡ Med (mod pq).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 495

Thus Cd mod pq ≡ Med(mod pq), and so it suffices to show that M ≡ Med (mod pq).

Recall that d was chosen to be a positive inverse for e modulo (p − 1)(q − 1), which exists because gcd(e, (p − 1)(q − 1)) = 1. In other words,

ed ≡ 1 (mod (p − 1)(q − 1)), or, equivalently,

ed = 1 + k(p − 1)(q − 1) for some positive integer k. Therefore,

Med = M1+k(p−1)(q−1) = M(M p−1)k(q−1) = M(Mq−1)k(p−1)

If p & M , then by Fermat’s little theorem, M p−1 ≡ 1 (mod p), and so Med = M(M p−1)k(q−1) ≡ M(1)k(q−1) (mod p) = M (mod p).

Similarly, if q & M , then by Fermat’s little theorem, Mq−1 ≡ 1 (mod q), and so Med = M(Mq−1)k(p−1) ≡ M(1)k(p−1) = M (mod q).

Thus, if M is relatively prime to pq,

Med ≡ M (mod p) and Med ≡ M (mod q). If M is not relatively prime to pq, then either p | M or q | M . Without loss of generality, assume p | M . It follows that Med ≡ 0 ≡ M (mod p). Moreover, because M < pq, q | M , and thus, as above, Med ≡ M (mod q). Therefore, in this case also,

Med ≡ M (mod p) and Med ≡ M (mod q). By Theorem 8.4.1,

p | (Med − M) and q | (Med − M), and, by definition of divisibility,

Med − M = pt for some integer t. By substitution, q | pt, and since q and p are distinct prime numbers, Euclid’s lemma applies to give

q | t. Thus t = qu for some integer u by definition of divisibility. By substitution,

M − Med = pt = p(qu) = (pq)u, where u is an integer, and so,

pq | (M − Med) by definition of divisibility. Thus

M − Med ≡ 0 (mod pq)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

496 Chapter 8 Relations

by definition of congruence, or, equivalently,

M ≡ Med(mod pq). Because M < pq, this last congruence implies that

M = Med mod pq, and thus the RSA cipher gives the correct result.

Additional Remarks on Number Theory and Cryptography The famous British mathematician G. H. Hardy (1877–1947) was fond of comparing the beauty of pure mathematics, especially number theory, to the beauty of art. Indeed, the theorems in this section have many beautiful and striking consequences beyond those we have had the space to describe, and the subject of number theory extends far beyond these theorems. Hardy also enjoyed describing pure mathematics as useless. Hence it is ironic that there are now whole books devoted to applications of number theory to computer science, RSA cryptography being just one such application. Furthermore, as the need for public-key cryptography has developed, techniques from other areas of mathematics, such as abstract algebra and algebraic geometry, have been used to develop additional cryptosystems.

Test Yourself 1. When letters of the alphabet are encrypted using the Caesar

cipher, the encrypted version of a letter is _____.

2. If a, b, and n are integers with n > 1, all of the following are different ways to express the fact that n | (a − b): _____, _____, _____, _____.

3. If a, b, c, d, m, and n are integers with n > 1 and if a ≡ c (mod n) and b ≡ d (mod n), then a + b ≡ _____, a − b ≡ _____, ab ≡ _____, and am ≡ _____.

4. If a, n, and k are positive integers with n > 1, an efficient way to compute ak (mod n) is to write k as a _____ and use the facts about computing products and powers modulo n.

5. To express a greatest common divisor of two integers as a linear combination of the integers, use the extended _____ algorithm.

6. To find an inverse for a positive integer a modulo an integer n with n > 1, you express the number 1 as _____.

7. To encrypt a message M using RSA cryptography with pub- lic key pq and e, you use the formula _____, and to decrypt a message C , you use the formula _____, where _____.

8. Euclid’s lemma says that for all integers a, b, and c if gcd(a, c) = 1 and a | bc, then _____.

9. Format’s little theorem says that if p is any prime number and a is any integer such that p | a then _____.

10. The crux of the proof that the RSA cipher works is that if (1) p and q are distinct large prime numbers, (2) M < pq, (3) M is relatively prime to pq, (4) e is relatively prime to (p − 1)(q − 1), and (5) d is a positive inverse for e modulo (p − 1)(q − 1), then M = _____.

Exercise Set 8.4 1. a. Use the Caesar cipher to encrypt the message WHERE

SHALL WE MEET. b. Use the Caesar cipher to decrypt the message LQ WKH

FDIHWHULD.

2. a. Use the Caesar cipher to encrypt the message AN APPLE A DAY.

b. Use the Caesar cipher to decrypt the message NHHSV WKH GRFWRU DZDB.

3. Let a = 25, b = 19, and n = 3. a. Verify that 3 | (25− 19). b. Explain why 25 ≡ 19 (mod 3). c. What value of k has the property that 25 = 19 + 3k?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.4 Modular Arithmetic with Applications to Cryptography 497

d. What is the (nonnegative) remainder obtained when 25 is divided by 3? When 19 is divided by 3?

e. Explain why 25 mod 3 = 19 mod 3. 4. Let a = 67, b = 32, and n = 7.

a. Verify that 7 | (68− 33). b. Explain why 68 ≡ 33 (mod 7). c. What value of k has the property that 68 = 33 + 7k? d. What is the (nonnegative) remainder obtained when 68

is divided by 7? When 33 is divided by 7? e. Explain why 68 mod 7 = 33 mod 7.

5. Prove the transitivity of modular congruence. That is, prove that for all integers a, b, c, and n with n > 1, if a ≡ b(mod n) and b ≡ c (mod n) then a ≡ c (mod n).

6.H Prove that the distinct equivalence classes of the relation of congruence modulo n are the sets [0], [1], [2], . . . , [n − 1], where for each a = 0, 1, 2, . . . , n − 1,

[a] = {m ∈ Z | m ≡ a (mod n)}.

7. Verify the following statements. a. 128 ≡ 2 (mod 7) and 61 ≡ 5 (mod 7) b. (128 + 61) ≡ (2 + 5) (mod 7) c. (128− 61) ≡ (2− 5) (mod 7) d. (128 ·61) ≡ (2 ·5) (mod 7) e. 1282 ≡ 22 (mod 7)

8. Verify the following statements. a. 45 ≡ 3 (mod 6) and 104 ≡ 2 (mod 6) b. (45 + 104) ≡ (3 + 2) (mod 6) c. (45− 104) ≡ (3− 2) (mod 6) d. (45 ·104) ≡ (3 ·2) (mod 6) e. 452 ≡ 32 (mod 6)

In 9–11, prove each of the given statements, assuming that a, b, c, d , and n are integers with n > 1 and that a ≡ c (mod n) and b ≡ d (mod n).

9. a. (a + b) ≡ (c + d) (mod n) b. (a − b) ≡ (c − d) (mod n)

10. a2 ≡ c2 (mod n) 11. am ≡ cm (mod n) for all integers m ≥ 1 (Use mathematical

induction on m.)

12. a. Prove that for all integers n ≥ 0, 10n ≡ 1 (mod 9). b. Use part (a) to prove that a positive integer is divisible

by 9 if, and only if, the sum of its digits is divisible by 9.

13. a. Prove that for all integers n ≥ 1, 10n ≡ (−1)n (mod 11). b. Use part (a) to prove that a positive integer is divisi-

ble by 11 if, and only if, the alternating sum of its dig- its is divisible by 11. (For instance, the alternating sum of the digits of 82,379 is 8− 2 + 3− 7 + 9 = 11 and 82,379 = 11 · 7489.)

14. Use the technique of Example 8.4.4 to find 142 mod 55, 144 mod 55, 148 mod 55, and 1416 mod 55.

15. Use the result of exercise 14 and the technique of Example 8.4.5 to find 1427 mod 55.

In 16–18, use the techniques of Example 8.4.4 and Example 8.4.5 to find the given numbers.

16. 675307 mod 713 17. 89307 mod 713

18. 48307 mod 713

In 19–24, use the RSA cipher from Examples 8.4.9 and 8.4.10. In 19–21, translate the message into its numeric equivalent and encrypt it. In 22–24, decrypt the ciphertext and translate the result into letters of the alphabet to discover the message.

19. HELLO 20. WELCOME 21. EXCELLENT

22. 13 20 20 09 23. 08 05 15 24. 51 14 49 15

25.H Use Theorem 5.2.3 to prove that if a and n are positive inte- gers and an − 1 is prime, then a = 2 and n is prime.

In 26 and 27, use the extended Euclidean algorithm to find the greatest common divisor of the given numbers and express it as a linear combination of the two numbers.

26. 6664 and 765 27. 4158 and 1568

Exercises 28 and 29 refer to the following formal version of the extended Euclidean algorithm.

Algorithm 8.4.1 Extended Euclidean Algorithm [Given integers A and B with A > B > 0, this algorithm com- putes gcd(A, B) and finds integers s and t such that s A + t B = gcd(A, B).]

Input: A, B [integers with A > B > 0]

Algorithm Body: a := A, b := B, s := 1, t := 0, u := 0, v := 1, [pre-condition: a = s A + t B and b = u A + vB] while (b ̸= 0)

[loop invariant: a = s A + t B and b = u A + vB, gcd(a, b) = gcd(A, B)] r := a mod b, q := a div b a := b, b := r newu := s − uq, newv := t − vq s := u, t := v u := newu, v := newv

end while

gcd := a [post-condition: gcd(A, B) = a = s A + t B]

Output: gcd[a positive integer], s, t [integers]

In 28 and 29, for the given values of A and B, make a table showing the value of s, t, and s A + t B before the start of the while loop and after each iteration of the loop.

28. A = 330, B = 156 29. A = 284, B = 168 30. Finish the proof of Theorem 8.4.5 by proving that if a, b

and c are as in the proof, then c | b.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

498 Chapter 8 Relations

31. a. Find an inverse for 210 modulo 13. b. Find a positive inverse for 210 modulo 13. c. Find a positive solution for the congruence 210x ≡ 8

(mod 13).

32. a. Find an inverse for 41 modulo 660. b. Find the least positive solution for the following congru-

ence: 41x ≡ 125 (mod 660). 33.H Use Theorem 8.4.5 to prove that for all integers a, b, and c,

if gcd(a, b) = 1 and a | c and b | c, then ab | c. 34. Give a counterexample to show that the converse of exer-

cise 33 is false.

35. Corollary 8.4.7 guarantees the existence of an inverse mod- ulo n for an integer a when a and n are relatively prime. Use Euclid’s lemma to prove that the inverse is unique mod- ulo n. In other words, show that any two integers whose product with a is congruent to 1 modulo n are congruent to each other modulo n.

In 36, 37, 39, and 40, use the RSA cipher with public key n = 713 = 23 · 31 and e = 43. In 36 and 37, encode the mes- sages into their numeric equivalents and encrypt them. In 39 and 40, decrypt the given ciphertext and find the original messages.

36. HELP 37. COME

38. Find the least positive inverse for 43 modulo 660.

39. 675 089 089 048

40. 028 018 675 129

41.H a. Use mathematical induction and Euclid’s lemma to prove that for all positive integers s, if p and q1, q2, . . . , qs are prime numbers and p | q1q2 · · · qs, then p = qi for some i with 1 ≤ i ≤ s.

b. The uniqueness part of the unique factorization theorem for the integers says that given any integer n, if

n = p1 p2 · · · pr = q1q2 · · · qs for some positive integers r and s and prime numbers p1 ≤ p2 ≤ · · · ≤ pr and q1 ≤ q2 ≤ · · · ≤ qs, then r = s and pi = qi for all integers i with 1 ≤ i ≤ r .

Use the result of part (a) to fill in the details of the following sketch of a proof: Suppose that n is an integer with two different prime factor- izations: n = p1 p2 · · · pt = q1q2 · · · qu . All the prime factors that appear on both sides can be cancelled (as many times as they appear on both sides) to arrive at the situation where p1 p2 · · · pr = q1q2 · · · qs, p1 ≤ p2 ≤ · · · ≤ pr , q1 ≤ q2 ≤ · · · ≤ qs , and pi ̸= q j for any integers i and j . Then use part (a) to deduce a contra- diction, and so the prime factorization of n is unique except, possibly, for the order in which the prime fac- tors are written.

42. According to Fermat’s little theorem, if p is a prime number and a and p are relatively prime, then a p−1 ≡ 1 (mod p). Verify that this theorem gives correct results for a. a = 15 and p = 7 b. a = 8 and p = 11

43. Fermat’s little theorem can be used to show that a number is not prime by finding a number a relatively prime to p with the property that a p−1 ≡/ 1 (mod p). However, it cannot be used to show that a number is prime. Find an example to illustrate this fact. That is, find integers a and p such that a and p are relatively prime and a p−1 ≡ 1 (mod p) but p is not prime.

Answers for Test Yourself 1. three places in the alphabet to the right of the letter, with X wrapped around to A, Y to B, and Z to C 2. a ≡ b (mod n); a = b + kn for some integer k; a and b have the same nonnegative remainder when divided by n; a mod n = b mod n 3. (c + d) (mod n); (c − d) (mod n); (cd) (mod n); cm (mod n) 4. sum of powers of 2 5. version of the Euclidean 6. a linear combination of a and n 7. C = Mc mod pq; M = Cd mod pq; d is a positive inverse for e modulo (p − 1)(q − 1) 8. a | b 9. a p−1 ≡ 1 (mod p) 10. Med mod pq

8.5 Partial Order Relations There is no branch of mathematics, however abstract, which may not some day be applied to phenomena of the real world. — Nicolai Ivanovitch Lobachevsky, 1792–1856

In order to obtain a degree in computer science at a certain university, a student must take a specified set of required courses, some of which must be completed before others can be started. Given the prerequistite structure of the program, one might ask what is the least number of school terms needed to fulfill the degree requirements, or what is the maximum number of courses that can be taken in the same term, or whether there is a sequence in which a part-time student can take the courses one per term. Later in this section, we will show how representing the prerequisite structure of the program as a partial order relation makes it relatively easy to answer such questions.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 499

Antisymmetry In Section 8.2 we defined three properties of relations: reflexivity, symmetry, and transi- tivity. A fourth property of relations is called antisymmetry. In terms of the arrow diagram of a relation, saying that a relation is antisymmetric is the same as saying that whenever there is an arrow going from one element to another distinct element, there is not an arrow going back from the second to the first.

• Definition Let R be a relation on a set A. R is antisymmetric if, and only if,

for all a and b in A, if a R b and b R a then a = b.

By taking the negation of the definition, you can see that a relation R is not antisym- metric if, and only if,

there are elements a and b in A such that a R b and b R a but a ̸= b.

Example 8.5.1 Testing for Antisymmetry of Finite Relations

Let R1 and R2 be the relations on {0, 1, 2} defined as follows: Draw the directed graphs for R1 and R2 and indicate which relations are antisymmetric.

a. R1 = {(0, 2), (1, 2), (2, 0)} b. R2 = {(0, 0), (0, 1), (0, 2), (1, 1), (1, 2)}

Solution

a. R1 is not antisymmetric.

0 1

2

Since 0 R1 2 and 2 R1 0 but 0 " 2, R1 is not antisymmetric.

b. R2 is antisymmetric.

In order for R2 not to be antisymmetric, there would have to exist a pair of distinct elements of A such that each is related to the other by R2 . But you can see by inspection that no such pair exists.

0 1

2 ■

Example 8.5.2 Testing for Antisymmetry of “Divides” Relations

Let R1 be the “divides” relation on the set of all positive integers, and let R2 be the “divides” relation on the set of all integers.

For all a, b ∈ Z+, a R1 b ⇔ a | b. For all a, b ∈ Z , a R2 b ⇔ a | b.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

500 Chapter 8 Relations

a. Is R1 antisymmetric? Prove or give a counterexample.

b. Is R2 antisymmetric? Prove or give a counterexample.

Solution

a. R1 is antisymmetric.

Proof: Suppose a and b are positive integers such that a R1 b and b R1 a. [We must show that a = b.] By definition of R1, a | b and b | a. Thus, by definition of divides, there are integers k1 and k2 with b = k1a and a = k2b. It follows that

b = k1a = k1(k2b) = (k1k2)b. Dividing both sides by b gives

k1k2 = 1. Now since a and b are both integers k1 and k2 are both positive integers also. But the only product of two positive integers that equals 1 is 1 · 1. Thus

k1 = k2 = 1

and so a = k2b = 1 · b = b. [This is what was to be shown.]

b. R2 is not antisymmetric.

Counterexample: Let a = 2 and b = −2. Then a | b [since−2 = (−1) · 2] and b | a [since 2 = (−1)(−2)]. Hence a R2 b and b R2 a but a ̸= b. ■

Example 8.5.2 illustrates the fact that a relation may be antisymmetric on a subset of a set but not antisymmetric on the set itself.

Partial Order Relations A relation that is reflexive, antisymmetric, and transitive is called a partial order.

• Definition Let R be a relation defined on a set A. R is a partial order relation if, and only if, R is reflexive, antisymmetric, and transitive.

Two fundamental partial order relations are the “less than or equal to” relation on a set of real numbers and the “subset” relation on a set of sets. These can be thought of as models, or paradigms, for general partial order relations.

Example 8.5.3 The “Subset” Relation

Let A be any collection of sets and define the “subset” relation, ⊆, on A as follows: For all U, V ∈ A ,

U ⊆ V ⇔ for all x , if x ∈ U then x ∈ V .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 501

By an argument almost identical to that of the solution for exercise 23 of Section 8.2, ⊆ is reflexive and transitive. Finish the proof that ⊆ is a partial order relation by proving that ⊆ is antisymmetric.

Solution For ⊆ to be antisymmetric means that for all sets U and V in A if U ⊆ V and V ⊆ U then U = V . But this is true by definition of equality of sets. ■

Example 8.5.4 A “Divides” Relation on a Set of Positive Integers

Let | be the “divides” relation on a set A of positive integers. That is, for all a, b ∈ A,

a | b ⇔ b = ka for some integer k.

Prove that | is a partial order relation on A.

Solution

| is reflexive: [We must show that for all a ∈ A, a | a.] Suppose a ∈ A. Then a = 1 · a, so a | a by definition of divisibility. | is antisymmetric: [We must show that for all a, b ∈ A, if a | b and b | a then a = b.] The proof of this is virtually identical to that of Example 8.5.2(a).

| is transitive: To show transitivity means to show that for all a, b, c ∈ A, if a | b and b | c then a | c. But this was proved as Theorem 4.3.3.

Since | is reflexive, antisymmetric, and transitive, | is a partial order relation on A. ■

Example 8.5.5 The “Less Than or Equal to” Relation

Let S be a set of real numbers and define the “less than or equal to” relation, ≤, on S as follows: For all real numbers x and y in S,

x ≤ y ⇔ x < y or x = y.

Show that ≤ is a partial order relation.

Solution

≤ is reflexive: For ≤ to be reflexive means that x ≤ x for all real numbers x in S. But x ≤ x means that x < x or x = x , and x = x is always true. ≤ is antisymmetric: For ≤ to be antisymmetric means that for all real numbers x and y in S, if x ≤ y and y ≤ x then x = y. This follows immediately from the definition of ≤ and the trichotomy property (see Appendix A, T17), which says that given any real numbers, x and y, exactly one of the following holds: x < y or x = y or x > y. ≤ is transitive: For ≤ to be transitive means that for all real numbers x, y, and z in S if x ≤ y and y ≤ z then x ≤ z. This follows from the definition of ≤ and the transitivity property of order (see Appendix A, T18), which says that given any real numbers x, y, and z, if x < y and y < z then x < z.

Because ≤ is reflexive, antisymmetric, and transitive, it is a partial order relation. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

502 Chapter 8 Relations

• Notation Because of the special paradigmatic role played by the ≤ relation in the study of partial order relations, the symbol ≼ is often used to refer to a general partial order relation, and the notation x ≼ y is read “x is less than or equal to y” or “y is greater than or equal to x .”

Lexicographic Order To figure out which of two words comes first in an English dictionary, you compare their letters one by one from left to right. If all letters have been the same to a certain point and one word runs out of letters, that word comes first in the dictionary. For example, play comes before playhouse. If all letters up to a certain point are the same and the next letters differ, then the word whose next letter is located earlier in the alphabet comes first in the dictionary. For instance, playhouse comes before playmate.

More generally, if A is any set with a partial order relation, then a dictionary or lexicographic order can be defined on a set of strings over A as indicated in the following theorem.

Theorem 8.5.1

Let A be a set with a partial order relation R, and let S be a set of strings over A. Define a relation ≼ on S as follows: For any two strings in S, a1a2 · · · am and b1b2 · · · bn , where m and n are positive integers,

1. If m ≤ n and ai = bi for all i = 1, 2, . . . , m, then a1a2 · · · am ≼ b1b2 · · · bn.

2. If for some integer k with k ≤ m, k ≤ n, and k ≥ 1, ai = bi for all i = 1, 2, . . . , k − 1, and ak ̸= bk , but ak R bk then

a1a2 · · · am ≼ b1b2 · · · bn. 3. If ε is the null string and s is any string in S, then ϵ ≼ s. If no strings are related other than by these three conditions, then ≼ is a partial order relation.

The proof of Theorem 8.5.1 is technical but straightforward. It is left for the exercises.

• Definition The partial order relation of Theorem 8.5.1 is called the lexicographic order for S that corresponds to the partial order R on A.

Example 8.5.6 A Lexicographic Order

Let A = {x, y} and let R be the following partial order relation on A: R = {(x, x), (x, y), (y, y)}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 503

Let S be the set of all strings over A, and denote by ≼ the lexicographic order for S that corresponds to R.

a. Is x ≼ xx? x ≼ xy? xx ≼ xxx? yxy ≼ yxyxxx? b. Is x ≼ y? xx ≼ xyx? xxxy ≼ xy? yxyxxyy ≼ yxyxy? c. Is ϵ ≼ x? ϵ ≼ xy? ϵ ≼ yyxy?

Solution

a. Yes in all cases, by property (1) of the definition of ≼. b. Yes in all cases, by property (2) of the definition of ≼. c. Yes in all cases, by property (3) of the definition of ≼. ■

Hasse Diagrams Let A = {1, 2, 3, 9, 18} and consider the “divides” relation on A: For all a, b ∈ A,

a | b ⇔ b = ka for some integer k.

The directed graph of this relation has the following appearance:

18

9

3

1

2

Note that there is a loop at every vertex, all other arrows point in the same direction (upward), and any time there is an arrow from one point to a second and from the second point to a third, there is an arrow from the first point to the third. Given any partial order relation defined on a finite set, it is possible to draw the directed graph in such a way that all of these properties are satisfied. This makes it possible to associate a somewhat simpler graph, called a Hasse diagram (after Helmut Hasse, a twentieth-century German number theorist), with a partial order relation defined on a finite set. To obtain a Hasse diagram, proceed as follows:

Start with a directed graph of the relation, placing vertices on the page so that all arrows point upward. Then eliminate

1. the loops at all the vertices,

2. all arrows whose existence is implied by the transitive property,

3. the direction indicators on the arrows.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

504 Chapter 8 Relations

For the relation given previously, the Hasse diagram is as follows:

2

1

3

9

18

Example 8.5.7 Constructing a Hasse Diagram

Consider the “subset” relation, ⊆, on the set P({a, b, c}). That is, for all sets U and V in P({a, b, c}),

U ⊆ V ⇔ ∀x, if x ∈ U then x ∈ V .

Construct the Hasse diagram for this relation.

Solution Draw the directed graph of the relation in such a way that all arrows except loops point upward.

{c}{b}{a}

{a, b, c}

{a, c}

{b, c}{a, b}

Then strip away all loops, unnecessary arrows, and direction indicators to obtain the Hasse diagram.

{c}

{b}

{a}

{a, b}

{a, b, c}

{a, c} {b, c}

∅ ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 505

To recover the directed graph of a relation from the Hasse diagram, just reverse the instructions given previously, using the knowledge that the original directed graph was sketched so that all arrows pointed upward:

1. Reinsert the direction markers on the arrows making all arrows point upward.

2. Add loops at each vertex.

3. For each sequence of arrows from one point to a second and from that second point to a third, add an arrow from the first point to the third.

Example 8.5.8 Obtaining the Directed Graph of a Partial Order Relation from the Hasse Diagram of the Relation

A partial order relation R has the following Hasse diagram. Find the directed graph of R.

a

d

f

g

e

c b

Solution

a

d

b

e

c

f

g

Partially and Totally Ordered Sets Given any two real numbers x and y, either x ≤ y or y ≤ x . In a situation like this, the elements x and y are said to be comparable. On the other hand, given two subsets A and B of {a, b, c}, it may be the case that neither A ⊆ B nor B ⊆ A. For instance, let A = {a, b} and B = {b, c}. Then A ! B and B ! A. In such a case, A and B are said to be noncomparable.

• Definition Suppose ≼ is a partial order relation on a set A. Elements a and b of A are said to be comparable if, and only if, either a ≼ b or b ≼ a. Otherwise, a and b are called noncomparable.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

506 Chapter 8 Relations

When all the elements of a partial order relation are comparable, the relation is called a total order.

• Definition If R is a partial order relation on a set A, and for any two elements a and b in A either a R b or b R a, then R is a total order relation on A.

Both the “less than or equal to” relation on sets of real numbers and the lexicographic order of the set of words in a dictionary are total order relations. Note that the Hasse diagram for a total order relation can be drawn as a single vertical “chain.”

Many important partial order relations have elements that are not comparable and are, therefore, not total order relations. For instance, the subset relation on P({a, b, c}) is not a total order relation because, as shown previously, the subsets {a, b} and {a, c} of {a, b, c} are not comparable. In addition, a “divides” relation is not a total order relation unless the elements are all powers of a single integer. (See exercise 21 at the end of this section.)

A set A is called a partially ordered set (or poset) with respect to a relation ≼ if, and only if, ≼ is a partial order relation on A. For instance, the set of real numbers is a partially ordered set with respect to the “less than or equal to” relation≤, and a set of sets is partially ordered with respect to the “subset” relation ⊆. It is entirely straightforward to show that any subset of a partially ordered set is partially ordered. (See exercise 35 at the end of this section.) This, of course, assumes the “same definition” for the relation on the subset as for the set as a whole. A set A is called a totally ordered set with respect to a relation ≼ if, and only if, A is partially ordered with respect to ≼ and ≼ is a total order.

A set that is partially ordered but not totally ordered may have totally ordered subsets. Such subsets are called chains.

• Definition Let A be a set that is partially ordered with respect to a relation ≼. A subset B of A is called a chain if, and only if, the elements in each pair of elements in B is comparable. In other words, a ≼ b or b ≼ a for all a and b in A. The length of a chain is one less than the number of elements in the chain.

Observe that if B is a chain in A, then B is a totally ordered set with respect to the “restriction” of ≼ to B.

Example 8.5.9 A Chain of Subsets

The set P({a, b, c}) is partially ordered with respect to the subset relation. Find a chain of length 3 in P({a, b, c}).

Solution Since ∅ ⊆ {a} ⊆ {a, b, } ⊆ {a, b, c}, the set S = {∅, {a}, {a, b}, {a, b, c}}

is a chain of length 3 in P({a, b, c}). ■

In exercise 39 at the end of this section, you are asked to show that a set that is partially ordered with respect to a relation ≼ is totally ordered with respect to ≼ if, and only if, it is a chain.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 507

A maximal element in a partially ordered set is an element that is greater than or equal to every element to which it is comparable. (There may be many elements to which it is not comparable.) A greatest element in a partially ordered set is an element that is greater than or equal to every element in the set (so it is comparable to every element in the set). Minimal and least elements are defined similarly.

• Definition Let a set A be partially ordered with respect to a relation ≼. 1. An element a in A is called a maximal element of A if, and only if, for all b in

A, either b ≼ a or b and a are not comparable. 2. An element a in A is called a greatest element of A if, and only if, for all b in

A, b ≼ a. 3. An element a in A is called a minimal element of A if, and only if, for all b in

A, either a ≼ b or b and a are not comparable. 4. An element a in A is called a least element of A if, and only if, for all b in

A, a ≼ b.

A greatest element is maximal, but a maximal element need not be a greatest element. However, every finite subset of a totally ordered set has both a least element and a greatest element. (See exercise 40 at the end of the section.) Similarly, a least element is minimal, but a minimal element need not be a least element. Furthermore, a set that is partially ordered with respect to a relation can have at most one greatest element and one least element (see exercise 42 at the end of the section), but it may have more than one maximal or minimal element. The next example illustrates some of these facts.

Example 8.5.10 Maximal, Minimal, Greatest, and Least Elements

Let A = {a, b, c, d, e, f, g, h, i} have the partial ordering ≼ defined by the following Hasse diagram. Find all maximal, minimal, greatest, and least elements of A.

a

b

c d

e

f

g

h

i

Solution There is just one maximal element, g, which is also the greatest element. The minimal elements are c, d, and i , and there is no least element. ■

Topological Sorting Is it possible to input the sets of P({a, b, c}) into a computer in a way that is compatible with the subset relation ⊆ in the sense that if set U is a subset of set V , then U is input before V ? The answer, as it turns out, is yes. For instance, the following input order satisfies the given condition:

∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

508 Chapter 8 Relations

Another input order that satisfies the condition is

∅, {a}, {b}, {a, b}, {c}, {b, c}, {a, c}, {a, b, c}.

• Definition Given partial order relations ≼ and ≼′ on a set A,≼′ is compatible with ≼ if, and only if, for all a and b in A, if a ≼ b then a ≼′ b.

Given an arbitrary partial order relation ≼ on a set A, is there a total order ≼′ on A that is compatible with≼? If the set on which the partial order is defined is finite, then the answer is yes. A total order that is compatible with a given order is called a topological sorting.

• Definition Given partial order relations ≼ and ≼′ on a set A,≼′ is a topological sorting for ≼ if, and only if, ≼′ is a total order that is compatible with ≼.

The construction of a topological sorting for a general finite partially ordered set is based on the fact that any partially ordered set that is finite and nonempty has a minimal element. (See exercise 41 at the end of the section.) To create a total order for a partially ordered set, simply pick any minimal element and make it number one. Then consider the set obtained when this element is removed. Since the new set is a subset of a partially ordered set, it is partially ordered. If it is empty, stop the process. If not, pick a minimal element from it and call that element number two. Then consider the set obtained when this element also is removed. If this set is empty, stop the process. If not, pick a minimal element and call it number three. Continue in this way until all the elements of the set have been used up.

Here is a somewhat more formal version of the algorithm:

Constructing a Topological Sorting

Let≼ be a partial order relation on a nonempty finite set A. To construct a topological sorting,

1. Pick any minimal element x in A. [Such an element exists since A is nonempty.]

2. Set A′ := A − {x}. 3. Repeat steps a–c while A′ ̸= ∅.

a. Pick any minimal element y in A′. b. Define x ≼′ y. c. Set A′ := A′ − {y} and x := y. [Completion of steps 1–3 of this algorithm gives enough information to construct the Hasse diagram for the total ordering≼′. We have already shown how to use the Hasse diagram to obtain a complete directed graph for a relation.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 509

Example 8.5.11 A Topological Sorting

Consider the set A = {2, 3, 4, 6, 18, 24} ordered by the “divides” relation |. The Hasse diagram of this relation is the following:

24

4

2

18

6

3

The ordinary “less than or equal to” relation ≤ on this set is a topological sorting for it since for positive integers a and b, if a | b then a ≤ b. Find another topological sorting for this set.

Solution The set has two minimal elements: 2 and 3. Either one may be chosen; say you pick 3. The beginning of the total order is

total order: 3.

Set A′ = A − {3}. You can indicate this by removing 3 from the Hasse diagram as shown below.

24

4

18

6

2

Next choose minimal element from A′ − {3}. Only 2 is minimal, so you must pick it. The total order thus far is

total order: 3 ≼ 2. Set A′ = (A − {3})− {2} = A − {3, 2}. You can indicate this by removing 2 from the Hasse diagram, as is shown below.

24

4

18

6

Choose a minimal element from A′ − {3, 2}. Again you have two choices: 4 and 6. Say you pick 6. The total order for the elements chosen thus far is

total order: 3 ≼ 2 ≼ 6. You continue in this way until every element of A has been picked. One possible sequence of choices gives

total order: 3 ≼ 2 ≼ 6 ≼ 18 ≼ 4 ≼ 24. You can verify that this order is compatible with the “divides” partial order by checking that for each pair of elements a and b in A such that a | b, then a ≼ b. Note that it is not the case that if a ≼ b then a | b. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

510 Chapter 8 Relations

An Application To return to the example that introduced this section, note that the following defines a partial order relation on the set of courses required for a university degree: For all required courses x and y,

x ≼ y ⇔ x = y or x is a prerequisite for y If the Hasse diagram for the relation is drawn, then the questions raised at the beginning of this section can be answered easily. For instance, consider the Hasse diagram for the requirements at a particular university, which is shown in Figure 8.5.1.

CS 390

CS 360

CS 300

CS 225

CS 250

CS 340

CS 345

CS 301

CS 230

CS 200

CS 155

CS 150

CS 350

MA 140

MA 141

Figure 8.5.1

The minimum number of school terms needed to complete the requirements is the size of a longest chain, which is 7 (150, 155, 225, 300, 340, 360, 390, for example). The maximum number of courses that could be taken in the same term (assuming the uni- versity allows it) is the maximum number of noncomparable courses, which is 6 (350, 360, 345, 301, 230, 200, for example). A part-time student could take the courses in a sequence determined by constructing a topological sorting for the set. (One such sorting is 140, 150, 141, 155, 200, 225, 230, 300, 250, 301, 340, 345, 350, 360, 390. There are many others.)

PERT and CPM Two important and widely used applications of partial order relations are PERT (Program Evaluation and Review Technique) and CPM (Critical Path Method). These techniques came into being in the 1950s as planners came to grips with the complexities of schedul- ing the individual activities needed to complete very large projects, and although they are very similar, their developments were independent. PERT was developed by the U.S. Navy to help organize the construction of the Polaris submarine, and CPM was developed by the E. I. Du Pont de Nemours company for scheduling chemical plant maintenance. Here is a somewhat simplified example of the way the techniques work.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 511

Example 8.5.12 A Job Scheduling Problem

At an automobile assembly plant, the job of assembling an automobile can be broken down into these tasks:

1. Build frame.

2. Install engine, power train components, gas tank.

3. Install brakes, wheels, tires.

4. Install dashboard, floor, seats.

5. Install electrical lines.

6. Install gas lines.

7. Install brake lines.

8. Attach body panels to frame.

9. Paint body.

Certain of these tasks can be carried out at the same time, whereas some cannot be started until other tasks are finished. Table 8.5.1 summarizes the order in which tasks can be performed and the time required to perform each task.

Table 8.5.1

Time Needed to Task Immediately Preceding Tasks Perform Task

1 7 hours 2 1 6 hours 3 1 3 hours 4 2 6 hours 5 2, 3 3 hours 6 4 1 hour 7 2, 3 1 hour 8 4, 5 2 hours 9 6, 7, 8 5 hours

Let T be the set of all tasks, and consider the partial order relation ≼ defined on T as follows: For all tasks x and y in T ,

x ≼ y ⇔ x = y or x precedes y.

If the Hasse diagram of this relation is turned sideways (as is customary in PERT and CPM analysis), it has the appearance shown below.

Task 4 6 hours Task 6

1 hour

Task 8 2 hours Task 9

5 hours Task 1 7 hours

Task 5 3 hours

Task 2 6 hours

Task 7 1 hour

Task 3 3 hours

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

512 Chapter 8 Relations

What is the minimum time required to assemble a car? You can determine this by working from left to right across the diagram, noting for each task (say, just above the box representing that task) the minimum time needed to complete that task starting from the beginning of the assembly process. For instance, you can put a 7 above the box for task 1 because task 1 requires 7 hours. Task 2 requires completion of task 1 (7 hours) plus 6 hours for itself, so the minimum time required to complete task 2, starting at the beginning of the assembly process, is 7 + 6 = 13 hours. You can put a 13 above the box for task 2. Similarly, you can put a 10 above the box for task 3 because 7 + 3 = 10. Now consider what number you should write above the box for task 5. The minimum times to complete tasks 2 and 3, starting from the beginning of the assembly process, are 13 and 10 hours respectively. Since both tasks must be completed before task 5 can be started, the minimum time to complete task 5, starting from the beginning, is the time needed for task 5 itself (3 hours) plus the maximum of the times to complete tasks 2 and 3 (13 hours), and this equals 3 + 13 = 16 hours. Thus you should place the number 16 above the box for task 5. The same reasoning leads you to place a 14 above the box for task 7. Similarly, you can place a 19 above the box for task 4, a 20 above the box for task 6, a 21 above the box for task 8, and a 26 above the box for task 9, as shown below.

Task 4 6 hours Task 6

1 hour

Task 8 2 hours Task 9

5 hours Task 1 7 hours

Task 5 3 hours

Task 2 6 hours

Task 7 1 hour

Task 3 3 hours

7

10

13 16

14

19 20

21 26

This analysis shows that at least 26 hours are required to complete task 9 starting from the beginning of the assembly process. When task 9 is finished, the assembly is complete, so 26 hours is the minimum time needed to accomplish the whole process.

Note that the minimum time required to complete tasks 1, 2, 4, 8, and 9 in sequence is exactly 26 hours. This means that a delay in performing any one of these tasks causes a delay in the total time required for assembly of the car. For this reason, the path through tasks 1, 2, 4, 8, and 9 is called a critical path. ■

Test Yourself 1. For a relation R on a set A to be antisymmetric means that

_____.

2. To show that a relation R on an infinite set A is antisymmet- ric, you suppose that _____ and you show that _____.

3. To show that a relation R on a set A is not antisymmetric, you _____.

4. To construct a Hasse diagram for a partial order relation, you start with a directed graph of the relation in which all arrows point upward and you eliminate _____, _____, and _____.

5. If A is a set that is partially ordered with respect to a relation ≼ and if a and b are elements of A, we say that a and b are comparable if, and only if, _____ or _____.

6. A relation≼ on a set A is a total order if, and only if, _____. 7. If A is a set that is partially ordered with respect to a relation ≼, and if B is a subset of A, then B is a chain if, and only if, for all a and b in B, _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 513

8. Let A be a set that is partially ordered with respect to a rela- tion ≼, and let a be an element of +. (a) a is maximal if, and only if, _____.

(b) a is a greatest element of A if, and only if, _____.

(c) a is minimal if, and only if, _____.

(d) a is a least element of A if, and only if, _____.

9. Given a set A that is partially ordered with respect to a rela- tion ≼, the relation ≼′ is a topological sorting for ≼, if, and only if, ≼′ is a _____ and for all a and b in A if a ≼ b then _____.

10. PERT and CPM are used to produce efficient _____.

Exercise Set 8.5 1. Each of the following is a relation on {0, 1, 2, 3}. Draw

directed graphs for each relation, and indicate which rela- tions are antisymmetric. a. R1 = {(0, 0), (0, 2), (1, 0), (1, 3), (2, 2), (3, 0), (3, 1)} b. R2 = {(0, 1), (0, 2), (1, 1), (1, 2), (1, 3), (2, 2), (3, 2)} c. R3 = {(0, 0), (0, 3), (1, 0), (1, 3), (2, 2), (3, 3), (3, 2)} d. R4 = {(0, 0), (1, 0), (1, 2), (1, 3), (2, 0), (2, 1), (3, 2),

(3, 0)} 2. Let P be the set of all people in the world and define a

relation R on P as follows: For all x, y ∈ P , x R y ⇔ x is no older than y.

Is R antisymmetric? Prove or give a counterexample.

3. Let S be the set of all strings of a’s and b’s. Define a relation R on S as follows: For all t ∈ S,

s R t ⇔ l(s) ≤ l(t), where l(x) denotes the length of a string x . Is R antisym- metric? Prove or give a counterexample.

4. Let R be the “less than” relation on the set R of all real numbers: For all x, y ∈ R,

x R y ⇔ x < y. Is R antisymmetric? Prove or give a counterexample.

5. Let R be the set of all real numbers and define a relation R on R× R as follows: For all (a, b) and (c, d) in R× R,

(a, b) R (c, d) ⇔ either a < c or both a = c and b ≤ d.

Is R a partial order relation? Prove or give a counter- example.

6. Let P be the set of all people who have ever lived and define a relation R on P as follows: For all r, s ∈ P ,

r R s ⇔ r is an ancestor of s or r = s. Is R a partial order relation? Prove or give a counter- example.

7. Define a relation R on the set Z of all integers as follows: For all m, n ∈ Z,

m R n ⇔ every prime factor of m is a prime factor of n.

Is R a partial order relation? Prove or give a counter- example.

8. Define a relation R on the set Z of all integers as follows: For all m, n ∈ Z,

m R n ⇔ m + n is even. Is R a partial order relation? Prove or give a counter- example.

9. Define a relation R on the set of all real numbers R as follows: For all x, y ∈ R,

x R y ⇔ x2 ≤ y2. Is R a partial order relation? Prove or give a counter- example.

10. Suppose R and S are antisymmetric relations on a set A. Must R ∪ S also be antisymmetric? Explain.

11. Let A = {a, b}, and suppose A has the partial order rela- tion R where R = {(a, a), (a, b), (b, b)}. Let S be the set of all strings in a’s and b’s and let ≼ be the corresponding lexicographic order on S. Indicate which of the following statements are true, and for each true statement cite as a reason part (1), (2), or (3) of the definition of lexicographic order given in Theorem 8.5.1. a. aab ≼ aaba b. bbab ≼ bba c. ϵ ≼ aba d. aba ≼ abb e. bbab ≼ bbaa f. ababa ≼ ababaa g. bbaba ≼ bbabb

12. Prove Theorem 8.5.1.

13. Let A = {a, b}. Describe all partial order relations on A. 14. Let A = {a, b, c}.

a. Describe all partial order relations on A for which a is a maximal element.

b. Describe all partial order relations on A for which a is a minimal element.

15.H Suppose a relation R on a set A is reflexive, symmetric, transitive, and antisymmetric. What can you conclude about R? Prove your answer.

16. Consider the “divides” relation on each of the following sets A. Draw the Hasse diagram for each relation. a. A = {1, 2, 4, 5, 10, 15, 20} b. A = {2, 3, 4, 6, 8, 9, 12, 18}

17. Consider the “subset” relation on P(S) for each of the fol- lowing sets S. Draw the Hasse diagram for each relation. a. S = {0, 1} b. S = {0, 1, 2}

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

514 Chapter 8 Relations

18. Let S = {0, 1} and consider the partial order relation R defined on S × S as follows: For all ordered pairs (a, b) and (c, d) in S × S, (a, b) R (c, d) ⇔ either a < c or both a = c and b ≤ d, where < denotes the usual “less than” and ≤ denotes the usual “less than or equal to” relation for real numbers. Draw the Hasse diagram for R.

19. Let S = {0, 1} and consider the partial order relation R defined on S × S as follows: For all ordered pairs (a, b) and (c, d) in S × S,

(a, b) R (c, d) ⇔ a ≤ c and b ≤ d, where ≤ denotes the usual “less than or equal to” relation

for real numbers. Draw the Hasse diagram for R.

20. Let S = {0, 1} and consider the partial order relation R defined on S × S × S as follows: For all ordered triples (a, b, c) and (d, e, f ) in S × S × S,

(a, b, c) R (d, e, f ) ⇔ a ≤ d, b ≤ e, and c ≤ f, where ≤ denotes the usual “less than or equal to” relation for real numbers. Draw the Hasse diagram for R.

21. Consider the “divides” relation defined on the set A={1, 2, 22, 23, . . . , 2n}, where n is a nonnegative integer. a. Prove that this relation is a total order relation on A. b. Draw the Hasse diagram for this relation for n = 4.

In 22–29, find all greatest, least, maximal, and minimal ele- ments for the relations in each of the referenced exercises.

22. Exercise 16(a) 23. Exercise 16(b)

24. Exercise 17(a) 25. Exercise 17(b)

26. Exercise 18 27. Exercise 19

28. Exercise 20 29. Exercise 21

30. Each of the following sets is partially ordered with respect to the “less than or equal to” relation, ≤, for real numbers. In each case, determine whether the set has a greatest or least element. a. R b. {x ∈ R | 0 ≤ x ≤ 1} c. {x ∈ R | 0 < x < 1} d. {x ∈ Z | 0 < x < 10}

31. Let A = {a, b, c, d}, and let R be the relation

R = {(a, a), (b, b), (c, c), (d, d), (c, a), (a, d), (c, d), (b, c), (b, d), (b, a)}.

Is R a total order on A? Justify your answer.

32. Let A = {a, b, c, d}, and let R be the relation

R = {(a, a), (b, b), (c, c), (d, d), (c, b), (a, d), (b, a), (b, d), (c, d), (c, a)}.

Is R a total order on A? Justify your answer.

33. Consider the set A = {12, 24, 48, 3, 9} ordered by the “divides” relation. Is A totally ordered with respect to the relation? Justify your answer.

34.H Suppose that R is a partial order relation on a set A and that B is a subset of A. The restriction of R to B is defined as follows:

The restriction of R to B

= {(x, y) | x ∈ B, y ∈ B, and (x, y) ∈ R}.

In other words, two elements of B are related by the restric- tion of R to B if, and only if, they are related by R. Prove that the restriction of R to B is a partial order relation on B. (In less formal language, this says that a subset of a partially ordered set is partially ordered.)

35. The set P({w, x, y, z}) is partially ordered with respect to the “subset” relation ⊆. Find a chain of length 4 in P({w, x, y, z}).

36. The set A = {2, 4, 3, 6, 12, 18, 24} is partially ordered with respect to the “divides” relation. Find a chain of length 3 in A.

37. Find a chain of length 2 for the relation defined in exercise 19.

38. Prove that a partially ordered set is totally ordered if, and only if, it is a chain.

39. Suppose that A is a totally ordered set. Use mathematical induction to prove that for any integer n ≥ 1, every subset of A with n elements has both a least element and a greatest element.

40. Prove that a nonempty finite partially ordered set has a. at least one minimal element, b. at least one maximal element.

41. Prove that a finite partially ordered set has a. at most one greatest element, b. at most one least element.

42. Draw a Hasse diagram for a partially ordered set that has two maximal elements and two minimal elements and is such that each element is comparable to exactly two other elements.

43. Draw a Hasse diagram for a partially ordered set that has three maximal elements and three minimal elements and is such that each element is either greater than or less than exactly two other elements.

44. Use the algorithm given in the text to find a topological sort- ing for the relation of exercise 16(a) that is different from the “less than or equal to” relation ≤.

45. Use the algorithm given in the text to find a topological sort- ing for the relation of exercise 16(b) that is different from the “less than or equal to” relation ≤.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

8.5 Partial Order Relations 515

46. Use the algorithm given in the text to find a topological sorting for the relation of exercise 19.

47. Use the algorithm given in the text to find a topological sorting for the relation of exercise 20.

48. Use the algorithm given in the text to find a topological sorting for the “subset” relation on P({a, b, c, d}).

49. Refer to the prerequisite structure shown in Figure 8.5.1. a. Find a list of six noncomparable courses that is different

from the list given in the text. b. Find two topological sortings that are different from the

one given in the text.

50. A set S of jobs can be ordered by writing x ≼ y to mean that either x = y or x must be done before y, for all x and y in S. The following is a Hasse diagram for this relation for a particular set S of jobs.

3

7

10 6

91 2

8

5

4

a. If one person is to perform all the jobs, one after another, find an order in which the jobs can be done.

b. Suppose enough people are available to perform any number of jobs simultaneously. (i) If each job requires one day to perform, what is the

least number of days needed to perform all ten jobs? (ii) What is the maximum number of jobs that can be

performed at the same time?

51. Suppose the tasks described in Example 8.5.12 require the following performance times:

Time Needed to Task Perform Task

1 9 hours 2 7 hours 3 4 hours 4 5 hours 5 7 hours 6 3 hours 7 2 hours 8 4 hours 9 6 hours

a. What is the minimum time required to assemble a car? b. Find a critical path for the assembly process.

Answers for Test Yourself 1. for all a and b in A, if a R b and b R a then a = b 2. a and b are any elements of A with a R b and b R a; a = b 3. show that there are elements a and b in A such that a R b and b R a and a ̸= b 4. all loops; all arrows whose existence is implied by the transitive property; the direction indicators on the arrows 5. a ≼ b; b ≼ a 6. for any two elements a and b in A, either a ≼ b or b ≼ a 7. a and b are comparable 8. (a) for all b in A either b ≼ a or b and a are not comparable (b) for all b in A, b ≼ a (c) for all b in A either a ≼ b or b and a are not comparable (d) for all b in A, a ≼′ b 9. total order; a ≼′ b 10. scheduling of tasks

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

516

CHAPTER 9

COUNTING AND PROBABILITY

“It’s as easy as 1–2–3.” That’s the saying. And in certain ways, counting is easy. But other aspects of counting

aren’t so simple. Have you ever agreed to meet a friend “in three days” and then realized that you and your friend might mean different things? For example, on the European continent, to meet in eight days means to meet on the same day as today one week hence; on the other hand, in English-speaking countries, to meet in seven days means to meet one week hence. The difference is that on the continent, all days including the first and the last are counted. In the English-speaking world, it’s the number of 24-hour periods that are counted.

Continental countries 1 2 3 4 5 6 7 8 ↕ ↕ ↕ ↕ ↓ ↕ ↕ ↕

Sun Mon Tue Wed Thu Fri Sat Sun︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸ English-speaking countries 1 2 3 4 5 6 7

The English convention for counting days follows the almost universal convention for counting hours. If it is 9 A.M. and two people anywhere in the world agree to meet in three hours, they mean that they will get back together again at 12 noon.

Musical intervals, on the other hand, are universally reckoned the way the Conti- nentals count the days of a week. An interval of a third consists of two tones with a single tone in between, and an interval of a second consists of two adjacent tones. (See Figure 9.1.1.)

C E C D

Interval of a third Interval of a second

Figure 9.1.1

Of course, the complicating factor in all these examples is not how to count but rather what to count. And, indeed, in the more complex mathematical counting problems dis- cussed in this chapter, it is what to count that is the central issue. Once one knows exactly what to count, the counting itself is as easy as 1–2–3.

R ep

rin te

d by

pe rm

is si

on of

U FS

,I nc

.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.1 Introduction 517

9.1 Introduction Imagine tossing two coins and observing whether 0, 1, or 2 heads are obtained. It would be natural to guess that each of these events occurs about one-third of the time, but in fact this is not the case. Table 9.1.1 below shows actual data obtained from tossing two quarters 50 times.

Table 9.1.1 Experimental Data Obtained from Tossing Two Quarters 50 Times

Frequency Relative Frequency (Number of times (Fraction of times

Event Tally the event occurred) the event occurred)

2 heads obtained |||| |||| | 11 22% 1 head obtained |||| |||| |||| |||| |||| || 27 54% 0 heads obtained |||| |||| || 12 24%

As you can see, the relative frequency of obtaining exactly 1 head was roughly twice as great as that of obtaining either 2 heads or 0 heads. It turns out that the mathematical theory of probability can be used to predict that a result like this will almost always occur. To see how, call the two coins A and B, and suppose that each is perfectly balanced. Then each has an equal chance of coming up heads or tails, and when the two are tossed together, the four outcomes pictured in Figure 9.1.2 are all equally likely.

A B A B A B A B

2 heads obtained 1 head obtained 0 heads obtained

Figure 9.1.2 Equally Likely Outcomes from Tossing Two Balanced Coins

Figure 9.1.2 shows that there is a 1 in 4 chance of obtaining two heads and a 1 in 4 chance of obtaining no heads. The chance of obtaining one head, however, is 2 in 4 because either A could come up heads and B tails or B could come up heads and A tails. So if you repeatedly toss two balanced coins and record the number of heads, you should expect relative frequencies similar to those shown in Table 9.1.1.

To formalize this analysis and extend it to more complex situations, we introduce the notions of random process, sample space, event and probability. To say that a process is random means that when it takes place, one outcome from some set of outcomes is sure to occur, but it is impossible to predict with certainty which outcome that will be. For instance, if an ordinary person performs the experiment of tossing an ordinary coin into the air and allowing it to fall flat on the ground, it can be predicted with certainty that the coin will land either heads up or tails up (so the set of outcomes can be denoted {heads, tails}), but it is not known for sure whether heads or tails will occur. We restricted this experiment to ordinary people because a skilled magician can toss a coin in a way that appears random but is not, and a physicist equipped with first-rate measuring devices may be able to analyze all the forces on the coin and correctly predict its landing position. Just a few of many examples of random processes or experiments are choosing winners in state lotteries, selecting respondents in public opinion polls, and choosing subjects to receive treatments or serve as controls in medical experiments. The set of outcomes that can result from a random process or experiment is called a sample space.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

518 Chapter 9 Counting and Probability

• Definition A sample space is the set of all possible outcomes of a random process or experiment. An event is a subset of a sample space.

In case an experiment has finitely many outcomes and all outcomes are equally likely to occur, the probability of an event (set of outcomes) is just the ratio of the number of outcomes in the event to the total number of outcomes. Strictly speaking, this result can be deduced from a set of axioms for probability formulated in 1933 by the Russian mathematician A. N. Kolmogorov. In Section 9.8 we discuss the axioms and show how to derive their consequences formally. At present, we take a naïve approach to probability and simply state the result as a principle.

Equally Likely Probability Formula

If S is a finite sample space in which all outcomes are equally likely and E is an event in S, then the probability of E, denoted P(E), is

P(E) = the number of outcomes in E the total number of outcomes in S

.

• Notation For any finite set A, N (A) denotes the number of elements in A.

With this notation, the equally likely probability formula becomes

P(E) = N (E) N (S)

.

Example 9.1.1 Probabilities for a Deck of Cards

An ordinary deck of cards contains 52 cards divided into four suits. The red suits are diamonds (%) and hearts ( ) and the black suits are clubs (♣) and spades (♠). Each suit contains 13 cards of the following denominations: 2, 3, 4, 5, 6, 7, 8, 9, 10, J (jack), Q (queen), K (king), and A (ace). The cards J, Q, and K are called face cards.

Mathematician Persi Diaconis, working with David Aldous in 1986 and Dave Bayer in 1992, showed that seven shuffles are needed to “thoroughly mix up” the cards in an ordinary deck. In 2000 mathematician Nick Trefethen, working with his father, Lloyd Trefethen, a mechanical engineer, used a somewhat different definition of “thoroughly mix up” to show that six shuffles will nearly always suffice. Imagine that the cards in a deck have become—by some method—so thoroughly mixed up that if you spread them out face down and pick one at random, you are as likely to get any one card as any other.

a. What is the sample space of outcomes?

b. What is the event that the chosen card is a black face card?

c. What is the probability that the chosen card is a black face card?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.1 Introduction 519

Solution

a. The outcomes in the sample space S are the 52 cards in the deck.

b. Let E be the event that a black face card is chosen. The outcomes in E are the jack, queen, and king of clubs and the jack, queen, and king of spades. Symbolically,

E = {J♣, Q♣, K♣, J♠, Q♠, K♠}. c. By part (b), N (E) = 6, and according to the description of the situation, all 52 out-

comes in the sample space are equally likely. Therefore, by the equally likely proba- bility formula, the probability that the chosen card is a black face card is

P(E) = N (E) N (S)

= 6 52 ∼= 11.5%. ■

Example 9.1.2 Rolling a Pair of Dice

A die is one of a pair of dice. It is a cube with six sides, each containing from one to six dots, called pips. Suppose a blue die and a gray die are rolled together, and the numbers of dots that occur face up on each are recorded. The possible outcomes can be listed as follows, where in each case the die on the left is blue and the one on the right is gray.

A more compact notation identifies, say, with the notation 24, with 53, and so forth.

a. Use the compact notation to write the sample space S of possible outcomes.

b. Use set notation to write the event E that the numbers showing face up have a sum of 6 and find the probability of this event.

Solution

a. S = {11, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26, 31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 45, 46, 51, 52, 53, 54, 55, 56, 61, 62, 63, 64, 65, 66}.

b. E = {15, 24, 33, 42, 51}. The probability that the sum of the numbers is 6 = P(E) = N (E)

N (S) = 5

36 . ■

The next example is called the Monty Hall problem after the host of an old game show, “Let’s Make A Deal.” When it was originally publicized in a newspaper column and on a radio show, it created tremendous controversy. Many highly educated people, even some with Ph.D.’s, submitted incorrect solutions or argued vociferously against the correct solution. Before you read the answer, think about what your own response to the situation would be.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

520 Chapter 9 Counting and Probability

Example 9.1.3 The Monty Hall Problem

There are three doors on the set for a game show. Let’s call them A, B, and C . If you pick the right door you win the prize. You pick door A. The host of the show, Monty Hall, then opens one of the other doors and reveals that there is no prize behind it. Keeping the remaining two doors closed, he asks you whether you want to switch your choice to the other closed door or stay with your original choice of door A. What should you do if you want to maximize your chance of winning the prize: stay with door A or switch—or would the likelihood of winning be the same either way?

B C B C B C

Case 1 Case 2 Case 3

Solution At the point just before the host opens one of the closed doors, there is no information about the location of the prize. Thus there are three equally likely possi- bilities for what lies behind the doors: (Case 1) the prize is behind A (i.e., it is not behind either B or C), (Case 2) the prize is behind B; (Case 3) the prize is behind C .

Since there is no prize behind the door the host opens, in Case 1 the host could open either door and you would win by staying with your original choice: door A. In Case 2 the host must open door C , and so you would win by switching to door B. In Case 3 the host must open door B, and so you would win by switching to door C . Thus, in two of the three equally likely cases, you would win by switching from A to the other closed door. In only one of the three equally likely cases would you win by staying with your original choice. Therefore, you should switch.

A reality note: The analysis used for this solution applies only if the host always opens one of the closed doors and offers the contestant the choice of staying with the original choice or switching. In the original show, Monty Hall made this offer only occasionally— most often when he knew the contestant had already chosen the correct door. ■

Many of the fundamental principles of probability were formulated in the mid-1600s in an exchange of letters between Pierre de Fermat and Blaise Pascal in response to ques- tions posed by a French nobleman interested in games of chance. In 1812, Pierre-Simon Laplace published the first general mathematical treatise on the subject and extended the range of applications to a variety of scientific and practical problems.

B et

tm an

n/ CO

R B

IS

Pierre-Simon Laplace (1749–1827)

Counting the Elements of a List Some counting problems are as simple as counting the elements of a list. For instance, how many integers are there from 5 through 12? To answer this question, imagine going along the list of integers from 5 to 12, counting each in turn.

list: 5 6 7 8 9 10 11 12 ↕ ↕ ↕ ↕ ↕ ↕ ↕ ↕

count: 1 2 3 4 5 6 7 8

So the answer is 8.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.1 Introduction 521

More generally, if m and n are integers and m ≤ n, how many integers are there from m through n? To answer this question, note that n = m + (n − m), where n − m ≥ 0 [since n ≥ m]. Note also that the element m + 0 is the first element of the list, the element m + 1 is the second element, the element m + 2 is the third, and so forth. In general, the element m + i is the (i + 1)st element of the list.

list: m(= m + 0) m + 1 m + 2 . . . n (= m + (n − m)) ↕ ↕ ↕ ↕

count: 1 2 3 . . . (n − m) + 1 And so the number of elements in the list is n − m + 1.

This general result is important enough to be restated as a theorem, the formal proof of which uses mathematical induction. (See exercise 28 at the end of this section.) The heart of the proof is the observation that if the list m, m + 1, . . . , k has k − m + 1 numbers, then the list m, m + 1, . . . , k, k + 1 has (k − m + 1) + 1 = (k + 1)− m + 1 numbers.

Theorem 9.1.1 The Number of Elements in a List

If m and n are integers and m ≤ n, then there are n − m + 1 integers from m to n inclusive.

Example 9.1.4 Counting the Elements of a Sublist

a. How many three-digit integers (integers from 100 to 999 inclusive) are divisible by 5?

b. What is the probability that a randomly chosen three-digit integer is divisible by 5?

Solution

a. Imagine writing the three-digit integers in a row, noting those that are multiples of 5 and drawing arrows between each such integer and its corresponding multiple of 5.

100 101 102 103 104 105 106 107 108 109 110 · · · 994 995 996 997 998 999 ↕ ↕ ↕ ↕

5 ·20 5 ·21 5 ·22 5 ·199

From the sketch it is clear that there are as many three-digit integers that are multi- ples of 5 as there are integers from 20 to 199 inclusive. By Theorem 9.1.1, there are 199− 20 + 1, or 180, such integers. Hence there are 180 three-digit integers that are divisible by 5.

b. By Theorem 9.1.1 the total number of integers from 100 through 999 is 999− 100 + 1 = 900. By part (a), 180 of these are divisible by 5. Hence the probability that a randomly chosen three-digit integer is divisible by 5 is 180/900 = 1/5. ■

Example 9.1.5 Application: Counting Elements of a One-Dimensional Array

Analysis of many computer algorithms requires skill at counting the elements of a one-dimensional array. Let A[1], A[2], . . . , A[n] be a one-dimensional array, where n is a positive integer.

a. Suppose the array is cut at a middle value A[m] so that two subarrays are formed: (1) A[1], A[2], . . . , A[m] and (2) A[m + 1], A[m + 2], . . . , A[n].

How many elements does each subarray have?

b. What is the probability that a randomly chosen element of the array has an even subscript

(i) if n is even? (ii) if n is odd?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

522 Chapter 9 Counting and Probability

Solution

a. Array (1) has the same number of elements as the list of integers from 1 through m. So by Theorem 9.1.1, it has m, or m − 1 + 1, elements. Array (2) has the same number of elements as the list of integers from m + 1 through n. So by Theorem 9.1.1, it has n − m, or n − (m + 1) + 1, elements.

b. (i) If n is even, each even subscript starting with 2 and ending with n can be matched up with an integer from 1 to n/2.

1 2 3 4 5 6 7 8 9 10 · · · n ↕ ↕ ↕ ↕ ↕ ↕

2 ·1 2 ·2 2 ·3 2 ·4 2 ·5 2 ·n/2

So there are n/2 array elements with even subscripts. Since the entire array has n elements, the probability that a randomly chosen element has an even subscript is n/2 n

= 1 2

.

(ii) If n is odd, then the greatest even subscript of the array is n − 1. So there are as many even subscripts between 1 and n as there are from 2 through n − 1. Then the reasoning of (i) can be used to conclude that there are (n − 1)/2 array elements with even subscripts.

1 2 3 4 5 6 · · · n − 1 n ↕ ↕ ↕ ↕

2 ·1 2 ·2 2 ·3 · · · 2 ·(n − 1)/2

Since the entire array has n elements, the probability that a randomly chosen

element has an even subscript is (n − 1)/2

n = n − 1

2n . Observe that as n gets larger

and larger, this probability gets closer and closer to 1/2.

Note that the answers to (i) and (ii) can be combined using the floor notation. By Theorem 4.5.2, the number of array elements with even subscripts is ⌊n/2⌋, so the prob- ability that a randomly chosen element has an even subscript is

⌊n/2⌋ n

. ■

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. A sample space of a random process or experiment is _____.

2. An event in a sample space is _____.

3. To compute the probability of an event using the equally likely probability formula, you take the ratio of the _____ to the _____.

4. If m ≤ n, the number of integers from m to n inclusive is _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.1 Introduction 523

Exercise Set 9.1* 1. Toss two coins 30 times and make a table showing the rel-

ative frequencies of 0, 1, and 2 heads. How do your values compare with those shown in Table 9.1.1?

2. In the example of tossing two quarters, what is the probabil- ity that at least one head is obtained? that coin A is a head? that coins A and B are either both heads or both tails?

In 3–6 use the sample space given in Example 9.1.1. Write each event as a set, and compute its probability.

3. The event that the chosen card is red and is not a face card.

4. The event that the chosen card is black and has an even number on it.

5. The event that the denomination of the chosen card is at least 10 (counting aces high).

6. The event that the denomination of the chosen card is at most 4 (counting aces high).

In 7–10, use the sample space given in Example 9.1.2. Write each of the following events as a set and compute its probability.

7. The event that the sum of the numbers showing face up is 8.

8. The event that the numbers showing face up are the same.

9. The event that the sum of the numbers showing face up is at most 6.

10. The event that the sum of the numbers showing face up is at least 9.

11. Suppose that a coin is tossed three times and the side show- ing face up on each toss is noted. Suppose also that on each toss heads and tails are equally likely. Let HHT indicate the outcome heads on the first two tosses and tails on the third, THT the outcome tails on the first and third tosses and heads on the second, and so forth. a. List the eight elements in the sample space whose out-

comes are all the possible head–tail sequences obtained in the three tosses.

b. Write each of the following events as a set and find its probability:

(i) The event that exactly one toss results in a head. (ii) The event that at least two tosses result in a head.

(iii) The event that no head is obtained.

12. Suppose that each child born is equally likely to be a boy or a girl. Consider a family with exactly three children. Let BBG indicate that the first two children born are boys and the third child is a girl, let GBG indicate that the first and third children born are girls and the second is a boy, and so forth. a. List the eight elements in the sample space whose out-

comes are all possible genders of the three children. b. Write each of the events in the next column as a set and

find its probability.

(i) The event that exactly one child is a girl. (ii) The event that at least two children are girls.

(iii) The event that no child is a girl.

13. Suppose that on a true/false exam you have no idea at all about the answers to three questions. You choose answers randomly and therefore have a 50–50 chance of being correct on any one question. Let CCW indicate that you were correct on the first two questions and wrong on the third, let WCW indicate that you were wrong on the first and third questions and correct on the second, and so forth. a. List the elements in the sample space whose outcomes

are all possible sequences of correct and incorrect responses on your part.

b. Write each of the following events as a set and find its probability:

(i) The event that exactly one answer is correct. (ii) The event that at least two answers are correct.

(iii) The event that no answer is correct.

14. Three people have been exposed to a certain illness. Once exposed, a person has a 50–50 chance of actually becom- ing ill. a. What is the probability that exactly one of the people

becomes ill? b. What is the probability that at least two of the people

become ill? c. What is the probability that none of the three people

becomes ill?

15. When discussing counting and probability, we often con- sider situations that may appear frivolous or of little practi- cal value, such as tossing coins, choosing cards, or rolling dice. The reason is that these relatively simple examples serve as models for a wide variety of more complex situ- ations in the real world. In light of this remark, comment on the relationship between your answer to exercise 11 and your answers to exercises 12–14.

16. Two faces of a six-sided die are painted red, two are painted blue, and two are painted yellow. The die is rolled three times, and the colors that appear face up on the first, second, and third rolls are recorded. a. Let BBR denote the outcome where the color appearing

face up on the first and second rolls is blue and the color appearing face up on the third roll is red. Because there are as many faces of one color as of any other, the out- comes of this experiment are equally likely. List all 27 possible outcomes.

b. Consider the event that all three rolls produce different colors. One outcome in this event is RBY and another RYB. List all outcomes in the event. What is the proba- bility of the event?

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

524 Chapter 9 Counting and Probability

c. Consider the event that two of the colors that appear face up are the same. One outcome in this event is RRB and another is RBR. List all outcomes in the event. What is the probability of the event?

17. Consider the situation described in exercise 16. a. Find the probability of the event that exactly one of the

colors that appears face up is red. b. Find the probability of the event that at least one of the

colors that appears face up is red.

18. An urn contains two blue balls (denoted B1 and B2) and one white ball (denoted W ). One ball is drawn, its color is recorded, and it is replaced in the urn. Then another ball is drawn, and its color is recorded. a. Let B1W denote the outcome that the first ball drawn

is B1 and the second ball drawn is W . Because the first ball is replaced before the second ball is drawn, the out- comes of the experiment are equally likely. List all nine possible outcomes of the experiment.

b. Consider the event that the two balls that are drawn are both blue. List all outcomes in the event. What is the probability of the event?

c. Consider the event that the two balls that are drawn are of different colors. List all outcomes in the event. What is the probability of the event?

19. An urn contains two blue balls (denoted B1 and B2) and three white balls (denoted W1, W2, and W3). One ball is drawn, its color is recorded, and it is replaced in the urn. Then another ball is drawn and its color is recorded. a. Let B1W2 denote the outcome that the first ball drawn

is B1 and the second ball drawn is W2. Because the first ball is replaced before the second ball is drawn, the out- comes of the experiment are equally likely. List all 25 possible outcomes of the experiment.

b. Consider the event that the first ball that is drawn is blue. List all outcomes in the event. What is the probability of the event?

c. Consider the event that only white balls are drawn. List all outcomes in the event. What is the probability of the event?

20. Refer to Example 9.1.3. Suppose you are appearing on a game show with a prize behind one of five closed doors: A, B, C, D, and E . If you pick the right door, you win the prize. You pick door A. The game show host then opens one of the other doors and reveals that there is no prize behind it. Then the host gives you the option of staying with your original choice of door A or switching to one of the other doors that is still closed. a. If you stick with your original choice, what is the prob-

ability that you will win the prize? b. If you switch to another door, what is the probability that

you will win the prize?

21. a. How many positive two-digit integers are multiples of 3? b. What is the probability that a randomly chosen positive

two-digit integer is a multiple of 3? c. What is the probability that a randomly chosen positive

two-digit integer is a multiple of 4?

22. a. How many positive three-digit integers are multiples of 6?

b. What is the probability that a randomly chosen positive three-digit integer is a multiple of 6?

c. What is the probability that a randomly chosen positive three-digit integer is a multiple of 7?

23. Suppose A[1], A[2], A[3], . . . , A[n] is a one-dimensional array and n ≥ 50. a. How many elements are in the array? b. How many elements are in the subarray

A[4], A[5], . . . , A[39]? c. If 3 ≤ m ≤ n, what is the probability that a randomly

chosen array element is in the subarray

A[3], A[4], . . . , A[m]? d. What is the probability that a randomly chosen array ele-

ment is in the subarray shown below if n = 39? A[⌊n/2⌋], A[⌊n/2⌋+ 1], . . . , A[n]

24. Suppose A[1], A[2], . . . , A[n] is a one-dimensional array and n ≥ 2. Consider the subarray

A[1], A[2], . . . , A[⌊n/2⌋]. a. How many elements are in the subarray (i) if n is even?

and (ii) if n is odd? b. What is the probability that a randomly chosen array

element is in the subarray (i) if n is even? and (ii) if n is odd?

25. Suppose A[1], A[2], . . . , A[n] is a one-dimensional array and n ≥ 2. Consider the subarray

A[⌊n/2⌋], A[⌊n/2⌋+ 1], . . . , A[n]. a. How many elements are in the subarray (i) if n is even?

and (ii) if n is odd? b. What is the probability that a randomly chosen array

element is in the subarray (i) if n is even? and (ii) if n is odd?

26. What is the 27th element in the one-dimensional array A[42], A[43], . . . , A[100]?

27. What is the 62nd element in the one-dimensional array B[29], B[30], . . . , B[100]?

28. If the largest of 56 consecutive integers is 279, what is the smallest?

29. If the largest of 87 consecutive integers is 326, what is the smallest?

30. How many even integers are between 1 and 1,001?

31. How many integers that are multiples of 3 are between 1 and 1,001?

32. A certain non-leap year has 365 days, and January 1 occurs on a Monday. a. How many Sundays are in the year? b. How many Mondays are in the year?

33.✶ Prove Theorem 9.1.1. (Let m be any integer and prove the theorem by mathematical induction on n.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 525

Answers for Test Yourself 1. the set of all outcomes of the random process or experiment 2. a subset of the sample space 3. number of outcomes in the event; total number of outcomes 4. n − m + 1

9.2 Possibility Trees and the Multiplication Rule Don’t believe anything unless you have thought it through for yourself. — Anna Pell Wheeler, 1883–1966

A tree structure is a useful tool for keeping systematic track of all possibilities in situa- tions in which events happen in order. The following example shows how to use such a structure to count the number of different outcomes of a tournament.

Example 9.2.1 Possibilities for Tournament Play

Teams A and B are to play each other repeatedly until one wins two games in a row or a total of three games. One way in which this tournament can be played is for A to win the first game, B to win the second, and A to win the third and fourth games. Denote this by writing A–B–A–A.

a. How many ways can the tournament be played?

b. Assuming that all the ways of playing the tournament are equally likely, what is the probability that five games are needed to determine the tournament winner?

Solution

a. The possible ways for the tournament to be played are represented by the distinct paths from “root” (the start) to “leaf” (a terminal point) in the tree shown sideways in Figure 9.2.1. The label on each branching point indicates the winner of the game. The notations in parentheses indicate the winner of the tournament.

Start

Winner of game 1

Winner of game 2

Winner of game 3

Winner of game 4

Winner of game 5

A

B

A

B

(A wins)

A

B (B wins)

(B wins)

(A wins)

A

B

(B wins)

(B wins)

A

B

A

(A wins)A

B (A wins)A

B

(B wins)

(A wins)A

BB

Figure 9.2.1 The Outcomes of a Tournament

The fact that there are ten paths from the root of the tree to its leaves shows that there are ten possible ways for the tournament to be played. They are (moving from the top down): A–A, A–B–A–A, A–B–A–B–A, A–B–A–B–B, A–B–B, B–A–A, B–A–B–A–A, B–A–B–A–B, B–A–B–B, and B–B. In five cases A wins, and in the other five B wins. The least number of games that must be played to determine a winner is two, and the most that will need to be played is five.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

526 Chapter 9 Counting and Probability

b. Since all the possible ways of playing the tournament listed in part (a) are assumed to be equally likely, and the listing shows that five games are needed in four different cases (A–B–A–B–A, A–B–A–B–B, B–A–B–A–B, and B–A–B–A–A), the proba- bility that five games are needed is 4/10 = 2/5 = 40%. ■

The Multiplication Rule Consider the following example. Suppose a computer installation has four input/output units (A, B, C, and D) and three central processing units (X, Y, and Z ). Any input/output unit can be paired with any central processing unit. How many ways are there to pair an input/output unit with a central processing unit?

To answer this question, imagine the pairing of the two types of units as a two-step operation:

Step 1: Choose the input/output unit.

Step 2: Choose the central processing unit.

The possible outcomes of this operation are illustrated in the possibility tree of Figure 9.2.2.

Start

Step 1: Choose the input/output unit.

Step 2: Choose the central processing unit.

A

B

C

D

X

Y

Z

X

Y

Z

X

Y

Z

X

Y

Z

Figure 9.2.2 Pairing Objects Using a Possibility Tree

The topmost path from “root” to “leaf” indicates that input/output unit A is to be paired with central processing unit X . The next lower branch indicates that input/output unit A is to be paired with central processing unit Y. And so forth.

Thus the total number of ways to pair the two types of units is the same as the number of branches of the tree, which is

3 + 3 + 3 + 3 = 4 ·3 = 12. The idea behind this example can be used to prove the following rule. A formal proof uses mathematical induction and is left to the exercises.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 527

Theorem 9.2.1 The Multiplication Rule

If an operation consists of k steps and

the first step can be performed in n1 ways,

the second step can be performed in n2 ways [regardless of how the first step was performed],

...

the kth step can be performed in nk ways [regardless of how the preceding steps were performed],

then the entire operation can be performed in n1n2 · · · nk ways.

To apply the multiplication rule, think of the objects you are trying to count as the output of a multistep operation. The possible ways to perform a step may depend on how preceding steps were performed, but the number of ways to perform each step must be constant regardless of the action taken in prior steps.

Example 9.2.2 Number of Personal Identification Numbers (PINs)

A typical PIN (personal identification number) is a sequence of any four symbols chosen from the 26 letters in the alphabet and the ten digits, with repetition allowed. How many different PINs are possible?

Solution Typical PINs are CARE, 3387, B32B, and so forth. You can think of forming a PIN as a four-step operation to fill in each of the four symbols in sequence.

4321

Pool of available symbols: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

36 ch

oic es

36 ch

oic es

36 ch

oic es

36 ch

oic

es

Step 1: Choose the first symbol.

Step 2: Choose the second symbol.

Step 3: Choose the third symbol.

Step 4: Choose the fourth symbol.

There is a fixed number of ways to perform each step, namely 36, regardless of how preceding steps were performed. And so, by the multiplication rule, there are 36 ·36 ·36 ·36 = 364 = 1,679,616 PINs in all. ■

Another way to look at the PINs of Example 9.2.2 is as ordered 4-tuples. For example, you can think of the PIN M2ZM as the ordered 4-tuple (M, 2, Z, M). Therefore, the total number of PINs is the same as the total number of ordered 4-tuples whose elements are either letters of the alphabet or digits. One of the most important uses of the multiplication rule is to derive a general formula for the number of elements in any Cartesian product of a finite number of finite sets. In Example 9.2.3, this is done for a Cartesian product of four sets.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

528 Chapter 9 Counting and Probability

Example 9.2.3 The Number of Elements in a Cartesian Product

Suppose A1, A2, A3, and A4 are sets with n1, n2, n3, and n4 elements, respectively. Show that the set A1 × A2 × A3 × A4 has n1n2n3n4 elements.

Solution Each element in A1 × A2 × A3 × A4 is an ordered 4-tuple of the form (a1, a2, a3, a4), where a1 ∈ A1, a2 ∈ A2, a3 ∈ A3, and a4 ∈ A4. Imagine the process of constructing these ordered tuples as a four-step operation:

Step 1: Choose the first element of the 4-tuple.

Step 2: Choose the second element of the 4-tuple.

Step 3: Choose the third element of the 4-tuple.

Step 4: Choose the fourth element of the 4-tuple.

There are n1 ways to perform step 1, n2 ways to perform step 2, n3 ways to perform step 3, and n4 ways to perform step 4. Hence, by the multiplication rule, there are n1n2n3n4 ways to perform the entire operation. Therefore, there are n1n2n3n4 distinct 4-tuples in A1 × A2 × A3 × A4. ■

Example 9.2.4 Number of PINs without Repetition

In Example 9.2.2 we formed PINs using four symbols, either letters of the alphabet or digits, and supposing that letters could be repeated. Now suppose that repetition is not allowed.

a. How many different PINs are there?

b. If all PINs are equally likely, what is the probability that a PIN chosen at random contains no repeated symbol?

Solution

a. Again think of forming a PIN as a four-step operation: Choose the first symbol, then the second, then the third, and then the fourth. There are 36 ways to choose the first symbol, 35 ways to choose the second (since the first symbol cannot be used again), 34 ways to choose the third (since the first two symbols cannot be reused), and 33 ways to choose the fourth (since the first three symbols cannot be reused). Thus, the mul- tiplication rule can be applied to conclude that there are 36 ·35 ·34 ·33 = 1,413,720 different PINs with no repeated symbol.

b. By part (a) there are 1,413,720 PINs with no repeated symbol, and by Example 9.2.2 there are 1,679,616 PINs in all. Thus the probability that a PIN chosen at random contains no repeated symbol is 1,413,7201,679,616

∼= .8417. In other words, approximately 84% of PINs have no repeated symbol. ■

Any circuit with two input signals P and Q has an input/output table consisting of four rows corresponding to the four possible assignments of values to P and Q : 11, 10, 01, and 00. The next example shows that there are only 16 distinct ways in which such a circuit can function.

Example 9.2.5 Number of Input/Output Tables for a Circuit with Two Input Signals

Consider the set of all circuits with two input signals P and Q. For each such circuit an input/output table can be constructed, but, as shown in Section 2.4, two such input/output tables may have the same values. How many distinct input/output tables can be con- structed for circuits with input/output signals P and Q?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 529

Solution Fix the order of the input values for P and Q. Then two input/output tables are distinct if their output values differ in at least one row. For example, the input/output tables shown below are distinct, because their output values differ in the first row.

P Q Output

1 1 1

1 0 0

0 1 1

0 0 0

P Q Output

1 1 0

1 0 0

0 1 1

0 0 0

For a fixed ordering of input values, you can obtain a complete input/output table by filling in the entries in the output column. You can think of this as a four-step operation:

Step 1: Fill in the output value for the first row.

Step 2: Fill in the output value for the second row.

Step 3: Fill in the output value for the third row.

Step 4: Fill in the output value for the fourth row. Each step can be performed in exactly two ways: either a 1 or a 0 can be filled in. Hence, by the multiplication rule, there are

2 ·2 ·2 ·2 = 16 ways to perform the entire operation. It follows that there are 24 = 16 distinct input/output tables for a circuit with two input signals P and Q. This means that such a circuit can function in only 16 distinct ways. ■

Recall from Section 5.9 that if S is a nonempty, finite set of characters, then a string over S is a finite sequence of elements of S. The number of characters in a string is called the length of the string. The null string over S is the “string” with no characters. It is usually denoted ε and is said to have length 0.

Observe that in Examples 9.2.2 and 9.2.4, the set of all PINs of length 4 is the same as the set of all strings of length 4 over the set

S = {x | x is a letter of the alphabet or x is a digit}. Also observe that another way to think of Example 9.2.5 is to realize that there are as many input/output tables for a circuit with two input signals as there are bit strings of length 4 (written vertically) that can be used to fill in the output values. As another example, here is a listing of all bit strings of length 3:

000, 001, 010, 100, 011, 101, 110, 111.

Example 9.2.6 Counting the Number of Iterations of a Nested Loop

Consider the following nested loop:

for i := 1 to 4 for j := 1 to 3

[Statements in body of inner loop. None contain branching statements that lead out of the inner loop.]

next j next i

How many times will the inner loop be iterated when the algorithm is implemented and run?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

530 Chapter 9 Counting and Probability

Solution The outer loop is iterated four times, and during each iteration of the outer loop, there are three iterations of the inner loop. Hence by the multiplication rule, the total number of iterations of the inner loop is 4 ·3 = 12. This is illustrated by the trace table below.

→ → → →i 1 2 3 4 j 1 2 3 1 2 3 1 2 3 1 2 3 ︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸

3 + 3 + 3 + 3 = 12 ■

When the Multiplication Rule Is Difficult or Impossible to Apply

Consider the following problem:

Three officers—a president, a treasurer, and a secretary—are to be chosen from among four people: Ann, Bob, Cyd, and Dan. Suppose that, for various reasons, Ann cannot be president and either Cyd or Dan must be secretary. How many ways can the officers be chosen?

It is natural to try to solve this problem using the multiplication rule. A person might answer as follows:

There are three choices for president (all except Ann), three choices for trea- surer (all except the one chosen as president), and two choices for secretary (Cyd or Dan). Therefore, by the multiplication rule, there are 3 ·3 ·2 = 18 choices in all.

Unfortunately, this analysis is incorrect. The number of ways to choose the secretary varies depending on who is chosen for president and treasurer. For instance, if Bob is chosen for president and Ann for treasurer, then there are two choices for secretary: Cyd and Dan. But if Bob is chosen for president and Cyd for treasurer, then there is just one choice for secretary: Dan. The clearest way to see all the possible choices is to construct the possibility tree, as is shown in Figure 9.2.3.

Step 3: Choose the secretary.

Step 2: Choose the treasurer.

Start

Bob

Cyd

Dan

Ann

Ann

Ann

Bob

Bob

Cyd

Dan

Cyd

Cyd

Cyd

Cyd

Dan

Dan

Dan

Dan

Step 1: Choose the president.

Figure 9.2.3

From the tree it is easy to see that there are only eight ways to choose a president, treasurer, and secretary so as to satisfy the given conditions.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 531

Another way to solve this problem is somewhat surprising. It turns out that the steps can be reordered in a slightly different way so that the number of ways to perform each step is constant regardless of the way previous steps were performed.

Example 9.2.7 A More Subtle Use of the Multiplication Rule

Reorder the steps for choosing the officers in the previous example so that the total num- ber of ways to choose officers can be computed using the multiplication rule.

Solution

Step 1: Choose the secretary.

Step 2: Choose the president.

Step 3: Choose the treasurer. There are exactly two ways to perform step 1 (either Cyd or Dan may be chosen), two ways to perform step 2 (neither Ann nor the person chosen in step 1 may be chosen but either of the other two may), and two ways to perform step 3 (either of the two people not chosen as secretary or president may be chosen as treasurer). Thus, by the multipli- cation rule, the total number of ways to choose officers is 2 ·2 ·2 = 8. A possibility tree illustrating this sequence of choices is shown in Figure 9.2.4. Note how balanced this tree is compared with the one in Figure 9.2.3.

Start

Step 1: Choose the secretary.

Step 2: Choose the president.

Step 3: Choose the treasurer.

Cyd

Dan

Dan

Dan

Bob

Bob

Ann

Ann

Ann

Ann

Cyd

Bob

Bob

Cyd

Figure 9.2.4 ■

Permutations A permutation of a set of objects is an ordering of the objects in a row. For example, the set of elements a, b, and c has six permutations.

abc acb cba bac bca cab

In general, given a set of n objects, how many permutations does the set have? Imag- ine forming a permutation as an n-step operation:

Step 1: Choose an element to write first.

Step 2: Choose an element to write second. ...

...

Step n: Choose an element to write nth.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

532 Chapter 9 Counting and Probability

Any element of the set can be chosen in step 1, so there are n ways to perform step 1. Any element except that chosen in step 1 can be chosen in step 2, so there are n − 1 ways to perform step 2. In general, the number of ways to perform each successive step is one less than the number of ways to perform the preceding step. At the point when the nth element is chosen, there is only one element left, so there is only one way to perform step n. Hence, by the multiplication rule, there are

n(n − 1)(n − 2) · · · 2 ·1 = n! ways to perform the entire operation. In other words, there are n! permutations of a set of n elements. This reasoning is summarized in the following theorem. A formal proof uses mathematical induction and is left as an exercise.

Theorem 9.2.2

For any integer n with n ≥ 1, the number of permutations of a set with n elements is n!.

Example 9.2.8 Permutations of the Letters in a Word

a. How many ways can the letters in the word COMPUTER be arranged in a row?

b. How many ways can the letters in the word COMPUTER be arranged if the letters CO must remain next to each other (in order) as a unit?

c. If letters of the word COMPUTER are randomly arranged in a row, what is the proba- bility that the letters CO remain next to each other (in order) as a unit?

Solution

a. All the eight letters in the word COMPUTER are distinct, so the number of ways in which we can arrange the letters equals the number of permutations of a set of eight elements. This equals 8! = 40,320.

b. If the letter group CO is treated as a unit, then there are effectively only seven objects that are to be arranged in a row.

CO M P U T E R

Hence there are as many ways to write the letters as there are permutations of a set of seven elements, namely 7! = 5,040.

c. When the letters are arranged randomly in a row, the total number of arrangements is 40,320 by part (a), and the number of arrangements with the letters CO next to each other (in order) as a unit is 5,040. Thus the probability is

5,040 40,320

= 1 8

= 12.5%. ■

Example 9.2.9 Permutations of Objects Around a Circle

At a meeting of diplomats, the six participants are to be seated around a circular table. Since the table has no ends to confer particular status, it doesn’t matter who sits in which chair. But it does matter how the diplomats are seated relative to each other. In other words, two seatings are considered the same if one is a rotation of the other. How many different ways can the diplomats be seated?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 533

Solution Call the diplomats by the letters A, B, C, D, E , and F . Since only relative posi- tion matters, you can start with any diplomat (say A), place that diplomat anywhere (say in the top seat of the diagram shown in Figure 9.2.5), and then consider all arrangements of the other diplomats around that one. B through F can be arranged in the seats around diplomat A in all possible orders. So there are 5! = 120 ways to seat the group.

Five other diplomats to be seated: B, C, D, E, F

A

Figure 9.2.5 ■

Permutations of Selected Elements Given the set {a, b, c}, there are six ways to select two letters from the set and write them in order.

ab ac ba bc ca cb

Each such ordering of two elements of {a, b, c} is called a 2-permutation of {a, b, c}.

• Definition An r-permutation of a set of n elements is an ordered selection of r elements taken from the set of n elements. The number of r -permutations of a set of n elements is denoted P(n, r).

Theorem 9.2.3

If n and r are integers and 1 ≤ r ≤ n, then the number of r -permutations of a set of n elements is given by the formula

P(n, r) = n(n − 1)(n − 2) · · · (n − r + 1) first version or, equivalently,

P(n, r) = n! (n − r)! second version.

A formal proof of this theorem uses mathematical induction and is based on the mul- tiplication rule. The idea of the proof is the following.

Suppose a set of n elements is given. Formation of an r -permutation can be thought of as an r -step process. Step 1 is to choose the element to be first. Since the set has n elements, there are n ways to perform step 1. Step 2 is to choose the element to be second. Since the element chosen in step 1 is no longer available, there are n − 1 ways to perform step 2. Step 3 is to choose the element to be third. Since neither of the two elements chosen in the first two steps is available, there are n − 2 choices for step 3. This process is repeated r times, as shown on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

534 Chapter 9 Counting and Probability

Position 2 Position rPosition 3Position 1

n choices

n – 1 choices

n – 2 choices n – (r – 1) choices

Pool of available elements: x1, x2, . . . , xn

The number of ways to perform each successive step is one less than the number of ways to perform the preceding step. Step r is to choose the element to be r th. At the point just before step r is performed, r − 1 elements have already been chosen, and so there are

n − (r − 1) = n − r + 1 left to choose from. Hence there are n − r + 1 ways to perform step r . It follows by the multiplication rule that the number of ways to form an r -permutation is

P(n, r) = n(n − 1)(n − 2) · · · (n − r + 1). Note that

n! (n − r)! =

n(n − 1)(n − 2) · · · (n − r + 1)(n − r)(n − r − 1) · · · 3 ·2 ·1 (n − r)(n − r − 1) · · · 3 ·2 ·1

= n(n − 1)(n − 2) · · · (n − r + 1). Thus the formula can be written as

P(n, r) = n! (n − r)! .

The second version of the formula is easier to remember. When you actually use it, however, first substitute the values of n and r and then immediately cancel the numerical value of (n − r)! from the numerator and denominator. Because factorials become so large so fast, direct use of the second version of the formula without cancellation can overload your calculator’s capacity for exact arithmetic even when n and r are quite small. For instance, if n = 15 and r = 2, then

n! (n − r)! =

15! 13! =

1,307,674,368,000 6,227,020,800

.

But if you cancel (n − r)! = 13! from numerator and denominator before multiplying out, you obtain

n! (n − r)! =

15! 13! =

15 ·14 ·13! 13! = 15 ·14 = 210.

In fact, many scientific calculators allow you to compute P(n, r) simply by entering the values of n and r and pressing a key or making a menu choice. Alternative notations for P(n, r) that you may see in your calculator manual are n Pr , Pn,r and n Pr .

Example 9.2.10 Evaluating r-Permutations

a. Evaluate P(5, 2).

b. How many 4-permutations are there of a set of seven objects?

c. How many 5-permutations are there of a set of five objects?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 535

Solution

a. P(5, 2) = 5! (5− 2)! =

5 ·4 ·3 ·2 ·1 3 ·2 ·1 = 20

b. The number of 4-permutations of a set of seven objects is

P(7, 4) = 7! (7− 4)! =

7 ·6 ·5 ·4 ·3 ·2 ·1 3 ·2 ·1 = 7 ·6 ·5 ·4 = 840.

c. The number of 5-permutations of a set of five objects is

P(5, 5) = 5! (5− 5)! =

5! 0! =

5! 1

= 5! = 120.

Note that the definition of 0! as 1 makes this calculation come out as it should, for the number of 5-permutations of a set of five objects is certainly equal to the number of permutations of the set. ■

Example 9.2.11 Permutations of Selected Letters of a Word

a. How many different ways can three of the letters of the word BYTES be chosen and written in a row?

b. How many different ways can this be done if the first letter must be B?

Solution

a. The answer equals the number of 3-permutations of a set of five elements. This equals

P(5, 3) = 5! (5− 3)! =

5 ·4 ·3 ·2 ·1 2 ·1 = 5 ·4 ·3 = 60.

b. Since the first letter must be B, there are effectively only two letters to be chosen and placed in the other two positions. And since the B is used in the first position, there are four letters available to fill the remaining two positions.

Position 2 Position 3Position 1

B

Pool of available letters: Y, T, E, S

Hence the answer is the number of 2-permutations of a set of four elements, which is

P(4, 2) = 4! (4− 2)! =

4 ·3 ·2 ·1 2 ·1 = 4 ·3 = 12. ■

In many applications of the mathematics of counting, it is necessary to be skillful in working algebraically with quantities of the form P(n, r). The next example shows a kind of problem that gives practice in developing such skill.

Example 9.2.12 Proving a Property of P(n, r)

Prove that for all integers n ≥ 2, P(n, 2) + P(n, 1) = n2.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

536 Chapter 9 Counting and Probability

Solution Suppose n is an integer that is greater than or equal to 2. By Theorem 9.2.3,

P(n, 2) = n! (n − 2)! =

n(n − 1)(n − 2)! (n − 2)! = n(n − 1)

and

P(n, 1) = n! (n − 1)! =

n ·(n − 1)! (n − 1)! = n.

Hence

P(n, 2) + P(n, 1) = n ·(n − 1) + n = n2 − n + n = n2, which is what we needed to show. ■

Test Yourself 1. The multiplication rule says that if an operation can be per-

formed in k steps and, for each i with 1≤ i≤k, the i th step can be performed in ni ways (regardless of how previous steps were performed), then the operation as a whole can be performed in _____.

2. A permutation of a set of elements is _____.

3. The number of permutations of a set of n elements equals _____.

4. An r -permutation of a set of n elements is _____.

5. The number of r -permutations of a set of n elements is denoted _____.

6. One formula for the number of r -permutations of a set of n elements is _____ and another formula is _____.

Exercise Set 9.2 In 1–4, use the fact that in baseball’s World Series, the first team to win four games wins the series.

1. Suppose team A wins the first three games. How many ways can the series be completed? (Draw a tree.)

2. Suppose team A wins the first two games. How many ways can the series be completed? (Draw a tree.)

3. How many ways can a World Series be played if team A wins four games in a row?

4. How many ways can a World Series be played if no team wins two games in a row?

5. In a competition between players X and Y , the first player to win three games in a row or a total of four games wins. How many ways can the competition be played if X wins the first game and Y wins the second and third games? (Draw a tree.)

6. One urn contains two black balls (labeled B1 and B2) and one white ball. A second urn contains one black ball and two white balls (labeled W1 and W2). Suppose the follow- ing experiment is performed: One of the two urns is chosen at random. Next a ball is randomly chosen from the urn. Then a second ball is chosen at random from the same urn without replacing the first ball. a. Construct the possibility tree showing all possible out-

comes of this experiment. b. What is the total number of outcomes of this experi-

ment?

c. What is the probability that two black balls are chosen? d. What is the probability that two balls of opposite color

are chosen?

7. One urn contains one blue ball (labeled B1) and three red balls (labeled R1, R2, and R3). A second urn contains two red balls (R4 and R5) and two blue balls (B2 and B3). An experiment is performed in which one of the two urns is chosen at random and then two balls are randomly chosen from it, one after the other without replacement. a. Construct the possibility tree showing all possible out-

comes of this experiment. b. What is the total number of outcomes of this experi-

ment? c. What is the probability that two red balls are chosen?

8. A person buying a personal computer system is offered a choice of three models of the basic unit, two models of keyboard, and two models of printer. How many distinct systems can be purchased?

9. Suppose there are three roads from city A to city B and five roads from city B to city C . a. How many ways is it possible to travel from city A to

city C via city B? b. How many different round-trip routes are there from city

A to B to C to B and back to A? c. How many different routes are there from city A to B

to C to B and back to A in which no road is traversed twice?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 537

10. Suppose there are three routes from North Point to Boulder Creek, two routes from Boulder Creek to Beaver Dam, two routes from Beaver Dam to Star Lake, and four routes directly from Boulder Creek to Star Lake. (Draw a sketch.) a. How many routes from North Point to Star Lake pass

through Beaver Dam? b. How many routes from North Point to Star Lake bypass

Beaver Dam?

11. a. A bit string is a finite sequence of 0’s and 1’s. How many bit strings have length 8?

b. How many bit strings of length 8 begin with three 0’s? c. How many bit strings of length 8 begin and end with a 1?

12. Hexadecimal numbers are made using the sixteen digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. They are denoted by the subscript 16. For example, 9A2D16 and BC5416 are hexadecimal numbers. a. How many hexadecimal numbers begin with one of the

digits 3 through B, end with one of the digits 5 through F, and are 5 digits long?

b. How many hexadecimal numbers begin with one of the digits 4 through D, end with one of the digits 2 through E, and are 6 digits long?

13. A coin is tossed four times. Each time the result H for heads or T for tails is recorded. An outcome of HHTT means that heads were obtained on the first two tosses and tails on the second two. Assume that heads and tails are equally likely on each toss. a. How many distinct outcomes are possible? b. What is the probability that exactly two heads occur? c. What is the probability that exactly one head occurs?

14. Suppose that in a certain state, all automobile license plates have four letters followed by three digits. a. How many different license plates are possible? b. How many license plates could begin with A and end

in 0? c. How many license plates could begin with TGIF? d. How many license plates are possible in which all the

letters and digits are distinct? e. How many license plates could begin with AB and have

all letters and digits distinct?

15. A combination lock requires three selections of numbers, each from 1 through 30. a. How many different combinations are possible? b. Suppose the locks are constructed in such a way that no

number may be used twice. How many different combi- nations are possible?

16. a. How many integers are there from 10 through 99? b. How many odd integers are there from 10 through 99? c. How many integers from 10 through 99 have distinct

digits?

d. How many odd integers from 10 through 99 have distinct digits?

e. What is the probability that a randomly chosen two-digit integer has distinct digits? has distinct digits and is odd?

17. a. How many integers are there from 1000 through 9999? b. How many odd integers are there from 1000 through

9999? c. How many integers from 1000 through 9999 have dis-

tinct digits? d. How many odd integers from 1000 through 9999 have

distinct digits? e. What is the probability that a randomly chosen four-

digit integer has distinct digits? has distinct digits and is odd?

18. The diagram below shows the keypad for an automatic teller machine. As you can see, the same sequence of keys represents a variety of different PINs. For instance, 2133, AZDE, and BQ3F are all keyed in exactly the same way.

1 QZ

2 ABC

3 DEF

4 GHI

5 JKL

6 MNO

7 PRS

8 TUV

9 WXY

0

a. How many different PINs are represented by the same sequence of keys as 2133?

b. How many different PINs are represented by the same sequence of keys as 5031?

c. At an automatic teller machine, each PIN corresponds to a four-digit numeric sequence. For instance, TWJM cor- responds to 8956. How many such numeric sequences contain no repeated digit?

19. Three officers—a president, a treasurer, and a secretary— are to be chosen from among four people: Ann, Bob, Cyd, and Dan. Suppose that Bob is not qualified to be trea- surer and Cyd’s other commitments make it impossible for her to be secretary. How many ways can the officers be chosen? Can the multiplication rule be used to solve this problem?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

538 Chapter 9 Counting and Probability

20. Modify Example 9.2.4 by supposing that a PIN must not begin with any of the letters A–M and must end with a digit. Continue to assume that no symbol may be used more than once and that the total number of PINs is to be determined. a. Find the error in the following “solution.”

“Constructing a PIN is a four-step process.

Step 1: Choose the left-most symbol.

Step 2: Choose the second symbol from the left.

Step 3: Choose the third symbol from the left.

Step 4: Choose the right-most symbol. Because none of the thirteen letters from A through M may be chosen in step 1, there are 36− 13 = 23 ways to perform step 1. There are 35 ways to perform step 2 and 34 ways to perform step 3 because previously used symbols may not be used. Since the symbol cho- sen in step 4 must be a previously unused digit, there are 10− 3 = 7 ways to perform step 4. Thus there are 23 ·35 ·34 ·7 = 191,590 different PINs that satisfy the given conditions.”

b. Reorder steps 1–4 in part (a) as follows:

Step 1: Choose the right-most symbol.

Step 2: Choose the left-most symbol.

Step 3: Choose the second symbol from the left.

Step 4: Choose the third symbol from the left.

Use the multiplication rule to find the number of PINs that satisfy the given conditions.

21.H Suppose A is a set with m elements and B is a set with n elements. a. How many relations are there from A to B? Explain. b. How many functions are there from A to B? Explain. c. What fraction of the relations from A to B are functions?

22. a. How many functions are there from a set with three elements to a set with four elements?

b. How many functions are there from a set with five elements to a set with two elements?

c. How many functions are there from a set with m elements to a set with n elements, where m and n are positive integers?

23. In Section 2.5 we showed how integers can be repre- sented by strings of 0’s and 1’s inside a digital computer. In fact, through various coding schemes, strings of 0’s and 1’s can be used to represent all kinds of symbols. One commonly used code is the Extended Binary-Coded Decimal Interchange Code (EBCDIC) in which each sym- bol has an 8-bit representation. How many distinct symbols can be represented by this code?

In each of 24–28, determine how many times the innermost loop will be iterated when the algorithm segment is implemented and run. (Assume that m, n, p, a, b, c, and d are all positive inte- gers.)

24. for i := 1 to 30 for j := 1 to 15

[Statements in body of inner loop. None contain branching statements that lead outside the loop.]

next j

next i

25. for j := 1 to m for k := 1 to n

[Statements in body of inner loop. None contain branching statements that lead outside the loop.]

next k

next j

26. for i := 1 to m for j := 1 to n

for k := 1 to p [Statements in body of inner loop. None contain branching statements that lead outside the loop.]

next k

next j

next i

27. for i := 5 to 50 for j := 10 to 20

[Statements in body of inner loop. None contain branching statements that lead outside the loop.]

next j

next i

28. Assume a ≤ b and c ≤ d. for i := a to b

for j := c to d [Statements in body of inner loop. None contain branching statements that lead outside the loop.]

next j

next i

29.✶H Consider the numbers 1 through 99,999 in their ordinary decimal representations. How many contain exactly one of each of the digits 2, 3, 4, and 5?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.2 Possibility Trees and the Multiplication Rule 539

30.✶ Let n = pk11 pk22 · · · pkmm where p1, p2, . . . , pm are distinct prime numbers and k1, k2, . . . , km are positive integers. How many ways can n be written as a product of two posi- tive integers that have no common factors a. assuming that order matters (i.e., 8 ·15 and 15 ·8 are

regarded as different)? b. assuming that order does not matter (i.e., 8 ·15 and

15 ·8 are regarded as the same)? 31.✶ a. If p is a prime number and a is a positive integer, how

many distinct positive divisors does pa have? b. If p and q are distinct prime numbers and a and b are

positive integers, how many distinct positive divisors does paqb have?

c. If p, q, and r are distinct prime numbers and a, b, and c are positive integers, how many distinct positive divisors does paqbrc have?

d. If p1, p2, . . . , pm are distinct prime numbers and a1, a2, . . . , am are positive integers, how many distinct positive divisors does pa11 p

a2 2 · · · pamm have?

e. What is the smallest positive integer with exactly 12 divisors?

32. a. How many ways can the letters of the word ALGORITHM be arranged in a row?

b. How many ways can the letters of the word ALGORITHM be arranged in a row if A and L must remain together (in order) as a unit?

c. How many ways can the letters of the word ALGORITHM be arranged in a row if the letters GOR must remain together (in order) as a unit?

33. Six people attend the theater together and sit in a row with exactly six seats. a. How many ways can they be seated together in the row? b. Suppose one of the six is a doctor who must sit on the

aisle in case she is paged. How many ways can the peo- ple be seated together in the row with the doctor in an aisle seat?

c. Suppose the six people consist of three married cou- ples and each couple wants to sit together with the hus- band on the left. How many ways can the six be seated together in the row?

34. Five people are to be seated around a circular table. Two seatings are considered the same if one is a rotation of the other. How many different seatings are possible?

35. Write all the 2-permutations of {W, X, Y, Z}. 36. Write all the 3-permutations of {s, t, u, v}. 37. Evaluate the following quantities.

a. P(6, 4) b. P(6, 6) c. P(6, 3) d. P(6, 1)

38. a. How many 3-permutations are there of a set of five objects?

b. How many 2-permutations are there of a set of eight objects?

39. a. How many ways can three of the letters of the word ALGORITHM be selected and written in a row?

b. How many ways can six of the letters of the word ALGORITHM be selected and written in a row?

c. How many ways can six of the letters of the word ALGORITHM be selected and written in a row if the first letter must be A?

d. How many ways can six of the letters of the word ALGORITHM be selected and written in a row if the first two letters must be OR?

40. Prove that for all integers n ≥ 2, P(n + 1, 3) = n3 − n. 41. Prove that for all integers n ≥ 2,

P(n + 1, 2)− P(n, 2) = 2P(n, 1). 42. Prove that for all integers n ≥ 3,

P(n + 1, 3)− P(n, 3) = 3P(n, 2). 43. Prove that for all integers n ≥ 2, P(n, n) = P(n, n − 1). 44. Prove Theorem 9.2.1 by mathematical induction.

45.H Prove Theorem 9.2.2 by mathematical induction.

46.✶ Prove Theorem 9.2.3 by mathematical induction.

47. A permutation on a set can be regarded as a function from the set to itself. For instance, one permutation of {1, 2, 3, 4} is 2341. It can be identified with the function that sends each position number to the number occupying that posi- tion. Since position 1 is occupied by 2, 1 is sent to 2 or 1 → 2; since position 2 is occupied by 3, 2 is sent to 3 or 2 → 3; and so forth. The entire permutation can be written using arrows as follows:

1 2 3 4 ↓ ↓ ↓ ↓ 2 3 4 1

a. Use arrows to write each of the six permutations of {1, 2, 3}.

b. Use arrows to write each of the permutations of {1, 2, 3, 4} that keep 2 and 4 fixed.

c. Which permutations of {1, 2, 3} keep no elements fixed? d. Use arrows to write all permutations of {1, 2, 3, 4} that

keep no elements fixed.

Answers for Test Yourself 1. n1n2 · · · nk ways 2. an ordering of the elements of the set in a row 3. n! 4. an ordered selection of r of the elements of the set 5. P(n, r) 6. n(n − 1)(n − 2) · · · (n − r + 1); n!

(n−r)!

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

540 Chapter 9 Counting and Probability

9.3 Counting Elements of Disjoint Sets: The Addition Rule The whole of science is nothing more than a refinement of everyday thinking. — Albert Einstein, 1879–1955

In the last section we discussed counting problems that can be solved using possibility trees. In this section we look at counting problems that can be solved by counting the number of elements in the union of two sets, the difference of two sets, or the intersection of two sets.

The basic rule underlying the calculation of the number of elements in a union or difference or intersection is the addition rule. This rule states that the number of elements in a union of mutually disjoint finite sets equals the sum of the number of elements in each of the component sets.

Theorem 9.3.1 The Addition Rule

Suppose a finite set A equals the union of k distinct mutually disjoint subsets A1, A2, . . . , Ak . Then

N (A) = N (A1) + N (A2) + · · · + N (Ak).

A formal proof of this theorem uses mathematical induction and is left to the exercises.

Example 9.3.1 Counting Passwords with Three or Fewer Letters

A computer access password consists of from one to three letters chosen from the 26 in the alphabet with repetitions allowed. How many different passwords are possible?

Solution The set of all passwords can be partitioned into subsets consisting of those of length 1, those of length 2, and those of length 3 as shown in Figure 9.3.1.

Set of All Passwords of Length ≤ 3

passwords of length 1

passwords of length 2

passwords of length 3

Figure 9.3.1

By the addition rule, the total number of passwords equals the number of passwords of length 1, plus the number of passwords of length 2, plus the number of passwords of length 3. Now the

number of passwords of length 1 = 26 because there are 26 letters in the alphabet number of passwords of length 2 = 262 because forming such a word can be

thought of as a two-step process in which there are 26 ways to perform each step

number of passwords of length 3 = 263 because forming such a word can be thought of as a three-step process in which there are 26 ways to perform each step.

Hence the total number of passwords = 26 + 262 + 263 = 18,278. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 541

Example 9.3.2 Counting the Number of Integers Divisible by 5

How many three-digit integers (integers from 100 to 999 inclusive) are divisible by 5?

Solution One solution to this problem was discussed in Example 9.1.4. Another approach uses the addition rule. Integers that are divisible by 5 end either in 5 or in 0. Thus the set of all three-digit integers that are divisible by 5 can be split into two mutually disjoint subsets A1 and A2 as shown in Figure 9.3.2.

Three-Digit Integers That Are Divisible by 5

three-digit integers that end in 0

three-digit integers that end in 5

A1 A2

A1 ∪ A2 = the set of all three-digit integers that are divisible by 5

A1 ∩ A2 = ∅

Figure 9.3.2

Now there are as many three-digit integers that end in 0 as there are possible choices for the left-most and middle digits (because the right-most digit must be a 0). As illus- trated below, there are nine choices for the left-most digit (the digits 1 through 9) and ten choices for the middle digit (the digits 0 through 9). Hence N (A1) = 9 ·10 = 90.

↑ ↑ ↑ 9 choices 10 choices number ends in 0

1, 2, 3, 4, 5, 6, 7, 8, 9 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Similar reasoning (using 5 instead of 0) shows that N (A2) = 90 also. So ⎡

⎣ the number of three-digit integers that are divisible by 5

⎦ = N (A1) + N (A2) = 90 + 90 = 180. ■

The Difference Rule An important consequence of the addition rule is the fact that if the number of elements in a set A and the number in a subset B of A are both known, then the number of elements that are in A and not in B can be computed.

Theorem 9.3.2 The Difference Rule

If A is a finite set and B is a subset of A, then

N (A − B) = N (A)− N (B).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

542 Chapter 9 Counting and Probability

The difference rule is illustrated in Figure 9.3.3.

A (n elements)

B (k elements) A – B (n – k elements)

Figure 9.3.3 The Difference Rule

The difference rule holds for the following reason: If B is a subset of A, then the two sets B and A − B have no elements in common and B ∪ (A − B) = A. Hence, by the addition rule,

N (B) + N (A − B) = N (A). Subtracting N (B) from both sides gives the equation

N (A − B) = N (A)− N (B).

Example 9.3.3 Counting PINs with Repeated Symbols

The PINs discussed in Examples 9.2.2 and 9.2.4 are made from exactly four symbols chosen from the 26 letters of the alphabet and the ten digits, with repetitions allowed.

a. How many PINs contain repeated symbols?

b. If all PINs are equally likely, what is the probability that a randomly chosen PIN contains a repeated symbol?

Solution

a. According to Example 9.2.2, there are 364 = 1,679,616 PINs when repetition is allowed, and by Example 9.2.4, there are 1,413,720 PINs when repetition is not allowed. Thus, by the difference rule, there are

1,679,616− 1,413,720 = 265,896 PINs that contain at least one repeated symbol.

b. By Example 9.2.2 there are 1,679,616 PINs in all, and by part (a) 265,896 of these contain at least one repeated symbol. Thus, by the equally likely probability formula, the probability that a randomly chosen PIN contains a repeated symbol is 265,8961,679,616

∼= 0.158 = 15.8%. ■

An alternative solution to Example 9.3.3(b) is based on the observation that if S is the set of all PINs and A is the set of all PINs with no repeated symbol, then S − A is the set of all PINs with at least one repeated symbol. It follows that

P(S − A) = N (S − A) N (S)

by definition of probability in the equally likely case

= N (S)− N (A) N (S)

by the difference rule

= N (S) N (S)

− N (A) N (S)

by the laws of fractions

= 1− P(A) by definition of probability in the equally likely case ∼= 1− 0.842 by Example 9.2.4 ∼= 0.158 = 15.8%

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 543

This solution illustrates a more general property of probabilities: that the probability of the complement of an event is obtained by subtracting the probability of the event from the number 1. In Section 9.8 we derive this formula from the axioms for probability.

Formula for the Probability of the Complement of an Event

If S is a finite sample space and A is an event in S, then

P(Ac) = 1− P(A).

Example 9.3.4 Number of Python Identifiers of Eight or Fewer Characters

In the computer language Python, identifiers must start with one of 53 symbols: either one of the 52 letters of the upper- and lower-case Roman alphabet or an underscore (_). The initial character may stand alone, or it may be followed by any number of additional characters chosen from a set of 63 symbols: the 53 symbols allowed as an initial character plus the ten digits. Certain keywords, however, such as and, if, print, and so forth, are set aside and may not be used as identifiers. In one implementation of Python there are 31 such reserved keywords, none of which has more than eight characters. How many Python identifiers are there that are less than or equal to eight characters in length?

Solution The set of all Python identifiers with eight or fewer characters can be partitioned into eight subsets—identifiers of length 1, identifiers of length 2, and so on—as shown in Figure 9.3.4. The reserved words have various lengths (all less than or equal to 8), so the set of reserved words is shown overlapping the various subsets.

Set of Python Identifiers with Eight or Fewer Characters

Reserved words

length 1

length 2

length 3

length 4

length 5

length 6

length 7

length 8

Figure 9.3.4

According to the rules for creating Python identifiers, there are

53 potential identifiers of length 1 because there are 53 choices for the first character

53 ·63 potential identifiers of length 2 because the first character can be any one of 53 symbols, and the second character can be any one of 63 symbols

53 ·632 potential identifiers of length 3 because the first character can be any one of 53 symbols, and each of the next two characters can be any one of 63 symbols

...

53 ·637 potential identifiers of length 8 because the first character can be any one of 53 symbols, and each of the next seven characters can be any one of 63 symbols.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

544 Chapter 9 Counting and Probability

Thus, by the addition rule, the number of potential Python identifiers with eight or fewer characters is

53 + 53 ·63 + 53 ·632 + 53 ·633 + 53 ·634 + 53 ·635 + 53 ·636 + 53 ·637

= 53 (

638 − 1 63− 1

)

= 212,133,167,002,880. Now 31 of these potential identifiers are reserved, so by the difference rule, the actual number of Python identifiers with eight or fewer characters is

212,133,167,002,880− 31 = 212,133,167,002,849. ■

Example 9.3.5 Internet Addresses

In order to communicate effectively, each computer in a network needs a distinguishing name called an address. For the Internet this address is currently a 32-bit number called the Internet Protocol (IP) address (although 128-bit addresses are being phased in to accommodate the growth of the Internet). For technical reasons some computers have more than one address, whereas other sets of computers, which use the Internet only sporadically, may share a pool of addresses that are assigned on a temporary basis. Like telephone numbers, IP addresses are divided into parts: one, the network ID, specifies the local network to which a given computer belongs, and the other, the host ID, specifies the particular computer.

An example of an IP address is 10001100 11000000 00100000 10001000, where the 32 bits have been divided into four groups of 8 for easier reading. To make the reading even easier, IP addresses are normally written as “dotted decimals,” in which each group of 8 bits is converted into a decimal number between 0 and 255. For instance, the IP address above converts into 140.192.32.136.

In order to accommodate the various sizes of the local networks connected through the Internet, the network IDs are divided into several classes, the most important of which are called A, B, and C. In every class, a host ID may not consist of either all 0’s or all 1’s.

Class A network IDs are used for very large local networks. The left-most bit is set to 0, and the left-most 8 bits give the full network ID. The remaining 24 bits are used for individual host IDs. However, neither 00000000 nor 01111111 is allowed as a network ID for a class A IP address.

Network ID Host ID

Class A: 0

Class B network IDs are used for medium to large local networks. The two left-most bits are set to 10, and the left-most 16 bits give the full network ID. The remaining 16 bits are used for individual host IDs.

Network ID Host ID

Class B: 1 0

Class C network IDs are used for small local networks. The three left-most bits are set to 110, and the left-most 24 bits give the full network ID. The remaining 8 bits are used for individual host IDs.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 545

Network ID Host ID

Class C: 1 1 0

a. Check that the dotted decimal form of 10001100 11000000 00100000 10001000 is 140.192.32.136.

b. How many Class B networks can there be?

c. What is the dotted decimal form of the IP address for a computer in a Class B network?

d. How many host IDs can there be for a Class B network?

Solution

a. 10001100 = 1 ·27 + 1 ·23 + 1 ·22 = 128 + 8 + 4 = 140 11000000 = 1 ·27 + 1 ·26 = 128 + 64 = 192 00100000 = 1 ·25 = 32 10001000 = 1 ·27 + 1 ·23 = 128 + 8 = 136

b. The network ID for a Class B network consists of 16 bits and begins with 10. Because there are two choices for each of the remaining 14 positions (either 0 or 1), the total number of possible network IDs is 214, or 16,384.

c. The network ID part of a Class B IP address goes from

10000000 00000000 to 10111111 11111111.

As dotted decimals, these numbers range from 128.0 to 191.255 because 100000002 = 12810, 000000002 = 010, 101111112 = 19110, and 111111112 = 25510. Thus the dot- ted decimal form of the IP address of a computer in a Class B network is w.x .y.z, where 128 ≤ w ≤ 191, 0 ≤ x ≤ 255, 0 ≤ y ≤ 255, and 0 ≤ z ≤ 255. However, y and z are not allowed both to be 0 or both to be 255 because host IDs may not consist of either all 0’s or all 1’s.

d. For a class B network, 16 bits are used for host IDs. Having two choices (either 0 or 1) for each of 16 positions gives a potential total of 216, or 65,536, host IDs. But because two of these are not allowed (all 0’s and all 1’s), the total number of host IDs is 65,534.

The Inclusion/Exclusion Rule The addition rule says how many elements are in a union of sets if the sets are mutually disjoint. Now consider the question of how to determine the number of elements in a union of sets when some of the sets overlap. For simplicity, begin by looking at a union of two sets A and B, as shown in Figure 9.3.5.

A B

A B

A B

Figure 9.3.5

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

546 Chapter 9 Counting and Probability

First observe that the number of elements in A ∪ B varies according to the number of elements the two sets have in common. If A and B have no elements in common, then N (A ∪ B) = N (A) + N (B). If A and B coincide, then N (A ∪ B) = N (A). Thus any general formula for N (A ∪ B) must contain a reference to the number of elements the two sets have in common, N (A ∩ B), as well as to N (A) and N (B).

The simplest way to derive a formula for N (A ∪ B) is to reason as follows: The number N (A) counts the elements that are in A and not in B and also the elements that are in both A and B. Similarly, the number N (B) counts the elements that are in B and not in A and also the elements that are in both A and B. Hence when the two numbers N (A) and N (B) are added, the elements that are in both A and B are counted twice. To get an accurate count of the elements in A ∪ B, it is necessary to subtract the number of elements that are in both A and B. Because these are the elements in A ∩ B,

N (A ∪ B) = N (A) + N (B)− N (A ∩ B).Note An alternative proof is outlined in exercise 46 at the end of this section.

A similar analysis gives a formula for the number of elements in a union of three sets, as shown in Theorem 9.3.3.

Theorem 9.3.3 The Inclusion/Exclusion Rule for Two or Three Sets

If A, B, and C are any finite sets, then

N (A ∪ B) = N (A) + N (B)− N (A ∩ B) and

N (A ∪ B ∪ C) = N (A) + N (B) + N (C)− N (A ∩ B)− N (A ∩ C) −N (B ∩ C) + N (A ∩ B ∩ C).

It can be shown using mathematical induction (see exercise 48 at the end of this section) that formulas analogous to those of Theorem 9.3.3 hold for unions of any finite number of sets.

Example 9.3.6 Counting Elements of a General Union

a. How many integers from 1 through 1,000 are multiples of 3 or multiples of 5?

b. How many integers from 1 through 1,000 are neither multiples of 3 nor multiples of 5?

Solution

a. Let A = the set of all integers from 1 through 1,000 that are multiples of 3. Let B = the set of all integers from 1 through 1,000 that are multiples of 5. Then

A ∪ B = the set of all integers from 1 through 1,000 that are multiples of 3 or multiples of 5

and

A ∩ B = the set of all integers from 1 through 1,000 that are multiples of both 3 and 5

= the set of all integers from 1 through 1,000 that are multiples of 15. [Now calculate N (A), N (B), and N (A ∩ B) and use the inclusion/exclusion rule to solve for N (A ∪ B).]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 547

Because every third integer from 3 through 999 is a multiple of 3, each can be rep- resented in the form 3k, for some integer k from 1 through 333. Hence there are 333 multiples of 3 from 1 through 1,000, and so N (A) = 333.

1 2 3 4 5 6 . . . 996 997 998 999 ↕ ↕ ↕ ↕

3 ·1 3 ·2 3 ·332 3 ·333

Similarly, each multiple of 5 from 1 through 1,000 has the form 5k, for some integer k from 1 through 200.

1 2 3 4 5 6 7 8 9 10 . . . 995 996 997 998 999 1,000 ↕ ↕ ↕ ↕

5 ·1 5 ·2 5 ·199 5 ·200

Thus there are 200 multiples of 5 from 1 through 1,000 and N (B) = 200. Finally, each multiple of 15 from 1 through 1,000 has the form 15k, for some integer k from 1 through 66 (since 990 = 66 ·15).

1 2 . . . 15 . . . 30 . . . 975 . . . 990 . . . 999 1,000 ↕ ↕ ↕ ↕

15 ·1 15 ·2 15 ·65 15 ·66

Hence there are 66 multiples of 15 from 1 through 1,000, and N (A ∩ B) = 66. It follows by the inclusion/exclusion rule that

N (A ∪ B) = N (A) + N (B)− N (A ∩ B) = 333 + 200− 66 = 467.

Thus, 467 integers from 1 through 1,000 are multiples of 3 or multiples of 5.

b. There are 1,000 integers from 1 through 1,000, and by part (a), 467 of these are multi- ples of 3 or multiples of 5. Thus, by the set difference rule, there are 1,000− 467 = 533 that are neither multiples of 3 nor multiples of 5. ■

Note that the solution to part (b) of Example 9.3.6 hid a use of De Morgan’s law. The number of elements that are neither in A nor in B is N (Ac ∩ Bc), and by De Morgan’s law, Ac ∩ Bc = (A ∪ B)c. So N ((A ∪ B)c) was then calculated using the set difference rule: N ((A ∪ B)c) = N (U )− N (A ∪ B), where the universe U was the set of all integers from 1 through 1,000. Exercises 37–39 at the end of this section explore this technique further.

Example 9.3.7 Counting the Number of Elements in an Intersection

A professor in a discrete mathematics class passes out a form asking students to check all the mathematics and computer science courses they have recently taken. The finding is that out of a total of 50 students in the class,

30 took precalculus; 16 took both precalculus and Java; 18 took calculus; 8 took both calculus and Java; 26 took Java; 47 took at least one of the three courses. 9 took both precalculus and calculus;

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

548 Chapter 9 Counting and Probability

Note that when we write “30 students took precalculus,” we mean that the total num- ber of students who took precalculus is 30, and we allow for the possibility that some of these students may have taken one or both of the other courses. If we want to say that 30 students took precalculus only (and not either of the other courses), we will say so explicitly.

a. How many students did not take any of the three courses?

b. How many students took all three courses?

c. How many students took precalculus and calculus but not Java? How many students took precalculus but neither calculus nor Java?

Solution

a. By the difference rule, the number of students who did not take any of the three courses equals the number in the class minus the number who took at least one course. Thus the number of students who did not take any of the three courses is

50− 47 = 3. b. Let

P = the set of students who took precalculus C = the set of students who took calculus J = the set of students who took Java.

Then, by the inclusion/exclusion rule,

N (P ∪ C ∪ J ) = N (P) + N (C) + N (J )− N (P ∩ C)− N (P ∩ J ) − N (C ∩ J ) + N (P ∩ C ∩ J )

Substituting known values, we get

47 = 30 + 26 + 18− 9− 16− 8 + N (P ∩ C ∩ J ). Solving for N (P ∩ C ∩ J ) gives

N (P ∩ C ∩ J ) = 6. Hence there are six students who took all three courses. In general, if you know any seven of the eight terms in the inclusion/exclusion formula for three sets, you can solve for the eighth term.

c. To answer the questions of part (c), look at the diagram in Figure 9.3.6.

11 10

6

7

8

3 2

P J

C

The number of students who took all three courses

The number of students who took both precalcules and calcules but not Java 3

Figure 9.3.6

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 549

Since N (P ∩ C ∩ J ) = 6, put the number 6 inside the innermost region. Then work outward to find the numbers of students represented by the other regions of the dia- gram. For example, since nine students took both precalculus and calculus and six took all three courses, 9− 6 = 3 students took precalculus and calculus but not Java. Similarly, since 16 students took precalculus and calculus and six took all three courses, 16− 6 = 10 students took precalculus and calculus but not Java. Now the total num- ber of students who took precalculus is 30. Of these 30, three also took calculus but not Java, ten took Java but not calculus, and six took both calculus and Java. That leaves 11 students who took precalculus but neither of the other two courses.

A similar analysis can be used to fill in the numbers for the other regions of the diagram. ■

Test Yourself 1. The addition rule says that if a finite set A equals the union

of k distinct mutually disjoint subsets A1, A2, . . . , Ak , then _____.

2. The difference rule says that if A is a finite set and B is a subset of A, then _____.

3. If S is a finite sample space and A is an event in S, then the probability of Ac equals _____.

4. The inclusion/exclusion rule for two sets says that if A and B are any finite sets, then _____.

5. The inclusion/exclusion rule for three sets says that if A, B, and C are any finite sets, then _____.

Exercise Set 9.3 1. a. How many bit strings consist of from one through

four digits? (Strings of different lengths are con- sidered distinct. Thus 10 and 0010 are distinct strings.)

b. How many bit strings consist of from five through eight digits?

2. a. How many strings of hexadecimal digits consist of from one through three digits? (Recall that hexadecimal num- bers are constructed using the 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.)

b. How many strings of hexadecimal digits consist of from two through five digits?

3. a. How many integers from 1 through 999 do not have any repeated digits?

b. How many integers from 1 through 999 have at least one repeated digit?

c. What is the probability that an integer chosen at random from 1 through 999 has at least one repeated digit?

4. How many arrangements in a row of no more than three let- ters can be formed using the letters of the word NETWORK (with no repetitions allowed)?

5. a. How many five-digit integers (integers from 10,000 through 99,999) are divisible by 5?

b. What is the probability that a five-digit integer chosen at random is divisible by 5?

6. In a certain state, license plates consist of from zero to three letters followed by from zero to four digits, with the provi- sion, however, that a blank plate is not allowed. a. How many different license plates can the state produce? b. Suppose 85 letter combinations are not allowed because

of their potential for giving offense. How many different license plates can the state produce?

7. In another state, all license plates consist of from four to six symbols chosen from the 26 letters of the alphabet together with the ten digits 0–9. a. How many license plates are possible if repetition of

symbols is allowed? b. How many license plates do not contain any repeated

symbol? c.H How many license plates have at least one repeated sym-

bol? d. What is the probability that a license plate chosen at ran-

dom has a repeated symbol?

8. At a certain company, passwords must be from 3–5 symbols long and composed of the 26 letters of the alphabet, the ten digits 0–9, and the 14 symbols !,@,#,$,%,ˆ,&, ∗,(,),−,+,{, and }. a. How many passwords are possible if repetition of sym-

bols is allowed? b. How many passwords contain no repeated symbols?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

550 Chapter 9 Counting and Probability

c. How many passwords have at least one repeated sym- bol?

d. What is the probability that a password chosen at ran- dom has n repeated symbol?

9. a. Consider the following algorithm segment:

for i := 1 to 4 for j := 1 to i [Statements in body of inner loop. None contain branching statements that lead outside the loop.] next j

next i

How many times will the inner loop be iterated when the algorithm is implemented and run?

b. Let n be a positive integer, and consider the following algorithm segment:

for i := 1 to n for j := 1 to i [Statements in body of inner loop. None contain branching statements that lead outside the loop.] next j

next i

How many times will the inner loop be iterated when the algorithm is implemented and run?

10.✶ A calculator has an eight-digit display and a decimal point that is located at the extreme right of the number displayed, at the extreme left, or between any pair of digits. The cal- culator can also display a minus sign at the extreme left of the number. How many distinct numbers can the calcula- tor display? (Note that certain numbers are equal, such as 1.9, 1.90, and 01.900, and should, therefore, not be counted twice.)

11. a. How many ways can the letters of the word QUICK be arranged in a row?

b. How many ways can the letters of the word QUICK be arranged in a row if the Q and the U must remain next to each other in the order QU?

c. How many ways can the letters of the word QUICK be arranged in a row if the letters QU must remain together but may be in either the order QU or the order UQ?

12. a. How many ways can the letters of the word THEORY be arranged in a row?

b. How many ways can the letters of the word THEORY be arranged in a row if T and H must remain next to each other as either TH or HT ?

13. A group of eight people are attending the movies together. a. Two of the eight insist on sitting side-by-side. In how

many ways can the eight be seated together in a row?

b. Two of the people do not like each other and do not want to sit side-by-side. Now how many ways can the eight be seated together in a row?

14. An early compiler recognized variable names according to the following rules: Numeric variable names had to begin with a letter, and then the letter could be followed by another letter or a digit or by nothing at all. String variable names had to begin with the symbol $ followed by a letter, which could then be followed by another letter or a digit or by nothing at all. How many distinct variable names were recognized by this compiler?

15.H Identifiers in a certain database language must begin with a letter, and then the letter may be followed by other charac- ters, which can be letters, digits, or underscores (_). How- ever, 82 keywords (all consisting of 15 or fewer charac- ters) are reserved and cannot be used as identifiers. How many identifiers with 30 or fewer characters are possible? (Write the answer using summation notation and evaluate it using a formula from Section 5.2.)

16. a. If any seven digits could be used to form a tele- phone number, how many seven-digit telephone num- bers would not have any repeated digits?

b. How many seven-digit telephone numbers would have at least one repeated digit?

c. What is the probability that a randomly chosen seven- digit telephone number would have at least one repeated digit?

17. a. How many strings of four hexadecimal digits do not have any repeated digits?

b. How many strings of four hexadecimal digits have at least one repeated digit?

c. What is the probability that a randomly chosen string of four hexadecimal digits has at least one repeated digit?

18. Just as the difference rule gives rise to a formula for the probability of the complement of an event, so the addi- tion and inclusion/exclusion rules give rise to formulas for the probability of the union of mutually disjoint events and for a general union of (not necessarily mutually exclusive) events. a. Prove that for mutually disjoint events A and B,

P(A ∪ B) = P(A) + P(B). b. Prove that for any events A and B.

P(A ∪ B) = P(A) + P(B)− P(A ∩ B). 19.H A combination lock requires three selections of num-

bers, each from 1 through 39. Suppose the lock is con- structed in such a way that no number can be used twice in a row but the same number may occur both first and third. For example, 20 13 20 would be acceptable, but 20 20 13 would not. How many different combinations are possible?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 551

20.✶ a. How many integers from 1 through 100,000 contain the digit 6 exactly once?

b. How many integers from 1 through 100,000 contain the digit 6 at least once?

c. If an integer is chosen at random from 1 through 100,000, what is the probability that it contains two or more occurrences of the digit 6?

21.✶H Six new employees, two of whom are married to each other, are to be assigned six desks that are lined up in a row. If the assignment of employees to desks is made randomly, what is the probability that the married couple will have nonad- jacent desks? (Hint: First find the probability that the cou- ple will have adjacent desks, and then subtract this number from 1.)

22.✶ Consider strings of length n over the set {a, b, c, d}. a. How many such strings contain at least one pair of adja-

cent characters that are the same? b. If a string of length ten over {a, b, c, d} is chosen at ran-

dom, what is the probability that it contains at least one pair of adjacent characters that are the same?

23. a. How many integers from 1 through 1,000 are multiples of 4 or multiples of 7?

b. Suppose an integer from 1 through 1,000 is chosen at random. Use the result of part (a) to find the probability that the integer is a multiple of 4 or a multiple of 7.

c. How many integers from 1 through 1,000 are neither multiples of 4 nor multiples of 7?

24. a. How many integers from 1 through 1,000 are multiples of 2 or multiples of 9?

b. Suppose an integer from 1 through 1,000 is chosen at random. Use the result of part (a) to find the probability that the integer is a multiple of 2 or a multiple of 9.

c. How many integers from 1 through 1,000 are neither multiples of 2 nor multiples of 9?

25. Counting Strings: a. Make a list of all bit strings of lengths zero, one, two,

three, and four that do not contain the bit pattern 111. b. For each integer n ≥ 0, let dn = the number of bit strings

of length n that do not contain the bit pattern 111. Find d0, d1, d2, d3, and d4.

c. Find a recurrence relation for d0, d1, d2, . . . . d. Use the results of parts (b) and (c) to find the number

of bit strings of length five that do not contain the pat- tern 111.

26. Counting Strings: Consider the set of all strings of a’s, b’s, and c’s. a. Make a list of all of these strings of lengths zero, one,

two, and three that do not contain the pattern aa. b. For each integer n ≥ 0, let sn = the number of strings

of a’s, b’s, and c’s of length n that do not contain the pattern aa. Find s0, s1, s2, and s3.

c.H Find a recurrence relation for s0, s1, s2, . . .. d. Use the results of parts (b) and (c) to find the number

of strings of a’s, b’s, and c’s of length four that do not contain the pattern aa.

e.H Use the technique described in Section 5.8 to find an explicit formula for s0, s1, s2, . . . .

27. For each integer n ≥ 0, let ak be the number of bit strings of length n that do not contain the pattern 101. a. Show that ak = ak−1 + ak−3 + ak−4 + · · · + a0 + 2, for

all integers k ≥ 3. b. Use the result of part (a) to show that if k ≥ 3, then

ak = 2ak−1 − ak−2 + ak−3. 28.✶ For each integer n ≥ 2 let an be the number of permu-

tations of {1, 2, 3, . . . , n} in which no number is more than one place removed from its “natural” position. Thus a1 = 1 since the one permutation of {1}, namely 1, does not move 1 from its natural position. Also a2 = 2 since nei- ther of the two permutations of {1,2}, namely 12 and 21, moves either number more than one place from its natural position. a. Find a3. b. Find a recurrence relation for a1, a2, a3, . . . .

29. Refer to Example 9.3.5. a. Write the following IP address in dotted decimal form:

11001010 00111000 01101011 11101110

b. How many Class A networks can there be? c. What is the dotted decimal form of the IP address for a

computer in a Class A network? d. How many host IDs can there be for a Class A network? e. How many Class C networks can there be? f. What is the dotted decimal form of the IP address for a

computer in a Class C network? g. How many host IDs can there be for a Class C network? h. How can you tell, by looking at the first of the four num-

bers in the dotted decimal form of an IP address, what kind of network the address is from? Explain.

i. An IP address is 140.192.32.136. What class of network does it come from?

j. An IP address is 202.56.107.238. What class of network does it come from?

30.✶ A row in a classroom has n seats. Let sn be the number of ways nonempty sets of students can sit in the row so that no student is seated directly adjacent to any other stu- dent. (For instance, a row of three seats could contain a sin- gle student in any of the seats or a pair of students in the two outer seats. Thus s3 = 4.) Find a recurrence relation for s1, s2, s3, . . . .

31. Assume that birthdays are equally likely to occur in any one of the 12 months of the year. a. Given a group of four people, A, B, C , and D, what is

the total number of ways in which birth months could be associated with A, B, C , and D? (For instance, A and B might have been born in May, C in September, and D in February. As another example, A might have been born in January, B in June, C in March, and D in October.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

552 Chapter 9 Counting and Probability

b. How many ways could birth months be associated with A, B, C , and D so that no two people would share the same birth month?

c. How many ways could birth months be associated with A, B, C , and D so that at least two people would share the same birth month?

d. What is the probability that at least two people out of A, B, C , and D share the same birth month?

e. How large must n be so that in any group of n people, the probability that two or more share the same birth month is at least 50%?

32.H Assuming that all years have 365 days and all birthdays occur with equal probability, how large must n be so that in any randomly chosen group of n people, the probability that two or more have the same birthday is at least 1/2? (This is called the birthday problem. Many people find the answer surprising.)

33. A college conducted a survey to explore the academic inter- ests and achievements of its students. It asked students to place checks beside the numbers of all the statements that were true of them. Statement #1 was “I was on the honor roll last term,” statement #2 was “I belong to an academic club, such as the math club or the Spanish club,” and state- ment #3 was “I am majoring in at least two subjects.” Out of a sample of 100 students, 28 checked #1, 26 checked #2, and 14 checked #3, 8 checked both #1 and #2, 4 checked both #1 and #3, 3 checked both #2 and #3, and 2 checked all three statements. a. How many students checked at least one of the state-

ments? b. How many students checked none of the statements? c. Let H be the set of students who checked #1, C the set

of students who checked #2, and D the set of students who checked #3. Fill in the numbers for all eight regions of the diagram below.

Sample of Students

H

C

D

d. How many students checked #1 and #2 but not #3? e. How many students checked #2 and #3 but not #1? f. How many students checked #2 but neither of the other

two?

34. A study was done to determine the efficacy of three differ- ent drugs—A, B, and C—in relieving headache pain. Over

the period covered by the study, 50 subjects were given the chance to use all three drugs. The following results were obtained:

21 reported relief from drug A.

21 reported relief from drug B.

31 reported relief from drug C.

9 reported relief from both drugs A and B.

14 reported relief from both drugs A and C.

15 reported relief from both drugs B and C.

41 reported relief from at least one of the drugs.

Note that some of the 21 subjects who reported relief from drug A may also have reported relief from drugs B or C . A similar occurrence may be true for the other data. a. How many people got relief from none of the drugs? b. How many people got relief from all three drugs? c. Let A be the set of all subjects who got relief from drug

A, B the set of all subjects who got relief from drug B, and C the set of all subjects who got relief from drug C . Fill in the numbers for all eight regions of the diagram below.

A

B

C

Sample of Subjects

d. How many subjects got relief from A only?

35. An interesting use of the inclusion/exclusion rule is to check survey numbers for consistency. For example, sup- pose a public opinion polltaker reports that out of a national sample of 1,200 adults, 675 are married, 682 are from 20 to 30 years old, 684 are female, 195 are married and are from 20 to 30 years old, 467 are married females, 318 are females from 20 to 30 years old, and 165 are married females from 20 to 30 years old. Are the polltaker’s figures consistent? Could they have occurred as a result of an actual sample survey?

36. Fill in the reasons for each step below. If A and B are sets in a finite universe U , then

N (A ∩ B) = N (U )− N ((A ∩ B)c) (a) = N (U )− N (Ac ∪ Bc) (b) = N (U )− (N (Ac) + N (Bc)− N (Ac ∩ Bc)) (c) .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.3 Counting Elements of Disjoint Sets: The Addition Rule 553

For each of exercises 37–39 below, the number of elements in a certain set can be found by computing the number in some larger universe that are not in the set and subtracting this from the total. In each case, as indicated by exercise 34, De Morgan’s laws and the inclusion/exclusion rule can be used to compute the number that are not in the set.

37. How many positive integers less than 1,000 have no com- mon factors with 1,000?

38.✶ How many permutations of abcde are there in which the first character is a, b, or c and the last character is c, d, or e?

39.✶ How many integers from 1 through 999,999 contain each of the digits 1, 2, and 3 at least once? (Hint: For each i = 1, 2, and 3, let Ai be the set of all integers from 1 through 999,999 that do not contain the digit i .)

For 40 and 41, use the definition of the Euler phi function φ on page 396.

40.H Use the inclusion/exclusion principle to prove the follow- ing: If n = pq, where p and q are distinct prime numbers, then ϕ(n) = (p − 1)(q − 1).

41. Use the inclusion/exclusion principle to prove the follow- ing: If n = pqr , where p, q , and r are distinct prime num- bers, then ϕ(n) = (p − 1)(q − 1)(r − 1).

42. A gambler decides to play successive games of blackjack until he loses three times in a row. (Thus the gambler could play five games by losing the first, winning the second, and losing the final three or by winning the first two and los- ing the final three. These possibilities can be symbolized as LWLLL and WWLLL.) Let gn be the number of ways the gambler can play n games. a. Find g3, g4, and g5. b. Find g6. c.H Find a recurrence relation for g3, g4, g5, . . ..

43.✶ A derangement of the set {1, 2, . . . , n} is a permutation that moves every element of the set away from its “natu- ral” position. Thus 21 is a derangement of {1, 2}, and 231 and 312 are derangements of {1, 2, 3}. For each positive integer n, let dn be the number of derangements of the set {1, 2, . . . , n}. a. Find d1, d2, and d3. b. Find d4. c.H Find a recurrence relation for d1, d2, d3, . . . .

44. Note that a product x1x2x3 may be parenthesized in two different ways: (x1x2)x3 and x1(x2x3). Similarly, there are several different ways to parenthesize x1x2x3x4. Two such ways are (x1x2)(x3x4) and x1((x2x3)x4). Let Pn be the num- ber of different ways to parenthesize the product x1x2 . . . x4. Show that if P1 = 1, then

Pn = n−1∑

k=1 Pk Pn−k for all integers n ≥ 2.

(It turns out that the sequence P1, P2, P3, . . . is the same as the sequence of Catalan numbers: Pn = Cn−1 for all inte- gers n ≥ 1. See Example 5.6.4.)

45. Use mathematical induction to prove Theorem 9.3.1.

46. Prove the inclusion/exclusion rule for two sets A and B by showing that A ∪ B can be partitioned into A ∩ B, A − (A ∩ B), and B − (A ∩ B), and then using the addi- tion and difference rules.

47. Prove the inclusion/exclusion rule for three sets.

48.✶H Use mathematical induction to prove the general inclu- sion/exclusion rule:

If A1, A2, . . . , An are finite sets, then

N (A1 ∪ A2 ∪ · · · ∪ An) = ∑

1≤i≤n N (Ai )−

1≤i< j≤n N (Ai ∩ A j )

+ ∑

1≤i< j<k≤n N (Ai ∩ A j ∩ Ak)

− · · · + (−1)n+1 N (A1 ∩ A2 ∩ · · · ∩ An). (The notation

∑ 1≤i< j≤n N (Ai ∩ A j ) means that quantities

of the form N (Ai ∩ A j ) are to be added together for all integers i and j with 1 ≤ i < j ≤ n.)

49.✶ A circular disk is cut into n distinct sectors, each shaped like a piece of pie and all meeting at the center point of the disk. Each sector is to be painted red, green, yellow, or blue in such a way that no two adjacent sectors are painted the same color. Let Sn be the number of ways to paint the disk. a.H Find a recurrence relation for Sk in terms of Sk−1 and

Sk−2 for each integer k ≥ 4. b. Find an explicit formula for Sn for n ≥ 2.

Answers for Test Yourself 1. the number of elements in A equals N (A1) + N (A2) + . . . + N (An) 2. the number of elements in A − B is the difference between the number of elements in A and the number of elements in B, that is, N (A − B) = N (A)− N (B). 3. 1− P(A) 4. N (A ∪ B) = N (A) + N (B)− N (A ∩ B) 5. N (A ∪ B ∪ C) = N (A) + N (B) + N (C)− N (A ∩ B)− N (A ∩ C)− N (B ∩ C) + N (A ∩ B ∩ C)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

554 Chapter 9 Counting and Probability

9.4 The Pigeonhole Principle The shrewd guess, the fertile hypothesis, the courageous leap to a tentative conclusion—these are the most valuable coin of the thinker at work — Jerome S. Bruner, 1960

The pigeonhole principle states that if n pigeons fly into m pigeonholes and n > m, then at least one hole must contain two or more pigeons. This principle is illustrated in Figure 9.4.1 for n = 5 and m = 4. Illustration (a) shows the pigeons perched next to their holes, and (b) shows the correspondence from pigeons to pigeonholes. The pigeonhole principle is sometimes called the Dirichlet box principle because it was first stated for- mally by J. P. G. L. Dirichlet (1805–1859).

1 2

3 4

(a) (b)

3

5

2

1

1

2

3

4

5

1

2

3

4

Pigeons Pigeonholes

4

Figure 9.4.1

Illustration (b) suggests the following mathematical way to phrase the principle.

Pigeonhole Principle

A function from one finite set to a smaller finite set cannot be one-to-one: There must be a least two elements in the domain that have the same image in the co-domain.

Thus an arrow diagram for a function from a finite set to a smaller finite set must have at least two arrows from the domain that point to the same element of the co-domain. In Figure 9.4.1(b), arrows from pigeons 1 and 4 both point to pigeonhole 3.

Since the truth of the pigeonhole principle is easy to accept on an intuitive basis, we move immediately to applications, leaving a formal proof to the end of the section. Applications of the pigeonhole principle range from the totally obvious to the extremely subtle. A representative sample is given in the examples and exercises that follow.

Example 9.4.1 Applying the Pigeonhole Principle

a. In a group of six people, must there be at least two who were born in the same month? In a group of thirteen people, must there be at least two who were born in the same month? Why?

b. Among the residents of New York City, must there be at least two people with the same number of hairs on their heads? Why?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.4 The Pigeonhole Principle 555

Solution

a. A group of six people need not contain two who were born in the same month. For instance, the six people could have birthdays in each of the six months January through June.

A group of thirteen people, however, must contain at least two who were born in the same month, for there are only twelve months in a year and 13 > 12. To get at the essence of this reasoning, think of the thirteen people as the pigeons and the twelve months of the year as the pigeonholes. Denote the thirteen people by the symbols x1, x2, . . . , x13 and define a function B from the set of people to the set of twelve months as shown in the following arrow diagram.

x1

x2

x12

x 13

B Jan

Feb

Dec

B(xi) = birth month of xi

13 people (pigeons) 12 months (pigeonholes)

The pigeonhole principle says that no matter what the particular assignment of months to people, there must be at least two arrows pointing to the same month. Thus at least two people must have been born in the same month.

b. The answer is yes. In this example the pigeons are the people of New York City and the pigeonholes are all possible numbers of hairs on any individual’s head. Call the population of New York City P . It is known that P is at least 5,000,000. Also the maximum number of hairs on any person’s head is known to be no more than 300,000. Define a function H from the set of people in New York City {x1, x2, . . . , x p} to the set {0, 1, 2, 3, . . . , 300 000}, as shown below.

x1

x2

x3

xp

H

0

1

2

300,000

H(xi) = the number of

People in New York City (pigeons)

Possible number of hairs on a person's head (pigeonholes)

hairs on xi 's head

Since the number of people in New York City is larger than the number of possible hairs on their heads, the function H is not one-to-one; at least two arrows point to the same number. But that means that at least two people have the same number of hairs on their heads. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

556 Chapter 9 Counting and Probability

Example 9.4.2 Finding the Number to Pick to Ensure a Result

A drawer contains ten black and ten white socks. You reach in and pull some out without looking at them. What is the least number of socks you must pull out to be sure to get a matched pair? Explain how the answer follows from the pigeonhole principle.

Solution If you pick just two socks, they may have different colors. But when you pick a third sock, it must be the same color as one of the socks already chosen. Hence the answer is three.

This answer could be phrased more formally as follows: Let the socks pulled out be denoted s1, s2, s3, . . . , sn and consider the function C that sends each sock to its color, as shown below.

s1

s2

sn

C

C(si ) = color of si

Socks pulled out (pigeons) Colors (pigeonholes)

white

black

If n = 2, C could be a one-to-one correspondence (if the two socks pulled out were of different colors). But if n > 2, then the number of elements in the domain of C is larger than the number of elements in the co-domain of C . Thus by the pigeonhole principle, C is not one-to-one: C(si ) = C(s j ) for some si ̸= s j . This means that if at least three socks are pulled out, then at least two of them have the same color. ■

Example 9.4.3 Selecting a Pair of Integers with a Certain Sum

Let A = {1, 2, 3, 4, 5, 6, 7, 8}. a. If five integers are selected from A, must at least one pair of the integers have a

sum of 9?

b. If four integers are selected from A, must at least one pair of the integers have a sum of 9?

Solution

a. Yes. Partition the set A into the following four disjoint subsets:

{1, 8}, {2, 7}, {3, 6}, and {4, 5} Observe that each of the integers in A occurs in exactly one of the four subsets and that the sum of the integers in each subset is 9. Thus if five integers from A are chosen, then by the pigeonhole principle, two must be from the same subset. It follows that the sum of these two integers is 9.

To see precisely how the pigeonhole principle applies, let the pigeons be the five selected integers (call them a1, a2, a3, a4, and a5) and let the pigeonholes be the sub- sets of the partition. The function P from pigeons to pigeonholes is defined by letting P(ai ) be the subset that contains ai .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.4 The Pigeonhole Principle 557

a1

a2

a3

a4

a5

P

P(ai ) = the subset that

The 5 selected integers (pigeons)

The 4 subsets in the partition of A (pigeonholes)

{1, 8}

{2, 7}

{3, 6}

{4, 5}

contains ai

The function P is well defined because for each integer ai in the domain, ai belongs to one of the subsets (since the union of the subsets is A) and ai does not belong to more than one subset (since the subsets are disjoint).

Because there are more pigeons than pigeonholes, at least two pigeons must go to the same hole. Thus two distinct integers are sent to the same set. But that implies that those two integers are the two distinct elements of the set, so their sum is 9. More formally, by the pigeonhole principle, since P is not one-to-one, there are integers ai and a j such that

P(ai ) = P(a j ) and ai ̸= a j . But then, by definition of P , ai and a j belong to the same subset. Since the elements in each subset add up to 9, ai + a j = 9.

b. The answer is no. This is a case where the pigeonhole principle does not apply; the number of pigeons is not larger than the number of pigeonholes. For instance, if you select the numbers 1, 2, 3, and 4, then since the largest sum of any two of these numbers is 7, no two of them add up to 9. ■

Application to Decimal Expansions of Fractions One important consequence of the piegonhole principle is the fact that

the decimal expansion of any rational number either terminates or repeats.

A terminating decimal is one like 3.625,

and a repeating decimal is one like 2.38246,

where the bar over the digits 246 means that these digits are repeated forever. Note Strictly speaking, a terminating decimal like 3.625 can be regarded as a repeating decimal by adding trailing zeros: 3.625 = 3.6250. This can also be written as 3.6249.

Recall that a rational number is one that can be written as a ratio of integers—in other words, as a fraction. Recall also that the decimal expansion of a fraction is obtained by dividing its numerator by its denominator using long division. For example, the decimal expansion of 4/33 is obtained as follows:

.1 2 1 2 1 2 1 2. . . 33 4 0 0 0 0 0 0 0 0 0 0 0

3 3 7 0 6 6

4 0 3 3

7 0 6 6

4...

These are the same number.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

558 Chapter 9 Counting and Probability

Because the number 4 reappears as a remainder in the long-division process, the sequence of quotients and remainders that give the digits of the decimal expansion repeats forever; hence the digits of the decimal expansion repeat forever.

In general, when one integer is divided by another, it is the pigeonhole principle (together with the quotient-remainder theorem) that guarantees that such a repetition of remainders and hence decimal digits must always occur. This is explained in the following example. The analysis in the example uses an obvious generalization of the pigeonhole principle, namely that a function from an infinite set to a finite set cannot be one-to-one.

Example 9.4.4 The Decimal Expansion of a Fraction

Consider a fraction a/b, where for simplicity a and b are both assumed to be positive. The decimal expansion of a/b is obtained by dividing the a by the b as illustrated here for a = 3 and b = 14.

Let r0 = a and let r1, r2, r3, . . . be the successive remainders obtained in the long division of a by b. By the quotient-remainder theorem, each remainder must be between 0 and b − 1. (In this example, a is 3 and b is 14, and so the remainders are from 0 to 13.) If some remainder ri = 0, then the division terminates and a/b has a terminating decimal expansion. If no ri = 0, then the division process and hence the sequence of remainders continues forever. By the pigeonhole principle, since there are more remainders than

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.4 The Pigeonhole Principle 559

values that the remainders can take, some remainder value must repeat: r j = rk , for some indices j and k with j < k. This is illustrated below for a = 3 and b = 14.

r0

r1

r2

r7

0

1

3

2

13

F

F(ri) = value of ri

Sequence of remainders Values of remainders when b = 14

If follows that the decimal digits obtained from the divisions between r j and rk−1 repeat forever. In the case of 3/14, the repetition begins with r7 = 2 = r1 and the decimal expansion repeats the quotients obtained from the divisions from r1 through r6 forever: 3/14 = 0.2142857. ■

Note that since the decimal expansion of any rational number either terminates or repeats, if a number has a decimal expansion that neither terminates nor repeats, then it cannot be rational. Thus, for example, the following number cannot be rational: 0.01011011101111011111 . . . (where each string of 1’s is one longer than the previous string).

Generalized Pigeonhole Principle A generalization of the pigeonhole principle states that if n pigeons fly into m pigeonholes and, for some positive integer k, k < n/m, then at least one pigeonhole contains k + 1 or more pigeons. This is illustrated in Figure 9.4.2 for m = 4, n = 9, and k = 2. Since 2 < 9/4 = 2.25, at least one pigeonhole contains three (2 + 1) or more pigeons. (In this example, pigeonhole 3 contains three pigeons.)

6

)b()a(

1 2 3 4 5 6 7 8 9

1

2

3

4

Pigeons Pigeonholes

13 8 21 4

47 932 5

Figure 9.4.2

Generalized Pigeonhole Principle

For any function f from a finite set X with n elements to a finite set Y with m elements and for any positive integer k, if k < n/m, then there is some y ∈ Y such that y is the image of at least k + 1 distinct elements of X .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

560 Chapter 9 Counting and Probability

Example 9.4.5 Applying the Generalized Pigeonhole Principle

Show how the generalized pigeonhole principle implies that in a group of 85 people, at least 4 must have the same last initial.

Solution In this example the pigeons are the 85 people and the pigeonholes are the 26 possible last initials of their names. Note that

3 < 85/26 ∼= 3.27. Consider the function L from people to initials defined by the following arrow diagram.

x1

x2

x26

x85

L

L(xi ) = the initial of

)selohnoegip( slaitini 62)snoegip( elpoep 58

A

B

Z

xi 's last name

Since 3 < 85/26, the generalized pigeonhole principle states that some initial must be the image of at least four (3 + 1) people. Thus at least four people have the same last initial. ■

Consider the following contrapositive form of the generalized pigeonhole principle.

Generalized Pigenohole Principle (Contrapositive Form)

For any function f from a finite set X with n elements to a finite set Y with m elements and for any positive integer k, if for each y ∈ Y, f −1(y) has at most k elements, then X has at most km elements; in other words, n ≤ km.

You may find it natural to use the contrapositive form of the generalized pigeonhole principle in certain situations. For instance, the result of Example 9.4.5 can be explained as follows:

Suppose no 4 people out of the 85 had the same last initial. Then a tmost 3 would share any particular one. By the generalized pigeonhole principle (contrapositive form), this would imply that the total number of people is at most 3 ·26 = 78. But this contradicts the fact that there are 85 people in all. Hence at least 4 people share a last initial.

Example 9.4.6 Using the Contrapositive Form of the Generalized Pigeonhole Principle

There are 42 students who are to share 12 computers. Each student uses exactly 1 com- puter, and no computer is used by more than 6 students. Show that at least 5 computers are used by 3 or more students.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.4 The Pigeonhole Principle 561

Solution

a. Using an Argument by Contradiction: Suppose not. Suppose that 4 or fewer comput- ers are used by 3 or more students. [A contradiction will be derived.] Then 8 or more computers are used by 2 or fewer students. Divide the set of computers into two sub- sets: C1 and C2. Into C1 place 8 of the computers used by 2 or fewer students; into C2 place the computers used by 3 or more students plus any remaining computers (to make a total of 4 computers in C2). (See Figure 9.4.3.)

The Set of 12 Computers

Each of these computers serves at most 2 students. So the maximum number served by these computers is 2 ⋅ 8 = 16.

Some or all of these computers serve 3 or more students. Each computer serves at most 6 students. So the maximum number served by these computers is 6 ⋅ 4 = 24.

C2C1

Figure 9.4.3

Since at most 6 students are served by any one computer, by the contrapositive form of the generalized pigeonhole principle, the computers in set C2 serve at most 6 ·4 = 24 students. Since at most 2 students are served by any one computer in C1, by the generalized pigeonhole principle (contrapositive form), the computers in set C1 serve at most 2 ·8 = 16 students. Hence the total number of students served by the computers is 24 + 16 = 40. But this contradicts the fact that each of the 42 students is served by a computer. Therefore, the supposition is false: At least 5 computers are used by 3 or more students.

b. Using a Direct Argument: Let k be the number of computers used by 3 or more stu- dents. [We must show that k ≥ 5.] Because each computer is used by at most 6 students, these computers are used by at most 6k students (by the contrapositive form of the generalized pigeonhole principle). Each of the remaining 12− k computers is used by at most 2 students. Hence, taken together, they are used by at most 2(12− k) = 24− 2k students (again, by the contrapositive form of the generalized pigeonhole principle). Thus the maximum number of students served by the computers is 6k + (24− 2k) = 4k + 24. Because 42 students are served by the computers, 4k+24≥42. Solving for k gives that k ≥ 4.5, and since k is an integer, this implies that k ≥ 5 [as was to be shown]. ■

Proof of the Pigeonhole Principle The truth of the pigeonhole principle depends essentially on the sets involved being finite. Recall from Section 7.4 that a set is called finite if, and only if, it is the empty set or there is a one-to-one correspondence from {1, 2, . . . , n} to it, where n is a positive integer. In the first case the number of elements in the set is said to be 0, and in the second case it is said to be n. A set that is not finite is called infinite.

Thus any finite set is either empty or can be written in the form {x1, x2, . . . , xn} where n is a positive integer.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

562 Chapter 9 Counting and Probability

Theorem 9.4.1 The Pigeonhole Principle

For any function f from a finite set X with n elements to a finite set Y with m elements, if n > m, then f is not one-to-one.

Proof:

Suppose f is any function from a finite set X with n elements to a finite set Y with m elements where n > m. Denote the elements of Y by y1, y2, . . . , ym . Recall that for each yi in Y , the inverse image set f −1(yi ) = {x ∈ X | f (x) = yi }. Now consider the collection of all the inverse image sets for all the elements of Y :

f −1(y1), f −1(y2), . . . , f −1(ym).

By definition of function, each element of X is sent by f to some element of Y . Hence each element of X is in one of the inverse image sets, and so the union of all these sets equals X . But also, by definition of function, no element of X is sent by f to more than one element of Y . Thus each element of X is in only one of the inverse image sets, and so the inverse image sets are mutually disjoint. By the addition rule, therefore,

N (X) = N ( f −1(y1)) + N ( f −1(y2)) + · · · + N ( f −1(ym)). 9.4.1

Now suppose that f is one-to-one [which is the opposite of what we want to prove]. Then each set f −1(yi ) has at most one element, and so

N ( f −1(y1)) + N ( f −1(y2)) + · · · + N ( f −1(ym)) ≤ 1 + 1 + · · · + 1︸ ︷︷ ︸ m terms

= m 9.4.2

Putting equations (9.4.1) and (9.4.2) together gives that

n = N (X) ≤ m = N (Y ).

This contradicts the fact that n > m, and so the supposition that f is one-to-one must be false. Hence f is not one-to-one [as was to be shown].

An important theorem that follows from the pigeonhole principle states that a function from one finite set to another finite set of the same size is one-to-one if, and only if, it is onto. As shown in Section 7.4, this result does not hold for infinite sets.

Theorem 9.4.2 One-to-One and Onto for Finite Sets

Let X and Y be finite sets with the same number of elements and suppose f is a function from X to Y . Then f is one-to-one if, and only if, f is onto.

Proof:

Suppose f is a function from X to Y , where X and Y are finite sets each with m elements. Let X = {x1, x2, . . . , xm} and Y = {y1, y2, . . . , ym}. If f is one-to-one, then f is onto: Suppose f is one-to-one. Then f (x1), f (x2), . . . , f (xm) are all distinct. Consider the set S of all elements of Y that are not the image of any element of X.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.4 The Pigeonhole Principle 563

Then the sets

{ f (x1)}, { f (x2)}, . . . , { f (xm)} and S are mutually disjoint. By the addition rule,

N (Y ) = N ({ f (x1)}) + N ({ f (x2)}) + · · · + N ({ f (xm)}) + N (S) = 1 + 1 + · · · + 1︸ ︷︷ ︸

m terms

+ N (S) because each { f (xi )} is a singleton set

= m + N (S). Thus

m = m + N (S) because N (Y ) = m, ⇒ N (S) = 0 by subtracting m from both sides.

Hence S is empty, and so there is no element of Y that is not the image of some element of X . Consequently, f is onto.

If f is onto, then f is one-to-one: Suppose f is onto. Then f −1(yi ) ̸= ∅ and so N ( f −1(yi )) ≥ 1 for all i = 1, 2, . . . , m. As in the proof of the pigeonhole principle (Theorem 9.4.1), X is the union of the mutually disjoint sets f −1(y1), f −1(y2), . . . , f −1(ym). By the addition principle,

N (X) = N ( f −1(y1)) + N ( f −1(y2)) + · · · + N ( f −1(ym))︸ ︷︷ ︸ ≥ m. m terms, each ≥ 1

9.4.3

Now if any one of the sets f −1(yi ) has more than one element, then the sum in equa- tion (9.4.3) is greater than m. But we know this is not the case because N (X) = m. Hence each set f −1(yi ) has exactly one element, and thus f is one-to-one [as was to be shown].

Note that Theorem 9.4.2 applies in particular to the case X = Y . Thus a one-to-one function from a finite set to itself is onto, and an onto function from a finite set to itself is one-to-one. Such functions are permutations of the sets on which they are defined. For instance, the function defined by the diagram on the left is another representation for the permutation cdba obtained by listing the images of a, b, c, and d in order.

a b c d

a b c d

Test Yourself 1. The pigeonhole principle states that _____.

2. The generalized pigeonhole principle states that _____.

3. If X and Y are finite sets and f is a function from X to Y then f is one-to-one if, and only if, _____

Exercise Set 9.4 1. a. If 4 cards are selected from a standard 52-card deck,

must at least 2 be of the same suit? Why? b. If 5 cards are selected from a standard 52-card deck,

must at least 2 be of the same suit? Why?

2. a. If 13 cards are selected from a standard 52-card deck, must at least 2 be of the same denomination? Why?

b. If 20 cards are selected from a standard 52-card deck, must at least 2 be of the same denomination? Why?

3. A small town has only 500 residents. Must there be 2 resi- dents who have the same birthday? Why?

4. In a group of 700 people, must there be 2 who have the same first and last initials? Why?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

564 Chapter 9 Counting and Probability

5. a. Given any set of four integers, must there be two that have the same remainder when divided by 3? Why?

b. Given any set of three integers, must there be two that have the same remainder when divided by 3? Why?

6. a. Given any set of seven integers, must there be two that have the same remainder when divided by 6? Why?

b. Given any set of seven integers, must there be two that have the same remainder when divided by 8? Why?

7.H Let S = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12}. Suppose six inte- gers are chosen from S. Must there be two integers whose sum is 15? Why?

8. Let T = {1, 2, 3, 4, 5, 6, 7, 8, 9}. Suppose five integers are chosen from T . Must there be two integers whose sum is 10? Why?

9. a. If seven integers are chosen from between 1 and 12 inclusive, must at least one of them be odd? Why?

b. If ten integers are chosen from between 1 and 20 inclu- sive, must at least one of them be even? Why?

10. If n + 1 integers are chosen from the set {1, 2, 3, . . . , 2n},

where n is a positive integer, must at least one of them be odd? Why?

11. If n + 1 integers are chosen from the set {1, 2, 3, . . . , 2n},

where n is a positive integer, must at least one of them be even? Why?

12. How many cards must you pick from a standard 52-card deck to be sure of getting at least 1 red card? Why?

13. Suppose six pairs of similar-looking boots are thrown together in a pile. How many individual boots must you pick to be sure of getting a matched pair? Why?

14. How many integers from 0 through 60 must you pick in order to be sure of getting at least one that is odd? at least one that is even?

15. If n is a positive integer, how many integers from 0 through 2n must you pick in order to be sure of getting at least one that is odd? at least one that is even?

16. How many integers from 1 through 100 must you pick in order to be sure of getting one that is divisible by 5?

17. How many integers must you pick in order to be sure that at least two of them have the same remainder when divided by 7?

18. How many integers must you pick in order to be sure that at least two of them have the same remainder when divided by 15?

19. How many integers from 100 through 999 must you pick in order to be sure that at least two of them have a digit

in common? (For example, 256 and 530 have the common digit 5.)

20. a. If repeated divisions by 20,483 are performed, how many distinct remainders can be obtained?

b. When 5/20483 is written as a decimal, what is the max- imum length of the repeating section of the representa- tion?

21. When 683/1493 is written as a decimal, what is the maximum length of the repeating section of the representation?

22. Is 0.101001000100001000001 . . . (where each string of 0’s is one longer than the previous one) rational or irra- tional?

23. Is 56.556655566655556666 . . . (where the strings of 5’s and 6’s become longer in each repetition) rational or irra- tional?

24. Show that within any set of thirteen integers chosen from 2 through 40, there are at least two integers with a common divisor greater than 1.

25. In a group of 30 people, must at least 3 have been born in the same month? Why?

26. In a group of 30 people, must at least 4 have been born in the same month? Why?

27. In a group of 2,000 people, must at least 5 have the same birthday? Why?

28. A programmer writes 500 lines of computer code in 17 days. Must there have been at least 1 day when the pro- grammer wrote 30 or more lines of code? Why?

29. A certain college class has 40 students. All the students in the class are known to be from 17 through 34 years of age. You want to make a bet that the class contains at least x students of the same age. How large can you make x and yet be sure to win your bet?

30. A penny collection contains twelve 1967 pennies, seven 1968 pennies, and eleven 1971 pennies. If you are to pick some pennies without looking at the dates, how many must you pick to be sure of getting at least five pennies from the same year?

31.H A group of 15 executives are to share 5 assistants. Each executive is assigned exactly 1 assistant, and no assistant is assigned to more than 4 executives. Show that at least 3 assistants are assigned to 3 or more executives.

32.H ✶ Let A be a set of six positive integers each of which is less than 13. Show that there must be two distinct sub- sets of A whose elements when added up give the same sum. (For example, if A = {5, 12, 10, 1, 3, 4}, then the ele- ments of the subsets S1 = {1, 4, 10} and S2 = {5, 10} both add up to 15.)

33.H Let A be a set of six positive integers each of which is less than 15. Show that there must be two distinct subsets of A

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 565

whose elements when added up give the same sum. (Thanks to Jonathan Goldstine for this problem.)

34. Let S be a set of ten integers chosen from 1 through 50. Show that the set contains at least two different (but not necessarily disjoint) subsets of four integers that add up to the same number. (For instance, if the ten numbers are {3, 8, 9, 18, 24, 34, 35, 41, 44, 50}, the subsets can be taken to be {8, 24, 34, 35} and {9, 18, 24, 50}. The numbers in both of these add up to 101.)

35.✶H Given a set of 52 distinct integers, show that there must be 2 whose sum or difference is divisible by 100.

36.✶H Show that if 101 integers are chosen from 1 to 200 inclu- sive, there must be 2 with the property that one is divisible by the other.

37.✶ a. Suppose a1, a2, . . . , an is a sequence of n integers none of which is divisible by n. Show that at least one of the differences ai − a j (for i ̸= j) must be divisible by n.

b.H Show that every finite sequence x1, x2, . . . , xn of n inte- gers has a consecutive subsequence xi+1, xi+2, . . . , x j whose sum is divisible by n. (For instance, the sequence

3, 4, 17, 7, 16 has the consecutive subsequence 17, 7, 16 whose sum is divisible by 5.) (From: James E. Schultz and William F. Burger, “An Approach to Problem- Solving Using Equivalence Classes Modulo n,” College Mathematics Journal (15), No. 5, 1984, 401–405.)

38.✶H Observe that the sequence 12, 15, 8, 13, 7, 18, 19, 11, 14, 10 has three increasing subsequences of length four: 12, 15, 18, 19; 12, 13, 18, 19; and 8, 13, 18, 19. It also has one decreasing subsequence of length four: 15, 13, 11, 10. Show that in any sequence of n2 + 1 distinct real numbers, there must be a sequence of length n + 1 that is either strictly increasing or strictly decreasing.

39.✶ What is the largest number of elements that a set of inte- gers from 1 through 100 can have so that no one element in the set is divisible by another? (Hint: Imagine writing all the numbers from 1 through 100 in the form 2k ·m, where k ≥ 0 and m is odd.)

40. Suppose X and Y are finite sets, X has more elements than Y , and F: X → Y is a function. By the pigeonhole princi- ple, there exist elements a and b in X such that a ̸= b and F(a) = F(b). Write a computer algorithm to find such a pair of elements a and b.

Answers for Test Yourself 1. if n pigeons fly into m pigeonholes and n > m, then at least two pigeons fly into the same pigeonhole Or: a function from one finite set to a smaller finite set cannot be one-to-one 2. if n pigeons fly into m pigeonholes and, for some positive integer k, k < n/m, then at least one pigeonhole contains k + 1 or more pigeons Or: for any function f from a finite set X with n elements to a finite set Y with m elements and for any positive integer k, if k < n/m, then there is some y ∈ Y such that y is the image of at least k + 1 distinct elements of Y 3. f is onto

9.5 Counting Subsets of a Set: Combinations “But ‘glory’ doesn’t mean ‘a nice knock-down argument,’” Alice objected. “When I use a word,” Humpty Dumpty said, in rather a scornful tone, “it means just what I choose it to mean—neither more nor less.” — Lewis Carroll, Through the Looking Glass, 1872

Consider the following question:

Suppose five members of a group of twelve are to be chosen to work as a team on a special project. How many distinct five-person teams can be selected?

This question is answered in Example 9.5.4. It is a special case of the following more general question:

Given a set S with n elements, how many subsets of size r can be chosen from S?

The number of subsets of size r that can be chosen from S equals the number of subsets of size r that S has. Each individual subset of size r is called an r -combination of the set.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

566 Chapter 9 Counting and Probability

• Definition Let n and r be nonnegative integers with r ≤ n. An r-combination of a set of n elements is a subset of r of the n elements. As indicated in Section 5.1, the symbol

( n r

) ,

which is read “n choose r ,” denotes the number of subsets of size r (r -combinations) that can be chosen from a set of n elements.

Recall from Section 5.1 that calculators generally use symbols like C(n, r), nCr , Cn,r , or nCr instead of

(n r

) .

Example 9.5.1 3-Combinations

Let S = {Ann, Bob, Cyd, Dan}. Each committee consisting of three of the four people in S is a 3-combination of S.

a. List all such 3-combinations of S. b. What is (4

3

) ?

Solution

a. Each 3-combination of S is a subset of S of size 3. But each subset of size 3 can be obtained by leaving out one of the elements of S. The 3-combinations are

{Bob, Cyd, Dan} leave out Ann {Ann, Cyd, Dan} leave out Bob {Ann, Bob, Dan} leave out Cyd {Ann, Bob, Cyd} leave out Dan.

b. Because (4

3

) is the number of 3-combinations of a set with four elements, by part (a),(4

3

) = 4. ■

There are two distinct methods that can be used to select r objects from a set of n elements. In an ordered selection, it is not only what elements are chosen but also the order in which they are chosen that matters. Two ordered selections are said to be the same if the elements chosen are the same and also if the elements are chosen in the same order. An ordered selection of r elements from a set of n elements is an r -permutation of the set.

In an unordered selection, on the other hand, it is only the identity of the chosen ele- ments that matters. Two unordered selections are said to be the same if they consist of the same elements, regardless of the order in which the elements are chosen. An unordered selection of r elements from a set of n elements is the same as a subset of size r or an r -combination of the set.

Example 9.5.2 Unordered Selections

How many unordered selections of two elements can be made from the set {0, 1, 2, 3}?

Solution An unordered selection of two elements from {0, 1, 2, 3} is the same as a 2- combination, or subset of size 2, taken from the set. These can be listed systematically:

{0, 1}, {0, 2}, {0, 3} subsets containing 0 {1, 2}, {1, 3} subsets containing 1 but not already listed {2, 3} subsets containing 2 but not already listed.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 567

Since this listing exhausts all possibilities, there are six subsets in all. Thus (4

2

) = 6,

which is the number of unordered selections of two elements from a set of four. ■

When the values of n and r are small, it is reasonable to calculate values of (n

r

)

using the method of complete enumeration (listing all possibilities) illustrated in Exam- ples 9.5.1 and 9.5.2. But when n and r are large, it is not feasible to compute these numbers by listing and counting all possibilities.

The general values of (n

r

) can be found by a somewhat indirect but simple method.

An equation is derived that contains (n

r

) as a factor. Then this equation is solved to obtain

a formula for (n

r

) . The method is illustrated by Example 9.5.3.

Example 9.5.3 Relation between Permutations and Combinations

Write all 2-permutations of the set {0, 1, 2, 3}. Find an equation relating the number of 2-permutations, P(4, 2), and the number of 2-combinations,

(4 2

) , and solve this equation

for (4

2

) .

Solution According to Theorem 9.2.3, the number of 2-permutations of the set {0, 1, 2, 3} is P(4, 2), which equals

4! (4− 2)! =

4 ·3 ·2 ·1 2 ·1 = 12.

Now the act of constructing a 2-permutation of {0, 1, 2, 3} can be thought of as a two-step process:

Step 1: Choose a subset of two elements from {0, 1, 2, 3}. Step 2: Choose an ordering for the two-element subset.

This process can be illustrated by the possibility tree shown in Figure 9.5.1.

Start

Step 1: Write the 2-combinations of {0, 1, 2, 3}.

Step 2: Order the 2-combinations to obtain 2-permutations.

{0, 1}

{0, 2}

{0, 3}

{1, 2}

{1, 3}

{2, 3}

01

10

02

20

03

30 12

21

13

31

23

32

Figure 9.5.1 Relation between Permutations and Combinations

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

568 Chapter 9 Counting and Probability

The number of ways to perform step 1 is (4

2

) , the same as the number of subsets of

size 2 that can be chosen from {0, 1, 2, 3}. The number of ways to perform step 2 is 2!, the number of ways to order the elements in a subset of size 2. Because the number of ways of performing the whole process is the number of 2-permutations of the set {0, 1, 2, 3}, which equals P(4, 2), it follows from the product rule that

P(4, 2) = (

4 2

) ·2!. This is an equation that relates P(4, 2) and

(4 2

) .

Solving the equation for (4

2

) gives

( 4 2

) = P(4, 2)

2! Recall that P(4, 2) = 4!

(4−2)! . Hence, substituting yields

( 4 2

) =

4! (4− 2)!

2! = 4!

2!(4− 2)! = 6. ■

The reasoning used in Example 9.5.3 applies in the general case as well. To form an r -permutation of a set of n elements, first choose a subset of r of the n elements (there are (n

r

) ways to perform this step), and then choose an ordering for the r elements (there

are r ! ways to perform this step). Thus the number of r -permutations is

P(n, r) = (

n r

) ·r !.

Now solve for (n

r

) to obtain the formula

( n r

) = P(n, r)

r ! .

Since P(n, r) = n! (n−r)! , substitution gives

( n r

) =

n! (n − r)!

r ! = n!

r !(n − r)! .

The result of this discussion is summarized and extended in Theorem 9.5.1.

Theorem 9.5.1

The number of subsets of size r (or r -combinations) that can be chosen from a set of n elements,

(n r

) , is given by the formula

( n r

) = P(n, r)

r ! first version

or, equivalently, (

n r

) = n!

r !(n − r)! second version

where n and r are nonnegative integers with r ≤ n.

Note that the analysis presented before the theorem proves the theorem in all cases where n and r are positive. If r is zero and n is any nonnegative integer, then

(n 0

) is the

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 569

number of subsets of size zero of a set with n elements. But you know from Section 6.2 that there is only one set that does not have any elements. Consequently,

(n 0

) = 1. Also

n! 0!(n − 0)! =

n! 1 ·n! = 1

since 0! = 1 by definition. (Remember we said that definition would turn out to be con- venient!) Hence the formula

( n 0

) = n!

0!(n − 0)! holds for all integers n ≥ 0, and so the theorem is true for all nonnegative integers n and r with r ≤ n.

Example 9.5.4 Calculating the Number of Teams

Consider again the problem of choosing five members from a group of twelve to work as a team on a special project. How many distinct five-person teams can be chosen?

Solution The number of distinct five-person teams is the same as the number of subsets of size 5 (or 5-combinations) that can be chosen from the set of twelve. This number is

(12 5

) .

By Theorem 9.5.1, (

12 5

) = 12!

5!(12− 5)! = 12 ·11 ·10 ·9 ·8 ·7! (5 ·4 ·3 ·2 ·1) ·7! = 11 ·9 ·8 = 792.

Thus there are 792 distinct five-person teams. ■

The formula for the number of r -combinations of a set can be applied in a wide variety of situations. Some of these are illustrated in the following examples.

Example 9.5.5 Teams That Contain Both or Neither

Suppose two members of the group of twelve insist on working as a pair—any team must contain either both or neither. How many five-person teams can be formed?

Solution Call the two members of the group that insist on working as a pair A and B. Then any team formed must contain both A and B or neither A nor B. The set of all possible teams can be partitioned into two subsets as shown in Figure 9.5.2 on the next page.

Because a team that contains both A and B contains exactly three other people from the remaining ten in the group, there are as many such teams as there are subsets of three people that can be chosen from the remaining ten. By Theorem 9.5.1, this number is

( 10 3

) = 10!

3! ·7! = 3 4

10 · 9 · 8 ·7! 3 · 2 ·1·7! = 120.

Because a team that contains neither A nor B contains exactly five people from the remaining ten, there are as many such teams as there are subsets of five people that can be chosen from the remaining ten. By Theorem 9.5.1, this number is

( 10 5

) = 10!

5! ·5! = 2 2

10 ·9 · 8 · 7 · 6 ·5! 5 · 4 ·3 · 2 ·1·5! = 252.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

570 Chapter 9 Counting and Probability

Because the set of teams that contain both A and B is disjoint from the set of teams that contain neither A nor B, by the addition rule, ⎡

⎣ number of teams containing both A and B or neither A nor B

⎦ =

⎣ number of teams containing both A and B

⎦+

⎣ number of teams containing neither A nor B

= 120 + 252 = 372. This reasoning is summarized in Figure 9.5.2.

All Possible Five-Person Teams Containing Both or Neither

teams with both A and B

teams with neither A nor B

There are 10 3( ) = 120 of these.

There are 10 5( ) = 252 of these.

So the total number of teams that contain either both A and B or neither A nor B is 120 + 252 = 372.

Figure 9.5.2 ■

Example 9.5.6 Teams That Do Not Contain Both

Suppose two members of the group don’t get along and refuse to work together on a team. How many five-person teams can be formed?

Solution Call the two people who refuse to work together C and D. There are two different ways to answer the given question: One uses the addition rule and the other uses the difference rule.

To use the addition rule, partition the set of all teams that don’t contain both C and D into three subsets as shown in Figure 9.5.3 on the next page.

Because any team that contains C but not D contains exactly four other people from the remaining ten in the group, by Theorem 9.5.1 the number of such teams is

( 10 4

) = 10!

4!(10− 4)! = 3

10 · 9 · 8 ·7 · 6! 4 · 3 · 2 ·1· 6! = 210.

Similarly, there are (10

4

) = 210 teams that contain D but not C . Finally, by the same

reasoning as in Example 9.5.5, there are 252 teams that contain neither C nor D. Thus, by the addition rule,

[ number of teams that do not contain both C and D

] = 210 + 210 + 252 = 672.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 571

This reasoning is summarized in Figure 9.5.3.

All Possible Five-Person Teams That Do Not Contain Both C and D

teams that contain C but not D

There are 10 4( ) = 210

of these.

teams that contain D but not C

There are 10 4( ) = 210

of these.

teams that contain neither C nor D

There are 10 5( ) = 252

of these.

So the total number of teams that do not contain both C and D is 210 + 210 + 252 = 672.

Figure 9.5.3

The alternative solution by the difference rule is based on the following observation: The set of all five-person teams that don’t contain both C and D equals the set difference between the set of all five-person teams and the set of all five-person teams that contain both C and D. By Example 9.5.4, the total number of five-person teams is

(12 5

) = 792.

Thus, by the difference rule, [

number of teams that don’t contain both C and D

] = [

total number of teams of five

] − [

number of teams that contain both C and D

]

= (

12 5

) − (

10 3

) = 792− 120 = 672.

This reasoning is summarized in Figure 9.5.4. ■

All Five-Person Teams

teams that do not contain both C and D

teams that contain both C and D

So there are 792 – 120 = 672 of these.

There are 12 5( ) = 792 of these.

There are 10 3( ) = 120 of these. Figure 9.5.4

Before we begin the next example, a remark on the phrases at least and at most is in order:

The phrase at least n means “n or more.” The phrase at most n means “n or fewer.”

For instance, if a set consists of three elements and you are to choose at least two, you will choose two or three; if you are to choose at most two, you will choose none, or one, or two.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

572 Chapter 9 Counting and Probability

Example 9.5.7 Teams with Members of Two Types

Suppose the group of twelve consists of five men and seven women.

a. How many five-person teams can be chosen that consist of three men and two women?

b. How many five-person teams contain at least one man?

c. How many five-person teams contain at most one man?

Solution

a. To answer this question, think of forming a team as a two-step process:

Step 1: Choose the men.

Step 2: Choose the women.

There are (5

3

) ways to choose the three men out of the five and

(7 2

) ways to choose the

two women out of the seven. Hence, by the product rule, [

number of teams of five that contain three men and two women

] = (

5 3

)( 7 2

) = 5!

3!2! · 7!

2!5!

= 7 ·6 ·5 ·4 ·3 ·2 ·1 3 ·2 ·1 ·2 ·1 ·2 ·1

= 210. b. This question can also be answered either by the addition rule or by the difference

rule. The solution by the difference rule is shorter and is shown first. Observe that the set of five-person teams containing at least one man equals the

set difference between the set of all five-person teams and the set of five-person teams that do not contain any men. See Figure 9.5.5 below.

Now a team with no men consists entirely of five women chosen from the seven women in the group, so there are

(7 5

) such teams. Also, by Example 9.5.4, the total

number of five-person teams is (12

5

) = 792. Hence, by the difference rule,

⎣ number of teams with at least one man

⎦ =

⎣ total number of teams of five

⎦−

⎣ number of teams of five that do not contain any men

= (

12 5

) − (

7 5

) = 792− 7!

5! ·2!

= 792− 3

7 ·6 ·5! 5! ·2 ·1 = 792− 21 = 771.

This reasoning is summarized in Figure 9.5.5.

All Five-Person Teams

teams that contain at least one man

teams that contain no men

So there are 792 – 21 = 771 of these.

There are 7 5( ) = 21 of these.

There are 12 5( ) = 792 of these.

Figure 9.5.5

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 573

Alternatively, to use the addition rule, observe that the set of teams containing at least one man can be partitioned as shown in Figure 9.5.6. The number of teams in each subset of the partition is calculated using the method illustrated in part (a). There are

( 5 1

)( 7 4

) teams with one man and four women

( 5 2

)( 7 3

) teams with two men and three women

( 5 3

)( 7 2

) teams with three men and two women

( 5 4

)( 7 1

) teams with four men and one woman

( 5 5

)( 7 0

) teams with five men and no women.

Hence, by the addition rule, [

number of teams with at least one man

]

= (

5 1

)( 7 4

) + (

5 2

)( 7 3

) + (

5 3

)( 7 2

) + (

5 4

)( 7 1

) + (

5 5

)( 7 0

)

= 5! 1!4! ·

7! 4!3! +

5! 2!3! ·

7! 3!4! +

5! 3!2! ·

7! 2!5! +

5! 4!1! ·

7! 1!6! +

5! 5!0! ·

7! 0!7!

= 5 ·4! ·7 ·6 ·5 ·4! 4! ·3 ·2 ·4! +

2 5 ·4 ·3! ·7 ·6 ·5 ·4!

3! ·2 ·4! ·3 ·2 + 2 3

5 ·4 ·3! ·7 ·6 ·5! 2 ·3! ·5! ·2

+ 5 ·4! ·7 ·6! 4! ·6! +

5! ·7! 5! ·7!

= 175 + 350 + 210 + 35 + 1 = 771. This reasoning is summarized in Figure 9.5.6.

Teams with At Least One Man

teams with one man

teams with two men

teams with three men

teams with four men

teams with five men

There are 5 1

7 4( )( ) = 175

of these.

There are 5 2

7 3( )( ) = 350

of these.

There are 5 3

7 2( )( ) = 210

of these.

There are 5 4

7 1( )( ) = 35

of these.

There are 5 5

7 0( )( ) = 1

of these.

So the total number of teams with at least one man is 175 + 350 + 210 + 35 + 1 = 771.

Figure 9.5.6

c. As shown in Figure 9.5.7 on the next page, the set of teams containing at most one man can be partitioned into the set that does not contain any men and the set that contains exactly one man. Hence, by the addition rule,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

574 Chapter 9 Counting and Probability

⎣ number of teams with at most one man

⎦ =

⎣ number of teams without any men

⎦+

⎣ number of teams with one man

= (

5 0

)( 7 5

) + (

5 1

)( 7 4

) = 21 + 175 = 196.

This reasoning is summarized in Figure 9.5.7.

Teams with At Most One Man

teams without any men

teams with one man

There are 5 0

7 5( )( ) = 21

of these.

There are 5 1

7 4( )( ) = 175

of these.

So the total number of teams with at most one man is 21 + 175 = 196.

Figure 9.5.7 ■

Example 9.5.8 Poker Hand Problems

The game of poker is played with an ordinary deck of cards (see Example 9.1.1). Var- ious five-card holdings are given special names, and certain holdings beat certain other holdings. The named holdings are listed from highest to lowest below.

Royal flush: 10, J, Q, K, A of the same suit

Straight flush: five adjacent denominations of the same suit but not a royal flush—aces can be high or low, so A, 2, 3, 4, 5 of the same suit is a straight flush.

Four of a kind: four cards of one denomination—the fifth card can be any other in the deck

Full house: three cards of one denomination, two cards of another denomination

Flush: five cards of the same suit but not a straight or a royal flush

Straight: five cards of adjacent denominations but not all of the same suit—aces can be high or low

Three of a kind: three cards of the same denomination and two other cards of different denominations

Two pairs: two cards of one denomination, two cards of a second denomination, and a fifth card of a third denomination

One pair: two cards of one denomination and three other cards all of different denom- inations

No pairs: all cards of different denominations but not a straight or straight flush or flush

a. How many five-card poker hands contain two pairs?

b. If a five-card hand is dealt at random from an ordinary deck of cards, what is the probability that the hand contains two pairs?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 575

Solution

a. Consider forming a hand with two pairs as a four-step process:

Step 1: Choose the two denominations for the pairs.

Step 2: Choose two cards from the smaller denomination.

Step 3: Choose two cards from the larger denomination.

Step 4: Choose one card from those remaining.

The number of ways to perform step 1 is (13

2

) because there are 13 denominations

in all. The number of ways to perform steps 2 and 3 is (4

2

) because there are four cards

of each denomination, one in each suit. The number of ways to perform step 4 is (44

1

)

because the fifth card is chosen from the eleven denominations not included in the pair and there are four cards of each denomination. Thus [

the total number of hands with two pairs

] = (

13 2

)( 4 2

)( 4 2

)( 44 1

)

= 13! 2!(13− 2)! ·

4! 2!(4− 2)! ·

4! 2!(4− 2)! ·

44! 1!(44− 1)!

= 13 ·12 ·11! (2 ·1) ·11! ·

4 ·3 ·2! (2 ·1) ·2! ·

4 ·3 ·2! (2 ·1) ·2! ·

44 ·43! 1 ·43!

= 78 ·6 ·6 ·44 = 123,552. b. The total number of five-card hands from an ordinary deck of cards is

(52 5

) =2,598,960.

Thus if all hands are equally likely, the probability of obtaining a hand with two pairs is 123,5522,598,960

∼= 4.75%. ■

Example 9.5.9 Number of Bit Strings with Fixed Number of 1’s

How many eight-bit strings have exactly three 1’s?

Solution To solve this problem, imagine eight empty positions into which the 0’s and 1’s of the bit string will be placed. In step 1, choose positions for the three 1’s, and in step 2, put the 0’s into place.

Three 1's and five 0's to be put into the positions

1 2 3 4 5 6 7 8

Once a subset of three positions has been chosen from the eight to contain 1’s, then the remaining five positions must all contain 0’s (since the string is to have exactly three 1’s). It follows that the number of ways to construct an eight-bit string with exactly three 1’s is the same as the number of subsets of three positions that can be chosen from the eight into which to place the 1’s. By Theorem 9.5.1, this equals

( 8 3

) = 8!

3! ·5! = 8 ·7 ·6 ·5! 3 ·2 ·5! = 56. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

576 Chapter 9 Counting and Probability

Example 9.5.10 Permutations of a Set with Repeated Elements

Consider various ways of ordering the letters in the word MISSISSIPPI:

IIMSSPISSIP, ISSSPMIIPIS, PIMISSSSIIP, and so on.

How many distinguishable orderings are there?

Solution This example generalizes Example 9.5.9. Imagine placing the 11 letters of MISSISSIPPI one after another into 11 positions.

Letters of MISSISSIPPI to be placed into the positions

1 2 3 4 5 6 7 8 9 10 11

Because copies of the same letter cannot be distinguished from one another, once the posi- tions for a certain letter are known, then all copies of the letter can go into the positions in any order. It follows that constructing an ordering for the letters can be thought of as a four-step process:

Step 1: Choose a subset of four positions for the S’s.

Step 2: Choose a subset of four positions for the I ’s.

Step 3: Choose a subset of two positions for the P’s.

Step 4: Choose a subset of one position for the M .

Since there are 11 positions in all, there are (11

4

) subsets of four positions for the

S’s. Once the four S’s are in place, there are seven positions that remain empty, so there are (7

4

) subsets of four positions for the I ’s. After the I ’s are in place, there are three

positions left empty, so there are (3

2

) subsets of two positions for the P’s. That leaves just

one position for the M . But 1 = (1

1

) . Hence by the multiplication rule,

[ number of ways to position all the letters

] = (

11 4

)( 7 4

)( 3 2

)( 1 1

)

= 11! 4!7! ·

7! 4!3! ·

3! 2!1! ·

1! 1!0!

= 11! 4! ·4! ·2! ·1! = 34,650. ■

In exercise 18 at the end of the section, you are asked to show that changing the order in which the letters are placed into the positions does not change the answer to this example.

The same reasoning used in this example can be used to derive the following general theorem.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 577

Theorem 9.5.2 Permutations with sets of Indistinguishable Objects

Suppose a collection consists of n objects of which

n1 are of type 1 and are indistinguishable from each other

n2 are of type 2 and are indistinguishable from each other ...

nk are of type k and are indistinguishable from each other,

and suppose that n1 + n2 + · · · + nk = n. Then the number of distinguishable permutations of the n objects is

( n n1

)( n − n1

n2

)( n − n1 − n2

n3

) · · · (

n − n1 − n2 − · · ·− nk−1 nk

)

= n! n1! n2! n3! · · · nk !

.

Some Advice about Counting Students learning counting techniques often ask, “How do I know what to multiply and what to add? When do I use the multiplication rule and when do I use the addition rule?” Unfortunately, these questions have no easy answers. You need to imagine, as vividly as possible, the objects you are to count. You might even start to make an actual list of the items you are trying to count to get a sense for how to obtain them in a systematic way. You should then construct a model that would allow you to continue counting the objects one by one if you had enough time. If you can imagine the elements to be counted as being obtained through a multistep process (in which each step is performed in a fixed number of ways regardless of how preceding steps were performed), then you can use the multiplication rule. The total number of elements will be the product of the number of ways to perform each step. If, however, you can imagine the set of elements to be counted as being broken up into disjoint subsets, then you can use the addition rule. The total number of elements in the set will be the sum of the number of elements in each subset.

One of the most common mistakes students make is to count certain possibilities more than once.

Example 9.5.11 Double Counting

Consider again the problem of Example 9.5.7(b). A group consists of five men and seven women. How many teams of five contain at least one man?

Incorrect Solution Imagine constructing the team as a two-step process:

Step 1: Choose a subset of one man from the five men.

Step 2: Choose a subset of four others from the remaining eleven people.

Hence, by the multiplication rule, there are (5

1

) · (11

4

) = 1,650 five-person teams that con-

tain at least one man.

! Caution! Be careful to avoid counting items twice when using the multiplication rule.

Analysis of the Incorrect Solution The problem with the solution above is that some teams are counted more than once. Suppose the men are Anwar, Ben, Carlos, Dwayne,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

578 Chapter 9 Counting and Probability

and Ed and the women are Fumiko, Gail, Hui-Fan, Inez, Jill, Kim, and Laura. According to the method described previously, one possible outcome of the two-step process is as follows:

Outcome of step 1: Anwar

Outcome of step 2: Ben, Gail, Inez, and Jill.

In this case the team would be {Anwar, Ben, Gail, Inez, Jill}. But another possible outcome is

Outcome of step 1: Ben

Outcome of step 2: Anwar, Gail, Inez, and Jill,

which also gives the team {Anwar, Ben, Gail, Inez, Jill}. Thus this one team is given by two different branches of the possibility tree, and so it is counted twice. ■

The best way to avoid mistakes such as the one just described is to visualize the possibility tree that corresponds to any use of the multiplication rule and the set partition that corresponds to a use of the addition rule. Check how your division into steps works by applying it to some actual data—as was done in the analysis above—and try to pick data that are as typical or generic as possible.

It often helps to ask yourself (1) “Am I counting everything?” and (2) “Am I counting anything twice?” When using the multiplication rule, these questions become (1) “Does every outcome appear as some branch of the tree?” and (2) “Does any outcome appear on more than one branch of the tree?” When using the addition rule, the questions become (1) “Does every outcome appear in some subset of the diagram?” and (2) “Do any two subsets in the diagram share common elements?”

The Number of Partitions of a Set into r Subsets In an ordinary (or singly indexed) sequence, integers n are associated to numbers an . In a doubly indexed sequence, ordered pairs of integers (m, n) are associated to numbers am,n . For example, combinations can be thought of as terms of the doubly indexed sequence defined by Cn,r =

(n r

) for all integers n and r with 0 ≤ r ≤ n.

Note Stirling numbers of the first kind are used in counting r -permutations with various properties.

An important example of a doubly indexed sequence is the sequence of Stirling num- bers of the second kind. These numbers, named after the Scottish mathematician James Stirling (1692–1770), arise in a surprisingly large variety of counting problems. They are defined recursively and can be interpreted in terms of partitions of a set.

Observe that if a set of three elements {x1, x2, x3} is partitioned into two subsets, then one of the subsets has one element and the other has two elements. Therefore, there are three ways the set can be partitioned:

{x1, x2}{x3} put x3 by itself {x1, x3}{x2} put x2 by itself {x2, x3}{x1} put x1 by itself

In general, let

Sn,r = number of ways a set of size n can be partitioned into r subsets

Then, by the above, S3.2 = 3. The numbers Sn,r are called Stirling numbers of the second kind.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 579

Example 9.5.12 Values of Stirling Numbers

Find S4,1, S4,2, S4,3, and S4,4.

Solution Given a set with four elements, denote it by {x1, x2, x3, x4}. The Stirling number S4,1 = 1 because a set of four elements can be partitioned into one subset in only one way:

{x1, x2, x3, x4}. Similarly, S4,4 = 1 because there is only one way to partition a set of four elements into four subsets:

{x1}{x2}{x3}{x4}. The number S4,2 = 7. The reason is that any partition of {x1, x2, x3, x4} into two sub-

sets must consist either of two subsets of size two or of one subset of size three and one subset of size one. The partitions for which both subsets have size two must pair x1 with x2, with x3, or with x4, which give rise to these three partitions:

{x1, x2}{x3, x4} x2 paired with x1 {x1, x3}{x2, x4} x3 paired with x1 {x1, x4}{x2, x3} x4 paired with x1

The partitions for which one subset has size one and the other has size three can have any one of the four elements in the subset of size one, which leads to these four partitions:

{x1}{x2, x3, x4} x1 by itself {x2}{x1, x3, x4} x2 by itself {x3}{x1, x2, x4} x3 by itself {x4}{x1, x2, x3} x4 by itself

It follows that the total number of ways that the set {x1, x2, x3, x4} can be partitioned into two subsets is 3 + 4 = 7.

Finally, S4,3 = 6 because any partition of a set of four elements into three subsets must have two elements in one subset and the other two elements in subsets by themselves. There are

(4 2

) = 6 ways to choose the two elements to put together, which results in the

following six possible partitions:

{x1, x2}{x3}{x4} {x2, x3}{x1}{x4} {x1, x3}{x2}{x4} {x2, x4}{x1}{x3} {x1, x4}{x2}{x3} {x3, x4}{x1}{x2} ■

Example 9.5.13 Finding a Recurrence Relation for Sn,r Find a recurrence relation relating Sn,r to values of the sequence with lower indices than n and r , and give initial conditions for the recursion.

Solution To solve this problem recursively, suppose a procedure has been found to count both the number of ways to partition a set of n − 1 elements into r − 1 subsets and the number of ways to partition a set of n − 1 elements into r subsets. The partitions of a set of n elements {x1, x2, . . . , xn} into r subsets can be divided, as shown in Figure 9.5.8 on the next page, into those that contain the set {xn} and those that do not.

To obtain the result shown in Figure 9.5.8 first count the number of partitions of {x1, x2, . . . , xn} into r subsets where one of the subsets is {xn}. To do this, imagine taking any one of the Sn−1, r−1 partitions of {x1, x2, . . . , xn−1} into r − 1 subsets and adding the

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

580 Chapter 9 Counting and Probability

Partitions of {x1, x2, . . . , xn} into r Subsets

Partitions of {x1, x2, . . . , xn} into r subsets where one of the subsets is {xn}

Partitions of {x1, x2, . . . , xn} into r subsets where none of the subsets is {xn}

There are Sn–1, r–1 partitions that include {xn}.

There are rSn–1, r partitions that do not include {xn}.

Thus the total number of partitions of {x1, x2, . . . , xn} into r subsets is Sn–1, r–1 + rSn–1, r .

Figure 9.5.8

subset {xn} to the partition. For example, if n = 4 and r = 3, you would take one of the three partitions of {x1, x2, x3} into two subsets, namely

{x1, x2}{x3}, {x1, x3}{x2}, or {x2, x3}{x1},

and add {x4}. The result would be one of the partitions

{x1, x2}{x3}{x4}, {x1, x3}{x3}{x4}, or {x2, x3}{x1}{x4}.

Clearly, any partition of {x1, x2, . . . , xn} into r subsets with {xn} as one of the subsets can be obtained in this way. Hence Sn−1,r−1 is the number of partitions of {x1, x2, . . . , xn} into r subsets of which one is {xn}.

Next, count the number of partitions of {x1, x2, . . . , xn} into r subsets where {xn} is not one of the subsets of the partition. Imagine taking any one of the Sn−1,r partitions of {x1, x2, . . . , xn−1} into r subsets. Now imagine choosing one of the r subsets of the partition and adding in the element xn . The result is a partition of {x1, x2, . . . , xn} into r subsets none of which is the singelton subset {xn}. Since the element xn could have been added to any one of the r subsets of the partition, it follows from the multiplication rule that there are r Sn−1,r partitions of this type. For instance, if n = 4 and r = 3, you would take the (unique) partition of {x1, x2, x3} into three subsets, namely {x1}{x2}{x3}, and add x4 to one of these sets. The result would be one of the partitions

{x1, x4}{x2}{x3}, {x1}{x2, x4}{x3}, or {x1}{x2}{x3, x4}. ↑ ↑ ↑

x4 is added to {x1} x4 is added to {x2} x4 is added to {x3}

Clearly, any partition of {x1, x2, . . . , xn} into r subsets, none of which is {xn}, can be obtained in the way described above, for when xn is removed from whatever subset con- tains it in such a partition, the result is a partition of {x1, x2, . . . , xn−1} into r subsets. Hence r Sn−1,r is the number of partitions of {x1, x2, . . . , xn} that do not contain {xn}.

Since any partition of {x1, x2, . . . , xn} either contains {xn} or does not, ⎡

⎣ the number of partitions of {x1, x2, . . . , xn} into r subsets

⎦ =

⎣ the number of partitions of {x1, x2, . . . , xn} into r subsets of which {xn} is one

+

⎣ the number of partitions of {x1, x2, . . . , xn} into r subsets none of which is {xn}

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 581

Thus Sn,r = Sn−1,r−1 + r Sn−1,r

for all integers n and r with 1 < r < n. The initial conditions for the recurrence relation are

Sn,1 = 1 and Sn,n = 1 for all integers n ≥ 1 because there is only one way to partition {x1, x2, . . . , xn} into one subset, namely

{x1, x2, . . . , xn}. and only one way to partition {x1, x2, . . . , xn} into n subsets, namely

{x1}, {x2}, . . . , {xn}. ■

Test Yourself 1. The number of subsets of size r that can be formed from

a set with n elements is denoted _____, which is read as “_____.”

2. The number of r -combinations of a set of n elements is _____.

3. Two unordered selections are said to be the same if the ele- ments chosen are the same, regardless of _____.

4. A formula relating (n

r

) and P(n, r) is _____.

5. The phrase “at least n” means _____, and the phrase “at most n” means _____.

6. Suppose a collection consists of n objects of which, for each i with 1 ≤ i ≤ k, ni are of type i and are indistinguishable from each other. Also suppose that n = n1 + n2 + · · · + nk . Then the number of distinct permutations of the n objects is _____.

7. The Stirling number of the second kind, Sn,r , can be inter- preted as _____.

8. Because any partition of a set X = {x1, x2, . . . , xn} either contains {xn} or does not, the number of partitions of X into r subsets equals _____ plus _____.

Exercise Set 9.5 1. a. List all 2-combinations for the set {x1, x2, x3}. Deduce

the value of (3

2

) .

b. List all unordered selections of four elements from the

set {a, b, c, d, e}. Deduce the value of (5

4

) .

2. a. List all 3-combinations for the set {x1, x2, x3, x4, x5}. Deduce the value of

(5 3

) .

b. List all unordered selections of two elements from the

set {x1, x2, x3, x4, x5, x6}. Deduce the value of (6

2

) .

3. Write an equation relating P(7, 2) and (7

2

) .

4. Write an equation relating P(8, 3) and (8

3

) .

5. Use Theorem 9.5.1 to compute each of the following.

a. (6

0

) b. (6

1

) c. (6

2

)

d. (6

3

) e. (6

4

) f. (6

5

) g. (6

6

)

6. A student council consists of 15 students. a. In how many ways can a committee of six be selected

from the membership of the council? b. Two council members have the same major and are not

permitted to serve together on a committee. How many

ways can a committee of six be selected from the mem- bership of the council?

c. Two council members always insist on serving on com- mittees together. If they can’t serve together, they won’t serve at all. How many ways can a committee of six be selected from the council membership?

d. Suppose the council contains eight men and seven women. (i) How many committees of six contain three men and

three women? (ii) How many committees of six contain at least one

woman? e. Suppose the council consists of three freshmen, four

sophomores, three juniors, and five seniors. How many committees of eight contain two representatives from each class?

7. A computer programming team has 13 members. a. How many ways can a group of seven be chosen to work

on a project? b. Suppose seven team members are women and six are

men. (i) How many groups of seven can be chosen that

contain four women and three men?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

582 Chapter 9 Counting and Probability

(ii) How many groups of seven can be chosen that contain at least one man?

(iii) How many groups of seven can be chosen that contain at most three women?

c. Suppose two team members refuse to work together on projects. How many groups of seven can be chosen to work on a project?

d. Suppose two team members insist on either working together or not at all on projects. How many groups of seven can be chosen to work on a project?

8.H An instructor gives an exam with fourteen questions. Stu- dents are allowed to choose any ten to answer. a. How many different choices of ten questions are there? b. Suppose six questions require proof and eight do not.

(i) How many groups of ten questions contain four that require proof and six that do not?

(ii) How many groups of ten questions contain at least one that requires proof?

(iii) How many groups of ten questions contain at most three that require proof?

c. Suppose the exam instructions specify that at most one of questions 1 and 2 may be included among the ten. How many different choices of ten questions are there?

d. Suppose the exam instructions specify that either both questions 1 and 2 are to be included among the ten or neither is to be included. How many different choices of ten questions are there?

9. A club is considering changing its bylaws. In an initial straw vote on the issue, 24 of the 40 members of the club favored the change and 16 did not. A committee of six is to be chosen from the 40 club members to devote further study to the issue. a. How many committees of six can be formed from the

club membership? b. How many of the committees will contain at least three

club members who, in the preliminary survey, favored the change in the bylaws?

10. Two new drugs are to be tested using a group of 60 labo- ratory mice, each tagged with a number for identification purposes. Drug A is to be given to 22 mice, drug B is to be given to another 22 mice, and the remaining 16 mice are to be used as controls. How many ways can the assignment of treatments to mice be made? (A single assignment involves specifying the treatment for each mouse—whether drug A, drug B, or no drug.)

11.✶ Refer to Example 9.5.8. For each poker holding below, (1) find the number of five-card poker hands with that holding; (2) find the probability that a randomly chosen set of five cards has that holding. a. royal flush b. straight flush c. four of a kind d. full house e. flush f. straight g. three of a kind h. one pair i. neither a repeated denomination nor five of the same suit

nor five adjacent denominations

12. How many pairs of two distinct integers chosen from the set {1, 2, 3, . . . , 101} have a sum that is even?

13. A coin is tossed ten times. In each case the outcome H (for heads) or T (for tails) is recorded. (One possible outcome of the ten tossings is denoted T H H T T T H T T H .) a. What is the total number of possible outcomes of the

coin-tossing experiment? b. In how many of the possible outcomes are exactly five

heads obtained? c. In how many of the possible outcomes are at least eight

heads obtained? d. In how many of the possible outcomes is at least one

head obtained? e. In how many of the possible outcomes is at most one

head obtained?

14. a. How many 16-bit strings contain exactly seven 1’s? b. How many 16-bit strings contain at least thirteen 1’s? c. How many 16-bit strings contain at least one 1? d. How many 16-bit strings contain at most one 1?

15. a. How many even integers are in the set

{1, 2, 3, . . . , 100}? b. How many odd integers are in the set

{1, 2, 3, . . . , 100}? c. How many ways can two integers be selected from the

set {1, 2, 3, . . . , 100} so that their sum is even? d. How many ways can two integers be selected from the

set {1, 2, 3, . . . , 100} so that their sum is odd? 16. Suppose that three computer boards in a production run of

forty are defective. A sample of five is to be selected to be checked for defects. a. How many different samples can be chosen? b. How many samples will contain at least one defective

board? c. What is the probability that a randomly chosen sample

of five contains at least one defective board?

17. Ten points labeled A, B, C, D, E, F, G, H, I, J are arranged in a plane in such a way that no three lie on the same straight line. a. How many straight lines are determined by the ten

points? b. How many of these straight lines do not pass through

point A? c. How many triangles have three of the ten points as ver-

tices? d. How many of these triangles do not have A as a vertex?

18. Suppose that you placed the letters in Example 9.5.10 into positions in the following order: first the M , then the I ’s, then the S’s, and then the P’s. Show that you would obtain the same answer for the number of distinguishable order- ings.

19. a. How many distinguishable ways can the letters of the word HULLABALOO be arranged in order?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.5 Counting Subsets of a Set: Combinations 583

b. How many distinguishable orderings of the letters of HULLABALOO begin with U and end with L?

c. How many distinguishable orderings of the letters of HULLABALOO contain the two letters HU next to each other in order?

20. a. How many distinguishable ways can the letters of the word MILLIMICRON be arranged in order?

b. How many distinguishable orderings of the letters of MILLIMICRON begin with M and end with N?

c. How many distinguishable orderings of the letters of MILLIMICRON contain the letters C R next to each other in order and also the letters ON next to each other in order?

21. In Morse code, symbols are represented by variable-length sequences of dots and dashes. (For example, A = ·−, 1 = · −−−−, ? = · · −− · · .) How many different sym- bols can be represented by sequences of seven or fewer dots and dashes?

22. Each symbol in the Braille code is represented by a rectan- gular arrangement of six dots, each of which may be raised or flat against a smooth background. For instance, when the word Braille is spelled out, it looks like this:

· ·· ·· · · ·· ·· · · ·· ·· · · ·· ·· · · ·· ·· · · ·· ·· · · ·· ·· · Given that at least one of the six dots must be raised, how many symbols can be represented in the Braille code?

23. On an 8× 8 chessboard, a rook is allowed to move any number of squares either horizontally or vertically. How many different paths can a rook follow from the bottom- left square of the board to the top-right square of the board if all moves are to the right or upward?

24. The number 42 has the prime factorization 2 ·3 ·7. Thus 42 can be written in four ways as a product of two posi- tive integer factors (without regard to the order of the fac- tors): 1 ·42, 2 ·21, 3 ·14, and 6 ·7. Answer a–d below with- out regard to the order of the factors. a. List the distinct ways the number 210 can be written as

a product of two positive integer factors. b. If n = p1 p2 p3 p4, where the pi are distinct prime num-

bers, how many ways can n be written as a product of two positive integer factors?

c. If n = p1 p2 p3 p4 p5, where the pi are distinct prime numbers, how many ways can n be written as a prod- uct of two positive integer factors?

d. If n = p1 p2 · · · pk , where the pi are distinct prime num- bers, how many ways can n be written as a product of two positive integer factors?

25. a. How many one-to-one functions are there from a set with three elements to a set with four elements?

b. How many one-to-one functions are there from a set with three elements to a set with two elements?

c. How many one-to-one functions are there from a set with three elements to a set with three elements?

d. How many one-to-one functions are there from a set with three elements to a set with five elements?

e.H How many one-to-one functions are there from a set with m elements to a set with n elements, where m ≤ n?

26. a. How many onto functions are there from a set with three elements to a set with two elements?

b. How many onto functions are there from a set with three elements to a set with five elements?

c.H How many onto functions are there from a set with three elements to a set with three elements?

d. How many onto functions are there from a set with four elements to a set with two elements?

e. How many onto functions are there from a set with four elements to a set with three elements?

f.✶H Let cm,n be the number of onto functions from a set of m elements to a set of n elements, where m ≥ n ≥ 1. Find a formula relating cm,n to cm−1,n and cm−1,n−1.

27. Let A be a set with eight elements. a. How many relations are there on A? b. How many relations on A are reflexive? c. How many relations on A are symmetric? d. How many relations on A are both reflexive and sym-

metric?

28.✶H A student council consists of three freshmen, four sopho- mores, four juniors, and five seniors. How many commit- tees of eight members of the council contain at least one member from each class?

29.✶ An alternative way to derive Theorem 9.5.1 uses the follow- ing division rule: Let n and k be integers so that k divides n. If a set consisting of n elements is divided into subsets that each contain k elements, then the number of such subsets is n/k. Explain how Theorem 9.5.1 can be derived using the division rule.

30. Find the error in the following reasoning: “Consider form- ing a poker hand with two pairs as a five-step process.

Step 1: Choose the denomination of one of the pairs. Step 2: Choose the two cards of that denomination. Step 3: Choose the denomination of the other of the pairs. Step 4: Choose the two cards of that second denomination. Step 5: Choose the fifth card from the remaining denomi- nations.

There are (13

1

) ways to perform step 1,

(4 2

) ways to perform

step 2, (12

1

) ways to perform step 3,

(4 2

) ways to perform

step 4, and (44

1

) ways to perform step 5. Therefore, the total

number of five-card poker hands with two pairs is 13 ·6 ·12 ·6 ·44 = 247,104.”

31.✶ Let Pn be the number of partitions of a set with n elements. Show that

Pn = (

n − 1 0

) Pn−1 +

( n − 1

1

) Pn−2 + · · · +

( n − 1 n − 1

) P0

for all integers n ≥ 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

584 Chapter 9 Counting and Probability

Exercises 32–38 refer to the sequence of Stirling numbers of the second kind.

32. Find S3,4 by exhibiting all the partitions of {x1, x2, x3, x4, x5} into four subsets.

33. Use the values computed in Example 9.5.12 and the recurrence relation and initial conditions found in Exam- ple 9.5.13 to compute S5,2.

34. Use the values computed in Example 9.5.12 and the recurrence relation and initial conditions found in Exam- ple 9.5.13 to compute S5,3.

35. Use the results of exercises 32–34 to find the total number of different partitions of a set with five elements.

36. Use mathematical induction and the recurrence relation found in Example 9.5.13 to prove that for all integers n ≥ 2, Sn,2 = 2n−1 − 1.

37. Use mathematical induction and the recurrence relation found in Example 9.5.13 to prove that for all integers n ≥ 2,∑kk=2(34−k Sk,2)− Sn+1,3.

38.H If X is a set with n elements and Y is a set with m ele- ments, express the number of onto functions from X and Y using Stirling numbers of the second kind. Justify your answer.

Answers for Test Yourself 1. (n

r

) ; n choose r 2.

(n r

) (Or: n choose r ) 3. the order in which they are chosen 4.

(n r

) = P(n,r)r ! 5. n or more; n or fewer

6. ( n

n1

) (n−n1 n2

) (n−n1−n2 n3

) · · · (n−n1−n2−···−nk−1

nk

) ( Or : n!n1!n2!n3!···nk !

) 7. the number of ways a set of size n can be partitioned

into r subsets 8. the number of partitions of X into r subsets of which {xn} is one; the number of partitions of X into r subsets, none of which is {xn}

9.6 r-Combinations with Repetition Allowed The value of mathematics in any science lies more in disciplined analysis and abstract thinking than in particular theories and techniques. — Alan Tucker, 1982

In Section 9.5 we showed that there are (n

r

) r -combinations, or subsets of size r , of a set

of n elements. In other words, there are (n

r

) ways to choose r distinct elements without

regard to order from a set of n elements. For instance, there are (4

3

) = 4 ways to choose

three elements out of a set of four: {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}. In this section we ask: How many ways are there to choose r elements without regard

to order from a set of n elements if repetition is allowed? A good way to imagine this is to visualize the n elements as categories of objects from which multiple selections may be made. For instance, if the categories are labeled 1, 2, 3, and 4 and three elements are chosen, it is possible to choose two elements of type 3 and one of type 1, or all three of type 2, or one each of types 1, 2 and 4. We denote such choices by [3, 3, 1], [2, 2, 2], and [1, 2, 4], respectively. Note that because order does not matter, [3, 3, 1] = [3, 1, 3] = [1, 3, 3], for example.

• Definition An r-combination with repetition allowed, or multiset of size r, chosen from a set X of n elements is an unordered selection of elements taken from X with repetition allowed. If X = {x1, x2, . . . , xn}, we write an r -combination with repetition allowed, or multiset of size r , as [xi1, xi2, . . . , xir ] where each xi j is in X and some of the xi j may equal each other.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.6 r -Combinations with Repetition Allowed 585

Example 9.6.1 r-Combinations with Repetition Allowed

Write a complete list to find the number of 3-combinations with repetition allowed, or multisets of size 3, that can be selected from {1, 2, 3, 4}. Observe that because the order in which the elements are chosen does not matter, the elements of each selection may be written in increasing order, and writing the elements in increasing order will ensure that no combinations are overlooked.

Solution [1, 1, 1] ; [1, 1, 2]; [1, 1, 3]; [1, 1, 4] all combinations with 1, 1 [1, 2, 2] ; [1, 2, 3]; [1, 2, 4]; all additional combinations with 1, 2 [1, 3, 3] ; [1, 3, 4]; [1, 4, 4]; all additional combinations with 1, 3 or 1, 4 [2, 2, 2] ; [2, 2, 3]; [2, 2, 4]; all additional combinations with 2, 2 [2, 3, 3] ; [2, 3, 4]; [2, 4, 4]; all additional combinations with 2, 3 or 2, 4 [3, 3, 3] ; [3, 3, 4]; [3, 4, 4]; all additional combinations with 3, 3 or 3, 4 [4, 4, 4] the only additional combination with 4, 4

Thus there are twenty 3-combinations with repetition allowed. ■

How could the number twenty have been predicted other than by making a complete list? Consider the numbers 1, 2, 3, and 4 as categories and imagine choosing a total of three numbers from the categories with multiple selections from any category allowed. The results of several such selections are represented by the table below.

Category 1 Category 2 Category 3 Category 4 Result of the Selection

1 from category 2| × | | ×× 2 from category 4

1 each from categories× | | × | × 1, 3, and 4

× × × | | | 3 from category 1

As you can see, each selection of three numbers from the four categories can be repre- sented by a string of vertical bars and crosses. Three vertical bars are used to separate the four categories, and three crosses are used to indicate how many items from each category are chosen. Each distinct string of three vertical bars and three crosses represents a dis- tinct selection. For instance, the string

×× | |× | represents the selection: two from category 1, none from category 2, one from category 3, and none from category 4. Thus the number of distinct selections of three elements that can be formed from the set {1, 2, 3, 4} with repetition allowed equals the number of dis- tinct strings of six symbols consisting of three |’s and three ×’s. But this equals the number of ways to select three positions out of six because once three positions have been chosen for the ×’s, the |’s are placed in the remaining three positions. Thus the answer is

( 6 3

) = 6!

3!(6− 3)! = 6 ·5 ·4 ·3! 3 ·2 ·1 ·3! = 20,

as was obtained earlier by a careful listing. The analysis of this example extends to the general case. To count the number of

r -combinations with repetition allowed, or multisets of size r , that can be selected from a

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

586 Chapter 9 Counting and Probability

set of n elements, think of the elements of the set as categories. Then each r -combination with repetition allowed can be represented as a string of n − 1 vertical bars (to separate the n categories) and r crosses (to represent the r elements to be chosen). The number of ×’s in each category represents the number of times the element represented by that category is repeated.

r ×'s to be placed in categories

Category 1 Category 2 Category 3 Category n – 1 Category n

The number of strings of n − 1 vertical bars and r crosses is the number of ways to choose r positions, into which to place the r crosses, out of a total of r + (n − 1) positions, leaving the remaining positions for the vertical bars. But by Theorem 9.5.1, this number is (r+n−1

r

) .

This discussion proves the following theorem.

Theorem 9.6.1

The number of r -combinations with repetition allowed (multisets of size r ) that can be selected from a set of n elements is

( r + n − 1

r

) .

This equals the number of ways r objects can be selected from n categories of objects with repetition allowed.

Example 9.6.2 Selecting 15 Cans of Soft Drinks of Five Different Types

A person giving a party wants to set out 15 assorted cans of soft drinks for his guests. He shops at a store that sells five different types of soft drinks.

a. How many different selections of cans of 15 soft drinks can he make?

b. If root beer is one of the types of soft drink, how many different selections include at least six cans of root beer?

c. If the store has only five cans of root beer but at least 15 cans of each other type of soft drink, how many different selections are there?

Solution

a. Think of the five different types of soft drinks as the n categories and the 15 cans of soft drinks to be chosen as the r objects (so n = 5 and r = 15). Each selection of cans of soft drinks is represented by a string of 5− 1 = 4 vertical bars (to separate the categories of soft drinks) and 15 crosses (to represent the cans selected). For instance, the string

××× | ××××××× | |××× |×× represents a selection of three cans of soft drinks of type 1, seven of type 2, none of type 3, three of type 4, and two of type 5. The total number of selections of 15 cans

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.6 r -Combinations with Repetition Allowed 587

of soft drinks of the five types is the number of strings of 19 symbols, 5− 1 = 4 of them | and 15 of them ×:

( 15 + 5− 1

15

) = (

19 15

) =

6 2 19 · 18 · 17 · 16 · 15!

15! · 4 · 3 · 2 ·1 = 3,876.

b. If at least six cans of root beer are included, we can imagine choosing six such cans first and then choosing 9 additional cans. The choice of the nine additional cans can be represented as a string of 9 ×’s and 4 |’s. For example, if root beer is type 1, then the string××× | |×× |×××× | represents a selection of three cans of root beer (in addition to the six chosen initially), none of type 2, two of type 3, four of type 4, and none of type 5. Thus the total number of selections of 15 cans of soft drinks of the five types, including at least six cans of root beer, is the number of strings of 13 symbols, 4 (= 5− 1) of them | and 9 of them ×:

( 9 + 4

9

) = (

13 9

) =

5 13 · 12 · 11 · 10 · 9!

9! · 4 · 3 · 2 ·1 = 715.

c. If the store has only five cans of root beer, then the number of different selections of 15 cans of soft drinks of the five types is the same as the number of different selections that contain five or fewer cans of root beer. Let T be the set of selections for which the type of cans of root beer is unrestricted, R≤5 the set of selections containing five or fewer cans of root beer, and R≥6 the set of selections containing six or more cans of root beer. Then

T = R≤5 ∪ R≥6 and R≤5 ∩ R≥6 = ∅. By part (a) N (T ) = 3,876 and by part (b) N (R≥6) = 715. Thus, by the difference rule,

N (R≤5) = N (T )− N (R≥6) = 3,876− 715 = 3,161. So the number of different selections of soft drinks is 3,161. ■

Example 9.6.3 Counting Triples (i, j, k) with 1 ≤ i ≤ j ≤ k ≤ n If n is a positive integer, how many triples of integers from 1 through n can be formed in which the elements of the triple are written in increasing order but are not necessarily distinct? In other words, how many triples of integers (i, j, k) are there with 1 ≤ i ≤ j ≤ k ≤ n?

Solution Any triple of integers (i, j, k) with 1 ≤ i ≤ j ≤ k ≤ n can be represented as a string of n − 1 vertical bars and three crosses, with the positions of the crosses indicating which three integers from 1 to n are included in the triple. The table below illustrates this for n = 5.

Category Result of the Selection 1 2 3 4 5

| | ×× | | × (3, 3, 5) × | × | | × | (1, 2, 4)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

588 Chapter 9 Counting and Probability

Thus the number of such triples is the same as the number of strings of (n − 1) |’s and 3×’s, which is

( 3 + (n − 1)

3

) = (

n + 2 3

) = (n + 2)!

3!(n + 2− 3)!

= (n + 2)(n + 1)n(n − 1)! 3!(n − 1)! =

n(n + 1)(n + 2) 6

. ■

Note that in Examples 9.6.2 and 9.6.3 the reasoning behind Theorem 9.6.1 was used rather than the statement of the theorem itself. Alternatively, in either example we could invoke Theorem 9.6.1 directly by recognizing that the items to be counted either are r -combinations with repetition allowed or are the same in number as such combinations. For instance, in Example 9.6.3 we might observe that there are exactly as many triples of integers (i, j, k) with 1 ≤ i ≤ j ≤ k ≤ n as there are 3-combinations of integers from 1 through n with repetition allowed because the elements of any such 3-combination can be written in increasing order in only one way.

Example 9.6.4 Counting Iterations of a Loop

How many times will the innermost loop be iterated when the algorithm segment below is implemented and run? (Assume n is a positive integer.)

for k := 1 to n for j := 1 to k

for i := 1 to j [Statements in the body of the inner loop, none containing branching statements that lead outside the loop]

next i next j

next k

Solution Construct a trace table for the values of k, j , and i for which the statements in the body of the innermost loop are executed. (See the table that follows.) Because i goes from 1 to j , it is always the case that i ≤ j . Similarly, because j goes from 1 to k, it is always the case that j ≤ k. To focus on the details of the table construction, consider what happens when k = 3. In this case, j takes each value 1, 2, and 3. When j = 1, i can only take the value 1 (because i ≤ j). When j = 2, i takes each value 1 and 2 (again because i ≤ j). When j = 3, i takes each value 1, 2, and 3 (yet again because i ≤ j).

→ → → → → → → →

k 1 2 3 · · · n j 1 1 2 1 2 3 · · · 1 2 · · · n i 1 1 1 2 1 1 2 1 2 3 · · · 1 1 2 · · · 1 · · · n

Observe that there is one iteration of the innermost loop for each column of this table, and there is one column of the table for each triple of integers (i, j, k) with 1 ≤ i ≤ j ≤ k ≤ n. But Example 9.6.3 showed that the number of such triples is [n(n + 1)(n + 2)]/6. Thus there are [n(n + 1)(n + 2)]/6 iterations of the innermost loop. ■

The solution in Example 9.6.4 is the most elegant and generalizable one. (See exer- cises 8 and 9.) An alternative solution using summations is outlined in exercise 21.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.6 r -Combinations with Repetition Allowed 589

Example 9.6.5 The Number of Integral Solutions of an Equation

How many solutions are there to the equation x1 + x2 + x3 + x4 = 10 if x1, x2, x3, and x4 are nonnegative integers?

Solution Think of the number 10 as divided into ten individual units and the variables x1, x2, x3, and x4 as four categories into which these units are placed. The number of units in each category xi indicates the value of xi in a solution of the equation. Each solution can, then, be represented by a string of three vertical bars (to separate the four categories) and ten crosses (to represent the ten individual units). For example, in the following table, the two crosses under x1, five crosses under x2, and three crosses under x4 represent the solution x1 = 2, x2 = 5, x3 = 0, and x4 = 3.

Categories Solution to the equation x1 + x2 + x3 + x4 = 10x1 x2 x3 x4 ×× | × × × × × | | × × × x1 = 2, x2 = 5, x3 = 0, and x4 = 3

× × × × | × × × × ×× | | x1 = 4, x2 = 6, x3 = 0, and x4 = 0

Therefore, there are as many solutions to the equation as there are strings of ten crosses and three vertical bars, namely

( 10 + 3

10

) = (

13 10

) = 13!

10!(13− 10)! = 13 ·12 ·11 ·10!

10! ·3 ·2 ·1 = 286. ■

Example 9.6.6 illustrates a variation on Example 9.6.5.

Example 9.6.6 Additional Constraints on the Number of Solutions

How many integer solutions are there to the equation x1 + x2 + x3 + x4 = 10 if each xi ≥ 1?

Solution In this case imagine starting by putting one cross in each of the four categories. Then distribute the remaining six crosses among the categories. Such a distribution can be represented by a string of three vertical bars and six crosses. For example, the string

××× | |×× | ×

indicates that there are three more crosses in category x1 in addition to the one cross already there (so x1 = 4), no more crosses in category x2 in addition to the one already there (so x2 = 1), two more crosses in category x3 in addition to the one already there (so x3 = 3), and one more cross in category x4 in addition to the one already there (so x4 = 2). It follows that the number of solutions to the equation that satisfy the given condition is the same as the number of strings of three vertical bars and six crosses, namely

( 6 + 3

6

) = (

9 6

) = 9!

6!(9− 6)! = 9 ·8 ·7 ·6! 6! ·3 ·2 ·1 = 84.

An alternative solution to this example is based on the observation that since each xi ≥ 1, we may introduce new variables yi = xi − 1 for each i = 1, 2, 3, 4. Then each yi ≥ 0, and y1 + y2 + y3 + y4 = 6. Thus the number of solutions of y1+y2+y3+y4 =6 in nonnegative integers is the same as the number of solutions of x1 + x2 + x3 + x4 = 10 in positive integers. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

590 Chapter 9 Counting and Probability

Which Formula to Use? Sections 9.2, 9.3, 9.5, and 9.6 have discussed four different ways of choosing k elements from n. The order in which the choices are made may or may not matter, and repetition may or may not be allowed. The following table summarizes which formula to use in which situation.

Order Matters Order Does Not Matter

Repetition Is Allowed nk (

k + n − 1 k

)

Repetition Is Not Allowed P(n, k) (

n

k

)

Test Yourself 1. Given a set X = {x1, x2, . . . , xn}, an r -combination with

repetition allowed, or a multiset of size r , chosen from X is _____, which is denoted _____.

2. If X = {x1, x2, . . . , xn}, the number of r -combinations with repetition allowed (or multisets of size r ) chosen from X is _____.

3. When choosing k elements from a set of n elements, order may or may not matter and repetition may or may not be allowed.

• The number of ways to choose the k elements when repetition is allowed and order matters is _____.

• The number of ways to choose the k elements when repetition is not allowed and order matters is _____.

• The number of ways to choose the k elements when repetition is not allowed and order does not matter is _____.

• The number of ways to choose the k elements when repetition is allowed and order does not matter is _____.

Exercise Set 9.6 1. a. According to Theorem 9.6.1, how many 5-combinations

with repetition allowed can be chosen from a set of three elements?

b. List all of the 5-combinations that can be chosen with repetition allowed from {1, 2, 3}.

2. a. According to Theorem 9.6.1, how many multisets of size four can be chosen from a set of three elements?

b. List all of the multisets of size four that can be chosen from the set {x, y, z}.

3. A bakery produces six different kinds of pastry, one of which is eclairs. Assume there are at least 20 pastries of each kind.

a. How many different selections of twenty pastries are there?

b. How many different selections of twenty pastries are there if at least three must be eclairs?

c. How many different selections of twenty pastries con- tain at most two eclairs?

4. A camera shop stocks eight different types of batteries, one of which is type A7b. Assume there are at least 30 batteries of each type. a. How many ways can a total inventory of 30 batteries be

distributed among the eight different types? b. How many ways can a total inventory of 30 batteries be

distributed among the eight different types if the inven- tory must include at least four A76 batteries?

c. How many ways can a total inventory of 30 batteries be distributed among the eight different types if the inven- tory includes at most three A7b batteries?

5. If n is a positive integer, how many 4-tuples of integers from 1 through n can be formed in which the elements of the 4-tuple are written in increasing order but are not nec- essarily distinct? In other words, how many 4-tuples of integers (i, j, k, m) are there with 1 ≤ i ≤ j ≤ k ≤ m ≤ n?

6. If n is a positive integer, how many 5-tuples of integers from 1 through n can be formed in which the elements of the 5-tuple are written in decreasing order but are not nec- essarily distinct? In other words, how many 5-tuples of integers (h, i, j, k, m) are there with n ≥ h ≥ i ≥ j ≥ k ≥ m ≥ 1?

7. Another way to count the number of nonnegative integral solutions to an equation of the form x1+x2+· · ·+xn =m is to reduce the problem to one of finding the number of n- tuples (y1, y2, . . . , yn) with 0 ≤ y1 ≤ y2 ≤ · · · ≤ yn ≤ m. The reduction results from letting yi = x1 + x2 + · · · + xi for each i = 1, 2, . . . , n. Use this approach to derive a gen- eral formula for the number of nonnegative integral solu- tions to x1 + x2 + · · · + xn = m.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.6 r -Combinations with Repetition Allowed 591

In 8 and 9, how many times will the innermost loop be iterated when the algorithm segment is implemented and run? Assume n, m, k, and j are positive integers.

8. for m := 1 to n for k := 1 to m

for j := 1 to k for i := 1 to j

[Statements in the body of the inner loop, none containing branching statements that lead outside the loop]

next i

next j

next k

next m

9. for k := 1 to n for j := k to n

for i := j to n [Statements in the body of the inner loop, none containing branching statements that lead outside the loop]

next i

next j

next k

In 10–14, find how many solutions there are to the given equa- tion that satisfy the given condition.

10. x1 + x2 + x3 = 20, each xi is a nonnegative integer. 11. x1 + x2 + x3 = 20, each xi is a positive integer.

12. y1 + y2 + y3 + y4 = 30, each yi is a nonnegative integer. 13. y1 + y2 + y3 + y4 = 30, each yi is an integer that is at

least 2.

14. a + b + c + d + e = 500, each of a, b, c, d, and e is an integer that is at least 10.

15.✶ For how many integers from 1 through 99,999 is the sum of their digits equal to 10?

16. Consider the situation in Example 9.6.2.

a. Suppose the store has only six cans of lemonade but at least 15 cans of each of the other four types, of soft drink. In how many different ways can five cans of soft drink be selected?

b. Suppose that the store has only five cans of root beer and only six cans of lemonade but at least 15 cans of each of

the other three types of soft drink. In how many different ways can five cans of soft drink be selected?

17. a.H A store sells 8 kinds of balloons with at least 30 of each kind. How many different combinations of 30 balloons can be chosen?

b. If the store has only 12 red balloons but at least 30 of each other kind of balloon, how many combinations of balloons can be chosen?

c. If the store has only 8 blue balloons but at least 30 of each other kind of balloon, how many combinations of balloons can be chosen?

d. If the store has only 12 red balloons and only 8 blue bal- loons but at least 30 of each other kind of balloon, how many combinations of balloons can be chosen?

18. A large pile of coins consists of pennies, nickels, dimes, and quarters. a. How many different collections of 30 coins can be cho-

sen if there are at least 30 of each kind of coin? b. If the pile contains only 15 quarters but at least 30 of

each other kind of coin, how many collections of 30 coins can be chosen?

c. If the pile contains only 20 dimes but at least 30 of each other kind of coin, how many collections of 30 coins can be chosen?

d. If the pile contains only 15 quarters and only 20 dimes but at least 30 of each other kind of coin, how many col- lections of 30 coins can be chosen?

19.H Suppose the bakery in exercise 3 has only ten eclairs but has at least twenty of each of the other kinds of pastry. a. How many different selections of twenty pastries are

there? b. Suppose in addition to having only ten eclairs, the bak-

ery has only eight napoleon slices. How many different selections of twenty pastries are there?

20. Suppose the camera shop in exercise 4 can obtain at most ten A76 batteries but can get at least 30 of each of the other types. a. How many ways can a total inventory of 30 batteries be

distributed among the eight different types? b. Suppose that in addition to being able to obtain only ten

A76 batteries, the store can get only six of type D303. How many ways can a total inventory of 30 batteries be distributed among the eight different types?

21. Observe that the number of columns in the trace table for Example 9.6.4 can be expressed as the sum

1 + (1 + 2) + (1 + 2 + 3) + · · · + (1 + 2 + · · · + n). Explain why this is so, and show how this sum simplifies to the same expression given in the solution of Example 9.6.4. Hint: Use a formula from the exercise set for Section 5.2.

Answers for Test Yourself 1. an unordered selection of elements taken from X with repetition allowed; [xi1 , xi2 , . . . , xir ] where each xi j is in X and some of the xi j may equal each other 2.

(r+n−1 r

) 3. nk; n(n − 1)(n − 2) · · · (n − k + 1) (Or : P(n, k)) ;

(n k

) ; (k+n−1

k

)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

592 Chapter 9 Counting and Probability

9.7 Pascal’s Formula and the Binomial Theorem I’m very well acquainted, too, with matters mathematical, I understand equations both the simple and quadratical. About binomial theorem I am teaming with a lot of news, With many cheerful facts about the square of the hypotenuse. — William S. Gilbert, The Pirates of Penzance, 1880

In this section we derive several formulas for values of (n

r

) The most important is Pascal’s

formula, which is the basis for Pascal’s triangle and is a crucial component of one of the proofs of the binomial theorem. We offer two distinct proofs for both Pascal’s formula and the binomial theorem. One of them is called “algebraic” because it relies to a great extent on algebraic manipulation, and the other is called “combinatorial,” because it is based on the kind of counting arguments we have been discussing in this chapter.

Example 9.7.1 Values of (

n n

) ,

( n

n − 1 )

,

( n

n − 2 )

Think of Theorem 9.5.1 as a general template: Regardless of what nonnegative numbers are placed in the boxes, if the number in the lower box is no greater than the number in the top box, then

( " ♦

) = "!♦!("− ♦)! .

Use Theorem 9.5.1 to show that for all integers n ≥ 0, (

n n

) = 1 9.7.1

( n

n − 1 )

= n, if n ≥ 1 9.7.2 (

n n − 2 )

= n(n − 1) 2

, if n ≥ 2. 9.7.3

Solution (

n n

) = n!

n!(n − n)! = 1 0! = 1 since 0! = 1 by definition

( n

n − 1 )

= n! (n − 1)!(n − (n − 1))!

= n ·(n − 1)! (n − 1)!(n − n + 1)! =

n 1

= n (

n n − 2

) = n!

(n − 2)!(n − (n − 2))!

= n ·(n − 1) ·(n − 2)! (n − 2)!2! =

n(n − 1) 2

Note that the result derived algebraically above, that (n

n

) equals 1, agrees with the fact

that a set with n elements has just one subset of size n, namely itself. Similarly, exercise 1 at the end of the section asks you to show algebraically that

(n 0

) = 1, which agrees with

the fact that a set with n elements has one subset, the empty set, of size 0. In exercise 2 you are also asked to show algebraically that

(n 1

) = n. This result agrees with the fact

that there are n subsets of size 1 that can be chosen from a set with n elements, namely the subsets consisting of each element taken alone.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 593

Example 9.7.2 (

n r

) = (

n n − r )

In exercise 5 at the end of the section you are asked to verify algebraically that (

n r

) = (

n n − r )

for all nonnegative integers n and r with r ≤ n. An alternative way to deduce this formula is to interpret it as saying that a set A with n

elements has exactly as many subsets of size r as it has subsets of size n − r . Derive the formula using this reasoning.

Solution Observe that any subset of size r can be specified either by saying which r ele- ments lie in the subset or by saying which n − r elements lie outside the subset.

A, A Set with n Elements

B, a subset with r elements

A – B, a subset with n – r elements

Any subset B with r elements completely determines a subset, A – B, with n – r elements.

Suppose A has k subsets of size r : B1, B2, . . . , Bk . Then each Bi can be paired up with exactly one set of size n − r , namely its complement A − Bi as shown below.

Subsets of Size r Subsets of Size n – r

B1

B2

Bk

A – B1

A – B2

A – Bk

All subsets of size r are listed in the left-hand column, and all subsets of size n − r are listed in the right-hand column. The number of subsets of size r equals the number of subsets of size n − r , and so

(n r

) = ( n

n−r ) . ■

The type of reasoning used in this example is called combinatorial, because it is obtained by counting things that are combined in different ways. A number of theorems have both combinatorial proofs and proofs that are purely algebraic.

Pascal’s Formula Pascal’s formula, named after the seventeenth-century French mathematician and philoso- pher Blaise Pascal, is one of the most famous and useful in combinatorics (which is the formal term for the study of counting and listing problems). It relates the value of

(n+1 r

)

to the values of ( n

r−1 )

and (n

r

) . Specifically, it says that

( n + 1

r

) = (

n r − 1 )

+ (

n r

)

whenever n and r are positive integers with r ≤ n. This formula makes it easy to compute higher combinations in terms of lower ones: If all the values of

(n r

) are known, then the

values of (n+1

r

) can be computed for all r such that 0 < r ≤ n.

H ul

to n-

D eu

tc h

Co lle

ct io

n/ CO

R B

IS

Blaise Pascal (1623–1662)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

594 Chapter 9 Counting and Probability

Pascal’s triangle, shown in Table 9.7.1, is a geometric version of Pascal’s formula. Sometimes it is simply called the arithmetic triangle because it was used centuries before Pascal by Chinese and Persian mathematicians. But Pascal discovered it independently, and ever since 1654, when he published a treatise that explored many of its features, it has generally been known as Pascal’s triangle.

Table 9.7.1 Pascal’s Triangle for (

Values of (

n r

))

r 0 1 2 3 4 5 · · · r − 1 r · · ·

n

0 1 · · . . . 1 1 1 · · . . . 2 1 2 1 · · . . . 3 1 3 3 1 · · . . . 4 1 4 6 + 4 1 · · . . . 5 1 5 10 = 10 5 1 · · . . . · · · · · · · · · . . .· · · · · · · · · . . .· · · · · · · · · . . . n

( n

0

) ( n

1

) ( n

2

) ( n

3

) ( n

4

) ( n

5

) . . .

( n

r − 1

) +

( n

r

) . . .

n + 1 (

n + 1 0

) ( n + 1

1

) ( n + 1

2

) ( n + 1

3

) ( n + 1

4

) ( n + 1

5

) . . . =

( n + 1

r

) . . .

· · · · · · · · . . . · · · · · · · · . . . · · · · · · · · . . .

Each entry in the triangle is a value of (n

r

) . Pascal’s formula translates into the fact that

the entry in row n + 1, column r equals the sum of the entry in row n, column r − 1 plus the entry in row n, column r . That is, the entry in a given interior position equals the sum of the two entries directly above and to the above left. The left-most and right-most entries in each row are 1 because

(n n

) = 1 by Example 9.7.1 and

(n 0

) = 1 by exercise 1 at

the end of this section.

Example 9.7.3 Calculating (

n r

) Using Pascal’s Triangle

Use Pascal’s triangle to compute the values of (

6 2

) and (

6 3

) .

Solution By construction, the value in row n, column r of Pascal’s triangle is the value of(n r

) , for every pair of positive integers n and r with r ≤ n. By Pascal’s formula,

(n+1 r

)

can be computed by adding together ( n

r−1 )

and (n

r

) , which are located directly above and

above left of (n+1

r

) . Thus, (

6 2

) = (

5 1

) + (

5 2

) = 5 + 10 = 15 and

( 6 3

) = (

5 2

) + (

5 3

) = 10 + 10 = 20. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 595

Pascal’s formula can be derived by two entirely different arguments. One is alge- braic; it uses the formula for the number of r -combinations obtained in Theorem 9.5.1. The other is combinatorial; it uses the definition of the number of r -combinations as the number of subsets of size r taken from a set with a certain number of elements. We give both proofs since both approaches have applications in many other situations.

Theorem 9.7.1 Pascal’s Formula

Let n and r be positive integers and suppose r ≤ n. Then (

n + 1 r

) = (

n r − 1 )

+ (

n r

) .

Proof (algebraic version):

Let n and r be positive integers with r ≤ n. By Theorem 9.5.1, (

n r − 1 )

+ (

n r

) = n!

(r − 1)!(n − (r − 1))! + n!

r !(n − r)!

= n! (r − 1)!(n − r + 1)! +

n! r !(n − r)! .

To add these fractions, a common denominator is needed, so multiply the numera- tor and denominator of the left-hand fraction by r and multiply the numerator and denominator of the right-hand fraction by (n − r + 1). Then

( n

r − 1 )

+ (

n r

) = n!

(r − 1)!(n − r + 1)! · r r

+ n! r !(n − r)! ·

(n − r + 1) (n − r + 1)

= n! ·r (n − r + 1)!r(r − 1)! +

n ·n!− n! ·r + n! (n − r + 1)(n − r)!r !

= n! ·r + n! ·n − n! ·r + n! (n − r + 1)!r ! =

n!(n + 1) (n + 1− r)!r !

= (n + 1)! ((n + 1)− r)!r ! =

( n + 1

r

) .

Proof (combinatorial version):

Let n and r be positive integers with r ≤ n. Suppose S is a set with n + 1 elements. The number of subsets of S of size r can be calculated by thinking of S as consisting of two pieces: one with n elements {x1, x2, . . . , xn} and the other with one element {xn+1}.

Any subset of S with r elements either contains xn+1 or it does not. If it contains xn+1, then it contains r − 1 elements from the set {x1, x2, . . . , xn}. If it does not contain xn+1, then it contains r elements from the set {x1, x2, . . . , xn}.

continued on page 596

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

596 Chapter 9 Counting and Probability

Subsets of Size r of {x1, x2, . . . , xn+1}

subsets of size r that consist entirely of elements from {x1, x2 , . . . , xn}

subsets of size r that contain xn+1 and r – 1 elements from {x1, x2 , . . . , xn}

There are n r( )of these.

There are n

r – 1( )of these.

By the addition rule, ⎡

⎣ number of subsets of {x1, x2, . . . , xn, xn+1} of size r

⎦ =

⎣ number of subsets of {x1, x2, . . . , xn} of size r − 1

⎦+

⎣ number of subsets of {x1, x2, . . . , xn} of size r

⎦ .

By Theorem 9.5.1, the set {x1, x2, . . . , xn, xn+1} has (n+1

r

) subsets of size r , the set

{x1, x2, . . . , xn} has ( n

r−1 )

subsets of size r − 1, and the set {x1, x2, . . . , xn} has (n

r

)

subsets of size r . Thus (

n + 1 r

) = (

n r − 1 )

+ (

n r

) ,

as was to be shown.

Example 9.7.4 Deriving New Formulas from Pascal’s Formula

Use Pascal’s formula to derive a formula for (n+2

r

) in terms of values of

(n r

) , ( n

r−1 ) , and( n

r−2 ) . Assume n and r are nonnegative integers and 2 ≤ r ≤ n.

Solution By Pascal’s formula, (

n + 2 r

) = (

n + 1 r − 1 )

+ (

n + 1 r

) .

Now apply Pascal’s formula to (n+1

r−1 )

and (n+1

r

) and substitute into the above to obtain

( n + 2

r

) = [(

n r − 2 )

+ (

n r − 1 )]

+ [(

n r − 1 )

+ (

n r

)] .

Combining the two middle terms gives (

n + 2 r

) = (

n r − 2 )

+ 2 (

n r − 1 )

+ (

n r

)

for all nonnegative integers n and r such that 2 ≤ r ≤ n. ■

The Binomial Theorem In algebra a sum of two terms, such as a + b, is called a binomial. The binomial

theorem gives an expression for the powers of a binomial (a + b)n , for each positive integer n and all real numbers a and b.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 597

Consider what happens when you calculate the first few powers of a + b. According to the distributive law of algebra, you take the sum of the products of all combinations of individual terms:

(a + b)2 = (a + b)(a + b) = aa + ab + ba + bb, (a + b)3 = (a + b)(a + b)(a + b)

= aaa + aab + aba + abb + baa + bab + bba + bbb, (a + b)4 = (a + b)︸ ︷︷ ︸(a + b)︸ ︷︷ ︸(a + b)︸ ︷︷ ︸(a + b)︸ ︷︷ ︸

1st 2nd 3rd 4th factor factor factor factor

= aaaa + aaab + aaba + aabb + abaa + abab + abba + abbb + baaa + baab + baba + babb + bbaa + bbab + bbba + bbbb.

Now focus on the expansion of (a + b)4. (It is concrete, and yet it has all the features of the general case.) A typical term of this expansion is obtained by multiplying one of the two terms from the first factor times one of the two terms from the second factor times one of the two terms from the third factor times one of the two terms from the fourth factor. For example, the term abab is obtained by multiplying the a’s and b’s marked with arrows below.

↓ ↓ ↓ ↓ (a + b)(a + b)(a + b)(a + b)

Since there are two possible values—a or b—for each term selected from one of the four factors, there are 24 = 16 terms in the expansion of (a + b)4.

Now some terms in the expansion are “like terms” and can be combined. Consider all possible orderings of three a’s and one b, for example. By the techniques of Section 9.5, there are

(4 1

) = 4 of them. And each of the four occurs as a term in the expansion of

(a + b)4:

aaab aaba abaa baaa.

By the commutative and associative laws of algebra, each such term equals a3b, so all four are “like terms.” When the like terms are combined, therefore, the coefficient of a3b equals (4

1

) .

Similarly, the expansion of (a + b)4 contains the (4

2

) = 6 different orderings of two

a’s and two b’s,

aabb abab abba baab baba bbaa,

all of which equal a2b2, so the coefficient of a2b2 equals (4

2

) . By a similar analysis, the

coefficient of ab3 equals (4

3

) . Also, since there is only one way to order four a’s, the

coefficient of a4 is 1 (which equals (4

0

) , and since there is only one way to order four

b’s, the coefficient of b4 is 1 (which equals (4

4

) ). Thus, when all of the like terms are

combined,

(a + b)4 = (

4 0

) a4 + (

4 1

) a3b + (

4 2

) a2b2 +

( 4 3

) ab3 + (

4 4

) b4

= a4 + 4a3b + 6a2b2 + 4ab3 + b4.

The binomial theorem generalizes this formula to an arbitrary nonnegative integer n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

598 Chapter 9 Counting and Probability

Theorem 9.7.2 Binomial Theorem

Given any real numbers a and b and any nonnegative integer n,

(a + b)n = n∑

k=0

( n k

) an−kbk

= an + (

n 1

) an−1b1 +

( n 2

) an−2b2 + · · · +

( n

n − 1 )

a1bn−1 + bn.

Note that the second expression equals the first because (n

0

) = 1 and

(n n

) = 1, for all

nonnegative integers n, provided that b0 = 1 and an−n = 1. It is instructive to see two proofs of the binomial theorem: an algebraic proof and a

combinatorial proof. Both require a precise definition of integer power.

• Definition For any real number a and any nonnegative integer n, the nonnegative integer powers of a are defined as follows:

an = {

1 if n = 0 a ·an−1 if n > 0

In some mathematical contexts, 00 is left undefined. Defining it to be 1, as is done

here, makes it possible to write general formulas such as n∑

i=0 xi = 11−x without having to

exclude values of the variables that result in the expression 00. The algebraic version of the binomial theorem uses mathematical induction and calls

upon Pascal’s formula at a crucial point.

Note This is the definition of O0 given by Donald E. Knuth in The Art of Computer Programming, Volume 1: Fundamental Algorithms, Third Edition (Reading, Mass.: Addison-Wesley, 1997), p. 57.

Proof of the Binomial Theorem (algebraic version):

Suppose a and b are real numbers. We use mathematical induction and let the prop- erty P(n) be the equation

(a + b)n = n∑

k=0

( n k

) an−kbk . ← P(n)

Show that P(0) is true: When n = 0, the binomial theorem states that:

(a + b)0 = 0∑

k=0

( 0 k

) a0−kbk . ← P(0)

But the left-hand side is (a + b)0 = 1 [by definition of power], and the right-hand side is

0∑

k=0

( 0 k

) a0−kbk =

( 0 0

) a0−0b0

= 0! 0! ·(0− 0)! ·1 ·1 =

1 1 ·1 = 1

also [since 0! = 1, a0 = 1, and b0 = 1]. Hence P(0) is true.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 599

Show that for all integers m≥0, if P(m) is true then P(m+1) is true: Let an integer m ≥ 0 be given, and suppose P(m) is true. That is, suppose

(a + b)m = m∑

k=0

( m k

) am−kbk . P(m)

inductive hypothesis.

We need to show that P(m + 1) is true:

(a + b)m+1 = m+1∑

k=0

( m + 1

k

) a(m+1)−kbk . P(m + 1)

Now, by definition of the (m + 1)st power,

(a + b)m+1 = (a + b) ·(a + b)m, so by substitution from the inductive hypothesis,

(a + b)m+1 = (a + b) · m∑

k=0

( m k

) am−kbk

= a · m∑

k=0

( m k

) am−kbk + b ·

m∑

k=0

( m k

) am−kbk

= m∑

k=0

( m k

) am+1−kbk +

m∑

k=0

( m k

) am−kbk+1

by the generalized distributive law and the facts that a ·am−k = a1+m−k = am+1−k and b ·bk = b1+k = bk+1.

We transform the second summation on the right-hand side by making the change of variable j = k + 1. When k = 0, then j = 1. When k = m, then j = m + 1. And since k = j − 1, the general term is

( m k

) am−kbk+1 =

( m

j − 1 )

am−( j−1)b j = (

m j − 1 )

am+1− j b j .

Hence the second summation on the right-hand side above is

m+1∑

j=1

( m

j − 1 )

am+1− j b j .

But the j in this summation is a dummy variable; it can be replaced by the letter k, as long as the replacement is made everywhere the j occurs:

m+1∑

j=1

( m

j − 1 )

am+1− j b j = m+1∑

k=1

( m

k − 1 )

am+1−kbk .

Substituting back, we get

(a + b)m+1 = m∑

k=0

( m k

) am+1−kbk +

m+1∑

k=1

( m

k − 1 )

am+1−kbk .

[The reason for the above maneuvers was to make the powers of a and b agree so that we can add the summations together term by term, except for the first and the last terms, which we must write separately.]

continued on page 600

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

600 Chapter 9 Counting and Probability

Thus

(a + b)m+1 = (

m 0

) am+1−0b0 +

m∑

k=1

[( m k

) + (

m k − 1 )]

am+1−kbk

+ (

m (m + 1)− 1

) am+1−(m+1)bm+1

= am+1 + m∑

k=1

[( m k

) + (

m k − 1 )]

am+1−kbk + bm+1 since a0 = b0 = 1 and(

m 0

) = (

m m

) = 1.

But [(

m k

) + (

m k − 1 )]

= (

m + 1 k

) by Pascal’s formula.

Hence

(a + b)m+1 = am+1 + m∑

k=1

( m + 1

k

) a(m+1)−kbk + bm+1

= m+1∑

k=0

( m + 1

k

) a(m+1)−kbk because

( m + 1

0

) = (

m + 1 m + 1

) = 1

which is what we needed to show.

It is instructive to write out the product (a + b) ·(a + b)m without using the summa- tion notation but using the inductive hypothesis about (a + b)m :

(a + b)m+1 = (a + b) · [

am + (

m 1

) am−1b + · · · +

( m

k − 1 )

am−(k−1)bk−1

+ (

m k

) am−kbk + · · · +

( m

m − 1 )

abm−1 + bm ]

.

You will see that the first and last coefficients are clearly 1 and that the term containing am+1−kbk is obtained from multiplying am−kbk by a and am−(k−1)bk−1 by b [because m + 1− k = m − (k − 1)]. Hence the coefficient of am+1−kbk equals the sum of

(m k

)

and ( m

k−1 ) . This is the crux of the algebraic proof.

If n and r are nonnegative integers and r ≤ n, then (n

r

) is called a binomial coefficient

because it is one of the coefficients in the expansion of the binomial expression (a + b)n . The combinatorial proof of the binomial theorem follows.

Proof of Binomial Theorem (combinatorial version):

[The combinatorial argument used here to prove the binomial theorem works only for n ≥ 1. If we were giving only this combinatorial proof, we would have to prove the case n = 0 separately. Since we have already given a complete algebraic proof that includes the case n = 0, we do not prove it again here.]

Let a and b be real numbers and n an integer that is at least 1. The expression (a + b)n can be expanded into products of n letters, where each letter is either a or b.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 601

For each k = 0, 1, 2, . . . , n, the product an−kbk = a ·a ·a · · · a︸ ︷︷ ︸ ·b ·b ·b · · · b︸ ︷︷ ︸

n − k factors k factors

occurs as a term in the sum the same number of times as there are orderings of (n − k) a’s and k b’s. But this number is

(n k

) , the number of ways to choose k

positions into which to place the b’s. [The other n − k positions will be filled by a′s.] Hence, when like terms are combined, the coefficient of an−kbk in the sum is

(n k

) .

Thus

(a + b)n = n∑

k=0

( n k

) an−kbk .

This is what was to be proved.

Example 9.7.5 Substituting into the Binomial Theorem

Expand the following expressions using the binomial theorem:

a. (a + b)5 b. (x − 4y)4

Solution

a. (a + b)5 = 5∑

k=0

( 5 k

) a5−kbk

= a5 + (

5 1

) a5−1b1 +

( 5 2

) a5−2b2 +

( 5 3

) a5−3b3 +

( 5 4

) a5−4b4 + b5

= a5 + 5a4b + 10a3b2 + 10a2b3 + 5ab4 + b5

b. Observe that (x − 4y)4 = (x + (−4y))4. So let a = x and b = (−4y), and substitute into the binomial theorem.

(x − 4y)4 = 4∑

k=0

( 4 k

) x4−k(−4y)k

= x4 + (

4 1

) x4−1(−4y)1 +

( 4 2

) x4−2(−4y)2 +

( 4 3

) x4−3(−4y)3 + (−4y)4

= x4 + 4x3(−4y) + 6x2(16y2) + 4x1(−64y3) + (256y4) = x4 − 16x3 y + 96x2 y2 − 256xy3 + 256y4 ■

Example 9.7.6 Deriving Another Combinatorial Identity from the Binomial Theorem

Use the binomial theorem to show that

2n = n∑

k=0

( n k

) = (

n 0

) + (

n 1

) + (

n 2

) + · · · +

( n n

)

for all integers n ≥ 0. Solution Since 2 = 1 + 1, 2n = (1 + 1)n . Apply the binomial theorem to this expression

by letting a = 1 and b = 1. Then

2n = n∑

k=0

( n k

) ·1n−k ·1k =

n∑

k=0

( n k

) ·1 ·1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

602 Chapter 9 Counting and Probability

since 1n−k = 1 and 1k = 1. Consequently,

2n = n∑

k=0

( n k

) = (

n 0

) + (

n 1

) + (

n 2

) + · · · +

( n n

) . ■

Example 9.7.7 Using a Combinatorial Argument to Derive the Identity

According to Theorem 6.3.1, a set with n elements has 2n subsets. Apply this fact to give a combinatorial argument to justify the identity

( n 0

) + (

n 1

) + (

n 2

) + (

n 3

) + · · · +

( n n

) = 2n.

Solution Suppose S is a set with n elements. Then every subset of S has some number of elements k, where k is between 0 and n. It follows that the total number of subsets of S, N (P(S)), can be expressed as the following sum:

⎣ number of subsets of S

⎦ =

⎣ number of subsets of size 0

⎦+

⎣ number of subsets of size 1

⎦+ · · · +

⎣ number of subsets of size n

⎦ .

Now the number of subsets of size k of a set with n elements is (n

k

) . Hence the

number of subsets of S = (

n 0

) + (

n 1

) + (

n 2

) + · · · +

( n n

)

But by Theorem 6.3.1, S has 2n subsets. Hence (

n 0

) + (

n 1

) + (

n 2

) + (

n 3

) + · · · +

( n n

) = 2n. ■

Example 9.7.8 Using the Binomial Theorem to Simplify a Sum

Express the following sum in closed form (without using a summation symbol and with- out using an ellipsis · · · ):

n∑

k=0

( n k

) 9k

Solution When the number 1 is raised to any power, the result is still 1. Thus n∑

k=0

( n k

) 9k =

n∑

k=0

( n k

) 1n−k9k

= (1 + 9)n by the binomial theorem with a = 1 and b = 9 = 10n . ■

Test Yourself 1. If n and r are nonnegative integers with r ≤ n, then the rela-

tion between (n

r

) and ( n

n−r )

is _____.

2. Pascal’s formula says that if n and r are positive integers with r ≤ n, then _____.

3. The crux of the algebraic proof of Pascal’s formula is that to add two fractions you need to express both of them with a _____.

4. The crux of the combinatorial proof of Pascal’s formula is that the set of subsets of size r of a set {x1, x2, . . . , xn+1} can be partitioned into the set of subsets of size r that con- tain _____ and those that _____.

5. The binomial theorem says that given any real numbers a and b and any nonnegative integer n, _____.

6. The crux of the algebraic proof of the binomial theorem is that, after making a change of variable so that two

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.7 Pascal’s Formula and the Binomial Theorem 603

summations have the same lower and upper limits and the exponents of a and b are the same, you use the fact that(m

k

) + ( m

k−1 )

= _____.

7. The crux of the combinatorial proof of the binomial theorem is that the number of ways to arrange k b’s and (n − k) a’s in order is _____.

Exercise Set 9.7 In 1–4, use Theorem 9.5.1 to compute the values of the indi- cated quantities. (Assume n is an integer.)

1. (

n 0

) , for n ≥ 0 2.

( n 1

) , for n ≥ 1

3. (

n 2

) , for n ≥ 2 4.

( n 3

) , for n ≥ 3

5. Use Theorem 9.5.1 to prove algebraically that (n

r

) = ( n

n−r ) ,

for integers n and r with 0 ≤ r ≤ n. (This can be done by direct calculation; it is not necessary to use mathematical induction.)

Justify the equations in 6–9 either by deriving them from for- mulas in Example 9.7.1 or by direct computation from Theo- rem 9.5.1. Assume m, n, k, and r are integers.

6. (

m + k m + k − 1

) = m + k, for m + k ≥ 1

7. (

n + 3 n + 1

) = (n + 3)(n + 2)

2 , for n ≥ −1

8. (

k − r k − r

) = 1, for k − r ≥ 0

9. (

2n n

) for n ≥ 0

10. a. Use Pascal’s triangle given in Table 9.7.1 to compute the

values of (6

2

) , (6

3

) , (6

4

) , and (6

5

) .

b. Use the result of part (a) and Pascal’s formula to compute(7 3

) , (7

4

) , and (7

5

) .

c. Complete the row of Pascal’s triangle that corresponds to n = 7.

11. The row of Pascal’s triangle that corresponds to n = 8 is as follows:

1 8 28 56 70 56 28 8 1.

What is the row that corresponds to n = 9? 12. Use Pascal’s formula repeatedly to derive a formula for(n+3

r

) in terms of values of

(n k

) with k ≤ r . (Assume n and

r are integers with n ≥ r ≥ 3.) 13. Use Pascal’s formula to prove by mathematical induction

that if n is an integer and n ≥ 1, then n+1∑

i=2

( i 2

) = (

2 2

) + (

3 2

) + · · · +

( n + 1

2

)

= (

n + 2 3

) .

14.H Prove that if n is an integer and n ≥ 1, then

1 ·2 + 2 ·3 + · · · + n(n + 1) = 2 (

n + 2 3

) .

15. Prove the following generalization of exercise 13: Let r be a fixed nonnegative integer. For all integers n with n ≥ r ,

n∑

i=r

( i r

) = (

n + 1 r + 1

) .

16. Think of a set with m + n elements as composed of two parts, one with m elements and the other with n elements. Give a combinatorial argument to show that (

m + n r

) = (

m 0

)( n r

) + (

m 1

)( n

r − 1

) + · · · +

( m r

)( n 0

) ,

where m and n are positive integers and r is an integer that is less than or equal to both m and n.

This identity gives rise to many useful additional identi- ties involving the quantities

(n k

) . Because Alexander Vander-

monde published an influential article about it in 1772, it is generally called the Vandermonde convolution. However, it was known at least in the 1300s in China by Chu Shih-chieh.

17.H Prove that for all integers n ≥ 0, (

n 0

)2 + (

n 1

)2 + · · · +

( n n

)2 = (

2n n

) .

18. Let m be any nonnegative integer. Use mathematical induc- tion and Pascal’s formula to prove that for all integers n ≥ 0, (

m 0

) + (

m + 1 1

) + · · · +

( m + n

n

) = (

m + n + 1 n

) .

Use the binomial theorem to expand the expressions in 19–27.

19. (1 + x)7 20. (p + q)6 21.(1− x)6

22. (u − v)5 23. (p − 2q)4 24. (u2 − 3v)4

25. (

x + 1 x

)5 26. (

3 a − a

3

)5 27. (

x2 + 1 x

)5

28. In Example 9.7.5 it was shown that

(a + b)5 = a5 + 5a4b + 10a3b2 + 10a2b3 + 5ab4 + b35. Evaluate (a + b)6 by substituting the expression above into the equation

(a + b)6 = (a + b)(a + b)5

and then multiplying out and combining like terms.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

604 Chapter 9 Counting and Probability

In 29–34, find the coefficient of the given term when the expres- sion is expanded by the binomial theorem.

29. x6 y3 in (x + y)9 30. x7 in (2x + 3)10

31. a5b7 in (a − 2b)12 32. u16v4 in (u2 − v2)10

33. p16q7 in (3p2 − 2q)15 34. x9 y10 in (2x − 3y2)14

35. As in the proof of the binomial theorem, transform the sum- mation

n∑

k=0

( m k

) am−kbk+1

by making the change of variable j = k + 1. Use the binomial theorem to prove each statement in 36–41.

36. For all integers n ≥ 1, (

n 0

) − (

n 1

) + (

n 2

) − · · · + (−1)n

( n n

) = 0.

(Hint: Use the fact that 1 + (−1) = 0.) 37.H For all integers n ≥ 0,

3n = (

n 0

) + 2 (

n 1

) + 22 (

n 2

) + · · · + 2n

( n n

) .

38. For all integers m ≥ 0, m∑

i=0 (−1)i (

m i

) 2m−i = 1.

39. For all integers n ≥ 0, n∑

i=0 (−1)i (

n i

) 3n−i = 2n .

40. For all integers n ≥ 0 and for all nonnegative real numbers x, 1 + nx ≤ (1 + x)n .

41.H For all integers n ≥ 1, (

n 0

) − 1

2

( n 1

) + 1

22

( n 2

) − 1

23

( n 3

)

+ · · · + (−1)n−1 1 2n−1

( n

n − 1

) =

⎧ ⎨

⎩ 0 if n is even

1 2n−1

if n is odd .

42. Use mathematical induction to prove that for all integers n ≥ 1, if S is a set with n elements, then S has the same

number of subsets with an even number of elements as with an odd number of elements. Use this fact to give a combina- torial argument to justify the identity of exercise 36.

Express each of the sums in 43–54 in closed form (without using a summation symbol and without using an ellipsis · · · ).

43. n∑

k=0

( n k

) 5k 44.

m∑

i=0

( m i

) 4i

45. n∑

i=0

( n i

) xi 46.

m∑

k=0

( m k

) 2m−k xk

47. 2n∑

j=0 (−1) j (

2n j

) x j 48.

n∑

r=0

( n r

) x2r

49. m∑

i=0

( m i

) pm−i q2i 50.

n∑

k=0

( n k

) 1 2k

51. m∑

i=0 (−1)i (

m i

) 1 2i

52. n∑

k=0

( n k

) 32n−2k22k

53. n∑

i=0 (−1)i (

n i

) 5n−i 2i 54.

n∑

k=0 (−1)k (

n k

) 32n−2k22k

55.✶ (For students who have studied calculus) a. Explain how the equation below follows from the bino-

mial theorem:

(1 + x)n = n∑

k=0

( n k

) xk .

b. Write the formula obtained by taking the derivative of both sides of the equation in part (a) with respect to x .

c. Use the result of part (b) to derive the formulas below.

(i) 2n−1 = 1 n

[( n 1

) + 2 (

n 2

) + 3 (

n 3

) + · · · + n

( n n

)]

(ii) n∑

k=1 k (

n k

) (−1)k = 0

d. Express n∑

k=1 k (

n k

) 3k in closed form (without using a

summation sign or ellipsis).

Answers for Test Yourself 1. (n

r

) = ( n

n−r )

2. (n+1

r

) = ( n

r−1 )

+ (n

r

) 3. common denominator 4. xn+1; do not contain xn+1

5. (a + b)n = n∑

k=0

(n k

) an−kbk 6.

(m+1 k

) 7. (n

k

)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.8 Probability Axioms and Expected Value 605

9.8 Probability Axioms and Expected Value The theory of probability is at bottom nothing but common sense reduced to a calculus. — Pierre-Simon Laplace (1749–1827)

Up to this point, you have calculated probabilities only for situations, such as tossing a fair coin or rolling a pair of balanced dice, where the outcomes in the sample space are all equally likely. But coins are not always fair and dice are not always balanced. How is it possible to calculate probabilities for these more general situations?

Ye vg

en y

K ha

ld ei

/C O

R B

IS

Andrei Nikolaevich Kolmogorov (1903–1987)

The following axioms were formulated by A. N. Kolmogorov in 1933 to provide a theoretical foundation for a far-ranging theory of probability. In this section we state the axioms, derive a few consequences, and introduce the notion of expected value.

Recall that a sample space is a set of all outcomes of a random process or experiment and that an event is a subset of a sample space.

Probability Axioms

Let S be a sample space, A probability function P from the set of all events in S to the set of real numbers satisfies the following three axioms: For all events A and B in S,

1. 0 ≤ P(A) ≤ 1 2. P(∅) = 0 and P(S) = 1 3. If A and B are disjoint (that is, if A ∩ B = ∅), then the probability of the union

of A and B is

P(A ∪ B) = P(A) + P(B).

Example 9.8.1 Applying the Probability Axioms

Suppose that A and B are events in a sample space S. If A and B are disjoint, could P(A) = 0.6 and P(B) = 0.8?

Solution No. Probability axiom 3 would imply that P(A ∪ B) = P(A) + P(B) = 0.6 + 0.8 = 1.4, and since 1.4 > 1, this result would violate probability axiom 1. ■

Example 9.8.2 The Probability of the Complement of an Event

Suppose that A is an event in a sample space S. Deduce that P(Ac) = 1− P(A). Solution By Theorem 6.2.2(5), with S playing the role of the universal set U ,

A ∩ Ac = ∅ and A ∪ Ac = S. Thus S is the disjoint union of A and Ac, and so

P(A ∪ Ac) = P(A) + P(Ac) = P(S) = 1. Subtracting P(A) from both sides gives the result that P(Ac) = 1− P(A). ■

Probability of the Complement of an Event

If A is any event in a sample space S, then

P(Ac) = 1− P(A). 9.8.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

606 Chapter 9 Counting and Probability

It is important to check that Kolmogorov’s probability axioms are consistent with the results obtained using the equally likely probability formula. To see that this is the case, let S be a finite sample space with outcomes a1, a2, a3, . . . , an . It is clear that all the singleton sets {a1}, {a2}, {a3}, . . . , {an} are mutually disjoint and that their union is S. Since P(S) = 1, probability axiom 3 can be applied multiple times (see exercise 13 at the end of this section) to obtain

P({a1} ∪ {a2} ∪ {a3} ∪ · · · ∪ {an}) = n∑

k=1 P({ak}) = 1.

If, in addition, all the outcomes are equally likely, there is a positive real number c so that

P({a1}) = P({a2}) = P({a3}) = · · · = P({an}) = c. Hence

1 = n∑

k=1 c = c + c + · · · + c︸ ︷︷ ︸ = nc,

n terms

and thus

c = 1 n .

It follows that if A is any event with outcomes ai1 , ai2 , ai3 , . . . , aim , then

P(A) = m∑

k=1 P({aik }) =

m∑

k=1

1 n

= m n

= N (A) N (S)

,

which is the result given by the equally likely probability formula.

Example 9.8.3 The Probability of a General Union of Two Events

Follow the steps outlined in parts (a) and (b) below to prove the following formula:

Probability of a General Union of Two Events

If S is any sample space and A and B are any events in S, then

P(A ∪ B) = P(A) + P(B)− P(A ∩ B). 9.8.2

In both steps, suppose that A and B are any events in a sample space S.

a. Show that A ∪ B is a disjoint union of the following sets: A − (A ∩ B), B − (A ∩ B), and A ∩ B.

b. In exercise 12 at the end of the section, you are asked to prove that for any events U and V in a sample space S, if U ⊆ V then P(V −U ) = P(V )− P(U ). Use this result and the result of part (a) to finish the proof of the formula.

Solution

a. Refer to Figure 9.8.1 on the next page as you read the following explanation. Elements in the set A − (A ∩ B) are in the region shaded blue, elements in B − (A ∩ B) are in the region shaded gray, and elements in A ∩ B are in the white region.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.8 Probability Axioms and Expected Value 607

A BA – (A B) B – (A B)

BA

Figure 9.8.1

Part 1: Show that A ∪ B ⊆ (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B): Given any element x in A ∪ B, x satisfies exactly one of the following three conditions:

(1) x ∈ A and x ∈ B (2) x ∈ A and x /∈ B (3) x ∈ B and x /∈ A

1. In the first case, x ∈ A ∩ B, and so x ∈ (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B) by definition of union.

2. In the second case, x /∈ A ∩ B (because x /∈ B), and so x ∈ A − (A ∩ B). Therefore x ∈ (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B) by definition of union.

3. In the third case, x /∈ A ∩ B (because x /∈ A), and hence x ∈ B − (A ∩ B). So, again, x ∈ (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B) by definition of union.

Hence, in all three cases, x ∈ (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B), which com- pletes the proof of part 1.

Moreover, since the three conditions are mutually exclusive, the three sets A − (A ∩ B), B − (A ∩ B), and A ∩ B are mutually disjoint. Part 2: Show that (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B) ⊆ A ∪ B: : Suppose x is any element in (A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B). By definition of union, x ∈ A − (A ∩ B) or x ∈ B − (A ∩ B) or x ∈ A ∩ B. 1. In case x ∈ A − (A ∩ B), then x ∈ A and x /∈ A ∩ B by definition of set difference.

In particular, x ∈ A and so x ∈ A ∪ B. 2. In case x ∈ B − (A ∩ B), then x ∈ B and x /∈ A ∩ B by definition of set difference.

In particular, x ∈ B and so x ∈ A ∪ B. 3. In case x ∈ A ∩ B, then in particular, x ∈ A and so x ∈ A ∪ B. Hence, in all three cases, x ∈ A ∪ B, which completes the proof of part 2. b. P(A ∪ B) = P((A − (A ∩ B)) ∪ (B − (A ∩ B)) ∪ (A ∩ B)) by part (a)

= P(A − (A ∩ B)) + P(B − (A ∩ B)) + P(A ∩ B) by exercise 13 at the end of the section and the fact that A − (A ∩ B), B − (A ∩ B), and A ∩ B are mutually disjoint

= P(A)− P(A ∩ B) + P(B)− P(A ∩ B) + P(A ∩ B) by exercise 12 at the end of the section because A ∩ B ⊆ A and A ∩ B ⊆ B

= P(A) + P(B)− P(A ∩ B) by algebra. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

608 Chapter 9 Counting and Probability

Example 9.8.4 Computing the Probability of a General Union of Two Events

Suppose a card is chosen at random from an ordinary 52-card deck (see Section 9.1). What is the probability that the card is a face card (jack, queen, or king) or is from one of the red suits (hearts or diamonds)?

Solution Let A be the event that the chosen card is a face card, and let B be the event that the chosen card is from one of the red suits. The event that the card is a face card or is from one of the red suits is A ∪ B. Now N (A) = 4 ·3 = 12 (because each of the four suits has three face cards), and so P(A) = 12/52. Also N (B) = 26 (because half the cards are red), and so P(B) = 26/52. Finally, N (A ∩ B) = 6 (because there are three face cards in hearts and another three in diamonds), and so P(A ∩ B) = 6/52. It follows from the formula for the probability of a union of any two events that

P(A ∪ B) = P(A) + P(B)− P(A ∩ B) = 12 52

+ 26 52 − 6

52 = 32

52 ∼= 61.5%.

Thus the probability that the chosen card is a face card or is from one of the red suits is approximately 61.5%. ■

Expected Value People who buy lottery tickets regularly often justify the practice by saying that, even though they know that on average they will lose money, they are hoping for one significant gain, after which they believe they will quit playing. Unfortunately, when people who have lost money on a string of losing lottery tickets win some or all of it back, they generally decide to keep trying their luck instead of quitting.

The technical way to say that on average a person will lose money on the lottery is to say that the expected value of playing the lottery is negative.

• Definition Suppose the possible outcomes of an experiment, or random process, are real num- bers a1, a2, a3, . . . , an , which occur with probabilities p1, p2, p3, . . . , pn . The expected value of the process is

n∑

k=1 ak pk = a1 p1 + a2 p2 + a3 p3 + · · · + an pn.

Example 9.8.5 Expected Value of a Lottery

Suppose that 500,000 people pay $5 each to play a lottery game with the following prizes: a grand prize of $1,000,000, 10 second prizes of $1,000 each, 1,000 third prizes of $500 each, and 10,000 fourth prizes of $10 each. What is the expected value of a ticket?

Solution Each of the 500,000 lottery tickets has the same chance as any other of contain- ing a winning lottery number, and so pk = 1500000 for all k = 1, 2, 3, . . . , 500000. Let a1, a2, a3, . . . , a500000 be the net gain for an individual ticket, where a1 = 999995 (the net gain for the grand prize ticket, which is one million dollars minus the $5 cost of the winning ticket), a2 = a3 = · · · = a11 = 995 (the net gain for each of the 10 second prize tickets), a12 = a13 = · · · = a1011 = 495 (the net gain for each of the 1,000 third prize tickets), and a1012 = a1013 = · · · = a11011 = 5 (the net gain for each of the 10,000 fourth prize tickets). Since the remaining 488,989 tickets just lose $5, a11012 = a11013 = · · · = a500000 = −5.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.8 Probability Axioms and Expected Value 609

The expected value of a ticket is therefore

500000∑

k=1 ak pk =

500000∑

k=1

( ak ·

1 500000

) because each pk = 1/500000

= 1 500000

500000∑

k=1 ak by Theorem 5.1.1(2)

= 1 500000

(999995 + 10 ·995 + 1000 ·495 + 10000 ·5 + (−5) ·488989)

= 1 500000

(999995 + 9950 + 495000 + 50000− 2444945) = −1.78.

In other words, a person who continues to play this lottery for a very long time will probably win some money occasionally but on average will lose $1.78 per ticket. ■

Example 9.8.6 Gambler’s Ruin

A gambler repeatedly bets $1 that a coin will come up heads when tossed. Each time the coin comes up heads, the gambler wins $1; each time it comes up tails, he loses $1. The gambler will quit playing either when he is ruined (loses all his money) or when he has $M (where M is a positive number he has decided in advance). Let Pn be the probability that the gambler is ruined if he begins playing with $n. Then if the coin is fair (has an equal chance of coming up heads or tails),

Pk−1 = 1 2

Pk + 1 2

Pk−2 for each integer k with 2 ≤ k ≤ M.

(This follows from the fact that if the gambler has $(k − 1), then he has an equal chance of winning $1 or losing $1, and if he wins $1, then his chance of being ruined is Pk , whereas if he loses $1, then his chance of being ruined is Pk−2.) Also P0 = 1 (because if he has $0, he is certain of being ruined) and PM = 0 (because once he has $M , he quits and so stands no chance of being ruined). Find an explicit formula for Pn . How should the gambler choose M to minimize his chance of being ruined?

Solution Multiplying both sides of Pk−1 = 12 Pk + 12 Pk−2 by 2 and subtracting Pk−2 from both sides gives

Pk = 2Pk−1 − Pk−2. This is a second-order homogeneous recurrence relation with constant coefficients. Because Pk − 2Pk−1 + Pk−2 = 0 its characteristic equation is

t2 − 2t + 1 = 0, which has the single root r = 1. Thus, by the single-root theorem from Section 5.8,

Pn = Crn + Dnrn = C + Dn (since r = 1), where C and D are determined by two values of the sequence. But P0 = 1 and PM = 0. Hence

1 = P0 = C + D ·0 = C, 0 = PM = C + DM = 1 + DM.

It follows that C = 1 and D = − 1M , and so

Pn = 1− 1 M

n = M − n M

for each integer n with 0 ≤ n ≤ M.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

610 Chapter 9 Counting and Probability

For instance, a gambler who starts with $20 and decides to quit either if his total grows to $100 or if he goes broke has the following chance of going broke:

P20 = 100− 20

100 = 80

100 = 80%.

Observe that the larger M is relative to n, the closer Pn is to 1. In other words, the larger the amount of money the gambler sets himself as a target, the more likely he is to go broke. Conversely, the more modest he is in his goal, the more likely he is to reach it. ■

Test Yourself 1. If A is an event in a sample space S, P(A) can take values

between _____ and _____. Moreover, P(S) = _____, and P(∅) = _____.

2. If A and B are disjoint events in a sample space S, P(A ∪ B) = _____.

3. If A is an event in a sample space S, P(Aa) = _____.

4. If A and B are any events in a sample space S, P(A ∪ B) = _____.

5. If the possible outcomes of a random process or experiment are real numbers a1, a2, . . . , an , which occur with prob- abilities p1, p2, . . . , pn , then the expected value of the process is _____.

Exercise Set 9.8 1. In any sample space S, what is P(∅)? 2. Suppose A, B, and C are mutually exclusive events in a

sample space S, A ∪ B ∪ C = S, and A and B have proba- bilities 0.3 and 0.5, respectively. a. What is P(A ∪ B)? b. What is P(C)?

3. Suppose A and B are mutually exclusive events in a sam- ple space S, C is another event in S, A ∪ B ∪ C = S, and A and B have probabilities 0.4 and 0.2, respectively. a. What is P(A ∪ B)? b. Is it possible that P(C) = 0.2? Explain.

4. Suppose A and B are events in a sample space S with probabilities 0.8 and 0.7, respectively. Suppose also that P(A ∩ B) = 0.6. What is P(A ∪ B)?

5. Suppose A and B are events in a sample space S and sup- pose that P(A) = 0.6, P(Bc) = 0.4, and P(A ∩ B) = 0.2. What is P(A ∪ B)?

6. Suppose U and V are events in a sample space S and sup- pose that P(U c) = 0.3, P(V ) = 0.6, and P(U c ∪ V c) = 0.4. What is P(U ∪ V )?

7. Suppose a sample space S consists of three outcomes: 0, 1, and 2. Let A = {0}, B = {1}, and C = {2}, and suppose P(A) = 0.4, and P(B) = 0.3. Find each of the following: a. P(A ∪ B) b. P(C) c. P(A ∪ C) d. P(Ac) e. P(Ac ∩ Bc) f. P(Ac ∪ Bc)

8. Redo exercise 7 assuming that P(A) = 0.5 and P(B) = 0.4.

9. Let A and B be events in a sample space S, and let C = S − (A ∪ B). Suppose P(A) = 0.4, P(B) = 0.5, and P(A ∩ B) = 0.2. Find each of the following:

a. P(A ∪ B) b. P(C) c. P(Ac) d. P(Ac ∩ Bc) e. P(Ac ∪ Bc) f. P(Bc ∩ C)

10. Redo exercise 9 assuming that P(A) = 0.7, P(B) = 0.3, and P(A ∩ B) = 0.1.

11.H Prove that if S is any sample space and U and V are events in S with U ⊆ V , then P(U ) ≤ P(V ).

12.H Prove that if S is any sample space and U and V are any events in S, then P(V −U ) = P(V )− P(U ∩ V ).

13.H Use the axioms for probability and mathematical induction to prove that for all integers n ≥ 2, if A1, A2, A3, . . . , An are any mutually disjoint events in a sample space S, then

P(A1 ∪ A2 ∪ A3 ∪ · · · ∪ An) = n∑

k=1 P(Ak).

14. A lottery game offers $2 million to the grand prize winner, $20 to each of 10,000 second prize winners, and $4 to each of 50,000 third prize winners. The cost of the lottery is $2 per ticket. Suppose that 1.5 million tickets are sold. What is the expected gain or loss of a ticket?

15. A company sends millions of people an entry form for a sweepstakes accompanied by an order form for magazine subscriptions. The first, second, and third prizes are $10,000,000, $1,000,000, and $50,000, respectively. In order to qualify for a prize, a person is not required to order any magazines but has to spend 60 cents to mail back the entry form. If 30 million people qualify by sending back their entry forms, what is a person’s expected gain or loss?

16. An urn contains four balls numbered 2, 2, 5, and 6. If a per- son selects a set of two balls at random, what is the expected value of the sum of the numbers on the balls?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 611

17. An urn contains five balls numbered 1, 2, 2, 8, and 8. If a person selects a set of two balls at random, what is the expected value of the sum of the numbers on the balls?

18. An urn contains five balls numbered 1, 2, 2, 8, and 8. If a person selects a set of three balls at random, what is the expected value of the sum of the numbers on the balls?

19. When a pair of balanced dice are rolled and the sum of the numbers showing face up is computed, the result can be any number from 2 to 12, inclusive. What is the expected value of the sum?

20.H Suppose a person offers to play a game with you. In this game, when you draw a card from a standard 52-card deck, if the card is a face card you win $3, and if the card is any- thing else you lose $1. If you agree to play the game, what is your expected gain or loss?

21. A person pays $1 to play the following game: The person tosses a fair coin four times. If no heads occur, the person pays an additional $2, if one head occurs, the person pays

an additional $1, if two heads occur, the person just loses the initial dollar, if three heads occur, the person wins $3, and if four heads occur, the person wins $4. What is the person’s expected gain or loss?

22.H A fair coin is tossed until either a head comes up or four tails are obtained. What is the expected number of tosses?

23.H A gambler repeatedly bets that a die will come up 6 when rolled. Each time the die comes up 6, the gambler wins $1; each time it does not, the gambler loses $1. He will quit playing either when he is ruined or when he wins $300. If Pn is the probability that the gambler is ruined when he begins play with $n, then Pk−1 = 16 Pk + 56 Pk−2 for all integers k with 2 ≤ k ≤ 300. Also P0 = 1 and P300 = 0. Find an explicit formula for Pn and use it to calculate P20. (Exercise 33 in Section 9.9 asks you to derive the recurrence relation.)

Answers for Test Yourself 1. 0; 1; 1; 0 2. P(A) + P(B) 3. 1− P(A) 4. P(A) + P(B)− P(A ∩ B) 5. a1 p1 + a2 p2 + · · · + an pn

9.9 Conditional Probability, Bayes’ Formula, and Independent Events It is remarkable that a science which began with the consideration of games of chance should have become the most important object of human knowledge.. . . The most important questions of life are, for the most part, really only problems of probability. — Pierre-Simon Laplace 1749–1827

In this section we introduce the notion of conditional probability and discuss Bayes’ Theorem and the kind of interesting results to which it leads. We then define the concept of independent events and give some applications.

Conditional Probability Imagine a couple with two children, each of whom is equally likely to be a boy or a girl. Now suppose you are given the information that one is a boy. What is the probability that the other child is a boy?

Figure 9.9.1 shows the four equally likely combinations of gender for the children. You can imagine that the first letter refers to the older child and the second letter to the

BB BG GB GG

Figure 9.9.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

612 Chapter 9 Counting and Probability

younger. Thus the combination BG indicates that the older child is a boy and the younger is a girl.

The combinations where one of the children is a boy are shaded gray, and the combi- nation where the other child is also a boy is shaded blue-gray. Given that you know one child is a boy, only the three combinations in the gray region could be the case, so you can think of the set of those outcomes as a new sample space with three elements, all of which are equally likely. Within the new sample space, there is one combination where the other child is a boy (in the region shaded blue-gray). Thus it would be reasonable to say that the likelihood that the other child is a boy, given that at least one is a boy, is 1/3 = 33 13 %. Note that because the original sample space contained four outcomes,

P(at least one child is a boy and the other child is also a boy) P(at least one child is a boy)

= 1 4 3 4

= 1 3

also. A generalization of this observation forms the basis for the following definition.

• Definition Let A and B be events in a sample space S. If P(A) ̸= 0, then the conditional probability of B given A, denoted P(B | A), is

P(B | A) = P(A ∩ B) P(A)

. 9.9.1

Example 9.9.1 Computing a Conditional Probability

A pair of fair dice, one blue and the other gray, are rolled. What is the probability that the sum of the numbers showing face up is 8, given that both of the numbers are even?

Solution The sample space is the set of all 36 outcomes obtained from rolling the two dice and noting the numbers showing face up on each. As in Section 9.1, denote by ab the outcome that the number showing face up on the blue die is a and the one on the gray die is b. Let A be the event that both numbers are even and B the event that the sum of the numbers is 8. Then A = {22, 24, 26, 42, 44, 46, 62, 64, 66}, B = {26, 35, 44, 53, 62}, and A ∩ B = {26, 44, 62}. Because the dice are fair (so all outcomes are equally likely), P(A) = 9/36, P(B) = 5/36 and P(A ∩ B) = 3/36. By definition of conditional probability,

P(B | A) = P(A ∩ B) P(A)

= 3 36 9 36

= 3 9

= 1 3 . ■

Note that when both sides of the formula for conditional probability (formula 9.9.1) are multiplied by P(A), a formula for P(A ∩ B) is obtained:

P(A ∩ B) = P(B | A) · P(A). 9.9.2

Dividing both sides of formula (9.9.2) by P(B | A) gives a formula for P(A):

P(A) = P(A ∩ B) P(B | A) . 9.9.3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 613

Example 9.9.2 Representing Conditional Probabilities with a Tree Diagram

An urn contains 5 blue and 7 gray balls. Let us say that 2 are chosen at random, one after the other, without replacement.

a. Find the following probabilities and illustrate them with a tree diagram: the probability that both balls are blue, the probability that the first ball is blue and the second is not blue, the probability that the first ball is not blue and the second ball is blue, and the probability that neither ball is blue.

b. What is the probability that the second ball is blue?

c. What is the probability that at least one of the balls is blue?

d. If the experiment of choosing two balls from the urn were repeated many times over, what would be the expected value of the number of blue balls?

Solution Let S denote the sample space of all possible choices of two balls from the urn, let B1 be the event that the first ball is blue, and let B2 be the event that the second ball is blue. Then Bc1 is the event that the first ball is not blue and B

c 2 is the event that the second

ball is not blue.

a. Because there are 12 balls of which 5 are blue and 7 are gray, the probability that the first ball is blue is

P(B1) = 5 12

and the probability that the first ball is not blue is

P(B c1 ) = 7 12

.

If the first ball is blue, then the urn would contain 4 blue balls and 7 gray balls, and so

P(B2 | B1) = 1 11

and P(B c2 | B1) = 7 11

,

where P(B2 | B1) is the probability that the second ball is blue given that the first ball is blue and P(B c2 | B1) is the probability that the second ball is not blue given that the first ball is blue. It follows from formula (9.9.2) that

P(B1 ∩ B2) = P(B2 | B1) · P(B1) = 4 11

· 5 12

= 20 132

and

P(B1 ∩ B c2 ) = P(B c2 | B1) · P(B1) = 7 11

· 5 12

= 35 132

.

Similarly, if the first ball is not blue, then the urn would contain 5 blue balls and 6 gray balls, and so

P(B2 | B c1 ) = 5 11

and P(B c2 | B c1 ) = 6 11

,

where P(B2 | B c1 ) is the probability that the second ball is blue given that the first ball is not blue and P(B c2 | B c1 ) is the probability that the second ball is not blue given that the first ball is not blue. It follows from formula (9.9.2) that

P(B c1 ∩ B2) = P(B2 | B c1 ) · P(B c1 ) = 5 11

· 7 12

= 35 132

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

614 Chapter 9 Counting and Probability

and

P(B c1 ∩ B c2 ) = P(B c2 | B c1 ) · P(B c1 ) = 6 11

· 7 12

= 42 132

.

The tree diagram in Figure 9.9.2 is a convenient way to help calculate these results.

P(B1) = —

5 12

P(B2 B1) =

— 4 11

4 11

5 12

20 132

P(B1 B c) = — · — = —–

P(B1 B2) = — · — = —–

7 11

5 12

35 132

B1 B2

B1

B1 B c

P(B c B c) = — · — = —–6 11

7 12

42 132

7 12

P(B c ) = —1

B c 1

6 11

P(B c B c ) = —2 1

2

5 11P(B

B c ) = —1

7 11

P(B c B ) = —2 1

B c B21

2

P(B2 B c) = — · — = —–5

11 7

12 35 1322

12 B c B c21

Figure 9.9.2

b. The event that the second ball is blue can occur in one of two mutually exclusive ways: Either the first ball is blue and the second is also blue, or the first ball is gray and the second is blue. In other words, B2 is the disjoint union of B2 ∩ B1 and B2 ∩ B c1 . Hence

P(B2) = P ( (B2 ∩ B1) ∪

( B2 ∩ B c1

))

= P(B2 ∩ B1) + P ( B2 ∩ B c1

) by probability axiom 3

= 20 132

+ 35 132

by part (a)

= 55 132

= 5 12

.

Thus the probability that the second ball is blue is 5/12, the same as the probability that the first ball is blue.

c. By formula 9.8.2, for the union of any two events,

P(B1 ∪ B2) = P(B1) + P(B2)− P(B1 ∩ B2)

= 5 12

+ 5 12 − 20

132 by parts (a) and (b)

= 90 132

= 15 22

.

Thus the probability is 15/22, or approximately 68.2%, that at least one of the balls is blue.

d. The event that neither ball is blue is the complement of the event that at least one of the balls is blue, so

P(0 blue balls) = 1− P (at least one ball is blue) by formula 9.8.1

= 1− 15 22

by part (c)

= 7 22

.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 615

The event that one ball is blue can occur in one of two mutually exclusive ways: Either the second ball is blue and the first is not, or the first ball is blue and the second is not. Part (a) showed that the probability of the first way is 35132 , and the probability of the second way is also 35132 . Thus, by probability axiom 3,

P(1 blue ball) = 35 132

+ 35 132

= 70 132

.

Finally, by part (a),

P(2 blue balls) = 20 132

.

Therefore, [

the expected value of the number of blue balls

] = 0 · P(0 blue balls) + 1 · P(1 blue ball)

+ 2 · P(2 blue balls)

= 0 · 7 22

+ 1 · 70 132

+ 2 · 20 132

= 110 132

∼= 0.8. ■

Bayes’ Theorem Suppose that one urn contains 3 blue and 4 gray balls and a second urn contains 5 blue and 3 gray balls. A ball is selected by choosing one of the urns at random and then picking a ball at random from that urn. If the chosen ball is blue, what is the probability that it came from the first urn?

This problem can be solved by carefully interpreting all the information that is known and putting it together in just the right way. Let A be the event that the chosen ball is blue, B1 the event that the ball came from the first urn, and B2 the event that the ball came from the second urn. Because 3 of the 7 balls in urn one are blue, and 5 of the 8 balls in urn two are blue,

P(A | B1) = 3 7

and P(A | B2) = 5 8 .

And because the urns are equally likely to be chosen,

P(B1) = P(B2) = 1 2 .

Moreover, by formula (9.9.2),

P(A ∩ B1) = P(A | B1) · P(B1) = 3 7

· 1 2

= 3 14

, and

P(A ∩ B2) = P(A | B2) · P(B2) = 5 8

· 1 2

= 5 16

.

But A is the disjoint union of (A ∩ B1) and (A ∩ B2), so by probability axiom 3,

P(A) = P((A ∩ B1) ∪ (A ∩ B2)) = P(A ∩ B1) + P(A ∩ B2) = 3 14

+ 5 16

= 59 112

.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

616 Chapter 9 Counting and Probability

Finally, by definition of conditional probability,

P(B1 | A) = P(B1 ∩ A)

P(A) =

3 14 59 112

= 336 826

∼= 40.7%.

Thus, if the chosen ball is blue, the probability is approximately 40.7% that it came from the first urn.

Co ur

te sy

St ep

he n

St ig

le r

Thomas Bayes (1702–1761)

The steps used to derive the answer in the previous example can be generalized to prove Bayes’ Theorem. (See exercises 9.9 and 9.10 at the end of this section.) Thomas Bayes was an English Presbyterian minister who devoted much of his energies to math- ematics. The theorem that bears his name was published posthumously in 1763. The portrait at the left is the only one attributed to him, but its authenticity has recently come into question.

Theorem 9.9.1 Bayes’ Theorem

Suppose that a sample space S is a union of mutually disjoint events B1, B2, B3, . . . , Bn , suppose A is an event in S, and suppose A and all the B1 have nonzero probabil- ities. If k is an integer with 1 ≤ k ≤ n, then

P(Bk | A) = P(A | Bk)P(Bk)

P(A | B1)P(B1) + P(A | B2)P(B2) + · · · + P(A | Bn)P(Bn)

Example 9.9.3 Applying Bayes’ Theorem

Most medical tests occasionally produce incorrect results, called false positives and false negatives. When a test is designed to determine whether a patient has a certain disease, a false positive result indicates that a patient has the disease when the patient does not have it. A false negative result indicates that a patient does not have the disease when the patient does have it.

When large-scale health screenings are performed for diseases with relatively low incidence, those who develop the screening procedures have to balance several consid- erations: the per-person cost of the screening, follow-up costs for further testing of false positives, and the possibility that people who have the disease will develop unwarranted confidence in the state of their health.

Consider a medical test that screens for a disease found in 5 people in 1,000. Suppose that the false positive rate is 3% and the false negative rate is 1%. Then 99% of the time a person who has the condition tests positive for it, and 97% of the time a person who does not have the condition tests negative for it. (See exercise 4 at the end of this section.)

a. What is the probability that a randomly chosen person who tests positive for the dis- ease actually has the disease?

b. What is the probability that a randomly chosen person who tests negative for the dis- ease does not indeed have the disease?

Solution Consider a person chosen at random from among those screened. Let A be the event that the person tests positive for the disease, B1 the event that the person actually has the disease, and B2 the event that the person does not have the disease. Then

P(A | B1) = 0.99, P(Ac | B1) = 0.01, P(Ac | B2) = 0.97, and P(A | B2) = 0.03. Also, because 5 people in 1,000 have the disease,

P(B1) = 0.005 and P(B2) = 0.995.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 617

a. By Bayes’ Theorem,

P(B1 | A) = P(A | B1)P(B1)

P(A | B1)P(B1) + P(A | B2)P(B2)

= (0.99)(0.005) (0.99)(0.005) + (0.03)(0.995)

∼= 0.1422 ∼= 14.2%. Thus the probability that a person with a positive test result actually has the disease is approximately 14.2%.

b. By Bayes’ Theorem,

P(B2 | Ac) = P(Ac | B2)P(B2)

P(Ac | B1)P(B1) + P(Ac | B2)P(B2)

= (0.97)(0.995) (0.01)(0.005) + (0.97)(0.995)

∼= 0.999948 ∼= 99.995%.

Thus the probability that a person with a negative test result does not have the disease is approximately 99.995%.

You might be surprised by these numbers, but they are fairly typical of the situation where the screening test is significantly less expensive than a more accurate test for the same disease yet produces positive results for nearly all people with the disease. Using the screening test limits the expense of unnecessarily using the more costly test to a relatively small percentage of the population being screened, while only rarely indicating that a person who has the disease is free of it. ■

Independent Events Suppose a coin is tossed twice. It seems intuitively clear that the outcome of the first toss does not depend in any way on the outcome of the second toss, and conversely. In other words, if, for instance, A is the event that a head is obtained on the first toss and B is the event that a head is obtained on the second toss, then if the coin is tossed randomly both times, events A and B should be independent in the sense that P(A | B) = P(A) and P(B | A) = P(B). This intuitive idea of independence is supported by the following analysis. If the coin is fair, then the four outcomes H H, H T, T H , and T T are equally likely, and

A = {H H, H T }, B = {T H, H H}, A ∩ B = {H H}. Hence

P(A) = P(B) = 2 4

= 1 2 .

But also

P(A | B) = P(A ∩ B) P(B)

= 1 4 1 2

= 1 2

and P(B | A) = P(A ∩ B) P(A)

= 1 4 1 2

= 1 2 ,

and thus P(A | B) = P(A) and P(B | A) = P(B). To obtain the final form for definition of independence, observe that

if P(B) ̸= 0 and P(A | B) = P(A), then P(A ∩ B) = P(A | B) · P(B) = P(A) · P(B).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

618 Chapter 9 Counting and Probability

By the same argument,

if P(A) ̸= 0 and P(B | A) = P(B), then P(A ∩ B) = P(A) · P(B). Conversely (see exercise 18 at the end of this section),

if P(A ∩ B) = P(A) · P(B) and P(A) ̸= 0, then P(B | A) = P(B), and

if P(A ∩ B) = P(A) · P(B) and P(B) ̸= 0, then P(A | B) = P(A). Thus, for convenience and to eliminate the requirement that the probabilities be nonzero, we use the following product formula to define independent events.

Note It would be natural to think that mutually disjoint events would be independent, but in fact almost the opposite is true: Mutually disjoint events with nonzero probabilities are dependent.

• Definition If A and B are events in a sample space S, then A and B are independent if, and only if,

P(A ∩ B) = P(A) · P(B).

Example 9.9.4 Disjoint Events and Independence

Let A and B be events in a sample space S, and suppose A ∩ B = ∅, P(A) ̸= 0, and P(B) ̸= 0. Show that P(A ∩ B) ̸= P(A) · P(B).

Solution Because A ∩ B = ∅, P(A ∩ B) = 0 by probability axiom 2. But P(A) · P(B) ̸= 0 because neither P(A) nor P(B) equals zero. Thus P(A ∩ B) ̸= P(A) · P(B). ■

The following example, and its immediate consequence, show how the independence of two events extends to their complements.

Example 9.9.5 The Probability of A ∩ Bc When A and B Are Independent Events Suppose A and B are independent events in a sample space S. Show that A and Bc are also independent.

Solution The solution for exercises 8 and 25 in Section 6.2 show that for all sets A and B,

(1) (A ∩ B) ∪ (A ∩ Bc) = A and (2) (A ∩ B) ∩ (A ∩ Bc) = ∅ It follows that probability axiom 3 may be applied to equation (1) to obtain

P((A ∩ B) ∪ (A ∩ Bc)) = P(A ∩ B) + P(A ∩ Bc) = P(A). Solving for P(A ∩ Bc) gives that

P(A ∩ Bc) = P(A)− P(A ∩ B) = P(A)− P(A) · P(B) because A and B are independent = P(A)(1− P(B)) by factoring out P(A) = P(A) · P(Bc) by formula 9.8.1.

Thus A and Bc are independent events. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 619

It follows immediately from Example 9.9.5 that if A and B are independent, then Ac and B are also independent and so are Ac and Bc. (See exercise 22 at the end of this section.) These results are applied in Example 9.9.6.

Example 9.9.6 Computing Probabilities of Intersections of Two Independent Events

A coin is loaded so that the probability of heads is 0.6. Suppose the coin is tossed twice. Although the probability of heads is greater than the probability of tails, there is no reason to believe that whether the coin lands heads or tails on one toss will affect whether it lands heads or tails on the other toss. Thus it is reasonable to assume that the results of the tosses are independent.

a. What is the probability of obtaining two heads?

b. What is the probability of obtaining one head?

c. What is the probability of obtaining no heads?

d. What is the probability of obtaining at least one head?

Solution The sample space S consists of the four outcomes {H H, H T, T H, T T }, which are not equally likely. Let E be the event that a head is obtained on the first toss, and let F be the event that a head is obtained on the second toss. Then P(E) = P(F) = 0.6, and it is to be assumed that E and F are independent.

a. The probability of obtaining two heads is P(E ∩ F). Because E and F are independent,

P (two heads) = P(E ∩ F) = P(E) · P(F) = (0.6)(0.6) = 0.36 = 36%. b. One head can be obtained in two mutually exclusive ways: head on the first toss and

tail on the second, or tail on the first toss and head on the second. Thus, the event of obtaining exactly one head is (E ∩ Fc) ∪ (Ec ∩ F). Also (E ∩ Fc) ∩ (Ec ∩ F) = ∅, and, moreover, by the formula for the probability of the complement of an event, P(Ec) = P(Fc) = 1− 0.6 = 0.4. Hence

P(one head) = P((E ∩ Fc) ∪ (Ec ∩ F)) = P(E) · P(Fc) + P(Ec) · P(F) by Example 9.9.5 and exercise 22 = (0.6)(0.4) + (0.4)(0.6) = 0.48 = 48%.

c. The probability of obtaining no heads is P(Ec ∩ Fc). By exercise 22, P(no heads) = P(Ec ∩ Fc) = P(Ec) · P(Fc) = (0.4)(0.4) = 0.16 = 16%.

d. There are two ways to solve this problem. One is to observe that because the event of obtaining one head and the event of obtaining two heads are mutually disjoint,

P(at least one head) = P(one head) + P(two heads) = 0.48 + 0.36 by parts (a) and (b) = 0.84 = 84%.

The second way is to use the fact that the event of obtaining at least one head is the complement of the event of obtaining no heads. So

P(at least one head) = 1− P(no heads) = 1− 0.16 by part (c) = 0.84 = 84%. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

620 Chapter 9 Counting and Probability

Example 9.9.7 Expected Value of Tossing a Loaded Coin Twice

Suppose that a coin is loaded so that the probability of heads is 0.6, and suppose the coin is tossed twice. If this experiment is repeated many times, what is the expected value of the number of heads?

Solution Think of the outcomes of the coin tossings as just 0, 1, or 2 heads. Example 9.9.6 showed that the probabilities of these outcomes are 0.16, 0.48, and 0.36, respectively. Thus, by definition of expected value, the

expected number of heads = 0 ·(0.16) + 1 ·(0.48) + 2 ·(0.36) = 1.2. ■

What if a loaded coin is tossed more than twice? Suppose it is tossed ten times, or a hundred times. What are the probabilities of various numbers of heads? To answer this question, it is necessary to expand the notion of independence to more than two events. For instance, we say three events A, B, and C are pairwise independent if, and only if,

P(A ∩ B) = P(A) · P(B), P(A ∩ C) = P(A) · P(C), and P(B ∩ C) = P(B) · P(C). The next example shows that events can be pairwise independent without satisfying the condition P(A ∩ B ∩ C) = P(A) · P(B) · P(C). Conversely, they can satisfy the condi- tion P(A ∩ B ∩ C) = P(A) · P(B) · P(C) without being pairwise independent (see exer- cise 26 at the end of this section).

Example 9.9.8 Exploring Independence for Three Events

Suppose that a fair coin is tossed twice. Let A be the event that a head is obtained on the first toss, B the event that a head is obtained on the second toss, and C the event that either two heads or two tails are obtained. Show that A, B, and C are pairwise independent but do not satisfy the condition P(A ∩ B ∩ C) = P(A) · P(B) · P(C).

Solution Because there are four equally likely outcomes—H H, H T, T H , and T T —it is clear that P(A) = P(B) = P(C) = 12 . You can also see that A ∩ B = {H H}, A ∩ C = {H H}, B ∩ C = {H H}, and A ∩ B ∩ C = {H H}. Hence P(A ∩ B) = P(A ∩ C) = P(B ∩ C) = 14 , and so P(A ∩ B) = P(A) · P(B), P(A ∩ C) = P(A) · P(C), and P(B ∩ C) = P(B) · P(C). Thus A, B, and C are pairwise indepen- dent. But

P(A ∩ B ∩ C) = P({H H}) = 1 4 ̸= (

1 2

)3 = P(A) · P(B) · P(C). ■

Because of situations like that in Example 9.9.8, four conditions must be included in the definition of independence for three events.

• Definition Let A, B, and C be events in a sample space S. A, B, and C are pairwise indepen- dent if, and only if, they satisfy conditions 1–3 below. They are mutually independent if, and only if, they satisfy all four conditions below.

1. P(A ∩ B) = P(A) · P(B) 2. P(A ∩ C) = P(A) · P(C) 3. P(B ∩ C) = P(B) · P(C) 4. P(A ∩ B ∩ C) = P(A) · P(B) · P(C)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 621

The definition of mutual independence for any collection of n events with n ≥ 2 generalizes the two definitions given previously.

• Definition Events A1, A2, A3, . . . , An in a sample space S are mutually independent if, and only if, the probability of the intersection of any subset of the events is the product of the probabilities of the events in the subset.

Example 9.9.9 Tossing a Loaded Coin Ten Times

A coin is loaded so that the probability of heads is 0.6 (and thus the probability of tails is 0.4). Suppose the coin is tossed ten times. As in Example 9.9.6, it is reasonable to assume that the results of the tosses are mutually independent.

a. What is the probability of obtaining eight heads?

b. What is the probability of obtaining at least eight heads?

Solution

a. For each i = 1, 2, . . . , 10, let Hi be the event that a head is obtained on the i th toss, and let Ti be the event that a tail is obtained on the i th toss. Suppose that the eight heads occur on the first eight tosses and that the remaining two tosses are tails. This is the event H1 ∩ H2 ∩ H3 ∩ H4 ∩ H5 ∩ H6 ∩ H7 ∩ H8 ∩ T9 ∩ T10. For simplicity, we denote it as H H H H H H H H T T . By definition of mutually independent events,

P(H H H H H H H H T T ) = (0.6)8(0.4)2. Because of the commutative law for multiplication, if the eight heads occur on any other of the ten tosses, the same number is obtained. For instance, if we denote the event H1 ∩ H2 ∩ T3 ∩ H4 ∩ H5 ∩ H6 ∩ H7 ∩ H8 ∩ T9 ∩ H10 by H H T H H H H H T H , then

P(H H T H H H H H T H) = (0.6)2(0.4)(0.6)5(0.4)(0.6) = (0.6)8(0.4)2. Now there are as many different ways to obtain eight heads in ten tosses as there are subsets of eight elements (the toss numbers on which heads are obtained) that can be chosen from a set of ten elements. This number is

(10 8

) . It follows that, because the

different ways of obtaining eight heads are all mutually exclusive,

P(eight heads) = (

10 8

) (0.6)8(0.4)2.

b. By reasoning similar to that in part (a),

P(nine heads) =

⎣ the number of different ways nine heads can be obtained in ten tosses

⎦ ·(0.6)9(0.4)1 = (

10 9

) (0.6)9(0.4),

and

P(ten heads) =

⎣ the number of different ways ten heads can be obtained in ten tosses

⎦ ·(0.6)10(0.4)0 = (

10 10

) (0.6)10.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

622 Chapter 9 Counting and Probability

Because obtaining eight, obtaining nine, and obtaining ten heads are mutually disjoint events,

P(at least eight heads) = P(eight heads) + P(nine heads) + P(ten heads)

= (

10 8

) (0.6)8(0.4)2 +

( 10 9

) (0.6)9(0.4) +

( 10 10

) (0.6)10

∼= 0.167 = 16.7%. ■

Note the occurrence of the binomial coefficients (n

k

) in solutions to problems like the

one in Example 9.9.9. For that reason, probabilities of the form (

n k

) pn−k(1− p)k,

where 0 ≤ p ≤ 1, are called binomial probabilities.

Note Binomial probabilities occur in situations with multiple, mutually independent repetitions of a random process, all of which have the same two possible outcomes with the same probabilities on each repetition.

Test Yourself 1. If A and B are any events in a sample space S and

P(A) ̸= 0, then the conditional probability of B given A is P(B | A) = _____.

2. Bayes’ theorem says that if a sample space S is a union of mutually disjoint events B1, B2, . . . , Bn with nonzero prob- abilities, if A is an event in S with P(A) ̸= 0, and if k is an integer with 1 ≤ k ≤ n, then _____.

3. Events A and B in a sample space S are independent if, and only if, _____.

4. Events A, B, and C in a sample space S are mutually inde- pendent if, and only if, _____, _____, _____, and _____.

Exercise Set 9.9 1. Suppose P(A | B) = 1/2 and P(A ∩ B) = 1/6. What is

P(B)?

2. Suppose P(X | Y ) = 1/3 and P(Y ) = 1/4. What is P(X ∩ Y )?

3.H The instructor of a discrete mathematics class gave two tests. Twenty-five percent of the students received an A on the first test and 15% of the students received A’s on both tests. What percent of the students who received A’s on the first test also received A’s on the second test?

4. a. Prove that if A and B are any events in a sample space S, with P(B) ̸= 0, then P(Ac | B) = 1− P(A | B).

b. Explain how this result justifies the following state- ments: (1) If the probability of a false positive on a test for a condition is 4%, then there is a 96% probability that a person who does not have the condition will have a negative test result. (2) If the probability of a false neg- ative on a test for a condition is 1%, then there is a 99% probability that a person who does have the condition will test positive for it.

5.H Suppose that A and B are events in a sample space S and that P(A), P(B), and P(A | B) are known. Derive a for- mula for P(A | Bc).

6. An urn contains 25 red balls and 15 blue balls. Two are chosen at random, one after the other, without replacement.

a. Use a tree diagram to help calculate the following prob- abilities: the probability that both balls are red, the prob- ability that the first ball is red and the second is not, the probability that the first ball is not red and the second is red, the probability that neither ball is red.

b. What is the probability that the second ball is red? c. What is the probability that at least one of the balls is

red?

7. Redo exercise 6 assuming that the urn contains 30 red balls and 40 blue balls.

8. A pool of 10 semifinalists for a job consists of 7 men and 3 women. Because all are considered equally qualified, the names of two of the semifinalists are drawn, one after the other, at random, to become finalists for the job. a. What is the probability that both finalists are women? b. What is the probability that both finalists are men? c.H What is the probability that one finalist is a woman and

the other is a man?

9.H Prove Bayes’ Theorem for n = 2. That is, prove that if a sample space S is a union of mutually disjoint events B1 and B2, if A is an event in S with P(A) ̸= 0, and if k = 1 or k = 2, then

P(Bk | A) = P(A | Bk)P(Bk)

P(A | B1)P(B1) + P(A | B2)P(B2) .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

9.9 Conditional Probability, Bayes’ Formula, and Independent Events 623

10. Prove the full version of Bayes’ Theorem.

11. One urn contains 12 blue balls and 7 white balls, and a sec- ond urn contains 8 blue balls and 19 white balls. An urn is selected at random, and a ball is chosen from the urn. a. What is the probability that the chosen ball is blue? b. If the chosen ball is blue, what is the probability that it

came from the first urn?

12. Redo exercise 11 assuming that the first urn contains 4 blue balls and 16 white balls and the second urn contains 10 blue balls and 9 white balls.

13.H One urn contains 10 red balls and 25 green balls, and a sec- ond urn contains 22 red balls and 15 green balls. A ball is chosen as follows: First an urn is selected by tossing a loaded coin with probability 0.4 of landing heads up and probability 0.6 of landing tails up. If the coin lands heads up, the first urn is chosen; otherwise, the second urn is cho- sen. Then a ball is picked at random from the chosen urn. a. What is the probability that the chosen ball is green? b. If the chosen ball is green, what is the probability that it

was picked from the first urn?

14. A drug-screening test is used in a large population of peo- ple of whom 4% actually use drugs. Suppose that the false positive rate is 3% and the false negative rate is 2%. Thus a person who uses drugs tests positive for them 98% of the time, and a person who does not use drugs tests negative for them 987% of the time. a. What is the probability that a randomly chosen person

who tests positive for drugs actually uses drugs? b. What is the probability that a randomly chosen person

who tests negative for drugs does not use drugs?

15. Two different factories both produce a certain automobile part. The probability that a component from the first fac- tory is defective is 2%, and the probability that a compo- nent from the second factory is defective is 5%. In a supply of 180 of the parts, 100 were obtained from the first factory and 80 from the second factory. a. What is the probability that a part chosen at random from

the 180 is from the first factory? b. What is the probability that a part chosen at random from

the 180 is from the second factory? c. What is the probability that a part chosen at random from

the 180 is defective? d. If the chosen part is defective, what is the probability

that it came from the first factory?

16.H Three different suppliers—X, Y , and Z—provide produce for a grocery store. Twelve percent of produce from X is superior grade, 8% of produce from Y is superior grade and 15% of produce from Z is superior grade. The store obtains 20% of its produce from X , 45% from Y , and 35% from Z . a. If a piece of produce is purchased, what is the probabil-

ity that it is superior grade? b. If a piece of produce in the store is superior grade, what

is the probability that it is from X?

17. Prove that if A and B are events in a sample space S with the property that P(A | B) = P(A) and P(A) ̸= 0, then P(B | A) = P(B).

18. Prove that if P(A ∩ B) = P(A) · P(B), P(A) ̸= 0, and P(B) ̸= 0, then P(A | B) = P(A) and P(B | A) = P(B).

19. A pair of fair dice, one blue and the other gray, are rolled. Let A be the event that the number face up on the blue die is 2, and let B be the event that the number face up on the gray die is 4 or 5. Show that P(A | B) = P(A) and P(B | A) = P(B).

20. Suppose a fair coin is tossed three times. Let A be the event that a head appears on the first toss, and let B be the event that an even number of heads is obtained. Show that P(A | B) = P(A) and P(B | A) = P(B).

21. If A and B are events in a sample space S and A ∩ B = ∅, what must be true in order for A and B to be independent? Explain.

22. Prove that if A and B are independent events in a sample space S, then Ac and B are also independent, and so are Ac

and Bc.

23. A student taking a multiple-choice exam does not know the answers to two questions. All have five choices for the answer. For one of the two questions, the student can elim- inate two answer choices as incorrect but has no idea about the other answer choices. For the other question, the stu- dent has no clue about the correct answer at all. Assume that whether the student chooses the correct answer on one of the questions does not affect whether the student chooses the correct answer on the other question. a. What is the probability that the student will answer both

questions correctly? b. What is the probability that the student will answer

exactly one of the questions correctly? c. What is the probability that the student will answer nei-

ther question correctly?

24. A company uses two proofreaders X and Y to check a cer- tain manuscript. X misses 12% of typographical errors and Y misses 15%. Assume that the proofreaders work indepen- dently. a. What is the probability that a randomly chosen typo-

graphical error will be missed by both proofreaders? b. If the manuscript contains 1,000 typographical errors,

what number can be expected to be missed?

25. A coin is loaded so that the probability of heads is 0.7 and the probability of tails is 0.3. Suppose that the coin is tossed twice and that the results of the tosses are independent. a. What is the probability of obtaining exactly two heads? b. What is the probability of obtaining exactly one head? c. What is the probability of obtaining no heads? d. What is the probability of obtaining at least one head?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

624 Chapter 9 Counting and Probability

26.✶ Describe a sample space and events A, B, and C , where P(A ∩ B ∩ C) = P(A) · P(B) · P(C) but A, B, and C are not pairwise independent.

27.H The example used to introduce conditional probability described a family with two children each of whom was equally likely to be a boy or a girl. The example showed that if it is known that one child is a boy, the probability that the other child is a boy is 1/3. Now imagine the same kind of family—two children each of whom is equally likely to be a boy or a girl. Suppose you meet one of the children and see that it is a boy. What is the probability that the other child is a boy? Explain. (Be careful. The answer may surprise you.)

28. A coin is loaded so that the probability of heads is 0.7 and the probability of tails is 0.3. Suppose that the coin is tossed ten times and that the results of the tosses are mutually inde- pendent. a. What is the probability of obtaining exactly seven

heads? b. What is the probability of obtaining exactly ten heads? c. What is the probability of obtaining no heads? d. What is the probability of obtaining at least one head?

29. Suppose that ten items are chosen at random from a large batch delivered to a company. The manufacturer claims that just 3% of the items in the batch are defective. Assume that the batch is large enough so that even though the selection is made without replacement, the number 0.03 can be used to approximate the probability that any one of the ten items is defective. In addition, assume that because the items are chosen at random, the outcomes of the choices are mutually independent. Finally, assume that the manufacturer’s claim is correct. a. What is the probability that none of the ten is defective? b. What is the probability that at least one of the ten is

defective? c. What is the probability that exactly four of the ten are

defective? d. What is the probability that at most two of the ten are

defective?

30. Suppose the probability of a false positive result on a mammogram is 4% and that radiologists’ interpretations of mammograms are mutually independent in the sense that whether or not a radiologist finds a positive result on one mammogram does not influence whether or not the radiolo- gist finds a positive result on another mammogram. Assume that a woman has a mammogram every year for ten years. a. What is the probability that she will have no false posi-

tive results during that time?

b. What is the probability that she will have at least one false positive result during that time?

c. What is the probability that she will have exactly two false positive results during that time?

d. Suppose that the probability of a false negative result on a mammogram is 2%, and assume that the probabil- ity that a randomly chosen woman has breast cancer is 0.0002. (i) If a woman has a positive test result one year, what

is the probability that she actually has breast cancer? (ii) If a woman has a negative test result one year, what

is the probability that she actually has breast cancer?

31. Empirical data indicate that approximately 103 out of every 200 children born are male. Hence the probability of a new- born being male is about 51.5%. Suppose that a family has six children, and suppose that the genders of all the children are mutually independent. a.H What is the probability that none of the children is male? b. What is the probability that at least one of the children

is male? c. What is the probability that exactly five of the children

are male?

32. A person takes a multiple-choice exam in which each ques- tion has four possible answers. Suppose that the person has no idea about the answers to three of the questions and sim- ply chooses randomly for each one. a. What is the probability that the person will answer all

three questions correctly? b. What is the probability that the person will answer

exactly two questions correctly? c. What is the probability that the person will answer

exactly one question correctly? d. What is the probability that the person will answer no

questions correctly? e. Suppose that the person gets one point of credit for each

correct answer and that 1/3 point is deducted for each incorrect answer. What is the expected value of the per- son’s score for the three questions?

33. In exercise 23 of Section 9.8, let Ck be the event that the gambler has k dollars, wins the next roll of the die, and is eventually ruined, let Dk be the event that the gambler has k dollars, loses the next roll of the die, and is even- tually ruined, and let Pn be the probability that the gam- bler is eventually ruined. Use the probability axioms and the definition of conditional probability to derive the equa- tion Pk−1 = 16 Pk +

5 6 Pk−2.

Answers for Test Yourself

1. P(A ∩ B)

P(A) 2. P(Bk | A) =

P(A | Bk)P(Bk) P(A | B1)P(B1) + P(A | B2)P(B2) + · · · + P(A | Bn)P(Bn)

3. P(A ∩ B) = P(A) · P(B)

4. P(A ∩ B) = P(A) · P(B); P(A ∩ C) = P(A) · P(C); P(B ∩ C) = P(B) · P(C); P(A ∩ B ∩ C) = P(A) · P(B) · P(C)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

625

CHAPTER 10

GRAPHS AND TREES

Graphs and trees have appeared previously in this book as convenient visualizations. For instance, a possibility tree shows all possible outcomes of a multistep operation with a finite number of outcomes for each step, the directed graph of a relation on a set shows which elements of the set are related to which a Hasse diagram illustrates the relations among elements in a partially ordered set, and a PERT diagram shows which tasks must precede which in executing a project.

In this chapter we present some of the mathematics of graphs and trees, discussing concepts such as the degree of a vertex, connectedness, Euler and Hamiltonian circuits, representation of graphs by matrices, isomorphisms of graphs, the relation between the number of vertices and the number of edges of a tree, properties of rooted trees span- ning trees, and shortest paths in graphs. Applications include uses of graphs and trees in the study of artificial intelligence, chemistry, scheduling problems, and transportation systems.

10.1 Graphs: Definitions and Basic Properties The whole of mathematics consists in the organization of a series of aids to the imagination in the process of reasoning. — Alfred North Whitehead, 1861–1947

Imagine an organization that wants to set up teams of three to work on some projects. In order to maximize the number of people on each team who had previous expe- rience working together successfully, the director asked the members to provide names of their past partners. This information is displayed below both in a table and in a diagram.

Name Past Partners

Ana Dan, Flo Bev Cai, Flo, Hal Cai Bev, Flo Dan Ana, Ed Ed Dan, Hal Flo Cai, Bev, Ana Gia Hal Hal Gia, Ed, Bev, Ira Ira Hal

Ana

Bev

Cai

Dan

EdFlo

Gia

Hal

Ira

From the diagram, it is easy to see that Bev, Cai, and Flo are a group of three past partners, and so they should form one of these teams. The figure on the next page shows the result when these three names are removed from the diagram.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

626 Chapter 10 Graphs and Trees

Ana

Dan

Ed

Gia

Hal

Ira

This drawing shows that placing Hal on the same team as Ed would leave Gia and Ira on a team containing no past partners. However, if Hal is placed on a team with Gia and Ira, then the remaining team would consist of Ana, Dan, and Ed, and both teams would contain at least one pair of past partners.

Drawings such as those shown previously are illustrations of a structure known as a graph. The dots are called vertices (plural of vertex) and the line segments joining vertices are called edges. As you can see from the drawing, it is possible for two edges to cross at a point that is not a vertex. Note also that the type of graph described here is quite different from the “graph of an equation” or the “graph of a function.”

In general, a graph consists of a set of vertices and a set of edges connecting various pairs of vertices. The edges may be straight or curved and should either connect one vertex to another or a vertex to itself, as shown below.

Parallel edges Isolated vertex

Loop

e3

e1

e2 e4

e6

e5

v2

v4

v1

v3

v5

v7

v6

In this drawing, the vertices have been labeled with v’s and the edges with e’s. When an edge connects a vertex to itself (as e5 does), it is called a loop. When two edges connect the same pair of vertices (as e2 and e3 do), they are said to be parallel. It is quite possible for a vertex to be unconnected by an edge to any other vertex in the graph (as v5 is), and in that case the vertex is said to be isolated. The formal definition of a graph follows.

• Definition A graph G consists of two finite sets: a nonempty set V (G) of vertices and a set E(G) of edges, where each edge is associated with a set consisting of either one or two vertices called its endpoints. The correspondence from edges to endpoints is called the edge-endpoint function.

An edge with just one endpoint is called a loop, and two or more distinct edges with the same set of endpoints are said to be parallel. An edge is said to connect its endpoints; two vertices that are connected by an edge are called adjacent; and a vertex that is an endpoint of a loop is said to be adjacent to itself.

An edge is said to be incident on each of its endpoints, and two edges incident on the same endpoint are called adjacent. A vertex on which no edges are incident is called isolated.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 627

Graphs have pictorial representations in which the vertices are represented by dots and the edges by line segments. A given pictorial representation uniquely determines a graph.

Example 10.1.1 Terminology

Consider the following graph:

e3 e2

e4

e6

e5

e7

e1

v1

v2 v3

v4

v6

v5

a. Write the vertex set and the edge set, and give a table showing the edge-endpoint function.

b. Find all edges that are incident on v1, all vertices that are adjacent to v1, all edges that are adjacent to e1, all loops, all parallel edges, all vertices that are adjacent to themselves, and all isolated vertices.

Solution

a. vertex set = {v1, v2, v3, v4, v5, v6} edge set = {e1, e2, e3, e4, e5, e6, e7} edge-endpoint function:

Edge Endpoints

e1 {v1, v2} e2 {v1, v3} e3 {v1, v3} e4 {v2, v3} e5 {v5, v6} e6 {v5} e7 {v6}

Note that the isolated vertex v4 does not appear in this table. Although each edge must have either one or two endpoints, a vertex need not be an endpoint of an edge.

b. e1, e2, and e3 are incident on v1. v2 and v3 are adjacent to v1. e2, e3, and e4 are adjacent to e1. e6 and e7 are loops. e2 and e3 are parallel. v5 and v6 are adjacent to themselves. v4 is an isolated vertex. ■

As noted earlier, a given pictorial representation uniquely determines a graph. However, a given graph may have more than one pictorial representation. Such things as the lengths or curvatures of the edges and the relative position of the vertices on the page may vary from one pictorial representation to another.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

628 Chapter 10 Graphs and Trees

Example 10.1.2 Drawing More Than One Picture for a Graph

Consider the graph specified as follows:

vertex set = {v1, v2, v3, v4} edge set = {e1, e2, e3, e4} edge-endpoint function:

Edge Endpoints

e1 {v1, v3} e2 {v2, v4} e3 {v2, v4} e4 {v3}

Both drawings (a) and (b) shown below are pictorial representations of this graph.

e4

e1

e2 e2

e4

e3 e1

e3

v3

v2 v4

v1

v2 v1

v3 v4

(a) (b) ■

Example 10.1.3 Labeling Drawings to Show They Represent the Same Graph

Consider the two drawings shown in Figure 10.1.1. Label vertices and edges in such a way that both drawings represent the same graph.

(a) (b)

Figure 10.1.1

Solution Imagine putting one end of a piece of string at the top vertex of Figure 10.1.1(a) (call this vertex v1), then laying the string to the next adjacent vertex on the lower right (call this vertex v2), then laying it to the next adjacent vertex on the upper left (v3), and so forth, returning finally to the top vertex v1. Call the first edge e1, the second e2, and so forth, as shown below.

e3 e1

e4 e2

e5

v3 v4

v5 v2

v1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 629

Now imagine picking up the piece of string, together with its labels, and repositioning it as follows:

e3

e1

e4 e2

v4

v1

v5 v2

v3

e5

This is the same as Figure 10.1.1(b), so both drawings are representations of the graph with vertex set {v1, v2, v3, v4, v5}, edge set {e1, e2, e3, e4, e5}, and edge-endpoint function as follows:

Edge Endpoints

e1 {v1, v2} e2 {v2, v3} e3 {v3, v4} e4 {v4, v5} e5 {v5, v1} ■

In Chapter 8 we discussed the directed graph of a binary relation on a set. The general definition of directed graph is similar to the definition of graph, except that one associates an ordered pair of vertices with each edge instead of a set of vertices. Thus each edge of a directed graph can be drawn as an arrow going from the first vertex to the second vertex of the ordered pair.

• Definition A directed graph, or digraph, consists of two finite sets: a nonempty set V (G) of vertices and a set D(G) of directed edges, where each is associated with an ordered pair of vertices called its endpoints. If edge e is associated with the pair (v,w) of vertices, then e is said to be the (directed) edge from v to w.

Note that each directed graph has an associated ordinary (undirected) graph, which is obtained by ignoring the directions of the edges.

Examples of Graphs Graphs are a powerful problem-solving tool because they enable us to represent a com- plex situation with a single image that can be analyzed both visually and with the aid of a computer. A few examples follow, and others are included in the exercises.

Example 10.1.4 Using a Graph to Represent a Network

Telephone, electric power, gas pipeline, and air transport systems can all be represented by graphs, as can computer networks—from small local area networks to the global Internet system that connects millions of computers worldwide. Questions that arise in the design of such systems involve choosing connecting edges to minimize cost, optimize a certain type of service, and so forth. A typical network, called a hub and spoke model, is shown on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

630 Chapter 10 Graphs and Trees

Boston

New York

Washington

Chicago Denver

San Francisco

Los Angeles

Example 10.1.5 Using a Graph to Represent the World Wide Web

The World Wide Web, or Web, is a system of interlinked documents, or webpages, con- tained on the Internet. Users employing Web browsers, such as Internet Explorer, Google Chrome, Apple Safari, and Opera, can move quickly from one webpage to another by clicking on hyperlinks, which use versions of software called hypertext transfer protocols (HTTPs). Individuals and individual companies create the pages, which they transmit to servers that contain software capable of delivering them to those who request them through a Web browser. Because the amount of information currently on the Web is so vast, search engines, such as Google, Yahoo, and Bing, have algorithms for finding infor- mation very efficiently.

The picture below shows a minute fraction of the hyperlink connections on the Inter- net that radiate in and out from the Wikipedia main page.

W ik

ip ed

ia /C

hr is

73

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 631

Example 10.1.6 Using a Graph to Represent Knowledge

In many applications of artifical intelligence, a knowledge base of information is col- lected and represented inside a computer. Because of the way the knowledge is repre- sented and because of the properties that govern the artificial intelligence program, the computer is not limited to retrieving data in the same form as it was entered; it can also derive new facts from the knowledge base by using certain built-in rules of inference. For example, from the knowledge that the Los Angeles Times is a big-city daily and that a big-city daily contains national news, an artifical intelligence program could infer that the Los Angeles Times contains national news. The directed graph shown in Fig- ure 10.1.2 is a pictorial representation for a simplified knowledge base about periodical publications.

According to this knowledge base, what paper finish does the New York Times use?

Paper made-of Periodical

contains

is-ais-a

is-ais-ais-a

is-a

is-a

Printed writing

Sports Illustrated

instance-of Sports magazine

Motor Trend insta

nce- of

Newspaper

Big-city daily

cont ains

Suburban weekly

Scholarly journal

Scientific journal

Literary journal

instance-of

ins tan

ce -o

f instance-of

Poetry Magazine

Los Angeles Times

New York Times

contains contains

contains

National news

Local news

Sports news

Glossy

paper-finish

paper-finish Matte

Long words

Figure 10.1.2

Solution The arrow going from New York Times to big-city daily (labeled “instance-of”) shows that the New York Times is a big-city daily. The arrow going from big-city daily to newspaper (labeled “is-a”) shows that a big-city daily is a newspaper. The arrow going from newspaper to matte (labeled “paper-finish”) indicates that the paper finish on a news- paper is matte. Hence it can be inferred that the paper finish on the New York Times is matte. ■

Example 10.1.7 Using a Graph to Solve a Problem: Vegetarians and Cannibals

The following is a variation of a famous puzzle often used as an example in the study of artificial intelligence. It concerns an island on which all the people are of one of two types, either vegetarians or cannibals. Initially, two vegetarians and two cannibals are on the left bank of a river. With them is a boat that can hold a maximum of two people. The aim of the puzzle is to find a way to transport all the vegetarians and cannibals to the right bank of the river. What makes this difficult is that at no time can the number of cannibals on either bank outnumber the number of vegetarians. Otherwise, disaster befalls the vegetarians!

Solution A systematic way to approach this problem is to introduce a notation that can indicate all possible arrangements of vegetarians, cannibals, and the boat on the banks of

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

632 Chapter 10 Graphs and Trees

the river. For example, you could write (vvc/Bc) to indicate that there are two vegetarians and one cannibal on the left bank and one cannibal and the boat on the right bank. Then (vvccB/) would indicate the initial position in which both vegetarians, both cannibals, and the boat are on the left bank of the river. The aim of the puzzle is to figure out a sequence of moves to reach the position (/Bvvcc) in which both vegetarians, both cannibals, and the boat are on the right bank of the river.

Construct a graph whose vertices are the various arrangements that can be reached in a sequence of legal moves starting from the initial position. Connect vertex x to ver- tex y if it is possible to reach vertex y in one legal move from vertex x . For instance, from the initial position there are four legal moves: one vegetarian and one cannibal can take the boat to the right bank; two cannibals can take the boat to the right bank; one cannibal can take the boat to the right bank; or two vegetarians can take the boat to the right bank. You can show these by drawing edges connecting vertex (vvccB/) to vertices (vc/Bvc), (vv/Bcc), (vvcBc), and (cc/Bvv). (It might seem natural to draw directed edges rather than undirected edges from one vertex to another. The rationale for drawing undirected edges is that each legal move is reversible.) From the position (vc/Bvc), the only legal moves are to go back to (vvccB/) or to go to (vvcB/c). You can also show these by drawing in edges. Continue this process until finally you reach (/Bvvcc). From Figure 10.1.3 it is apparent that one successful sequence of moves is (vvccB/) → (vc/Bvc) → (vvcB/c) → (c/Bvvc) → (ccB/vv) → (/Bvvcc).

vc/Bvc

vv/Bcc

vvccB/

vvc/Bc

cc/Bvv

vvcB/c c/Bvvc /Bvvcc

ccB/vv

vcB/vc

Figure 10.1.3 ■

Special Graphs One important class of graphs consists of those that do not have any loops or parallel edges. Such graphs are called simple. In a simple graph, no two edges share the same set of endpoints, so specifying two endpoints is sufficient to determine an edge.

• Definition and Notation A simple graph is a graph that does not have any loops or parallel edges. In a simple graph, an edge with endpoints v and w is denoted {v,w}.

Example 10.1.8 A Simple Graph

Draw all simple graphs with the four vertices {u, v, w, x} and two edges, one of which is {u, v}.

Solution Each possible edge of a simple graph corresponds to a subset of two vertices. Given four vertices, there are

(4 2

) = 6 such subsets in all: {u, v}, {u, w}, {u, x}, {v,w},

{v, x}, and {w, x}. Now one edge of the graph is specified to be {u, v}, so any of the remaining five from this list can be chosen to be the second edge. The possibilities are shown on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 633

u

w

v

x

u

w

v

x

u

w

v

x

u

w

v

x

u

w

v

x ■

Another important class of graphs consists of those that are “complete” in the sense that all pairs of vertices are connected by edges.

Note The K stands for the German word komplett, which means “complete.”

• Definition Let n be a positive integer. A complete graph on n vertices, denoted Kn, is a simple graph with n vertices and exactly one edge connecting each pair of distinct vertices.

Example 10.1.9 Complete Graphs on n Vertices: K1, K2, K3, K4, K5 The complete graphs K1, K2, K3, K4, and K5 can be drawn as follows:

v1 v1 v5

v2 v4

v2

v4

v3

v3

v1

v2

v3v1 v2

K2K1 K3 K4 K5 ■

In yet another class of graphs, the vertex set can be separated into two subsets: Each vertex in one of the subsets is connected by exactly one edge to each vertex in the other subset, but not to any vertices in its own subset. Such a graph is called complete bipartite.

• Definition Let m and n be positive integers. A complete bipartite graph on (m, n) vertices, denoted Km,n, is a simple graph with distinct vertices v1, v2, . . . , vm and w1, w2, . . . , wn that satisfies the following properties: For all i, k = 1, 2, . . . , m and for all j, l = 1, 2, . . . , n,

1. There is an edge from each vertex vi to each vertex w j .

2. There is no edge from any vertex vi to any other vertex vk .

3. There is no edge from any vertex w j to any other vertex wl .

Example 10.1.10 Complete Bipartite Graphs: K3,2 and K3,3 The complete bipartite graphs K3,2 and K3,3 are illustrated below.

v1

v2

v3

v1

v2

v3

w1

w2

w3

w2

w1

K3, 2 K3, 3 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

634 Chapter 10 Graphs and Trees

• Definition A graph H is said to be a subgraph of a graph G if, and only if, every vertex in H is also a vertex in G, every edge in H is also an edge in G, and every edge in H has the same endpoints as it has in G.

Example 10.1.11 Subgraphs

List all subgraphs of the graph G with vertex set {v1, v2} and edge set {e1, e2, e3}, where the endpoints of e1 are v1 and v2, the endpoints of e2 are v1 and v2, and e3 is a loop at v1.

Solution G can be drawn as shown below.

v1

v2

e1

e2

e3

There are 11 subgraphs of G, which can be grouped according to those that do not have any edges, those that have one edge, those that have two edges, and those that have three edges. The 11 subgraphs are shown in Figure 10.1.4.

v1

v2v2

e1

e2

v1

v2

e1

e2

e3v1 e3 v1

v2

e1

e3 v1

v2

e2

e3

v1v1

v2

e2

v2

e3v1 v1

v2

v1

v2

e1

1 2 3 4 5 6

7 8 9 10 11

Figure 10.1.4 ■

The Concept of Degree The degree of a vertex is the number of end segments of edges that “stick out of” the vertex. We will show that the sum of the degrees of all the vertices in a graph is twice the number of edges of the graph.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 635

• Definition Let G be a graph and v a vertex of G. The degree of v, denoted deg(v), equals the number of edges that are incident on v, with an edge that is a loop counted twice. The total degree of G is the sum of the degrees of all the vertices of G.

Since an edge that is a loop is counted twice, the degree of a vertex can be obtained from the drawing of a graph by counting how many end segments of edges are incident on the vertex. This is illustrated below.

The degree of this vertex equals 5.

Example 10.1.12 Degree of a Vertex and Total Degree of a Graph

Find the degree of each vertex of the graph G shown below. Then find the total degree of G.

v1

v2

v3

e1 e2

e3

Solution deg(v1) = 0 since no edge is incident on v1 (v1 is isolated). deg(v2) = 2 since both e1 and e2 are incident on v2. deg(v3) = 4 since e1 and e2 are incident on v3 and the loop e3 is also

incident on v3 (and contributes 2 to the degree of v3).

total degree of G = deg(v1) + deg(v2) + deg(v3) = 0 + 2 + 4 = 6. ■

Note that the total degree of the graph G of Example 10.1.12, which is 6, equals twice the number of edges of G, which is 3. Roughly speaking, this is true because each edge has two end segments, and each end segment is counted once toward the degree of some vertex. This result generalizes to any graph.

In fact, for any graph without loops, the general result can be explained as follows: Imagine a group of people at a party. Depending on how social they are, each person shakes hands with various other people. So each person participates in a certain number of handshakes—perhaps many, perhaps none—but because each handshake is experienced by two different people, if the numbers experienced by each person are added together, the sum will equal twice the total number of handshakes. This is such an attractive way of understanding the situation that the following theorem is often called the handshake lemma or the handshake theorem. As the proof demonstrates, the conclusion is true even if the graph contains loops.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

636 Chapter 10 Graphs and Trees

Theorem 10.1.1 The Handshake Theorem

If G is any graph, then the sum of the degrees of all the vertices of G equals twice the number of edges of G. Specifically, if the vertices of G are v1, v2, . . . , vn, where n is a nonnegative integer, then

the total degree of G = deg(v1) + deg(v2) + · · · + deg(vn) = 2 ·(the number of edges of G).

Proof:

Let G be a particular but arbitrarily chosen graph, and suppose that G has n vertices v1, v2, . . . , vn and m edges, where n is a positive integer and m is a nonnegative integer. We claim that each edge of G contributes 2 to the total degree of G. For sup- pose e is an arbitrarily chosen edge with endpoints vi and v j . This edge contributes 1 to the degree of vi and 1 to the degree v j . As shown below, this is true even if i = j , because an edge that is a loop is counted twice in computing the degree of the vertex on which it is incident.

vi vj

e e vi = vj

i = ji ≠ j

Therefore, e contributes 2 to the total degree of G. Since e was arbitrarily chosen, this shows that each edge of G contributes 2 to the total degree of G. Thus

the total degree of G = 2 · (the number of edges of G).

The following corollary is an immediate consequence of Theorem 10.1.1.

Corollary 10.1.2

The total degree of a graph is even.

Proof:

By Theorem 10.1.1 the total degree of G equals 2 times the number of edges, which is an integer, and so the total degree of G is even.

Example 10.1.13 Determining Whether Certain Graphs Exist

Draw a graph with the specified properties or show that no such graph exists.

a. A graph with four vertices of degrees 1, 1, 2, and 3

b. A graph with four vertices of degrees 1, 1, 3, and 3

c. A simple graph with four vertices of degrees 1, 1, 3, and 3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 637

Solution

a. No such graph is possible. By Corollary 10.1.2, the total degree of a graph is even. But a graph with four vertices of degrees 1, 1, 2, and 3 would have a total degree of 1 + 1 + 2 + 3 = 7, which is odd.

b. Let G be any of the graphs shown below.

a

d

b

c

a

d

b

c

a

d

b

c

a

d

b

c

In each case, no matter how the edges are labeled, deg(a) = 1, deg(b) = 1, deg(c) = 3, and deg(d) = 3.

c. There is no simple graph with four vertices of degrees 1, 1, 3, and 3.

Proof (by contradiction):

Suppose there were a simple graph G with four vertices of degrees 1, 1, 3, and 3. Call a and b the vertices of degree 1, and call c and d the vertices of degree 3. Since deg(c) = 3 and G does not have any loops or parallel edges (because it is simple), there must be edges that connect c to a, b, and d.

a

d

b

c

By the same reasoning, there must be edges connecting d to a, b, and c.

a

d

b

c

But then deg(a) ≥ 2 and deg(b) ≥ 2, which contradicts the supposition that these vertices have degree 1. Hence the supposition is false, and consequently there is no simple graph with four vertices of degrees 1, 1, 3, and 3. ■

Example 10.1.14 Application to an Acquaintance Graph

Is it possible in a group of nine people for each to be friends with exactly five others?

Solution The answer is no. Imagine constructing an “acquaintance graph” in which each of the nine people represented by a vertex and two vertices are joined by an edge if, and only if, the people they represent are friends. Suppose each of the people were friends with exactly five others. Then the degree of each of the nine vertices of the graph would be five, and so the total degree of the graph would be 45. But this contradicts Corollary 10.1.2, which says that the total degree of a graph is even. This contradiction shows that the supposition is false, and hence it is impossible for each person in a group of nine people to be friends with exactly five others. ■

The following proposition is easily deduced from Corollary 10.1.2 using properties of even and odd integers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

638 Chapter 10 Graphs and Trees

Proposition 10.1.3

In any graph there are an even number of vertices of odd degree.

Proof:

Suppose G is any graph, and suppose G has n vertices of odd degree and m vertices of even degree, where n is a positive integer and m is a nonnegative integer. [We must show that n is even.] Let E be the sum of the degrees of all the vertices of even degree, O the sum of the degrees of all the vertices of odd degree, and T the total degree of G. If u1, u2, . . . , um are the vertices of even degree and v1, v2, . . . , vn are the vertices of odd degree, then

E = deg(u1) + deg(u2) + · · · + deg(um), O = deg(v1) + deg(v2) + · · · + deg(vn), and T = deg(u1) + · · · + deg(um) + deg(v1) + · · · + deg(vn) = E + O.

Now T , the total degree of G, is an even integer by Corollary 10.1.2. Also E is even since either E is zero, which is even, or E is a sum of the numbers deg(ui ), each of which is even. But

T = E + O, and therefore O = T − E . Hence O is a difference of two even integers, and so O is even.

By assumption, deg(vi ) is odd for all i = 1, 2, . . . , n. Thus O , an even integer, is a sum of the n odd integers deg(v1), deg(v2), . . . , deg(vn). But if a sum of n odd integers is even, then n is even. (See exercise 32 at the end of this section.) Therefore, n is even [as was to be shown].

Example 10.1.15 Applying the Fact That the Number of Vertices with Odd Degree Is Even

Is there a graph with ten vertices of degrees 1, 1, 2, 2, 2, 3, 4, 4, 4, and 6?

Solution No. Such a graph would have three vertices of odd degree, which is impossible by Proposition 10.1.3.

Note that this same result could have been deduced directly from Corollary 10.1.2 by computing the total degree (1 + 1 + 2 + 2 + 2 + 3 + 4 + 4 + 4 + 6 = 29) and noting that it is odd. However, use of Proposition 10.1.3 gives the result without the need to perform this addition. ■

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. A graph consists of two finite sets: _____ and _____, where each edge is associated with a set consisting of _____.

2. A loop in a graph is _____.

3. Two distinct edges in a graph are parallel if, and only if, _____.

4. Two vertices are called adjacent if, and only if, _____.

5. An edge is incident on _____.

6. Two edges incident on the same endpoint are _____.

7. A vertex on which no edges are incident is _____.

8. In a directed graph, each edge is associated with _____.

9. A simple graph is _____.

10. A complete graph on n vertices is a _____.

11. A complete bipartite graph on (m, n) vertices is a simple graph whose vertices can be partitioned into two disjoint sets

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 639

V1 and V2 in such a way that (1) each of the m vertices in V1 is _____ to each of the n vertices in V2, no vertex in V1 is connected to _____, and no vertex in V2 is connected to _____.

12. A graph H is a subgraph of a graph G if, and only if, (1) _____, (2) _____, and (3) _____.

13. The degree of a vertex in a graph is _____.

14. The total degree of a graph is defined as _____.

15. The handshake theorem says that the total degree of a graph is _____.

16. In any graph the number of vertices of odd degree is _____.

Exercise Set 10.1* In 1 and 2, graphs are represented by drawings. Define each graph formally by specifying its vertex set, its edge set, and a table giving the edge-endpoint function.

1.

v2v1

v3

v4 e2

e3

e1

2.

v2

v3

v1

v4 e2 e3

e4 e5 e1

In 3 and 4, draw pictures of the specified graphs.

3. Graph G has vertex set {v1, v2, v3, v4, v5} and edge set {e1, e2, e3, e4}, with edge-endpoint function as follows:

Edge Endpoints

e1 {v1, v2} e2 {v1, v2} e3 {v2, v3} e4 {v2}

4. Graph H has vertex set {v1, v2, v3, v4, v5} and edge set {e1, e2, e3, e4} with edge-endpoint function as follows:

Edge Endpoints

e1 {v1} e2 {v2, v3} e3 {v2, v3} e4 {v1, v5}

In 5–7, show that the two drawings represent the same graph by labeling the vertices and edges of the right-hand drawing to correspond to those of the left-hand drawing.

5.

v2 v1 v3

v4v5v6

e7 e6 e5

e2

e3 e4e1

6. v1

v4

v2

v3

e2 e3e4

e1

7.

v1

v2

v7

v3

v5

v4

v6

e2

e1 e3

e5e7 e6

e8 e4

e9

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbolH indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

640 Chapter 10 Graphs and Trees

For each of the graphs in 8 and 9: (i) Find all edges that are incident on v1.

(ii) Find all vertices that are adjacent to v3. (iii) Find all edges that are adjacent to e1. (iv) Find all loops. (v) Find all parallel edges.

(vi) Find all isolated vertices. (vii) Find the degree of v3.

(viii) Find the total degree of the graph.

8. v1

v5 v4

v3

v2 v6

e2

e3

e8

e9 e7

e5e4

e6

e1 e10

9.

v2 v1

v3 v5

v4

e2

e4 e5

e7

e3

e6

e1

10. Use the graph of Example 10.1.6 to determine a. whether Sports Illustrated contains printed writing; b. whether Poetry Magazine contains long words.

11. Find three other winning sequences of moves for the vege- tarians and the cannibals in Example 10.1.7.

12. Another famous puzzle used as an example in the study of artificial intelligence seems first to have appeared in a collection of problems, Problems for the Quickening of the Mind, which was compiled about A.D. 775. It involves a wolf, a goat, a bag of cabbage, and a ferryman. From an initial position on the left bank of a river, the ferryman is to transport the wolf, the goat, and the cabbage to the right bank. The difficulty is that the ferryman’s boat is only big enough for him to transport one object at a time, other than himself. Yet, for obvious reasons, the wolf cannot be left alone with the goat, and the goat cannot be left alone with the cabbage. How should the ferryman proceed?

13. Solve the vegetarians-and-cannibals puzzle for the case where there are three vegetarians and three cannibals to be transported from one side of a river to the other.

14.H Two jugs A and B have capacities of 3 quarts and 5 quarts, respectively. Can you use the jugs to measure out exactly 1 quart of water, while obeying the following restrictions? You may fill either jug to capacity from a water tap; you may empty the contents of either jug into a drain; and you may pour water from either jug into the other.

15. A graph has vertices of degrees 0, 2, 2, 3, and 9. How many edges does the graph have?

16. A graph has vertices of degrees 1, 1, 4, 4, and 6. How many edges does the graph have?

In each of 17–25, either draw a graph with the specified proper- ties or explain why no such graph exists.

17. Graph with five vertices of degrees 1, 2, 3, 3, and 5.

18. Graph with four vertices of degrees 1, 2, 3, and 3.

19. Graph with four vertices of degrees 1, 1, 1, and 4.

20. Graph with four vertices of degrees 1, 2, 3, and 4.

21. Simple graph with four vertices of degrees 1, 2, 3, and 4.

22. Simple graph with five vertices of degrees 2, 3, 3, 3, and 5.

23. Simple graph with five vertices of degrees 1, 1, 1, 2, and 3.

24. Simple graph with six edges and all vertices of degree 3.

25. Simple graph with nine edges and all vertices of degree 3.

26. Find all subgraphs of each of the following graphs.

a.

v1

v2

e2

e1

b.

v0

v1

c.

v1 v3

v2

27. a. In a group of 15 people, is it possible for each person to have exactly 3 friends? Explain. (Assume that friendship is a symmetric relationship: If x is a friend of y, then y is a friend of x .)

b. In a group of 4 people, is it possible for each person to have exactly 3 friends? Why?

28. In a group of 25 people, is it possible for each to shake hands with exactly 3 other people? Explain.

29. Is there a simple graph, each of whose vertices has even degree? Explain.

30. Suppose that G is a graph with v vertices and e edges and that the degree of each vertex is at least dmin and at most dmax. Show that

1 2

dmin ·v ≤ e ≤ 1 2

dmax ·v.

31. Prove that any sum of an odd number of odd integers is odd.

32.H Deduce from exercise 31 that for any positive integer n, if there is a sum of n odd integers that is even, then n is even.

33. Recall that Kn denotes a complete graph on n vertices. a. Draw K6. b.H Show that for all integers n ≥ 1, the number of edges of

Kn is n(n − 1)

2 .

34. Use the result of exercise 33 to show that the number of edges of a simple graph with n vertices is less than or equal

to n(n − 1)

2 .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.1 Graphs: Definitions and Basic Properties 641

35. Is there a simple graph with twice as many edges as ver- tices? Explain. (You may find it helpful to use the result of exercise 34.)

36. Recall that Km,n denotes a complete bipartite graph on (m, n) vertices. a. Draw K4,2 b. Draw K1,3 c. Draw K3,4 d. How many vertices of Km,n have degree m? degree n? e. What is the total degree of Km,n? f. Find a formula in terms of m and n for the number of

edges of Km,n . Explain.

37. A bipartite graph G is a simple graph whose vertex set can be partitioned into two disjoint nonempty subsets V1 and V2 such that vertices in V1 may be connected to vertices in V2, but no vertices in V1 are connected to other vertices in V1 and no vertices in V2 are connected to other vertices in V2. For example, the graph G illustrated in (i) can be redrawn as shown in (ii). From the drawing in (ii), you can see that G is bipartite with mutually disjoint vertex sets V1 = {v1, v3, v5} and V2 = {v2, v4, v6}.

(i)

v1

v6

v3

v2

v5

v4

(ii) v1

v3

v5

v2

v4

v6

Find which of the following graphs are bipartite. Redraw the bipartite graphs so that their bipartite nature is evident.

a. v1

v4

v2

v3

b. v1

v3

v2

c.

v1

v4

v3

v6

v2

v5

d.

v1

v2

v6

v5

v4

v3

e. v1

v5

v2

v3

v4

f.

v1

v5

v3

v4

v2

38. Suppose r and s are any positive integers. Does there exist a graph G with the property that G has vertices of degrees r and s and of no other degrees? Explain.

Definition: If G is a simple graph, the complement of G, denoted G′, is obtained as follows: The vertex set of G ′ is identical to the vertex set of G. However, two distinct ver- tices v and w of G ′ are connected by an edge if, and only if, v and w are not connected by an edge in G. For example, if G is the graph

v1

v2

v4

v3

then G ′ is v2

v4

v1 v3

39. Find the complement of each of the following graphs.

a.

v1 v3

v2

v4

b. v1

v4

v2

v3

40. a. Find the complement of the graph K4, the complete graph on four vertices. (See Example 10.1.9.)

b. Find the complement of the graph K3,2, the complete bipartite graph on (3, 2) vertices. (See Example 10.1.10.)

41. Suppose that in a group of five people A, B, C, D, and E the following pairs of people are acquainted with each other: A and C, A and D, B and C, C and D, C and E . a. Draw a graph to represent this situation. b. Draw a graph that illustrates who among these five peo-

ple are not acquainted. That is, draw an edge between two people if, and only if, they are not acquainted.

42.H Let G be a simple graph with n vertices. What is the rela- tion between the number of edges of G and the number of edges of the complement G ′?

43. Show that at a party with at least two people, there are at least two mutual acquaintances or at least two mutual strangers.

44. a. In a simple graph, must every vertex have degree that is less than the number of vertices in the graph? Why?

b. Can there be a simple graph that has four vertices each of different degrees?

c.H ✶ Can there be a simple graph that has n vertices all of different degrees?

45.✶H In a group of two or more people, must there always be at least two people who are acquainted with the same number of people within the group? Why?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

642 Chapter 10 Graphs and Trees

46. Imagine that the diagram shown below is a map with coun- tries labeled a–g. Is it possible to color the map with only three colors so that no two adjacent countries have the same color? To answer this question, draw and analyze a graph in which each country is represented by a vertex and two ver- tices are connected by an edge if, and only if, the countries share a common border.

a b c

d e

g f

47.H In this exercise a graph is used to help solve a scheduling problem. Twelve faculty members in a mathematics depart- ment serve on the following committees:

Undergraduate Education: Tenner, Peterson, Kashina, Cohen

Graduate Education: Gatto, Yang, Cohen, Catoiu

Colloquium: Sahin, McMurry, Ash

Library: Cortzen, Tenner, Sahin

Hiring: Gatto, McMurry, Yang, Peterson

Personnel: Yang, Wang, Cortzen

The committees must all meet during the first week of classes, but there are only three time slots available. Find

a schedule that will allow all faculty members to attend the meetings of all committees on which they serve. To do this, represent each committee as the vertex of a graph, and draw an edge between two vertices if the two committees have a common member. Find a way to color the vertices using only three colors so that no two committees have the same color, and explain how to use the result to schedule the meetings.

48. A department wants to schedule final exams so that no stu- dent has more than one exam on any given day. The vertices of the graph below show the courses that are being taken by more than one student, with an edge connecting two ver- tices if there is a student in both courses. Find a way to color the vertices of the graph with only four colors so that no two adjacent vertices have the same color and explain how to use the result to schedule the final exams.

MCS101 MCS102

MCS110

MCS120MCS130 MCS135

MCS100

Answers for Test Yourself 1. a finite, nonempty set of vertices; a finite set of edges; one or two vertices called its endpoints 2. an edge with a single endpoint 3. they have the same set of endpoints 4. they are connected by an edge 5. each of its endpoints 6. adjacent 7. isolated 8. an ordered pair of vertices called its endpoints 9. a graph with no loops or parallel edges 10. simple graph with n vertices whose set of edges contains exactly one edge for each pair of vertices 11. connected by an edge; any other vertex in V1; any other vertex in V2 12. every vertex in H is also a vertex in G; every edge in H is also an edge in G; every edge in H has the same endpoints as it has in G 13. the number of edges that are incident on the vertex, with an edge that is a loop counted twice 14. the sum of the degrees of all the vertices of the graph 15. equal to twice the number of edges of the graph 16. an even number

10.2 Trails, Paths, and Circuits One can begin to reason only when a clear picture has been formed in the imagination. — W. W. Sawyer, Mathematician’s Delight, 1943

The subject of graph theory began in the year 1736 when the great mathematician Leon- hard Euler published a paper giving the solution to the following puzzle:

The town of Königsberg in Prussia (now Kaliningrad in Russia) was built at a point where two branches of the Pregel River came together. It consisted of an island and some land along the river banks. These were connected by seven bridges as shown in Figure 10.2.1.

The question is this: Is it possible for a person to take a walk around town, starting and ending at the same location and crossing each of the seven bridges exactly once?∗

∗In his original paper, Euler did not require the walk to start and end at the same point. The analysis of the problem is simplified, however, by adding this condition. Later in the section, we discuss walks that start and end at different points.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 643

Pregel River B

D

A

C

M er

ia n-

E rb

en

B

D

A

C

Figure 10.2.1 The Seven Bridges of Königsberg

To solve this puzzle, Euler translated it into a graph theory problem. He noticed that all points of a given land mass can be identified with each other since a person can travel from any one point to any other point of the same land mass without crossing a bridge. Thus for the purpose of solving the puzzle, the map of Königsberg can be identified with the graph shown in Figure 10.2.2, in which the vertices A, B, C , and D represent land masses and the seven edges represent the seven bridges.

B et

tm an

n/ CO

R B

IS

Leonhard Euler (1707–1783)

A

D

B C

Figure 10.2.2 Graph Version of Königsberg Map

In terms of this graph, the question becomes the following:

Is it possible to find a route through the graph that starts and ends at some vertex, one of A, B, C, or D, and traverses each edge exactly once?

Equivalently:

Is it possible to trace this graph, starting and ending at the same point, without ever lifting your pencil from the paper?

Take a few minutes to think about the question yourself. Can you find a route that meets the requirements? Try it!

Looking for a route is frustrating because you continually find yourself at a vertex that does not have an unused edge on which to leave, while elsewhere there are unused edges that must still be traversed. If you start at vertex A, for example, each time you pass through vertex B, C , or D, you use up two edges because you arrive on one edge and depart on a different one. So, if it is possible to find a route that uses all the edges of the graph and starts and ends at A, then the total number of arrivals and departures from each vertex B, C , and D must be a multiple of 2. Or, in other words, the degrees of

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

644 Chapter 10 Graphs and Trees

the vertices B, C , and D must be even. But they are not: deg(B) = 5, deg(C) = 3, and deg(D) = 3. Hence there is no route that solves the puzzle by starting and ending at A. Similar reasoning can be used to show that there are no routes that solve the puzzle by starting and ending at B, C, or D. Therefore, it is impossible to travel all around the city crossing each bridge exactly once.

Definitions Travel in a graph is accomplished by moving from one vertex to another along a sequence of adjacent edges. In the graph below, for instance, you can go from u1 to u4 by taking f1 to u2 and then f7 to u4. This is represented by writing

u1f1u2f7u4.

f1 f2

f7 f4

f3

f5

f6

u1

u5

u2

u4

u3

Or you could take the roundabout route

u1 f1u2 f3u3 f4u2 f3u3 f5u4 f6u4 f7u2 f3u3 f5u4.

Certain types of sequences of adjacent vertices and edges are of special importance in graph theory: those that do not have a repeated edge, those that do not have a repeated vertex, and those that start and end at the same vertex.

• Definition Let G be a graph, and let v and w be vertices in G.

A walk from v to w is a finite alternating sequence of adjacent vertices and edges of G. Thus a walk has the form

v0e1v1e2 · · · vn−1envn, where the v’s represent vertices, the e’s represent edges, v0 = v, vn = w, and for all i = 1, 2, . . . n, vi−1 and vi are the endpoints of ei . The trivial walk from v to v consists of the single vertex v.

A trail from v to w is a walk from v to w that does not contain a repeated edge. A path from v to w is a trail that does not contain a repeated vertex. A closed walk is a walk that starts and ends at the same vertex. A circuit is a closed walk that contains at least one edge and does not contain a repeated edge.

A simple circuit is a circuit that does not have any other repeated vertex except the first and last.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 645

For ease of reference, these definitions are summarized in the following table:

Repeated Repeated Starts and Ends Must Contain at Edge? Vertex? at Same Point? Least One Edge?

Walk allowed allowed allowed no

Trail no allowed allowed no

Path no no no no

Closed walk allowed allowed yes no

Circuit no allowed yes yes

Simple circuit no first and yes yes last only

Often a walk can be specified unambiguously by giving either a sequence of edges or a sequence of vertices. The next two examples show how this is done.

Example 10.2.1 Notation for Walks a. In the graph below, the notation e1e2e4e3 refers unambiguously to the following walk:

v1e1v2e2v3e4v3e3v2. On the other hand, the notation e1 is ambiguous if used to refer to a walk. It could mean either v1e1v2 or v2e1v1.

v1 v2 v3

e2

e3

e1 e4

b. In the graph of part (a), the notation v2v3 is ambiguous if used to refer to a walk. It could mean v2e2v3 or v2e3v3. On the other hand, in the graph below, the notation v1v2v2v3 refers unambiguously to the walk v1e1v2e2v2e3v3.

v1 v2 v3

e2

e1 e3 ■

Note that if a graph G does not have any parallel edges, then any walk in G is uniquely determined by its sequence of vertices.

Example 10.2.2 Walks, Trails Paths, and Circuits

In the graph below, determine which of the following walks are trails, paths, circuits, or simple circuits.

a. v1e1v2e3v3e4v3e5v4 b. e1e3e5e5e6 c. v2v3v4v5v3v6v2 d. v2v3v4v5v6v2 e. v1e1v2e1v1 f. v1

v1 v2

v6

v3 v4

v5

e2

e5

e9

e4

e3 e7

e8

e10 e6

e1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

646 Chapter 10 Graphs and Trees

Solution

a. This walk has a repeated vertex but does not have a repeated edge, so it is a trail from v1 to v4 but not a path.

b. This is just a walk from v1 to v5. It is not a trail because it has a repeated edge.

c. This walk starts and ends at v2, contains at least one edge, and does not have a repeated edge, so it is a circuit. Since the vertex v3 is repeated in the middle, it is not a simple circuit.

d. This walk starts and ends at v2, contains at least one edge, does not have a repeated edge, and does not have a repeated vertex. Thus it is a simple circuit.

e. This is just a closed walk starting and ending at v1. It is not a circuit because edge e1 is repeated.

f. The first vertex of this walk is the same as its last vertex, but it does not contain an edge, and so it is not a circuit. It is a closed walk from v1 to v1. (It is also a trail from v1 to v1.) ■

Because most of the major developments in graph theory have happened relatively recently and in a variety of different contexts, the terms used in the subject have not been stan- dardized. For example, what this book calls a graph is sometimes called a multigraph, what this book calls a simple graph is sometimes called a graph, what this book calls a vertex is sometimes called a node, and what this book calls an edge is sometimes called an arc. Similarly, instead of the word trail, the word path is sometimes used; instead of the word path, the words simple path are sometimes used; and instead of the words sim- ple circuit, the word cycle is sometimes used. The terminology in this book is among the most common, but if you consult other sources, be sure to check their definitions.

Connectedness It is easy to understand the concept of connectedness on an intuitive level. Roughly speak- ing, a graph is connected if it is possible to travel from any vertex to any other vertex along a sequence of adjacent edges of the graph. The formal definition of connectedness is stated in terms of walks.

• Definition Let G be a graph. Two vertices v and w of G are connected if, and only if, there is a walk from v to w. The graph G is connected if, and only if, given any two vertices v and w in G, there is a walk from v to w. Symbolically,

G is connected ⇔ ∀ vertices v,w ∈ V (G), ∃ a walk from v to w.

If you take the negation of this definition, you will see that a graph G is not connected if, and only if, there are two vertices of G that are not connected by any walk.

Example 10.2.3 Connected and Disconnected Graphs

Which of the following graphs are connected?

v1 v1 v3

v2 v3

v4

v5

v6

v2 v2

v3

v6

v5 v1

v4 v4

v5

v8 v7

v6

(a) (b) (c)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 647

Solution The graph represented in (a) is connected, whereas those of (b) and (c) are not. To understand why (c) is not connected, recall that in a drawing of a graph, two edges may cross at a point that is not a vertex. Thus the graph in (c) can be redrawn as follows:

v1

v2

v3

v4

v6

v5

Some useful facts relating circuits and connectedness are collected in the following lemma. Proofs of (a) and (b) are left for the exercises. The proof of (c) is in Section 10.5.

Lemma 10.2.1

Let G be a graph.

a. If G is connected, then any two distinct vertices of G can be connected by a path.

b. If vertices v and w are part of a circuit in G and one edge is removed from the circuit, then there still exists a trail from v to w in G.

c. If G is connected and G contains a circuit, then an edge of the circuit can be removed without disconnecting G.

Look back at Example 10.2.3. The graphs in (b) and (c) are both made up of three pieces, each of which is itself a connected graph. A connected component of a graph is a connected subgraph of largest possible size.

• Definition A graph H is a connected component of a graph G if, and only if,

1. H is subgraph of G;

2. H is connected; and

3. no connected subgraph of G has H as a subgraph and contains vertices or edges that are not in H .

The fact is that any graph is a kind of union of its connected components.

Example 10.2.4 Connected Components

Find all connected components of the following graph G.

v1

v2

v4

v5

v8

v6

v7v3

e2 e4

e1

e3

e5

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

648 Chapter 10 Graphs and Trees

Solution G has three connected components: H1, H2, and H3 with vertex sets V1, V2, and V3 and edge sets E1, E2, and E3, where

V1 = {v1, v2, v3}, E1 = {e1, e2}, V2 = {v4}, E2 = ∅, V3 = {v5, v6, v7, v8}, E3 = {e3, e4, e5}. ■

Euler Circuits Now we return to consider general problems similar to the puzzle of the Königsberg bridges. The following definition is made in honor of Euler.

• Definition Let G be a graph. An Euler circuit for G is a circuit that contains every vertex and every edge of G. That is, an Euler circuit for G is a sequence of adjacent vertices and edges in G that has at least one edge, starts and ends at the same vertex, uses every vertex of G at least once, and uses every edge of G exactly once.

The analysis used earlier to solve the puzzle of the Königsberg bridges generalizes to prove the following theorem:

Theorem 10.2.2

If a graph has an Euler circuit, then every vertex of the graph has positive even degree.

Proof:

Suppose G is a graph that has an Euler circuit. [We must show that given any vertex v of G, the degree of v is even.] Let v be any particular but arbitrarily chosen vertex of G. Since the Euler circuit contains every edge of G, it contains all edges incident on v. Now imagine taking a journey that begins in the middle of one of the edges adjacent to the start of the Euler circuit and continues around the Euler circuit to end in the middle of the starting edge. (See Figure 10.2.3. There is such a starting edge because the Euler circuit has at least one edge.) Each time v is entered by traveling along one edge, it is immediately exited by traveling along another edge (since the journey ends in the middle of an edge).

In this example, the Euler circuit is v0v1v2v3v4v5v0, and v is v2. Each time v2 is entered by one edge, it is exited by another edge.

Start here First entry/exit pair of edges

Second entry/exit pair of edges

v1

v5

v2 v0

v3

v4

Figure 10.2.3 Example for the Proof of Theorem 10.2.2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 649

Because the Euler circuit uses every edge of G exactly once, every edge incident on v is traversed exactly once in this process. Hence the edges incident on v occur in entry/exit pairs, and consequently the degree of v must be a positive multiple of 2. But that means that v has positive even degree [as was to be shown].

Recall that the contrapositive of a statement is logically equivalent to the statement. The contrapositive of Theorem 10.2.2 is as follows:

Contrapositive Version of Theorem 10.2.2

If some vertex of a graph has odd degree, then the graph does not have an Euler circuit.

This version of Theorem 10.2.2 is useful for showing that a given graph does not have an Euler circuit.

Example 10.2.5 Showing That a Graph Does Not Have an Euler Circuit

Show that the graph below does not have an Euler circuit.

v1 v4

v3

e2

e7

e6 e5

e4

e3

e1v2

Solution Vertices v1 and v3 both have degree 3, which is odd. Hence by (the contrapositive form of) Theorem 10.2.2, this graph does not have an Euler circuit. ■

Now consider the converse of Theorem 10.2.2: If every vertex of a graph has even degree, then the graph has an Euler circuit. Is this true? The answer is no. There is a graph G such that every vertex of G has even degree but G does not have an Euler circuit. In fact, there are many such graphs. The illustration below shows one example.

v1

v2

e2

e1

v4

v3

e4

Every vertex has even degree, but the graph does not have an Euler circuit.

e3

Note that the graph in the preceding drawing is not connected. It turns out that although the converse of Theorem 10.2.2 is false, a modified converse is true: If every vertex of a graph has positive even degree and if the graph is connected, then the graph has an Euler circuit. The proof of this fact is constructive: It contains an algorithm to find an Euler circuit for any connected graph in which every vertex has even degree.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

650 Chapter 10 Graphs and Trees

Theorem 10.2.3

If a graph G is connected and the degree of every vertex of G is a positive even integer, then G has an Euler circuit.

Proof:

Suppose that G is any connected graph and suppose that every vertex of G is a positive even integer. [We must find an Euler circuit for G.] Construct a circuit C by the following algorithm:

Step 1: Pick any vertex v of G at which to start. [This step can be accomplished because the vertex set of G is nonempty by assumption.]

Step 2: Pick any sequence of adjacent vertices and edges, starting and ending at v and never repeating an edge. Call the resulting circuit C . [This step can be performed for the following reasons: Since the degree of each vertex of G is a positive even integer, as each vertex of G is entered by traveling on one edge, either the vertex is v itself and there is no other unused edge adja- cent to v, or the vertex can be exited by traveling on another previously unused edge. Since the number of edges of the graph is finite (by definition of graph), the sequence of distinct edges cannot go on forever. The sequence can eventu- ally return to v because the degree of v is a positive even integer, and so if an edge connects v to another vertex, there must be a different edge that connects back to v.]

Step 3: Check whether C contains every edge and vertex of G. If so, C is an Euler circuit, and we are finished. If not, perform the following steps.

Step 3a: Remove all edges of C from G and also any vertices that become isolated when the edges of C are removed. Call the resulting subgraph G ′. [Note that G ′ may not be connected (as illustrated in Figure 10.2.4), but every vertex of G ′ has positive, even degree (since removing the edges of C removes an even number of edges from each vertex, the difference of two even integers is even, and isolated vertices with degree 0 were removed.)]

G:

u

v

w

C

G'

Figure 10.2.4

Step 3b: Pick any vertex w common to both C and G ′. [There must be at least one such vertex since G is connected. (See exercise 44.) (In Figure 10.2.4 there are two such vertices: u and w.)]

Step 3c: Pick any sequence of adjacent vertices and edges of G ′, starting and ending at w and never repeating an edge. Call the resulting circuit C ′. [This can be done since each vertex of G ′ has positive, even degree and G ′ is finite. See the justification for step 2.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 651

Step 3d: Patch C and C ′ together to create a new circuit C ′′ as follows: Start at v and follow C all the way to w. Then follow C ′ all the way back to w. After that, continue along the untraveled portion of C to return to v. [The effect of executing steps 3c and 3d for the graph of Figure 10.2.4 is shown in Figure 10.2.5.]

G:

u

v

w

C

C''

C'

Figure 10.2.5

Step 3e: Let C = C ′′ and go back to step 3. Since the graph G is finite, execution of the steps outlined in this algorithm must eventually terminate. At that point an Euler circuit for G will have been constructed. (Note that because of the element of choice in steps 1, 2, 3b, and 3c, a variety of different Euler circuits can be produced by using this algorithm.)

Example 10.2.6 Finding an Euler Circuit

Use Theorem 10.2.3 to check that the graph below has an Euler circuit. Then use the algorithm from the proof of the theorem to find an Euler circuit for the graph.

a

b c

d

e

f i

j

h g

Solution Observe that

deg(a) = deg(b) = deg(c) = deg( f ) = deg(g) = deg(i) = deg( j) = 2 and that deg(d) = deg(e) = deg(h) = 4. Hence all vertices have even degree. Also, the graph is connected. Thus, by Theorem 10.2.3, the graph has an Euler circuit.

To construct an Euler circuit using the algorithm of Theorem 10.2.3, let v = a and let C be

C: abcda. C is represented by the labeled edges shown below.

a

b c

d

e

f i

j

h g

2

4

1 3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

652 Chapter 10 Graphs and Trees

Observe that C is not an Euler circuit for the graph but that C intersects the rest of the graph at d. Let C ′ be

C ′: deghjid. Patch C ′ into C to obtain

C ′′: abcdegh jida. Set C = C ′′. Then C is represented by the labeled edges shown below.

a

b c

d

e

f i

j

h g

2

10

1 3 4

5 6

7

8

9

Observe that C is not an Euler circuit for the graph but that it intersects the rest of the graph at e. Let C ′ be

C ′: e f he. Patch C ′ into C to obtain

C ′′: abcde f hegh jida. Set C = C ′′. Then C is represented by the labeled edges shown below.

a

b c

d

e

f i

j

h g

2

13

1 3 4

5 67

10

11

12

8 9

Since C includes every edge of the graph exactly once, C is an Euler circuit for the graph. ■

In exercise 45 at the end of this section you are asked to show that any graph with an Euler circuit is connected. This result can be combined with Theorems 10.2.2 and 10.2.3 to give a complete characterization of graphs that have Euler circuits, as stated in Theorem 10.2.4.

Theorem 10.2.4

A graph G has an Euler circuit if, and only if, G is connected and every vertex of G has positive even degree.

A corollary to Theorem 10.2.4 gives a criterion for determining when it is possible to find a walk from one vertex of a graph to another, passing through every vertex of the graph at least once and every edge of the graph exactly once.

• Definition Let G be a graph, and let v and w be two distinct vertices of G. An Euler trail from v to w is a sequence of adjacent edges and vertices that starts at v, ends at w, passes through every vertex of G at least once, and traverses every edge of G exactly once.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 653

Corollary 10.2.5

Let G be a graph, and let v and w be two distinct vertices of G. There is an Euler path from v to w if, and only if, G is connected, v and w have odd degree, and all other vertices of G have positive even degree.

The proof of this corollary is left as an exercise.

Example 10.2.7 Finding an Euler Trail

The floor plan shown below is for a house that is open for public viewing. Is it possible to find a trail that starts in room A, ends in room B, and passes through every interior doorway of the house exactly once? If so, find such a trail.

A

B

C D J K

I

E

HG

F

Solution Let the floor plan of the house be represented by the graph below.

A

B

C

G

H

F

D

E J

I

K

Each vertex of this graph has even degree except for A and B, each of which has degree 1. Hence by Corollary 10.2.5, there is an Euler path from A to B. One such trail is

AG H F E I H E K J DC B. ■

Hamiltonian Circuits Theorem 10.2.4 completely answers the following question: Given a graph G, is it pos-

B et

tm an

n/ CO

R B

IS

Sir Wm. Hamilton (1805–1865)

sible to find a circuit for G in which all the edges of G appear exactly once? A related question is this: Given a graph G, is it possible to find a circuit for G in which all the vertices of G (except the first and the last) appear exactly once?

In 1859 the Irish mathematician Sir William Rowan Hamilton introduced a puzzle in the shape of a dodecahedron (DOH-dek-a-HEE-dron). (Figure 10.2.6 contains a drawing of a dodecahedron, which is a solid figure with 12 identical pentagonal faces.)

Figure 10.2.6 Dodecahedron

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

654 Chapter 10 Graphs and Trees

Each vertex was labeled with the name of a city—London, Paris, Hong Kong, New York, and so on. The problem Hamilton posed was to start at one city and tour the world by visiting each other city exactly once and returning to the starting city. One way to solve the puzzle is to imagine the surface of the dodecahedron stretched out and laid flat in the plane, as follows:

The circuit denoted with black lines is one solution. Note that although every city is visited, many edges are omitted from the circuit. (More difficult versions of the puzzle required that certain cities be visited in a certain order.)

The following definition is made in honor of Hamilton.

• Definition Given a graph G, a Hamiltonian circuit for G is a simple circuit that includes every vertex of G. That is, a Hamiltonian circuit for G is a sequence of adjacent vertices and distinct edges in which every vertex of G appears exactly once, except for the first and the last, which are the same.

Note that although an Euler circuit for a graph G must include every vertex of G, it may visit some vertices more than once and hence may not be a Hamiltonian circuit. On the other hand, a Hamiltonian circuit for G does not need to include all the edges of G and hence may not be an Euler circuit.

Despite the analogous-sounding definitions of Euler and Hamiltonian circuits, the mathematics of the two are very different. Theorem 10.2.4 gives a simple criterion for determining whether a given graph has an Euler circuit. Unfortunately, there is no anal- ogous criterion for determining whether a given graph has a Hamiltonian circuit, nor is there even an efficient algorithm for finding such a circuit. There is, however, a simple technique that can be used in many cases to show that a graph does not have a Hamilto- nian circuit. This follows from the following considerations:

Suppose a graph G with at least two vertices has a Hamiltonian circuit C given con- cretely as

C: v0e1v1e2 · · · vn−1envn. Since C is a simple circuit, all the ei are distinct and all the v j are distinct except that v0 = vn . Let H be the subgraph of G that is formed using the vertices and edges of C . An example of such an H is shown below.

H is indicated by the black lines.

Note that H has the same number of edges as it has vertices since all its n edges are distinct and so are its n vertices v1, v2, . . . , vn . Also, by definition of Hamiltonian circuit,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 655

every vertex of G is a vertex of H , and H is connected since any two of its vertices lie on a circuit. In addition, every vertex of H has degree 2. The reason for this is that there are exactly two edges incident on any vertex. These are ei and ei+1 for any vertex vi except v0 = vn , and they are e1 and en for v0 (= vn). These observations have established the truth of the following proposition in all cases where G has at least two vertices.

Proposition 10.2.6

If a graph G has a Hamiltonian circuit, then G has a subgraph H with the following properties:

1. H contains every vertex of G.

2. H is connected.

3. H has the same number of edges as vertices.

4. Every vertex of H has degree 2.

Note that if G contains only one vertex and G has a Hamiltonian circuit, then the circuit has the form v e v, where v is the vertex of G and e is an edge incident on v. In this case, the subgraph H consisting of v and e satisfies conditions (1)–(4) of Proposition 10.2.6.

Recall that the contrapositive of a statement is logically equivalent to the statement. The contrapositive of Proposition 10.2.6 says that if a graph G does not have a subgraph H with properties (1)–(4), then G does not have a Hamiltonian circuit.

Example 10.2.8 Showing That a Graph Does Not Have a Hamiltonian Circuit

Prove that the graph G shown below does not have a Hamiltonian circuit.

a

e

b c

d

Solution If G has a Hamiltonian circuit, then by Proposition 10.2.6, G has a subgraph H that (1) contains every vertex of G, (2) is connected, (3) has the same number of edges as vertices, and (4) is such that every vertex has degree 2. Suppose such a subgraph H exists. In other words, suppose there is a connected subgraph H of G such that H has five vertices (a, b, c, d, e) and five edges and such that every vertex of H has degree 2. Since the degree of b in G is 4 and every vertex of H has degree 2, two edges incident on b must be removed from G to create H . Edge {a, b} cannot be removed because if it were, vertex a would have degree less than 2 in H . Similar reasoning shows that edges {e, b}, {b, a}, and {b, d} cannot be removed either. It follows that the degree of b in H must be 4, which contradicts the condition that every vertex in H has degree 2 in H . Hence no such subgraph H exists, and so G does not have a Hamiltonian circuit. ■

The next example illustrates a type of problem known as a traveling salesman prob- lem. It is a variation of the problem of finding a Hamiltonian circuit for a graph.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

656 Chapter 10 Graphs and Trees

Example 10.2.9 A Traveling Salesman Problem

Imagine that the drawing below is a map showing four cities and the distances in kilome- ters between them. Suppose that a salesman must travel to each city exactly once, starting and ending in city A. Which route from city to city will minimize the total distance that must be traveled?

B

DA

C

2535

40

30

30 50

Solution This problem can be solved by writing all possible Hamiltonian circuits starting and ending at A and calculating the total distance traveled for each.

Route Total Distance (In Kilometers)

ABC D A 30 + 30 + 25 + 40 = 125 AB DC A 30 + 35 + 25 + 50 = 140 AC B D A 50 + 30 + 35 + 40 = 155 AC DB A 140 [AB DC A backwards] ADBC A 155 [AC B D A backwards] ADC B A 125 [ABC D A backwards]

Thus either route ABC D A or ADC B A gives a minimum total distance of 125 kilometers. ■

The general traveling salesman problem involves finding a Hamiltonian circuit to minimize the total distance traveled for an arbitrary graph with n vertices in which each edge is marked with a distance. One way to solve the general problem is to use the method of Example 10.2.9: Write down all Hamiltonian circuits starting and ending at a particular vertex, compute the total distance for each, and pick one for which this total is minimal. However, even for medium-sized values of n this method is impractical. For a complete graph with 30 vertices, there would be (29!)/2 ∼= 4.42× 1030 Hamiltonian circuits starting and ending at a particular vertex to check. Even if each circuit could be found and its total distance computed in just one nanosecond, it would require approx- imately 1.4× 1014 years to finish the computation. At present, there is no known algo- rithm for solving the general traveling salesman problem that is more efficient. However, there are efficient algorithms that find “pretty good” solutions—that is, circuits that, while not necessarily having the least possible total distances, have smaller total distances than most other Hamiltonian circuits.

Test Yourself 1. Let G be a graph and let v and w be vertices in G.

(a) A walk from v to w is _____.

(b) A trail from v to w is _____.

(c) A path from v to w is _____.

(d) A closed walk is _____.

(e) A circuit is _____.

(f) A simple circuit is _____.

(g) A trivial walk is _____.

(h) Vertices v and w are connected if, and only if, _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 657

2. A graph is connected if, and only if, _____.

3. Removing an edge from a circuit in a graph does not _____.

4. An Euler circuit in a graph is _____.

5. A graph has an Euler circuit if, and only if, _____.

6. Given vertices v and w in a graph, there is an Euler path from v to w if, and only if, _____.

7. A Hamiltonian circuit in a graph is _____.

8. If a graph G has a Hamiltonian circuit, then G has a subgraph H with the following properties: _____, _____, _____, and _____.

9. A traveling salesman problem involves finding a _____ that minimizes the total distance traveled for a graph in which each edge is marked with a distance.

Exercise Set 10.2 1. In the graph below, determine whether the following walks

are trails, paths, closed walks, circuits, simple circuits, or just walks. a. v0e1v1e10v5e9v2e2v1 b. v4e7v2e9v5e10v1e3v2e9v5 c. v2 d. v5v2v3v4v4v5 e. v2v3v4v5v2v4v3v2 f. e5e8e10e3

v1

v2

v3

v5 v4

v0

e2 e3

e9 e7

e5

e6

e4e1

e10

e8

2. In the graph below, determine whether the following walks are trails, paths, closed walks, circuits, simple circuits, or just walks. a. v1e2v2e3v3e4v4e5v2e2v1e1v0 b. v2v3v4v5v2 c. v4v2v3v4v5v2v4 d. v2v1v5v2v3v4v2 e. v0v5v2v3v4v2v1 f. v5v4v2v1

v1

v2

v3

v5 v4

v0 e2

e7 e8e10

e5 e4

e3e1

e9

e6

3. Let G be the graph

v1 v2

e2

e1

and consider the walk v1e1v2e2v1. a. Can this walk be written unambiguously as v1v2v1?

Why? b. Can this walk be written unambiguously as e1e2? Why?

4. Consider the following graph.

v1 v2 v3 v4

e2 e1 e5e3

e4

a. How many paths are there from v1 to v4? b. How many trails are there from v1 to v4? c. How many walks are there from v1 to v4?

5. Consider the following graph.

e2

e1

e5 e3

e4

ca b

a. How many paths are there from a to c? b. How many trails are there from a to c? c. How many walks are there from a to c?

6. An edge whose removal disconnects the graph of which it is a part is called a bridge. Find all bridges for each of the following graphs.

a. v1

v5

v2

v4

v3

b. v0 v1 v2

v7 v8

v3 v4

v5v6

c. v1

v9

v2 v3 v4

v5 v6 v7

v8

v10

7. Given any positive integer n, (a) find a connected graph with n edges such that removal of just one edge discon- nects the graph; (b) find a connected graph with n edges that cannot be disconnected by the removal of any single edge.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

658 Chapter 10 Graphs and Trees

8. Find the number of connected components for each of the following graphs.

a.

a c hf

b e

g

d

b.

u

z

w

x

v

y

c.

a

j h

e

db c

i

g

f

d.

v1 v3

v2

v4

9. Each of (a)–(c) describes a graph. In each case answer yes, no, or not necessarily to this question: Does the graph have an Euler circuit? Justify your answers. a. G is a connected graph with five vertices of degrees 2,

2, 3, 3, and 4. b. G is a connected graph with five vertices of degrees 2,

2, 4, 4, and 6. c. G is a graph with five vertices of degrees 2, 2, 4, 4,

and 6.

10. The solution for Example 10.2.5 shows a graph for which every vertex has even degree but which does not have an Euler circuit. Give another example of a graph satisfying these properties.

11. Is it possible for a citizen of Königsberg to make a tour of the city and cross each bridge exactly twice? (See Figure 10.2.1.) Why?

Determine which of the graphs in 12–17 have Euler circuits. If the graph does not have an Euler circuit, explain why not. If it does have an Euler circuit, describe one.

12.

v1

v2

v4

v5 v3

e2 e1

e8

e4

e5 e7

e3

e6

13.

v1

v0v9

v8

v6v7

v4

v2

v5 v3

14. a

b

c f

de

i h

g

15.

r z y x

s w

vt

u

16. v1

v4

v0

v5

v2

v3

17.

E

C

A

F

D

B

18. Is it possible to take a walk around the city whose map is shown below, starting and ending at the same point and crossing each bridge exactly once? If so, how can this be done?

B

E

A C

D

River

For each of the graphs in 19–21, determine whether there is an Euler path from u to w. If there is, find such a path.

19.

v1v7

v4

v0

v5

v2 v6

w

u

v3

20.

a u f

h w

e

b c d

g

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.2 Trails, Paths, and Circuits 659

21.

v1

v2v3

v4

v0v7

v6

w

v5

u

22. The following is a floor plan of a house. Is it possible to enter the house in room A, travel through every interior doorway of the house exactly once, and exit out of room E? If so, how can this be done?

A B

G

F

C

D

E

H

Find Hamiltonian circuits for each of the graphs in 23 and 24.

23. v0

v1

v3

v6

v5

v7

v2

v4

24. a

l

k

j

h b

c

d

g

f

i

e

Show that none of the graphs in 25–27 has a Hamiltonian cir- cuit.

25.H

a e

b d

g f

c

26. a

j h

c

b

i f

e

d

g

27.

A

F

G

C

D

E

B

In 28–31 find Hamiltonian circuits for those graphs that have them. Explain why the other graphs do not.

28.H a b

f g

e d c

29.

a

g

c

e

b

d

f

30.

v0

v4

v7

v2

v1

v3

v6v5

31.

a c

b

e f

h g

d

32.H Give two examples of graphs that have Euler circuits but not Hamiltonian circuits.

33.H Give two examples of graphs that have Hamiltonian circuits but not Euler circuits.

34.H Give two examples of graphs that have circuits that are both Euler circuits and Hamiltonian circuits.

35.H Give two examples of graphs that have Euler circuits and Hamiltonian circuits that are not the same.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

660 Chapter 10 Graphs and Trees

36. A traveler in Europe wants to visit each of the cities shown on the map exactly once, starting and ending in Brussels. The distance (in kilometers) between each pair of cities is given in the table. Find a Hamiltonian circuit that mini- mizes the total distance traveled. (Use the map to narrow the possible circuits down to just a few. Then use the table to find the total distance for each of those.)

Berlin

Brussels Düsseldorf Luxembourg Munich Paris

783 564 764 585

1,057

223 219 771 308

224 613 497

517 375 832

Brussels Düsseldorf

Luxembourg

Berlin Brussels Düsseldorf Luxembourg Munich

Munich

Paris

37. a. Prove that if a walk in a graph contains a repeated edge, then the walk contains a repeated vertex.

b. Explain how it follows from part (a) that any walk with no repeated vertex has no repeated edge.

38. Prove Lemma 10.2.1(a): If G is a connected graph, then any two distinct vertices of G can be connected by a path.

39. Prove Lemma 10.2.1(b): If vertices v and w are part of a circuit in a graph G and one edge is removed from the circuit, then there still exists a trail from v to w in G.

40. Draw a picture to illustrate Lemma 10.2.1(c): If a graph G is connected and G contains a circuit, then an edge of the circuit can be removed without disconnecting G.

41. Prove that if there is a trail in a graph G from a vertex v to a vertex w, then there is a trail from w to v.

42.H If a graph contains a circuit that starts and ends at a vertex v, does the graph contain a simple circuit that starts and ends at v? Why?

43. Prove that if there is a circuit in a graph that starts and ends at a vertex v and if w is another vertex in the circuit, then there is a circuit in the graph that starts and ends at w.

44. Let G be a connected graph, and let C be any circuit in G that does not contain every vertex of C . Let G ′ be the subgraph obtained by removing all the edges of C from G and also any vertices that become isolated when the edges of C are removed. Prove that there exists a vertex v such that v is in both C and G ′.

45. Prove that any graph with an Euler circuit is connected.

46. Prove Corollary 10.2.5.

47. For what values of n does the complete graph Kn with n vertices have (a) an Euler circuit? (b) a Hamiltonian circuit? Justify your answers.

48.✶ For what values of m and n does the complete bipartite graph on (m, n) vertices have (a) an Euler circuit? (b) a Hamiltonian circuit? Justify your answers.

49.✶ What is the maximum number of edges a simple dis- connected graph with n vertices can have? Prove your answer.

50.✶ Show that a graph is bipartite if, and only if, it does not have a circuit with an odd number of edges. (See exercise 37 of Section 10.1 for the definition of bipartite graph.)

Answers for Test Yourself 1. (a) a finite alternating sequence of adjacent vertices and edges of G (b) a walk that does not contain a repeated edge (c) a trail that does not contain a repeated vertex (d) a walk that starts and ends at the same vertex (e) a closed walk that contains at least one edge and does not contain a repeated edge (f) a circuit that does not have any repeated vertex other than the first and the last (g) a walk consisting of a single vertex and no edge (h) there is a walk from v to w 2. given any two vertices in the graph, there is a walk from one to the other 3. disconnect the graph 4. a circuit that contains every vertex and every edge of the graph 5. the graph is connected, and every vertex has positive, even degree 6. the graph is connected, v and w have odd degree, and all other vertices have positive even degree 7. a simple circuit that includes every vertex of the graph 8. H contains every vertex of G; H is connected; H has the same number of edges as vertices; every vertex of H has degree 2 9. Hamiltonian circuit

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 661

10.3 Matrix Representations of Graphs Order and simplification are the first steps toward the mastery of a subject. — Thomas Mann, The Magic Mountain, 1924

How can graphs be represented inside a computer? It happens that all the information needed to specify a graph can be conveyed by a structure called a matrix, and matrices (matrices is the plural of matrix) are easy to represent inside computers. This section contains some basic definitions about matrices and matrix operations, a description of the relation between graphs and matrices, and some applications.

Matrices Matrices are two-dimensional analogues of sequences. They are also called two- dimensional arrays.

• Definition An m × n (read “m by n”) matrix A over a set S is a rectangular array of elements of S arranged into m rows and n columns:

A =

⎢⎢⎢⎢⎢⎢⎢⎢⎣

a11 a12 . . . a1 j . . . a1n a21 a22 . . . a2 j . . . a2n ...

... ...

...

ai1 ai2 . . . ai j . . . ain ...

... ...

...

am1 am2 . . . amj . . . amn

⎥⎥⎥⎥⎥⎥⎥⎥⎦ ← i th row of A

↑ j th column of A

We write A = (ai j ).

The ith row of A is

[ai1 ai2 · · · ain]

and the j th column of A is ⎡

⎢⎢⎢⎣

a1 j a2 j ...

amj

⎥⎥⎥⎦ .

The entry ai j in the i th row and j th column of A is called the i j th entry of A. An m × n matrix is said to have size m × n. If A and B are matrices, then A = B if, and only if, A and B have the same size and the corresponding entries of A and B are all equal; that is,

ai j = bi j for all i = 1, 2, . . . , m and j = 1, 2 . . . , n.

A matrix for which the numbers of rows and columns are equal is called a square matrix. If A is a square matrix of size n × n, then the main diagonal of A consists of all the entries a11, a22, . . . , ann :

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

662 Chapter 10 Graphs and Trees

⎢⎢⎢⎢⎢⎢⎢⎢⎣

a11 a12 . . . a1i . . . a1n a21 a22 . . . a2i . . . a2n ...

... ...

...

ai1 ai2 . . . aii . . . ain ...

... ...

...

an1 an2 . . . ani . . . ann

⎥⎥⎥⎥⎥⎥⎥⎥⎦

main diagonal of A

Example 10.3.1 Matrix Terminology

The following is a 3× 3 matrix over the set of integers. ⎡

⎣ 1 0 −3 4 −1 5 −2 2 0

a. What is the entry in row 2, column 3?

b. What is the second column of A?

c. What are the entries in the main diagonal of A? Solution

a. 5 b.

⎣ 0

−1 2

⎦ c. 1,−1, and 0 ■

Matrices and Directed Graphs Consider the directed graph shown in Figure 10.3.1. This graph can be represented by the matrix A = (ai j ) for which ai j = the number of arrows from vi to v j , for all i = 1, 2, 3 and j = 1, 2, 3. Thus a11 = 1 because there is one arrow from v1 to v1, a12 = 0 because there is no arrow from v1 to v2, a23 = 2 because there are two arrows from v2 to v3, and so forth. A is called the adjacency matrix of the directed graph. For convenient reference, the rows and columns of A are often labeled with the vertices of the graph G.

v1

v3

v2

e2

e4 e5e6

e3e1

A =

v1 v2 v3

v1 1 0 0 v2 1 1 2 v3 1 0 0

Directed Graph G Adjacency Matrix

)b()a(

Figure 10.3.1 A Directed Graph and Its Adjacency Matrix

• Definition Let G be a directed graph with ordered vertices v1, v2, . . . , vn . The adjacency matrix of G is the n × n matrix A = (aij) over the set of nonnegative integers such that

ai j = the number of arrows from vi to v j for all i, j = 1, 2, . . . , n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 663

Note that nonzero entries along the main diagonal of an adjacency matrix indicate the presence of loops, and entries larger than 1 correspond to parallel edges. Moreover, if the vertices of a directed graph are reordered, then the entries in the rows and columns of the corresponding adjacency matrix are moved around.

Example 10.3.2 The Adjacency Matrix of a Graph

The two directed graphs shown below differ only in the ordering of their vertices. Find their adjacency matrices.

v1

v3

v2e2

e4

e5

e1

e3

v3

v2

v1e2

e4

e5

e1

e3

(a) (b)

Solution Since both graphs have three vertices, both adjacency matrices are 3× 3 matrices. For (a), all entries in the first row are 0 since there are no arrows from v1 to any other vertex. For (b), the first two entries in the first row are 1 and the third entry is 0 since from v1 there are single arrows to v1 and to v2 and no arrows to v3. Continuing the analysis in this way, you obtain the following two adjacency matrices:

v1 v2 v3

v1 0 0 0 v2 0 1 1 v3 2 1 0

v1 v2 v3

v1 1 1 0 v2 1 0 2 v3 0 0 0

(a) (b) ■

If you are given a square matrix with nonnegative integer entries, you can construct a directed graph with that matrix as its adjacency matrix. However, the matrix does not tell you how to label the edges, so the directed graph is not uniquely determined.

Example 10.3.3 Obtaining a Directed Graph from a Matrix

Let

A =

⎢⎢⎣

0 1 1 0 1 1 0 2 0 0 1 1 2 1 0 0

⎥⎥⎦ .

Draw a directed graph that has A as its adjacency matrix.

Solution Let G be the graph corresponding to A, and let v1, v2, v3, v4 be the vertices of G. Label A across the top and down the left side with these vertex names, as shown below.

A =

⎢⎢⎣

v1 v2 v3 v4

v1 0 1 1 0 v2 1 1 0 2 v3 0 0 1 1 v4 2 1 0 0

⎥⎥⎦

Then, for instance, the 2 in the fourth row and the first column means that there are two arrows from v4 to v1. The 0 in the first row and the fourth column means that there is no arrow from v1 to v4. A corresponding directed graph is shown on the next page (without edge labels because the matrix does not determine those).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

664 Chapter 10 Graphs and Trees

v1

v2

v3

v4 ■

Matrices and Undirected Graphs Once you know how to associate a matrix with a directed graph, the definition of the matrix corresponding to an undirected graph should seem natural to you. As before, you must order the vertices of the graph, but in this case you simply set the i j th entry of the adjacency matrix equal to the number of edges connecting the i th and j th vertices of the graph.

• Definition Let G be an undirected graph with ordered vertices v1, v2, . . . , vn . The adjacency matrix of G is the n × n matrix A = (ai j ) over the set of nonnegative integers such that

ai j = the number of edges connecting vi and v j for all i, j = 1, 2, . . . , n.

Example 10.3.4 Finding the Adjacency Matrix of a Graph

Find the adjacency matrix for the graph G shown below.

v1 v2

v3 v4

e3

e4

e6

e1 e5

e2

Solution

A =

⎢⎢⎣

v1 v2 v3 v4

v1 0 1 0 1 v2 1 1 2 1 v3 0 2 0 0 v4 1 1 0 1

⎥⎥⎦ ■

Note that if the matrix A = (ai j ) in Example 10.3.4 is flipped across its main diagonal, it looks the same: ai j = a ji , for i, j = 1, 2, . . . , n. Such a matrix is said to be symmetric.

• Definition An n × n square matrix A = (ai j ) is called symmetric if, and only if, for all i, j = 1, 2, . . . , n,

ai j = a ji .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 665

Example 10.3.5 Symmetric Matrices

Which of the following matrices are symmetric?

a. [

1 0 1 2

] b.

⎣ 0 1 2 1 1 0 2 0 3

⎦ c. [

2 0 0 0 1 0

]

Solution Only (b) is symmetric. In (a) the entry in the first row and the second column differs from the entry in the second row and the first column; the matrix in (c) is not even square. ■

It is easy to see that the matrix of any undirected graph is symmetric since it is always the case that the number of edges joining vi and v j equals the number of edges joining v j and vi for all i, j = 1, 2, . . . , n.

Matrices and Connected Components Consider a graph G, as shown below, that consists of several connected components.

v1

v2

v4 v6

v7

v5

v3

e2

e3 e7

e4

e5

e6

e8

e1

The adjacency matrix of G is

A =

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣

1 0 1 ....................

0 0 ....................

0 0 0 0 2 0 0 0 0

. . . . . . . . . . . . . . . . . . . . . .1 2 0 0 0 0 0

0 0 0 0 1 0 0

. . . . . . . . . . . . . . . . . . . . . .0 0 0 1 1 0 0

0 0 0 0 0 0 2 0 0 0 0 0 2 0

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎦

.

As you can see, A consists of square matrix blocks (of different sizes) down its diagonal and blocks of 0’s everywhere else. The reason is that vertices in each connected com- ponent share no edges with vertices in other connected components. For instance, since v1, v2, and v3 share no edges with v4, v5, v6, or v7, all entries in the top three rows to the right of the third column are 0 and all entries in the left three columns below the third row are also 0. Sometimes matrices whose entries are all 0’s are themselves denoted 0. If this convention is followed here, A is written as

A =

⎢⎢⎢⎢⎢⎢⎢⎢⎢⎣

1 0 1 0 0 2 1 2 0

✎ ✍

☞ ✌

✎ ✍

☞ ✌✎✍ ☞✌0 11 1 ✎✍☞✌✎✍ ☞✌✎✍☞✌0 22 0

⎥⎥⎥⎥⎥⎥⎥⎥⎥⎦

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

666 Chapter 10 Graphs and Trees

The previous reasoning can be generalized to prove the following theorem:

Theorem 10.3.1

Let G be a graph with connected components G1, G2, . . . , Gk . If there are ni vertices in each connected component Gi and these vertices are numbered consecutively, then the adjacency matrix of G has the form

⎢⎢⎢⎢⎢⎣

A1 O O · · · O O O A2 O · · · O O O O A3 · · · O O ...

... ...

... ...

O O O · · · O Ak

⎥⎥⎥⎥⎥⎦

where each Ai is the ni × ni adjacency matrix of Gi , for all i = 1, 2, . . . , k, and the O’s represent matrices whose entries are all 0.

Matrix Multiplication

Matrix multiplication is an enormously useful operation that arises in many contexts, including the investigation of walks in graphs. Although matrix multiplication can be defined in quite abstract settings, the definition for matrices whose entries are real num- bers will be sufficient for our applications. The product of two matrices is built up of scalar or dot products of their individual rows and columns.

• Definition Suppose that all entries in matrices A and B are real numbers. If the number of ele- ments, n, in the i th row of A equals the number of elements in the j th column of B, then the scalar product or dot product of the i th row of A and the j th column of B is the real number obtained as follows:

[ai1 ai2 · · · ain]

⎢⎢⎢⎣

b1 j b2 j ...

bnj

⎥⎥⎥⎦ = ai1b1 j + ai2b2 j + · · · + ainbnj .

Example 10.3.6 Multiplying a Row and a Column

[3 0 − 1 2]

⎢⎢⎣

−1 2 3 0

⎥⎥⎦ = 3 ·(−1) + 0 ·2 + (−1) ·3 + 2 ·0

= −3 + 0− 3 + 0 = −6 ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 667

More generally, if A and B are matrices whose entries are real numbers and if A and B have compatible sizes in the sense that the number of columns of A equals the number of rows of B, then the product AB is defined. It is the matrix whose i j th entry is the scalar product of the i th row of A times the j th column of B, for all possible values of i and j .

• Definition Let A = (ai j ) be an m × k matrix and B = (bi j ) a k × n matrix with real entries. The (matrix) product of A times B, denoted AB, is that matrix (ci j ) defined as follows:⎡

⎢⎢⎢⎢⎢⎢⎢⎢⎣

a11 a12 · · · a1k a21 a22 · · · a2k ...

... ...

ai1 ai2 · · · aik ...

... ...

am1 am2 · · · amk

⎥⎥⎥⎥⎥⎥⎥⎥⎦

⎢⎢⎢⎢⎢⎢⎢⎢⎣

b11 b12 · · · b1 j · · · b1n b21 b22 · · · b2 j · · · b2n

· · · · · · · · ·

bk1 bk2 · · · bk j · · · bkn

⎥⎥⎥⎥⎥⎥⎥⎥⎦

=

⎢⎢⎢⎢⎢⎢⎢⎢⎣

c11 c12 · · · c1 j · · · c1n c21 c22 · · · c2 j · · · c2n ...

... ...

...

ci1 ci2 · · · ci j · · · cin ...

... ...

...

cm1 cm2 · · · cmj · · · cmn

⎥⎥⎥⎥⎥⎥⎥⎥⎦

where

ci j = ai1b1 j + ai2b2 j + · · · + aikbk j = k∑

r=1 air br j ,

for all i = 1, 2, . . . , m and j = 1, 2, . . . , n.

Example 10.3.7 Computing a Matrix Product

Let A = [

2 0 3 −1 1 0

] and B =

[ 4 3 2 2 −2 −1

] . Compute AB.

Solution A has size 2× 3 and B has size 3× 2, so the number of columns of A equals the number of rows of B and the matrix product of A and B can be computed. Then

[ 2 0 3 −1 1 0

]⎡

⎣ 4 3 2 2 −2 −1

⎦ = [

c11 c12 c21 c22

] ,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

668 Chapter 10 Graphs and Trees

where

c11 = 2 ·4 + 0 ·2 + 3 ·(−2) = 2 [ ✞✝ ☎✆2 0 3 −1 1 0

]⎡

✎ ✍

☞ ✌

4 3 2 2

−2 −1

c12 = 2 ·3 + 0 ·2 + 3 ·(−1) = 3 [ ✞✝ ☎✆2 0 3 −1 1 0

]⎡

⎣ 4

✎ ✍

☞ ✌

3 2 2

−2 −1

c21 = (−1) ·4 + 1 ·2 + 0 ·(−2) = 2 [

2 0 3✞✝ ☎✆− 1 1 0 ]⎡

✎ ✍

☞ ✌

4 3 2 2

−2 −1

c22 = (−1) ·3 + 0 ·2 + 3 ·(−1) = −1 [

2 0 3✞✝ ☎✆− 1 1 0 ]⎡

⎣ 4

✎ ✍

☞ ✌

3 2 2 −2 −1

⎦ .

Hence

AB = [

2 3 −2 −1

] . ■

Matrix multiplication is both similar to and different from multiplication of real num- bers. One difference is that although the product of any two numbers can be formed, only matrices with compatible sizes can be multiplied. Also, multiplication of real numbers is commutative (for all real numbers a and b, ab = ba), whereas matrix multiplication is not. For instance,

[ 1 1 0 1

] [ 0 1 0 1

] = [

0 2 0 1

] , but

[ 0 1 0 1

] [ 1 1 0 1

] = [

0 1 0 1

] .

On the other hand, both real number and matrix multiplications are associative ((ab)c = a(bc), for all elements a, b, and c for which the products are defined). This is proved in Example 10.3.8 for products of 2× 2 matrices. Additional exploration of matrix multi- plication is offered in the exercises.

Example 10.3.8 Associativity of Matrix Multiplication for 2 × 2 Matrices Prove that if A, B, and C are 2× 2 matrices over the set of real numbers, then (AB)C = A(BC).

Solution Suppose A = (ai j ), B = (bi j ), and C = (ci j ) are particular but arbitrarily chosen 2× 2 matrices with real entries. Since the numbers of rows and columns are all the same, AB, BC, (AB)C, and A(BC) are defined. Let AB = (di j ) and BC = (ei j ). Then for all integers i = 1, 2 and j = 1, 2,

the i j th entry of (AB)C = 2∑

r=1 dir cr j

by definition of the product of AB and C

= di1c1 j + di2c2 j by definition of %

= (

2∑

r=1 air br1

)

c1 j + (

2∑

r=1 air br2

)

c2 j by definition of the product of A and B

= (ai1b11 + ai2b21)c1 j + (ai1b12 + ai2b22)c2 j

by definition of %

= ai1b11c1 j + ai2b21c1 j + ai1b12c2 j + ai2b22c2 j .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 669

Similarly, the i j th entry of A(BC) is

(A(BC))i j = 2∑

r=1 air er j

= ai1e1 j + ai2e2 j

= ai1 (

2∑

r=1 b1r cr j

)

+ ai2 (

2∑

r=1 b2r cr j

)

= ai1(b11c1 j + b12c2 j ) + ai2(b21c1 j + b22c2 j ) = ai1b11c1 j + ai1b12c2 j + ai2b21c1 j + ai2b22c2 j = ai1b11c1 j + ai2b21c1 j + ai1b12c2 j + ai2b22c2 j .

Comparing the results of the two computations shows that for all i and j ,

the i j th entry of (AB)C = the i j th entry of A(BC). Since all corresponding entries are equal, (AB)C = A(BC), as was to be shown. ■

As far as multiplicative identities are concerned, there are both similarities and differ- ences between real numbers and matrices. You know that the number 1 acts as a multi- plicative identity for products of real numbers. It turns out that there are certain matrices, called identity matrices, that act as multiplicative identities for certain matrix products. For instance, mentally perform the following matrix multiplications to check that for any real numbers a, b, c, d, e, f, g, h and i ,

[ 1 0 0 1

] [ a b c d e f

] = [

a b c d e f

]

and ⎡

⎣ a b c d e f g h i

⎣ 1 0 0 0 1 0 0 0 1

⎣ a b c d e f g h i

⎦ .

These computations show that [

1 0 0 1

] acts as an identity on the left side for multiplication

with 2× 3 matrices and that [

1 0 0 0 1 0 0 0 1

] acts as an identity on the right side for multiplica-

tion with 3× 3 matrices. Note that [

1 0 0 1

] cannot act as an identity on the right side for

multiplication with 2× 3 matrices because the sizes are not compatible. • Definition For each positive integer n, the n × n identity matrix, denoted In = (δi j ) or just I (if the size of the matrix is obvious from context), is the n × n matrix in which all the entries in the main diagonal are 1’s and all other entries are 0’s. In other words,

δi j = {

1 if i = j 0 if i ̸= j , for all i, j = 1, 2, . . . , n.

The German mathematician Leopold Kronecker introduced the symbol δi j to make matrix

D av

id Eu

ge ne

Sm ith

Co lle

ct io

n, R

ar e

B oo

k an

d M

an us

cr ip

t Li

br ar

y, Co

lu m

bi a

U ni

ve rs

ity

Leopold Kronecker (1823–1891) computations more convenient. In his honor, this symbol is called the Kronecker delta.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

670 Chapter 10 Graphs and Trees

Example 10.3.9 An Identity Matrix Acts as an Identity

Prove that if A is any m × n matrix and I is the n × n identity matrix, then AI = A. (In exercise 14 at the end of this section you are asked to show that if I is the m × m identity matrix, then IA = A.)

Proof:

Let A be any n × n matrix and let ai j be the i j th entry of A for all integers i = 1, 2, . . . , m and j = 1, 2, . . . , n. Consider the product AI, where I is the n × n identity matrix. Observe that

⎢⎢⎢⎣

a11 a12 · · · a1n a21 a22 · · · 22n ...

... ...

am1 am2 · · · amn

⎥⎥⎥⎦

⎢⎢⎢⎣

1 0 · · · 0 0 1 · · · 0 ...

... ...

0 0 · · · 1

⎥⎥⎥⎦ =

⎢⎢⎢⎣

a11 a12 · · · a1n a21 a22 · · · a2n ...

... ...

am1 am2 · · · amn

⎥⎥⎥⎦

because

the i j th entry of AI = n∑

r=1 airδr j by definition of 1

= ai1δ1 j + ai2δ2 j + · · · by definition of % + ai jδ j j + · · · + ainδnj

= ai jδ j j since δk j = 0 whenever k ̸= j and δ j j = 1 = ai j = the i j th entry of A.

Thus AI = A, as was to be shown. ■

There are also similarities and differences between real numbers and matrices with respect to the computation of powers. Any number can be raised to a nonnegative integer power, but a matrix can be multiplied by itself only if it has the same number of rows as columns. As for real numbers, however, the definition of matrix powers is recursive. Just as any number to the zero power is defined to be 1, so any n × n matrix to the zero power is defined to be the n × n identity matrix. The nth power of an n × n matrix A is defined to be the product of A with its (n − 1)st power.

• Definition For any n × n matrix A, the powers of A are defined as follows:

A0 = I where I is the n × n identity matrix An = AAn−1 for all integers n ≥ 1

Example 10.3.10 Powers of a Matrix

Let A = [

1 2 2 0

] . Compute A0, A1, A2, and A3.

Solution A0 = the 2× 2 identity matrix = [

1 0 0 1

]

A1 = AA0 = AI = A

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 671

A2 = AA1 = AA = [

1 2 2 0

] [ 1 2 2 0

] = [

5 2 2 4

]

A3 = AA2 = [

1 2 2 0

] [ 5 2 2 4

] = [

9 10 10 4

] ■

Counting Walks of Length N A walk in a graph consists of an alternating sequence of vertices and edges. If repeated edges are counted each time they occur, then the number of edges in the sequence is called the length of the walk. For instance, the walk v2e3v3e4v2e2v2e3v3 has length 4 (counting e3 twice). Consider the following graph G:

v1

v2

v3

e2

e1 e4

e3

How many distinct walks of length 2 connect v2 and v2? Your can list the possibilities systematically as follows: From v1, the first edge of the walk must go to some vertex of G: v1, v2, or v3. There is one walk of length 2 from v2 to v2 that starts by going from v2 to v1:

v2e1v1e1v2.

There is one walk of length 2 from v2 to v2 that starts by going from v2 to v2:

v2e2v2e2v2.

And there are four walks of length 2 from v2 to v2 that start by going from v2 to v3:

v2e3v3e4v2,

v2e4v3e3v2,

v2e3v3e3v2,

v2e4v3e4v2.

Thus the answer is six. The general question of finding the number of walks that have a given length and con-

nect two particular vertices of a graph can easily be answered using matrix multiplication. Consider the adjacency matrix A of the graph G on the previous page:

A =

v1 v2 v3

v1 0 1 0 v2 1 1 2 v3 0 2 0

⎦.

Compute A2 as follows: ⎡

⎣ 0 1 0 1 1 2 0 2 0

⎣ 0 1 0 1 1 2 0 2 0

⎦ =

⎣ 1 1 2 1 6 2 2 2 4

⎦ .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

672 Chapter 10 Graphs and Trees

Note that the entry in the second row and the second column is 6, which equals the number of walks of length 2 from v2 to v2. This is no accident! To compute a22, you multiply the second row of A times the second column of A to obtain a sum of three terms:

[ 1 1 2

] ⎡

⎣ 1 1 2

⎦ = 1 ·1 + 1 ·1 + 2 ·2.

Observe that

[ the first term of this sum

] =

⎣ number of edges from v2 to v1

⎦ .

⎣ number of edges from v1 to v2

⎦ =

⎣ number of pairs of edges from v2 to v1 and v1 to v2

⎦ .

Now consider the i th term of this sum, for each i = 1, 2, and 3. It equals the number of edges from v2 to vi times the number of edges from vi to v2. By the multiplication rule this equals the number of pairs of edges from v2 to vi and from vi back to v2. But this equals the number of walks of length 2 that start and end at v2 and pass through vi . Since this analysis holds for each term of the sum for i = 1, 2, and 3, the sum as a whole equals the total number of walks of length 2 that start and end at v2:

1 ·1 + 1 ·1 + 2 ·2 = 1 + 1 + 4 = 6.

More generally, if A is the adjacency matrix of a graph G, the i j th entry of A2 equals the number of walks of length 2 connecting the i th vertex to the j th vertex of G. Even more generally, if n is any positive integer, the i j th entry of An equals the number of walks of length n connecting the i th and the j th vertices of G.

Theorem 10.3.2

If G is a graph with vertices v1, v2, . . . , vm and A is the adjacency matrix of G, then for each positive integer n and for all integers i, j = 1, 2, . . . , m,

the i j th entry of An = the number of walks of length n from vi to v j .

Proof:

Suppose G is a graph with vertices v1, v2, . . . , vm and A is the adjacency matrix of G. Let P(n) be the sentence

For all integers i, j = 1, 2, . . . , m, ← P(n) the i j th entry of An = the number of walks of length n from vi to v j .

We will use mathematical induction to show that P(n) is true for all integers n ≥ 1. Show that P(1) is true:

The i j th entry of A1 = the i j th entry of A because A1 = A = the number of edges by definition of adjacency matrix

connecting vi to v j = the number of walks of

length 1 from vi to v j because a walk of length 1 contains a single edge.

Show that for all integers k with k ≥ 1, if P(k) is true then P(k + 1) is true:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.3 Matrix Representations of Graphs 673

Let k be any integer with k ≥ 1, and suppose that For all integers i, j = 1, 2, . . . , m, ← P(k) the i j th entry of Ak = the number of walks of length k from vi to v j . inductive

hypothesis We must show that

For all integers i, j = 1, 2, . . . , m, ← P(k + 1) the i j th entry of Ak+1 = the number of walks of length k + 1 from vi to v j .

Let A = (ai j ) and Ak = (bi j ). Since Ak+1 = AAk , the i j th entry of Ak+1 is obtained by multiplying the i th row of A by the j th column of Ak :

the i j th entry of Ak+1 = ai1b1 j + ai2b2 j + · · · + aimbmj 10.3.1 for all i, j = 1, 2, . . . , m. Now consider the individual terms of this sum: ai1 is the number of edges from vi to v1; and, by inductive hypothesis, b1 j is the number of walks of length k from v1 to v j . But any edge from vi to v1 can be joined with any walk of length k from v1 to v j to create a walk of length k + 1 from vi to v j with v1 as its second vertex. Thus, by the multiplication rule,

ai1b1 j = [

the number of walks of length k + 1 from vi to v j that have v1 as their second vertex

] .

More generally, for each integer r = 1, 2, . . . , m,

air br j = [

the number of walks of length k + 1 from vi to v j that have vr as their second vertex

] .

Since any walk of length k + 1 from vi to v j must have one of the vertices v1, v2, . . . , vm as its second vertex, the total number of walks of length k + 1 from vi to v j equals the sum in (10.3.1), which equals the i j th entry of Ak+1. Hence

the i j th entry of Ak+1 = the number of walks of length k + 1 from vi to v j [as was to be shown]. [Since both the basis step and the inductive step have been proved, the sentence P(n) is true for all integers n ≥ 1.]

Test Yourself 1. In the adjacency matrix for a directed graph, the entry in the

i th row and j th column is _____.

2. In the adjacency matrix for an undirected graph, the entry in the i th row and j th column is _____.

3. An n × n square matrix is called symmetric if, and only if, for all integers i and j from 1 to n, the entry in row _____ and column _____ equals the entry in row _____ and column _____.

4. The ijth entry in the product of two matrices A and B is obtained by multiplying row _____ of A by row _____ of B.

5. In an n × n identity matrix the entries on the main diagonal are all _____ and the off-diagonal entries are all _____.

6. If G is a graph with vertices v1, v2, . . . , vm and A is the adjacency matrix of G, then for each positive integer n and for all integers i and j with i, j = 1, 2, . . . , m, the ijth entry of An = _____.

Exercise Set 10.3 1. Find real numbers a, b, and c such that the following are

true.

a. [

a + b a − c c b − a

] = [

1 0 −1 3

] b. [

2a b + c c − a 2b − a

] = [

4 3 1 −2

]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

674 Chapter 10 Graphs and Trees

2. Find the adjacency matrices for the following directed graphs.

a. v1 v2

v3

e2

e1

e3

b.

v1

v2

v3v4

e2 e5

e6

e1

e3 e4

3. Find directed graphs that have the following adjacency matrices:

a.

⎢⎢⎣

1 0 1 2 0 0 1 0 0 2 1 1 0 1 1 0

⎥⎥⎦ b.

⎢⎢⎣

0 1 0 0 2 0 1 0 1 2 1 0 0 0 1 0

⎥⎥⎦

4. Find adjacency matrices for the following (undirected) graphs.

v1 v2

v3 v4

e2

e1 e4

e3 e5

b.

v1

v3

v2

v4

e1

e4

e3

e2

e5

e6

a.

c. K4, the complete graph on four vertices d. K2,3, the complete bipartite graph on (2, 3) vertices

5. Find graphs that have the following adjacency matrices.

a.

⎣ 1 0 1 0 1 2 1 2 0

⎦ b.

⎣ 0 2 0 2 1 0 0 0 1

6. The following are adjacency matrices for graphs. In each case determine whether the graph is connected by analyz- ing the matrix without drawing the graph.

a.

⎣ 0 1 1 1 1 0 1 0 0

⎦ b.

⎢⎢⎣

0 2 0 0 2 0 0 0 0 0 1 1 0 0 1 1

⎥⎥⎦

7. Suppose that for all positive integers i , all the entries in the i th row and i th column of the adjacency matrix of a graph are 0. What can you conclude about the graph?

8. Find each of the following products.

a. [ 2 −1]

[ 1 3

] b. [ 4 −1 7]

⎣ 1 2 0

9. Find each of the following products.

a. [

3 0 1 −2

] [ 1 −1 4 0 2 1

]

b. [

2 0 1 0 −1 0

]⎡

⎣ 1 3 5 −4

−2 2

c. [−1

2

] [ 2 3 ]

10. Let A = [

1 1 −1 0 −2 1

] , B = [−2 0

1 3

] , and

C =

⎣ 0 −2 3 1 1 0

⎦.

For each of the following, determine whether the indicated product exists, and compute it if it does. a. AB b. BA c. A2 d. BC e. CB f. B2 g. B3 h. C2 i. AC j. CA

11. Give an example different from that in the text to show that matrix multiplication is not commutative. That is, find 2× 2 matrices A and B such that AB and BA both exist but AB ̸= BA.

12. Let O denote the matrix [

0 0 0 0

] . Find 2× 2 matrices A and

B such that A ̸= O and B ̸= O, but AB = O.

13. Let O denote the matrix [

0 0 0 0

] . Find 2× 2 matrices A and

B such that A ̸= B, B ̸= O, and AB ̸= O, but BA = O. In 14–18 assume the entries of all matrices are real numbers.

14.H Prove that if I is the m × m identity matrix and A is any m × n matrix, then IA = A.

15. Prove that if A is an m × m symmetric matrix, then A2 is symmetric.

16. Prove that matrix multiplication is associative: If A, B, and C are any m × k, k × r , and r × n matrices, respectively, then (AB)C = A(BC).

17. Use mathematical induction and the result of exercise 16 to prove that if A is any m × m matrix, then AnA = AAn for all integers n ≥ 1.

18. Use mathematical induction to prove that if A is an m × m symmetric matrix, then for any integer n ≥ 1, An is also symmetric.

19. a. Let A =

⎣ 1 1 2 1 0 1 2 1 0

⎦. Find A2 and A3.

b. Let G be the graph with vertices v1, v2, and v3 and with A as its adjacency matrix. Use the answers to part (a) to find the number of walks of length 2 from v1 to v3 and the number of walks of length 3 from v1 to v3. Do not draw G to solve this problem.

c. Examine the calculations you performed in answering part (a) to find five walks of length 2 from v3 to v3. Then draw G and find the walks by visual inspection.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.4 Isomorphisms of Graphs 675

20. The following is an adjacency matrix for a graph:

⎢⎢⎣

v1 v2 v3 v4

v1 0 1 1 0 v2 1 0 2 1 v3 1 2 0 1 v4 0 1 1 1

⎥⎥⎦

Answer the following questions by examining the matrix and its powers only, not by drawing the graph: a. How many walks of length 2 are there from v2 to v3? b. How many walks of length 2 are there from v3 to v4? c. How many walks of length 3 are there from v1 to v4? d. How many walks of length 3 are there from v2 to v3?

21. Let A be the adjacent matrix for K3, the complete graph on three vertices. Use mathematical induction to prove that for each positive integer n, all the entries along the main diag- onal of An are equal to each other and all the entries that do not lie along the main diagonal are equal to each other.

22. a. Draw a graph that has ⎡

⎢⎢⎢⎢⎣

0 0 0 1 2 0 0 0 1 1 0 0 0 2 1 1 1 2 0 0 2 1 1 0 0

⎥⎥⎥⎥⎦

as its adjacency matrix. Is this graph bipartite? (For a definition of bipartite, see exercise 37 in Section 10.1.)

Definition: Given an m × n matrix A whose i j th entry is denoted ai j , the transpose of A is the matrix At whose i j th entry is a ji , for all i = 1, 2, . . . , m and j = 1, 2, . . . , n.

Note that the first row of A becomes the first column of At , the second row of A becomes the second column of At , and so forth. For instance,

if A = [

0 2 1 1 2 3

] , then At =

⎣ 0 1 2 2 1 3

⎦ .

b.H Show that a graph with n vertices is bipartite if, and only if, for some labeling of its vertices, its adjacency matrix has the form

[ O A At O

]

where A is a k × (n − k) matrix for some integer k such that 0 < k < n, the top left O represents a k × k matrix all of whose entries are 0, At is the transpose of A, and the bottom right O represents an (n − k)× (n − k) matrix all of whose entries are 0.

23. a. Let G be a graph with n vertices, and let v and w be dis- tinct vertices of G. Prove that if there is a walk from v to w, then there is a walk from v to w that has length less than or equal to n − 1.

b.H If A = (ai j ) and B = (bi j ) are any m × n matrices, the matrix A + B is the m × n matrix whose i j th entry is ai j + bi j for all i = 1, 2, . . . , m and j = 1, 2, . . . , n. Let G be a graph with n vertices where n > 1, and let A be the adjacency matrix of G. Prove that G is connected if, and only if, every entry of A + A2 + · · · + An−1 is positive.

Answers for Test Yourself 1. the number of arrows from vi (the i th vertex) to v j (the j th vertex) 2. the number of edges connecting vi (the i th vertex) and v j (the j th vertex) 3. i; j; j; i 4. i; j 5. 1; 0 6. the number of walks of length n from vi to v j

10.4 Isomorphisms of Graphs Thinking is a momentary dismissal of irrelevancies. — R. Buckminster Fuller, 1969

Recall from Example 10.1.3 that the two drawings shown in Figure 10.4.1 both repre- sent the same graph: Their vertex and edge sets are identical, and their edge-endpoint functions are the same. Call this graph G.

v1

v4 v3

v3

v5 v2

v4v5 v2

e2 e2

e5

e3

e4

e5 e1

e3

v1

e1

e4

Figure 10.4.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

676 Chapter 10 Graphs and Trees

Now consider the graph G ′ represented in Figure 10.4.2.

v1

v4 v5

v2 v3

e3e2

e4 e1

e5

Figure 10.4.2

Observe that G ′ is a different graph from G (for instance, in G the endpoints of e1 are v1 and v2, whereas in G ′ the endpoints of e1 are v1 and v3). Yet G ′ is certainly very similar to G. In fact, if the vertices and edges of G ′ are relabeled by the functions shown in Figure 10.4.3, then G ′ becomes the same as G.

v1

v2

v3

v4

v5

v1

v2

v3

v4

v5

e1

e2

e3

e4

e5

e1

e2

e3

e4

e5

Vertices of G

Vertices of G'

Edges of G

Edges of G'

Figure 10.4.3

Note that these relabeling functions are one-to-one and onto. Two graphs that are the same except for the labeling of their vertices and edges are

called isomorphic. The word isomorphism comes from the Greek, meaning “same form.” Isomorphic graphs are those that have essentially the same form.

• Definition Let G and G ′ be graphs with vertex sets V (G) and V (G ′) and edge sets E(G) and E(G ′), respectively. G is isomorphic to G′ if, and only if, there exist one-to-one correspondences g: V (G)→ V (G ′) and h: E(G)→ E(G ′) that preserve the edge- endpoint functions of G and G ′ in the sense that for all v ∈ V (G) and e ∈ E(G),

v is an endpoint of e ⇔ g(v) is an endpoint of h(e). 10.4.1

In words, G is isomorphic to G ′ if, and only if, the vertices and edges of G and G ′ can be matched up by one-to-one, onto functions such that the edges between corresponding vertices correspond to each other.

It is common in mathematics to identify objects that are isomorphic. For instance, if we are given a graph G with five vertices such that each pair of vertices is connected by an edge, then we may identify G with K5, saying that G is K5 rather than that G is isomorphic to K5.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.4 Isomorphisms of Graphs 677

Example 10.4.1 Showing That Two Graphs Are Isomorphic

Show that the following two graphs are isomorphic.

f1 f2 f5

f3

f7

f4

f6

w1

v1

v2

v5

v3

v4 w5

w3

w4

w2

e1

e4

e5

e7 e6 e2 e3

GG '

Solution To solve this problem, you must find functions g: V (G)→ V (G ′) and h: E(G)→ E(G ′) such that for all v ∈ V (G) and e ∈ E(G), v is an endpoint of e if, and only if, g(v) is an endpoint of h(e). Setting up such functions is partly a matter of trial and error and partly a matter of deduction. For instance, since e2 and e3 are parallel (have the same endpoints), h(e2) and h(e3) must be parallel also. So h(e2) = f1 and h(e3) = f2 or h(e2) = f2 and h(e3) = f1. Also, the endpoints of e2 and e3 must correspond to the end- points of f1 and f2, and so g(v3) = w1 and g(v4) = w5 or g(v3) = w5 and g(v4) = w1.

Similarly, since v1 is the endpoint of four distinct edges (e1, e7, e5, and e4), g(v1) must also be the endpoint of four distinct edges (because every edge incident on g(v1) is the image under h of an edge incident on v1 and h is one-to-one and onto). But the only vertex in G ′ that has four edges coming out of it is w2, and so g(v1) = w2. Now if g(v3) = w1, then since v1 and v3 are endpoints of e1 in G, g(v1) = w2 and g(v3) = w1 must be endpoints of h(e1) in G ′. This implies that h(e1) = f3.

By continuing in this way, possibly making some arbitrary choices as you go, you eventually can find functions g and h to define the isomorphism between G and G ′. One pair of functions (there are several) is the following:

v1

v2

v3

v4

v5

w1

w2

w3

w4

w5

V(G) V(G' ) g

e1 e2 e3 e4

e6 e7

e5

f1 f2 f3 f4

f6 f7

f5

E (G) E(G' ) h

It is not hard to show that graph isomorphism is an equivalence relation on a set of graphs; in other words, it is reflexive, symmetric, and transitive.

Theorem 10.4.1 Graph Isomorphism is an Equivalence Relation

Let S be a set of graphs and let R be the the relation of graph isomorphism on S. Then R is an equivalence relation on S.

Proof:

R is reflexive: Given any graph G in S, define a graph isomorphism from G to G by using the identity functions on the set of vertices and on the set of edges of G.

R is symmetric: Given any graphs G and G ′ in S such that G is isomorphic to G ′, we must show that G ′ is isomorphic to G.

continued on page 678

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

678 Chapter 10 Graphs and Trees

But this is true because if g and h are vertex and edge correspondences from G to G ′ that preserve the edge-endpoint functions, then g−1 and h−1 are vertex and edge correspondences from G ′ to G that preserve the edge-endpoint functions.

R is transitive: Given any graphs G, G ′, and G ′′ in S such that G is isomorphic to G ′ and G ′ is isomorphic to G ′′, we must show that G is isomorphic to G ′′.

But this follows from the fact that if g1 and h1 are vertex and edge correspon- dences from G to G ′ that preserve the edge-endpoint functions of G and G ′ and g2 and h2 are vertex and edge correspondences from G ′ to G ′′ that preserve the edge- endpoint functions of G ′ and G ′′, then g2◦g1 and h2◦h1 are vertex and edge corre- spondences from G to G ′′ that preserve the edge-endpoint functions of G and G ′′.

Note As a consequence of the symmetry property, you can simply say “G and G ′ are isomorphic” instead of “G is isomorphic to G ′” or “G ′ is isomorphic to G.”

Example 10.4.2 Finding Representatives of Isomorphism Classes

Find all nonisomorphic graphs that have two vertices and two edges. In other words, find a collection of representative graphs with two vertices and two edges such that every such graph is isomorphic to one in the collection.

Solution There are four nonisomorphic graphs that have two vertices and two edges. These can be drawn without vertex and edge labels because any two labelings give isomorphic graphs.

(a) (b) (c) (d)

To see that these four drawings show all the nonisomorphic graphs that have two vertices and two edges, first note whether one of the edges joins the two vertices or not. If it does, there are two possibilities: The other edge can also join the two vertices (as in (a)) or it can be a loop incident on one of them (as in (b)—it makes no difference which vertex is chosen to have the loop because interchanging the two vertex labels gives isomorphic graphs). If neither edge joins the two vertices, then both edges are loops. In this case, there are only two possibilities: Either both loops are incident on the same vertex (as in (c)) or the two loops are incident on separate vertices (as in (d)). There are no other possibilities for placing the edges, so the listing is complete. ■

Now consider the question, “Is there a general method to figure out whether graphs G and G ′ are isomorphic?” In other words, is there some algorithm that will accept graphs G and G ′ as input and produce a statement as to whether they are isomorphic? In fact, there is such an algorithm. It consists of generating all one-to-one, onto functions from the set of vertices of G to the set of vertices of G ′ and from the set of edges of G to the set of edges of G ′ and checking each pair to determine whether it preserves the edge-endpoint functions of G and G ′. The problem with this algorithm is that it takes an unreasonably long time to perform, even on a high-speed computer. If G and G ′ each have n vertices and m edges, the number of one-to-one correspondences from vertices to vertices is n! and the number of one-to-one correspondences from edges to edges is m!, so the total number of pairs of functions to check is n! ·m!. For instance, if m = n = 20, there would be 20! ·20! ∼= 5.9× 1036 pairs to check. Assuming that each check takes just 1 nanosecond, the total time would be approximately 1.9× 1020 years!

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.4 Isomorphisms of Graphs 679

Unfortunately, there is no more efficient general method known for checking whether two graphs are isomorphic. However, there are some simple tests that can be used to show that certain pairs of graphs are not isomorphic. For instance, if two graphs are isomorphic, then they have the same number of vertices (because there is a one-to-one correspondence from the vertex set of one graph to the vertex set of the other). It follows that if you are given two graphs, one with 16 vertices and the other with 17, you can immediately conclude that the two are not isomorphic. More generally, a property that is preserved by graph isomorphism is called an isomorphic invariant. For instance, “having 16 vertices” is an isomorphic invariant: If one graph has 16 vertices, then so does any graph that is isomorphic to it.

• Definition A property P is called an invariant for graph isomorphism if, and only if, given any graphs G and G ′, if G has property P and G ′ is isomorphic to G, then G ′ has property P .

Theorem 10.4.2

Each of the following properties is an invariant for graph isomorphism, where n, m, and k are all nonnegative integers:

1. has n vertices; 6. has a simple circuit of length k;

2. has m edges; 7. has m simple circuits of length k;

3. has a vertex of degree k; 8. is connected;

4. has m vertices of degree k; 9. has an Euler circuit;

5. has a circuit of length k; 10. has a Hamiltonian circuit.

Example 10.4.3 Showing That Two Graph Are Not Isomorphic

Show that the following pairs of graphs are not isomorphic by finding an isomorphic invariant that they do not share.

a.

G G'G G'

b.

H'H H'H

Solution

a. G has nine edges; G ′ has only eight.

b. H has a vertex of degree 4; H ′ does not. ■

We prove part (3) of Theorem 10.4.2 on the next page and leave the proofs of the other parts as exercises.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

680 Chapter 10 Graphs and Trees

Example 10.4.4 Proof of Theorem 10.4.2, Part (3)

Prove that if G is a graph that has a vertex of degree k and G ′ is isomorphic to G, then G ′ has a vertex of degree k.

Proof:

Suppose G and G ′ are isomorphic graphs and G has a vertex v of degree k, where k is a nonnegative integer. [We must show that G ′ has a vertex of degree k.] Since G and G ′ are isomorphic, there are one-to-one, onto functions g and h from the vertices of G to the vertices of G ′ and from the edges of G to the edges of G ′ that preserve the edge-endpoint functions in the sense that for all edges e and all vertices u of G, u is an endpoint of e if, and only if, g(u) is an endpoint of h(e). An example for a particular vertex v is shown below.

e3

e4

e2 h(e2) h(e1)

h(e4)

e5

e1

v g(v)

Degree v = 3 + 2 · 2 = 7 Degree g(v) = 3 + 2 · 2 = 7

h(e3)

h(e5)

Let e1, e2, . . . , em be the m distinct edges that are incident on a vertex v in G, where m is a nonnegative integer. Then h(e1), h(e2), . . . , h(em) are m distinct edges that are incident on g(v) in G ′. [The reason why h(e1), h(e2), . . . , h(em) are distinct is that h is one-to-one and e1, e2, . . . , em are distinct. And the reason why h(e1), h(e2), . . . , h(em) are incident on g(v) is that g and h preserve the edge-endpoint functions of G and G ′ and e1, e2, . . . , em are incident on v.]

Also, there are no edges incident on g(v) other than the ones that are images under g of edges incident on v [because g is onto and g and h preserve the edge-endpoint functions of G and G ′]. Thus the number of edges incident on v equals the number of edges incident on g(v).

Finally, an edge e is a loop at v if, and only if, h(e) is a loop at g(v), so the number of loops incident on v equals the number of loops incident on g(v). [For since g and h preserve the edge-endpoint functions of G and G ′, a vertex w is an endpoint of e in G if, and only if, g(w) is an endpoint of h(e) in G ′. It follows that v is the only endpoint of e in G if, and only if, g(v) is the only endpoint of h(e) in G ′.]

Now the degree of v, which is k, equals the number of edges incident on v plus the number of edges incident on v that are loops (since each loop contributes 2 to the degree of v). But we have already shown that the number of edges incident on v equals the number of edges incident on g(v) and that the number of loops incident on v equals the number of loops incident on g(v). Hence g(v) also has degree k. ■

Graph Isomorphism for Simple Graphs When graphs G and G ′ are both simple, the definition of G being isomorphic to G ′ can be written without referring to the correspondence between the edges of G and the edges of G ′.

• Definition If G and G ′ are simple graphs, then G is isomorphic to G′ if, and only if, there exists a one-to-one correspondence g from the vertex set V (G) of G to the vertex set V (G ′) of G ′ that preserves the edge-endpoint functions of G and G ′ in the sense that for all vertices u and v of G,

{u, v} is an edge in G ⇔ {g(u), g(v)} is an edge in G ′. 10.4.2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.4 Isomorphisms of Graphs 681

Example 10.4.5 Isomorphism of Simple Graphs

Are the two graphs shown below isomorphic? If so, define an isomorphism.

a

b

c

d

x

z

yw

GG '

Solution Yes. Define f : V (G)→ V (G ′) by the arrow diagram shown below.

a b c d

w x y z

V (G) V (G' )g

Then g is one-to-one and onto by inspection. The fact that g preserves the edge-endpoint functions of G and G ′ is shown by the following table:

Edges of G Edges of G′

{a, b} {y, w} = {g(a), g(b)} {a, c} {y, x} = {g(a), g(c)} {a, d} {y, z} = {g(a), g(d)} {c, d} {x, z} = {g(c), g(d)} ■

Test Yourself 1. If G and G ′ are graphs, then G is isomorphic to G ′ if, and

only if, there exist a one-to-one correspondence g from the vertex set of G to the vertex set of G ′ and a one-to-one cor- respondence h from the edge set of G to the edge set of G ′

such that for all vertices v and edges e in G, v is an endpoint of e if, and only if, _____.

2. A property P is an invariant for graph isomorphism if, and only if, given any graphs G and G ′, if G has property P and G ′ is isomorphic to G then _____.

3. Some invariants for graph isomorphisms are _____, _____, _____, _____, _____, _____, _____, _____, _____, and _____.

Exercise Set 10.4 For each pair of graphs G and G ′ in 1–5, determine whether G and G ′ are isomorphic. If they are, give functions g: V (G)→ V (G ′) and h: E(G)→ E(G ′) that define the isomorphism. If they are not, give an invariant for graph isomorphism that they do not share.

1. v1

w1 w3 w2

w4

v4

v2 v3

e1 e3

f1

f2e2

e4

G G'

f3

f4

2.

v1

v5 v3 v4

v2

e2

e3

e1

e6

e7

e5

e4

G

w2

w1

w4 w6

w3

f1 f2

f3 f4

f6

w5f5 f7

G'

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

682 Chapter 10 Graphs and Trees

3.

v1 v3

v2 v4

e6

e1 e3 e5

e2

e4

G

f6

f5

f2 f3

f1

w1

w3

w2

w4

f4

G'

4.

v1

v2

v5 v4

v3 e2 e7

e1

e6

e5

e3

e4

G

w1

w2

w3

w5 w4

f1

f3 f5

f6

f7

f2

f4

G'

5.

v1

v5

v2

v3

v4

e2

e3

e4

e5

e7

e6

e1

G

w1

w5 w4

w3

w2

f6

f4

f5

f3

f2

f1

f7

G'

For each pair of simple graphs G and G ′ in 6–13, determine whether G and G ′ are isomorphic. If they are, give a function g: V (G)→ V (G ′) that defines the isomorphism. If they are not, give an invariant for graph isomorphism that they do not share.

6.

v1 v2 v3 v4

w1

w4

w2

w3

GG '

7. w1

w4

w2

w3

v1

v4

v2

v3

G G'

8.

a

f

c

d

b

e y

v

u

z

w

x

G G'

9.

a

f

e

b

c

d

G

u

z y

x

v w

G'

10.

a

g

c

e d

b

f

G

t

z

v

w

x

y

u

G'

11.

a

f

c

d

b

e

G

u

z y

x

w v

G'

12. a

d

b

c

f

e

h

g

G

s x

v

w

t

u

G'

z y

13. a

f

d

e b

c

G

h g

s x

v

w

t

u

G'

z y

14. Draw all nonisomorphic simple graphs with three vertices.

15. Draw all nonisomorphic simple graphs with four vertices.

16. Draw all nonisomorphic graphs with three vertices and no more than two edges.

17. Draw all nonisomorphic graphs with four vertices and no more than two edges.

18.H Draw all nonisomorphic graphs with four vertices and three edges.

19. Draw all nonisomorphic graphs with six vertices, all having degree 2.

20. Draw four nonisomorphic graphs with six vertices, two of degree 4 and four of degree 3.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 683

Prove that each of the properties in 21–29 is an invariant for graph isomorphism. Assume that n, m, and k are all nonnega- tive integers.

21. Has n vertices 22. Has m edges

23. Has a circuit of length k

24. Has a simple circuit of length k

25.H Has m vertices of degree k

26. Has m simple circuits of length k

27.H Is connected 28. Has an Euler circuit

29. Has a Hamiltonian circuit

30. Show that the following two graphs are not isomorphic by supposing they are isomorphic and deriving a contradiction.

v1 v2 v3 v4 v5 v6

e1 e2 e3

e4

e5 e6

w1 w2 w3 w4 w5 w6

f1 f2 f3 f4

f5

f6

G

G'

Answers for Test Yourself 1. g(v) is an endpoint of h(e) 2. G

′ has property P 3. has n vertices; has m edges; has a vertex of degree k; has m vertices of

degree k; has a circuit of length k; has a simple circuit of length k; has m simple circuits of length k; is connected; has an Euler circuit; has a Hamiltonian circuit

10.5 Trees We are not very pleased when we are forced to accept a mathematical truth by virtue of a complicated chain of formal conclusions and computations, which we traverse blindly, link by link, feeling our way by touch. We want first an overview of the aim and of the road; we want to understand the idea of the proof, the deeper context. — Hermann Weyl, 1885–1955

If a friend asks what you are studying and you answer “trees,” your friend is likely to infer you are taking a course in botany. But trees are also a subject for mathematical investi- gation. In mathematics, a tree is a connected graph that does not contain any circuits. Mathematical trees are similar in certain ways to their botanical namesakes.

• Definition A graph is said to be circuit-free if, and only if, it has no circuits. A graph is called a tree if, and only if, it is circuit-free and connected. A trivial tree is a graph that consists of a single vertex. A graph is called a forest if, and only if, it is circuit-free and not connected.

Example 10.5.1 Trees and Non-Trees

All the graphs shown in Figure 10.5.1 are trees, whereas those in Figure 10.5.2 are not.

(a) (b) (c) (d)

Figure 10.5.1 Trees. All the graphs in (a)–(d) are connected and circuit-free.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

684 Chapter 10 Graphs and Trees

(a) (b) (c) (d)

Figure 10.5.2 Non-Trees. The graphs in (a), (b), and (c) all have circuits, and the graph in (d) is not connected. ■

Examples of Trees The following examples illustrate just a few of the many and varied situations in which mathematical trees arise.

Example 10.5.2 A Decision Tree

During orientation week, a college administers an exam to all entering students to deter- mine placement in the mathematics curriculum. The exam consists of two parts, and placement recommendations are made as indicated by the tree shown in Figure 10.5.3. Read the tree from left to right to decide what course should be recommended for a stu- dent who scored 9 on part I and 7 on part II.

Score on part I

Score on part II

Math 100

Math 100

Math 110

Math 110

Math 120 Score on part II

>10

<8

= 8, 9, 10

>10

10

>6

6

Figure 10.5.3

Solution Since the student scored 9 on part I, the score on part II is checked. Since it is greater than 6, the student should be advised to take Math 110. ■

Example 10.5.3 A Parse Tree

In the last 30 years, Noam Chomsky and others have developed new ways to describe the syntax (or grammatical structure) of natural languages such as English. As is discussed briefly in Chapter 12, this work has proved useful in constructing compilers for high- level computer languages. In the study of grammars, trees are often used to show the derivation of grammatically correct sentences from certain basic rules. Such trees are called syntactic derivation trees or parse trees.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 685

A very small subset of English grammar, for example, specifies that

1. a sentence can be produced by writing first a noun phrase and then a verb phrase;

2. a noun phrase can be produced by writing an article and then a noun;

3. a noun phrase can also be produced by writing an article, then an adjective, and then a noun;

4. a verb phrase can be produced by writing a verb and then a noun phrase;

5. one article is “the”;

6. one adjective is “young”;

7. one verb is “caught”;

8. one noun is “man”;

9. one (other) noun is “ball.”

The rules of a grammar are called productions. It is customary to express them using

Co ur

te sy

of IB

M Co

rp or

at io

n

John Backus (1924–1998)

the shorthand notation illustrated below. This notation, introduced by John Backus in 1959 and modified by Peter Naur in 1960, was used to describe the computer language Algol and is called the Backus-Naur notation. In the notation, the symbol | represents the word or, and angle brackets ⟨ ⟩ are used to enclose terms to be defined (such as a sentence or noun phrase).

1. ⟨sentence⟩ → ⟨noun phrase⟩⟨verb phrase⟩ 2., 3. ⟨noun phrase⟩ → ⟨article⟩⟨noun⟩ | ⟨article⟩⟨adjective⟩⟨noun⟩ 4. ⟨verb phrase⟩ → ⟨verb⟩⟨noun phrase⟩ 5. ⟨article⟩ → the 6. ⟨adjective⟩ → young 7, 8. ⟨noun⟩ → man | ball 9. ⟨verb⟩ → caught

The derivation of the sentence “The young man caught the ball” from the above rules

Co ur

te sy

of Pe

te r

N au

r

Peter Naur (born 1928)

is described by the tree shown below.

⟨sentence⟩

⟨noun phrase ⟨⟩ verb phrase⟩

⟨article⟩ ⟨adjective⟩ ⟨noun⟩ ⟨verb⟩

caught

⟨noun phrase⟩

⟨article⟩ ⟨noun⟩

the ball

the young man

In the study of linguistics, syntax refers to the grammatical structure of sentences, and semantics refers to the meanings of words and their interrelations. A sentence can be syn- tactically correct but semantically incorrect, as in the nonsensical sentence “The young ball caught the man,” which can be derived from the rules given above. Or a sentence can contain syntactic errors but not semantic ones, as, for instance, when a two-year-old child says, “Me hungry!” ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

686 Chapter 10 Graphs and Trees

Example 10.5.4 Structure of Hydrocarbon Molecules

The German physicist Gustav Kirchhoff (1824–1887) was the first to analyze the behav- ior of mathematical trees in connection with the investigation of electrical circuits. Soon after (and independently), the English mathematician Arthur Cayley used the mathemat- ics of trees to enumerate all isomers for certain hydrocarbons. Hydrocarbon molecules are composed of carbon and hydrogen; each carbon atom can form up to four chemical bonds with other atoms, and each hydrogen atom can form one bond with another atom. Thus the structure of hydrocarbon molecules can be represented by graphs such as those shown following, in which the vertices represent atoms of hydrogen and carbon, denoted H and C, and the edges represent the chemical bonds between them.

H

H

H

H

H

H HH

HH CC

C

C

H

H

H HC

H

H

C

H

H

C

H

H

C

IsobutaneButane

Note that each of these graphs has four carbon atoms and ten hydrogen atoms, but the two graphs show different configurations of atoms. When two molecules have the same chemical formulae (in this case C4H10) but different chemical bonds, they are called isomers.

Certain saturated hydrocarbon molecules contain the maximum number of hydro-

B et

tm an

n/ CO

R B

IS

Arthur Cayley (1821–1895)

gen atoms for a given number of carbon atoms. Cayley showed that if such a saturated hydrocarbon molecule has k carbon atoms, then it has 2k + 2 hydrogen atoms. The first step in doing so is to prove that the graph of such a saturated hydrocarbon molecule is a tree. Prove this using proof by contradiction. (You are asked to finish the derivation of Cayley’s result in exercise 4 at the end of this section.)

Solution Suppose there is a hydrocarbon molecule that contains the maximum number of hydrogen atoms for the number of its carbon atoms and whose graph G is not a tree. [We must derive a contradiction.] Since G is not a tree, G is not connected or G has a circuit. But the graph of any molecule is connected (all the atoms in a molecule must be connected to each other), and so G must have a nontrivial circuit. Now the edges of the circuit can link only carbon atoms because every vertex of a circuit has degree at least 2 and a hydrogen atom vertex has degree 1. Delete one edge of the circuit and add two new edges to join each of the newly disconnected carbon atom vertices to a hydrogen atom vertex as shown below.

C

C

C

C

H

H

Add Delete

Rest of circuit

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 687

The resulting molecule has two more hydrogen atoms than the given molecule, but the number of carbon atoms is unchanged. This contradicts the supposition that the given molecule has the maximum number of hydrogen atoms for the given number of carbon atoms. Hence the supposition is false, and so G is a tree. ■

Characterizing Trees There is a somewhat surprising relation between the number of vertices and the number of edges of a tree. It turns out that if n is a positive integer, then any tree with n vertices (no matter what its shape) has n − 1 edges. Perhaps even more surprisingly, a partial converse to this fact is also true—namely, any connected graph with n vertices and n − 1 edges is a tree. It follows from these facts that if even one new edge (but no new vertex) is added to a tree, the resulting graph must contain a circuit. Also, from the fact that removing an edge from a circuit does not disconnect a graph, it can be shown that every connected graph has a subgraph that is a tree. It follows that if n is a positive integer, any graph with n vertices and fewer than n − 1 edges is not connected.

A small but very important fact necessary to derive the first main theorem about trees is that any nontrivial tree must have at least one vertex of degree 1.

Lemma 10.5.1

Any tree that has more than one vertex has at least one vertex of degree 1.

A constructive way to understand this lemma is to imagine being given a tree T with more than one vertex. You pick a vertex v at random and then search outward along a path from v looking for a vertex of degree 1. As you reach each new vertex, you check whether it has degree 1. If it does, you are finished. If it does not, you exit from the vertex along a different edge from the one you entered on. Because T is circuit-free, the vertices included in the path never repeat. And since the number of vertices of T is finite, the process of building a path must eventually terminate. When that happens, the final vertex v′ of the path must have degree 1. This process is illustrated below.

Start here Search outward from v to find vertex v' of degree 1.

e e'

v

v'

This discussion is made precise in the following proof.

Proof:

Let T be a particular but arbitrarily chosen tree that has more than one vertex, and consider the following algorithm:

Step 1: Pick a vertex v of T and let e be an edge incident on v. [If there were no edge incident on v, then v would be an isolated vertex. But this would contradict the assumption that T is connected (since it is a tree) and has at least two vertices.]

Step 2: While deg(v) > 1, repeat steps 2a, 2b, and 2c:

continued on page 688

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

688 Chapter 10 Graphs and Trees

Step 2a: Choose e′ to be an edge incident on v such that e′ ̸= e. [Such an edge exists because deg(v) > 1 and so there are at least two edges incident on v.]

Step 2b: Let v′ be the vertex at the other end of e′ from v. [Since T is a tree, e′

cannot be a loop and therefore e′ has two distinct endpoints.]

Step 2c: Let e = e′ and v = v′. [This is just a renaming process in preparation for a repetition of step 2.]

The algorithm just described must eventually terminate because the set of ver- tices of the tree T is finite and T is circuit-free. When it does, a vertex v of degree 1 will have been found.

Using Lemma 10.5.1 it is not difficult to show that, in fact, any tree that has more than one vertex has at least two vertices of degree 1. This extension of Lemma 10.5.1 is left to the exercises at the end of this section.

• Definition Let T be a tree. If T has only one or two vertices, then each is called a terminal vertex. If T has at least three vertices, then a vertex of degree 1 in T is called a terminal vertex (or a leaf ), and a vertex of degree greater than 1 in T is called an internal vertex (or a branch vertex).

Example 10.5.5 Terminal and Internal Vertices

Find all terminal vertices and all internal vertices in the following tree:

v8

v0

v7

v6

v1

v5

v3 v2

v4

Solution The terminal vertices are v0, v2, v4, v5, v7, and v8. The internal vertices are v6, v1, and v3. ■

The following is the first of the two main theorems about trees:

Theorem 10.5.2

For any positive integer n, any tree with n vertices has n − 1 edges.

The proof is by mathematical induction. To do the inductive step, you assume the theorem is true for a positive integer k and then show it is true for k + 1. Thus you assume you have a tree T with k + 1 vertices, and you must show that T has (k + 1)− 1 = k edges. As you do this, you are free to use the inductive hypothesis that any tree with k vertices has k − 1 edges. To make use of the inductive hypothesis, you need to reduce the tree T with k + 1 vertices to a tree with just k vertices. But by Lemma 10.5.1, T has a vertex v of degree 1, and since T is connected, v is attached to the rest of T by a single edge e as sketched on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 689

e v

T:

Rest of T

Now if e and v are removed from T , what remains is a tree T ′ with (k + 1)− 1 = k vertices. By inductive hypothesis, then, T ′ has k − 1 edges. But the original tree T has one more vertex and one more edge than T ′. Hence T must have (k − 1) + 1 = k edges, as was to be shown. A formal version of this argument is given below.

Proof (by mathematical induction):

Let the property P(n) be the sentence

Any tree with n vertices has n − 1 edges. ← P(n)

We use mathematical induction to show that this property is true for all integers n ≥ 1. Show that P(1) is true: Let T be any tree with one vertex. Then T has zero edges (since it contains no loops). But 0 = 1− 1, so P(1) is true. Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is true: Suppose k is any positive integer for which P(k) is true. In other words, suppose that

Any tree with k vertices has k - 1 edges. ← P(k) inductive hypothesis

We must show that P(k + 1) is true. In other words, we must show that

Any tree with k + 1 vertices has (k + 1)− 1 = k edges. ← P(k + 1)

Let T be a particular but arbitrarily chosen tree with k + 1 vertices. [We must show that T has k edges.] Since k is a positive integer, (k + 1) ≥ 2, and so T has more than one vertex. Hence by Lemma 10.5.1, T has a vertex v of degree 1. Also, since T has more than one vertex, there is at least one other vertex in T besides v. Thus there is an edge e connecting v to the rest of T . Define a subgraph T ′ of T so that

V (T ′) = V (T )− {v} Then

E(T ′) = E(T )− {e}.

1. The number of vertices of T ′ is (k + 1)− 1 = k. 2. T ′ is circuit-free (since T is circuit-free, and removing an edge and a vertex

cannot create a circuit).

3. T ′ is connected (see exercise 24 at the end of this section).

Hence, by the definition of tree, T ′ is a tree. Since T ′ has k vertices, by inductive hypothesis

the number of edges of T ′ = (the number of vertices of T ′)− 1 = k − 1.

continued on page 690

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

690 Chapter 10 Graphs and Trees

But then

the number of edges of T = (the number of edges of T ′) + 1 = (k − 1) + 1 = k.

[This is what was to be shown.]

Example 10.5.6 Determining Whether a Graph Is a Tree

A graph G has ten vertices and twelve edges. Is it a tree?

Solution No. By Theorem 10.5.2, any tree with ten vertices has nine edges, not twelve. ■

Example 10.5.7 Finding Trees Satisfying Given Conditions

Find all nonisomorphic trees with four vertices.

Solution By Theorem 10.5.2, any tree with four vertices has three edges. Thus the total degree of a tree with four vertices must be 6. Also, every tree with more than one vertex has at least two vertices of degree 1 (see the comment following Lemma 10.5.1 and exercises 5 and 29 at the end of this section). Thus the following combinations of degrees for the vertices are the only ones possible:

1, 1, 1, 3 and 1, 1, 2, 2.

There are two nonisomorphic trees corresponding to both of these possibilities, as shown below.

and ■

To prove the second major theorem about trees, we need another lemma.

Lemma 10.5.3

If G is any connected graph, C is any circuit in G, and any one of the edges of C is removed from G, then the graph that remains is connected.

Essentially, the reason why Lemma 10.5.3 is true is that any two vertices in a circuit are connected by two distinct paths. It is possible to draw the graph so that one of these goes “clockwise” and the other goes “counterclockwise” around the circuit. For example, in the circuit shown on the next page, the clockwise path from v2 to v3 is

v2e3v3

and the counterclockwise path from v2 to v3 is

v2e2v1e1v0e6v5e5v4e4v3.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 691

v2 v3

v0 v5

v1 v4

e2

e1

e4

e5

e3

e6

Clockwise

Counterclockwise

Proof:

Suppose G is a connected graph, C is a circuit in G, and e is an edge of C . Form a subgraph G ′ of G by removing e from G. Thus

V (G ′) = V (G) E(G ′) = E(G)− {e}.

We must show that G ′ is connected. [To show a graph is connected, we must show that if u and w are any vertices of the graph, then there exists a walk in G ′ from u to w.] Suppose u and w are any two vertices of G ′. [We must find a walk from u to w.] Since the vertex sets of G and G ′ are the same, u and w are both vertices of G, and since G is connected, there is a walk W in G from u to w.

Case 1 (e is not an edge of W): The only edge in G that is not in G ′ is e, so in this case W is also a walk in G ′. Hence u is connected to w by a walk in G ′.

Case 2 (e is an edge of W): In this case the walk W from u to w includes a section of the circuit C that contains e. Let C be denoted as follows:

C: v0e1v1e2v2 · · · envn (= v0). Now e is one of the edges of C , so, to be specific, let e = ek . Then the walk W contains either the sequence

vk−1ekvk or vkekvk−1.

If W contains vk−1ekvk , connect vk−1 to vk by taking the “counterclockwise” walk W ′ defined as follows:

W ′: vk−1ek−1vk−2 · · · v0envn−1 · · · ek+1vk . An example showing how to go from u to w while avoiding ek is given in Fig- ure 10.5.4.

u

vk–1

vk+1

vk

vk–2

ek–1 ek+1 To go from u to w while avoiding ek , go counterclockwise around the circuit.

ek

w

Figure 10.5.4 An Example of a Walk from u to w That Does Not Include Edge ek

If W contains vkekvk−1, connect vk to vk−1 by taking the “clockwise” walk W ′′

defined as follows:

W ′′: vkek+1vk+1 · · · vne1v1e2 · · · ek−1vk−1. continued on page 692

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

692 Chapter 10 Graphs and Trees

Now patch either W ′ or W ′′ into W to form a new walk from u to w. For instance, to patch W ′ into W , start with the section of W from u to vk−1, then take W ′ from vk−1 to vk , and finally take the section of W from vk to w. If this new walk still contains an occurrence of e, just repeat the process described previously until all occurrences are eliminated. [This must happen eventually since the number of occurrences of e in C is finite.] The result is a walk from u to w that does not contain e and hence is a walk in G ′.

The previous arguments show that both in case 1 and in case 2 there is a walk in G ′ from u to w. Since the choice of u and w was arbitrary, G ′ is connected.

The second major theorem about trees is a modified converse to Theorem 10.5.2.

Theorem 10.5.4

For any positive integer n, if G is a connected graph with n vertices and n − 1 edges, then G is a tree.

Proof:

Let n be a positive integer and suppose G is a particular but arbitrarily chosen graph that is connected and has n vertices and n − 1 edges. [We must show that G is a tree. Now a tree is a connected, circuit-free graph. Since we already know G is connected, it suffices to show that G is circuit-free.] Suppose G is not circuit-free. That is, suppose G has a circuit C . [We must derive a contradiction.] By Lemma 10.5.3, an edge of C can be removed from G to obtain a graph G ′ that is connected. If G ′ has a circuit, then repeat this process: Remove an edge of the circuit from G ′ to form a new con- nected graph. Continue repeating the process of removing edges from circuits until eventually a graph G ′′ is obtained that is connected and is circuit-free. By definition, G ′′ is a tree. Since no vertices were removed from G to form G ′′, G ′′ has n vertices just as G does. Thus, by Theorem 10.5.2, G ′′ has n − 1 edges. But the supposition that G has a circuit implies that at least one edge of G is removed to form G ′′. Hence G ′′ has no more than (n − 1)− 1 = n − 2 edges, which contradicts its having n − 1 edges. So the supposition is false. Hence G is circuit-free, and therefore G is a tree [as was to be shown].

Theorem 10.5.4 is not a full converse of Theorem 10.5.2. Although it is true that every connected graph with n vertices and n − 1 edges (where n is a positive integer) is a tree, it is not true that every graph with n vertices and n − 1 edges is a tree.

Example 10.5.8 A Graph with n Vertices and n − 1 Edges That Is Not a Tree Give an example of a graph with five vertices and four edges that is not a tree.

Solution By Theorem 10.5.4, such a graph cannot be connected. One example of such an unconnected graph is shown below.

v1 v4

v5v2 v3

e2

e3

e1 e4

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.5 Trees 693

Test Yourself 1. A circuit-free graph is a graph with _____.

2. A forest is a graph that is _____, and a tree is a graph that is _____.

3. A trivial tree is a graph that consists of _____.

4. Any tree with at least two vertices has at least one vertex of degree _____.

5. If a tree T has at least two vertices, then a terminal vertex (or leaf) in T is a vertex of degree _____ and an internal vertex (or branch vertex) in T is a vertex of degree _____.

6. For any positive integer n, any tree with n vertices has _____.

7. For any positive integer n, if G is a connected graph with n vertices and n − 1 edges then _____.

Exercise Set 10.5 1. Read the tree in Example 10.5.2 from left to right to answer

the following questions: a. What course should a student who scored 12 on part I

and 4 on part II take? b. What course should a student who scored 8 on part I and

9 on part II take?

2. Draw trees to show the derivations of the following sen- tences from the rules given in Example 10.5.3. a. The young ball caught the man. b. The man caught the young ball.

3.H What is the total degree of a tree with n vertices? Why?

4. Let G be the graph of a hydrocarbon molecule with the maximum number of hydrogen atoms for the number of its carbon atoms. a. Draw the graph of G if G has three carbon atoms and

eight hydrogen atoms. b. Draw the graphs of three isomers of C5H12. c. Use Example 10.5.4 and exercise 3 to prove that if the

vertices of G consist of k carbon atoms and m hydrogen atoms, then G has a total degree of 2k + 2m − 2.

d.H Prove that if the vertices of G consist of k carbon atoms and m hydrogen atoms, then G has a total degree of 4k + m.

e. Equate the results of (c) and (d) to prove Cayley’s result that a saturated hydrocarbon molecule with k carbon atoms and a maximum number of hydrogen atoms has 2k + 2 hydrogen atoms.

5.H Extend the argument given in the proof of Lemma 10.5.1 to show that a tree with more than one vertex has at least two vertices of degree 1.

6. If graphs are allowed to have an infinite number of vertices and edges, then Lemma 10.5.1 is false. Give a counterex- ample that shows this. In other words, give an example of an “infinite tree” (a connected, circuit-free graph with an infinite number of vertices and edges) that has no vertex of degree 1.

7. Find all terminal vertices and all internal vertices for the following trees.

a.

v1 v4

v2

v3

v5

v7

v6

b. v1 v4 v2

v3 v5

v7

v6 v8

In each of 8–21, either draw a graph with the given specifica- tions or explain why no such graph exists.

8. Tree, nine vertices, nine edges

9. Graph, connected, nine vertices, nine edges

10. Graph, circuit-free, nine vertices, six edges

11. Tree, six vertices, total degree 14

12. Tree, five vertices, total degree 8

13. Graph, connected, six vertices, five edges, has a nontrivial circuit

14. Graph, two vertices, one edge, not a tree

15. Graph, circuit-free, seven vertices, four edges

16. Tree, twelve vertices, fifteen edges

17. Graph, six vertices, five edges, not a tree

18. Tree, five vertices, total degree 10

19. Graph, connected, ten vertices, nine edges, has a nontrivial circuit

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

694 Chapter 10 Graphs and Trees

20. Simple graph, connected, six vertices, six edges

21. Tree, ten vertices, total degree 24

22. A connected graph has twelve vertices and eleven edges. Does it have a vertex of degree 1? Why?

23. A connected graph has nine vertices and twelve edges. Does it have a nontrivial circuit? Why?

24. Suppose that v is a vertex of degree 1 in a connected graph G and that e is the edge incident on v. Let G ′ be the sub- graph of G obtained by removing v and e from G. Must G ′

be connected? Why?

25. A graph has eight vertices and six edges. Is it connected? Why?

26.H If a graph has n vertices and n − 2 or fewer edges, can it be connected? Why?

27. A circuit-free graph has ten vertices and nine edges. Is it connected? Why?

28.H Is a circuit-free graph with n vertices and at least n − 1 edges connected? Why?

29. Prove that every nontrivial tree has at least two vertices of degree 1 by filling in the details and completing the follow- ing argument: Let T be a nontrivial tree and let S be the set of all paths from one vertex to another of T . Among all the paths in S, choose a path P with the most edges. (Why is it possible to find such a P?) What can you say about the initial and final vertices of P? Why?

30. Find all nonisomorphic trees with five vertices.

31. a. Prove that the following is an invariant for graph iso- morphism: A vertex of degree i is adjacent to a vertex of degree j .

b.H Find all nonisomorphic trees with six vertices.

Answers for Test Yourself 1. no circuits 2. circuit-free and not connected; connected and circuit-free 3. a single vertex (and no edges) 4. 1 5. 1; greater than 1 (Or: at least 2) 6. n − 1 edges 7. G is a tree

10.6 Rooted Trees

Let us grant that the pursuit of mathematics is a divine madness of the human spirit, a refuge from the goading urgency of contingent happenings. — Alfred North Whitehead, 1861–1947

An outdoor tree is rooted and so is the kind of family tree that shows all the descendants of one particular person. The terminology and notation of rooted trees blends the language of botanical trees and that of family trees. In mathematics, a rooted tree is a tree in which one vertex has been distinguished from the others and is designated the root. Given any other vertex v in the tree, there is a unique path from the root to v. (After all, if there were two distinct paths, a circuit could be constructed.) The number of edges in such a path is called the level of v, and the height of the tree is the length of the longest such path. It is traditional in drawing rooted trees to place the root at the top (as is done in family trees) and show the branches descending from it.

• Definition A rooted tree is a tree in which there is one vertex that is distinguished from the others and is called the root. The level of a vertex is the number of edges along the unique path between it and the root. The height of a rooted tree is the maximum level of any vertex of the tree. Given the root or any internal vertex v of a rooted tree, the children of v are all those vertices that are adjacent to v and are one level farther away from the root than v. If w is a child of v, then v is called the parent of w, and two distinct vertices that are both children of the same parent are called siblings. Given two distinct vertices v and w, if v lies on the unique path between w and the root, then v is an ancestor of w and w is a descendant of v.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.6 Rooted Trees 695

These terms are illustrated in Figure 10.6.1.

Level 0

Level 1

Level 2

Level 3

Level 4

u

v w

Vertices in the enclosed region are descendants of u, which is an ancestor of each.

v is a child of u. u is the parent of v. v and w are siblings.

Root

Figure 10.6.1 A Rooted Tree

Example 10.6.1 Rooted Trees

Consider the tree with root v0 shown below.

a. What is the level of v5? b. What is the level of v0?

c. What is the height of this rooted tree? d. What are the children of v3?

e. What is the parent of v2? f. What are the siblings of v8?

g. What are the descendants of v3?

v1 v2 v3

v4

v7 v8 v9 v10

v5 v6

v0

Solution

a. 2 b. 0 c. 3 d. v5 and v6 e. v0 f. v7 and v9 g. v5, v6, v10 ■

Note that in the tree with root v0 shown below, v1 has level 1 and is the child of v0, and both v0 and v1 are terminal vertices.

v1

v0

Binary Trees When every vertex in a rooted tree has at most two children and each child is designated either the (unique) left child or the (unique) right child, the result is a binary tree.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

696 Chapter 10 Graphs and Trees

• Definition A binary tree is a rooted tree in which every parent has at most two children. Each child in a binary tree is designated either a left child or a right child (but not both), and every parent has at most one left child and one right child. A full binary tree is a binary tree in which each parent has exactly two children.

Given any parent v in a binary tree T , if v has a left child, then the left subtree of v is the binary tree whose root is the left child of v, whose vertices consist of the left child of v and all its descendants, and whose edges consist of all those edges of T that connect the vertices of the left subtree. The right subtree of v is defined analogously.

These terms are illustrated in Figure 10.6.2.

v is the left child of u.

v

u

Root

w x is the right child of w.

x

Left subtree of w Right subtree of w

Figure 10.6.2 A Binary Tree

Example 10.6.2 Representation of Algebraic Expressions

Binary trees are used in many ways in computer science. One use is to represent algebraic expressions with arbitrary nesting of balanced parentheses. For instance, the following (labeled) binary tree represents the expression a/b: The operator is at the root and acts on the left and right children of the root in left-right order.

/

a b

More generally, the binary tree shown below represents the expression a/(c + d). In such a representation, the internal vertices are arithmetic operators, the terminal vertices are variables, and the operator at each vertex acts on its left and right subtrees in left-right order.

c d

/

a +

Draw a binary tree to represent the expression ((a − b) ·c) + (d/e).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.6 Rooted Trees 697

Solution

a

d e– c

+

· /

b ■

An interesting theorem about binary trees says that if you know the number of internal vertices of a full binary tree, then you can calculate both the total number of vertices and the number of terminal vertices, and conversely. More specifically, a full binary tree with k internal vertices has a total of 2k + 1 vertices of which k + 1 are terminal vertices.

Theorem 10.6.1

If k is a positive integer and T is a full binary tree with k internal vertices, then T has a total of 2k + 1 vertices and has k + 1 terminal vertices.

Proof:

Suppose k is a positive integer and T is a full binary tree with k internal vertices. Observe that the set of all vertices of T can be partitioned into two disjoint subsets: the set of all vertices that have a parent and the set of all vertices that do not have a parent. Now there is just one vertex that does not have a parent, namely the root. Also, since every internal vertex of a full binary tree has exactly two children, the number of vertices that have a parent is twice the number of parents, or 2k, since each parent is an internal vertex. Hence

[ the total number of vertices of T

] =

⎣ the number of vertices that have a parent

⎦ +

⎣ the number of vertices that do not have a parent

= 2k + 1. But it is also true that the total number of vertices of T equals the number of internal vertices plus the number of terminal vertices. Thus

[ the total number of vertices of T

] = [

the number of internal vertices

] + [

the number of terminal vertices

]

= k + [

the number of terminal vertices

]

Now equate the two expressions for the total number of vertices of T:

2k + 1 = k + [

the number of terminal vertices

]

Solving this equation gives [

the number of terminal vertices

] = (2k + 1)− k = k + 1.

Thus the total number of vertices is 2k + 1 and the number of terminal vertices is k + 1 [as was to be shown].

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

698 Chapter 10 Graphs and Trees

Example 10.6.3 Determining Whether a Certain Full Binary Tree Exists

Is there a full binary tree that has 10 internal vertices and 13 terminal vertices?

Solution No. By Theorem 10.6.1, a full binary tree with 10 internal vertices has 10 + 1 = 11 terminal vertices, not 13. ■

Another interesting theorem about binary trees specifies the maximum number of terminal vertices of a binary tree of a given height. Specifically, the maximum number of terminal vertices of a binary tree of height h is 2h . Another way to say this is that a binary tree with t terminal vertices has height of at least log2 t .

Theorem 10.6.2

For all integers h ≥ 0, if T is any binary tree with of height h and t terminal vertices, then

t ≤ 2h .

Equivalently, log2 t ≤ h.

Proof (by strong mathematical induction):

Let P(h) be the sentence

If T is any binary tree of height h, then the number of ← P(h) terminal vertices of T is at most 2h .

Show that P(0) is true: We must show that if T is any binary tree of height 0, then the number of terminal vertices of T is at most 20. Suppose T is a tree of height 0. Then T consists of a single vertex, the root. By definition this is a terminal vertex and so the number of terminal vertices is t = 1 = 2◦ = 2h . Hence t ≤ 2h [as was to be shown].

Show that for all integers k ≥ 0, if P(i) is true for all integers i from 0 through k, then it is true for k + 1: Let k be any integer with k ≥ 0, and suppose that

For all integers i from 0 through k, if T is any binary tree of height i, then the number of ← inductive hypothesis terminal vertices of T is at most 2i .

We must show that

If T is any binary tree of height k + 1, then the number of ← P(k + 1) terminal vertices of T is 2k+1.

Let T be a binary tree of height k + 1, root v, and t terminal vertices. Because k ≥ 0, we have that k + 1 ≥ 1 and so v has at least one child. Case 1 (v has only one child): In this case we may assume without loss of generality that v’s child is a left child and denote it by vL . Let TL be the left subtree of v. Then vL is the root of TL . (This situation is illustrated in Figure 10.6.3.) Because v has only one child, v is itself a terminal vertex, so the total number of terminal vertices in T equals the number of terminal vertices in TL plus 1. Thus if tL is the number of terminal vertices in TL , then t = tL + 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.6 Rooted Trees 699

Now by inductive hypothesis, tL ≤ 2k because the height of TL is k, one less than the height of T . Also, because v has a child, k + 1 ≥ 1, and so 2k ≥ 20 = 1. Therefore,

t = tL + 1 ≤ 2k + 1 ≤ 2k + 2k = 2 ·2k = 2(k+1).

Level 0

Level 1

Level 2

Level 3

Left subtree TL

vL

v

Figure 10.6.3 A Binary Tree Whose Root Has One Child

Case 2 (v has two children): In this case, v has both a left child, vL , and a right child, vR , and vL and vR are roots of a left subtree TL and a right subtree TR . Note that TL and TR are binary trees because T is a binary tree. (This situation is illustrated in Figure 10.6.4.)

Level 0

Level 1

Level 2

Level 3

Level 4

v

vL vR

Right subtree TRLeft subtree TL

Figure 10.6.4 A Binary Tree Whose Root Has Two Children

Now vL and vR are the roots of the left and right subtrees of v, denoted TL and TR , respectively. Note that TL and TR are binary trees because T is a binary tree. Let hL and h R be the heights of TL and TR , respectively. Then hL ≤ k and h R ≤ k since T is obtained by joining TL and TR and adding a level. Let tL and tR be the numbers of terminal vertices of TL and TR , respectively. Then, since both TL and TR have heights less than k + 1, by inductive hypothesis

tL ≤ 2hL and tR ≤ 2h R . But the terminal vertices of T consist exactly of the terminal vertices of TL together with the terminal vertices of TR . Therefore,

t = tL + tR ≤ 2hL + 2h R by inductive hypothesis since hL ≤ k and h R ≤ k continued on page 700

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

700 Chapter 10 Graphs and Trees

Hence,

t ≤ 2k + 2k = 2 ·2k = 2k+1 by basic algebra. Thus the number of terminal vertices is at most 2k + 1 [as was to be shown].

Since both the basis step and the inductive step have been proved, we conclude that for all integers h ≥ 0, if T is any binary tree with height h and t terminal ver- tices, then t ≤ 2h .

The equivalent inequality log2 t ≤ h follows from the fact that the logarithmic function with base 2 is increasing. In other words, for all positive real numbers x and y,

if x < y then log2 x < log2 y.

Thus if we apply the logarithmic function with base 2 to both sides of

t ≤ 2h, we obtain

log2 t ≤ log2(2h). Now by definition of logarithm, log2(2

h) = h [because log2(2h) is the exponent to which 2 must be raised to obtain 2h]. Hence

log2 t ≤ h [as was to be shown].

Example 10.6.4 Determining Whether a Certain Binary Tree Exists

Is there a binary tree that has height 5 and 38 terminal vertices?

Solution No. By Theorem 10.6.2, any binary tree T with height 5 has at most 25 = 32 terminal vertices, so such a tree cannot have 38 terminal vertices. ■

Test Yourself 1. A rooted tree is a tree in which _____. The level of a

vertex in a rooted tree is _____. The height of a rooted tree is _____.

2. A binary tree is a rooted tree in which _____.

3. A full binary tree is a rooted tree in which _____.

4. If k is a positive integer and T is a full binary tree with k internal vertices, then T has a total of _____ vertices and has _____ terminal vertices.

5. If T is a binary tree that has t terminal vertices and height h, then t and h are related by the inequality _____.

Exercise Set 10.6 1. Consider the tree shown at right with root a.

a. What is the level of n? b. What is the level of a? c. What is the height of this rooted tree? d. What are the children of n? e. What is the parent of g? f. What are the siblings of j? g. What are the descendants of f ?

j k

q r s t

x y z

l

e

b

a

d c

f

m

u

n o p

g h i

v w

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 701

2. Consider the tree shown below with root v0. a. What is the level of v8? b. What is the level of v0? c. What is the height of this rooted tree? d. What are the children of v10? e. What is the parent of v5? f. What are the siblings of v1? g. What are the descendants of v12?

v7

v1

v3 v4

v0

v2

v6

v12

v17

v19v18

v16v15v14v13

v10 v11v8 v9

v5

3. Draw binary trees to represent the following expressions: a. a ·b − (c/(d + e)) b. a/(b − c ·d)

In each of 4–20 either draw a graph with the given specifications or explain why no such graph exists.

4. Full binary tree, five internal vertices

5. Full binary tree, five internal vertices, seven terminal ver- tices

6. Full binary tree, seven vertices, of which four are internal vertices

7. Full binary tree, twelve vertices

8. Full binary tree, nine vertices

9. Binary tree, height 3, seven terminal vertices

10. Full binary tree, height 3, six terminal vertices

11. Binary tree, height 3, nine terminal vertices

12. Full binary tree, eight internal vertices, seven terminal vertices.

13. Binary tree, height 4, eight terminal vertices

14. Full binary tree, seven vertices

15. Full binary tree, nine vertices, five internal vertices

16. Full binary tree, four internal vertices

17. Binary tree, height 4, eighteen terminal vertices

18. Full binary tree, sixteen vertices

19. Full binary tree, height 3, seven terminal vertices

20. What can you deduce about the height of a binary tree if you know that it has the following properties? a. Twenty-five terminal vertices b. Forty terminal vertices c. Sixty terminal vertices

Answers for Test Yourself 1. one vertex is distinguished from the others and is called the root; the number of edges along the unique path between it and the root; the maximum level of any vertex of the tree 2. every parent has at most two children 3. every parent has exactly two children 4. 2k + 1; k + 1 5. t ≤ 2h , or, equivalently, log2 t ≤ h

10.7 Spanning Trees and Shortest Paths I contend that each science is a real science insofar as it is mathematics. — Immanuel Kant, 1724–1804

An East Coast airline company wants to expand service to the Midwest and has received permission from the Federal Aviation Authority to fly any of the routes shown in Fig- ure 10.7.1.

St. Louis

Chicago

Minneapolis

Milwaukee Detroit

Cincinnati

Louisville

Nashville

Figure 10.7.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

702 Chapter 10 Graphs and Trees

The company wishes to legitimately advertise service to all the cities shown but, for reasons of economy, wants to use the least possible number of individual routes to connect them. One possible route system is given in Figure 10.7.2.

St. Louis

Chicago

Minneapolis

Milwaukee Detroit

Cincinnati

Louisville

Nashville

Figure 10.7.2

Clearly this system joins all the cities. Is the number of individual routes minimal? The answer is yes, and the reason may surprise you.

The fact is that the graph of any system of routes that satisfies the company’s wishes is a tree, because if the graph were to contain a circuit, then one of the routes in the circuit could be removed without disconnecting the graph (by Lemma 10.5.3), and that would give a smaller total number of routes. But any tree with eight vertices has seven edges. Therefore, any system of routes that connects all eight vertices and yet minimizes the total number of routes consists of seven routes.

• Definition A spanning tree for a graph G is a subgraph of G that contains every vertex of G and is a tree.

The preceding discussion contains the essence of the proof of the following proposition:

Proposition 10.7.1

1. Every connected graph has a spanning tree.

2. Any two spanning trees for a graph have the same number of edges.

Proof of (1):

Suppose G is a connected graph. If G is circuit-free, then G is its own spanning tree and we are done. If not, then G has at least one circuit C1. By Lemma 10.5.3, the subgraph of G obtained by removing an edge from C1 is connected. If this subgraph is circuit-free, then it is a spanning tree and we are done. If not, then it has at least one circuit C2, and, as above, an edge can be removed from C2 to obtain a connected subgraph. Continuing in this way, we can remove successive edges from circuits, until eventually we obtain a connected, circuit-free subgraph T of G. [This must happen at some point because the number of edges of G is finite, and at no stage does removal of an edge disconnect the subgraph.] Also, T contains every vertex of G because no vertices of G were removed in constructing it. Thus T is a spanning tree for G.

The proof of part (2) is left as an exercise.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 703

Example 10.7.1 Spanning Trees

Find all spanning trees for the graph G pictured below.

v5

v0

v4

v1

v3

v2

Solution The graph G has one circuit v2v1v4v2, and removal of any edge of the circuit gives a tree. Thus, as shown below, there are three spanning trees for G.

v5

v0

v4

v1

v3

v2

v5

v0

v4

v1

v3

v2

v5

v0

v4

v1

v3

v2 ■

Minimum Spanning Trees The graph of the routes allowed by the Federal Aviation Authority shown in Figure 10.7.1 can be annotated by adding the distances (in miles) between each pair of cities. This is done in Figure 10.7.3.

St. Louis

Chicago

Minneapolis

Milwaukee Detroit

Cincinnati

Louisville

Nashville

355

695 74

262

242

348

151

83

230

269 306

Figure 10.7.3

Now suppose the airline company wants to serve all the cities shown, but with a route system that minimizes the total mileage. Note that such a system is a tree, because if the system contained a circuit, removal of an edge from the circuit would not affect a person’s ability to reach every city in the system from every other (again, by Lemma 10.5.3), but it would reduce the total mileage of the system.

More generally, a graph whose edges are labeled with numbers (known as weights) is called a weighed graph. A minimum-weight spanning tree, or simply a minimum spanning tree, is a spanning tree for which the sum of the weights of all the edges is as small as possible.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

704 Chapter 10 Graphs and Trees

• Definition A weighted graph is a graph for which each edge has an associated positive real number weight. The sum of the weights of all the edges is the total weight of the graph. A minimum spanning tree for a connected weighted graph is a spanning tree that has the least possible total weight compared to all other spanning trees for the graph.

If G is a weighed graph and e is an edge of G, then w(e) denotes the weight of e and w(G) denotes the total weight of G.

The problem of finding a minimum spanning tree for a graph is certainly solvable. One solution is to list all spanning trees for the graph, compute the total weight of each, and choose one for which this total is a minimum. (Note that the well-ordering principle for the integers guarantees the existence of such a minimum total.) This solution, how- ever, is inefficient in its use of computing time because the number of distinct spanning trees is so large. For instance, a complete graph with n vertices has nn−2 spanning trees. Even using the fastest computers available today, examining all such trees in a graph with approximately 100 vertices would require more time than is estimated to remain in the life of the universe.

In 1956 and 1957 Joseph B. Kruskal and Robert C. Prim each described much more efficient algorithms to construct minimum spanning trees. Even for large graphs, both algorithms can be implemented so as to take relatively short computing times.

Kruskal’s Algorithm In Kruskal’s algorithm, the edges of a connected weighted graph are examined one by

Co ur

te sy

of Jo

se ph

K ru

sk al

Joseph Kruskal (born 1928)

one in order of increasing weight. At each stage the edge being examined is added to what will become the minimum spanning tree, provided that this addition does not create a circuit. After n − 1 edges have been added (where n is the number of vertices of the graph), these edges, together with the vertices of the graph, form a minimum spanning tree for the graph.

Algorithm 10.7.1 Kruskal

Input: G [a connected weighted graph with n vertices, where n is a positive integer] Algorithm Body: [Build a subgraph T of G to consist of all the vertices of G with edges added in order of increasing weight. At each stage, let m be the number of edges of T .]

1. Initialize T to have all the vertices of G and no edges.

2. Let E be the set of all edges of G, and let m := 0. 3. while (m < n − 1)

3a. Find an edge e in E of least weight. 3b. Delete e from E . 3c. if addition of e to the edge set of T does not produce a circuit

then add e to the edge set of T and set m := m + 1 end while

Output: T [T is a minimum spanning tree for G.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 705

The following example shows how Kruskal’s algorithm works for the graph of the airline route system.

Example 10.7.2 Action of Kruskal’s Algorithm

Describe the action of Kruskal’s algorithm on the graph shown in Figure 10.7.4, where n = 8.

St. Louis

Chicago

Minneapolis

Milwaukee Detroit

Cincinnati

Louisville

Nashville

355

695 74

262

242

348

151

83

230

269 306

Figure 10.7.4

Solution Iteration Number Edge Considered Weight Action Taken 1 Chicago–Milwaukee 74 added 2 Louisville–Cincinnati 83 added 3 Louisville–Nashville 151 added 4 Cincinnati–Detroit 230 added 5 St. Louis–Louisville 242 added 6 St. Louis–Chicago 262 added 7 Chicago–Louisville 269 not added 8 Louisville–Detroit 306 not added 9 Louisville–Milwaukee 348 not added

10 Minneapolis–Chicago 355 added

The tree produced by Kruskal’s algorithm is shown in Figure 10.7.5.

Minneapolis

Milwaukee

Chicago

355

74

262

St. Louis 242

Nashville

Louisville

Cincinnati

Detroit

151

83

230

Figure 10.7.5 ■

When Kruskal’s algorithm is used on a graph in which some edges have the same weight as others, more than one minimum spanning tree can occur as output. To make

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

706 Chapter 10 Graphs and Trees

the output unique, the edges of the graph can be placed in an array and edges having the same weight can be added in the order they appear in the array.

It is not obvious from the description of Kruskal’s algorithm that it does what it is supposed to do. To be specific, what guarantees that it is possible at each stage to find an edge of least weight whose addition does not produce a circuit? And if such edges can be found, what guarantees that they will all eventually connect? And if they do connect, what guarantees that the resulting tree has minimum weight? Of course, the mere fact that Kruskal’s algorithm is printed in this book may lead you to believe that everything works out. But the questions above are real, and they deserve serious answers.

Theorem 10.7.2 Correctness of Kruskal’s Algorithm

When a connected, weighted graph is input to Kruskal’s algorithm, the output is a minimum spanning tree.

Proof:

Suppose that G is a connected, weighted graph with n vertices and that T is a sub- graph of G produced when G is input to Kruskal’s algorithm. Clearly T is circuit- free [since no edge that completes a circuit is ever added to T]. Also T is connected. For as long as T has more than one connected component, the set of edges of G that can be added to T without creating a circuit is nonempty. [The reason is that since G is connected, given any vertex v1 in one connected component C1 of T and any vertex v2 in another connected component C2, there is a path in G from v1 to v2. Since C1 and C2 are distinct, there is an edge e of this path that is not in T . Adding e to T does not create a circuit in T , because deletion of an edge from a circuit does not disconnect a graph and deletion of e would.] The preceding arguments show that T is circuit-free and connected. Since by construction T contains every vertex of G, T is a spanning tree for G.

Next we show that T has minimum weight. Let T1 be any minimum spanning tree for G such that the number of edges T1 and T have in common is a maximum. Suppose that T ̸= T1. Then there is an edge e in T that is not an edge of T1. [Since trees T and T1 both have the same vertex set, if they differ at all, they must have different, but same-size, edge sets.] Now adding e to T1 produces a graph with a unique circuit (see exercise 19 at the end of this section). Let e′ be an edge of this circuit such that e′ is not in T . [Such an edge must exist because T is a tree and hence circuit-free.] Let T2 be the graph obtained from T1 by removing e′ and adding e. This situation is illustrated below.

e (add to T1 to form T2.)

e' (remove from T1 to form T2.)

The entire graph is G. T1 has black edges. e is in T but not T1. e′ is in T1 but not T .

Note that T2 has n − 1 edges and n vertices and that T2 is connected [since by Lemma 10.5.3 the subgraph obtained by removing an edge from a circuit in a connected graph is connected]. Consequently, T2 is a spanning tree for G. In addition,

w(T2) = w(T1)− w(e′) + w(e).

Now w(e) ≤ w(e′) because at the stage in Kruskal’s algorithm when e was added to T , e′ was available to be added [since it was not already in T , and at that stage its

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 707

addition could not produce a circuit since e was not in T ], and e′ would have been added had its weight been less than that of e. Thus

w(T2) = w(T1)− [w(e′)− w(e)]︸ ︷︷ ︸ ≥0

≤ w(T1). But T1 is a minimum spanning tree. Since T2 is a spanning tree with weight less than or equal to the weight of T1, T2 is also a minimum spanning tree for G.

Finally, note that by construction, T2 has one more edge in common with T than T1 does, which contradicts the choice of T1 as a minimum spanning tree for G with a maximum number of edges in common with T . Thus the supposition that T ̸= T1 is false, and hence T itself is a minimum spanning tree for G.

Prim’s Algorithm Prim’s algorithm works differently from Kruskal’s. It builds a minimum spanning tree T

Co ur

te sy

of Al

ca te

l-L uc

en t

Te ch

no lo

gi es

Robert Prim (born 1921)

by expanding outward in connected links from some vertex. One edge and one vertex are added at each stage. The edge added is the one of least weight that connects the vertices already in T with those not in T , and the vertex is the endpoint of this edge that is not already in T .

Algorithm 10.7.2

Input: G [a connected weighted graph with n vertices where n is a positive integer] Algorithm Body: [Build a subgraph T of G by starting with any vertex v of G and attaching edges (with their endpoints) one by one to an as-yet-unconnected vertex of G, each time choosing an edge of least weight that is adjacent to a vertex of T .]

1. Pick a vertex v of G and let T be the graph with one vertex, v, and no edges.

2. Let V be the set of all vertices of G except v.

3. for i := 1 to n − 1 3a. Find an edge e of G such that (1) e connects T to one of the vertices in

V , and (2) e has the least weight of all edges connecting T to a vertex in V . Let w be the endpoint of e that is in V .

3b. Add e and w to the edge and vertex sets of T , and delete w from V . next i

Output: T [T is a minimum spanning tree for G.]

The following example shows how Prim’s algorithm works for the graph of the airline route system.

Example 10.7.3 Action of Prim’s Algorithm

Describe the action of Prim’s algorithm for the graph in Figure 10.7.6 using the Min- neapolis vertex as a starting point.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

708 Chapter 10 Graphs and Trees

St. Louis

Chicago

Minneapolis

Milwaukee Detroit

Cincinnati

Louisville

Nashville

355

695 74

262

242

348

151

83

230

269 306

Figure 10.7.6

Solution Iteration Number Vertex Added Edge Added Weight 0 Minneapolis 1 Chicago Minneapolis–Chicago 355 2 Milwaukee Chicago–Milwaukee 74 3 St. Louis Chicago–St. Louis 262 4 Louisville St. Louis–Louisville 242 5 Cincinnati Louisville–Cincinnati 83 6 Nashville Louisville–Nashville 151 7 Detroit Cincinnati–Detroit 230 ■

Note that the tree obtained is the same as that obtained by Kruskal’s algorithm, but the edges are added in a different order.

As with Kruskal’s algorithm, in order to ensure a unique output, the edges of the graph could be placed in an array and those with the same weight could be added in the order they appear in the array. It is not hard to see that when a connected graph is input to Prim’s algorithm, the result is a spanning tree. What is not so clear is that this spanning tree is a minimum. The proof of the following theorem establishes that it is.

Theorem 10.7.3 Correctness of Prim’s Algorithm

When a connected, weighted graph G is input to Prim’s algorithm, the output is a minimum spanning tree for G.

Proof:

Let G be a connected, weighted graph, and suppose G is input to Prim’s algorithm. At each stage of execution of the algorithm, an edge must be found that connects a vertex in a subgraph to a vertex outside the subgraph. As long as there are vertices outside the subgraph, the connectedness of G ensures that such an edge can always be found. [For if one vertex in the subgraph and one vertex outside it are chosen, then by the connectedness of G there is a walk in G linking the two. As one travels along this walk, at some point one moves along an edge from a vertex inside the subgraph to a vertex outside the subgraph.]

Now it is clear that the output T of Prim’s algorithm is a tree because the edge and vertex added to T at each stage are connected to other edges and vertices of T

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 709

and because at no stage is a circuit created since each edge added connects vertices in two disconnected sets. [Consequently, removal of a newly added edge produces a disconnected graph, whereas by Lemma 10.5.3, removal of an edge from a circuit produces a connected graph.] Also, T includes every vertex of G because T , being a tree with n − 1 edges, has n vertices [and that is all G has]. Thus T is a spanning tree for G.

Next we show that T has minimum weight. Let T1 be a minimum spanning tree for G such that the number of edges T1 and T have in common is a maximum. Suppose that T ̸= T1. Then there is an edge e in T that is not an edge of T1. [Since trees T and T1 both have the same vertex set if they differ at all, they must have different, same-size edge sets.] Of all such edges, let e be the last that was added when T was constructed using Prim’s algorithm. Let S be the set of vertices of T just before the addition of e. Then one endpoint, say v of e, is in S and the other, say w, is not. Since T1 is a spanning tree, there is a path in T1 joining v to w. And since v ∈ S and w ̸∈ S, as one travels along this path, one must encounter an edge e′ that joins a vertex in S to one that is not in S and that therefore is not in T because e was the last edge added to T . Now at the stage when e was added to T, e′ could also have been added and it would have been added instead of e had its weight been less than that of e. Since e′ was not added at that stage, we conclude that

w(e′) ≥ w(e). Let T2 be the graph obtained from T1 by removing e′ and adding e. [Thus T2

has one more edge in common with T than T1 does.] Note that T2 is a tree. The rea- son is that since e′ is part of a path in T1 from v to w, and e connects v and w, adding e to T1 creates a circuit. When e′ is removed from this circuit, the resulting subgraph remains connected. In fact, T2 is a spanning tree for G since no vertices were removed in forming T2 from T1. The argument showing that w(T2) ≤ w(T1) is left as an exercise. [It is virtually identical to part of the proof of Theorem 10.7.2.] It follows that T2 is a minimum spanning tree for G.

By construction, T2 has one more edge in common with T than T1, does which contradicts the choice of T1 as a minimum spanning tree for G with a maximum number of edges in common with T . It follows that T = T1, and hence T itself is a minimum spanning tree for G.

Example 10.7.4 Finding Minimum Spanning Trees

Find all minimum spanning trees for the following graph. Use Kruskal’s algorithm and Prim’s algorithm starting at vertex a. Indicate the order in which edges are added to form each tree.

a

b

c

d

e

f

6 5

1

6

4 3

3

2

Solution When Kruskal’s algorithm is applied, edges are added in one of the following two orders:

1. {d, f }, {a, c}, {a, b}, {c, d}, {d, e} 2. {d, f }, {a, c}, {b, c}, {c, d}, {d, e}

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

710 Chapter 10 Graphs and Trees

When Prim’s algorithm is applied starting at a, edges are added in one of the following two orders:

1. {a, c}, {a, b}, {c, d}, {d, f }, {d, e} 2. {a, c}, {b, c}, {c, d}, {d, f }, {d, e} Thus, as shown below, there are two distinct minimum spanning trees for this graph.

aa

c e

dbdb 3

2 c e

2

4 5

11

ff 5 4

3

)b()a( ■

Dijkstra’s Shortest Path Algorithm Although the trees produced by Kruskal’s and Prim’s algorithms have the least pos-

sible total weight compared to all other spanning trees for the given graph, they do not always reveal the shortest distance between any two points on the graph. For instance, according to the complete route system shown in Figure 10.7.3, one can fly directly from Nashville to Minneapolis for a distance of 695 miles, whereas if you use the minimum spanning tree shown in Figure 10.7.5 the only way to fly from Nashville to Minneapolis is by going through Louisville, St. Louis, and Chicago, which gives a total distance of 151 + 242 + 262 + 355 = 1, 010 miles and the unpleasantness of three changes of plane.

In 1959 the computing pioneer, Edsgar Dijkstra (see Section 5.5), developed an algo- rithm to find the shortest path between a starting vertex and an ending vertex in a weighted graph in which all the weights are positive. It is somewhat similar to Prim’s algorithm in that it works outward from a starting vertex a, adding vertices and edges one by one to construct a tree T . However, it differs from Prim’s algorithm in the way it chooses the next vertex to add, ensuring that for each added vertex v, the length of the shortest path from a to v has been identified.

At the start of execution of the algorithm, each vertex u of G is given a label L(u), which indicates the current best estimate of the length of the shortest path from a to u. L(a) is initially set equal to 0 because the shortest path from a to a has length zero, but, because there is no previous information about the lengths of the shortest paths from a to any other vertices of G, the label L(u) of each vertex u other than a is initially set equal to a number, denoted ∞, that is greater than the sum of the weights of all the edges of G. As execution of the algorithm progresses, the values of L(u) are changed, eventually becoming the actual lengths of the shortest paths from a to u in G.

Because T is built up outward from a, at each stage of execution of the algorithm the only vertices that are candidates to join T are those that are adjacent to at least one vertex of T . Thus at each stage of Dijkstra’s algorithm, the graph G can be thought of as divided into three parts: the tree T that is being built up, the set of “fringe” vertices that are adjacent to at least one vertex of the tree, and the rest of the vertices of G. Each fringe vertex is a candidate to be the next vertex added to T . The one that is chosen is the one for which the length of the shortest path to it from a through T is a minimum among all the vertices in the fringe.

An essential observation underlying Dijkstra’s algorithm is that after each addition of a vertex v to T , the only fringe vertices for which a shorter path from a might be found are those that are adjacent to v [because the length of the path from a to v was a minimum among all the paths from a to vertices in what was then the fringe]. So after each addition of a vertex v to T , each fringe vertex u adjacent to v is examined and two numbers are

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 711

compared: the current value of L(u) and the value of L(v) + w(v, u), where L(v) is the length of the shortest path to v (in T ) and w(v, u) is the weight of the edge joining v and u. If L(v) + w(v, u) < L(u), then the value of L(u) is changed to L(v) + w(v, u).

At the beginning of execution of the algorithm, the tree consists only of the vertex a, and L(a) = 0. When execution terminates, L(z) is the length of a shortest path from a to z.

As with Kruskal’s and Prim’s algorithms for finding minimum spanning trees, there is a simple but dramatically inefficient way to find the shortest path from a to z: compute the lengths of all the paths and choose one that is shortest. The problem is that even for relatively small graphs using this method to find a shortest path could require billions of years, whereas Dijkstra’s algorithm could do the job in a few seconds.

Algorithm 10.7.3 Dijkstra

Input: G [a connected simple graph with a positive weight for every edge],∞ [a num- ber greater than the sum of the weights of all the edges in the graph], w(u, v) [the weight of edge {u, v}], a [the starting vertex], z [the ending vertex] Algorithm Body:

1. Initialize T to be the graph with vertex a and no edges. Let V (T ) be the set of vertices of T , and let E(T ) be the set of edges of T .

2. Let L(a) = 0, and for all vertices in G except a, let L(u) =∞. [The number L(x) is called the label of x.]

3. Initialize v to equal a and F to be {a}. [The symbol v is used to denote the vertex most recently added to T.]

4. while (z ̸∈ V (T )) 4a. F := (F − {v})∪ {vertices that are adjacent to v and are not in V (T )}

[The set F is called the fringe. Each time a vertex is added to T, it is removed from the fringe and the vertices adjacent to it are added to the fringe if they are not already in the fringe or the tree T.]

4b. For each vertex u that is adjacent to v and is not in V (T ), if L(v) + w(v, u) < L(u) then

L(u) := L(v) + w(v, u)

D(u) := v [Note that adding v to T does not affect the labels of any vertices in the fringe F except those adjacent to v. Also, when L(u) is changed to a smaller value, the notation D(u) is introduced to keep track of which vertex in T gave rise to the smaller value.]

Note The unique path in the tree T from a to z is the shortest path in G from a to z.

4c. Find a vertex x in F with the smallest label Add vertex x to V (T ), and add edge {D(x), x} to E(T ) v := x [This statement sets up the notation for the next iteration of the loop.]

end while

Output: L(z) [L(z), a nonnegative integer, is the length of the shortest path from a to z.]

The action of Dijkstra’s algorithm is illustrated by the flow of the drawings in Example 10.7.5.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

712 Chapter 10 Graphs and Trees

Example 10.7.5 Action of Dijkstra’s Algorithm

Show the steps in the execution of Dijkstra’s shortest path algorithm for the graph shown below with starting vertex a and ending vertex z.

a

b

c

d

e

z

12

7

6

25 3

6

4

Solution Step 1: Going into the while loop: V (T ) = {a}, E(T ) = ∅, and F = {a}

a

b

c

d

e

z

12

7

1

6

25 3

4

During iteration: F = {b, c}, L(b) = 3, L(c) = 4. Since L(b) < L(c), b is added to V (T ) and {a, b} is added to E(T ).

Step 2: Going into the while loop: V (T ) = {a, b}, E(T ) = {{a, b}}

a

b

c

d

e

z

12

7

1

6

25 3

4

During iteration: F = {c, d, e}, L(c) = 4, L(d) = 9, L(e) = 8. Since L(c) < L(d) and L(c) < L(e), c is added to V (T ) and {a, c} is added to E(T ).

Step 3: Going into the while loop: V (T ) = {a, b, c}, E(T ) = {{a, b}, {a, c}}

a

b

c

d

e

z

12

7

1

6

25 3

4

During iteration: F = {d, e}, L(d) = 9, L(e) = 5 L(e) becomes 5 because ace, which has length 5, is a shorter path to e than abe, which has length 8. Since L(e) < L(d), e is added to V (T ) and {c, e} is added to E(T ).

Step 4: Going into the while loop: V (T ) = {a, b, c, e}, E(T ) = {{a, b}, {a, c}, {c, e}}

a

b

c

d

e

z

12

7

1

6

25 3

4

During iteration: F = {d, z}, L(d) = 7, L(z) = 17 L(d) becomes 7 because aced, which has length 7, is a shorter path to d than abd, which has length 9. Since L(d) < L(z), d is added to V (T ) and {e, d} is added to E(T ).

Step 5: Going into the while loop: V (T ) = {a, b, c, e, d}, E(T ) = {{a, b},{a, c}, {c, e}, {e, d}}

a

b

c

d

e

z

12

7

1

6

25 3

4

During iteration: F = {z}, L(z) = 14 L(z) becomes 14 because acedz, which has length 14, is a shorter path to d than abdz, which has length 17. Since z is the only vertex in F , its label is a minimum, and so z is added to V (T ) and {e, z} is added to E(T ).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 713

Execution of the algorithm terminates at this point because z ∈ V (T ). The shortest path from a to z has length L(z) = 14. ■

Keeping track of the steps in a table is a convenient way to show the action of Dijk- stra’s algorithm. Table 10.7.1 does this for the graph in Example 10.7.5.

Table 10.7.1

Step V (T ) E(T ) F L(a) L(b) L(c) L(d) L(e) L(z)

0 {a} ∅ {a} 0 ∞ ∞ ∞ ∞ ∞ 1 {a} ∅ {b, c} 0 3 4 ∞ ∞ ∞ 2 {a, b} {{a, b}} {c, d, e} 0 3 4 9 8 ∞ 3 {a, b, c} {{a, b}, {a, c}} {d, e} 0 3 4 9 5 ∞ 4 {a, b, c, e} {{a, b}, {a, c}, {c, e}} {d, z} 0 3 4 7 5 17 5 {a, b, c, e, d} {{a, b}, {a, c}, {c, e}, {e, d}} {z} 0 3 4 7 5 14 6 {a, b, c, e, d, z} {{a, b}, {a, c}, {c, e}, {e, d}, {e, z}}

It is clear that Dijkstra’s algorithm keeps adding vertices to I until it has added z. The proof of the following theorem shows that when the algorithm terminates, the label z goes the length of the shortest path to it from a.

Theorem 10.7.4 Correctness of Dijkstra’s Algorithm

When a connected, simple graph with a positive weight for every edge is input to Dijkstra’s algorithm with starting vertex a and ending vertex z, the output is the length of a shortest path from a to z.

Proof:

Let G be a connected, weighted graph with no loops or parallel edges and with a positive weight for every edge. Let T be the graph built up by Dijkstra’s algorithm, and for each vertex u in G, let L(u) be the label given by the algorithm to vertex u. For each integer n ≥ 0, let the property P(n) be the sentence

After the nth iteration of the while loop in Dijkstra’s algorithm, (1) T is a tree, and (2) for every vertex v in T, L(v) is the length of a ← P(n) shortest path in G from a to v.

We will show by mathematical induction that P(n) is true for all integers n from 0 through the termination of the algorithm.

Show that P(0) is true: When n = 0, the graph T is a tree because it is defined to consist only of the vertex a and no edges. In addition, L(a) is the length of the shortest path from a to a because the initial value of L(a) is 0.

Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is also true: Let k be any integer with k ≥ 0 and suppose that

After the kth iteration of the while loop in Dijkstra’s algorithm, (1) T ← P(k) is a tree, and (2) for every vertex v in T, L(v) is the length of a inductive shortest path in G from a to v.

hypothesis

We must show that

After the (k + 1)st iteration of the while loop in Dijkstra’s algorithm, (1) T is a tree, and (2) for every vertex v in T, ← P(k + 1) L(v) is the length of a shortest path in G from a to v.

continued on page 714

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

714 Chapter 10 Graphs and Trees

So suppose that after the (k + 1)st iteration of the while loop in Dikjstra’s algorithm, the vertex v and edge {x, v} have been added to T , where x is in V (T ). Clearly the new value of T is a tree because adding a new vertex and edge to a tree does not create a circuit and does not disconnect the tree. By inductive hypothesis for each vertex y in the tree before the addition of v, L(y) is the length of a shortest path from a to y. So it remains only to show that L(v) is the length of a shortest path from a to v.

Now, according to the algorithm, the final value of L(v) = L(x) + w(x, v). Con- sider any shortest path from a to v, and let {s, t} be the first edge in this path to leave T , where s ∈ V (T ) and t ̸∈ V (T ). This situation is illustrated below.

a s

x

v

t

Let L S P(a, v) be the length of a shortest path from a to v, and let L S P(a, s) be the length of a shortest path from a to s. Observe that

L S P(a, v) ≥ L S P(a, s) + w(s, t) because the path from t to v has length ≥ 0 ≥ L(s) + w(s, t) by inductive hypothesis because s is a vertex in T

≥ L(x) + w(x, v) t is in the fringe of the tree, and so if L(s)+w(s, t) were less than L(x)+w(x, v) then t would have been added to T instead of v.

On the other hand

L(x) + w(x, v) ≥ L S P(a, v) because L(x)+w(x , v) is the length of a path from a to v and so it is greater than or equal to the length of the shortest path from a to v.

It follows that L S P(a, v) = L(x) + w(x, v), and, since L(v) = L(x) + w(x, v), L(v) is the length of a shortest path from a to v. This completes the proof by math- ematical induction.

The algorithm terminates as soon as z is in T , and, since we have proved that the label of every vertex in the tree gives the length of the shortest path to it from a, then, in particular, L(z) is the length of a shortest path from a to z.

Test Yourself 1. A spanning tree for a graph G is _____.

2. A weighted graph is a graph for which _____, and the total weight of the graph is _____.

3. A minimum spanning tree for a connected, weighted graph is _____.

4. In Kruskal’s algorithm, the edges of a connected, weighted graph are examined one by one in order of _____ starting with _____.

5. In Prim’s algorithm, a minimum spanning tree is built by expanding outward from an _____ in a sequence of ____.

6. In Dijkstra’s algorithm, a vertex is in the fringe if it is _____ vertex in the tree that is being built up.

7. At each stage of Dijkstra’s algorithm, the vertex that is added to the tree is a vertex in the fringe whose label is a _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

10.7 Spanning Trees and Shortest Paths 715

Exercise Set 10.7 Find all possible spanning trees for each of the graphs in 1 and 2.

1. a b

d c

2. v0 v1

v3 v2

Find a spanning tree for each of the graphs in 3 and 4.

3. a

g

b d

c e

f

4.

z

r s t

u

y

x

v w

Use Kruskal’s algorithm to find a minimum spanning tree for each of the graphs in 5 and 6. Indicate the order in which edges are added to form each tree.

5.

a

b c

e

g

d

f

1

8 10

9

7

3 4

2

6 5

6. v1v0

v7v6

v5 v4 v3 v2

12

13

10 2 4 7

8 15

5

18

20

19

Use Prim’s algorithm starting with vertex a or v0 to find a min- imum spanning tree for each of the graphs in 7 and 8. Indicate the order in which edges are added to form each tree.

7. The graph of exercise 5. 8. The graph of exercise 6.

For each of the graphs in 9 and 10, find all minimum spanning trees that can be obtained using (a) Kruskal’s algorithm and (b) Prim’s algorithm starting with vertex a or t . Indicate the order in which edges are added to form each tree.

9.

4

4

4

1

5

3

3 7

7 11

12

10

a

g f

b

c

d e

10. t

w x y z

u v

3 15 1 8 10 7

7

5 2 5

2

11. A pipeline is to be built that will link six cities. The cost (in hundreds of millions of dollars) of constructing each poten- tial link depends on distance and terrain and is shown in the weighted graph below. Find a system of pipelines to con- nect all the cities and yet minimize the total cost.

Albuquerque Phoenix

Salt Lake City Cheyenne

Denver

Amarillo

1.8

2.2

1.6

1.2

1.9 2.5

2.9

0.8

1.5

1.1

1.7

12. Use Dijkstra’s algorithm for the airline route system of Fig- ure 10.7.3 to find the shortest distance from Nashville to Minneapolis. Make a table similar to Table 10.7.1 to show the action of the algorithm.

Use Dijkstra’s algorithm to find the shortest path from a to z for each of the graphs in 13–16. In each case make tables similar to Table 10.7.1 to show the action of the algorithm.

13.

a

b

d

c

e

z

2

8

10

3

15 2

1

14.

a

b

e

d

g

z

1

20

f

c

87 1

1 1

4 1 1

15. The graph of exercise 9 with a = a and z = f 16. The graph of exercise 10 with a = u and z = w 17. Prove part (2) of Proposition 10.7.1: Any two spanning

trees for a graph have the same number of edges.

18. Given any two distinct vertices of a tree, there exists a unique path from one to the other. a. Give an informal justification for the above statement. b.✶ Write a formal proof of the above statement.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

716 Chapter 10 Graphs and Trees

19. Prove that if G is a graph with spanning tree T and e is an edge of G that is not in T , then the graph obtained by adding e to T contains one and only one set of edges that forms a circuit.

20. Suppose G is a connected graph and T is a circuit-free sub- graph of G. Suppose also that if any edge e of G not in T is added to T , the resulting graph contains a circuit. Prove that T is a spanning tree for G.

21. a. Suppose T1 and T2 are two different spanning trees for a graph G. Must T1 and T2 have an edge in common? Prove or give a counterexample.

b. Suppose that the graph G in part (a) is simple. Must T1 and T2 have an edge in common? Prove or give a coun- terexample.

22.H Prove that an edge e is contained in every spanning tree for a connected graph G if, and only if, removal of e discon- nects G.

23. Consider the spanning trees T1 and T2 in the proof of The- orem 10.7.3. Prove that w(T2) ≤ w(T1).

24. Suppose that T is a minimum spanning tree for a connected, weighted graph G and that G contains an edge e (not a loop) that is not in T . Let v and w be the endpoints of e. By exer- cise 18 there is a unique path in T from v to w. Let e′ be any edge of this path. Prove that w(e′) ≤ w(e).

25.H Prove that if G is a connected, weighted graph and e is an edge of G (not a loop) that has smaller weight than any other edge of G, then e is in every minimum spanning tree for G.

26.✶ If G is a connected, weighted graph and no two edges of G have the same weight, does there exist a unique minimum spanning tree for G? Use the result of exercise 19 to help justify your answer.

27.✶ Prove that if G is a connected, weighted graph and e is an edge of G that (1) has greater weight than any other edge of G and (2) is in a circuit of G, then there is no minimum spanning tree T for G such that e is in T .

28. Suppose a disconnected graph is input to Kruskal’s algo- rithm. What will be the output?

29. Suppose a disconnected graph is input to Prim’s algorithm. What will be the output?

30. Prove that if a connected, weighted graph G is input to Algorithm 10.7.4 (shown below), the output is a minimum spanning tree for G.

Algorithm 10.7.4

Input: G [a connected graph]

Algorithm Body:

1. T := G. 2. E := the set of all edges of G, m := the number of edges

of G.

3. while (m > 0)

3a. Find an edge e in E that has maximal weight. 3b. Remove e from E and set m := m − 1. 3c. if the subgraph obtained when e is removed from

the edge set of T is connected then remove e from the edge set of T

end while

Output: T [a minimum spanning tree for G]

31. Modify Algorithm 10.7.3 so that the output consists of the sequence of edges in the shortest path from a to z.

Answers for Test Yourself 1. a subgraph of G that contains every vertex of G and is a tree. 2. each edge has an associated positive real number weight; the sum of the weights of all the edges of the graph 3. a spanning tree that has the least possible total weight compared to all other spanning trees for the graph 4. weight; an edge of least weight 5. initial vertex; adjacent vertices and edges 6. adjacent to a 7. minimum among all those in the fringe

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

717

CHAPTER 11

ANALYSIS OF ALGORITHM EFFICIENCY

In 1637 the French mathematician and philosopher René Descartes published his great philosophical work Discourse on Method. An appendix to this work, called “Geometry,” laid the foundation for the subject of analytic geometry, in which geometric methods are applied to the study of algebraic objects, such as functions, equations, and inequalities, and algebraic methods are used to study geometric objects, such as straight lines, circles, and half-planes.

B et

tm an

n/ CO

R B

IS

René Descartes (1596–1650)

The analytic geometry of Descartes provides the foundation for the main topic of this chapter: the big-O, big-Omega, and big-Theta notations and their application to the analysis of algorithms. In Section 11.1 we brie y discuss certain properties of graphs of real-valued functions of a real variable that are needed to understand these notations. In Section 11.2 we define the notations and apply them to power and polynomial functions, and in Section 11.3 we show how the notations are used to study the efficiency of algo- rithms. Because the analysis of algorithms often involves logarithmic and exponential functions, we develop the needed properties of these functions in Section 11.4 and use them to analyze several algorithms in Section 11.5.

11.1 Real-Valued Functions of a Real Variable and Their Graphs The first precept was never to accept a thing as true until I knew it as such without a single doubt — René Descartes, 1637

A Cartesian plane or two-dimensional Cartesian coordinate system is a pictorial representation of R × R obtained by setting up a one-to-one correspondence between ordered pairs of real numbers and points in a Euclidean plane. To obtain it, two perpen- dicular lines, called the horizontal and vertical axes, are drawn in the plane. Their point of intersection is called the origin, and a unit of distance is chosen for each axis. An ordered pair (x, y) of real numbers corresponds to the point P that lies |x | units to the right or left of the vertical axis and |y| units above or below the horizontal axis. On each axis the positive direction is marked with an arrow.

A real-valued function of a real variable is a function from one set of real numbers to another. If f is such a function, then for each real number x in the domain of f , there is a unique corresponding real number f (x). Thus it is possible to define the graph of f as follows:

• Definition Let f be a real-valued function of a real variable. The graph of f is the set of all points (x, y) in the Cartesian coordinate plane with the property that x is in the domain of f and y = f (x).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

718 Chapter 11 Analysis of Algorithm Efficiency

The definition of graph (see Figure 11.1.1) means that for all x in the domain of f :

y = f (x) ⇔ the point (x, y) lies on the graph of f.

Graph of f

(x, f (x))

x

f (x) = the height of the graph of f at x

Figure 11.1.1 Graph of a Function f

Note that if f (x) can be written as an algebraic expression in x , the graph of the function f is the same as the graph of the equation y = f (x) where x is restricted to lie in the domain of f .

Power Functions A function that sends a real number x to a particular power, xa , is called a power function. For applications in computer science, we are almost invariably concerned with situations where x and a are nonnegative, and so we restrict our definition to these cases.

• Definition Let a be any nonnegative real number. Define pa , the power function with expo- nent a, as follows:

pa(x) = xa for each nonnegative real number x .

Example 11.1.1 Graphs of Power Functions

Plot the graphs of the power functions p0, p1/2, p1, and p2 on the same coordinate axes.

Solution Because the power function with exponent zero satisfies p0(x) = x0 = 1 for all nonnegative numbers x ,∗ all points of the form (x, 1) lie on the graph of p0 for all such x . So the graph is just a horizontal half-line of height 1 lying above the horizon- tal axis. Similarly, p1(x) = x for all nonnegative numbers x , and so the graph of p1 consists of all points of the form (x, x) where x is nonnegative. The graph is therefore the half-line of slope 1 that emanates from (0, 0).

Since for each nonnegative number x, p1/2(x) = x1/2 = √

x , any point with coordi- nates (x,

√ x), where x is nonnegative, is on the graph of p1/2. For instance, the graph of

∗As in Section 9.7 (see page 598), for simplicity we define 00 = 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.1 Real-Valued Functions of a Real Variable and Their Graphs 719

p1/2 contains the points (0, 0), (1, 1), (4, 2), and (9, 3). Similarly, since p2(x) = x2, any point with coordinates (x, x2) lies on the graph of p2. Thus, for instance, the graph of p2 contains the points (0, 0), (1, 1), (2, 4), and (3, 9).

The graphs of all four functions are shown in Figure 11.1.2.

x

y y = x2

y = x

y = x1/2

y = 1

Figure 11.1.2 Graphs of Some Power Functions ■

The Floor Function The floor and ceiling functions arise in many computer science contexts. Example 11.1.2 illustrates the graph of the floor function. In exercise 6 at the end of this section you are asked to draw the graph of the ceiling function.

Example 11.1.2 Graph of the Floor Function

Recall that each real number either is an integer itself or sits between two consecutive integers: For each real number x , there exists a unique integer n such that n ≤ x < n + 1. The floor of a number is the integer immediately to its left on the number line. More formally, the floor function F is defined by the rule

For each real number x ,

F(x) = ⌊x⌋ = the greatest integer that is less than or equal to x = the unique integer n such that n ≤ x < n + 1.

Graph the floor function.

Solution If n is any integer, then for each real number x in the interval n ≤ x < n + 1, the floor of x, ⌊x⌋, equals n. Thus on each such interval, the graph of the floor function is horizontal; for each x in the interval, the height of the graph is n.

It follows that the graph of the floor function consists of horizontal line segments, like a staircase, as shown in Figure 11.1.3. The open circles at the right-hand edge of each step are used to show that those points are not on the graph.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

720 Chapter 11 Analysis of Algorithm Efficiency

x

y

y = ⌊x⌋

1–1–2–3–4–5 2 3 54

–1

1

2

3

–2

–3

Figure 11.1.3 Graph of the Floor Function ■

Graphing Functions Defined on Sets of Integers Many real-valued functions used in computer science are defined on sets of integers and not on intervals of real numbers. Suppose you know what the graph of a function looks like when it is given by a certain formula on an interval of real numbers. You can obtain the graph of the function defined by the same formula on the integers in the interval by selecting out only those points on the known graph with integers as their first coordi- nates. For instance, if f is the function defined by the same formula as the power function p1 but having as its domain the set of nonnegative integers, then f (n) = n for all non- negative integers n. The graphs of p1, reproduced from Example 11.1.2, and f are shown side-by-side below.

1 2 3 4

1

2

3

4

1 2 3 4

1

2

3

4

Graph of p1 where p1(x) = x for all nonnegative real numbers x

Graph of f where f (n) = n for all nonnegative integers n

Example 11.1.3 Graph of a Function Defined on a Set of Integers

Consider an integer version of the power function p1/2. In other words, define a function g by the formula g(n) = n1/2 for all nonnegative integers n. Draw the graph of g.

Solution Look back at the graph of p1/2 in Figure 11.1.2. Draw the graph of g by repro- ducing only those points on the graph of p1/2 with integer first coordinates. Thus for each nonnegative integer n, the point (n, n1/2) is on the graph of g.

1 2 3 4 5 6 7 8 9 10 11 12

1

2

3

4

Graph of g where g(n) = n1/2 for all nonnegative integers n ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.1 Real-Valued Functions of a Real Variable and Their Graphs 721

Graph of a Multiple of a Function A multiple of a function is obtained by multiplying every value of the function by a fixed number. To understand the concept of O-notation, it is helpful to understand the relation between the graph of a function and the graph of a multiple of the function.

• Definition Let f be a real-valued function of a real variable and let M be any real number. The function M f , called the multiple of f by M or M times f , is the real-valued function with the same domain as f that is defined by the rule

(M f )(x) = M ·( f (x)) for all x ∈ domain of f.

If the graph of a function is known, the graph of any multiple can easily be deduced. Specifically, if f is a function and M is a real number, the height of the graph of M f at any real number x is M times the quantity f (x). To sketch the graph of M f from the graph of f , you plot the heights M ·( f (x)) on the basis of knowledge of M and visual inspection of the heights f (x).

Example 11.1.4 Graph of a Multiple of a Function

Let f be the function whose graph is shown below. Sketch the graph of 2 f .

Graph of f

y

1–1–2–3–4–5–6 2 3 4 5 6

1

–1

–2

2

Solution At each real number x , you obtain the height of the graph of 2 f by measuring the height of the graph of f at x and multiplying that number by 2. The result is the following graph. Note that the general shapes of f and 2 f are very similar, but the graph of 2 f is “stretched out”: the “highs” are twice as high and the “lows” are twice as low.

Graph of 2 f

y

1–1–2–3–4–5–6 2 3 4 5 6

1

–1

–2

–3

–4

2

3

4

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

722 Chapter 11 Analysis of Algorithm Efficiency

Increasing and Decreasing Functions Consider the absolute value function, A, which is defined as follows:

A(x) = |x | = {

x if x ≥ 0 −x if x < 0 for all real numbers x .

When x ≥ 0, the graph of A is the same as the graph of y = x, the straight line with slope 1 that passes through the origin (0, 0). For x < 0, the graph of A is the same as the graph of y = −x , which is the straight line with slope−1 that passes through (0, 0). (See Figure 11.1.4.)

x

y

1 2 3 4–1–2–3–4

1

–1

2

3

4

y = |x|

Figure 11.1.4 Graph of the Absolute Value Function

Note that as you trace from left to right along the graph to the left of the origin, the height of the graph continually decreases. For this reason, the absolute value function is said to be decreasing on the set of real numbers less than 0. On the other hand, as you trace from left to right along the graph to the right of the origin, the height of the graph continually increases. Consequently, the absolute value function is said to be increasing on the set of real numbers greater than 0.

Since the height of the graph of a function f at a point x is f (x), these geometric concepts translate to the following analytic definition.

• Definition Let f be a real-valued function defined on a set of real numbers, and suppose the domain of f contains a set S. We say that f is increasing on the set S if, and only if,

for all real numbers x1 and x2 in S, if x1 < x2 then f (x1) < f (x2).

We say that f is decreasing on the set S if, and only if,

for all real numbers x1 and x2 in S, if x1 < x2 then f (x1) > f (x2).

We say that f is an increasing (or decreasing) function if, and only if, f is increas- ing (or decreasing) on its entire domain.

Figure 11.1.5 illustrates the analytic definitions of increasing and decreasing.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.1 Real-Valued Functions of a Real Variable and Their Graphs 723

f (x1) = the height of graph at x1

f (x1) = the height of graph at x1

f (x2) = the height of graph at x2

f (x2) = the height of graph at x2

x1

(x1, f (x1))

(x2, f (x2))

x2

f (x1) < f (x2) f (x1) > f (x2)

x x

(x1, f (x1))

x1 x2

(x2, f (x2))

An Increasing Function A Decreasing Function

(a) (b)

Figure 11.1.5

It follows almost immediately from the definitions that both increasing functions and decreasing functions are one-to-one. You are asked to show this in the exercises.

Example 11.1.5 A Positive Multiple of an Increasing Function Is Increasing

Suppose that f is a real-valued function of a real variable that is increasing on a set S of real numbers, and suppose M is any positive real number. Show that M f is also increasing on S.

Solution Suppose x1 and x2 are particular but arbitrarily chosen elements of S such that

x1 < x2.

[We must show that (M f )(x1) < (M f )(x2).] From the facts that x1 < x2 and f is increas- ing, it follows that

f (x1) < f (x2).

Then

M f (x1) < M f (x2),

since multiplying both sides of the inequality by a positive number does not change the direction of the inequality. Hence, by definition of M f ,

(M f )(x1) < (M f )(x2),

and, consequently, M f is increasing on S. ■

It is also true that a positive multiple of a decreasing function is decreasing, that a negative multiple of a increasing function is decreasing, and that a negative multiple of a decreasing function is increasing. The proofs of these facts are left to the exercises.

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. If f is a real-valued function of a real variable, then the domain and co-domain of f are both _____.

2. A point (x, y) lies on the graph of a real-valued function of a real variable f if, and only if, _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

724 Chapter 11 Analysis of Algorithm Efficiency

3. If a is any nonnegative real number, then the power function with exponent a, pa , is defined by _____.

4. Given a function f : R → R and a real number M , the func- tion Mf is defined by _____.

5. Given a function f : R → R, to prove that f is increasing, you suppose that _____ and then you show that _____.

6. Given a function f : R → R, to prove that f is decreasing, you suppose that _____ and then you show that _____.

Exercise Set 11.1* 1. The graph of a function f is shown below.

a. Is f (0) positive or negative? b. For what values of x does f (x) = 0? c. Find approximate values for x1 and x2 so that

f (x1) = f (x2) = 1 but x1 ̸= x2. d. Find an approximate value for x such that f (x) = 1.5. e. As x increases from −3 to −1, do the values of f

increase or decrease? f. As x increases from 0 to 4, do the values of f increase

or decrease?

1–1–2–3–4 2 3 4

1

–1

–2

2

Graph of f

2. The graph of a function g is shown below. a. Is g(0) positive or negative? b. Find an approximate value of x so that g(x) = 0. c. Find approximate values for x1 and x2 so that g(x1) =

g(x2) = 1 but x1 ̸= x2. d. Find an approximate value for x such that g(x) = −2. e. As x increases from−2 to 1, do the values of g increase

or decrease? f. As x increases from 1 to 3, do the values of g increase

or decrease?

1–1–2–3–4 2 3 4

1

–1

–2

2

3

Graph of g

3. Draw the graphs of the power functions p1/3 and p1/4 on the same set of axes. When 0 < x < 1, which is greater: x1/3 or x1/4? When x > 1, which is greater: x1/3 or x1/4?

4. Draw the graphs of the power functions p3 and p4 on the same set of axes. When 0 < x < 1, which is greater: x3 or x4? When x > 1, which is greater: x3 or x4?

5. Draw the graphs of y = 2⌊x⌋ and y = ⌊2x⌋ for all real numbers x . What can you conclude from these graphs?

Graph each of the functions defined in 6–9 below.

6. g(x) = ⌈x⌉ for all real numbers x (Recall that the ceil- ing of x , ⌈x⌉, is the least integer that is greater than or equal to x . That is, ⌈x⌉ = the unique integer n such that n − 1 < x ≤ n.)

7. h(x) = ⌈x⌉ − ⌊x⌋ for all real numbers x 8. F(x) = ⌊x1/2⌋ for all real numbers x 9. G(x) = x − ⌊x⌋ for all real numbers x

In each of 10–13 a function is defined on a set of integers. Graph each function.

10. f (n) = |n| for each integer n 11. g(n) = (n/2) + 1 for each integer n 12. h(n) = ⌊n/2⌋ for each integer n ≥ 0 13. k(n) = ⌊n1/2⌋ for each integer n ≥ 0 14. The graph of a function f is shown below. Find the inter-

vals on which f is increasing and the intervals on which f is decreasing.

1–1–2–3 2 3

1

–1

–2

2

Graph of f

15. Show that the function f : R → R defined by the formula f (x) = 2x − 3 is increasing on the set of all real numbers.

16. Show that the function g: R → R defined by the formula g(x) = −(x/3) + 1 is decreasing on the set of all real numbers.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 725

17. Let h be the function from R to R defined by the formula h(x) = x2 for all real numbers x . a. Show that h is decreasing on the set of all real numbers

less than zero. b. Show that h is increasing on the set of all real numbers

greater than zero.

18. Let k: R → R be the function defined by the formula k(x) = (x − 1)/x for all real numbers x ̸= 0. a. Show that k is increasing for all real numbers x > 0. b. Is k increasing or decreasing for x < 0? Prove your

answer.

19. Show that if a function f : R → R is increasing, then f is one-to-one.

20. Given real-valued functions f and g with the same domain D, the sum of f and g, denoted f + g, is defined as follows:

For all real numbers x , ( f + g)(x) = f (x) + g(x). Show that if f and g are both increasing on a set S, then f + g is also increasing on S.

21. a. Let m be any positive integer, and define f (x) = xm for all nonnegative real numbers x . Use the binomial theo- rem to show that f is an increasing function.

b. Let m and n be any positive integers, and let g(x) = xm/n for all nonnegative real numbers x . Prove that g is an increasing function.

The results of this exercise are used in the exercises for Sections 11.2 and 11.4.

22. Let f be the function whose graph is shown below. Draw the graph of 3 f .

Graph of f

1–2–3–4–5 2 3 4 5

1

–1

–2

2

23. Let h be the function whose graph is shown below. Draw the graph of 2h.

Graph of h

1–2–3–4–5 2 3 4 5

1

–1

–2

2

3

24. Let f be a real-valued function of a real variable. Show that if f is decreasing on a set S and if M is any positive real number, then M f is decreasing on S.

25. Let f be a real-valued function of a real varaible. Show that if f is increasing on a set S and if M is any negative real number, then M f is decreasing on S.

26. Let f be a real-valued function of a real variable. Show that if f is decreasing on a set S and if M is any negative real number, then M f is increasing on S.

In 27 and 28, functions f and g are defined. In each case draw the graphs of f and 2g on the same set of axes and find a number x0 so that f (x) ≤ 2g(x) for all x > x0. You can find an exact value for x0 by solving a quadratic equation, or you can find an approximate value for x0 by using a graphing calculator.

27. f (x) = x2 + 10x + 11 and g(x) = x2 for all real numbers x ≥ 0

28. f (x) = x2 + 125x + 254 and g(x) = x2 for all real numbers x ≥ 0

Answers for Test Yourself 1. sets of real numbers 2. y = f (x) 3. pa(x) = xa for all real numbers x 4. (M f )(x) = M · f (x) for x ∈ R 5. x1 and x2 are any real numbers such that x1 < x2; f (x1) < f (x2) 6. x1 and x2 are any real numbers such that x1 < x2; f (x1) > f (x2)

11.2 O-, "-, and #-Notations Although this may seem a paradox, all exact science is dominated by the idea of approximation. — Bertrand Russell, 1872–1970

It often happens that any one of several algorithms could be used to do a certain job but the time or memory space they require varies dramatically. The O-,!-, and "-notations provide approximations that make it easy to evaluate large-scale differences in algorithm

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

726 Chapter 11 Analysis of Algorithm Efficiency

efficiency, while ignoring differences of a constant factor and differences that occur only for small sets of input data.

The oldest of the notations, O-notation (read “big-O notation”), was introduced by the German mathematician Paul Bachmann in 1894 in a book on analytic number the- ory. Both the !- (read “big-Omega”) and "- (read “big-Theta”) notations were developed by Donald Knuth, one of the pioneers of the science of computer programming.

The idea of the notations is this. Suppose f and g are real-valued functions of a real variable x .

1. If, for sufficiently large values of x , the values of | f | are less than those of a multiple of |g|, then f is of order at most g, or f (x) is O(g(x)).

2. If, for sufficiently large values of x , the values of | f | are greater than those of a multiple of |g|, then f is of order at least g, or f (x) is !(g(x)).

3. If, for sufficiently large values of x , the values of | f | are bounded both above and below by those of multiples of |g|, then f is of order g, or f (x) is "(g(x)). These relationships are illustrated in Figure 11.2.1.

a x

(x, A|g(x)|)

(x, | f (x)|)

f(x) is Ω (g(x))

Graph of | f |

Graph of A|g|

b x

(x, B|g(x)|)

(x, | f (x)|)

f(x) is O(g(x))

Graph of | f |

Graph of B|g|

(x, B|g(x)|)

k x

(x, A|g(x)|)

(x, | f (x)|)

f(x) is Θ(g(x))

Graph of | f |

Graph of B|g|

Graph of A|g|

Figure 11.2.1

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 727

• Definition Let f and g be real-valued functions defined on the same set of nonnegative real numbers. Then

1. f is of order at least g, written f (x) is "(g(x)), if, and only if, there exist a positive real number A and a nonnegative real number a such that

A|g(x)| ≤ | f (x)| for all real numbers x > a. 2. f is of order at most g, written f (x) is O(g(x)), if, and only if, there exist a

positive real number B and a nonnegative real number b such that

| f (x)| ≤ B|g(x)| for all real numbers x > b. 3. f is of order g, written f (x) is #(g(x)), if, and only if, there exist a positive real

number A, B, and a nonnegative real number k such that

A|g(x)| ≤ | f (x)| ≤ B|g(x)| for all real numbers x > k.

Remark on Notation: In Section 7.1 we stated that we would generally make a careful distinction between a function f and its value f (x). The traditional use of the order notation violates this general rule. For instance, in the statement “ f (x) is "(g(x)),” the symbols f (x) and g(x) are understood to refer to the functions f and g defined by the expressions f (x) and g(x), respectively. Thus the statement

3 √

x + 4 is "(x1/2) means that f is of order g where f and g are defined by f (x) = 3√x + 4 and g(x) = x1/2 with some common domain (usually the largest set of nonnegative real numbers for which both function formulas are defined).

Example 11.2.1 Translating to #-Notation

Use "-notation to express the statement

10|x6| ≤ |17x6 − 45x3 + 2x + 8| ≤ 30|x6| for all real numbers x > 2. Solution Let A = 10, B = 30, and k = 2. Then the statement translates to

A|x6| ≤ |17x6 − 45 x3 + 2x + 8| ≤ B|x6| for all real numbers x > k. So, by definition of "-notation,

17x6 − 45x3 + 2x + 8 is "(x6). ■

Example 11.2.2 Translating to O- and "-Notations

a. Use ! and O notations to express the statements

(i) 15 |√x | ≤ ∣∣∣∣ 15 √

x(2x + 9) x + 1

∣∣∣∣ for all real numbers x > 0.

(ii) ∣∣∣∣ 15 √

x(2x + 9) x + 1

∣∣∣∣ ≤ 45 | √

x | for all real numbers x > 7.

b. Justify the statement: 15 √

x(2x + 9) x + 1 is "

(√ x ) .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

728 Chapter 11 Analysis of Algorithm Efficiency

Solution

a. (i) Let A = 15 and a = 0. The given statement translates to

A|√x | ≤ ∣∣∣∣ 15 √

x(2x + 9) x + 1

∣∣∣∣ for all real numbers x > a.

So by definition of !-notation,

15 √

x(2x + 9) x + 1 is !(

√ x).

(ii) Let B = 45 and b = 7. The given statement translates to ∣∣∣∣ 15 √

x(2x + 9) x + 1

∣∣∣∣ ≤ B| √

x | for all real numbers x > b

So by definition of O-notation,

15 √

x(2x + 9) x + 1 is O(

√ x).

b. Let A = 15, B = 45, and let k be the larger of 0 and 7. Then when x > k, both inequalities in a(i) and a(ii) are satisfied, and so

A|√x | ≤ ∣∣∣∣ 15 √

x(2x + 9) x + 1

∣∣∣∣ ≤ B| √

x | for all real numbers x > k.

Hence by definition of "-notation, 15 √

x(2x + 9) x + 1 is "(

√ x). ■

Part (b) of Example 11.2.2 illustrates the fact that if you know both that f is of order at most g and that f is of order at least g, then you may take k to be the larger of the numbers a and b promised in the definitions for big-Omega and big-O and conclude that f is of order g. Conversely, if f is of order g, then both a and b may be taken to be the number k promised in the definition for big-Theta to show that f is of order at most g and f is of order at least g. These results, and a transitive property of order, are stated for- mally in the following theorem. Additional useful properties of the notations are included in the exercises at the end of the section.

Theorem 11.2.1 Properties of O-, "-, and #-Notations

Let f and g be real-valued functions defined on the same set of nonnegative real numbers.

1. f (x) is !(g(x)) and f (x) is O(g(x)) if, and only if f (x) is "(g(x)).

2. f (x) is !(g(x)) if, and only if, g(x) is O( f (x)).

3. If f (x) is O(g(x)) and g(x) is O(h(x)), then f (x) is O(h(x)).

Proof: 1. The proof of this property was given before the statement of the theorem.

2. We first show that if f (x) is !(g(x)), then g(x) is O( f (x)). Thus, suppose f (x) is !(g(x)). By definition of !-notation, there exist a positive real number A and a nonnegative real number a such that

A|g(x)| ≤ | f (x)| for all real numbers x > a. Divide both sides by A to obtain

|g(x)| ≤ 1 A

| f (x)| for all real numbers x > a.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 729

Let B = 1/A and b = a. Then B is a positive real number and b is a nonnegative real number, and

|g(x)| ≤ B| f (x)| for all real numbers x > b, and so g(x) is O( f (x)) by definition of O-notation.

The proof that if g(x) is O( f (x)) then f (x) is !(g(x)) is left as exercise 10 at the end of the section.

3. Suppose f (x) is O(g(x)) and g(x) is O(h(x)). By definition of O-notation, there exist positive real numbers B1 and B2, and nonnegative real numbers b1 and b2 such that

| f (x)| ≤ B1|g(x)| for all real numbers x > b1, and

|g(x)| ≤ B2|h(x)| for all real numbers x > b2. Let B = B1 B2, and let b be the greater of b1 and b2. Then if x > b,

| f (x)| ≤ B1|g(x)| ≤ B1(B2|h(x)|) ≤ B|h(x)|. Thus, by definition of O-notation, f (x) is O(h(x)).

Orders of Power Functions Observe that if 1 < x,

then x < x2 multiplying both sides by x (which is positive)

and so x2 < x3 multiplying again by x .

Thus if 1 < x , then 1 < x < x2 < x3.

The following generalization of this result is developed in exercises 15 and 50 at the end of this section.

For any rational numbers r and s,

if x > 1 and r < s, then xr < xs . 11.2.1

Property (11.2.1) has the following consequence for orders.

For any rational numbers r and s,

if r < s, then xr is O(xs). 11.2.2

The relation among the graphs of various positive power functions of x for x ≥ 1 is shown graphically in Figure 11.2.2 on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

730 Chapter 11 Analysis of Algorithm Efficiency

x

y y = x3

y = x2

y = xy = x 3/2

y = x1/2

y = x2/3

y = x1/3

If r < s, the graph of y = xr lies underneath the graph of y = xs for x > 1.

1 2 3 4

1

2

3

4

Figure 11.2.2 Graphs of Powers of x for x ≥ 1

Orders of Polynomial Functions The following example shows how to use property (11.2.1) to derive a polynomial in- equality.

Example 11.2.3 A Polynomial Inequality

Show that for any real number x ,

if x > 1, then 3x3 + 2x + 7 ≤ 12x3. Solution Suppose x is a real number and x > 1. Then by property (11.2.1),

x < x3 and 1 < x3.

Multiply the left-hand inequality by 2 and the right-hand inequality by 7 to get

2x < 2x3 and 7 < 7x3.

Now add 3x3 ≤ 3x3, 2x < 2x3, and 7 < 7x3 to obtain 3x3 + 2x + 7 ≤ 3x3 + 2x3 + 7x3 = 12x3. ■

The method of Example 11.2.3 is used in the next example (more compactly) to show that a polynomial function has a certain order.

Example 11.2.4 Using the Definitions to Show That a Polynomial Function with Positive Coefficients Has a Certain Order

Use the definitions of big-Omega, big-O , and big-Theta to show that 2x4 + 3x3 + 5 is "(x4).

Solution Define functions f and g as follows. For all nonnegative real numbers x ,

f (x) = 2x4 + 3x3 + 5, and g(x) = x4.

Observe that for all real numbers x > 0,

2x4 ≤ 2x4 + 3x3 + 5 because 3x3 + 5 > 0 for x > 0,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 731

and so

2|x4| ≤ |2x4 + 3x3 + 5| because all terms on both sides of the inequality are positive.

Let A = 2 and a = 0. Then A|x4| ≤ |2x4 + 3x3 + 5| for all x > a,

and so by definition of !-notation, 2x4 + 3x3 + 5 is !(x4). Also for x > 1,

2x4 + 3x3 + 5 ≤ 2x4 + 3x4 + 5x4 because by (11.2.1), x3 < x4 and 1 < x4, and so 3x3 < 3x4 and 5 < 5x4

⇒ 2x4 + 3x3 + 5 ≤ 10x4 because 2 + 3 + 5 = 10 ⇒ |2x4 + 3x3 + 5| ≤ 10|x4| because all terms on both sides

of the inequality are positive

Note When the implication arrow,⇒, is placed at the beginning of a line, it means that every number x that makes the inequality in the line above true also makes the inequality in the given line true.

Let B = 10 and b = 1. Then |2x4 + 3x3 + 5| ≤ B|x4| for all x > b,

and so, by definition of O-notation, 2x4 + 3x3 + 5 is O(x4). Since 2x4 + 3x3 + 5 is both !(x4) and O(x4), by Theorem 11.2.1, it is "(x4). ■

The technique used in Example 11.2.4 can be generalized to show that any polynomial with nonnegative coefficients is big-Theta of its highest-power term. Taken together, the next two examples show that such a result can hold for a polynomial with negative as well as positive coefficients.

Example 11.2.5 A Big-O Approximation for a Polynomial with Some Negative Coefficients

a. Use the definition of O-notation to show that 3x3 − 1000x − 200 is O(x3). b. Show that 3x3 − 1000x − 200 is O(xs) for all integers s > 3.

Solution

a. According to the triangle inequality for absolute value (Theorem 4.4.6),

|a + b| ≤ |a| + |b| for all real numbers a and b. triangle inequality

If −b is substituted in place of b, the result is |a − b| = |a + (−b)| ≤ |a| + |− b| = |a| + |b|, or |a − b| ≤ |a| + |b|.

It follows that for all real numbers x > 1,

|3x3 − 1000x − 200| ≤ |3x3| + |1000x | + |200| ⇒ |3x3 − 1000x − 200| ≤ 3x3 + 1000x + 200 because all terms on the right side

of the inequality are positive when x > 1

⇒ |3x3 − 1000x − 200| ≤ 3x3 + 1000x3 + 200x3 because by (11.2.1), x < x3 and 1 < x3, and so 1000x < 1000x3

and 200 < 200x3

⇒ |3x3 − 1000x − 200| ≤ 1203x3 because 3 + 1000 + 200 = 1203 ⇒ |3x3 − 1000x − 200| ≤ 1203|x3| because x3 is positive.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

732 Chapter 11 Analysis of Algorithm Efficiency

Let b = 1 and B = 1203. Then |3x3 − 1000x − 200| ≤ B|x3| for all real numbers x > b.

So, by definition of O-notation, 3x3 − 1000x − 200 is O(x3). b. Suppose s is an integer with s > 3. By property (11.2.1), x3 < xs for all real numbers

x > 1. So B|x3| < B|xs | for all real numbers x > b (because b = 1), and thus by part (a),

|3x3 − 1000x − 200| ≤ B|xs | for all real numbers x > b. Hence, by definition of O-notation, 3x3 − 1000x − 200 is O(xs) for all integers s > 3.

Example 11.2.6 A Big-Omega Approximation for a Polynomial with Some Negative Coefficients

a. Use the definition of !-notation to show that 3x3 − 1000x − 200 is !(x3). b. Show that 3x3 − 1000x − 200 is !(xr ) for all integers r < 3.

Solution

a. To show that 3x3 − 1000x − 200 is !(x3), you need to find numbers a and A so that A|x3| ≤ |3x3 − 1000x − 200| for all real numbers x > a. Exercise 27 at the end of the section shows that the following procedure for choosing a will always produce an A that will give the desired result.

Choose a as follows: Add up the absolute values of the coefficients of the lower- order terms of 3x3 − 1000x − 200, divide by the absolute value of the highest-power term, and multiply the result by 2. The result is a = 2(1000 + 200)/3, which equals 800. If you follow the steps below, you will see that when a is chosen in this way, A can be taken to be one-half of the absolute value of the highest power of the polynomial. Accordingly, assume that x > a. Then

x > 800

⇒ x > 2 (

1000 + 200 3

) because 2(1000 + 200)/3 = 800

⇒ x > 2 · 1000 3

+ 2 · 200 3

by the rules for adding fractions

⇒ x > 2 · 1000 3

· 1 x

+ 2 · 200 3

· 1 x2

because x > 800 and so by

(11.2.1), 1> 1 x

and 1> 1 x2

⇒ 3 2

x3 > 1000x + 200 by multiplying both sides by

3 2

x2

⇒ 3x3 − 3 2

x3 > 1000x + 200 because 32 = 3− 32

⇒ 3x3 − 1000x − 200 > 3 2

x3 by adding 3 2 x

3 − 1000x − 200 to both sides

⇒ |3x3 − 1000x − 200| > 3 2 |x3|

because the expressions on both sides of the inequality are positive when x > 800.

Let A = 32 and let a = 800. Then

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 733

A|x3| ≤ |3x3 − 1000x − 200| for all real numbers x > a. So, by definition of !-notation, 3x3 − 1000x − 200 is !(x3).

b. Suppose r is an integer with r < 3. By property (11.2.1), xr < x3 for all real numbers x > 1. So, since a = 800 > 1, A|xr | < A|x3| for all real numbers x > a. Thus, by part (a),

A|xr | ≤ |3x3 − 1000x − 200| for all real numbers x > a. Hence, by definition of !-notation, 3x3 − 1000x − 200 is !(xr ) for all integers r < 3.

By Theorem 11.2.1, it follows immediately from Examples 11.2.5(a) and 11.2.6(a) that 3x3− 1000x − 200 is big-Theta of x3, and the techniques used in the examples can be generalized to show that every polynomial is big-Theta of the power function of its highest power. Moreover, the findings in parts (b) of the examples—that 3x3− 1000x − 200 is also big-O of xs for every integer s greater than 3 and is big-Omega of xr for every integer r less than 3—can also be generalized to all polynomials. These facts are summarized in the next theorem.

Theorem 11.2.2 On Polynomial Orders

Suppose a0, a1, a2, . . . , an are real numbers and an ̸= 0. 1. an xn + an−1xn−1 + · · · + a1x + a0 is O(xs) for all integers s ≥ n. 2. an xn + an−1xn−1 + · · · + a1x + a0 is !(xr ) for all integers r ≤ n. 3. an xn + an−1xn−1 + · · · + a1x + a0 is "(xn).

Theorem 11.2.2 can easily be proved using calculus. As suggested by Examples 11.2.5 and 11.2.6, however, it can also be derived without calculus. (See exercises 26, 27, and 49 at the end of this section.)

Example 11.2.7 Calculating Polynomial Orders Using the Theorem on Polynomial Orders

Use the theorem on polynomial orders to find orders for the functions given by the fol- lowing formulas.

a. f (x) = 7x5 + 5x3 − x + 4, for all real numbers x .

b. g(x) = (x − 1)(x + 1) 4

, for all real numbers x .

Solution

a. By direct application of the theorem on polynomial orders, 7x5 + 5x3 − x + 4 is "(x5)

b. g(x) = (x − 1)(x + 1) 4

= 1 4 (x2 − 1)

= 1 4

x2 − 1 4

by algebra

Thus g(x) is "(x2) by the theorem on polynomial orders. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

734 Chapter 11 Analysis of Algorithm Efficiency

Example 11.2.8 Showing That Two Power Functions Have Different Orders

Show that x2 is not O(x), and deduce that x2 is not "(x).

Solution [Argue by contradiction.] Suppose that x2 is O(x). [Derive a contradiction.] By the supposition that x2 is O(x), there exist a positive real number B and a nonnegative real number b such that

|x2| ≤ B|x | for all real numbers x > b. (∗) Let x be a positive real number that is greater than both B and b. Then

x · x > B · x by multiplying both sides of x > B by x which is positive

⇒ |x2| > B|x | because b is positive. Thus there is a real number x > b such that

|x2| > B|x |. This contradicts (∗). Hence the supposition is false, and so x2 is not O(x).

By Theorem 11.2.1, if x2 is "(x), then x2 is O(x). But x2 is not O(x), and thus x2 is not "(x). ■

The technique used in Example 11.2.8 can be extended and generalized to prove that any polynomial function in x of degree n is not big-O (or big-Theta) of the mth power function xm for any m < n. (See exercise 53 at the end of this section.)

Theorem 11.2.3 Limitation on Orders of Polynomial Functions

Let n be a positive integer, and let a0, a1, a2, . . . , an be real numbers with an ̸= 0. If m is any integer with m < n, then

an xn + an−1xn−1 + · · · + a1x + a0 is not O(xm) and

an xn + an−1xn−1 + · · · + a1x + a0 is not "(xm).

It follows from Theorems 11.2.2 and 11.2.3 that integral power functions are conve- nient benchmarks for comparisons among general polynomial functions because every polynomial function has the same order as some integral power function, and no power function has the same order as any other.

Orders for Functions of Integer Variables It is traditional to use the symbol x to denote a real number variable, whereas n is used to represent an integer variable. Thus, given a statement of the form

f (n) is "(g(n)),

we assume that f and g are functions defined on sets of integers. If it is true that

f (x) is "(g(x)),

where f and g are functions defined for real numbers, then it is certainly true that f (n) is "(g(n)). The reason is that if f (x) is "(g(x)), then an inequality

A|g(x)|≤ | f (x)|≤ B|g(x)|

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 735

holds for all real numbers x > k. Hence, in particular, the inequality

A|g(n)| ≤ | f (n)| ≤ B|g(n)| holds for all integers n > k.

Example 11.2.9 An Order for the Sum of the First n Integers

Sums of the form 1 + 2 + 3 + · · · + n arise in the analysis of computer algorithms such as selection sort. Show that for a positive integer variable n,

1 + 2 + 3 + · · · + n is "(n2). Solution By the formula for the sum of the first n integers (see Theorem 5.2.2), for all

positive integers n,

1 + 2 + 3 + · · · + n = n(n + 1) 2

.

But n(n + 1)

2 = 1

2 n2 + 1

2 n by basic algebra.

And, by the theorem on polynomial orders,

1 2

n2 + 1 2

n is "(n2).

Hence

1 + 2 + 3 + · · · + n is "(n2). ■

Extension to Functions Composed of Rational Power Functions

Consider a function of the form

(x3/2 + 3)(x − 2)2 x1/2(2x1/2 + 1) =

x7/2 − 4x5/2 + 4x3/2 + 3x2 − 12x + 12 2x + x1/2 .

When the numerator and denominator are expanded, each is a sum of terms of the form axr , where a is a real number and r is a positive rational number. The degree of such a sum can be taken to be the largest exponent of x that occurs in one of its terms. If the difference between the degree of the numerator and that of the denominator is called the degree of the function and denoted d, then it can be shown that f (x) is "(xd), that f (x) is O(xc) for all real numbers c > d , and that f (x) is not O(xc) for any real number c < d. For the example given above, this means that d = 7/2− 1 = 5/2 and that

(x3/2 + 3)(x − 2)2 x1/2(2x1/2 + 1) is "(x

5/2),

(x3/2 + 3)(x − 2)2 x1/2(2x1/2 + 1) is O(x

c) for all real numbers c > 5/2,

and

(x3/2 + 3)(x − 2)2 x1/2(2x1/2 + 1) is not O(x

c) for any real number c < 5/2.

We state the general result as Theorem 11.2.4.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

736 Chapter 11 Analysis of Algorithm Efficiency

Theorem 11.2.4 Orders of Functions Composed of Rational Power Functions

Let m and n be positive integers, and let r0, r1, r2, . . . , rn and s0, s1, s2, . . . , sm be nonnegative rational numbers with r0 < r1 < r2 < · · · < rn and s0 < s1 < s2 < · · · < sm . Let a0, a1, a2, . . . , an and b0, b1, b2, . . . , bm be real numbers with an ̸= 0 and bm ̸= 0. Then

an xrn + an−1xrn−1 + · · · + a1xr1 + a0xr0 bm xsm + bm−1xsm−1 + · · · + b1xs1 + b0xs0

is "(xrn−sm ).

an xrn + an−1xrn−1 + · · · + a1xr1 + a0xr0 bm xsm + bm−1xsm−1 + · · · + b1xs1 + b0xs0

is O(xc) for all real numbers c > rn − sm .

an xrn + an−1xrn−1 + · · · + a1xr1 + a0xr0 bm xsm + bm−1xsm−1 + · · · + b1xs1 + b0xs0

is not O(xc) for any real number c < rn − sm .

Test Yourself 1. A sentence of the form “A|g(x)| ≤ | f (x)| for all x > a”

translates into !-notation as _____.

2. A sentence of the form “| f (x)| ≤ B|g(x)| for all x > b” translates into O-notation as _____.

3. A sentence of the form “A|g(x)| ≤ | f (x)| ≤ B|g(x)| for all x > k” translates into "-notation as _____.

4. When x > 1, x2 _____ x and x5 _____ x2.

5. According to the theorem on polynomial orders, if p(x) is a polynomial in x , then p(x) is "(xn), where n is _____.

6. If n is a positive integer, then 1 + 2 + 3 + · · · + n has order _____.

Exercise Set 11.2 1. The following is a formal definition for !-notation, writ-

ten using quantifiers and variables: f (x) is !(g(x)) if, and only if, ∃ positive real numbers a and A such that ∀x > a,

A|g(x)| ≤ | f (x)|. a. Write the formal negation for the definition using the

symbols ∀ and ∃. b. Restate the negation less formally without using the

symbols ∀ and ∃. 2. The following is a formal definition for O-notation, writ-

ten using quantifiers and variables: f (x) is O(g(x)) if, and only if, ∃ positive real numbers b and B such that ∀x > b,

| f (x)| ≤ B|g(x)|. a. Write the formal negation for the definition using the

symbols ∀ and ∃. b. Restate the negation less formally without using the

symbols ∀ and ∃. 3. The following is a formal definition for "-notation, writ-

ten using quantifiers and variables: f (x) is "(g(x)) if, and only if, ∃ positive real numbers k, A, and B such that ∀x > k,

A|g(x)| ≤ | f (x)| ≤ B|g(x)|. a. Write the formal negation for the definition using the

symbols ∀ and ∃. b. Restate the negation less formally without using the

symbols ∀ and ∃.

In 4–9, express each statement using !-, O-, or "-notation.

4. |5x8 − 9x7 + 2x5 + 3x − 1| ≤ 6|x8| for all real numbers x > 3. (Use O-notation.)

5. |x | ≤ ∣∣∣∣ (x2 − 1)(12x + 25)

3x2 + 4

∣∣∣∣ ≤ 6|x | for all real numbers x > 2.

6. |x7/2| ≤ ∣∣∣∣ (x2 − 7)2(10x1/2 + 3)

x + 1

∣∣∣∣ for all real numbers

x > 4. (Use !-notation.)

7. |3x6 + 5x4 − x3| ≤ 9|x6| for all real numbers x > 1. (Use O-notation.)

8. 12 x 4 ≤ |x4 − 50x3 + 1| for all real numbers x > 101. (Use

!-notation.)

9. 12 x 2 ≤ |3x2 − 80x + 7| ≤ 3|x2| for all real numbers

x > 25.

In each of 10–14 assume f and g are real-valued functions defined on the same set of nonnegative real numbers.

10. Prove that if g(x) is O( f (x)), then f (x) is !(g(x)).

11. Prove that if f (x) is O(g(x)) and c is any nonzero real number, then c f (x) is O(g(x)).

12. Prove that if f (x) is O(h(x)) and g(x) is O(k(x)), then f (x) + g(x) is O(G(x)), where, for each x in the domain, G(x) = max(|h(x)|, |k(x)|).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.2 O-, !-, and "-Notations 737

13. Prove that f (x) is "( f (x)).

14.H Prove that if f (x) is O(h(x)) and g(x) is O(k(x)), then f (x)g(x) is O(h(x)k(x)).

15. a. Use mathematical induction to prove that if x is any real number with x > 1, then xn > 1 for all integers n ≥ 1.

b.H Prove that if x is any real number with x > 1, then xm < xn for any integers m and n with m < n.

16. a. Show that for any real number x ,

if x > 1 then |x2| ≤ |2x2 + 15x + 4|. b. Show that for any real number x ,

if x > 1 then |2x2 + 15x + 4| ≤ 21|x2|. c. Use the !- and O-notations to express the results of

parts (a) and (b). d. What can you deduce about the order of 2x2 + 15x + 4?

17. a. Show that for any real number x ,

if x > 1 then |x4| ≤ |23x4 + 8x2 + 4x |. b. Show that for any real number x ,

if x > 1 then |23x4 + 8x2 + 4x | ≤ 35|x4|. c. Use the !- and O-notations to express the results of

parts (a) and (b). d. What can you deduce about the order of

23x4 + 8x2 + 4x? 18. Use the definition of "-notation to show that

5x3 + 65x + 30 is "(x3). 19. Use the definition of "-notation to show that

x2 + 100x + 88 is "(x2). 20. a. Show that for any real number x , if x > 1 then

|x2| ≤ |⌈x2⌉|. b. Show that for any real number x , if x > 1 then

1 2 |⌈x

2⌉| ≤ |x2|. c. Use the !- and O-notations to express the results of

parts (a) and (b). d. What can you deduce about the order of ⌈x2⌉?

21. a. Show that for any real number x , if x > 1 then |⌊√x⌋| ≤ |√x |.

b. Show that for any real number x , if x > 1 then 1 2 | √

x | ≤ |⌊x⌋|. c. Use the !- and O-notation to express the results of parts

(a) and (b). d. What can you deduce about the order of ⌊√x⌋?

22. a. Show that for any real number x , if x > 1 then |7x4 − 95x3 + 3| ≤ 105|x4|.

b. Use O-notation to express the result of part (a).

23. a. Show that for any real number x , if x > 1 then |15 x

2 − 42x − 8| ≤ 51|x2|. b. Use O-notation to express the result of part (a).

24. a. Show that for any real number x , if x > 1 then |14 x

5 − 50x3 + 3x + 12| ≤ 66|x5|. b. Use O-notation to express the result of part (a).

25.H Show that x5 is not O(x2).

26. Suppose a0, a1, a2, . . . , an are real numbers and an ̸= 0. Use the generalization of the triangle inequality to n inte- gers (exercise 43, Section 5.5) to show that

an xn + an−1xn−1 + · · · + a1x + a0 is O(xn). 27. Suppose a0, a1, a2, . . . , an are real numbers and an ̸= 0.

Show that an xn + an−1xn−1 + · · · + a1x + a0 is !(xn) by letting

d = 2 ( |a0| + |a1| + |a2| + · · · + |an−1|

|an|

) .

and letting a = max(d, 1).

In 28–30: (a) Let d be the number obtained by adding up the absolute values of the coefficients of the lower-order terms of the given polynomial, dividing by the absolute value of the highest-order term, and multiplying the result by 2. Let a be the maximum number of d and 1, and let A be half the coefficient of the absolute value of the highest-order term of the polynomial. (b) Show that if x > a, the absolute value of the polynomial will be greater than the product of A and the absolute value of x4, where n is the degree of the polynomial. (c) Deduce the result given in the exercise.

28. 7x4 − 95x3 + 3 is !(x4).

29. 15 x 2 − 42x − 8 is !(x2).

30. 14 x 5 − 50x3 + 3x + 12 is !(x5).

31. Refer to the results of exercises 22 and 28 to find an order for 7x4 − 95x3 + 3 from among the set of power functions.

32. Refer to the results of exercises 23 and 29 to find an order for 15 x

2 − 42x − 8 from among the set of power functions. 33. Refer to the results of exercises 24 and 30 to find an

order for 14 x 5 − 50x3 + 3x + 12 from among the set of

power functions.

Use the theorem on polynomial orders to prove each of the state- ments in 34–39.

34. (x + 1)(x − 2)

4 is "(x2).

35. x 3 (4x2 − 1) is "(x3).

36. x(x − 1)

2 + 3x is "(x2).

37. n(n + 1)(2n + 1)

6 is "(n3).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

738 Chapter 11 Analysis of Algorithm Efficiency

38. [

n(n + 1) 2

]2 is "(n4).

39. 2(n − 1) + n(n + 1) 2

+ 4 (

n(n − 1) 2

) is "(n2).

Prove each of the statements in 40–47, assuming n is a vari- able that takes positive integer values. (Use formulas from the exercise set of Section 5.2 and the theorem on polynomial orders as appropriate.)

40. 12 + 22 + 32 + · · · + n2 is "(n3). 41. 13 + 23 + 33 + · · · + n3 is "(n4). 42. 2 + 4 + 6 + · · · + 2n is "(n2). 43. 5 + 10 + 15 + 20 + 25 + · · · + 5n is "(n2).

44. n∑

i=1 (4i − 9) is "(n2). 45.

n∑

k=1 (k + 3) is "(n2).

46.H n∑

i=1 i(i + 1) is "(n3). 47.

n∑

k=3 (k2 − 2k) is "(n3).

48.H (Requires the concept of limit from calculus) a. Let a0, a1, a2, . . . , an be real numbers with an ̸= 0.

Prove that

lim x→∞

∣∣∣∣ an xn + an−1xn−1 + · · · + a1x + a0

an xn

∣∣∣∣ = 1.

b. Use the result of part (a) and the definition of limit to prove that

an xn + an−1xn−1 + · · · + a1x + a0 is "(xn). 49. Another approach to proving part of the theorem on poly-

nomial orders uses properties of O-notation. a. Show that if f, g, and h are functions from R to R and

f (x) is O(h(x)) and g(x) is O(h(x)), then f (x) + g(x) is O(h(x)).

b. How does it follow from part (a) and Theorem 11.2.1(3) that x4 + x2 is O(x4)?

c. The result of exercise 11 states that if f is a function from R to R, f (x) is O(g(x)), and c is any nonzero real number, then c f (x) is O(g(x)). How does it follow from this result and part (a) that 12x5 − 34x2 + 7 is O(x5)?

d. Use the results of part (a) and exercise 11 to show that if n is any positive integer and a1, a2, . . . , an are real num- bers, then

an xn + an−1xn−1 + · · · + a1x + a0 is O(xn). 50. a. Let x be any positive real number. Use mathematical

induction to prove that for all integers n ≥ 1, if x ≤ 1 then xn ≤ 1.

b. Explain how it follows from part (a) that if x is any pos- itive real number, then for all integers n ≥ 1, if xn > 1 then x > 1.

c. Explain how it follows from part (b) that if x is any pos- itive real number, then for all integers n ≥ 1, if x > 1 then x1/n > 1.

d.H Let p, q, and s be positive integers, let r be a nonneg- ative integer, and suppose p/q > r/s. Use part (c) and the result of exercise 15 to prove property (11.2.1). In other words show that for any real number x , if x > 1 then x p/q > xr/s .

Explain how each statement in 51 and 52 follows from exercise 50, exercise 13, and parts (a) and (c) of exercise 49.

51. 4x4/3 − 15x + 7 is O(x4/3). 52.

√ x(38x5 + 9) is O(x11/2).

53.H Prove that if r and s are rational numbers with r > s, then xr is not O(xs).

In 54–56, use Theorem 11.2.4 to find an order for each of the given functions from among the set of rational power functions.

54. f (x) = √

x(3x + 5) 2x + 1

55. f (x) = (2x 7/2 + 1)(x − 1)

(x1/2 + 1)(x + 1)

56. f (x) = (5x 2 + 1) (√

x − 1 )

4x3/2 − 2x 57.✶ a. Use mathematical induction to prove that

√ 1 +

√ 2 +

√ 3 + · · · +√n ≤ n3/2

for all integers n ≥ 1. b.H Use mathematical induction to prove that

1 2

n3/2 ≤ √

1 + √

2 + √

3 + · · · +√n.

c. What can you conclude from parts (a) and (b) about an order of

√ 1 +

√ 2 +

√ 3 + · · · +√n?

58.✶ a. Use mathematical induction to prove that 11/3 + 21/3 + · · · + n1/3 ≤ n4/3, for all integers n ≥ 1.

b. Use mathematical induction to prove that

1 2

n4/3 ≤ 11/3 + 21/3 + 31/3 + · · · + n1/3.

c. What can you conclude from parts (a) and (b) about an order for 11/3 + 21/3 + 31/3 + · · · + n1/3?

Exercises 59–61 use the following definition, which requires the concept of limit from calculus.

Definition: If f and g are real-valued functions of a real vari- able and limx→∞ g(x) ̸= 0, then

f (x) is o(g(x)) ⇔ lim x→∞

f (x) g(x)

= 0.

The notation f (x) is o(g(x)) is read “ f (x) is little-oh of g(x).”

59. Prove that if f (x) is o(g(x)), then f (x) is O(g(x)).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 739

60. Prove that if f (x) and g(x) are both o(h(x)), then for all real numbers a and b, a f (x) + bg(x) is o(h(x)).

61. Prove that for any positive real numbers a and b, if a < b then xa is o(xb).

Answers for Test Yourself 1. f (x) is !(g(x)) 2. f (x) is O(g(x)) 3. f (x) is "(g(x)) 4. >; > 5. the degree of p(x) 6. n2

11.3 Application: Analysis of Algorithm Efficiency I As soon as an Analytical Engine exists, it will necessarily guide the future course of the science. Whenever any result is sought by its aid, the question will then arise—by what course of calculation can these results be arrived at by the machine in the shortest time? — Charles Babbage, 1864

Charles Babbage’s Analytical Engine was similar in concept to a modern computer, and the quotation shown above suggests that well over a hundred years ago he anticipated the importance of analyzing the efficiencies of computer algorithms. Starting in the late 1940s, a number of mathematicians and computer scientists contributed to the develop- ment of algorithm analysis. Alan Turing may have been the first to suggest a concrete way for doing this. In a 1948 paper he wrote: “It is convenient to have a measure of the amount of work involved in a computing process, even though it be a very crude one. . . . We might, for instance, count the number of additions, subtractions, multiplications, divi- sions, recording of numbers . . .”∗ In the early 1960s, Donald Knuth started writing The Art of Computer Programming, a multivolume work, which provides a solid and exten- sive foundation for the subject that is both elegant and mathematically rigorous.†

B et

tm an

n/ CO

R B

IS

Charles Babbage (1792–1871)

Note For more about the work of Alan Turing, see Sections 6.4 and 12.2.

The Sequential Search Algorithm The object of a search algorithm is to hunt through an array of data in an attempt to find a particular item x . In a sequential search, x is compared to the first item in the array, then to the second, then to the third, and so on. The search is stopped if a match is found at any stage. On the other hand, if the entire array is processed without finding a match, then x is not in the array. An example of a sequential search is shown diagrammatically in Figure 11.3.1.

a[1]

a[1] = x ? a[2] = x ? a[3] = x ? a[4] = x ? a[5] = x ?

a[2] a[3] a[4] a[5] a[6] a[7] no no no no

yes

Done

Figure 11.3.1 Sequential Search of a[1], a[2], . . . , a[7] for x where x = a[5]

∗Quarterly Journal of Mechanics and Applied Mathematics, vol. 1 (1948), pp. 287–308. †Donald E. Knuth, The Art of Computer Programming, vol. 1: Fundamental Algorithms, 3rd ed. (1997); vol. 2: Seminumerical Algorithms, 3rd ed., (1997); vol. 3: Searching and Sorting, 2nd ed. (1998) (Reading, MA: Addison-Wesley).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

740 Chapter 11 Analysis of Algorithm Efficiency

Example 11.3.4 Best- and Worst-Case Orders for Sequential Search

Find best- and worst-case orders for the sequential search algorithm from among the set of power functions.

Solution Suppose the sequential search algorithm is applied to an input array a[1], a[2], . . . , a[n] to find an item x . In the best case, the algorithm requires only one compari- son between x and the items in a[1], a[2], . . . , a[n]. This occurs when x is the first item in the array. Thus in the best case, the sequential search algorithm is "(1). (Note that "(1) = "(n0).) In the worst case, however, the algorithm requires n comparisons. This occurs when x = a[n] or when x does not appear in the array at all. Thus in the worst case, the sequential search algorithm is "(n). ■

The Insertion Sort Algorithm Insertion sort is an algorithm for arranging the items in an array into ascending order. Initially, the second item is compared to the first. If the second item is less than the first, their values are interchanged, and as a result the first two array items are in ascending order. The idea of the algorithm is gradually to lengthen the section of the array that is known to be in ascending order by inserting each subsequent array item into its correct position relative to the preceding ones. When the last item has been placed, the entire array is in ascending order.

Co ur

te sy

of D

on al

d K

nu th

Donald Knuth (born 1938)

Figure 11.3.2 illustrates the action of step k of insertion sort on an array a[1], a[2], a[3], . . . , a[n].

sorted subarray

a[1], a[2], a[3], . . . , a[k – 1], a[k], a[k + 1], . . . , a[n]

Step k: Insert the value of a[k] into its proper position relative to a[1], a[2], . . . , a[k – 1]. At the end of this step a[1], a[2], . . . , a[k] is sorted.

Figure 11.3.2 Step k of Insertion Sort

Understanding the relative efficiencies of algorithms designed to do the same job is of much more than academic interest. In industrial and scientific settings, the choice of an efficient over an inefficient program may result in the saving of many thousands of dollars or may make the difference between being able or not being able to do a project at all.

Two aspects of algorithm efficiency are important: the amount of time required to execute the algorithm and the amount of memory space needed when it is run. In this chapter we introduce basic techniques for calculating time efficiency. Similar techniques exist for calculating space efficiency. Occasionally, one algorithm may make more effi- cient use of time but less efficient use of memory space than another, forcing a trade-off based on the resources available to the user.

Time Efficiency of an Algorithm How can the time efficiency of an algorithm be calculated? The answer depends on sev- eral factors. One is the size of the set of data that is input to the algorithm; for example, it takes longer for a sort algorithm to process 1,000,000 items than 100 items. Conse- quently, the execution time of an algorithm is generally expressed as a function of its input size.

Another factor that may affect the run time of an algorithm is the nature of the input data. For instance, a program that searches sequentially through a list of length n to find a

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 741

data item requires only one step if the item is first on the list, but it uses n steps if the item is last on the list. Thus algorithms are frequently analyzed in terms of their “best case,” “worst case,” and “average case” performances for an input of size n.

Roughly speaking, the analysis of an algorithm for time efficiency begins by try- ing to count the number of elementary operations that must be performed when the algorithm is executed with an input of size n (in the best case, worst case, or average case). What is classified as an “elementary operation” may vary depending on the nature of the problem the algorithms being compared are designed to solve. For instance, to compare two algorithms for evaluating a polynomial, the crucial issue is the number of additions and multiplications that are needed, whereas to compare two algorithms for searching a list to find a particular element, the important distinction is the number of comparisons that are required. As is common, we will classify the following as elemen- tary operations: addition, subtraction, multiplication, division, and comparisons that are indicated explicitly in an if-statement using one of the relational symbols <,≤,>,≥, =, or ̸=.

When algorithms are implemented in a particular programming language and run on a particular computer, some operations are executed faster than others, and, of course, there are differences in execution times from one machine to another. In certain prac- tical situations these factors are taken into account when we decide which algorithm or which machine to use to solve a particular problem. In other cases, however, the machine is fixed, and rough estimates are all that we need to determine the clear supe- riority of one algorithm over another. Since each elementary operation is executed in time no longer than the slowest, the time efficiency of an algorithm is approximately proportional to the number of elementary operations required to execute the algorithm.

Consider the example of two algorithms, A and B, designed to do a certain job. Sup- pose that for an input of size n, the number of elementary operations needed to perform algorithm A is between 10n and 20n (at least for large n) and the number of elementary operations needed to perform algorithm B is between 2n2 and 4n2. Note that 20n < 2n2

whenever n > 10, which means that the maximum number of operations required to exe- cute A is less than the minimum number of operations required to execute B whenever n > 10. In fact, 20n is very much less than 2n2 when n is large. For instance, if n = 1000, then 20n = 20,000, whereas 2n2 = 2,000, 000. We say that in the worst case, algorithm A is "(n) (or has worst-case order n) and that in the worst case, algorithm B is "(n2) (or has worst-case order n2).

• Definition Let A be an algorithm.

1. Suppose the number of elementary operations performed when A is executed for an input of size n depends on n alone and not on the nature of the input data; say it equals f (n). If f (n) is "(g(n)), we say that A is #(g(n)) or A is of order g(n).

2. Suppose the number of elementary operations performed when A is executed for an input of size n depends on the nature of the input data as well as on n.

a. Let b(n) be the minimum number of elementary operations required to execute A for all possible input sets of size n. If b(n) is "(g(n)), we say that in the best case, A is #(g(n)) or A has a best-case order of g(n).

b. Let w(n) be the maximum number of elementary operations required to exe- cute A for all possible input sets of size n. If w(n) is "(g(n)), we say that in the worst case, A is #(g(n)) or A has a worst-case order of g(n).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

742 Chapter 11 Analysis of Algorithm Efficiency

Some of the orders most commonly used to describe algorithm efficiencies are shown in Table 11.3.1. As you see from the table, differences between the orders of various types of algorithms are more than astronomical. The time required for an algorithm of order 2n

to operate on a data set of size 100,000 is approximately 1030,076 times the estimated 15 billion years since the universe began (according to one theory of cosmology). On the other hand, an algorithm of order log2 n needs at most a fraction of a second to process the same data set.

Table 11.3.1 Time Comparisons of Some Algorithm Orders

Approximate Time to Execute f (n) Operations Assuming One Operation per Nanosecond∗

f (n) n = 10 n = 1,000 n = 100,000 n = 10,000,000 log2 n 3.3× 10−9 sec 10−8 sec 1.7× 10−8 sec 2.3× 10−8 sec

n 10−8 sec 10−6 sec 0.0001 sec 0.01 sec n log2 n 3.3× 10−8 sec 10−5 sec 0.0017 sec 0.23 sec

n2 10−7 sec 0.001 sec 10 sec 27.8 min n3 10−6 sec 1 sec 11.6 days 31,688 yr 2n 10−6 sec 3.4× 10284 yr 3.1× 1030086 yr 2.9× 103010283 yr

∗one nanosecond = 10−9 second

Example 11.3.1 Computing an Order of an Algorithm Segment

Assume n is a positive integer and consider the following algorithm segment:

p := 0, x := 2 for i := 2 to n

p := (p + i) ·x next i

a. Compute the actual number of additions and multiplications that must be performed when this algorithm segment is executed.

b. Use the theorem on polynomial orders to find an order for this algorithm segment.

Solution

a. There are one multiplication and one addition for each iteration of the loop, so there are twice as many multiplications and additions as there are iterations of the loop. Now the number of iterations of the for-next loop equals the top index of the loop minus the bottom index plus 1; that is, n − 2 + 1 = n − 1. Hence there are 2(n − 1) = 2n − 2 multiplications and additions.

b. By the theorem on polynomial orders,

2n − 2 is "(n), and so this algorithm segment is "(n). ■

The next example looks at an algorithm segment that contains a nested loop.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 743

Example 11.3.2 An Order for an Algorithm with a Nested Loop

Assume n is a positive integer and consider the following algorithm segment:

s := 0 for i := 1 to n

for j := 1 to i s := s + j ·(i − j + 1)

next j next i

a. Compute the actual number of additions, subtractions, and multiplications that must be performed when this algorithm segment is executed.

b. Use the theorem on polynomial orders to find an order for this algorithm segment.

Solution

a. There are two additions, one multiplication, and one subtraction for each iteration of the inner loop, so the total number of additions, multiplications, and subtractions is four times the number of iterations of the inner loop. Now the inner loop is iterated

one time when i = 1, two times when i = 2, three times when i = 3,

...

n times when i = n.

You can see this easily if you construct a table that shows the values of i and j for which the statements in the inner loop are executed. There is one iteration for each column in the table.

→ → → →i 1 2 3 4 · · · n j 1 1 2 1 2 3 1 2 3 4 · · · 1 2 3 · · · n ︸︷︷︸︸ ︷︷ ︸︸ ︷︷ ︸︸ ︷︷ ︸ ︸ ︷︷ ︸

1 2 3 4 n

Hence the total number of iterations of the inner loop is

1 + 2 + 3 + · · · + n = n(n + 1) 2

by Theorem 5.2.2,

and so the number of additions, subtractions, and multiplications is

4 · n(n + 1) 2

= 2n(n + 1).

An alternative method for computing the number of columns of the table uses an approach discussed in Example 9.6.3. Observe that the number of columns in the table is the same as the number of ways to place two×’s in n categories, 1, 2, . . . , n, where the location of the ×’s indicates the values of i and j with j ≤ i . By Theorem 9.6.1, this number is (

n − 1 + 2 2

) = (

n + 1 2

) = (n + 1)!

2!((n + 1)− 2)! = (n + 1)n(n − 1)!

2(n − 1)! = n(n + 1)

2 .

Although, for this example, the alternative method is more complicated than the one preceding it, it is simpler when the number of loop nestings exceeds two. (See exercise 19.)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

744 Chapter 11 Analysis of Algorithm Efficiency

b. By the theorem on polynomial orders, 2n(n + 1) = 2n2 + 2n is "(n2), and so this algorithm segment is "(n2). ■

Example 11.3.3 When the Number of lterations Depends on the Floor Function

Assume n is a positive integer and consider the following algorithm segment:

for i := ⌊n/2⌋ to n a := n − i

next i

a. Compute the actual number of subtractions that must be performed when this algo- rithm segment is executed.

b. Use the theorem on polynomial orders to find an order for this algorithm segment.

Solution

a. There is one subtraction for each iteration of the loop, and the loop is iterated

n − ⌊

n 2

⌋ + 1 times. If n is even, then

⌊ n 2

⌋ = n

2 , and so the number of subtractions is

n − ⌊

n 2

⌋ + 1 = n − n

2 + 1 = n + 2

2 .

If n is odd, then ⌊

n 2

⌋ = n − 1

2 , and so the number of subtractions is

n − ⌊

n 2

⌋ + 1 = n − n − 1

2 + 1 = 2n − (n − 1) + 2

2 = n + 3

2 .

b. By the theorem on polynomial orders,

n + 2 2

is "(n) and n + 3

2 is "(n)

also. Hence, regardless of whether n is even or odd, this algorithm segment is "(n). ■

The following is a formal algorithm for insertion sort.

Algorithm 11.3.1 Insertion Sort

[The aim of this algorithm is to take an array a[1], a[2], a[3], . . . , a[n], where n ≥ 1, and reorder it. The output array is also denoted a[1], a[2], a[3], . . . , a[n]. It has the same values as the input array, but they are in ascending order. In the kth step, a[1], a[2], a[3], . . . , a[k − 1] is in ascending order, and a[k] is inserted into the correct position with respect to it.]

Input: n [a positive integer], a[1], a[2], a[3], . . . , a[n] [an array of data items capa- ble of being ordered]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 745

Algorithm Body: for k := 2 to n [Compare a[k] to previous items in the array a[1], a[2], a[3], . . . , a[k − 1], starting from the largest and moving downward. Whenever a[k] is less than a preceding array item, increment the index of the preceding item to move it one position to the right. As soon as a[k] is greater than or equal to an array item, insert the value of a[k] to the right of that item. If a[k] is greater than or equal to a[k − 1], then leave the value of a[k] unchanged.]

x := a[k] j := k − 1 while ( j ̸= 0) if x < a[j] then

a[ j + 1] := a[ j] j := j − 1

end if end while a[ j + 1] := x

next k Output: a[1], a[2], a[3], . . . , a[n] [in ascending order]

Figure 11.3.3 shows the result of each step when insertion sort is applied to the par- ticular array

a[1] = 6, a[2] = 3, a[3] = 5, a[4] = 7, a[5] = 2.

6 3 5 7 2

a[1] a[2] a[3] a[4] a[5]

3 6 5 7 2

3 5 6 7 2

3 5 6 7 2

2 3 5 6 7

Initial

Result of step 1

Result of step 2

Result of step 3

Result of step 4

The top row of the table shows the initial values of the array, and the bottom row shows the final values. The result of each step is shown in a separate row. For each step, the sorted section of the array is shaded.

Figure 11.3.3 Action of Insertion Sort on an Array

Example 11.3.5 develops a trace table for the action of insertion sort on a particular array.

Example 11.3.5 A Trace Table for Insertion Sort

Construct a trace table showing the action of insertion sort on the array

a[1] = 6, a[2] = 3, a[3] = 5, a[4] = 7, a[5] = 2. Solution

The first column on the next page shows the state of the variables before the first iteration of the for-next loop. When the for-next loop is first iterated, k is assigned the value 2; x the value of a[2], which is 3; and j the value of k − 1, which is 1. Because j ̸= 0, the while loop is entered and the condition for the if-then-else statement is tested. Because a[1] > x , then a[2] is assigned the value of a[1], which is 6, j is assigned the value of j − 1, which is 0, and a[1] is assigned the value of x , which is 3. The condition governing the while loop is tested again, but since j = 0, it is not satisfied, and so the while loop is not entered. Thus the value of k is incremented by 1 (so that it equals 3),

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

746 Chapter 11 Analysis of Algorithm Efficiency

and the for-next loop is entered a second time. This process continues until the value of k has been incremented to 6. Because 6 is greater than the top value in the for-next loop, execution of the algorithm ceases, and the array items are seen to be in ascending order.

n 5

a[1] 6 3 2 a[2] 3 6 5 3 a[3] 5 6 5 a[4] 7 7 6 a[5] 2 7

k 2 3 4 5 6

x 3 5 7 2

j 1 0 2 1 3 4 3 2 1 0

Example 11.3.6 Finding a Worst-Case Order for Insertion Sort

a. What is the maximum number of comparisons that are performed when insertion sort is applied to the array a[1], a[2], a[3], . . . , a[n]?

b. Use the theorem on polynomial orders to find a worst-case order for insertion sort. Solution

a. In each attempted iteration of the while loop, two explicit comparisons are made: one to test whether j ̸= 0 and the other to test whether a[ j] > x . During the time that a[k] is put into position relative to a[1], a[2], . . . , a[k − 1], the maximum number of attempted iterations of the while loop is k. This happens when a[k] is less than every a[1], a[2], . . . , a[k − 1]; on the kth attempted iteration, the condition of the while loop is not satisfied because j = 0. Thus the maximum number of comparisons for a given value of k is 2k. Because k goes from 2 to n, it follows that the maximum total number of comparisons occurs when the items in the array are in reverse order, and it equals

2 ·2 + 2 ·3 + · · · + 2 ·n = 2(2 + 3 + · · · + n) by factoring out the 2 = 2[(1 + 2 + 3 + · · · + n)− 1] by adding and subtracting 1

= 2 (

n(n + 1) 2

− 1 )

by Theorem 5.2.2

= n(n + 1)− 2 = n2 + n − 2 by algebra.

b. By the theorem on polynomial orders, n2 + n − 2 is "(n2), and so the insertion sort algorithm has worst-case order "(n2). ■

The definition of expected value that was introduced in Section 9.8 can be used to find an average-case order for insertion sort.

Example 11.3.7 Finding an Average-Case Order for Insertion Sort

a. What is the average number of comparisons that are performed when insertion sort is applied to the array a[1], a[2], a[3], . . . , a[n]?

b. Use the theorem on polynomial orders to find an average-case order for insertion sort.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 747

Solution

a. Let En be the average, or expected, number of comparisons used to sort a[1], a[2], . . . , a[n] with insertion sort. Note that for each integer k = 2, 3, . . . , n, ⎡

⎣ the expected number of comparisons used to sort a[1], a[2], . . . , a[k]

=

⎣ the expected number of comparisons used to sort a[1], a[2], . . . , a[k − 1]

⎦+

⎣ the expected number of comparisons used to place a[k] into position relative to a[1], a[2], . . . , a[k − 1]

⎦ .

Thus

Ek = Ek−1 +

⎣ the expected number of comparisons used to place a[k] into position relative to a[1], a[2], . . . , a[k − 1]

⎦ .

Also, E1 = 0 because when there is just one item in the array, n = 1 and no iterations of the outer loop are performed.

Now at the time a[k] is placed relative to a[1], a[2], . . . , a[k − 1], a reasonable assumption is that it is equally likely to belong in any one of the first k positions. Thus the probability of its belonging in any particular position is 1/k. If it actually belongs in position j , then 2(k − j + 1) comparisons will be used in moving it, because there will be k − j + 1 attempted iterations of the while loop and there are 2 comparisons per attempted iteration.

According to the definition of expected value given in Section 9.8, the expected number of comparisons used to place a[k] relative to a[1], a[2], . . . , a[k − 1] is therefore

k∑

j=1

1 k

2(k − j + 1) = 2 k [k + (k − 1) + · · · + 3 + 2 + 1] by writing thesummation in expanded

form

= 2 k

( k(k + 1)

2

) by Theorem 5.2.2

= k + 1 by algebra. Hence

Ek = Ek−1 + k + 1 for all integers k ≥ 2, and E1 = 0.

Exercise 27 at the end of the section asks you to solve this recurrence relation to show that

En = n2 + 3n − 4

2 for each integer n ≥ 1.

b. By the theorem on polynomial orders, n2 + 3n − 4

2 = 1

2 n2 + 3

2 n − 2 is "(n2), and

so the average-case order of insertion sort is also "(n2). ■

Test Yourself 1. When an algorithm segment contains a nested for-next

loop, you can find the number of times the loop will iterate by constructing a table in which each column represents _____.

2. In the worst case for an input array of length n, the sequen- tial search algorithm has to look through _____ elements of the array before it terminates.

3. The worst-case order of the insertion sort algorithm is _____, and its average-case order is _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

748 Chapter 11 Analysis of Algorithm Efficiency

Exercise Set 11.3 1. Suppose a computer takes 1 nanosecond (= 10−9 second)

to execute each operation. Approximately how long will it take for the computer to execute the following numbers of operations? Convert your answers into seconds, minutes, hours, days, weeks, or years, as appropriate. For example, instead of 250 nanoseconds, write 13 days. a. log2 200 b. 200 c. 200 log2 200 d. 2002 e. 2008 f. 2200

2. Suppose an algorithm requires cn2 operations when per- formed with an input of size n (where c is a constant). a. How many operations will be required when the input

size is increased from m to 2m (where m is a positive integer)?

b. By what factor will the number of operations increase when the input size is doubled?

c. By what factor will the number of operations increase when the input size is increased by a factor of ten?

3. Suppose an algorithm requires cn3 operations when per- formed with an input of size n (where c is a constant). a. How many operations will be required when the input

size is increased from m to 2m (where m is a positive integer)?

b. By what factor will the number of operations increase when the input size is doubled?

c. By what factor will the number of operations increase when the input size is increased by a factor of ten?

Exercises 4–5 explore the fact that for relatively small values of n, algorithms with larger orders can be more efficient than algorithms with smaller orders.

4. Suppose that when run with an input of size n, algorithm A requires 2n2 operations and algorithm B requires 80n3/2

operations. a. What are orders for algorithms A and B from among the

set of power functions? b. For what values of n is algorithm A more efficient than

algorithm B? c. For what values of n is algorithm B at least 100 times

more efficient than algorithm A?

5. Suppose that when run with an input of size n, algorithm A requires 106n2 operations and algorithm B requires n3

operations. a. What are orders for algorithms A and B from among the

set of power functions? b. For what values of n is algorithm A more efficient than

algorithm B? c. For what values of n is algorithm B at least 100 times

more efficient than algorithm A?

For each of the algorithm segments in 6–19, assume that n is a positive integer. (a) Compute the actual number of additions,

subtractions, multiplications, divisions, and comparisons that must be performed when the algorithm segment is executed. For simplicity, however, count only comparisons that occur within if-then statements; ignore those implied by for-next loops. (b) Use the theorem on polynomial orders to find an order for the algorithm segment.

6. for i := 3 to n − 1 a := 3 ·n + 2 · i − 1

next i

7. max := a[1] for i := 2 to n

if max < a[i] then max := a[i] next i

8. for i := 1 to ⌊n/2⌋ a := n − i

next i

9. for i := 1 to n for j := 1 to 2n

a := 2 ·n + i · j next j

next i

10. for k := 2 to n for j := 1 to 3n

x := a[k]− b[ j] next j

next k

11. for k := 1 to n − 1 for j := 1 to k + 1

x := a[k] + b[ j] next j

next k

12. for k := 1 to n − 1 max := a[k] for i := k + 1 to n

if max < a[i] then max := a[i] next i

a[k] := max next k

13. for i := 1 to n − 1 for j := i to n

if a[ j] > a[i] then do temp := a[i] a[i] := a[ j] a[ j] := temp end do

next j next i

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.3 Application: Analysis of Algorithm Efficiency I 749

14. t := 0 for i := 1 to n

s := 0 for j := 1 to i

s := s + a[ j] next j t := t + s2

next i

15. r := 0 for i := 1 to n − 1

p := 1 q := 1 for j := i + 1 to n

p := p ·c[ j] q := q ·(c[ j])2

next j r := p + q

next i

16. t := 0 for i := 1 to n

s := 0 for j := 1 to i − 1

s := s + j ·(i − j + 1) next j r := s2

next i

17. for i := 1 to n for j := 1 to ⌊(i + 1)/2⌋

a := (n − i) ·(n − j) next j

next i

18. for i := 1 to n for j := ⌊(i + 1)/2⌋ to n

x := i · j next j

next i

19.✶H for i := 1 to n for j := 1 to i

for k := 1 to j x := i · j ·k

next k next j

next i

20. Construct a table showing the result of each step when insertion sort is applied to the array a[1] = 6, a[2] = 2, a[3] = 1, a[4] = 8, and a[5] = 4.

21. Construct a table showing the result of each step when insertion sort is applied to the array a[1] = 7, a[2] = 3, a[3] = 6, a[4] = 9, and a[5] = 5.

22. Construct a trace table showing the action of insertion sort on the array of exercise 20.

23. Construct a trace table showing the action of insertion sort on the array of exercise 21.

24. How many comparisons between values of a[ j] and x actu- ally occur when insertion sort is applied to the array of exer- cise 20?

25. How many comparisons between values of a[ j] and x actu- ally occur when insertion sort is applied to the array of exer- cise 21?

26. According to Example 11.3.6, the maximum number of comparisons needed to perform insertion sort on an array of length five is 52 − 5 + 2 = 22. Find an array of length five that requires the maximum number of comparisons when insertion sort is applied to it.

27.H Consider the recurrence relation that arose in Example 11.3.7: E1 = 0 and Ek = Ek−1 + k + 1, for all integers k ≥ 2. a. Use iteration to find an explicit formula for the sequence. b. Use mathematical induction to verify the correctness of

the formula.

Exercises 28–35 refer to selection sort, which is another algo- rithm to arrange the items in an array in ascending order.

Algorithm 11.3.2 Selection Sort [Starting with an array a[1], a[2], a[3], . . . , a[n], this algo- rithm sorts the array by selecting the correct item to place in each position by moving sequentially through the elements of the array. In general, for each k = 1 to n − 1, the kth step of the algorithm finds the index of the array item with minimum value from among a[k + 1], a[k + 2], a[k + 3], . . . , a[n]. Once this index is found, the value of the corresponding array item is inter- changed with the value of a[k]. At the end of execution the array elements are in order.]

Input: n [a positive integer], a[1], a[2], a[3], . . . , a[n] [an array of data items capable of being ordered]

Algorithm Body:

for k := 1 to n − 1 IndexOfMin := k for i := k + 1 to n

if (a[i] < a[IndexOfMin]) then IndexOfMin := i

next i if IndexOfMin ̸= k then

Temp := a[k] a[k] := a[IndexOfMin] a[IndexOfMin] := Temp

next k Output: , a[1], a[2], a[3], . . . , a[n] [in ascending order]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

750 Chapter 11 Analysis of Algorithm Efficiency

The action of selection sort can be represented pictorially as follows:

a[1] a[2] · · · a[k] a[k + 1] · · · a[n] ↑

kth step: Find the index of the array element with minimum value from among a[k + 1], . . . , a[n] and interchange its value with the value of a[k].

28. Construct a table showing the interchanges that occur when selection sort is applied to the array a[1] = 5, a[2] = 3, a[3] = 4, a[4] = 6, and a[5] = 2.

29. Construct a table showing the interchanges that occur when selection sort is applied to the array a[1] = 6, a[2] = 4, a[3] = 5, a[4] = 8, and a[5] = 1.

30. Construct a trace table showing the action of selection sort on the array of exercise 28.

31. Construct a trace table showing the action of selection sort on the array of exercise 29.

32. When selection sort is applied to the array of exercise 28, how many times is the comparison in the if-then statement performed?

33. When selection sort is applied to the array of exercise 29, how many times is the comparison in the if-then statement performed?

34. When selection sort is applied to an array a[1], a[2], a[3], a[4], how many times is the comparison in the if-then state- ment performed?

35. Consider applying selection sort to an array a[1], a[2], a[3], . . . , a[n]. a. How many times is the comparison in the if-then state-

ment performed when a[1] is compared to each of a[2], a[3], . . . , a[n]?

b. How many times is the comparison in the if-then state- ment performed when a[2] is compared to each of a[3], a[4], . . . , a[n]?

c. How many times is the comparison in the if-then state- ment performed when a[k] is compared to each of a[k − 1], a[k + 2], . . . , a[n]?

d.H Using the number of times the comparison in the if-then statement is performed as a measure of the time effi- ciency of selection sort, find an order for selection sort. Use the theorem on polynomial orders.

Exercises 36–39 refer to the following algorithm to compute the value of a real polynomial.

Algorithm 11.3.3 Term-by-Term Polynomial Evaluation [This algorithm computes the value of the real polynomial a[n]xn + a[n − 1]xn−1 + · · · + a[2]x2 + a[1]x + a[0] by computing each term separately, starting with a[0], and adding it on to an accumulating sum.]

Input: n [a nonnegative integer] a[0], a[1], a[2], . . . , a[n] [an array of real numbers], x [a real number] Algorithm Body:

polyval := a[0] for i := 1 to n

term := a[i] for j := 1 to i

term := term ·x next j polyval := polyval + term

next i [At this point

polyval= a[n]xn + a[n − 1]xn−1 + · · · + a[2]x2 + a[1]x + a[0].]

Output: polyval [a real number]

36. Trace Algorithm 11.3.3 for the input n = 3, a[0] = 2, a[1] = 1, a[2] = −1, a[3] = 3, and x = 2.

37. Trace Algorithm 11.3.3 for the input n = 2, a[0] = 5, a[1] = −1, a[2] = 2, and x = 3.

38. Let sn = the number of additions and multiplications that must be performed when Algorithm 11.3.3 is executed for a polynomial of degree n. Express sn as a function of n.

39. Use the theorem on on polynomial orders to find an order for Algorithm 11.3.3.

Exercises 40–43 refer to another algorithm, known as Horner’s rule, for finding the value of a real polynomial.

Algorithm 11.3.4 Horner’s Rule [This algorithm computes the value of the real polyno- mial a[n]xn + a[n − 1]xn−1 + · · · + a[2]x2 + a[1]x + a[0] by nesting successive additions and multiplications as indicated in the following parenthesization:

((· · · ((a[n]x + a[n − 1])x + a[n − 2])x + · · · + a[2])x + a[1])x + a[0].

At each stage, starting with a[n], the current value of polyval is multiplied by x and the next lower coefficient of the polynomial is added on.]

Input: n [a nonnegative integer] a[0], a[1], a[2], . . . , a[n] [an array of real numbers], x [a real number]

Algorithm Body:

polyval := a[n] for i := 1 to n

polyval := polyval · x + a[n − i] next i [At this point

polyval= a[n]xn + a[n − 1]xn−1 + · · · + a[2]x2 + a[1]x + a[0].]

Output: polyval [a real number]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 751

40. Trace Algorithm 11.3.4 for the input n = 3, a[0] = 2, a[1] = 1, a[2] = −1, a[3] = 3, and x = 2.

41. Trace Algorithm 11.3.4 for the input n = 2, a[0] = 5, a[1] = −1, a[2] = 2, and x = 3.

42.H Let tn = the number of additions and multiplications that

must be performed when Algorithm 11.3.4 is executed for a polynomial of degree n. Express tn as a function of n.

43. Use the theorem on polynomial orders to find an order for Algorithm 11.3.4. How does this order compare with that of Algorithm 11.3.3?

Answers for Test Yourself 1. one iteration of the innermost loop 2. n 3. n2; n2

11.4 Exponential and Logarithmic Functions: Graphs and Orders We ought never to allow ourselves to be persuaded of the truth of anything unless on the evidence of our own reason. — René Descartes, 1596–1650

Exponential and logarithmic functions are of great importance in mathematics in gen- eral and in computer science in particular. Several important computer algorithms have execution times that involve logarithmic functions of the size of the input data (which means they are relatively efficient for large data sets), and some have execution times that are exponential functions of the size of the input data (which means they are quite inefficient for large data sets). In addition, since exponential and logarithmic functions arise naturally in the descriptions of many growth and decay processes and in the compu- tation of many kinds of probabilities, these functions are used in the analysis of computer operating systems, in queuing theory, and in the theory of information.

Graphs of Exponential Functions As defined in Section 7.2, the exponential function with base b > 0 is the function that sends each real number x to bx . The graph of the exponential function with base 2 (together with a partial table of its values) is shown in Figure 11.4.1. Note that the values of this function increase with extraordinary rapidity. If we tried to continue drawing the graph using the scale shown in Figure 11.4.1, we would have to plot the point (10, 210) more than 21 feet above the horizontal axis. And the point (30, 230) would be located more than 610,080 miles above the axis—well beyond the moon!

x

y

1–1–2–3 2 3

1

2

3

4

5

6

7 y = 2x

x 2x

0

1

2

3

–1

–2

–3

0.5

–0.5

20 P 1 21 P 2 22 P 4 23 P 8

2–1 P 0.5 2–2 P 0.25 2–3 P 0.125 20.5 1.414

2–0.5 0.707

Figure 11.4.1 The Exponential Function with Base 2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

752 Chapter 11 Analysis of Algorithm Efficiency

The graph of any exponential function with base b > 1 has a shape that is similar to the graph of the exponential function with base 2. If 0 < b < 1, then 1/b > 0 and the graph of the exponential function with base b is the reflection across the vertical axis of the exponential function with base 1/b. These facts are illustrated in Figure 11.4.2.

1–1–2 2

y

x

(1, b)b 1(–1, )1b

y = bx, b > 1

Graph of the exponential function with base b > 1

(a)

1–1–2 2

y

x

(1, b) b 1

(–1, )1b

y = bx, 0 < b <†1

Graph of the exponential function with base b where 0 < b < 1

(b)

Figure 11.4.2 Graphs of Exponential Functions

Graphs of Logarithmic Functions Logarithms were first introduced by the Scotsman John Napier. Astronomers and naviga- tors found them so useful for reducing the time needed to do multiplication and division that they quickly gained wide acceptance and played a crucial role in the remarkable development of those areas in the seventeenth century. Nowadays, however, electronic calculators and computers are available to handle most computations quickly and conve- niently, and logarithms and logarithmic functions are used primarily as conceptual tools.

B et

tm an

n/ CO

R B

IS

John Napier (1550–1617)

Recall the definition of the logarithmic function with base b from Section 7.1. We state it formally below.

• Definition If b is a positive real number not equal to 1, then the logarithmic function with base b, log b: R+ → R, is the function that sends each positive real number x to the number logb x , which is the exponent to which b must be raised to obtain x .

The logarithmic function with base b is, in fact, the inverse of the exponential function with base b. (See exercise 10 at the end of this section.) It follows that the graphs of the two functions are symmetric with respect to the line y = x . The graph of the logarithmic function with base b > 1 is shown in Figure 11.4.3 on the next page.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 753

x

y

1

1

–1

y = logb x

logb x1

logb x2

x1 x2

Figure 11.4.3 The Graph of the Logarithmic Function with Base b > 1

If its base b is greater than 1, the logarithmic function is increasing. Analytically, this means that

if b > 1, then for all positive numbers x1 and x2,

if x1 < x2, then logb(x1) < logb(x2). 11.4.1

Corresponding to the rapid growth of the exponential function, however, is the very slow growth of the logarithmic function. Thus you must go very far out on the horizontal axis to find points whose logarithms are large numbers.

Note As examples, log2(1,024) is only 10 and log2(1,048,576) is just 20.

The following example shows how to make use of the increasing nature of the loga- rithmic function with base 2 to derive a remarkably useful property.

Example 11.4.1 Base 2 Logarithms of Numbers between Two Consecutive Powers of 2

Prove the following property:

a.

If k is an integer and x is a real number with

2k ≤ x < 2k+1, then ⌊log2 x⌋ = k. 11.4.2

b. Describe property (11.4.2) in words and give a graphical interpretation of the property for x > 1.

Solution

a. Suppose that k is an integer and x is a real number with

2k ≤ x < 2k+1. Because the logarithmic function with base 2 is increasing, this implies that

log2(2 k) ≤ log2 x < log2(2k+1).

But log2(2 k) = k [the exponent to which you must raise 2 to get 2k is k] and log2(2k+1) =

k + 1 [for a similar reason]. Hence k ≤ log2 x < k + 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

754 Chapter 11 Analysis of Algorithm Efficiency

By definition of the floor function, then,

⌊log2 x⌋ = k. b. Recall that the floor of a positive number is its integer part. For instance, ⌊2.82⌋ =

2. Hence property (11.4.2) can be described in words as follows:

If x is a positive number that lies between two consecutive integer powers of 2, the floor of the logarithm with base 2 of x is the exponent of the smaller power of 2.

A graphical interpretation follows:

y = log2 x

0

1

2

3

k

k + 1

1 2 22 = 4 23 = 8 2k 2k+1If x lies in here

then log2 x lies in here:

One consequence of property (11.4.2) does not appear particularly interesting in its own right but is frequently needed as a step in the analysis of algorithm efficiency.

Example 11.4.2 When ⌊log2(n − 1)⌋ = ⌊log2 n⌋ Prove the following property:

For any odd integer n > 1, ⌊log2(n − 1)⌋ = ⌊log2 n⌋. 11.4.3

Solution If n is an odd integer that is greater than 1, then n lies strictly between two suc- cessive powers of 2:

2k < n < 2k+1 for some integer k > 0. 11.4.4

It follows that 2k ≤ n − 1 because 2k < n and both 2k and n are integers. Consequently, 2k ≤ n − 1 < 2k+1. 11.4.5

Applying property (11.4.2) to both (11.4.4) and (11.4.5) gives

⌊log2 n⌋ = k and also ⌊log2(n − 1)⌋ = k. Hence ⌊log2 n⌋ = ⌊log2(n − 1)⌋. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 755

Application: Number of Bits Needed to Represent an Integer in Binary Notation

Given a positive integer n, how many binary digits are needed to represent n? To answer this question, recall from Section 5.4 that any positive integer n can be written in a unique way as

n = 2k + ck−1·2k−1 + · · · + c2·22 + c1·2 + c0, where k is a nonnegative integer and each c0, c1, c2, . . . ck−1 is either 0 or 1. Then the binary representation of n is

1ck−1ck−2 · · · c2c1c0, and so the number of binary digits needed to represent n is k + 1.

What is k + 1 as a function of n? Observe that since each ci ≤ 1, n = 2k + ck−1·2k−1 + · · · + c2·22 + c1·2 + c0 ≤ 2k + 2k−1 + · · · + 22 + 2 + 1.

But by the formula for the sum of a geometric sequence (Theorem 5.2.3),

2k + 2k−1 + · · · + 22 + 2 + 1 = 2 k+1 − 1 2− 1 = 2

k+1 − 1.

Hence, by transitivity of order,

n ≤ 2k+1 − 1 < 2k+1 11.4.6 In addition, because each ci ≥ 0,

2k ≤ 2k + ck−1·2k−1 + · · · + c2·22 + c1·2 + c0 = n. 11.4.7 Putting inequalities (11.4.6) and (11.4.7) together gives the double inequality

2k ≤ n < 2k+1. But then, by property (11.4.2),

k = ⌊log2 n⌋. Thus the number of binary digits needed to represent n is ⌊log2 n⌋+ 1.

Example 11.4.3 Number of Bits in a Binary Representation

How many binary digits are needed to represent 52,837 in binary notation?

Solution If you compute the logarithm with base 2 using the formula in part (a) of Theorem 7.2.1 and a calculator that gives you approximate values of logarithms with base 10, you find that

log2(52,837) ∼= log10(52,837)

log10(2) ∼= 4.722938151

0.3010299957 ∼= 15.7.

Thus the binary representation of 52,837 has ⌊15.7⌋+ 1 = 15 + 1 = 16 binary digits. ■

Application: Using Logarithms to Solve Recurrence Relations

In Chapter 5 we discussed methods for solving recurrence relations. One class of recur- rence relations that is very important in computer science has solutions that can be

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

756 Chapter 11 Analysis of Algorithm Efficiency

expressed in terms of logarithms. One such recurrence relation is discussed in the next example.

Example 11.4.4 A Recurrence Relation with a Logarithmic Solution

Define a sequence a1, a2, a3, . . . recursively as follows:

a1 = 1, ak = 2a⌊k/2⌋ for all integers k ≥ 2.

a. Use iteration to guess an explicit formula for this sequence.

b. Use strong mathematical induction to confirm the correctness of the formula obtained in part (a).

Solution

a. Begin by iterating to find the values of the first few terms of the sequence.

→ a1 = 1 1 = 20 a2 = 2a⌊2/2⌋ = 2a1 = 2 ·1 = 2→ a3 = 2a⌊3/2⌋ = 2a1 = 2 ·1 = 2

} 2 = 21

a4 = 2a⌊4/2⌋ = 2a2 = 2 ·2 = 4→ a5 = 2a⌊5/2⌋ = 2a2 = 2 ·2 = 4 a6 = 2a⌊6/2⌋ = 2a3 = 2 ·2 = 4 a7 = 2a⌊7/2⌋ = 2a3 = 2 ·2 = 4

⎫ ⎪⎪⎪⎬

⎪⎪⎪⎭

4 = 22

a8 = 2a⌊8/2⌋ = 2a4 = 2 ·4 = 8→ a9 = 2a⌊9/2⌋ = 2a4 = 2 ·4 = 8 ...

...

a15 = 2a⌊15/2⌋ = 2a7 = 2 ·4 = 8

⎫ ⎪⎪⎪⎬

⎪⎪⎪⎭

8 = 23

a16 = 2a⌊16/2⌋ = 2a8 = 2 ·8 = 16→... ...

⎫ ⎪⎪⎪⎪⎪⎬

⎪⎪⎪⎪⎪⎭

16 = 24

Note that in each case when the subscript n is between two powers of 2, an equals the smaller power of 2. More precisely:

If 2i ≤ n < 2i+1, then an = 2i . 11.4.8 But since n satisfies the inequality

2i ≤ n < 2i+1, then (by property 11.4.2)

i = ⌊log2 n⌋. Substituting into statement (11.4.8) gives

an = 2⌊log2 n⌋. b. The following proof shows that if a1, a2, a3, . . . is a sequence of numbers that satisfies

a1 = 1, and ak = 2a⌊k/2⌋ for all integers k ≥ 2, then the sequence satisfies the formula

an = 2⌊log2 n⌋ for all integers n ≥ 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 757

Proof:

Let a1, a2, a3, . . . be the sequence defined by specifying that a1 = 1 and ak = 2⌊ak/2⌋ for all integers k ≥ 2, and let the property P(n) be the equation

an = 2⌊log2 n⌋. ← P(n) We will use strong mathematical induction to prove that for all integers n ≥ 1, P(n) is true.

Show that P (1) is true: By definition of a1, a2, a3, . . . , we have that a1 = 1. But it is also the case that 2⌊log2 1⌋ = 20 = 1. Thus a1 = 2⌊log2 1⌋ and P(1) is true. Show that for all integers k ≥ 1, if P(i) is true for all integers i from 1 through k, then P(k + 1) is also true: Let k be any integer with k ≥ 1, and suppose that

ai = 2⌊log2 i⌋ for all integers i with 1 ≤ i ≤ k. ←inductive hypothesis We must show that

ak+1 = 2⌊log2(k+1)⌋ ← P(k + 1) Consider the two cases: k is even and k is odd.

Case 1 (k is even): In this case, k + 1 is odd, and ak+1 = 2a⌊(k+1)/2⌋ by definition of a1, a2, a3, . . .

= 2a k/2 because ⌊(k + 1)/2⌋ = k/2 since k + 1 is odd = 2 ·2⌊log2(k/2)⌋ by inductive hypothesis because, since k is even,

k ≥ 2, and so k/2 ≥ 1 = 2⌊log2(k/2)⌋+1 by the laws of exponents from algebra (7.2.1) = 2⌊log2 k−log2 2⌋+1 by the identity logb(x/y) = logb x − logb y

from Theorem 7.2.1

= 2⌊log2 k−1⌋+1 since log2 2 = 1 = 2⌊log2 k⌋−1+1 by substituting x = log2 k into the identity⌊x − 1⌋ = ⌊x⌋ − 1 derived in exercise 15 of Section 4.5 = 2⌊log2 k⌋ = 2⌊log2(k+1)⌋ by property (11.4.3)

Case 2 (k is odd): The analysis of this case is very similar to that of case 1 and is left as exercise 56 at the end of the section.

Thus in either case, an = 2⌊log2(k+1)⌋, as was to be shown. ■

Exponential and Logarithmic Orders Now consider the question “How do graphs of logarithmic and exponential functions compare with graphs of power functions?” It turns out that for large enough values of x , the graph of the logarithmic function with any base b > 1 lies below the graph of any pos- itive power function, and the graph of the exponential function with any base b > 1 lies above the graph of any positive power function. In analytic terms, this says the following:

For all real numbers b and r with b > 1 and r > 0,

logb x ≤ xr for all sufficiently large real numbers x . 11.4.9 and xr ≤ bx for all sufficiently large real numbers x . 11.4.10

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

758 Chapter 11 Analysis of Algorithm Efficiency

These statements have the following implications for O-notation.

For all real numbers b and r with b > 1 and r > 0,

logb x is O(x r ) 11.4.11

and xr is O(bx ) 11.4.12

Another important function in the analysis of algorithms is the function f defined by the formula

f (x) = x logb x for all real numbers x > 0. For large values of x , the graph of this function fits in between the graph of the identity function and the graph of the squaring function. More precisely:

For all real numbers b with b > 1 and for all sufficiently large real numbers x ,

x ≤ x logb x ≤ x2. 11.4.13

The O-notation versions of these facts are as follows:

For all real numbers b > 1,

x is O(x logb x) and x logb x is O(x 2). 11.4.14

Although proofs of some of these facts require calculus, proofs of some cases can be obtained using the algebra of inequalities. (See the exercises at the end of this section.) Figure 11.4.4 illustrates the relationships among some power functions, the logarithmic function with base 2, the exponential function with base 2, and the function defined by the formula x → x log2 x . Note that different scales are used on the horizontal and verti- cal axes.

Example 11.4.5 shows how to use inequalities such as (11.4.9), (11.4.10), and (11.4.13) to derive additional orders involving the logarithmic function.

Example 11.4.5 Deriving an Order from Logarithmic Inequalities

Show that x + x log2 x is "(x log2 x). Solution First observe that x + x log2 x is !(x log2 x) because for all real numbers x > 1,

x log2 x ≤ x + x log2 x, and since all quantities are positive,

|x log2 x | ≤ |x + x log2 x |. Let A = 1 and a = 1. Then

A|x log2 x | ≤ |x + x log2 x | for all x > a. Hence, by definition of !-notation,

x + x log2 x is !(x log2 x).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 759

x

y

1 2 3 4

5

10

15

20

y = 2x

y = x2

y = x log2x

y = log2x

y = x

Figure 11.4.4 Graphs of Some Logarithmic, Exponential, and Power Functions

To show that x + x log2 x is O(x log2 x), note that according to property (11.4.13) with b = 2, there is a number b such that for all x > b,

x < x log2 x

⇒ x + x log2 x < 2x log2 x by adding x log2 x to both sides Thus, if b is taken to be greater than 2, then

|x + x log2 x | < 2|x log2 x | because when x > 2, x log2 x > 0, and so |x + x log2 x | = x + x log2 x and log2 x = |x log2 x |.

Let B = 2. Then |x + x log2 x | ≤ B|x log2 x | for all x > b.

Hence, by definition of O-notation

x + x log2 x is O(x log2 x). Therefore, since x + x log2 x is !(x log2 x) and x + x log2 x is O(x log2 x), by Theorem 11.2.1,

x + x log2 x is "(x log2 x). ■

Example 11.4.5 illustrates a special case of a useful general fact about O-notation: If one function “dominates” another (in the sense of being larger for large values of the variable), then the sum of the two is big-O of the dominating function. (See exercise 49a in Section 11.2.)

Example 11.4.6 shows that any two logarithmic functions with bases greater than 1 have the same order.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

760 Chapter 11 Analysis of Algorithm Efficiency

Example 11.4.6 Logarithm with Base b Is Big-Theta of Logarithm with Base c

Show that if b and c are real numbers such that b > 1 and c > 1, then logb x is "(logc x).

Solution Suppose b and c are real numbers and b > 1 and c > 1. To show that logb x is "(logc x), positive real numbers A, B, and k must be found such that

A| logc x | ≤ | logb x | ≤ B| logc x | for all real numbers x > k. By part (d) of Theorem 7.2.1,

logb x = logc x logc b

= (

1 logc b

) logc x . (∗)

Since b > 1 and the logarithmic function with base c is strictly increasing, then logc b >

logc 1 = 0, and so 1

logc b > 0 also. Furthermore, if x > 1, then logb x > 0 and logc x > 0.

It follows from equation (∗), therefore, that (

1 logc b

) logc x ≤ logb x ≤

( 1

logc b

) logc x (∗∗)

for all real numbers x > 1. Accordingly, let A = 1 logc b

, B = 1 logc b

, and k = 1. Then, since all quantities in (∗∗) are positive,

A| logc x | ≤ | logb x | ≤ B| logc x | for all real numbers x > k. Hence, by definition of "-notation,

logb x is "(logc x). ■

Example 11.4.7 shows how a logarithmic order can arise from the computation of a certain kind of sum. It requires the following fact from calculus:

The area underneath the graph of y = 1/x between x = 1 and x = n equals ln n, where ln n = loge n. This fact is illustrated in Figure 11.4.5.

x

y

n1

1

Graph of y = 1x

Area of shaded region = ln n

Figure 11.4.5 Area Under Graph of y = 1 x

Between x = 1 and x = n

Example 11.4.7 Order of a Harmonic Sum

Sums of the form 1 + 1 2

+ · · · + 1 n

are called harmonic sums. They occur in the analysis

of various computer algorithms such as quick sort. Show that 1 + 1 2

+ 1 3

+ · · · + 1 n

is !(ln n) by performing the steps on the next page:

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 761

a. Interpret Figure 11.4.6 to show that

1 2

+ 1 3

+ · · · + 1 n ≤ ln n.

and

ln n ≤ 1 + 1 2

+ 1 3

+ · · · + 1 n .

b. Show that if n is an integer that is at least 3, then 1 ≤ ln n. c. Deduce from (a) and (b) that if the integer n is greater than or equal to 3, then

ln n ≤ 1 + 1 2

+ 1 3

+ · · · + 1 n ≤ 2 ln n.

d. Deduce from (c) that

1 + 1 2

+ 1 3

+ · · · + 1 n

is "(ln n).

Solution

a. Figure 11.4.6(a) shows rectangles whose bases are the intervals between each pair of integers from 1 to n and whose heights are the heights of the graph of y = 1/x above the right-hand endpoints of the intervals. Figure 11.4.6(b) shows rectangles with the same bases but whose heights are the heights of the graph above the left-hand endpoints of the intervals.

x

y

1 2 3 4 n – 1 n

(1, 1) Total area under graph from 1 to n = ln n

(2, )12 (3, )13 (4, )14 (n – 1, )1n – 1 (n, )1n (n – 1, ) 1

n – 1

x

y

1 2 3 4 n – 1 n

(1, 1)

Graph of y = 1xGraph of y = 1 x

Total area under graph from 1 to n = ln n

(2, )12 (3, )13 (4, )14 (n, )1n

(a) (b)

1 1

Figure 11.4.6 Now the area of each rectangle is its base times its height. Since all the rectangles

have base 1, the area of each rectangle equals its height. Thus in Figure 11.4.6(a),

the area of the rectangle from 1 to 2 is 1 2 ;

the area of the rectangle from 2 to 3 is 1 3 ;

...

the area of the rectangle from n − 1 to n is 1 n .

So the sum of the areas of all the rectangles is 1 2

+ 1 3

+ · · · + 1 n

. From the picture it

is clear that this sum is less than the area underneath the graph of f between x = 1 and x = n, which is known to equal ln n. Hence

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

762 Chapter 11 Analysis of Algorithm Efficiency

1 2

+ 1 3

+ · · · + 1 n ≤ ln n.

A similar analysis of the areas of the combined blue and gray rectangles in Figure 11.4.6(b) shows that

ln n ≤ 1 + 1 2

+ 1 3

+ · · · + 1 n .

b. Suppose n is an integer and n ≥ 3. Since e ∼= 2.718, then n ≥ e. Now the logarithmic function with base e is strictly increasing. Thus since e ≤ n, then 1 = ln e ≤ ln n.

c. By part (a),

1 2

+ 1 3

+ · · · + 1 n ≤ ln n,

and by part (b),

1 ≤ ln n. Adding these two inequalities together gives

1 + 1 2

+ 1 3

+ · · · + 1 n ≤ 2 ln n for any integer n ≥ 3.

d. Putting together the results of parts (a) and (c) leads to the conclusion that for all integers n ≥ 3,

ln n ≤ 1 + 1 2

+ 1 3

+ · · · + 1 n ≤ 2 ln n.

And because all the quantities are positive for n ≥ 3,

| ln n| ≤ ∣∣∣∣1 +

1 2

+ 1 3

+ · · · + 1 n

∣∣∣∣ ≤ 2| ln n|.

Let A = 1, B = 2, and k = 3. Then

A| ln n| ≤ ∣∣∣∣1 +

1 2

+ 1 3

+ · · · + 1 n

∣∣∣∣ ≤ B| ln n| for all n > k.

Hence by definition of "-notation,

1 + 1 2

+ 1 3

+ · · · + 1 n

is "(ln n). ■

Test Yourself 1. The domain of any exponential function is _____, and its

range is _____.

2. The domain of any logarithmic function is _____, and its range is _____.

3. If k is an integer and 2k ≤ x < 2k+1, then ⌊log2 x⌋ = _____.

4. If b is a real number with b > 1 and if x is a sufficiently large real number, then when the quantities x, x2, logb x , and x logb x are arranged in order of increasing size, the result is _____.

5. If n is a positive integer, then 1 + 12 + 13 + · · · + 1n has order _____.

Exercise Set 11.4 Graph each function defined in 1–8.

1. f (x) = 3x for all real numbers x 2. g(x) =

( 1 3

)x for all real numbers x

3. h(x) = log10 x for all positive real numbers x 4. k(x) = log2 x for all positive real numbers x 5. F(x) = ⌊log2 x⌋ for all positive real numbers x

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.4 Exponential and Logarithmic Functions: Graphs and Orders 763

6. G(x) = ⌈log2 x⌉ for all positive real numbers x 7. H(x) = x log2 x for all positive real numbers x 8. K (x) = x log10 x for all positive real numbers x 9. The scale of the graph shown in Figure 11.4.1 is one-fourth

inch to each unit. If the point (2, 264) is plotted on the graph of y = 2x , how many miles will it lie above the horizontal axis? What is the ratio of the height of the point to the dis- tance of the earth from the sun? (There are 12 inches per foot and 5,280 feet per mile. The earth is approximately 93,000,000 miles from the sun on average.) ( 14 inch

∼= 0.635 cm, 1 mile ∼= 0.62 km) 10. a. Use the definition of logarithm to show that logbb

x = x for all real numbers x .

b. Use the definition of logarithm to show that blogbx = x for all positive real numbers x .

c. By the result of exercise 25 in Section 7.3, if f : X → Y and g: Y→ X are functions and g◦ f = IX and f ◦g = IY , then f and g are inverse functions. Use this result to show that logb and expb (the exponential function with base b) are inverse functions.

11. Let b > 1. a. Use the fact that u = logb v ⇔ v = bu to show that a

point (u, v) lies on the graph of the logarithmic function with base b if, and only if, (v, u) lies on the graph of the exponential function with base b.

b. Plot several pairs of points of the form (u, v) and (v, u) on a coordinate system. Describe the geometric relation- ship between the locations of the points in each pair.

c. Draw the graphs of y = log2 x and y = 2x . Describe the geometric relationship between these graphs.

12. Give a graphical interpretation for property (11.4.2) in Example 11.4.1(a) for 0 < x < 1.

13.H Suppose a positive real number x satisfies the inequal- ity 10m ≤ x < 10m+1 where m is an integer. What can be inferred about ⌊log10 x⌋? Justify your answer.

14. a. Prove that if x is a positive real number and k is a nonnegative integer such that 2k−1 < x ≤ 2k , then ⌈log2 x⌉ = k.

b. Describe in words the statement proved in part (a).

15. If n is an odd integer and n > 1, is ⌈log2(n − 1)⌉ = ⌈log2(n)⌉? Justify your answer.

16.H If n is an odd integer and n > 1, is ⌈log2(n + 1)⌉ = ⌈log2(n)⌉? Justify your answer.

17. If n is an odd integer and n > 1, is ⌊log2(n + 1)⌋ = ⌊log2(n)⌋? Justify your answer.

In 18 and 19, indicate how many binary digits are needed to rep- resent the numbers in binary notation. Use the method shown in Example 11.4.3.

18. 148,206 19. 5,067,329

20. It was shown in the text that the number of binary digits needed to represent a positive integer n is ⌊log2 n⌋+ 1. Can this also be given as ⌈log2 n⌉? Why or why not?

In each of 21 and 22, a sequence is specified by a recurrence relation and initial conditions. In each case, (a) use iteration to guess an explicit formula for the sequence; (b) use strong math- ematical induction to confirm the correctness of the formula you obtained in part (a).

21. ak = a⌊k/2⌋ + 2, for all integers k ≥ 2 a1 = 1

22. bk = b⌈k/2⌉ + 1, for all integers k ≥ 2 b1 = 1.

23.H Define a sequence c1, c2, c3, . . . , recursively as follows:

c1 = 0, ck = 2c⌊k/2⌋ + k, for all integers k ≥ 2.

Use strong mathematical induction to show that cn ≤ n2 for all integers n ≥ 1.

24.H✶ Use strong mathematical induction to show that for the sequence of exercise 23, cn ≤ n log2 n, for all integers n ≥ 4.

Exercises 25–28 refer to properties 11.4.9 and 11.4.10. To solve them, think big!

25. Find a real number x > 3 such that log2 x < x 1/10.

26. Find a real number x > 1 such that x50 < 2x .

27. Find a real number x > 2 such that x < 1.0001x .

28. Use a graphing calculator or computer graphing program to find two distinct approximate values of x such that x = 1.0001x . On what approximate intervals is x > 1.0001x ? On what approximate intervals is x < 1.0001x ?

29. Use "-notation to express the following statement:

|x2| ≤ |7x2 + 3x log2 x | ≤ 10|x2|, for all real numbers x > 2.

Derive each statement in 30–33.

30. 2x + log2 x is "(x). 31. x2 + 5x log2 x is "(x2). 32. n2 + 2n is "(2n). 33.H 2n+1 is "(2n).

34.H Show that 4n is not O(2n).

Prove each of the statements in 35–40, assuming n is an integer variable that takes positive integer values. Use identities from Section 5.2 as needed.

35. 1 + 2 + 22 + 23 + · · · + 2n is "(2n). 36.H 4 + 42 + 43 + · · · + 4n is "(4n).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

764 Chapter 11 Analysis of Algorithm Efficiency

37. 2 + 2 ·32 + 2 ·34 + · · · + 2 ·32n is "(32n).

38. 1 5

+ 4 52

+ 4 2

53 + · · · + 4

n

5n+1 is "(1).

39. n + n 2

+ n 4

+ · · · + n 2n

is "(n).

40. 2n 3

+ 2n 32

+ 2n 33

+ · · · + 2n 3n

is "(n).

41. Quantities of the form

kn + kn log2 n for positive integers k1 ·k2, and n arise in the analysis of the merge sort algorithm in computer science. Show that for any positive integer k,

k1n + k2n log2 n is "(n log2 n). 42. Calculate the values of the harmonic sums

1 + 1 2

+ 1 3

+ · · · + 1 n

for n = 2, 3, 4, and 5.

43. Use part (d) of Example 11.4.7 to show that

n + n 2

+ n 3

+ · · · + n n

is "(n ln n).

44. Use the fact that log2 x = (

1 loge 2

) loge x and loge x =

ln x , for all positive numbers x , and part (c) of Example 11.4.7 to show that

1 + 1 2

+ 1 3

+ · · · + 1 n

is "(log2 n).

45. a. Show that ⌊log2 n⌋ is "(log2 n). b. Show that ⌊log2 n⌋+ 1 is "(log2 n).

46. Prove by mathematical induction that n ≤ 10n for all inte- gers n ≥ 1.

47.H Prove by mathematical induction that log2 n ≤ n for all inte- gers n ≥ 1.

48.H Show that if n is a variable that takes positive integer values, then 2n is O(n!).

49. Let n be a variable that takes positive integer values. a. Show that n! is O(nn).

b. Use part (a) to show that log2(n!) is O(n log2 n). c.H Show that nn ≤ (n!)2 for all integers n ≥ 2. d. Use part (c) to show that log2(n!) is !(n log2 n). e. Use parts (b) and (d) to find an order for log2(n!).

50.✶ a. For all positive real numbers u, log2 u < u. Use this fact to show that for any positive integer n, log2 x < nx

1/n

for all real numbers x > 0. b. Interpret the statement of part (a) using O-notation.

51. a. For all real numbers x, x < 2x . Use this fact to show that for any positive integer n, xn < nn2x for all real numbers x > 0.

b. Interpret the statement of part (a) using O-notation.

52.✶ For all positive real numbers u, log2 u < u. Use this fact and the result of exercise 21 in Section 11.1 to prove the following: For all integers n ≥ 1, log2 x < x1/n for all real numbers x > (2n)2n .

53. Use the result of exercise 52 above to prove the follow- ing: For all integers n ≥ 1, xn < 2x for all real numbers x > (2n)2n .

Exercises 54 and 55 use L’Hôpital’s rule from calculus.

54. a. Let b be any real number greater than 1. Use L’Hôpital’s rule and mathematical induction to prove that for all integers n ≥ 1,

lim x→∞

xn

bx = 0.

b. Use the result of part (a) and the definitions of limit and of O-notation to prove that xn is O(bx ) for any integer n ≥ 1.

55. a. Let b be any real number greater than 1. Use L’Hôpital’s rule to prove that for all integers n ≥ 1,

lim x→∞

logb x x1/n

= 0.

b. Use the result of part (a) and the definitions of limit and of O-notation to prove that logb x is O(x

1/n) for any integer n ≥ 1.

56. Complete the proof in Example 11.4.4.

Answers for Test Yourself 1. the set of all real numbers; the set of all positive real numbers 2. the set of all positive real numbers; the set of all real numbers 3. k 4. logb x < x < x logb x < x

2 5. ln x (or, equivalently, log2 x)

11.5 Application: Analysis of Algorithm Efficiency II Pick a Number, Any Number — Donal O’Shea, 2007

Have you ever played the “guess my number” game? A person thinks of a number between two other numbers, say 1 and 10 or 1 and 100 for example, and you try to figure out what it is, using the least possible number of guesses. Each time you guess a number, the person tells you whether you are correct, too low, or too high.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 765

If you have played this game, you have probably already hit upon the most efficient strategy: Begin by guessing a number as close to the middle of the two given numbers as possible. If your guess is too high, then the number is between the lower of the two given numbers and the one you first chose. If your guess is too low, then the number is between the number you first chose and the higher of the two given numbers. In either case, you take as your next guess a number as close as possible to the middle of the new range in which you now know the number lies. You repeat this process as many times as necessary until you have found the person’s number.

The technique described previously is an example of a general strategy called divide and conquer, which works as follows: To solve a problem, reduce it to a fixed number of smaller problems of the same kind, which can themselves be reduced to the same fixed number of smaller problems of the same kind, and so forth until easily resolved problems are obtained. In this case, the problem of finding a particular number in a given range of numbers is reduced at each stage to finding a particular number in a range of numbers approximately half as long.

It turns out that algorithms using a divide-and-conquer strategy are generally quite efficient and nearly always have orders involving logarithmic functions. In this section we define the binary search algorithm, which is the formalization of the “guess my num- ber” game described previously, and we compare the efficiency of binary search to the sequential search discussed in Section 11.3. Then we develop a divide-and-conquer algo- rithm for sorting, merge sort, and compare its efficiency with that of insertion sort and selection sort, which were also discussed in Section 11.3.

Binary Search Whereas a sequential search can be performed on an array whose elements are in any order, a binary search can be performed only on an array whose elements are arranged in ascending (or descending) order. Given an array a[1], a[2], . . . , a[n] of distinct elements arranged in ascending order, consider the problem of trying to find a particular element x in the array.

To use binary search, first compare x to the “middle element” of the array. If the two are equal, the search is successful. If the two are not equal, then because the array elements are in ascending order, comparing the values of x and the middle array element narrows the search either to the lower subarray (consisting of all the array elements below the middle element) or to the upper subarray (consisting of all array elements above the middle element).

The search continues by repeating this basic process over and over on successively smaller subarrays. It terminates either when a match occurs or when the subarray to which the search has been narrowed contains no elements. The efficiency of the algorithm is a result of the fact that at each step, the length of the subarray to be searched is roughly half the length of the array of the previous step. This process is illustrated in Figure 11.5.1.

left subarray middle element right subarray

a[r] a[s]a[mid – 1] a[mid + 1]a[mid ]

x > a[mid ]x < a[mid]

Compare x to a[mid ]. If the two are equal, the search ends.

Search the left subarray a[r], . . . , a[mid – 1] for x.

Search the right subarray a[mid + 1], . . . , a[s] for x.

Figure 11.5.1 One lteration of the Binary Search Process

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

766 Chapter 11 Analysis of Algorithm Efficiency

To write down a formal algorithm for binary search, we introduce a variable index whose final value will tell us whether or not x is in the array and, if so, will indicate the location of x . Since the array goes from a[1] to a[n], we intialize index to be 0. If and when x is found, the value of index is changed to the subscript of the array element equaling x . If index still has the value 0 when the algorithm is complete, then x is not one of the elements in the array. Figure 11.5.2 shows the action of a particular binary search.

a[5] = x ?

index = 5

a[6] = x ?

a[4] = x ? no: x > a[4]

no: x < a[6]

yes

a[1] a[2] a[3] a[4] a[5] a[6] a[7]

Figure 11.5.2 Binary Search of a[1], a[2], . . . , a[7] for x where x = a[5]

Formalizing a binary search algorithm also requires that we be more precise about the meaning of the “middle element” of an array. (This issue was side-stepped by careful choice of n in Figure 11.5.2.) If the array consists of an even number of elements, there are two elements in the middle. For instance, both a[6] and a[7] are equally in the middle of the following array.

a[3] a[4] a[5]︸ ︷︷ ︸ a[6] a[7]︸ ︷︷ ︸ a[8] a[9] a[10]︸ ︷︷ ︸ three elements two middle three elements

elements

In a case such as this, the algorithm must choose which of the two middle elements to take, the smaller or the larger. The choice is arbitrary—either would do. We will write the algorithm to choose the smaller. The index of the smaller of the two middle elements is the floor of the average of the top and bottom indices of the array. That is, if

bot = the bottom index of the array, top = the top index of the array, and mid = the lower of the two middle indices of the array,

then

mid = ⌊

bot + top 2

⌋ .

In this case, bot = 3 and top = 10, so the index of the “middle element” is

mid = ⌊

3 + 10 2

⌋ = ⌊

13 2

⌋ = ⌊6.5⌋ = 6.

The following is a formal algorithm for a binary search.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 767

Algorithm 11.5.1 Binary Search

[The aim of this algorithm is to search for an element x in an ascending array of elements a[1], a[2], . . . , a[n]. If x is found, the variable index is set equal to the index of the array element where x is located. If x is not found, index is not changed from its initial value, which is 0. The variables bot and top denote the bottom and top indices of the array currently being examined.]

Input: n [a positive integer], a[1], a[2], . . . , a[n] [an array of data items given in ascending order], x [a data item of the same data type as the elements of the array]

Algorithm Body: index := 0, bot := 1, top := n [Compute the middle index of the array, mid. Compare x to a[mid]. If the two are equal, the search is successful. If not, repeat the process either for the lower or for the upper subarray, either giving top the new value mid − 1 or giving bot the new value mid + 1. Each iteration of the loop either decreases the value of top or increases the value of bot. Thus, if the looping is not stopped by success in the search process, eventually the value of top will become less than the value of bot. This occurrence stops the looping process and indicates that x is not an element of the array.]

while (top ≥ bot and index = 0)

mid := ⌊

bot + top 2

if a[mid] = x then index := mid if a[mid] > x

then top := mid − 1 else bot := mid + 1

end while [If index has the value 0 at this point, then x is not in the array. Otherwise, index gives the index of the array where x is located.]

Output: index [a nonnegative integer]

Example 11.5.1 Tracing the Binary Search Algorithm

Trace the action of Algorithm 11.5.1 on the variables index, bot, top, mid, and the values of x given in (a) and (b) below for the input array

a[1] = Ann, a[2] = Dawn, a[3] = Erik, a[4] = Gail, a[5] = Juan, a[6] = Matt, a[7] = Max, a[8] = Rita, a[9] = Tsuji, a[10] = Yuen

where alphabetical ordering is used to compare elements of the array.

a. x = Max b. x = Sara Solution

a. index 0 7

bot 1 6 7

top 10 7

mid 5 8 6 7

b. index 0 bot 1 6 9

top 10 8

mid 5 8 9

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

768 Chapter 11 Analysis of Algorithm Efficiency

The Efficiency of the Binary Search Algorithm The idea of the derivation of the efficiency of the binary search algorithm is not dif- ficult. Here it is in brief. At each stage of the binary search process, the length of the new subarray to be searched is approximately half that of the previous one, and in the worst case, every subarray down to a subarray with a single element must be searched. Consequently, in the worst case, the maximum number of iterations of the while loop in the binary search algorithm is 1 more than the number of times the original input array can be cut approximately in half. If the length n of this array is a power of 2 (n = 2k for some integer k), then n can be halved exactly k = log2 n = ⌊log2 n⌋ times before an array of length 1 is reached. If n is not a power of 2, then n = 2k + m for some integer k (where m < 2k), and so n can be split approximately in half k times also. So in this case, k = ⌊log2 n⌋ also. Thus in the worst case, the number of iterations of the while loop in the binary search algorithm, which is proportional to the number of comparisons required to execute it, is ⌊log2 n⌋+ 1. The derivation is concluded by noting that ⌊log2 n⌋+ 1 is O(log2 n).

The details of the derivation are developed in Examples 11.5.2–11.5.6. Throughout the derivation, for each integer n ≥ 1, let

wn = the number of iterations of the while loop in a worst-case execution of the binary search algorithm for an input array of length n.

The first issue to consider is this. If the length of the input array for one iteration of the while loop is known, what is the greatest possible length of the array input to the next iteration?

Example 11.5.2 The Length of the Input Array to the Next Iteration of the Loop

Prove that if an array of length k is input to the while loop of the binary search algorithm, then after one unsuccessful iteration of the loop, the input to the next iteration is an array of length at most ⌊k/2⌋.

Solution Consider what occurs when an array of length k is input to the while loop in the case where x ̸= a[mid]:

a[bot], a[bot + 1], . . . , a[mid− 1]︸ ︷︷ ︸ , a[mid], a[mid + 1], . . . , a[top− 1], a[top].︸ ︷︷ ︸K⏐ new input to the while loop if x < a[mid] “middle

element”

new input to the while loop if x > a[mid]

Since the input array has length k, the value of mid depends on whether k is odd or even. In both cases we match up the array elements with the integers from 1 to k and analyze the lengths of the left and right subarrays. In case k is odd, both the left and the right subarrays have length ⌊k/2⌋. In case k is even, the left subarray has length ⌊k/2⌋ − 1 and the right subarray has length ⌊k/2⌋. The reasoning behind these results is shown in Figure 11.5.3.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 769

k odd: a[bot] a[top]a[mid – 1] a[mid + 1]a[mid ]

↕ ↕ ↕ ↕ ↕

↕ ↕ ↕ ↕

k even: a[bot] a[top]a[mid – 1] a[mid + 1]a[mid ]

1

1

k

k

k + 1 2

k + 1 2

– 1 k + 1 2

+ 1

k – 1 2

k + 1 2

– 1length = = = k 2

k 2

k 2

k 2

middle element

k + 1 2

+ 1length = k – + 1 = k – 1 2

= k 2( )

k 2

+ 1length = k – + 1 = = k 2

k 2( )

– 1 + 1

middle element

↑ length = k

2 – 1 – 1= k

2

Figure 11.5.3 Lengths of the Left and Right Subarrays

Because the maximum of the numbers ⌊k/2⌋ and ⌊k/2⌋ − 1 is ⌊k/2⌋, in the worst case this will be the length of the array input to the next iteration of the loop. ■

To find the order of the algorithm, a formula for w1, w2, w3, . . . is needed. The next example derives a recurrence relation for the sequence.

Example 11.5.3 A Recurrence Relation for w1, w2, w3, . . .

Prove that the sequence w1, w2, . . . , wn, . . . satisfies the recurrence relation and initial condition

w1 = 1, wk = 1 + w⌊k/2⌋ for all integers k > 1.

Solution Example 11.5.2 showed that given an input array of length k to the while loop, the worst that can happen is that the next iteration of the loop will have to search an array of length ⌊k/2⌋. Hence the maximum number of iterations of the loop is 1 more than the maximum number necessary to execute it for an input array of length ⌊k/2⌋. In symbols,

wk = 1 + w⌊k/2⌋.

Also w1 = 1

because for an input array of length 1 (bot = top), the while loop iterates only one time. ■

Now that a recurrence relation for w1, w2, w3, . . . has been found, iteration can be used to come up with a good guess for an explicit formula.

Example 11.5.4 An Explicit Formula for w1, w2, w3, . . .

Apply iteration to the recurrence relation found in Example 11.5.3 to conjecture an explicit formula for w1, w2, w3, . . . .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

770 Chapter 11 Analysis of Algorithm Efficiency

Solution Begin by iterating to find the values of the first few terms of the sequence.

→ w 1⃝ =

✞✝☎✆1 1 = 20; 1 = 0 + 1 → w 2⃝ = 1 + w⌊2/2⌋ = 1 + w1 = 1 + 1 =

✞✝☎✆2 w3 = 1 + w⌊3/2⌋ = 1 + w1 = 1 + 1 = 2

} 2 = 21; 2 = 1 + 1

→ w 4⃝ = 1 + w⌊4/2⌋ = 1 + w2 = 1 + 2 =

✞✝☎✆3 w5 = 1 + w⌊5/2⌋ = 1 + w2 = 1 + 2 = 3 w6 = 1 + w⌊6/2⌋ = 1 + w3 = 1 + 2 = 3 w7 = 1 + w⌊7/2⌋ = 1 + w3 = 1 + 2 = 3

⎫ ⎪⎪⎪⎬

⎪⎪⎪⎭

4 = 22; 3 = 2 + 1

→ w 8⃝ = 1 + w⌊8/2⌋ = 1 + w4 = 1 + 3 =

✞✝☎✆4 w9 = 1 + w⌊9/2⌋ = 1 + w4 = 1 + 3 = 4 ...

...

w15 = 1 + w⌊15/2⌋ = 1 + w7 = 1 + 3 = 4

⎫ ⎪⎪⎪⎬

⎪⎪⎪⎭

8 = 23; 4 = 3 + 1

w16⃝= 1 + w⌊16/2⌋ = 1 + w8 = 1 + 4 = ✞✝☎✆5

→... ...

⎫ ⎪⎪⎪⎪⎪⎬

⎪⎪⎪⎪⎪⎭

16 = 24; 5 = 4 + 1

Note that in each case when the subscript n is between two powers of 2, wn is 1 more than the exponent of the lower power of 2. In other words:

If 2i ≤ n < 2i+1, then wn = i + 1. 11.5.1 But if 2i ≤ n < 2i+1, then [by property (11.4.2) of Example 11.4.1]

i = ⌊log2 n⌋. Substitution into statement (11.5.1) gives the conjecture that

wn = ⌊log2 n⌋+ 1. ■

Now mathematical induction can be used to verify the correctness of the formula found in Example 11.5.4.

Example 11.5.5 Verifying the Correctness of the Formula

Use strong mathematical induction to show that if w1, w2, w3, . . . is a sequence of num- bers that satisfies the recurrence relation and initial condition

w1 = 1 and wk = 1 + w⌊k/2⌋ for all integers k > 1, then w1, w2, w3, . . . satisfies the formula

wn = ⌊log2 n⌋+ 1 for all integers n ≥ 1. Solution Let w1, w2, w3, . . . be the sequence defined by specifying that w1 = 1 and wk =

1 + w⌊k/2⌋ for all integers k ≥ 2, and let the property P(n) be the equation wn = ⌊log2 n⌋+ 1. ← P(n)

We will use mathematical induction to prove that for all integers n ≥ 1, P(n) is true. Show that P(1) is true: By definition of w1, w2, w3, . . . , we have that w1 = 1. But it is also the case that ⌊log2 1⌋+ 1 = 0 + 1 = 1. Thus w1 = ⌊log2 1⌋+ 1 and P(1) is true.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 771

Show that for all integers k ≥ 1, if P(i) is true for all integers i from 1 through k, then P(k + 1) is also true: Let k be any integer with k ≥ 1, and suppose that

wi = ⌊log2 i⌋+ 1 for all integers i with 1 ≤ i ≤ k. ← inductive hypothesis We must show that

wk+1 = ⌊log2(k + 1)⌋+ 1 ← P(k + 1) Consider the two cases: k is even and k is odd.

Case 1 (k is even): In this case, k + 1 is odd, and wk+1 = 1 + w⌊(k+1)/2⌋ by definition of w1 , w2 , w3 , . . .

= 1 + w⌊k/2⌋ because ⌊(k + 1)/2⌋ = k/2⌋ since k + 1 is odd

= 1 + (⌊

log2(k/2) ⌋

+ 1 ) by inductive hypothesis because, since k is even,

k ≥ 2, and so 1 ≤ ⌊k/2⌋ ≤ k/2 < k = ⌊log2(k)− log2 2⌋+ 2 by substituting into the identity

logb(x/y) = logb x − logb y from Theorem 7.2.1

= ⌊log2(k)− 1⌋+ 2 since log2 2 = 1 = (⌊log2(k)⌋ − 1) + 2 by substituting x = log2(k) into the identity

⌊x − 1⌋ = ⌊x⌋ − 1 derived in exercise 15 of Section 4.5 = ⌊log2(k + 1)⌋+ 1 by property (11.4.3) in Example 11.4.2

Case 2 (k is odd): In this case, it can also be shown that wk = ⌊log2 k⌋+ 1. The analysis is very similar to that of case 1 and is left as exercise 16 at the end of the section.

Hence regardless of whether k is even or k is odd,

wk+1 = ⌊log2(k + 1)⌋+ 1, as was to be shown. [Since both the basis and the inductive steps have been demonstrated, the proof by strong mathematical induction is complete.] ■

The final example shows how to use the formula for w1, w2, w3, . . . to find a worst- case order for the algorithm.

Example 11.5.6 The Binary Search Algorithm Is Logarithmic

Given that by Example 11.5.5, for all positive integers n,

wn = ⌊log2 n⌋+ 1, show that in the worst case, the binary search algorithm is "(log2 n).

Solution For any integer n > 2,

wn = ⌊log2 n⌋+ 1 by Example 11.5.5

⇒ log2 n ≤ wn ≤ log2 n + 1 because x < ⌊x⌋+ 1 and ⌊x⌋ ≤ x for all real numbers x

⇒ log2 n ≤ wn ≤ log2 n + log2 n since the logorithm with base 2 is increas-ing, if 2 < n, then 1 = log2 2 < log2 n ⇒ log2 n ≤ wn ≤ 2 log2 n.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

772 Chapter 11 Analysis of Algorithm Efficiency

Both wn and log2 n are positive for n > 2. Therefore,

| log2 n| ≤ |wn| ≤ 2| log2 n| for all integers n > 2.

Let A = 1, B = 2, and k = 2. Then A| log2 n| ≤ |wn| ≤ B| log2 n| for all integers n > k.

Hence by definition of "-notation,

wn is "(log2 n).

But wn , the number of iterations of the while loop, is proportional to the number of comparisons performed when the binary search algorithm is executed. Thus the binary search algorithm is "(log2 n). ■

Examples 11.5.2–11.5.6 show that in the worst case, the binary search algorithm has order log2 n. As noted in Section 11.3, in the worst case the sequential search algorithm has order n. This difference in efficiency becomes increasingly more important as n gets larger and larger. Assuming one loop iteration is performed each nanosecond, then per- forming n iterations for n = 100,000,000 requires 0.1 second, whereas performing log2 n iterations requires 0.000000027 second. For n = 100,000,000,000 the times are 1.67 minutes and 0.000000037 second, respectively. And for n = 100,000,000,000,000 the respective times are 27.78 hours and 0.000000047 second.

Merge Sort Note that it is much easier to write a detailed algorithm for sequential search than for binary search. Yet binary search is much more efficient than sequential search. Such trade-offs often occur in computer science. Frequently, the straightforward “obvious” solution to a problem is less efficient than a clever solution that is more complicated to describe.

In the text and exercises for Section 11.3, we gave two methods for sorting, insertion sort and selection sort, both of which are formalizations of methods human beings often use in ordinary situations. Can a divide-and-conquer approach be used to find a sorting method more efficient than these? It turns out that the answer is an emphatic “yes.” In fact, over the past few decades, computer scientists have developed several divide-and- conquer sorting methods all of which are somewhat more complex to describe but are significantly more efficient than either insertion sort or selection sort.

One of these methods, merge sort, is obtained by thinking recursively. Imagine that an efficient way for sorting arrays of length less than k is already known. How can such knowledge be used to sort an array of length k? One way is to suppose the array of length k is split into two roughly equal parts and each part is sorted using the known method. Is there an efficient way to combine the parts into a sorted array? Sure. Just “merge” them.

Figure 11.5.4 illustrates how a merge works. Imagine that the elements of two ordered subarrays, 2, 5, 6, 8 and 3, 6, 7, 9, are written on slips of paper (to make them easy to move around). Place the slips for each subarray in two columns on a tabletop, one at the left and one at the right. Along the bottom of the tabletop, set up eight positions into which the slips will be moved. Then, one-by-one, bring down the slips from the bottoms of the columns. At each stage compare the numbers on the slips currently at the column bottoms, and move the slip containing the smaller number down into the next position in the array as a whole. If at any stage the two numbers are equal, take, say, the slip on the left to move into the next position. And if one of the columns is empty at any stage, just move the slips from the other column into position one-by-one in order.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 773

1 2 3 4 5 6 7 8

2 3 5 6 6 7 8 9

2

5

6

8

3

6

7

9 Tabletop

Figure 11.5.4 Merging Two Sorted Subarrays to Obtain a Sorted Array

One important observation about the merging algorithm described previously: It requires memory space to move the array elements around. A second set of array posi- tions as long as the original one is needed into which to place the elements of the two subarrays in order. In Figure 11.5.4 this second set of array positions is represented by the positions set up at the bottom of the tabletop. Of course, once the elements of the original array have been placed into this new array, they can be moved back in order into the original array positions.

In terms of time, however, merging is efficient because the total number of compar- isons needed to merge two subarrays into an array of length k is just k − 1. You can see why by analyzing Figure 11.5.4. Observe that at each stage, the decision about which slip to move is made by comparing the numbers on the slips currently at the bottoms of the two columns—execpt when one of the columns is empty, in which case no comparisons are made at all. Thus in the worst case there will be one comparison for each of the k positions in the final array except the very last one (because when the last slip is placed into position, the other column is sure to be empty), or a total of k − 1 comparisons in all.

The merge sort algorithm is recursive: Its defining statements include references to itself. The algorithm is well defined, however, because at each stage the length of the array that is input to the algorithm is shorter than at the previous stage, so that, ultimately, the algorithm has to deal only with arrays of length 1, which are already sorted. Specifically, merge sort works as follows.

Given an array of elements that can be put into order, if the array consists of a single element, leave it as it is. It is already sorted. Otherwise:

1. Divide the array into two subarrays of as nearly equal length as possible.

2. Use merge sort to sort each subarray.

3. Merge the two subarrays together.

Figure 11.5.5 illustrates a merge sort in a particular case.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

774 Chapter 11 Analysis of Algorithm Efficiency

5 2

5

5

5

5

2

2

2

2

4 6

4

4

4

4

6

6

6

6

5 2 4 6

1 3 2 6

1 2 2 3 4 5 6 6

1

1

3

3

3

3

1

1

2

2

2

2

6

6

6

6

1 3 2 6

Initial array:

Sorted array:

split

split split

split

merge

merge merge

merge

split split

split

merge merge

merge

Figure 11.5.5 Applying Merge Sort to the Array 5, 2, 4, 6, 1, 3, 2, 6

As in the case of the binary search algorithm, in order to formalize merge sort we must decide at exactly what point to split each array. Given an array denoted by a[bot], a[bot + 1], . . . , a[top], let mid = ⌊(bot + top)/2⌋. Take the left subarray to be a[bot], a[bot + 1], . . . , a[mid] and the right subarray to be a[mid + 1], a[mid + 2], . . . , a[top]. The following is a formal version of merge sort.

Algorithm 11.5.2 Merge Sort

[The aim of this algorithm is to take an array of elements a[r ], a[r + 1], . . . , a[s] (where r ≤ s) and to order it. The output array is denoted a[r ], a[r + 1], . . . , a[s] also. It has the same values as the input array, but they are in ascending order. The input array is split into two nearly equal-length subarrays, each of which is ordered using merge sort. Then the two subarrays are merged together.]

Input: r and s, [positive integers with r < s] a[r ], a[r + 1], . . . , a[s] [an array of data items that can be ordered]

Algorithm Body: bot := r, top := s while (bot < top)

mid := ⌊

bot + top 2

call merge sort with input bot, mid, and a[bot], a[bot + 1], . . . , a[mid]

call merge sort with input mid + 1, top and a[mid + 1], a[mid + 2], . . . , a[top]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 775

[After these steps are completed, the arrays a[bot], a[bot + 1], . . . , a[mid] and a[mid + 1], a[mid + 2], . . . , a[top] are both in order.] merge a[bot], a[bot + 1], . . . , a[mid] and

a[mid + 1], a[mid + 2], . . . , a[top] [This step can be done with a call to a merge algorithm. To put the final array in ascending order, the merge algorithm must be written so as to take two arrays in ascending order and merge them into an array in ascending order.]

end while Output: a[r ], a[r + 1], . . . , a[s] [an array with the same elements as the input array but in ascending order]

To derive the efficiency of merge sort, let

mn = the maximum number of comparisons used when merge sort is applied to an array of length n.

Then m1 = 0 because no comparisons are used when merge sort is applied to an array of length 1. Also for any integer k > 1, consider an array a[bot], a[bot + 1], . . . , a[top] of length k that is split into two subarrays, a[bot], a[bot + 1], . . . , a[mid] and a[mid + 1], a[mid + 2], . . . , a[top], where mid = ⌊(bot + top)/2⌋. In exercise 24 you are asked to show that the right subarray has length ⌊k/2⌋ and the left subarray has length ⌈k/2⌉. From the previous discussion of the merge process, it is known that to merge two subarrays into an array of length k, at most k − 1 comparisons are needed.

Consequently, ⎡

⎣ the number of comparisons when merge sort is applied to an array of length k

⎦ =

⎣ the number of comparisons when merge sort is applied to an array of length ⌊k/2⌋

+

⎣ the number of comparisons when merge sort is applied to an array of length ⌈k/2⌉

⎦+

⎣ the number of comparisons used to merge two subarrays into an array of length k

⎦ .

Or, in other words,

mk = m⌊k/2⌋ + m⌈k/2⌉ + (k − 1) for all integers k > 1. In exercise 25 you are asked to use this recurrence relation to show that

1 2

n log2 n ≤ mn ≤ 2n log2 n for all integers n ≥ 1.

It follows that merge sort is "(n log2 n). In the text and exercises for Section 11.3, we showed that insertion sort and selection

sort are both "(n2). How much difference can it make that merge sort is "(n log2 n)? If n = 100,000,000 and a computer is used that performs one operation each nanosecond, the time needed to perform n log2 n operations is about 2.7 seconds, whereas the time needed to perform n2 operations is over 115 days.

Tractable and Intractable Problems At an opposite extreme from an algorithm such as binary search, which has logarithmic order, is an algorithm with exponential order. For example, consider an algorithm to direct

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

776 Chapter 11 Analysis of Algorithm Efficiency

the movement of each of the 64 disks in the Tower of Hanoi puzzle as they are transferred one by one from one pole to another. In Section 5.7 we showed that such a transfer requires 264 − 1 steps. If a computer took a nanosecond to calculate each transfer step, the total time to calculate all the steps would be

(264 − 1) · (

1 109

) · (

1 60

) · (

1 60

) · (

1 24

) · (

1 365.25

) ∼= 584 years.

↑ number of moves

moves per second

seconds per minute

minutes per hour

hours per day

days per year

Problems whose solutions can be found with algorithms whose worst-case order with respect to time is a polynomial are said to belong to class P. They are called polynomial- time algorithms and are said to be tractable. Problems that cannot be solved in poly- nomial time are called intractable. For certain problems, it is possible to check the correctness of a proposed solution with a polynomial-time algorithm, but it may not be possible to find a solution in polynomial time. Such problems are said to belong to class NP.∗ The biggest open question in theoretical computer science is whether every problem in class NP belongs to class P. This is known as the P vs. NP problem. The Clay Institute, in Cambridge, Massachusetts, has offered a prize of $1,000,000 to anyone who can either prove or disprove that P = NP.

In recent years, computer scientists have identified a fairly large set of problems, called NP-complete, that all belong to class NP but are widely believed not to belong to class P. What is known for sure is that if any one of these problems is solvable in polynomial time, then so are all the others. One of the NP-complete problems, commonly known as the traveling salesman problem, was discussed in Section 10.2.

A Final Remark on Algorithm Efficiency This section and the previous one on algorithm efficiency have offered only a partial view of what is involved in analyzing a computer algorithm. For one thing, it is assumed that searches and sorts take place in the memory of the computer. Searches and sorts on disk- based files require different algorithms, though the methods for their analysis are similar. For another thing, as mentioned at the beginning of Section 11.3, time efficiency is not the only factor that matters in the decision about which algorithm to choose. The amount of memory space required is also important, and there are mathematical techniques to estimate space efficiency very similar to those used to estimate time efficiency. Further- more, as parallel processing of data becomes increasingly prevalent, current methods of algorithm analysis are being modified and extended to apply to algorithms designed for this new technology.

Test Yourself 1. To solve a problem using a divide-and-conquer algorithm,

you reduce it to a fixed number of smaller problems of the same kind, which can themselves be _____, and so forth until _____.

2. To search an array using the binary search algorithm in each step, you compare a middle element of the array to _____. If the middle element is less than _____, you _____, and if the middle element is greater than _____, you _____.

3. The worst case order of the binary search algorithm is _____.

4. To sort an array using the merge sort algorithm, in each step until the last one you split the array into approximately two equal sections and sort each section using ____. Then you _____ the two sorted sections.

5. The worst case order of the merge sort algorithm is _____.

∗Technically speaking, a problem whose solution can be verified on an ordinary computer (or deterministic sequential machine) with a polynomial-time algorithm can be solved on a nondeterministic sequential machine with a polynomial-time algorithm. Such problems are called NP, which stands for nondeterministic polynomial-time algorithm.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

11.5 Application: Analysis of Algorithm Efficiency II 777

Exercise Set 11.5 1. Use the facts that log2 10 ∼= 3.32 and that for all real

numbers a, log2(10 a) = a log2 10 to find log2(1,000),

log2(1,000,000), and log2(1,000,000,000,000).

2. Suppose an algorithm requires c⌊log2 n⌋ operations when performed with an input of size n (where c is a constant). a. By what factor will the number of operations increase

when the input size is increased from m to m2 (where m is a positive integer power of 2)?

b. By what factor will the number of operations increase when the input size is increased from m to m10 (where m is a positive integer power of 2)?

c. When n increases from 128 (= 27) to 268,435,456 (= 228), by what factor is c⌊log2 n⌋ increased?

Exercises 3 and 4 illustrate that for relatively small values of n, algorithms with larger orders can be more efficient than algo- rithms with smaller orders. Use a graphing calculator or com- puter to answer these questions.

3. For what values of n is an algorithm that requires n operations more efficient than an algorithm that requires ⌊50 log2 n⌋ operations?

4. For what values of n is an algorithm that requires ⌊n2/10⌋ operations more efficient than an algorithm that requires ⌊n log2 n⌋ operations?

In 5 and 6, trace the action of the binary search algorithm (Algo- rithm 11.5.1) on the variables index, bot, top, mid, and the given values of x for the input array a[1] = Chia, a[2] = Doug, a[3] = Jan, a[4] = Jim, a[5] = José, a[6] = Mary, a[7] = Rob, a[8] = Roy, a[9] = Sue, a[10] = Usha, where alphabetical ordering is used to compare elements of the array.

5. a. x = Chia b. x = Max

6. a. x = Amanda b. x = Roy

7. Suppose bot and top are positive integers with bot ≤ top. Consider the array

a[bot], a[bot + 1], . . . , a[top].

a. How many elements are in this array? b. Show that if the number of elements in the array is odd,

then the quantity bot + top is even. c. Show that if the number of elements in the array is even,

then the quantity bot + top is odd.

Exercises 8–11 refer to the following algorithm segment. For each positive integer n, let an be the number of iterations of the while loop. while (n > 0)

n := n div 2 end while

8. Trace the action of this algorithm segment on n when the initial value of n is 27.

9. Find a recurrence relation for an .

10. Find an explicit formula for an .

11. Find an order for this algorithm segment.

Exercises 12–15 refer to the following algorithm segment. For each positive integer n, let bn be the number of iterations of the while loop.

while (n > 0) n := n div 3

end while

12. Trace the action of this algorithm segment on n when the initial value of n is 424.

13. Find a recurrence relation for bn .

14.H a. Use iteration to guess an explicit formula for bn . b. Prove that if k is an integer and x is a real number with

3k ≤ x < 3k , then ⌊log3 x⌋ = k. c. Prove that for all integers m ≥ 1,

⌊log3(3m)⌋ = ⌊log3(3m + 1)⌋ = ⌊log3(3m + 2)⌋. d. Prove the correctness of the formula you found in

part (a).

15. Find an order for the algorithm segment.

16. Complete the proof of case 2 of the strong induction argu- ment in Example 11.5.5. In other words, show that if k is an odd integer and wi = ⌊log2 i⌋+ 1 for all integers i with 1 ≤ i ≤ k, then wk+1 = ⌊log2 k + 1⌋+ 1.

For 17–19, modify the binary search algorithm (Algorithm 11.5.1) to take the upper of the two middle array elements in case the input array has even length. In other words, in Algo- rithm 11.5.1 replace

mid := ⌊

bot + top 2

⌋ with mid :=

⌈ bot + top

2

⌉ .

17. Trace the modified binary search algorithm for the same input as was used in Example 11.5.1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

778 Chapter 11 Analysis of Algorithm Efficiency

18. Suppose an array of length k is input to the while loop of the modified binary search algorithm. Show that after one iteration of the loop, if a[mid] ̸= x , the input to the next iteration is an array of length at most ⌊k/2⌋.

19. Let wn be the number of iterations of the while loop in a worst-case execution of the modified binary search algo- rithm for an input array of length n. Show that wk = 1 + w⌊k/2⌋ for k ≥ 2.

In 20 and 21, draw a diagram like Figure 11.5.4 to show how to merge the given subarrays into a single array in ascending order.

20. 3, 5, 6, 9, 12 and 2, 4, 7, 9, 11

21. F, K, L, R, U and C, E, L, P, W (alphabetical order)

In 22 and 23, draw a diagram like Figure 11.5.5 to show how merge sort works for the given input arrays.

22. R, G, B, U, C, F, H, G (alphabetical order)

23. 5, 2, 3, 9, 7, 4, 3, 2

24. Show that given an array a[bot], a[bot + 1], . . . , a[top] of length k, if mid = ⌊(bot + top)/2⌋ then a. the subarray a[mid + 1], a[mid + 2], . . . , a[top] has

length ⌊k/2⌋. b. the subarray a[bot], a[bot + 1], . . . , a[mid] has length ⌈k/2⌉.

25.H The recurrence relation for m1, m2, m3, . . . , which arises in the calculation of the efficiency of merge sort, is

m1 = 0 mk = m⌊k/2⌋ + m⌈k/2⌉ + k − 1.

Show that for all integers n ≥ 1, a. 12 n log2 n ≤ mn b. mn ≤ 2n log2 n

26. You might think that n − 1 multiplications are needed to compute xn , since

xn = x · x · · · x .︸ ︷︷ ︸ n−1 multiplications

But observe that, for instance, since 6 = 4 + 2, x6 = x4x2 = (x2)2x2.

Thus x6 can be computed using three multiplications: one to compute x2, one to compute (x2)2, and one to multiply (x2)2 times x2. Similarly, since 11 = 8 + 2 + 1,

x11 = x8x2x1 = ((x2)2)2x2x and so x11 can be computed using five multiplications: one to compute x2, one to compute (x2)2, one to compute ((x2)2)2, one to multiply ((x2)2)2 times x2, and one to mul- tiply that product by x . a. Write an algorithm to take a real number x and a positive

integer n and compute xn by (i) calling Algorithm 5.1.1 to find the binary represen-

tation of n:

(r [k] r [k − 1] · · · r [0])2, where each r [i] is 0 or 1;

(ii) computing x2, x2 2 , x2

3 , . . . , x2

k by squaring, then

squaring again, and so forth, (iii) computing xn using the fact that

xn = xr [k]2k+···+r [2]22+r [1]21+r [0]20

= xr [k]2k · · · xr [2]22 · xr [1]21 · xr [0]20

b. Show that the number of multiplications performed by the algorithm of part (a) is less than or equal to 2⌊log2 n⌋.

Answers for Test Yourself 1. reduced to the same finite number of smaller problems of the same kind; easily resolved problems are obtained 2. the element you are looking for; the element you are looking for; apply the binary search algorithm to the lower half of the array; the element you are looking for; apply the binary search algorithm to the upper half of the array 3. log2 n, where n is the length of the array 4. merge sort; merge 5. n log2 n

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

779

CHAPTER 12

REGULAR EXPRESSIONS AND FINITE-STATE AUTOMATA

The theoretical foundations of computer science were derived from several disciplines: logic (the foundations of mathematics), electrical engineering (the design of switching circuits), brain research (models of neurons), and linguistics (the formal specification of languages).

As discussed briefly in Sections 6.4 and 7.4, the 1930s saw the development of mathe- matical treatments of basic questions concerning what can be proved in mathematics and what can be computed by means of a finite sequence of mechanized operations. Although the first digital computers were not built until the early 1940s, ten years earlier Alan Tur- ing developed a simple abstract model of a machine, now called a Turing machine, by means of which he defined what it would mean for a function to be computable.

Around the same time, somewhat similar models of computation were developed by the American logicians Alonzo Church, Stephen C. Kleene, and Emil Post (who was born in Poland but came to the United States as a child), but Church and others showed these all to be equivalent. As a result, Church formulated a conjecture, now known as the Church-Turing thesis, asserting that the Turing machine is universal in the sense that anything that can ever be computed on a machine can be computed with a Turing machine. If this thesis is correct—which is widely believed—then all computers that have been or will ever be constructed are theoretically equivalent in what they can do, although they may differ widely in speed and storage capacity. For instance, quantum computers may have the capability to compute certain quantities enormously faster than classical computers. But Church’s thesis implies that the theory of computation is likely to remain fundamentally the same, even though the enabling technology is subject to constant change.

In the early 1940s, Warren S. McCulloch and Walter Pitts, working at the Massachusetts Institute of Technology (M.I.T.), developed a model of how the neurons in the brain might work and how models of neurons could be combined to make “cir- cuits” or “automata” capable of more complicated computations. To a certain extent, they were influenced by the results of Claude Shannon, who also worked at M.I.T. and had in the 1930s developed the foundations of a theory that implemented Boolean functions as switching circuits. In the 1950s, Kleene analyzed the work of McCulloch and Pitts and connected it with versions of the machine models introduced by Turing and others.

Another development of the 1950s was the introduction of high-level computer lan- guages. During the same years, linguist Noam Chomsky’s attempts to understand the underlying principles by means of which human beings generate speech led him to develop a theory of formal languages, which he defined using sets of abstract rules, called

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

780 Chapter 12 Regular Expressions and Finite-State Automata

grammars, of varying levels of complexity. It soon became apparent that Chomsky’s theory was of great utility in the analysis and construction of computer languages. For computer science, the most useful of Chomsky’s language classifications are also the two simplest: the regular languages and the context-free languages.

Regular languages, which are defined by regular expressions, are used extensively for matching patterns within text (as in word processing or Internet searches) and for lexical analysis in computer language compilers. They are part of sophisticated text editors and a number of UNIX∗ utilities, and they are also used in transforming XML†documents.

Through use of the Backus-Naur notation (introduced in Section 10.5), context-free languages are able to describe many of the more complex aspects of modern high-level computer languages, and they form the basis for the main part of compilers, which trans- late programs written in a high-level language into machine code suitable for execution.

A remarkable fact is that all of the subjects referred to previously are related. Each context-free grammar turns out to be equivalent to a type of automaton called a push- down automaton, and each regular expression turns out to be equivalent to a type of automaton called a finite-state automaton. In this chapter, we focus on the study of regular languages and finite-state automata, leaving the subject of context-free grammars and their equivalent automata to a later course in compiler construction or automata theory.

Note Automata is the plural of automaton.

12.1 Formal Languages and Regular Expressions The mind has finite means but it makes unbounded use of them and in very specific and organized ways. That’s the core problem of language that it became possible to face [by the mid-twentieth century]. — Noam Chomsky, circa 1998

An English sentence can be regarded as a string of words, and an English word can be regarded as a string of letters. Not every string of letters is a legitimate word, and not every string of words is a grammatical sentence. We could say that a word is legitimate if it can be found in an unabridged English dictionary and that a sentence is grammatical if it satisfies the rules in a standard English grammar book.

Ph ot

o by

N or

m an

Le nb

ur g,

19 79

.C ou

rt es

y U

ni ve

rs ity

of W

is co

ns in

-M ad

is on

Ar ch

iv es

.

Noam Chomsky (born 1928)

Computer languages are similar to English in that certain strings of characters are legitimate words of the language and certain strings of words can be put together accord- ing to certain rules to form syntactically correct programs. A compiler for a computer language analyzes the stream of characters in a program—first to recognize individual word and sentence units (this part of the compiler is called a lexical scanner), then to ana- lyze the syntax, or grammar, of the sentences (this part is called a syntactic analyzer), and finally to translate the sentences into machine code (this part is called a code generator).

In computer science it has proved useful to look at languages from a very abstract point of view as strings of certain fundamental units and allow any finite set of symbols to be used as an alphabet. It is common to denote an alphabet by a capital Greek sigma: %. (This just happens to be the same symbol as the one used for summation, but the two concepts have no other connection.)

The definition of a string of characters of an alphabet % (or a string over %) is a generalization of the definition of string introduced earlier. A formal language over an alphabet is any set of strings of characters of the alphabet. These definitions are given formally on the next page.

∗UNIX is an operating system that was developed in 1969 by Kenneth Thompson at Bell Labo- ratories. It was later rewritten in Dennis Ritchie’s C language, which was also developed at Bell Laboratories. †XML is a standard for defining markup languages used for Internet applications.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.1 Formal Languages and Regular Expressions 781

Alphabet $: a finite set of characters

String over $: (1) a finite sequence of elements (called characters) of % or (2) the null string ϵ

Length of a string over $: The number of characters that made up the string, with the null string having length 0.

Formal language over $: a set of strings over the alphabet

Note that the empty set satisfies the criteria for being a formal language. Allowing the empty set to be a formal language turns out to be convenient in certain technical situations.

Example 12.1.1 Examples of Formal Languages

Let the alphabet % = {a, b}. a. Define a language L1 over % to be the set of all strings that begin with the character a

and have length at most three characters. Find L1.

b. A palindrome is a string that looks the same if the order of its characters is reversed. For instance, aba and baab are palindromes. Define a language L2 over % to be the set of all palindromes obtained using the characters of %. Write ten elements of L2.

Solution

a. L1 = {a, aa, ab, aaa, aab, aba, abb} b. L2 contains the following ten strings (among infinitely many others):

ϵ, a, b, aa, bb, aaa, bab, abba, babaabab, abaabbbbbaaba ■

• Notation Let % be an alphabet. For each nonnegative integer n, let

%n = the set of all strings over % that have length n, %+ = the set of all strings over % that have length at least 1, and %∗ = the set of all strings over %.

Note that %n is essentially the Cartesian product of n copies of %. The language %∗ is called the Kleene closure of $, in honor of Stephen C. Kleene (pronounced CLAY-knee). %+ is the set of all strings over % except for ϵ and is called the positive closure of $.

U ni

ve rs

ity of

W is

co ns

in

Stephen C. Kleene (1909–1994)

Example 12.1.2 The Languages $n, $+, and $∗

Let % = {a, b}.

a. Find %0,%1,%2, and %3.

b. Let A = %0 ∪%1 and B = %2 ∪%3. Use words to describe A, B, and A ∪ B. c. Describe a systematic way of writing the elements of %+. What change needs to be

made to obtain the elements of %∗?

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

782 Chapter 12 Regular Expressions and Finite-State Automata

Solution

a. %0 = {ϵ},%1 = {a, b},%2 = {aa, ab, ba, bb}, and %3 = {aaa, aab, aba, abb, baa, bab, bba, bbb}

b. A is the set of all strings over % of length at most 1. B is the set of all strings over % of length 2 or 3. A ∪ B is the set of all strings over % of length at most 3.

c. Elements of %+ can be written systematically by writing all the strings of length 1, then all the strings of length 2, and so forth.

%+: a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb, aaaa, . . . Of course the process of writing the strings in %+ would continue forever, because %+ is an infinite set. The only change that needs to be made to obtain %∗ is to place the null string at the beginning of the list. ■

Example 12.1.3 Polish Notation: A Language Consisting of Postfix Expressions

An expression such as a + b, in which a binary operator such as + sits between the two quantities on which it acts, is said to be written in infix notation. Alternative nota- tions are called prefix notation (in which the binary operator precedes the quantities on which it acts) and postfix notation (in which the binary operator follows the quantities on which it acts). In prefix notation, a + b is written + ab. In postfix notation, a + b is written ab +.

Prefix and postfix notations were introduced in 1920 by the Polish mathematician Jan Łukasiewicz (pronounced Wu-cash-AY-vich). In his honor—and because some peo- ple have difficulty pronouncing his name—they are often referred to as Polish notation and reverse Polish notation, respectively. A great advantage of these notations is that they eliminate the need for parentheses in writing arithmetic expressions. For instance, in postfix (or reverse Polish) notation, the expression 8 4 + 6 / is evaluated from left to right as follows: Add 8 and 4 to obtain 12, and then divide 12 by 6 to obtain 2. As another example, if the expression (a + b) ·c in infix notation is converted to postfix notation, the result is ab + c · . a. If the expression ab ·cd ·+ in postfix notation is converted to infix notation, what is

the result?

b. Let % = {4, 1,+,−}, and let L = the set of all strings over % obtained by writing either a 4 or a 1 first, then either a 4 or a 1, and finally either a + or a −. List all elements of L between braces, and evaluate the resulting expressions.

Solution

a. a ·b + c ·d

b. L = {4 1 +, 4 1 −, 1 4 +, 1 4 −, 4 4 +, 4 4 −, 1 1 +, 1 1 −}

4 1 + = 4 + 1 = 5, 4 1 − = 4 − 1 = 3, 1 4 + = 1 + 4 = 5,

1 4 − = 1 − 4 = −3, 4 4 + = 4 + 4 = 8, 4 4 − = 4 − 4 = 0,

1 1 + = 1 + 1 = 2, 1 1 − = 1 − 1 = 0 ■ The following definition describes ways in which languages can be combined to form

new languages.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.1 Formal Languages and Regular Expressions 783

• Definition Let % be an alphabet. Given any strings x and y over %, the concatenation of x and y is the string obtained by writing all the characters of x followed by all the charac- ter of y. For any languages L and L ′ over %, three new languages can be defined as follows:

The concatenation of L and L′, denoted LL′, is

L L ′ = {xy | x ∈ L and y ∈ L ′}. The union of L and L′, denoted L ∪ L′, is

L ∪ L ′ = {x | x ∈ L or x ∈ L ′}. The Kleene closure of L, denoted L∗, is

L∗ = {x | x is a concatenation of any finite number of strings in L}. Note that ϵ is in L∗ because it is regarded as a concatenation of zero strings in L .

Example 12.1.4 New Languages from Old

Let L1 be the set of all strings consisting of an even number of a’s (namely, ε, aa, aaaa, aaaaaa, . . .), and let L2 = {b, bb, bbb}. Find L1L2, L1 ∪ L2, and (L1 ∪ L2)∗. Note that the null string ϵ is in L1 because 0 is an even number.

Solution L1L2 = the set of all strings that consist of an even number of a’s followed by b or by bb or by bbb.

L1 ∪ L2 = the set that includes the strings b, bb, bbb and any strings consisting of an even number of a’s.

(L1 ∪ L2)∗ = the set of all strings of a’s and b’s in which every occurrence of a is in a block consisting of an even number of a’s. ■

The Language Defined by a Regular Expression One of the most useful ways to define a language is by means of a regular expression, a concept first introduced by Kleene. We give a recursive definition for generating the set of all regular expressions over an alphabet.

• Definition Given an alphabet %, the following are regular expressions over $:

I. BASE: ∅, ϵ, and each individual symbol in % are regular expressions over %. II. RECURSION: If r and s are regular expressions over %, then the following are

also regular expressions over %:

(i) (rs) (ii) (r | s) (iii) (r∗) where rs denotes the concatenation of r and s, r∗ denotes the concatenation of r with itself any finite number (including zero) of times, and r | s denotes either one of the strings r or s. The regular expression r∗ is called the Kleene closure of r .

III. RESTRICTION: Nothing is a regular expression over % except for objects defined in (I) and (II) above.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

784 Chapter 12 Regular Expressions and Finite-State Automata

As an example, one regular expression over % = {a, b, c} is a | (b | c)∗ | (ab)∗.

If the alphabet % happens to include symbols—such as ( | ) ∗—special provisions have to be made to avoid ambiguity. An escape character, usually a backslash, is added before the potentially ambiguous symbol. For instance, a left parenthesis would be written as \( and the backslash itself would be written as \\.

To eliminate parentheses, an order of precedence for the operations used to define regular expressions has been introduced. The highest is ∗, concatenation is next, and | is the lowest. It is also customary to eliminate the outer set of parentheses in a regular expression, because doing so does not produce ambiguity. Thus

(a((bc)∗)) = a(bc)∗ and (a | (bc)) = a | bc.

Example 12.1.5 Order of Precedence for the Operations in a Regular Expression

a. Add parentheses to make the order of precedence clear in the following expression: ab∗ | b∗a.

b. Use the convention about order of precedence to eliminate the parentheses in the following expression: ((a | ((b∗)c))(a∗)).

Solution

a. ((a(b∗)) | ((b∗)a)) b. (a | b∗c)a∗ ■

Given a finite alphabet, every regular expression r over the alphabet defines a formal language L(r). The function L is defined recursively.

• Definition For any finite alphabet %, the function L that associates a language to each regular expression over % is defined by (I) and (II) below. For each such regular expression r, L(r) is called the language defined by r.

I. BASE: L(∅) = ∅, L(ϵ) = {ϵ}, L(a) = {a} for every a in %. II. RECURSION: If L(r) and L(r ′) are the languages defined by the regular expres-

sions r and r ′ over %, then

(i) L(rr ′) = L(r)L(r ′) (ii) L(r | r ′) = L(r) ∪ L(r ′) (iii) L(r∗) = (L(r))∗

Note that any finite language can be defined by a regular expression. For instance, the language {cat, dog, bird} is defined by the regular expression (cat | dog | bird). An important example is the following.

Example 12.1.6 Using Set Notation to Describe the Language Defined by a Regular Expression

Let % = {a, b}, and consider the language defined by the regular expression (a | b)∗. Use set notation to find this language, and describe it in words.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.1 Formal Languages and Regular Expressions 785

Solution The language defined by (a | b)∗ is L((a | b)∗) = (L(a | b))∗

= (L(a) ∪ L(b))∗ = ({a} ∪ {b})∗ = {a, b}∗ by definition of operations on languages = the set of all strings of a’s and b’s = %∗. ■

Note that concatenating strings and taking unions of sets are both associative opera- tions. Thus for any regular expressions r, s and t ,

L((rs)t) = L(r(st)). Moreover,

L ((r | s) | t) = (L(r | s)) ∪ L(t) by definition of | = (L(r) ∪ L(s)) ∪ L(t) by definition of | = L(r) ∪ (L(s) ∪ L(t)) by the associativity of union for sets = L(r) ∪ (L(s | t)) by definition of | = L(r | (s | t)) by definition of |.

Because of these relationships, it is customary to drop the parentheses in “associative” situations and write

rst = (rs)t = r(st) and r | s | t = (r | s) | t = r | (s | t).

As you become accustomed to working with regular expressions, you will find that you do not need to go through a formal derivation in order to determine the language defined by an expression.

Example 12.1.7 The Language Defined by a Regular Expression

Let % = {0, 1}. Use words to describe the languages defined by the following regular expressions over %.

a. 0∗1∗ | 1∗0∗ b. 0(0 | 1)∗

Solution

a. The strings in this language consist either of a string of 0’s followed by a string of 1’s or of a string of 1’s followed by a string of 0’s. However, in either case the strings could be empty, which means that ε is also in the language.

b. The strings in this language have to start with a 0. The 0 may be followed by any finite number (including zero) of 0’s and 1’s in any order. Thus the language is the set of all strings of 0’s and 1’s that start with a 0. ■

Example 12.1.8 Individual Strings in the Language Defined by a Regular Expression

In each of (a) and (b), let % = {a, b} and consider the language L over % defined by the given regular expression.

a. The regular expression is a∗b(a | b)∗. Write five strings that belong to L .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

786 Chapter 12 Regular Expressions and Finite-State Automata

b. The regular expression is a∗ | (ab)∗. Indicate which of the following strings belong to L:

a b aaaa abba ababab

Solution

a. The strings b, ab, abbb, abaaa, and ababba are five strings from the infinitely many in L .

b. The following strings are the only ones listed that belong to L: a, aaaa, and ababab. The string b does not belong to L because it is neither a string of a’s nor a string of possibly repeated ab’s. The string abba does not belong to L because any two b’s that might occur in a string of L are separated by an a. ■

Example 12.1.9 A Regular Expression That Defines a Language

Let % = {0, 1}. Find regular expressions over % that define that following languages. a. The language consisting of all strings of 0’s and 1’s that have even length and in which

the 0’s and 1’s alternate.

b. The language consisting of all strings of 0’s and 1’s with an even number of 1’s. Such strings are said to have even parity.

c. The language consisting of all strings of 0’s and 1’s that do not contain two consecu- tive 1’s.

Solution

a. If a string in the language starts with a 1, the pattern 10 must continue for the length of the string. If it starts with 0, the pattern 01 must continue for the length of the string. Also, the null string satisfies the condition by default. Thus an answer is

(10)∗ | (01)∗. b. Basic strings with even parity are ϵ, 0, and 10∗1. Concatenation of strings with even

parity also have even parity. Because such a string may start or end with a string of 0’s, an answer is

(0 | 10∗1)∗. c. Note that a string may end in a 1, but any other 1 must be followed immediately by a

0. Thus, it is enough to enforce the rule that a 1 must be followed by a 0, unless the 1 is at the end of the string. A regular expression satisfying these conditions is

(0 | 10)∗(ϵ | 1). ■

Note that a given language may be defined by more than one regular expression. For example, both

(a∗ | b∗)∗ and (a | b)∗

define the language consisting of the set of all strings of a’s and b’s.

Example 12.1.10 Deciding Whether Regular Expressions Define the Same Language

In (a) and (b), determine whether the given regular expressions define the same language. If they do, describe the language. If they do not, give an example of a string that is in one of the languages but not the other.

a. (a | ϵ)∗ and a∗ b. 0∗ | 1∗ and (01)∗

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.1 Formal Languages and Regular Expressions 787

Solution

a. Note that because the null string ϵ has no characters, when it is concatenated with any other string x , the result is just x : for all strings x, xϵ = ϵx = x . Now L((a | ϵ)∗) is the set of strings formed using a and ϵ in any order, and so, because aϵ = ϵa = a, this is the same as the set of strings consisting of zero or more a’s. Thus L((a | ϵ)∗) = L(a∗).

b. The two languages defined by the given regular expressions are not the same: 0101 is in the second language but not the first. ■

Practical Uses of Regular Expressions Many applications of computers involve performing operations on pieces of text. For instance, word and text processing programs allow us to find certain words or phrases in a document and possibly replace them with others. A compiler for a computer language analyzes an incoming stream of characters to find groupings that represent aspects of the computer language such as keywords, constants, identifiers, and operators. And in bioinformatics, pattern matching and flexible searching techniques are used extensively to analyze the long sequences of the characters A, C, G, and T that occur in DNA.

Through their connection with finite-state automata, which we discuss in the next sec- tion, regular expressions provide an extremely useful way to describe a pattern in order to identify a string or a collection of strings within a piece of text. Regular expressions make it possible to replace a long, complicated set of if-then-else statements with code that is easy both to produce and to understand. Because of their convenience, regular expres- sions were introduced into a number of UNIX utilities, such as grep (short for globally search for regular expression and print) and egrep (extended grep), in text editors, such as QED (short for Quick EDitor, the first text editor to use regular expressions), vi (short for visual interface), sed (short for stream editor and originally developed for UNIX but now used by many systems), and Emacs (short for Editor macros), and in the lexical scanner component of a compiler. The computer language Perl has a particularly power- ful implementation for regular expressions, which has become a de facto standard. The implementations used in Java and .NET are similar.

A number of shorthand notations have been developed to facilitate working with reg- ular expressions in text processing. When characters in an alphabet or in a part of an alphabet are understood to occur in a standard order, the notation [beginning character– ending character] is commonly used to represent the regular expression that consists of a single character in the range from the beginning to the ending character. It is called a character class. Thus

[A − C] stands for (A | B | C) and

[0− 9] stands for (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9). Character classes are also allowed to include more than one range of characters. For instance,

[A − C x − z] stands for (A | B | C | x | y | z) As an example, consider the language defined by the regular expression

[A − Z a − z]([A − Z a − z] | [0− 9])∗. The following are some strings in the language:

Account Number, z23, jsmith109, Draft2rev.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

788 Chapter 12 Regular Expressions and Finite-State Automata

In general, the language is the set of all strings that start with a letter followed by a sequence of digits or letters. This set is the same as the set of allowable identifiers in a number of computer languages.

Other commonly used shorthands are

[ABC] to stand for (A | B | C) and a single dot

. to stand for an arbitrary character.

Thus, for instance, if % = {A, B, C}, then A.C stands for (AAC | ABC | ACC).

When the symbol ˆ is placed at the beginning of a character class, it indicates that a character of the same type as those in the range of the class is to occur at that point in the string, except for one of the specific characters indicated after the ˆ sign. For instance,

[ˆ D − Z ][0− 9][0− 9]∗

stands for any string starting with a letter of the alphabet different from D to Z , followed by any positive number of digits from 0 to 9. Examples are B3097, C0046, and so forth. If r is a regular expression, the notation r+ denotes the concatenation of r with itself any positive finite number of times. In symbols,

r+ = rr∗. For example, [A − Z ]+ represents any nonempty string of capital letters. If r is a regular expression, then

r? = (ϵ | r). That is, r? denotes either zero occurrences or exactly one occurrence of r . Finally, if m and n are positive integers with m ≤ n,

r{n} denotes the concatenation of r with itself exactly n times, and

r{m, n} denotes the concatenation of r with itself anywhere from m through n times. Thus a check to help determine whether a given string is a local telephone number in the United States is to see whether it has the form

[0− 9][0− 9][0− 9] - [0− 9][0− 9][0− 9][0− 9], or, equivalently, whether it has the form

[0− 9]{3} - [0− 9]{4}.

Example 12.1.11 A Regular Expression for a Date

People often write dates in a variety of formats. For instance, in the United States the following all represent the fifth of February of 2050:

2/5/2050 2-5-2050 02/05/2050 02-05-2050

Write a regular expression that would help check whether a given string might be a valid date written in one of these forms.

Note In most of the rest of the world these expressions represent the second of May of 2050.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.1 Formal Languages and Regular Expressions 789

Solution The language defined by the following regular expression consists of all strings that begin with one or two digits followed by either a hyphen or a slash, followed by either one or two digits, followed by either a hyphen or a slash, followed by four digits.

[0− 9]{1, 2}[−/][0− 9]{1, 2}[0− 9]{4} All valid dates of the given format are elements of the language defined by this expression, but the language also includes strings that are not valid dates. For instance, 09/54/1978 is in the language, but it is not a valid date because September does not have 54 days, and 38/12/2184 is not valid because there is no 38th month. It is possible to write a more com- plicated regular expression that could be used to check all aspects of the validity of a date (see exercise 40 at the end of the section), but the kind of simpler expression given above is nonetheless useful. For instance, it provides an easy way to notify a user of an inter- active program that a certain kind of mistake was made and that information should be reentered. ■

Test Yourself Answers to Test Yourself questions are located at the end of each section.

1. If x and y are strings, the concatenation of x and y is _____.

2. If L and L ′ are languages, the concatenation of L and L ′ is _____.

3. If L and L ′ are languages, the union of L and L ′ is _____.

4. If L is a language, the Kleene closure of L is _____.

5. The set of regular expressions over an alphabet % is defined recursively. The BASE for the definition is the statement that _____. The RECURSION for the definition specifies that if r and s are any regular expressions over %, then the following are also regular expressions in the set: _____, _____, and _____.

6. The function that associates a language to each regular expression over an alphabet % is defined recursively. The BASE for the definition is the statement that L(∅) = _____,

L(ϵ) = _____, and L(a) = _____ for every a in %. The RECURSION for the definition specifies that if L(r) and L(r ′) are the languages defined by the regular expression r and r ′ over %, then L(rr ′) = _____, L(r | r ′) = _____, and L(r∗) = _____.

7. The notation [A - C] is an example of a _____ and denotes the regular expression _____.

8. Use of a single dot in a regular expression stands for _____.

9. The symbol ∧, placed at the beginning of a character class, indicates _____.

10. If r is a regular expression, the notation r+ denotes _____. 11. If r is a regular expression, the notation r? denotes _____.

12. If r is a regular expression, the notation r{n} denotes _____ and the notation r{m, n} denotes _____.

Exercise Set 12.1* In 1 and 2 let % = {x, y} be an alphabet.

1. a. Let L1 be the language consisting of all strings over % that are palindromes and have length ≤ 4. List the ele- ments of L1 between braces.

b. Let L2 be the language consisting of all strings over % that begin with an x and have length ≤ 3. List the ele- ments of L2.

2. a. Let L3 be the language consisting of all strings over % of length ≤ 3 in which all the x’s appear to the left of all the y’s. List the elements of L3 between braces.

b. List between braces the elements of %4, the set of strings of length 4 over %.

c. Let A = %1 ∪%2 and B = %3 ∪%4. Describe A, B, and A ∪ B in words.

3.H a. If the expression ab + cd + · in postfix notation is con- verted to infix notation, what is the result?

b. Let % = {1, 2,∗ , /} and let L be the set of all strings over % obtained by writing first a number (1 or 2), then a second number (1 or 2), which can be the same as the first one, and finally an operation (* or / where * indi- cates multiplication and / indicates division). Then L is a set of postfix, or reverse Polish, expressions. List all the elements of L between braces, and evaluate the resulting expressions.

∗For exercises with blue numbers or letters, solutions are given in Appendix B. The symbol H indicates that only a hint or a partial solution is given. The symbol ✶ signals that an exercise is more challenging than usual.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

790 Chapter 12 Regular Expressions and Finite-State Automata

In 4–6, describe L1 L2, L1 ∪ L2, and (L1 ∪ L2)∗ for the given languages L1 and L2.

4. L1 is the set of all strings of a’s and b’s that start with an a and contain only that one a; L2 is the set of all strings of a’s and b’s that contain an even number of a’s.

5. L1 is the set of all strings of a’s, b’s, and c’s that contain no c’s and have the same number of a’s as b’s; L2 is the set of all strings of a’s, b’s, and c’s that contain no a’s or b’s.

6. L1 is the set of all strings of 0’s and 1’s that start with a 0, and L2 is the set of all strings of 0’s and 1’s that end with a 0.

In 7–9, add parentheses to make the order of precedence clear in the given expressions.

7. (a | b∗b)(a∗ | ab) 8. 0∗1 | 0(0∗1)∗

9. (x | yz∗)∗(yx | (yz)∗z) In 10–12 use the convention about order of precedence to elim- inate the parentheses in the given regular expression.

10. ((a(b∗)) | (c(b∗))) ((ac) | (bc)) 11. (1(1∗)) | ((1(0∗)) | ((1∗)1)) 12. (xy)(((x∗)y)∗) | (((yx) | y)(y∗)) In 13–15 use set notation to derive the language defined by the given regular expression. Assume % = {a, b, c}. 13. ϵ | ab 14. ∅ | ϵ 15. (a | b)c In 16–18 write five strings that belong to the language defined by the given regular expression.

16. 0∗1(0∗1∗)∗ 17. b∗ | b∗ab∗ 18. x∗(yxxy | x)∗

In 19–21 use words to describe the language defined by the given regular expression.

19. b∗ab∗ab∗a 20. 1(0 | 1)∗00 21. (x | y)y(x | y)∗

In 22–24 indicate whether the given strings belong to the lan- guage defined by the given regular expression. Briefly justify your answers.

22. Expression: (b | ϵ)a(a | b)∗a(b | ϵ), strings: aaaba, baabb 23. Expression: (x∗y | zy∗)∗, strings: zyyxz, zyyzy 24. Expression: (01∗2)∗, strings: 120, 01202

In 25–27 find a regular expression that defines the given lan- guage.

25. The language consisting of all strings of 0’s and 1’s with an odd number of 1’s. (Such a string is said to have odd parity.)

26. The language consisting of all strings of a’s and b’s in which the third character from the end is a b.

27. The language consisting of strings of x’s and y’s in which the elements in every pair of x’s are separated by at least one y.

Let r, s, and t be regular expressions over % = {a, b}. In 28–30 determine whether the two regular expressions define the same language. If they do, describe the language. If they do not, give an example of a string that is in one of the languages but not the other.

28. (r | s)t and r t | st 29. (rs)∗ and r∗s∗

30. (rs)∗ and ((rs)∗)∗

In 31–39 write a regular expression to define the given set of strings. Use the shorthand notations given in the section when ever convenient. In most cases, your expression will describe other strings in addition to the given ones, but try to make your answer fit the given strings as closely as possible within reason- able space limitations.

31. All words that are written in lower-case letters and start with the letters pre but do not consist of pre all by itself.

32. All words that are written in upper-case letters, and contain the letters BIO (as a unit) or INFO (as a unit).

33. All words that are written in lower-case letters, end in ly, and contain at least five letters.

34. All words that are written in lower-case letters and contain at least one of the vowels a, e, i, o, or u.

35. All words that are written in lower-case letters and contain exactly one of the vowels a, e, i, o, or u.

36. All words that are written in upper-case letters and do not start with one of the vowels A, E, I, O, or U but contain exactly two of these vowels next to each other.

37. All United States social security numbers (which consist of three digits, a hyphen, two digits, another hyphen, and finally four more digits), where the final four digits start with a 3 and end with a 6.

38. All telephone numbers that have three digits, then a hyphen, then three more digits, then a hyphen, and then four digits, where the first three digits are either 800 or 888 and the last four digits start and end with a 2.

39. All signed or unsigned numbers with or without a decimal point. A signed number has one of the prefixes + or −, and an unsigned number does not have a prefix. Represent the decimal point as \. to distinguish it from the single dot symbol for an arbitrary character.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 791

40.H Write a regular expression to perform a complete check to determine whether a given string represents a valid date from 1980 to 2079 written in one of the formats of Example 12.1.11. (During this period, leap years occur every four years starting in 1980.)

41.✶ Write a regular expression to define the set of strings of 0’s and 1’s with an even number of 0’s and even number of 1’s.

Answers for Test Yourself 1. the string obtained by writing all the characters of x followed by all the characters of y 2. {xy | x ∈ L and y ∈ L ′} 3. {s | s ∈ L or s ∈ L ′} 4. {t | t is a concatenation of any finite number of strings in L} 5. ∅, ϵ, and each individual symbol in % are regular expressions over %; (rs) : (r | s); (r∗) 6. ∅; {ϵ}; {a}; L(r)L(r ′); L(r) ∪ L(r ′); (L(r))∗ 7. character class; (A | B | C) 8. an arbitrary character 9. a character of the same type as those in the range of the class is to occur at that point in the string except for one of the specific characters indicated after the ∧ sign. 10. The concatenation of r with itself any positive finite number of times 11. (ϵ | r) 12. the concatenation of r with itself exactly n times; the concatenation of r with itself anywhere from m through n times

12.2 Finite-State Automata The world of the future will be an ever more demanding struggle against the limitations of our intelligence, not a comfortable hammock in which we can lie down to be waited upon by our robot slaves. — Norbert Wiener, 1964

The kind of circuit discussed in Section 2.4 is called a combinational circuit. Such a cir- cuit is characterized by the fact that its output is completely determined by its input/output table, or, in other words, by a Boolean function. Its output does not depend in any way on the history of previous inputs to the circuit. For this reason, a combinational circuit is said to have no memory.

Combinational circuits are very important in computer design, but they are not the only type of circuits used. Equally important are sequential circuits. For sequential cir- cuits one cannot predict the output corresponding to a particular input unless one also knows something about the prior history of the circuit, or, more technically, unless one knows the state the circuit was in before receiving the input. The behavior of a sequential circuit is a function not only of the input to the circuit but also of the state the circuit is in when the input is received. A computer memory circuit is a type of sequential circuit.

A finite-state automaton (aw-TAHM-uh-tahn) is an idealized machine that embodies the essential idea of a sequential circuit. Each piece of input to a finite-state automaton leads to a change in the state of the automaton, which in turn affects how subsequent input is processed. Imagine, for example, the act of dialing a telephone number. Dialing 1–800 puts the telephone circuit in a state of readiness to receive the final seven digits of a toll-free call, whereas dialing 328 leads to a state of expectation for the four digits of a local call. Vending machines operate similarly. Just knowing that you put a quarter into a vending machine is not enough for you to be able to predict what the behavior of the machine will be. You also have to know the state the machine was in when the quarter was inserted. If 75c/ had already been deposited, you might get a beverage or some candy, but if the quarter was the first coin deposited, you would probably get nothing at all.

Example 12.2.1 A Simple Vending Machine

A simple vending machine dispenses bottles of juice that cost $1 each. The machine accepts quarters and half-dollars only and does not give change. As soon as the amount deposited equals or exceeds $1 the machine releases a bottle of juice. The next coin deposited starts the process over again. The operation of the machine is represented by the diagram of Figure 12.2.1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

792 Chapter 12 Regular Expressions and Finite-State Automata

half-dollar

half-dollar half-dollar

half-dollar

quarter

qu art

er

quarter half-dollar

quarter qu art

er

25¢ deposited

0¢ deposited

50¢ deposited

75¢ deposited

$1 or more

deposited

Figure 12.2.1 A Simple Vending Machine

Each circle represents a state of the machine: the state in which 0c/ has been deposited, 25c/ , 50c/ , 75c/ , and $1 or more. The unlabeled arrow pointing to “0c/ deposited” indi- cates that this is the initial state of the machine. The double circle around “$1 or more deposited” indicates that a bottle of juice is released when the machine has reached this state. (It is called an accepting state of the machine because when the machine is in this state, it has accepted the input sequence of coins as payment for juice.) The arrows that link the states indicate what happens when a particular input is made to the machine in each of its various states. For instance, the arrow labeled “quarter” that goes from “0c/ deposited” to “25c/ deposited” indicates that when the machine is in the state “0c/ deposited” and a quarter is inserted, the machine goes to the state “25c/ deposited.” The arrow labeled “half-dollar” that goes from “75c/ deposited” to “$1 or more deposited” indicates that when the machine is in the state “75c/ deposited” and a half-dollar is inserted, the machine goes to the state “$1 or more deposited” and juice is dispensed. (In this case the purchaser would pay $1.25 for the juice because the machine does not return change.) The arrow labeled “quarter” that goes from “$1 or more deposited” to “25c/ deposited” indicates that when the machine is in the state “$1 or more deposited” and a quater is inserted, the machine goes back to the state “25c/ deposited.” (This corresponds to the fact that after the machine has dispensed a bottle of juice, it starts operation all over again.)

Equivalently, the operation of the vending machine can be represented by a next-state table as shown in Table 12.2.1.

Table 12.2.1 Next-State Table

Input

Quarter Half-Dollar

→ 0c/ deposited 25c/ deposited 50c/ deposited 25c/ deposited 50c/ deposited 75c/ deposited

State 50c/ deposited 75c/ deposited $1 or more deposited 75c/ deposited $1 or more deposited $1 or more deposited

' $1 or more deposited 25c/ deposited 50c/ deposited

The arrow pointing to “0c/ deposited” in the table indicates that the machine begins operation in this state. The double circle next to “$1 or more deposited” indicates that a bottle of juice is released when the machine has reached this state. Entries in the body of the table are interpreted in the obvious way. For instance, the entry in the third row of the column labeled Half-Dollar shows that when the machine is in state “50c/ deposited” and a half-dollar is deposited, it goes to state “$1 or more deposited.”

Note that Table 12.2.1 conveys exactly the same information as the diagram of Figure 12.2.1. If the diagram is given, the table can be constructed; and if the table is given, the diagram can be drawn. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 793

Observe that the vending machine described in Example12.2.1 can be thought of as having a primitive memory: It “remembers” how much money has been deposited (within limits) by referring to the state it is in. This capability for storing information and acting upon it is what gives finite-state automata their tremendous power.

The most important finite-state automata are digital computers. Each computer con- sists of several subsystems: input devices, a processor, and output devices. A proces- sor typically consists of a central processing unit and a finite number of memory loca- tions. At any given time, the state of the processor is determined by the locations and values of all the bits stored within its memory. A computer that has n different loca- tions for storing a single bit can therefore exist in 2n different states. For a modern computer, n is many billions or even trillions, so the total number of states is enor- mous. But it is finite. Therefore, despite the complexity of a computer, just as for a vending machine, it is possible to predict the next state given knowledge of the cur-

D av

id Eu

ge ne

Sm ith

Co lle

ct io

n, R

ar e

B oo

k an

d M

an us

cr ip

t Li

br ar

y, Co

lu m

bi a

U ni

ve rs

ity

David Hilbert (1862–1943)

rent state and the input. Indeed, this is essentially what programmers try to do every time they write a program. Fortunately, modern, high-level computer languages provide a lot of help.

The basic theory of automata was developed to answer very theoretical questions about the foundations of mathematics posed by the great German mathematician David Hillbert in 1900. The ground-breaking work on automata was done in the mid-1930s by the English mathematician and logician Alan M. Turing. In the 1940s and 1950s, Turing’s work played an important role in the development of real-world automatic

Ti m

e &

Li fe

Pi ct

ur es

/G et

ty Im

ag es

Alan M. Turing (1912–1954)

computers.

Definition of a Finite-State Automaton A general finite-state automaton is completely described by giving a set of states, together with an indication about which is the initial state and which are the accepting states (when something special happens), a list of all input elements, and specification for a next-state function that defines which state is produced by each input in each state. This is formalized in the following definition:

• Definition A finite-state automaton A consists of five objects:

1. A finite set I , called the input alphabet, of input symbols;

2. A finite set S of states the automaton can be in;

3. A designated state s0 called the initial state;

4. A designated set of states called the set of accepting states;

5. A next-state function N: S × I → S that associates a “next-state” to each ordered pair consisting of a “current state” and a “current input.” For each state s in S and input symbol m in I, N (s, m) is the state to which A goes if m is input to A when A is in state s.

The operation of a finite-state automaton is commonly described by a diagram called a (state-)transition diagram, similar to that of Figure 12.2.1. It is called a transition diagram because it shows the transitions the machine makes from one state to another in response to various inputs. In a transition diagram, states are represented by circles and accepting states by double circles. There is one arrow that points to the initial state and other arrows that are labeled with input symbols and point from each state to other

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

794 Chapter 12 Regular Expressions and Finite-State Automata

states to indicate the action of the next-state function. Specifically, an arrow from state s to state t labeled m means that N (s, m) = t .

The next-state table for an automaton shows the values of the next-state function N for all possible states s and input symbols i . In the annotated next-state table, the initial state is indicated by an arrow and the accepting states are marked by double circles.

Example 12.2.2 A Finite-State Automaton Given by a Transition Diagram

Consider the finite-state automaton A defined by the transition diagram shown in Figure 12.2.2.

a. What are the states of A?

b. What are the input symbols of A?

c. What is the initial state of A?

d. What are the accepting states of A?

e. Determine N (s1, 1).

f. Construct the annotated next-state table for A.

1 0 0

1

1

0s0 s1 s2

Figure 12.2.2

Solution

a. The states of A are s0, s1, and s2 [since these are the labels of the circles].

b. The input symbols of A are 0 and 1 [since these are the labels of the arrows].

c. The initial state of A is s0 [since the unlabeled arrow points to s0].

d. The only accepting state of A is s2 [since this is the only state marked by a double circle].

e. N (s1, 1) = s2 [since there is an arrow from s1 to s2 labeled 1]. f. Input

0 1

→ s0 s1 s0 State s1 s1 s2

' s2 s1 s0 ■

Example 12.2.3 A Finite-State Automaton Given by an Annotated Next-State Table

Consider the finite-state automaton A defined by the following annotated next-state table:

Input

a b c

→ U Z Y Y ' V V V V

State Y Z V Y ' Z Z Z Z

a. What are the states of A?

b. What are the input symbols of A?

c. What is the initial state of A?

d. What are the accepting states of A?

e. Find N (U, c).

f. Draw the transition diagram for A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 795

Solution

a. The states of A are U, V, Y , and Z .

b. The input symbols of A are a, b, and c.

c. The initial state of A is U [since the arrow points to U].

d. The accepting states of A are V and Z [since these are marked with double circles].

e. N (U, c) = Y [since the entry in the row labeled U and the column labeled c of the next-state table is Y ].

f. The transition diagram for A is shown in Figure 12.2.3. It can be drawn more com- pactly by labeling arrows with multiple-input symbols where appropriate. This is illus- trated in Figure 12.2.4.

a

a

a a

b

b

b

c

c

b

c

c

U V

YZ

Figure 12.2.3

a

a

b

c a, b, c

a, b, c

b, c

U V

YZ

Figure 12.2.4

The Language Accepted by an Automaton Now suppose a string of input symbols is fed into a finite-state automaton in sequence. At the end of the process, after each successive input symbol has changed the state of the automaton, the automaton ends up in a certain state, which may be either an accepting state or a nonaccepting state. In this way, the action of a finite-state automaton separates the set of all strings of input symbols into two subsets: those that send the automaton to an accepting state and those that do not. Those strings that send the automaton to an accepting state are said to be accepted by the automaton.

• Definition Let A be a finite-state automaton with set of input symbols I . Let I ∗ be the set of all strings over I , and let w be a string in I ∗. Then w is accepted by A if, and only if, A goes to an accepting state when the symbols of w are input to A in sequence from left to right, starting when A is in its initial state. The language accepted by A, denoted L(A), is the set of all strings that are accepted by A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

796 Chapter 12 Regular Expressions and Finite-State Automata

Example 12.2.4 Finding the Language Accepted by an Automaton

Consider the finite-state automaton A defined in Example 12.2.2 and shown again below.

1 0 0

1

1

0s0 s1 s2

a. To what states does A go if the symbols of the following strings are input to A in sequence, starting from the initial state?

(i) 01 (ii) 0011 (iii) 0101100 (iv) 10101

b. Which of the strings in part (a) send A to an accepting state?

c. What is the language accepted by A?

d. Is there a regular expression that defines the same language?

Solution

a. (i) s2 (ii) s0 (iii) s1 (iv) s2

b. The strings 01 and 10101 send A to an accepting state.

c. Observe that if w is any string that ends in 01, then w is accepted by A. For if w is any string of length n ≥ 2, then after the first n − 2 symbols of w have been input, A is in one of its three states: s0, s1, or s2. But from any of these three states, input of the symbols 01 in sequence sends A first to s1 and then to the accepting state s2. Hence any string that ends in 01 is accepted by A.

Also note that the only strings accepted by A are those that end in 01. (That is, no other strings besides those ending in 01 are accepted by A.) The reason for this is that the only accepting state of A is s2, and the only arrow pointing to s2 comes from s1 and is labeled 1. Thus in order for an input string w of length n to send A to an accepting state, the last symbol of w must be a 1 and the first n − 1 symbols of w must send A to state s1. Now three arrows point to s1, one from each of the three states of A, and all are labeled 0. Thus the last of the first n − 1 symbols of w must be 0, or, in other words, the next-to-the-last symbol of w must be 0. Hence the last two symbols of w must be 01, and thus

L(A) = the set of all strings of 0’s and 1’s that end in 01. d. Yes. One regular expression that defines L(A) is (0 | 1)∗01. ■

A finite-state automaton with multiple accepting states can have output devices attached to each one so that the automaton can classify input strings into a variety of different categories, one for each accepting state. This is how finite-state automata are used in the lexical scanner component of a computer compiler to group the symbols from a stream of input characters into identifiers, keywords, and so forth.

The Eventual-State Function Now suppose a finite-state automaton is in one of its states (not necessarily the initial state) and a string of input symbols is fed into it in sequence. To what state will the automaton eventually go? The function that gives the answer to this question for every possible combination of input strings and states of the automaton is called the eventual- state function.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 797

• Definition Let A be a finite-state automaton with set of input symbols I , set of states S, and next-state function N : S × I → S. Let I ∗ be the set of all strings over I , and define the eventual-state function N ∗: S × I ∗ → S as follows:

For any state s and for any input string w,

N ∗(s, w) =

⎣ the state to which A goes if the symbols of w are input to A in sequence, starting when A is in state s

⎦ .

Example 12.2.5 Computing Values of the Eventual-State Function

Consider again the finite-state automaton of Example 12.2.2 shown below for conven- ience. Find N ∗(s1, 10110).

1 0 0

1

1

0s0 s1 s2

Solution By definition of the eventual-state function,

N ∗(s1, 10110) =

⎣ the state to which A goes if the symbols of 10110 are input to A in sequence, starting when A is in state s1

⎦ .

By referring to the transition diagram for A, you can see that starting from s1, when a 1 is input, A goes to s2; then when a 0 is input, A goes back to s1; after that, when a 1 is input, A goes to s2; from there, when a 1 is input, A goes to s0; and finally, when a 0 is input, A goes back to s1. This sequence of state transitions can be written as follows:

s1 1−→ s2

0−→ s1 1−→ s2

1−→ s0 0−→ s1.

Thus, after all the symbols of 10110 have been input in sequence, the eventual state of A is s1, so

N ∗(s1, 10110) = s1. ■

The definitions of string and language accepted by an automaton can be restated sym- bolically using the eventual-state function. Suppose A is a finite-state automaton with set of input symbols I and next-state function N , and suppose that I ∗ is the set of all strings over I and that w is a string in I ∗.

w is accepted by A ⇔ N ∗(s0, w) is an accepting state of A

L(A) = {w ∈ I ∗ | N ∗(s0, w) is an accepting state of A}

Designing a Finite-State Automaton Now consider the problem of starting with a description of a language and designing an automaton to accept exactly that language.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

798 Chapter 12 Regular Expressions and Finite-State Automata

Example 12.2.6 A Finite-State Automaton That Accepts the Set of Strings of 0’s and 1’s for Which the Number of 1’s Is Divisible by 3

a. Design a finite-state automaton A that accepts the set of all strings of 0’s and 1’s such that the number of 1’s in the string is divisible by 3.

b. Is there a regular expression that defines this set?

Solution

a. Let s0 be the initial state of A, s1 its state after one 1 has been input, and s2 its state after two 1’s have been input. Note that s0 is the state of A after zero 1’s have been input, and since zero is divisible by 3 (0 = 0 ·3), s0 must be an accepting state. The states s0, s1, and s2 must be different from one another because from state s0 three 1’s are needed to reach a new total divisible by 3, whereas from state s1 two additional 1’s are necessary, and from state s2 just one more 1 is required.

Now the state of A after three 1’s have been input can also be taken to be s0 because after three 1’s have been input, three more are needed to reach a new total divisible by 3. More generally, if 3k 1’s have been input to A, where k is any non- negative integer, then three more are needed for the total again to be divisible by 3 (since 3k + 3 = 3(k + 1)). Thus the state in which 3k 1’s have been input, for any nonnegative integer k, can be taken to be the initial state s0.

By similar reasoning, the states in which (3k + 1) 1’s and (3k + 2) 1’s have been input, where k is a nonnegative integer, can be taken to be s1 and s2, respectively.

Now every nonnegative integer can be written in one of the three forms 3k, 3k + 1, or 3k + 2 (see Section 4.4), so the three states s0, s1, and s2 are all that is needed to create A. Thus the states of A can be drawn and labeled as shown below.

s2

s1s0

Next consider the possible inputs to A in each of its states. No matter what state A is in, if a 0 is input the total number of 1’s in the input string remains unchanged. Thus there is a loop at each state labeled 0.

Now suppose a 1 is input to A when it is in state s0. Then A goes to state s1 (since the total number of 1’s in the input string has changed from 3k to 3k + 1). Similarly, if a 1 is input to A when it is in state s1, then A goes to state s2 (since the total number of 1’s in the input string has changed from 3k + 1 to 3k + 2). Finally, if a 1 is input to A when it is in state s2, then it goes to state s0 (since the total number of 1’s in the input string becomes (3k + 2) + 1 = 3k + 3 = 3(k + 1), which is a multiple of 3.)

It follows that the transition diagram for A has the appearance shown below. 0

1 0

11

0

This automaton accepts the set of strings of 0's and 1's for which the number of 1's is divisible by 3.

s2

s1s0

b. A regular expression that defines the given set is 0∗ | (0∗10∗10∗10∗)∗. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 799

Example 12.2.7 A Finite-State Automaton That Accepts the Set of All Strings of 0’s and 1’s Containing Exactly One 1

a. Design a finite-state automaton A to accept the set of all strings of 0’s and 1’s that contain exactly one 1.

b. Is there a regular expression that defines this set?

Solution

a. The automaton A must have at least two distinct states:

s0: initial state;

s1: state to which A goes when the input string contains exactly one 1.

If A is in state s0 and a 0 is input, A may as well stay in state s0 (since it still needs to wait for a 1 to move to state s1), but as soon as a 1 is input, A moves to state s1. Thus a partial drawing of the transition diagram is as shown below.

0

1s0 s1

Now consider what happens when A is in state s1. If a 0 is input, the input string still has a single 1, so A stays in state s1. But if a 1 is input, then the input string contains more than one 1, so A must leave s1 (since no string with more than one 1 is to be accepted by A). It cannot go back to state s0 because there is a way to get from s0 to s1, and after input of the second 1, A can never return to state s1. Hence A must go to a third state, s2, from which there is no return to s1. Thus from s2 every input may as well leave A in state s2. It follows that the completed transition diagram for A has the appearance shown below.

0 0, 10

1 1 This automaton accepts the set of strings 0's and 1's, with exactly one 1.

s0 s2s1

b. A regular expression that defines the given set is 0∗10∗. ■

Simulating a Finite-State Automaton Using Software Suppose items have been coded with strings of 0’s and 1’s. A program is to be written to govern the processing of items coded with strings that end 011; items coded any other way are to be ignored. This situation can be modeled by the finite-state automaton shown in Figure 12.2.5.

0 1

1

1 This automaton recognizes strings that end 011.

1 0 0

0

s0 s2s1 s3

Figure 12.2.5

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

800 Chapter 12 Regular Expressions and Finite-State Automata

The symbols of the code for the item are fed into this automaton in sequence, and every string of symbols in a given code sends the automaton to one of the four states s0, s1, s2, or s3. If state s3 is reached, the item is processed; if not, the item is ignored.

The action of this finite-state automaton can be simulated by a computer algorithm as given in Algorithm 12.2.1.

Algorithm 12.2.1 A Finite-State Automaton

[This algorithm simulates the action of the finite-state automaton of Figure 12.2.5 by mimicking the functioning of the transition diagram. The states are denoted 0, 1, 2, and 3.]

Input: string [a string of 0’s and 1’s plus an end marker e] Algorithm Body:

state := 0 symbol := first symbol in the input string while (symbol ̸= e)

if state = 0 then if symbol = 0 then state := 1 else state := 0

else if state = 1 then if symbol = 0 then state := 1 else state := 2

else if state = 2 then if symbol = 0 then state := 1 else state := 3

else if state = 3 then if symbol = 0 then state := 1 else state := 0

symbol := next symbol in the input string end while [After execution of the while loop, the value of state is 3 if, and only if, the in- put string ends in 011e.]

Output: state

Note how use of the finite-state automaton allows the creator of the algorithm to focus on each step of the analysis of the input string independently of the other steps.

An alternative way to program this automaton is to enter the values of the next-state function directly as a two-dimensional array. This is done in Algorithm 12.2.2.

Algorithm 12.2.2 A Finite-State Automaton

[This algorithm simulates the action of the finite-state automaton of Figure 12.2.5 by repeated application of the next-state function. The states are denoted 0, 1, 2, and 3.]

Input: string [a string of 0’s and 1’s plus an end marker e]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 801

Algorithm Body: N (0, 0) := 1, N (0, 1) := 0, N (1, 0) := 1, N (1, 1) := 2, N (2, 0) := 1, N (2, 1) := 3, N (3, 0) := 1, N (3, 1) := 0 state : = 0 symbol : = first symbol in the input string while (symbol ̸= e)

state := N (state, symbol) symbol := next symbol in the input string

end while [After execution of the while loop, the value of state is 3 if, and only if, the input string ends in 011e.]

Output: state

Finite-State Automata and Regular Expressions In the previous sections, each time we considered a language accepted by a finite-state automaton, we found a regular expression that defined the same language. Stephen Kleene showed that our ability to do this is not sheer coincidence. He proved that any language accepted by a finite-state automaton can be defined by a regular expression and that, con- versely, any language defined by a regular expression is accepted by a finite-state automa- ton. Thus for the many applications of regular expressions discussed in Section 12.1, it is theoretically possible to find a corresponding finite-state automaton, which can then be simulated using the kinds of computer algorithms described in the previous subsection.

In practice, it is often of interest to retain only pieces of the patterns sought. For instance, to obtain a reference in an HTML document, one would specify a regular expression defining the full HTML tag, <a href= “the desired URL”>, but one would be interested in retrieving only the string between the quotation marks. Because of these kinds of considerations, actual implementations of finite-state automata include addi- tional features.∗

We break the statement of Kleene’s theorem into two parts.

Kleene’s Theorem, Part 1

Given any language that is accepted by a finite-state automaton, there is a regular expression that defines the same language.

Proof:

Suppose A is a finite-state automaton with a set I of input symbols, a set S of n states, and a next-state function N : S × I → S. Let I ∗ denote the set of all strings over I . Number the states s1, s2, s3, . . . , sn , using s1 to denote the initial state, and for each integer k = 1, 2, 3, . . . , n, let

Lki, j =

⎧ ⎨

⎩x ∈ I ∗

∣∣∣∣∣∣

when the symbols of x are input to A in sequence, A goes from state si to state s j without traveling through an intermediate state sh for which h > k

⎫ ⎬

⎭ .

continued on page 802

∗For more information, see Mastering Regular Expressions, 3rd ed., by Jeffrey E. F. Friedl, (Sebastopol, CA: O’Reilly & Associates, 2006).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

802 Chapter 12 Regular Expressions and Finite-State Automata

Note that either index i or index j in Lki, j could be greater than k; the only restriction is that the symbols of a string in Lki, j cannot make A both enter and exit an intermediate state with index greater than k.

If s j is an accepting state and if k = n and i = 1, then Ln1, j is the set of all strings that send A to s j when the symbols of the string are input to A in sequence starting from s1. Thus

Ln1, j ⊆ L(A).

Moreover, because the sequence of symbols in every string in L(A) sends A to some accepting state s j ,

L(A) is the union of all the sets Ln1, j , where s j is an accepting state.

We use a version of mathematical induction to build up a set of regular expres- sions over I . Let the property P(m) be the sentence

For any pair of integers i and j with 1 ≤ i, j ≤ n, there is a regular expression rmi, j that defines L

m i, j . ← P(m)

Show that P(0) is true: For each pair of integers i and j with 1 ≤ i, j ≤ n, L0i, j is the set of all strings that send A from si to s j without sending it through any intermediate state sh for which h > 0. Because the subscript of every state in A is greater than zero, the strings in L0i, j do not send A through any intermediate states at all, and so each is a single input symbol from I . In other words, for all integers i and j with 1 ≤ i, j ≤ n,

L0i, j = {a ∈ I | N (si , a) = s j }.

Hence L0i, j is a subset of I , and so (because I is finite) we may denote the elements of L0i, j as follows:

L0i, j = {a1, a2, a3, . . . , aM } ⊆ I.

Now, by definition of regular expression, each single input symbol of I is a reg- ular expression over I ; thus every element of L0i, j is a regular expression over I . The result is that for all integers i and j with 1 ≤ i, j ≤ n, the following regular expression defines L0i, j :

a1 | a2 | a3| · · · |aM Show that for all integers k with 0 ≤ k < n, if P(k) is true then P(k + 1) is true: Let k be any integer with 1 ≤ k < n, and suppose that

For each pair of integers p and q with 1 ≤ p, q ≤ n, ← P(k) there is a regular expression rkp,q that defines L

k p,q . inductive hypothesis

We will show that

For each pair of integers i and j with 1 ≤ i, j ≤ n, there is a regular expression rk+1i, j that defines L

k+1 i, j . ← P(k + 1)

So suppose that i and j are any pair of integers with 1 ≤ i, j ≤ n, and observe that any string in Lk+1i, j sends A from si to s j , either by a route that makes A pass through sk+1 or by a route that does not make A pass through sk+1. Now each string that sends A from si to s j and makes A pass through sk+1 one or more times can be broken into segments. The symbols in the first segment send A from si to sk+1 without making A pass through sk+1; those in each of the intermediate segments send sk+1 to itself without making A pass through sk+1; and those in the final segment send A from

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 803

sk+1 to s j without making A pass through sk+1. (The intermediate segment could be the null string.) A typical path showing two intermediate segments is illustrated below.

si sjsk+1

Note that each intermediate segment of the string is in Lkk+1,k+1, and by assumption the regular expression rkk+1,k+1 defines this set. By the same reasoning, r

k i,k+1 defines

the set of all possible first segments of the string, and rkk+1, j defines the set of all possible final segments of the string. In addition, rki, j defines the set of all strings that send A from si to s j without making it pass through a state sm with m > k. Thus we may define the regular expression rk+1i, j as follows:

rk+1i, j = rki, j | rki,k+1 ( rkk+1,k+1

)∗ rkk+1, j .

Then rk+1i, j defines the set of all strings that send A from si to s j without making it pass through any states sm with m > k + 1, and so rk+11, j defines Lk+11, j [as was to be shown].

To complete the proof, let s j1 , s j2 , . . . , s jk be the accepting state of A. Because L(A) is the union of all the Ln1, j where s j is an accepting state, we have

L(A) = L (

rn1, j1

) ∪ L (

rn1, j2 ∪ · · · ∪ L (

rn1, jn

)

= L (

rn1, j1 |rn1, j2 | · · · |rn1, jn )

by the recursive definition for the language defined by a regular expression

Thus if we let r = rn1, j1 ∣∣∣rn1, j2 ∣∣∣ · · · ∣∣∣rn1, jn , we have that L(A) = L(r). In other words,

we have constructed a regular expression r that defines the language accepted by A.

Kleene’s Theorem, Part 2

Given any language defined by a regular expression, there is a finite-state automaton that accepts the same language.

The most common way to prove part 2 of Kleene’s theorem is to introduce a new cat- egory of automata called nondeterministic finite-state automata. These are similar to the (deterministic) finite-state automata we have been discussing, except that for any given state and input symbol, the next state is a subset of the set of states of the automaton, possibly even the empty set. Thus the next state of the automaton is not uniquely deter- mined by the combination of a current state and an input symbol. A string is accepted by a nondeterministic finite-state automaton if, and only if, when the symbols in the string are input to the automaton in sequence, starting from an initial state, there is some sequence of next states through which the automaton could travel that would send it to an accept- ing state. For instance, the transition diagram at the left is an example of a very simple nondeterministic finite-state automaton that accepts the set of all strings beginning with a 1. Observe that N (s0, 1) = {s1, s2} and N (s0, 0) = ∅.

1

0

1

1

s1

s2

s0

Given a language defined by any regular expression, there is a straightforward recur- sive algorithm for finding a nondeterministic finite-state automaton that defines the same

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

804 Chapter 12 Regular Expressions and Finite-State Automata

language. The proof of Kleene’s theorem is completed by showing that for any such non- deterministic finite-state automaton, there is a (deterministic) finite-state automaton that defines the same language. We leave the details of the proof to a course in automata theory.

Regular Languages According to Kleene’s theorem, the set of languages defined by regular expressions is identical to the set of languages accepted by finite-state automata. Any such language is called a regular language. The brief allusions we made earlier to context-free languages and Chomsky’s classification of languages suggest that not every language is regular. We will prove this by giving an example of a nonregular language.

To construct the example, note that because a finite-state automaton can assume only a finite number of states and because there are infinitely many input sequences, by the pigeonhole principle there must be at least one state to which the automaton returns over and over again. This is the essential feature of an automaton that makes it possible to find a nonregular language.

Example 12.2.8 Showing That a Language is Not Regular

Let the language L consist of all strings of the form akbk , where k is a positive integer. Symbolically, L is the language over the alphabet % = {a, b} defined by

L = {s ∈ %∗ | s = akbk, where k is a positive integer}. Use the pigeonhole principle to show that L is not regular. In other words, show that there is no finite-state automaton that accepts L .

Solution [Use a proof by contradiction.] Suppose not. That is, suppose there is a finite- state automaton A that accepts L . [A contradiction will be derived.] Since A has only a finite number of states, these states can be denoted s1, s2, s3, . . . , sn , where n is a positive integer. Consider all input strings that consist entirely of a’s: a, a2, a3, a4, . . . . Now there are infinitely many such strings and only finitely many states. Thus, by the pigeonhole principle, there must be a state sm and two input strings a p and aq with p ̸= q such that when either a p or aq is input to A, A goes to state sm . (See Figure 12.2.6.) [The pigeons are the strings of a’s, the pigeonholes are the states, and the correspondence associates each string with the state to which A goes when the string is input.]

a2

a3

ap

aq

a F

s2

s3

sm

sn

s1

Strings of a's States of A

There are an infinite number of these strings.

There are only n states.

F(ai) = the state to which A

= N*(S0, a i)

goes when ai is input

Since F is not one-to-one, ∃ strings ap and aq with p ≠ q such that both ap and aq send A to the same state sm.

Figure 12.2.6

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 805

Now, by supposition, A accepts L . Hence A accepts the string

a pbp.

This means that after p a’s have been input, at which point A is in state sm , inputting p additional b’s sends A into an accepting state, say sa . But that implies that

aqbp

also sends A to the accepting state sa , and so aqbp is accepted by A. The reason is that after q a’s have been input, A is also in state sm , and from that point, inputting p additional b’s sends A to state sa , which is an accepting state. Pictorially, if p < q , then

a a a

a

a a

a

a b b

p a's are input p b's are input

q – p additional a's are input

sm saso

Now, by supposition, L is the language accepted by A. Thus since s is accepted by A, s ∈ L . But by definition of L , L consists only of strings with equal numbers of a’s and b’s. So since p ̸= q, s /∈ L . Hence s ∈ L and s /∈ L , which is a contradiction.

It follows that the supposition is false, and so there is no finite-state automaton that accepts L . ■

Test Yourself 1. The five objects that make up a finite-state automaton are

_____, _____, _____, _____, and _____.

2. The next-state table for an automaton shows the values of _____.

3. In the annotated next-state table, the initial state is indicated with an _____ and the accepting states are marked by _____.

4. A string w consisting of input symbols is accepted by a finite-state automation A if, and only if, _____.

5. The language accepted by a finite-state automaton A is _____.

6. If N is the next-state function for a finite-state automation

A, the eventual-state function N ∗ is defined as follows: For each state s of A and for each string w that consists of input symbols of A, N ∗(s, w) = _____.

7. One part of Kleene’s theorem says that given any language that is accepted by a finite-state automaton, there is _____.

8. The second part of Kleene’s theorem says that given any language defined by a regular expression, there is _____.

9. A regular language is _____.

10. Given the language consisting of all strings of the form akbk , where k is a positive integer, the pigeonhole principle can be used to show that the language is _____.

Exercise Set 12.2 1. Find the state of the vending machine in Example 12.2.1

after each of the following sequences of coins have been input. a. Quarter, half-dollar, quarter b. Quarter, half-dollar, half-dollar c. Half-dollar, quarter, quarter, quarter, half-dollar

In 2–7 a finite-state automaton is given by a transition diagram. For each automaton:

a. Find its states. b. Find its input symbols. c. Find its initial state. d. Find its accepting states. e. Write its annotated next-state table.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

806 Chapter 12 Regular Expressions and Finite-State Automata

2. 1 0

0 1

1

0 s0 s1 s2

3. b b

b

a

b

a

aa

U0 U1

U2

U3

4.

1

1

0

1

0

0

s0 s1 s2

5.

y

x

y

x

y

x

x x

y

x

y

y

B

C

A F

D

E

6. 0 0

00

1

1

1 1

s0 s1

s3 s2

7. 0 0

00

1

1

1 1

s0

s2

s1

s3

In 8 and 9 a finite-state automaton is given by an annotated next- state table. For each automaton: a. Find its states. b. Find its input symbols. c. Find its initial state. d. Find its accepting states. e. Draw its transition diagram.

8. Next-State Table Input

0 1 → s0 s1 s2

State s1 s1 s2 ' s2 s1 s2

9. Next-State Table

Input

0 1 → s0 s0 s1 ' s1 s1 s2

State s2 s2 s3 s3 s3 s0

10. A finite-state automaton A, given by the transition diagram below, has next-state function N and eventual-state func- tion N ∗.

0

1

1

1

0 100

s0

s2

s3

s1

a. Find N (s1, 1) and N (s0, 1). b. Find N (s2, 0) and N (s1, 0). c. Find N ∗(s0, 10011) and N ∗(s1, 01001). d. Find N ∗(s2, 11010) and N ∗(s0, 01000).

11. A finite-state automaton A, given by the transition diagram below, has next-state function N and eventual-state func- tion N ∗.

1

0

0

0 1 0

1

1

0

1

s1s0

s4

s2s3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.2 Finite-State Automata 807

a. Find N (s3, 0) and N (s2, 1). b. Find N (s0, 0) and N (s4, 1). c. Find N ∗(s0, 010011) and N ∗(s3, 01101). d. Find N ∗(s0, 1111) and N ∗(s2, 00111).

12. Consider again the finite-state automaton of exercise 2. a. To what state does the automaton go when the symbols

of the following strings are input to it in sequence, start- ing from the initial state? (i) 1110001 (ii) 0001000 (iii) 11110000

b. Which of the strings in part (a) send the automaton to an accepting state?

c. What is the language accepted by the automaton? d. Find a regular expression that defines the language.

13. Consider again the finite-state automaton of exercise 3. a. To what state does the automaton go when the symbols

of the following strings are input to it in sequence, start- ing from the initial state? (i) bb (ii) aabbbaba (iii) babbbbbabaa (iv) bbaaaabaa

b. Which of the strings in part (a) send the automaton to an accepting state?

c. What is the language accepted by the automaton? d. Find a regular expression that defines the language.

In each of 14–19, (a) find the language accepted by the automa- ton in the referenced exercise, and (b) find a regular expression that defines the same language.

14. Exercise 4 15. Exercise 5 16. Exercise 6

17. Exercise 7 18. Exercise 8 19. Exercise 9

In each of 20–29, (a) design an automaton with the given input alphabet that accepts the given set of strings, and (b) find a regular expression that defines the language accepted by the automaton.

20. Input alphabet = {0, 1}; Accepts the set of all strings for which the final three input symbols are 1.

21.H Input alphabet = {a, b}; Accepts the set of all strings of length at least 2 for which the final two input symbols are the same.

22. Input alphabet = {0, 1}; Accepts the set of all strings that start with 01 or 10.

23. Input alphabet = {0, 1}; Accepts the set of all strings that start with 01.

24. Input alphabet = {0, 1}; Accepts the set of all strings that start with 101.

25. Input alphabet = {0, 1}; Accepts the set of all strings that end in 10.

26. Input alphabet = {a, b}; Accepts the set of all strings that contain exactly two b’s.

27. Input alphabet = {0, 1}; Accepts the set of all strings that start with 0 and contain exactly one 1.

28. Input alphabet = {0, 1}; Accepts the set of all strings that contain the pattern 010.

In 29–47, design a finite-state automaton to accept the language defined by the regular expression in the referenced exercise from Section 12.1.

29. Exercise 16 30. Exercise 17 31. Exercise 18

32. Exercise 19 33. Exercise 20 34. Exercise 21

35. Exercise 24 36. Exercise 25 37. Exercise 26

38. Exercise 27 39. Exercise 31 40. Exercise 32

41. Exercise 33 42. Exercise 34 43. Exercise 35

44. Exercise 36 45. Exercise 37 46. Exercise 38

47. Exercise 39

48. A simplified telephone switching system allows the follow- ing strings as legal telephone numbers: a. A string of seven digits in which neither of the first two

digits a 0 or a1 (a local call string). b. A 1 followed by a three-digit area code string (any digit

except 0 or 1 followed by a 0 or 1 followed by any digit) followed by a seven-digit local call string.

c. A 0 alone or followed by a three-digit area code string plus a seven-digit local call string. Design a finite-state automaton to recognize all the legal telephone numbers in (a), (b) and (c). Include an “error state” for invalid telephone numbers.

49. Write a computer algorithm that simulates the action of the finite-state automaton of exercise 2 by mimicking the action of the transition diagram.

50. Write a computer algorithm that simulates the action of the finite-state automaton of exercise 8 by repeated application of the next-state function.

51.H Let L be the language consisting of all strings of the form

ambn, where m and n are positive integers and m ≥ n. Show that there is no finite-state automaton that accepts L .

52. Let L be the language consisting of all strings of the form

ambn, where m and n are positive integers and m ≤ n. Show that there is no finite-state automaton that accepts L .

53.H Let L be the language consisting of all strings of the form

an, where n = m2, for some positive integer m. Show that there is no finite-state automaton that accepts L .

54. a. Let A be a finite-state automaton with input alphabet %, and suppose L(A) is the language accepted by A. The complement of L(A) is the set of all strings over % that are not in L(A). Show that the complement of a regular language is regular by proving the following: If L(A) is the language accepted by a finite-state automaton A,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

808 Chapter 12 Regular Expressions and Finite-State Automata

then there is a finite-state automaton A′ that accepts the complement of L(A).

b. Show that the intersection of any two regular languages is regular as follows: First prove that if L(A1) and L(A2) are languages accepted by automata A1 and A2,

respectively, then there is an automaton A that accepts (L(A1))c ∪ (L(A2))c. Then use one of De Morgan’s laws for sets, the double complement law for sets, and the result of part (a) to prove that there is an automaton that accepts L(A1) ∩ L(A2).

Answers for Test Yourself 1. a finite set of input symbols; a finite set of states; a designated initial state; a designated set of accepting states; a next-state function that associates a “next-state” with each state and input symbol of the automaton 2. the next-state function for each state and input symbol of the automaton 3. arrow; double circles 4. when the symbols in the string are input to the automaton in sequence from left to right, starting from the initial state, the automaton ends up in an accepting state 5. the set of strings that are accepted by A 6. the state to which A goes if it is in state s and the characters of w are input to it in sequence 7. a regular expression that defines the same language 8. a finite-state automaton that accepts the same language 9. a language defined by a regular expression (Or: a language accepted by a finite-state automaton) 10. not regular

12.3 Simplifying Finite-State Automata Our life is frittered away by detail. . . . Simplify, simplify. — Henry David Thoreau, Walden, 1854

Any string input to a finite-state automaton either sends the automaton to an accepting state or not, and the set of all strings accepted by an automaton is the language accepted by the automaton. It often happens that when an automaton is created to do a certain job (as in compiler construction, for example), the automaton that emerges “naturally” from the development process is unnecessarily complicated; that is, there may be an automaton with fewer states that accepts exactly the same language. It is desirable to find such an automaton because the memory space required to store an automaton with n states is approximately proportional to n2. Thus approximately 10,000 memory spaces are required to store an automaton with 100 states, whereas only about 100 memory spaces are needed to store an automaton with 10 states. In addition, the fewer states an automaton has, the easier it is to write a computer algorithm based on it; and to see that two automata both accept the same language, it is easiest to simplify each to a minimal number of states and compare the simplified automata. In this section we show how to take a given automaton and simplify it in the sense of finding an automaton with fewer states that accepts the same language.

Example 12.3.1 An Overview

Consider the finite-state automata A and A′ in Figure 12.3.1. A moment’s thought should convince you that A′ accepts all those strings, and only those strings, that contain an even number of 1’s. But A, although it appears more complicated, accepts exactly those

s1

00

00

1

1

1 1

A

0 0

1

1

A'

s0

s3 s2

s'0 s'1

Figure 12.3.1 Two Equivalent Automata

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 809

strings also. Thus the two automata are “equivalent” in the sense that they accept the same language, even though A′ has fewer states than A.

Roughly speaking, the reason for the equivalence of these automata is that some of the states of A can be combined without affecting the acceptance or nonacceptance of any input string. It turns out that s2 can be combined with state s0 and that s3 can be combined with state s1. (How to figure out which states can be combined is explained later in this section.) The automaton with the two combined states {s0, s2} and {s1, s3} is called the quotient automaton of A and is denoted A. Its transition diagram is obtained by combining the circles for s0 and s2 and for s1 and s3 and by replacing any arrow from a state s to a state t by an arrow from the combined state containing s to the combined state containing t . For instance, since there is an arrow labeled 1 from s1 to s2 in A, there is an arrow labeled 1 from {s1, s3} to {s0, s2} in A. The complete transition diagram for A is shown in Figure 12.3.2. As you can see, except for labeling the names of the states, it is identical to the diagram for A′.

0 0 1

1

{s0, s2} {s1, s3}

Figure 12.3.2 ■

In general, simplification of a finite-state automaton involves identifying “equiva- lent states” that can be combined without affecting the action of the automaton on input strings. Mathematically speaking, this means defining an equivalence relation on the set of states of the automaton and forming a new automaton whose states are the equivalence classes of the relation. The rest of this section is devoted to developing an algorithm to carry out this process in a practical way.

∗-Equivalence of States Two states of a finite-state automaton are said to be ∗-equivalent (this is read “star equiv- alent”) if any string accepted by the automaton when it starts from one of the states is accepted by the automaton when it starts from the other state. Recall that the value of the eventual-state function, N*, for a state s and input string w is the state to which the automaton goes if the characters of w are input in sequence when the automaton is in state s.

• Definition Let A be a finite-state automaton with next-state function N and eventual-state func- tion N*. Define a binary relation on the set of states of A as follows: Given any states s and t of A, we say that s and t are ∗-equivalent and write s R∗ t if, and only if, for all input strings w,

either both N*(s, w) and N*(t, w) are accepting states or both are nonaccepting states.

In other words, states s and t are ∗-equivalent if, and only if, for all input strings w, N*(s, w) is an accepting state ⇔ N*(t, w) is an accepting state.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

810 Chapter 12 Regular Expressions and Finite-State Automata

Or, more simply, for all input strings w, [

A goes to an accepting state if w is input when A is in state s

] ⇔ [

A goes to an accepting state if w is input when A is in state t

] .

It follows immediately, by substitution into the definition, that

R∗ is an equivalence relation on S, the set of states of A. 12.3.1

You are asked to prove this formally in the exercises at the end of this section.

k-Equivalence of States From a procedural point of view, it is difficult to determine the ∗-equivalence of two states using the definition directly. According to the definition, you must know the action of the automaton starting in states s and t on all input strings in order to tell whether s and t are equivalent. But since most languages have infinitely many input strings, you cannot check individually the effect of every string that is input to an automaton. As a practical matter, you can tell whether or not two states s and t are ∗-equivalent by using an iterative procedure based on a simpler kind of equivalence of states called k-equivalence. Two states are k-equivalent if any string of length less than or equal to k that is accepted by the automaton when it starts from one of the states is accepted by the automaton when it starts from the other state.

• Definition Let A be a finite-state automaton with next-state function N and eventual-state func- tion N*. Define a relation on the set of states of A as follows: Given any states s and t of A and an integer k ≥ 0, we say that s is k-equivalent to t and write s Rk t if, and only if, for all input strings w of length less than or equal to k, either N*(s, w) and N*(t, w) are both accepting states or they are both nonaccepting states.

Certain useful facts follow quickly from the definition of k-equivalence:

For each integer k ≥ 0, k-equivalence is an equivalence relation. 12.3.2 For each integer k ≥ 0, the k-equivalence classes partition the set of all states of the automaton into a union of mutually disjoint subsets. 12.3.3

For each integer k ≥ 1, if two states are k-equivalent, then they are also (k − 1) equivalent. 12.3.4 For each integer k ≥ 1, each k-equivalence class is a subset of a (k − 1)-equivalence class. 12.3.5 Any two states that are k-equivalent for all integers k ≥ 0 are ∗-equivalent. 12.3.6

Proofs of these facts are left for the exercises. The following theorem gives a recursive description of k-equivalence of states. It

says, first, that any two states are 0-equivalent if, and only if, either both are accepting states or both are nonaccepting states and, second, that any two states are k-equivalent

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 811

(for k ≥ 1) if, and only if, they are (k − 1)-equivalent and for any input symbols their next-states are also (k − 1)-equivalent.

Theorem 12.3.1

Let A be a finite-state automaton with next-state function N . Given any states s and t in A,

1. s is 0-equivalent to t ⇔ [

either s and t are both accepting states or they are both nonaccepting states

]

2. for every integer k ≥ 1, s is k-equivalent to t

⎣ s and t are (k − 1)-equivalent, and for any input symbol m, N (s, m) and N (t, m) are also (k − 1)-equivalent

⎦.

The truth of Theorem 12.3.1 follows from the fact that inputting a string w of length k has the same effect as inputting the first symbol of w and then the remaining k − 1 symbols of w. A detailed proof is somewhat technical.

Theorem 12.3.1 implies that if you know which states are (k − 1)-equivalent (where k is a positive integer) and if you know the action of the next-state function, then you can figure out which states are k-equivalent. Specifically, if s and t are (k − 1)-equivalent states whose next-states are (k − 1)-equivalent for any input symbol m, then s and t are k-equivalent. Thus the k-equivalence classes are obtained by subdividing the (k − 1)- equivalence classes according to the action of the next-state function on the members of the classes. An example should make this procedure clear.

Example 12.3.2 Finding k-Equivalence Classes

Find the 0-equivalence classes, the 1-equivalence classes, and the 2-equivalence classes for the states of the automaton shown below.

0

11 1

1

0 0 0

0

1

s2

s3

s1s0

s4

Solution

1. 0-equivalence classes: By Theorem 12.3.1 two states are 0-equivalent if, and only if, both are accepting states or both are nonaccepting states. Thus there are two sets of 0-equivalent states:

{s0, s1, s4} (the nonaccepting states) and {s2, s3} (the accepting states),

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

812 Chapter 12 Regular Expressions and Finite-State Automata

and so

the 0-equivalence classes are {s0, s1, s4} and {s2, s3}. 2. 1-equivalence classes: By Theorem 12.3.1, two states are 1-equivalent if, and only

if, they are 0-equivalent and, after input of any input symbol, their next-states are 0-equivalent. Thus s1 is not 1-equivalent to s0 because when a 0 is input to the automa- ton in state s1 it goes to state s2, whereas when a 0 is input to the automaton in state s0 it goes to state s0, and s2 and s0 are not 0-equivalent. On the other hand, s1 is 1-equivalent to s4 because when a 0 is input to the automaton in state s1 or s4 the next-states are s2 and s3, which are 0-equivalent; and when a 1 is input to the automaton in state s1 or s4 the next-states are s4 and s1, which are 0-equivalent. By a similar argument, s2 is 1-equivalent to s3. Since 1-equivalent states must also be 0-equivalent [by property (12.3.4)], no other pairs of states can be 1-equivalent. Hence

the 1-equivalence classes are {s0}, {s1, s4}, and {s2, s3}. 3. 2-equivalence classes: By Theorem 12.3.1, two states are 2-equivalent if, and only

if, they are 1-equivalent and, after input of any input symbol, their next-states are 1- equivalent. Now s1 is 2-equivalent to s4 because they are 1-equivalent; and when a 1 is input to the automaton in state s1 or s4 the next-states are s4 and s1, which are 1- equivalent; and when a 0 is input to the automaton in state s1 or s4 the next-states are s2 and s3, which are 1-equivalent. Similarly, s2 is 2-equivalent to s3. Since 2-equivalent states must also be 1-equivalent [by property (12.3.4)], no other pairs of states can be 2-equivalent. Hence

the 2-equivalence classes are {s0}, {s1, s4}, and {s2, s3}. Note that the set of 2-equivalence classes equals the set of 1-equivalence classes. ■

Finding the ∗-Equivalence Classes Example 12.3.2 illustrates the relative ease with which the sets of k-equivalence classes of states can be found. But to simplify a finite-state automaton, you need to find the set of ∗-equivalence classes of states. The next theorem says that for some integer K , the set of ∗-equivalence classes equals the set of K -equivalence classes.

Theorem 12.3.2

If A is a finite-state automaton, then for some integer, K ≥ 0, the set of K -equivalence classes of states of A equals the set of (K + 1)-equivalence classes of states of A, and for all such K these are both equal to the set of ∗-equivalence classes of states of A.

The detailed proof of Theorem 12.3.2 is somewhat technical, but the idea of the proof is not hard to understand. Theorem 12.3.2 follows from the fact that for each positive integer k, the k-equivalence classes are obtained by subdividing the (k − 1)-equivalence classes according to a certain rule that is the same for each k. Since the number of states of the automaton is finite, this subdivision process cannot continue forever, and so for some integer K ≥ 0, the set of K -equivalence classes equals the set of (K + 1)-equivalence classes. Moreover, the set of m-equivalence classes equals the set of K -equivalence classes for every integer m ≥ K . But this implies that the set of ∗-equivalence classes equals the set of K -equivalence classes.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 813

Example 12.3.3 Finding ∗-Equivalence Classes of R Let A be the finite-state automaton defined in Example 12.3.2. Find the ∗-equivalence classes of states of A.

Solution According to Example 12.3.2, the set of 1-equivalence classes for A equals the set of 2-equivalence classes. By Theorem 12.3.2, then, the set of ∗-equivalence classes also equals the set of 1-equivalence classes. Hence

the ∗-equivalence classes are {s0}, {s1, s4} and {s2, s3}. In the notation of Section 8.3, the equivalence classes are denoted

[s0] = {s0} [s1] = {s1, s4} = [s4] [s2] = {s2, s3} = [s3]. ■

The Quotient Automaton We next define the quotient automaton A of an automaton A. However, in order for all parts of the definition to make sense, we must point out two facts.

No ∗-equivalence class of states of A can contain both accepting and nonaccepting states.

12.3.7

The reason this is true is that the 0-equivalence classes divide the set of states of A into accepting and nonaccepting states, and the ∗-equivalence classes are subsets of 0-equivalence classes.

If two states are ∗-equivalent, then their next-states are also ∗-equivalent for any input symbol m. 12.3.8

This is true for the following reason. Suppose states s and t are ∗-equivalent. Then any input string that sends A to an accepting state when A is in state s sends A to an accepting state when A is in state t . Now suppose m is any input symbol, and consider the next- states N (s, m) and N (t, m). Inputting a string of length k to A when A is in state N (s, m) or N (t, m) produces the same effect as inputting a certain string of length k + 1 to A when A is in state s or t (namely the concatenation of m with the string of length k). Hence any string that sends A to an accepting state when A is in state N (s, m) also sends A to an accepting state when A is in state N (t, m). It follows that N (s, m) and N (t, m) are ∗-equivalent. Complete proofs of properties (12.3.7) and (12.3.8) are left to the exercises.

Now we can define the quotient automaton A of A. It is the finite-state automa- ton whose states are the ∗-equivalence classes of states of A, whose initial state is the ∗-equivalence class containing the initial state of A, whose accepting states are of the form [s] where s is an accepting state of A, whose input symbols are the same as the input symbols of A, and whose next-state function is derived from the next-state function for A in the following way: To find the next-state of A for a state s and an input symbol m, pick any state t in [s] and look to see what next-state A goes to if m is input when A is in state t ; the equivalence class of this state is the next-state of A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

814 Chapter 12 Regular Expressions and Finite-State Automata

• Definition Let A be a finite-state automaton with set of states S, set of input symbols I , and next-state function N . The quotient automaton A is defined as follows:

1. The set of states, S, of A is the set of ∗-equivalence classes of states of A. 2. The set of input symbols, I , of A equals I .

3. The initial state of A is [s0], where s0 is the initial state of A. 4. The accepting states of A are the states of the form [s], where s is an accepting

state of A.

5. The next-state function N : S × I → S is defined as follows: For all states [s] in S and input symbols m in I , N ([s], m) = [N (s, m)].

(That is, if m is input to A when A is in state [s], then A goes to the state that is the ∗-equivalence class of N (s, m).)

Note that since the states of A are sets of states of A, A generally has fewer states than A. (A and A have the same number of states only in the case where each ∗-equivalence class of states contains just one element.) Also, by property (12.3.7), each accepting state of A consists entirely of accepting states of A. Furthermore, property (12.3.8) guarantees that the next-state function N is well defined.

By construction, a quotient automaton A accepts exactly the same strings as A. We state this formally as Theorem 12.3.3. We leave the details to a more advanced course in automata theory.

Theorem 12.3.3

If A is a finite-state automaton, then the quotient automaton A accepts exactly the same languages as A. In other words, if L(A) denotes the language accepted by A and L(A) denotes the language accepted by A, then

L(A) = L(A).

Constructing the Quotient Automaton Let A be a finite-state automaton with set of states S, next-state function N , relation R∗ of ∗-equivalence of states, and relation Rk of k-equivalence of states. It follows from Theorems 12.3.2 and 12.3.3 and from the definition of quotient automaton that to find the quotient automaton A of A, you can proceed as follows:

1. Find the set of 0-equivalence classes of S.

2. For each integer k ≥ 1, subdivide the (k − 1)-equivalence classes of S (as described earlier) to find the k-equivalence classes of S. Stop subdividing when you observe that for some integer K the set of (K + 1)-equivalence classes equals the set of K -equivalence classes. At this point, conclude that the set of K -equivalence classes equals the set of ∗-equivalence classes.

3. Construct the quotient automaton A whose states are the ∗-equivalence classes of states of A and whose next-state function N is given by

N ([s], m) = [N (s, m)] for any state of A and any input symbol m,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 815

where s is any state in [s]. [That is, to see where A goes if m is input to A when it is in state s, look to see where A goes if m is input to A when it is in state s. The ∗-equivalence class of that state is the answer.]

Example 12.3.4 Constructing a Quotient Automaton

Consider the automaton A of Examples 12.3.2 and 12.3.3. This automaton is shown again below for reference. Find the quotient automaton of A.

0

11 1

1

0 0 0

0

1

s2

s3

s1s0

s4

Solution According to Example 12.3.3 the ∗-equivalence classes of the states of A are {s0}, {s1, s4}, and {s2, s3}.

Hence the states of the quotient automaton A are

[s0] = {s0}, [s1] = {s1, s4} = [s4], [s2] = {s2, s3} = [s3]. The accepting states of A are s2 and s3, so the accepting state of A is [s2] = [s3]. The next- state function N of A is defined as follows: for all states [s] and input symbols m of A,

N ([s], m) = [N (s, m)] = the ∗-equivalence class of N (s, m). Thus,

N ([s0], 0) = [N (s0, 0)] = the ∗-equivalence class of N (s0, 0). But N (s0, 0) = s0, so

N ([s0], 0) = the ∗-equivalence class of s0 = [s0]. Similarly,

N ([s0], 1) = [N (s0, 1)] = [s1] N ([s1], 0) = [N (s1, 0)] = [s2] N ([s1], 1) = [N (s1, 1)] = [s4] = [s1] N ([s2], 0) = [N (s2, 0)] = [s3] = [s2] N ([s2], 1) = [N (s2, 1)] = [s4] = [s1].

The transition diagram for A is, therefore, as shown below.

0 1 0

1 0

1 [s0] [s1] [s2]

By Theorem 12.3.3, this automaton accepts the same language as the original automaton. ■

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

816 Chapter 12 Regular Expressions and Finite-State Automata

Equivalent Automata Output devices may be attached to the states of finite-state automata to indicate whether they are accepting or nonaccepting states. For example, accepting states might produce an output of 1 and nonaccepting states an output of 0. Then a finite-state automaton can be thought of as an input/output device whose input consists of strings and whose out- put consists of 0’s and 1’s. Recall that a circuit can be thought of as a black box that transforms combinations of input signals into output signals. Two circuits that produce identical output signals for each combination of input signals are called equivalent. Sim- ilarly, a finite-state automaton can be regarded as a black box that processes input strings and produces output signals (indicating whether or not the strings are accepted). Two finite-state automata are called equivalent if they produce identical output signals for each input string. But this means that two finite-state automata are equivalent if, and only if, they accept the same language.

• Definition Let A and A′ be finite-state automata with the same set of input symbols I . Let L(A) denote the language accepted by A and L(A′) the language accepted by A′. Then A is said to be equivalent to A′ if, and only if, L(A) = L(A′).

Example 12.3.5 Showing That Two Automata Are Equivalent

Show that the automata A and A′ that follow are equivalent.

1

1

0 1

1

0

0

0 1

1

0

10

A

A'

0

0, 1

s0 s1

s3

s2

s'0 s'2

s'3

s'1

The label 0, 1 on an arrow of a transition

diagram means that for either input 0 or

1, the next-state of the automaton is the

state to which the arrow points.

Solution

For the automaton A: The 0-equivalence classes are

{s0, s1} and {s2, s3} since s0 and s1 are accepting states and s2 and s3 are nonaccepting states.

The 1-equivalence classes are

{s0}, {s1}, and {s2, s3}

since s0 and s1 are not 1-equivalent (because N (s0, 1) = s1, whereas N (s1, 1) = s3 and s1 is not 0-equivalent to s3) but s2 and s3 are 1-equivalent.

The 2-equivalence classes are

{s0}, {s1}, and {s2, s3} since s2 and s3 are 1-equivalent.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 817

This discussion shows that the set of 1-equivalence classes equals the set of 2-equivalence classes, so by Theorem 12.3.2 this is equal to the set of ∗-equivalence classes. Hence the ∗-equivalence classes are

{s0}, {s1}, and {s2, s3}. For the automaton A′: By reasoning similar to that done previously, the 0-equivalence classes are

{ s ′0, s

′ 2, s

′ 3

} and { s ′1 } .

The 1-equivalence classes are { s ′0, s

′ 3

} , { s ′2 } , and

{ s ′1 } .

The 2-equivalence classes are the same as the 1-equivalence classes, which are therefore equal to the ∗-equivalence classes. Thus the ∗-equivalence classes are

{ s ′0, s

′ 3

} { s ′2 } , and

{ s ′1 } .

To calculate the next-state functions for A and A′, you repeatedly use the fact that in the quotient automaton, the next-state of [s] and m is the class of the next-state of s and m. For instance,

N ([s1], 1) = [N (s1, 1)] = [s3] = [s2] and N ′

([ s ′0 ] , 0 )

= [ N ′ ( s ′0, 0 )]

= [ s ′3 ]

= [ s ′0 ]

where N is the next-state function for A and N ′ is the next-state function for A′. The complete transition diagrams for the quotient automata A and A′ are shown

below.

0

1

1 0 0, 1 0

1

1 0 0, 1

A A'

[s0] [s1]

[s2]

[s'0 ] [s'2]

[s'1]

As you can see, except for the labeling of the names of the states, A and A′ are identical and hence accept the same language. But by Theorem 12.3.3, each original automaton accepts the same language as its quotient automaton. Thus A and A′ accept the same language, and so they are equivalent. ■

In mathematics an object such as a finite-state automaton is called a structure. In general, when two mathematical structures are the same in all respects except for the labeling given to their elements, they are called isomorphic, which comes from the Greek words isos, meaning “same” or “equal,” and morphe, meaning “from.” It can be shown that two automata are equivalent if, and only if, their quotient automata are isomorphic, provided that “inaccessible states” have first been removed. (Inaccessible states are those that cannot be reached by inputting any string of symbols to the automaton when it is in its initial state.)

Test Yourself 1. Given a finite-state automaton A with eventual-state func-

tion N ∗ and given any states s and t in A, we say that s and t are ∗-equivalent if, and only if, _____.

2. Given a finite-state automaton A with eventual-state func- tion N ∗ and given any states s and t in A, we say that s and t are k-equivalent if, and only if, _____.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

818 Chapter 12 Regular Expressions and Finite-State Automata

3. Given states s and t in a finite-state automaton A, s is 0-equivalent to t if, and only if, either both s and t are _____ or both are _____. Moreover, for every integer k ≥ 1, s is k-equivalent to t if, and only if, (1) s and t are (k − 1)- equivalent and (2) _____.

4. If A is a finite-state automaton, then for some integer K ≥ 0, the set of K -equivalence classes of states of A equals the set of _____-equivalence classes of A, and for all such K these are both equal to the set of _____.

5. Given a finite-state automaton A, the set of states of the quo- tient automaton A is _____.

Exercise Set 12.3 1. Consider the finite-state automaton A given by the follow-

ing transition diagram:

0 0 0 01 1

1 0

1 0

1

1

s0 s2s1

s3 s5s4

a. Find the 0-, 1-, and 2-equivalence classes of states of A. b. Draw the transition diagram for A, the quotient automa-

ton of A.

2. Consider the finite-state automaton A given by the follow- ing transition diagram:

1

1

1

0

0

0

0 0 0

0

1

1

1

1

s0 s3 s4

s5

s2

s6

s1

a. Find the 0-, 1-, and 2-equivalence classes of states of A. b. Draw the transition diagram for A, the quotient automa-

ton of A.

3. Consider the finite-state automaton A discussed in Example 12.3.1:

0 0

00

1

1

1 1

s0

s2

s1

s3

a. Find the 0- and 1-equivalence classes of states of A. b. Draw the transition diagram of A, the quotient automa-

ton of A.

4. Consider the finite-state automaton given by the following transition diagram:

11 0

1

1

1

0

1 0

0 0

0s0 s2

s1

s5 s3

s4

a. Find the 0-,1-, 2-, and 3-equivalence classes of states of A.

b. Draw the transition diagram for A, the quotient automa- ton of A.

5. Consider the finite-state automaton given by the following transition diagram:

0

0

10

0

0

1

1

01

1

1

s1 s2

s5s4

s3

s0

a. Find the 0-, 1-, 2-, and 3-equivalence classes of states of A.

b. Draw the transition diagram for A, the quotient automa- ton of A.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

12.3 Simplifying Finite-State Automata 819

6. Consider the finite-state automaton given by the following transition diagram:

0

1 1

0

0 1

0

0 1 1

0

0

1

1

s0 s1 s3 s5

s6s4s2

a.H Find the 0-, 1-, 2-, and 3-equivalence classes of states of A. b. Draw the transition diagram for A, the quotient automaton of A.

7. Are the automata A and A′ shown below equivalent?

1

A A'

0

1

1 0

0 0 1

s'1

0

1

1

0

0 0 1 1 s0 s1

s3

s2 s'0

s'3 s'2

8. Are the automata A and A′ shown below equivalent?

1

1

0

11

1

0 0

0

0

A

A'

0

0

1

1 0

0

1

1

0

1

s0 s'0 s'2

s'3

s'1

s1

s2

s4

s'4

s3

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

820 Chapter 12 Regular Expressions and Finite-State Automata

9. Are the automata A and A′ shown below equivalent?

0

0 1

1

1 1

1 1

11

0

0

1 0 0

A A'

0

0

0 0

1

1

1

0

0

s4

s2

s1

s0 s'0

s'1s'4

s'2

s'5 s'3

s3

s5

10. Are the automata A and A′ shown below equivalent?

0

0

1

1

11

1 0

1

1 010

0

1

A

A'

0

0

0

0, 1

s0

s4

s1

s3

s2

s'4

s'2s '0 s'1

s'3

11.H Prove property (12.3.1).

12. How should the proof of property (12.3.1) be modified to prove property (12.3.2)?

13. Prove property (12.3.3). 14. Prove property (12.3.4).

15.H Prove property (12.3.5). 16. Prove property (12.3.6).

17.H Prove that if two states of a finite-state automaton are k-equivalent for some integer k, then those states are m-equivalent for all nonnegative integers m < k.

18. Write a complete proof of property (12.3.7).

19.H Write a complete proof of property (12.3.8).

Answers for Test Yourself 1. for all input strings w, either N ∗(s, w) and N ∗(t, w) are both accepting states or both are nonaccepting states 2. for all input strings w of length less than or equal to k, either N ∗(s, w) and N ∗(t, w) are both accepting states or both are nonaccepting states 3. accepting states; nonaccepting states; for any input symbol m, N (s, m) and N (t, m) are also (k − 1)-equivalent 4. (K + 1); ∗-equivalence classes of states of A 5. the set of ∗-equivalence classes of states of A

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-1

APPENDIX A

PROPERTIES OF THE REAL NUMBERS∗

In this text we take the real numbers and their basic properties as our starting point. We give a core set of properties, called axioms, which the real numbers are assumed to satisfy, and we state some useful properties that can be deduced from these axioms.

We assume that there are two binary operations defined on the set of real numbers, called addition and multiplication, such that if a and b are any two real numbers, the sum of a and b, denoted a + b, and the product of a and b, denoted a ·b or ab, are also real numbers. These operations satisfy properties F1–F6, which are called the field axioms.

F1. Commutative Laws For all real numbers a and b,

a + b = b + a and ab = ba. F2. Associative Laws For all real numbers a, b, and c,

(a + b) + c = a + (b + c) and (ab)c = a(bc). F3. Distributive Laws For all real numbers a, b, and c,

a(b + c) = ab + ac and (b + c)a = ba + ca. F4. Existence of Identity Elements There exist two distinct real numbers, denoted 0

and 1, such that for every real number a,

0 + a = a + 0 = a and 1 ·a = a ·1 = a. F5. Existence of Additive Inverses For every real number a, there is a real number,

denoted −a and called the additive inverse of a, such that a + (−a) = (−a) + a = 0.

F6. Existence of Reciprocals For every real number a ̸= 0, there is a real number, denoted 1/a or a−1, called the reciprocal of a, such that

a · (

1 a

) = (

1 a

) ·a = 1.

All the usual algebraic properties of the real numbers that do not involve order can be derived from the field axioms. The most important are collected as theorems T1–T16 as follows. In all these theorems the symbols a, b, c, and d represent arbitrary real numbers.

∗Adapted from Tom M. Apostol, Calculus, Volume I (New York: Blaisdell, 1961), pp. 13–19.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-2 Appendix A Properties of the Real Numbers

T1. Cancellation Law for Addition If a + b = a + c, then b = c. (In particular, this shows that the number 0 of Axiom F4 is unique.)

T2. Possibility of Subtraction Given a and b, there is exactly one x such that a + x = b. This x is denoted by b − a. In particular, 0− a is the additive inverse of a,−a.

T3. b − a = b + (−a). T4. −(−a) = a. T5. a(b − c) = ab − ac. T6. 0 ·a = a ·0 = 0. T7. Cancellation Law for Multiplication If ab = ac and a ̸= 0, then b = c. (In par-

ticular, this shows that the number 1 of Axiom F4 is unique.)

T8. Possibility of Division Given a and b with a ̸= 0, there is exactly one x such that ax = b. This x is denoted by b/a and is called the quotient of b and a. In particular, 1/a is the reciprocal of a.

T9. If a ̸= 0, then b/a = b ·a−1. T10. If a ̸= 0, then (a−1)−1 = a. T11. Zero Product Property If ab = 0, then a = 0 or b = 0. T12. Rule for Multiplication with Negative Signs

(−a)b = a(−b) = −(ab), (−a)(−b) = ab,

and

−a b

= −a b

= a−b .

T13. Equivalent Fractions Property

a b

= ac bc

, if b ̸= 0 and c ̸= 0.

T14. Rule for Addition of Fractions

a b

+ c d

= ad + bc bd

, if b ̸= 0 and d ̸= 0.

T15. Rule for Multiplication of Fractions

a b

· c d

= ac bd

, if b ̸= 0 and d ̸= 0.

T16. Rule for Division of Fractions

a b c d

= ad bc

, if b ̸= 0, c ̸= 0, and d ̸= 0.

The real numbers also satisfy the following axioms, called the order axioms. It is assumed that among all real numbers there are certain ones, called the positive real numbers, that satisfy properties Ord1–Ord3.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

Appendix A Properties of the Real Numbers A-3

Ord1. For any real numbers a and b, if a and b are positive, so are a + b and ab. Ord2. For every real number a ̸= 0, either a is positive or −a is positive but not both. Ord3. The number 0 is not positive.

The symbols <,>,≤, and ≥, and negative numbers are defined in terms of positive numbers.

• Definition Given real numbers a and b,

a < b means b + (−a) is positive. b > a means a < b. a ≤ b means a < b or a = b. b ≥ a means a ≤ b. If a < 0, we say that a is negative. If a ≥ 0, we say that a is nonnegative.

From the order axioms Ord1–Ord3 and the above definition, all the usual rules for cal- culating with inequalities can be derived. The most important are collected as theorems T17–T27 as follows. In all these theorems the symbols a, b, c, and d represent arbitrary real numbers.

T17. Trichotomy Law For arbitrary real numbers a and b, exactly one of the three rela- tions a < b, b < a, or a = b holds.

T18. Transitive Law If a < b and b < c, then a < c.

T19. If a < b, then a + c < b + c. T20. If a < b and c > 0, then ac < bc.

T21. If a ̸= 0, then a2 > 0. T22. 1 > 0.

T23. If a < b and c < 0, then ac > bc.

T24. If a < b, then −a > −b. In particular, if a < 0, then −a > 0. T25. If ab > 0, then both a and b are positive or both are negative.

T26. If a < c and b < d , then a + b < c + d . T27. If 0 < a < c and 0 < b < d, then 0 < ab < cd.

One final axiom distinguishes the set of real numbers from the set of rational numbers. It is called the least upper bound axiom.

LUB. Any nonempty set S of real numbers that is bounded above has a least upper bound. That is, if B is the set of all real numbers x such that x ≥ s for all s in S and if B has at least one element, then B has a smallest element. This element is called the least upper bound of S.

The least upper bound axiom holds for the set of real numbers but not for the set of rational numbers. For example, the set of all rational numbers that are less than

√ 2 has

upper bounds but not a least upper bound within the set of rational numbers.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-4

APPENDIX B

SOLUTIONS AND HINTS TO SELECTED EXERCISES

Section 1.1 1. a. x2 = −1 (Or: the square of x is −1)

b. A real number x 3. a. Between a and b

b. Real numbers a and b; there is a real number c 5. a. r is positive

b. Positive; the reciprocal of r is positive (Or: positive; 1/r is positive)

c. Is positive; 1/r is positive (Or: is positive; the reciprocal of r is positive)

7. a. There are real numbers whose sum is less than their dif- ference. True. For example, 1 + (−1)= 0, 1− (−1)= 1 + 1 = 2, and 0 < 2.

c. The square of any positive integer is greater than the integer. True. If n is any positive integer, then n ≥ 1. Multiply- ing both sides by the positive number n does not change the direction of the inequality (see Appendix A, T20), and so n2 ≥ n.

8. a. Have four sides b. Has four sides c. Has four sides d. Is a square; J has four sides e. J has four sides

10. a. Have a reciprocal b. A reciprocal c. s is a reciprocal for r

12. a. Real number; product with every number leaves the number unchanged

b. With every number leaves the number unchanged c. rs = s

Section 1.2 1. A = C and B = D 2. a. The set of all positive real numbers x such that 0 is less

than x and x is less than 1 c. The set of all integers n such that n is a factor of 6

3. a. No, {4} is a set with one element, namely 4, whereas 4 is just a symbol that represents the number 4

b. Three: the elements of the set are 3, 4, and 5. c. Three: the elements are the symbol 1, the set {1}, and

the set {1,{1}} 5. Hint: R is the set of all real numbers, Z is the set of all

integers, and Z+ is the set of all positive integers 6. Hint: T0 and T1 do not have the same number of elements

as T2 and T−3. 7. a. {1,−1}

c. ∅ (the set has no elements) d. Z (every integer is in the set)

8. a. No, B ! A :. j ∈ B and j ∉A d. Yes, C is a proper subset of A. Both elements of C are

in A, but A contains elements (namely c and f ) that are not in C .

9. a. Yes b. No f. No i. Yes

10. a. No. Observe that (−2)2 = (−2)(−2) = 4 whereas −22 = −(22) = −4. So ((−2)2,−22) = (4,−4), (−22, (−2)2) = (−4, 4), and (4,−4) ̸= (−4, 4) because −4 ̸= 4.

c. Yes. Note that 8− 9 = −1 and 3 √ −1 = −1, and so

(8− 9, 3 √ −1) = (−1,−1).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Solutions and Hints to Selected Exercises A-5

11. a. {(w, a), (w, b), (x, a), (x, b), (y, a), (y, b), (z, a), (z, b)}

b. {(a, w), (b, w), (a, x), (b, x), (a, y), (b, y), (a, z), (b, z)}

c. {(w,w), (w, x), (w, y), (w, z), (x, w), (x, x), (x, y), (x, z), (y, w), (y, x), (y, y), (y, z), (z, w), (z, x), (z, y), (z, z)}

d. {(a, a), (a, b), (b, a), (b, b)}

Section 1.3 1. a. No. Yes. No. Yes.

b. R = {(2, 6), (2, 8), (2, 10), (3, 6), (4, 8)} c. Domain of R = A = {2, 3, 4}, co-domain of R = B =

{6, 8, 10} d. R

6

8

10

2

3

4

3. a. 3 T 0 because 3−03 = 3 3 = 1, which is an integer.

1 T/ (−1) because 1−(−1)3 = 2 3 , which is not an integer.

(2,−1) ∈ T because 2−(−1)3 = 3 3 = 1, which is an

integer.

(3,−2) ∉ T because 3−(−2)3 = 5 3 , which is not an

integer. b. T = {(1,−2), (2,−1), (3, 0)} c. Domain of T = E = {1, 2, 3}, co-domain of T = F =

{−2,−1, 0} d. T

–2

–1

0

1

2

3

5. a. (2, 1) ∈ S because 2 ≥ 1. (2, 2) ∈ S because 2 ≥ 2. 2 S/ 3 because 2 ̸ ≥3. (−1) S/ (−2) because (−1) ≱(−2).

b.

x 1

x ≥ y in shaded region graph of S

7. a. R 5

6

7

4

5

6

A B

4 5 6

5 6 7

S TA B

4 5 6

5 6 7

b. R is not a function because it satisfies neither property (1) nor property (2) of the definition. It fails property (1) because (4, y) ∉ R, for any y in B. It fails property (2) because (6, 5) ∈ R and (6, 6) ∈ R and 5 ̸= 6.

S is not a function because (5, 5) ∈ S and (5, 7) ∈ S and 5 ̸= 7. So S does not satisfy property (2) of the def- inition of function.

T is not a function both because (5, x) ∉ T for any x in B and because (6, 5) ∈ T and (6, 7) ∈ T and 5 ̸= 7. So T does not satisfy either property (1) or property (2) of the definition of function.

9. a. ∅, {(0, 1)}, {(1, 1)}, {(0, 1), (1, 1)} b. {(0, 1), (1, 1)} c. 1/4

11. No, P is not a function because, for example, (4, 2) ∈ P and (4,−2) ∈ P but 2 ̸= −2.

13. a. Domain = A = {−1, 0, 1}, co-domain = B = {t, u, v, w} b. F(−1) = u, F(0) = w, F(1) = u

15. a. This diagram does not determine a function because 2 is related to both 2 and 6.

b. This diagram does not determine a function because 5 is in the domain but it is not related to any element in the co-domain.

16. f (−1) = (−1)2 = 1, f (0) = 02 = 0, f (

1 2

) = (

1 2

)2 = 14 . 19. For all x ∈ R, g(x) = 2x

3+2x x2+1 =

2x(x2+1) x2+1 = 2x = f (x).

Therefore, by definition of equality of functions, f = g.

Section 2.1 1. Common form: If p then q.

p. Therefore, q.

(a + 2b)(a2 − b) can be written in prefix notation. All algebraic expressions can be written in prefix notation.

3. Common form: p ∨ q . ∼p. Therefore, q.

My mind is shot. Logic is confusing. 5. a. It is a statement because it is a true sentence. 1,024

is a perfect square because 1,024 = 322, and the next smaller perfect square is 312 = 961, which has less than four digits.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-6 Appendix B Solutions and Hints to Selected Exercises

6. a. s ∧ i b. ∼s ∧ ∼i 8. a. (h ∧ w) ∧ ∼s d. (∼w ∧ ∼s) ∧ h

10. a. p ∧ q ∧ r c. p ∧ (∼q ∨ ∼r) 11. Inclusive or. For instance, a team could win the playoff by

winning games 1, 3, and 4 and losing game 2. Such an out- come would satisfy both conditions.

12. p q ∼p ∼p ∧ q T T F F

T F F F

F T T T

F F T F

14. p q r q ∧ r p ∧ (q ∧ r) T T T T T

T T F F F

T F T F F

T F F F F

F T T T F

F T F F F

F F T F F

F F F F F

16. p q p ∧ q p ∨ ( p ∧ q) p T T T T T

T F F T T

F T F F F

F F F F F

↑ ↑ p ∨ (p ∧ q) and p always have the same truth values, so they are logically equivalent. (This proves one of the absorption laws.)

18. p t p ∨ t T T T

F T T

↑ ↑ p ∨ t and t always have the same truth values, so they are logically equivalent. (This proves one of the universal bound laws.)

21. p q r p ∧ q q ∧ r ( p ∧ q) ∧ r p ∧ (q ∧ r) T T T T T T T

T T F T F F F

T F T F F F F

T F F F F F F

F T T F T F F

F T F F F F F

F F T F F F F

F F F F F F F

↑ ↑ (p∧ q)∧ r and p∧ (q ∧ r) always have the same truth values, so they are logically equivalent. (This proves the associative law for∧.)

23. p q r p ∧ q q ∨ r ( p ∧ q) ∨ r p ∧ (q ∨ r) T T T T T T T

T T F T T T T

T F T F T T T

T F F F F F F

F T T F T T F

F T F F T F F

F F T F T T F

F F F F F F F

↑ ↑ (p ∧ q) ∨ r and p ∧ (q ∨ r) have different truth values in the fifth and seventh rows, so they are not logically equivalent. (This proves that parentheses are needed with∧ and∨.)

25. Hal is not a math major or Hal’s sister is not a computer science major.

27. The connector is not loose and the machine is not unplugged.

32. −2 ≥ x or x ≥ 7 34. 2 ≤ x ≤ 5 36. 1 ≤ x or x < −3 38. This statement’s logical form is (p ∧ q) ∨ r , so its

negation has the form∼((p ∧ q) ∨ r) ≡∼(p ∧ q) ∧ ∼r ≡ (∼p ∨ ∼q) ∧ ∼r . Thus a negation for the statement is (num−orders ≤ 100 or num−instock > 500) and num−instock ≥ 200.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.1 Solutions and Hints to Selected Exercises A-7

40. p q ∼p ∼q p ∧ q p ∧ ∼q ∼p ∨ ( p ∧ ∼q) ( p ∧ q) ∨ (∼p ∨ ( p ∧ ∼q)) T T F F T F F T

T F F T F T T T

F T T F F F T T

F F T T F F T T ↑

Its truth values are all T’s, so (p ∧ q) ∨ (∼p ∨ (p∧ ∼q)) is a tautology.

41. p q ∼p ∼q p ∧ ∼q ∼p ∨ q ( p ∧ ∼q) ∧ (∼p ∨ q) T T F F F T F

T F F T T F F

F T T F F T F

F F T T F T F ↑

Its truth values are all F’s, so (p ∧ ∼q) ∧ (∼p ∨ q) is a contradiction.

44. Let p be ‘x < 2’, q be ‘1 < x’, and r be ‘x < 3’. Then the sentences in (a) and (b) are symbolized as p ∨ ∼(q ∧ r) and ∼q ∨ (p ∨ ∼r), respectively.

p q r ∼q ∼r q ∧ r ∼(q ∧ r) p ∨ ∼r p ∨ ∼(q ∧ r) ∼q ∨ ( p ∨ ∼r) T T T F F T F T T T T T F F T F T T T T T F T T F F T T T T T F F T T F T T T T F T T F F T F F F F F T F F T F T T T T F F T T F F T F T T F F F T T F T T T T

↑ ↑ The statement forms p ∨ ∼(q ∧ r) and ∼q ∨ (p ∨ ∼r) always have the same truth values, so they are logically equivalent.

Therefore the statements in (a) and (b) are logically equivalent.

46. a. Solution 1: Construct a truth table for p ⊕ p using the truth values for exclusive or.

p p ⊕ p T F

F F

because an exclusive or statement is false when both components are true and when both components are false.

Since all its truth values are false, p ⊕ p ≡ c, a contra- diction. Solution 2: Replace q by p in the logical equivalence p ⊕ q ≡ (p ∨ q)∧ ∼(p ∧ q), and simplify the result. p ⊕ p ≡ (p ∨ q) ∧ ∼(p ∧ p) by defintion of ⊕

≡ p ∧ ∼p by the identity laws ≡ c by the negation law for ∧

47. There is a famous story about a philosopher who once gave a talk in which he observed that whereas in English and many other languages a double negative is equiva- lent to a positive, there is no language in which a dou- ble positive is equivalent to a negative. To this, another philosopher, Sidney Morgenbesser, responded sarcastically, “Yeah, yeah.”

[Strictly speaking, sarcasm functions like negation. When spoken sarcastically, the words “Yeah, yeah” are not a true double positive; they just mean “no.”]

48. a. The distributive law b. The commutative law for ∨ c. The negation law for ∨ d. The identity law for ∧

50. (p∧ ∼q) ∨ p ≡ p ∨ (p∧ ∼q) by the commutative law for ∨

≡ p by the absorption law (with ∼q in place of q)

53. ∼((∼p ∧ q) ∨ (∼p ∧ ∼q)) ∨ (p ∧ q) ≡∼[∼p ∧ (q ∨ ∼q)] ∨ (p ∧ q) by the distributive law ≡∼(∼p ∧ t) ∨ (p ∧ q) by the negation law for ∨ ≡∼(∼p) ∨ (p ∧ q) by the identity law for ∧ ≡ p ∨ (p ∧ q) by the double negative law ≡ p by the absorption law

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-8 Appendix B Solutions and Hints to Selected Exercises

Section 2.2 1. If this loop does not contain a stop or a go to, then it will

repeat exactly N times. 3. If you do not freeze, then I’ll shoot. 5. conclusion︷ ︸︸ ︷ hypothesis︷ ︸︸ ︷

p q ∼p ∼q ∼p ∨ q ∼p ∨ q → ∼q T T F F T F

T F F T F T

F T T F T F

F F T T T T

7. conclusion︷ ︸︸ ︷ hypothesis︷ ︸︸ ︷

p q r ∼q p ∧ ∼q p ∧ ∼q → r T T T F F T

T T F F F T

T F T T T T

T F F T T F

F T T F F T

F T F F F T

F F T T F T

F F F T F T

9. p q r ∼r p ∧ ∼r q ∨ r p ∧ ∼r ↔ q ∨ r T T T F F T F

T T F T T T T

T F T F F T F

T F F T T F F

F T T F F T F

F T F T F T F

F F T F F T F

F F F T F F T

12. If x > 2 then x2 > 4, and if x < −2 then x2 > 4. 13. a. 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

↑ ↑ p → q and∼p ∨ q always have the same truth values, so they are logically equivalent.

14. a. Hint: p → q ∨ r is true in all cases except when p is true and both q and r are false.

16. Let p represent “You paid full price” and q represent “You didn’t buy it at Crown Books.” Thus, “If you paid full price, you didn’t buy it at Crown Books” has the form p → q. And “You didn’t buy it at Crown Books or you paid full price” has the form q ∨ p.

p q p → q q ∨ p T T T T

T F F T

F T T T

F F T F

These two statements are not logically equivalent because their forms have different truth values in rows 2 and 4.

(An alternative representation for the forms of the two statements is p →∼q and ∼q ∨ p. In this case, the truth values differ in rows 1 and 3.)

19. False. The negation of an if-then statement is not an if-then statement. It is an and statement.

20. a. P is a square and P is not a rectangle. d. n is prime and both n is not odd and n is not 2.

Or: n is prime and n is neither odd nor 2. f. Tom is Ann’s father and either Jim is not her uncle or

Sue is not her aunt. 21. a. Because p → q is false, p is true and q is false. Hence

∼p is false, and so ∼p → q is true. 22. a. If P is not a rectangle, then P is not a square.

d. If n is not odd and n is not 2, then n is not prime. f. If either Jim is not Ann’s uncle or Sue is not her aunt,

then Tom is not her father. 23. a. Converse: If P is a rectangle, then P is a square.

Inverse: If P is not a square, then P is not a rectangle. d. Converse: If n is odd or n is 2, then n is prime.

Inverse: If n is not prime, then n is not odd and n is not 2.

f. Converse: If Jim is Ann’s uncle and Sue is her aunt, then Tom is her father.

Inverse: If Tom is not Ann’s father, then Jim is not her uncle or Sue is not her aunt.

24. p q p → q q → p T T T T

T F F T

F T T F

F F T T

↑ ↑ p → q and q → p have different truth values in the second and third rows, so they are not logically equivalent.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.2 Solutions and Hints to Selected Exercises A-9

26. p q ∼q ∼p ∼q → ∼p p → q T T F F T T

T F T F F F

F T F T T T

F F T T T T ↑ ↑

∼q →∼p and p → q always have the same truth values, so they are logically equivalent.

28. Hint: A person who says “I mean what I say” claims to speak sincerely. A person who says “I say what I mean” claims to speak with precision.

29. (p → (q ∨ r))↔ ((p∧ ∼q)→ r)

p q r ∼q q ∨ r p ∧ ∼q p → (q ∨ r) p ∧ ∼q → r ( p → (q ∨ r)) ↔ (( p ∧ ∼q) → r) T T T F T F T T T

T T F F T F T T T

T F T T T T T T T

T F F T F T F F T

F T T F T F T T T

F T F F T F T T T

F F T T T F T T T

F F F T F F T T T

↑ (p → (q ∨ r)) ↔ ((p∧ ∼q)→ r) is a tautology because all of its truth values are T.

32. If this quadratic equation has two distinct real roots, then its discriminant is greater than zero, and if the discriminant of this quadratic equation is greater than zero, then the equa- tion has two real roots.

34. If the Cubs do not win tomorrow’s game, then they will not win the pennant. If the Cubs win the pennant, then they will have won tomor- row’s game.

37. If a new hearing is not granted, payment will be made on the fifth.

40. If I catch the 8:05 bus, then I am on time for work. 42. If this number is not divisible by 3, then it is not divisible

by 9. If this number is divisible by 9, then it is divisible by 3.

44. If Jon’s team wins the rest of its games, then it will win the championship.

46. a. This statement is the converse of the given statement, and so it is not necessarily true. For instance, if the actual boiling point of compound X were 200◦C, then the given statement would be true but this statement would be false.

b. This statement must be true. It is the contrapositive of the given statement.

47. a. p ∧ ∼q → r ≡ ∼(p ∧ ∼q) ∨ r b. Result of (a) ≡∼[∼(∼(p∧ ∼q))∧ ∼r ]

an acceptable answer

≡∼[(p∧ ∼q)∧ ∼r ] by the double negative law (another acceptable answer)

49. a. (p → r)↔ (q → r) ≡ (∼p ∨ r)↔ (∼q ∨ r) ≡∼(∼p ∨ r) ∨ (∼q ∨ r)] ∧ [∼(∼q ∨ r) ∨ (∼p ∨ r)]

an acceptable answer

≡ [(p∧ ∼r) ∨ (∼q ∨ r)] ∧ [(q ∧ ∼r) ∨ (∼p ∨ r)] by De Morgan’s law (another acceptable answer)

b. Result of (a) ≡∼[∼(p∧ ∼r)∧ ∼(∼q ∨ r)]∧ ∼[∼(q ∧ ∼r)∧ ∼(∼p ∨ r)]

by De Morgan’s law

≡∼[∼(p∧ ∼r) ∧ (q ∧ ∼r)]∧ ∼[∼(q ∧ ∼r) ∧ (p∧ ∼r)]

by De Morgan’s law

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-10 Appendix B Solutions and Hints to Selected Exercises

Section 2.3 1. √

2 is not rational. 3. Logic is not easy. 6. premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q p → q q → p p ∨ q T T T T T

T F F T

F T T F

F F T T F ← This row shows that it is possible for an argument of this form to have true premises and a false conclusion. Thus this argument form is invalid.

7. premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q r ∼q p p → q ∼q ∨ r r T T T F T T T T

T T F F T T F

T F T T T F T

This row describes the only situation in which all the premises are true. Because the conclusion is also true here, the argument form is valid.

T F F T T F T

F T T F F T T

F T F F F T F

F F T T F T T

F F F T F T T

8. premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q r ∼q p ∨ q p → ∼q p → r r T T T F T F T

T T F F T F F

T F T T T T T T

T F F T T T F

F T T F T T T T

This row shows that it is possible for an argument of this form to have true premises and a false conclusion. Thus this argument form is invalid.

F T F F T T T F

F F T T F T T

F F F T F T T

12. a. premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q p → q q p T T T T T

T F F F

F T T T F ←

This row shows that it is possible for an argument of this form to have true premises and a false conclusion. Thus this argument form is invalid.

F F T F

14. premise︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q p p ∨ q T T T T

T F T T

F T F

← ←

These two rows show that in all situations where the premise is true, the conclusion is also true. Thus the argument form is valid.

F F F

18. premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q p ∨ q ∼q p T T T F

T F T T T ←

This row represents the only situation in which both premises are true. Because the conclusion is also true here the argument form is valid.

F T T F

F F F T

22. Let p represent “Tom is on team A” and q represent “Hua is on team B.” Then the argument has the form

∼p → q ∼q → p

∴ ∼p∨ ∼q

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.3 Solutions and Hints to Selected Exercises A-11

premises︷ ︸︸ ︷ conclusion︷ ︸︸ ︷

p q ∼p ∼q ∼p → q ∼q → p ∼p ∨ ∼q T T F F T T F

T F F T T T T

This row shows that it is possible for an argument of this form to have true premises and a false con- clusion. Thus this argument form is invalid.

F T T F T T T

F F T T F F

24. p → q q

∴ p invalid: converse error 25. p ∨ q

∼p ∴ q valid: elimination

26. p → q q → r

∴ p → r valid: transitivity 27. p → q

∼p ∴ ∼q invalid: inverse error

36. The program contains an undeclared variable. One explanation: 1. There is not a missing semicolon and there is not a mis-

spelled variable name. (by (c) and (d) and definition of ∧)

2. It is not the case that there is a missing semicolon or a misspelled variable name. (by (1) and De Morgan’s laws)

3. There is not a syntax error in the first five lines. (by (b) and (2) and modus tollens)

4. There is an undeclared variable. (by (a) and (3) and elimination)

37. The treasure is buried under the flagpole. One explanation: 1. The treasure is not in the kitchen. (by (c) and (a) and

modus ponens) 2. The tree in the front yard is not an elm. (by (b) and (1)

and modus tollens) 3. The treasure is buried under the flagpole. (by (d) and (2)

and elimination) 38. a. A is a knave and B is a knight.

One explanation: 1. Suppose A is a knight. 2. ∴ What A says is true. (by definition of knight) 3. ∴ B is a knight also. (That’s what A said.) 4. ∴ What B says is true. (by definition of knight) 5. ∴ A is a knave. (That’s what B said.) 6. ∴ We have a contradiction: A is a knight and a

knave. (by (1) and (5)) 7. ∴ The supposition that A is a knight is false. (by the

contradiction rule) 8. ∴ A is a knave. (negation of supposition)

9. ∴ What B says is true. (B said A was a knave, which we now know to be true.)

10. ∴ B is a knight. (by definition of knight) d. Hint: W and Y are knights; the rest are knaves.

39. The chauffeur killed Lord Hazelton. One explanation: 1. Suppose the cook was in the kitchen at the time of the

murder. 2. ∴ The butler killed Lord Hazelton with strychnine. (by

(c) and (1) and modus ponens) 3. ∴ We have a contradiction: Lord Hazelton was killed

by strychnine and a blow on the head. (by (2) and (a)) 4. ∴ The supposition that the cook was in the kitchen is

false. (by the contradiction rule) 5. ∴ The cook was not in the kitchen at the time of the

murder. (negation of supposition) 6. ∴ Sara was not in the dining room when the murder was

committed. (by (e) and (5) and modus ponens) 7. ∴ Lady Hazelton was in the dining room when the

murder was committed. (by (b) and (6) and elimination)

8. ∴ The chauffeur killed Lord Hazelton. (by (d) and (7) and modus ponens)

41. (1) p → t by premise (d ) ∼t by premise (c)

∴ ∼p by modus tollens (2) ∼p by (1)

∴ ∼p ∨ q by generalization (3) ∼p ∨ q → r by premise (a)

∼p ∨ q by (2) ∴ r by modus ponens

(4) ∼p by (1) r by (3)

∴ ∼p ∧ r by conjunction (5) ∼p ∧ r →∼s by premise (e)

∼p ∧ r by (4) ∴ ∼s by modus ponens

(6) s ∨ ∼q by premise (b) ∼s by (5)

∴ ∼q by elimination 43. (1) ∼w by premise (d )

u ∨ w by premise (e) ∴ u by elimination

(2) u →∼p by premise (c) u by (1)

∴ ∼p by modus ponens (3) ∼p → r ∧ ∼s by premise (a)

∼p by (2) ∴ r ∧ ∼s by modus ponens

(4) r ∧ ∼s by (3) ∴ ∼s by specialization

(5) t → s by premise (b) ∼s by (4)

∴ ∼t by modus tollens

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-12 Appendix B Solutions and Hints to Selected Exercises

Section 2.4 1. R = 1 3. S = 1 5.

Input Output

P Q R

1 1 1

1 0 1

0 1 0

0 0 1

7. Input Output

P Q R S

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 1

0 1 1 1

0 1 0 0

0 0 1 1

0 0 0 0

9. P ∨ ∼Q 11. (P ∧ ∼Q) ∨ R 13.

OR NOTP

Q

16.

OR

NOT

P

Q

R

AND

18. a. (P ∧ Q ∧ ∼R) ∨ (∼P ∧ Q ∧ R) b. P

Q

R NOT

NOT

AND

OR

AND

20. a. (P ∧ Q ∧ R) ∨ (P ∧ ∼Q ∧ R) ∨ (∼P ∧ ∼Q ∧ ∼R) b.

AND

P

Q

R

AND

NOT

NOT

NOT

ANDNOT

OR

22. The input/output table is

Input Output

P Q R S

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 0

0 1 0 0

0 0 1 1

0 0 0 0

One circuit (among many) having this input/output table is shown below.

P

Q

R NOT

NOT

NOT

AND

AND

OR

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

2.4 Solutions and Hints to Selected Exercises A-13

24. Let P and Q represent the positions of the switches in the classroom, with 0 being “down” and 1 being “up.” Let R represent the condition of the light, with 0 being “off” and 1 being “on.” Initially, P = Q = 0 and R = 0. If either P or Q (but not both) is changed to 1, the light turns on. So when P = 1 and Q = 0, then R = 1, and when P = 0 and Q = 1, then R = 1. Thus when one switch is up and the other is down the light is on, and hence moving the switch that is down to the up position turns the light off. So when P = 1 and Q = 1, then R = 0. It follows that the input/output table has the following appearance:

Input Output

P Q R

1 1 0

1 0 1

0 1 1

0 0 0

One circuit (among many) having this input/output table is the following:

P

Q AND

OR

NOT

AND NOT

R

26. The Boolean expression for (a) is (P ∧ Q) ∨ Q, and for (b) it is (P ∨ Q) ∧ Q. We must show that if these expres- sions are regarded as statement forms, then they are logi- cally equivalent. But

(P ∧ Q) ∨ Q ≡ Q ∨ (P ∧ Q) by the commutative law for ∨ ≡ (Q ∨ P) ∧ (Q ∨ Q) by the distributive law ≡ (Q ∨ P) ∧ Q by the idempotent law ≡ (P ∨ Q) ∧ Q by the commutative law for ∧

Alternatively, by the absorption laws, both statement forms are logically equivalent to Q.

28. The Boolean expression for (a) is

(P ∧ Q) ∨ (P ∧ ∼Q) ∨ (∼P ∧ ∼Q) and for (b) it is P ∨ ∼Q. We must show that if these expres- sions are regarded as statement forms, then they are logi- cally equivalent. But

(P ∧ Q) ∨ (P ∧ ∼Q) ∨ (∼P ∧ ∼Q) ≡ ((P ∧ Q) ∨ (P ∧ ∼Q)) ∨ (∼P ∧ ∼Q)

by inserting parentheses (which is legal by the associative law)

≡ (P ∧ (Q ∨ ∼Q)) ∨ (∼P ∧ ∼Q) by the distributive law

≡ (P ∧ t) ∨ (∼P ∧ ∼Q) by the negation law for ∨ ≡ P ∨ (∼P ∧ ∼Q) by the identity law for ∧ ≡ (P ∨ ∼P) ∧ (P ∨ ∼Q) by the distibutive law ≡ t ∧ (P ∨ ∼Q) by the negation law for ∨ ≡ (P ∨ ∼Q) ∧ t by the commutative law for ∧ ≡ P ∨ ∼Q by the identity law for ∧

30. (P ∧ Q) ∨ (∼P ∧ Q) ∨ (∼P ∧ ∼Q) ≡ (P ∧ Q) ∨ ((∼P ∧ Q) ∨ (∼P ∧ ∼Q))

by inserting parentheses (which is legal by the associative law)

≡ (P ∧ Q) ∨ (∼P ∧ (Q ∨ ∼Q)) by the distributive law

≡ (P ∧ Q) ∨ (∼P ∧ t) by the negation law for ∨ ≡ (P ∧ Q)∨ ∼P by the identity law for ∧ ≡∼P ∨ (P ∧ Q) by the commutative law for ∨ ≡ (∼P ∨ P) ∧ (∼P ∨ Q) by the distributive law ≡ (P ∨ ∼P) ∧ (∼P ∨ Q)

by the commutative law for ∨ ≡ t ∧ (∼P ∨ Q) by the negation law for ∨ ≡ (∼P ∨ Q) ∧ t by the commutative law for ∧ ≡∼P ∨ Q by the identity law for ∧

The following is, therefore, a circuit with at most two logic gates that has the same input/output table as the circuit cor- responding to the given expression.

OR NOTP

Q

34. b. (P ↓ Q) ↓ (P ↓ Q) ≡ ∼(P ↓ Q) by part (a) ≡ ∼[∼(P ∨ Q)] by definition of ↓ ≡ P ∨ Q by the double negative law

d. Hint: Use the results of exercise 13 of Section 2.2 and part (a) and (c) of this exercise.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-14 Appendix B Solutions and Hints to Selected Exercises

Section 2.5 1. 1910 = 16 + 2 + 1 = 100112 4. 45810 = 256 + 128 + 64 + 8 + 2 = 1110010102 7. 11102 = 8 + 4 + 2 = 1410

10. 11001012 = 64 + 32 + 4 + 1 = 10110 13. 1 1 1

1 0 1 12 + 1 0 12

1 0 0 0 02 15. 1 1 1 1

1 0 1 1 0 12 + 1 1 1 0 12

1 0 0 1 0 1 02 17. 1

1 10 10 1 1 0 1 0 02

− 1 1 0 12 1 1 12

19. 0 10 1 0 1 1 0 12

− 1 0 0 1 12 1 1 0 1 02

21. a. S = 0, T = 1 23. 2310 = (16 + 4 + 2 + 1)10 = 000101112 → 11101000 →

11101001. So the answer is 11101001. 25. 410 = 000001002 → 11111011 → 11111100. So the answer

is 11111100. 27. Because the leading bit is 1, this is the 8-bit represen-

tation of a negative integer. 11010011 → 00101100 → 001011012 ↔ −(32 + 8 + 4 + 1)10 = −4510. So the answer is −4510.

29. Because the leading bit is 1, this is the 8-bit represen- tation of a negative integer. 11110010 → 00001101 → 000011102 ↔ −(8 + 4 + 2)10 = −1410. So the answer is −1410.

31. 5710 = (32 + 16 + 8 + 1)10 = 1110012 → 00111001− 11810 = −(64 + 32 + 16 + 4 + 2)10 = −1110110 → 01110110 → 10001001 → 10001010. So the 8-bit rep- resentations of 57 and −118 are 00111001 and 10001010. Adding the 8-bit representations gives

0 0 1 1 1 0 0 1 +

1 0 0 0 1 0 1 0

1 1 0 0 0 0 1 1

Since the leading bit of this number is a 1, the answer is negative. Converting back to decimal form gives

11000011 → 00111100 →−001111012 = −(32 + 16 + 8 + 4 + 1)10 = −6110.

So the answer is −61.

32. 6210 = (32 + 16 + 8 + 4 + 2)10 = 1111102 → 00111110

−1810 = −(16 + 2)10 = −100102 → 00010010 → 11101101 → 11101110

Thus the 8-bit representations of 62 and −18 are 00111110 and 11101110. Adding the 8-bit representations gives

0 0 1 1 1 1 1 0 +

1 1 1 0 1 1 1 0

0 0 1 0 1 1 0 01

Truncating the 1 in the 28th position gives 00101100. Since the leading bit of this number is a 0, the answer is positive. Converting back to decimal form gives

00101100 → 1011002 = (32 + 8 + 4)10 = 4410. So the answer is 44.

33. −610 = −(4 + 2)10 = −1102 → 00000110 → 11111001 → 11111010

−7310 = −(64 + 8 + 1)10 = −10010012→ 01001001→ 10110110→ 10110111

Thus the 8-bit representations of−6 and−73 are 11111010 and 10110111. Adding the 8-bit representations gives

1 1 1 1 1 0 1 0 +

1 0 1 1 0 1 1 1

1 0 1 1 0 0 0 11

Truncating the 1 in the 28th position gives 10110001. Since the leading bit of this number is a 1, the answer is negative. Converting back to decimal form gives

10110001 → 01001110 →−010011112 = −(64 + 8 + 4 + 2 + 1)10 = −7910.

So the answer is −79. 38. A2BC16 = 10 ·163 + 2 ·162 + 11 ·16 + 12 = 4166010 41. 0001110000001010101111102 44. 2E16 47. a. 6 ·84 + 1 ·83 + 5 ·82 + 0 ·8 + 2 ·1 = 25,41010

Section 3.1 1. a. False b. True 2. a. The statement is true. The integers correspond to cer-

tain of the points on a number line, and the real numbers correspond to all the points on the number line.

b. The statement is false; 0 is neither positive nor negative. c. The statement is false. For instance, let r = −2. Then −r = −(−2) = 2, which is positive.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.1 Solutions and Hints to Selected Exercises A-15

d. The statement is false. For instance, the number 12 is a real number, but it is not an integer.

3. a. P(2) is “2 > 12 ,” which is true.

P (

1 2

) is “ 12 >

1 1 2

.” This is false because 11 2

= 2, and 1 2 ≯ 2. P(−1) is “−1 > 1−1 .” This is false because

1 −1 = −1,

and −1 ≯ −1. P ( − 12 )

is “− 12 > 1

−12 .” This is true because 1

−12 =

−2 and −12 > −2. P(−8) is “−8 > 1−8 .” This is false because

1 −8 = −

1 8

and −8 ≯ − 18 . b. If the domain of P(x) is the set of all real numbers, then

its truth set is the set of all real numbers x for which either x > 1 or −1 < x < 0.

c. If the domain of P(x) is the set of all positive real num- bers, then its truth set is the set of all real numbers x for which x > 1.

4. b. If the domain of Q(n) is the set of all integers, then its truth set is {−5,−4,−3,−2,−1, 0, 1, 2, 3, 4, 5}.

5. a. Q(−2,1) is the statement “If −2 < 1 then (−2)2 < 12.” The hypothesis of this statement is −2 < 1, which is true. The conclusion is (−2)2 < 12, which is false because (−2)2 = 4 and 12 = 1 and 4 ̸< 1. Thus Q(−2, 1) is a conditional statement with a true hypoth- esis and a false conclusion. So Q(−2, 1) is false.

c. Q(3,8) is the statement “If 3 < 8 then 32 < 82.” The hypothesis of this statement is 3 < 8, which is true. The conclusion is 32 < 82, which is also true because 32 = 9 and 82 = 64 and 9 < 64. Thus Q(3, 8) is a conditional statement with a true hypothesis and a true conclusion. So Q(3, 8) is true.

7. a. The truth set is the set of all integers d such that 6/d is an integer, so the truth set is {−6,−3,−2,−1, 1, 2, 3, 6}.

c. The truth set is the set of all real numbers x with the property that 1 ≤ x2 ≤ 4, so the truth set is {x ∈ R | − 2 ≤ x ≤ −1 or 1 ≤ x ≤ 2}. In other words, the truth set is the set of all real numbers between −2 and −1 inclusive together with those between 1 and 2 inclusive.

8. a. {−9,−8,−7,−6,−5,−4,−3,−2,−1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

9. Counterexample: Let x = 1 : 1 ≯ 11 . (This is one coun- terexample among many.)

11. Counterexample: Let m = 1 and n = 1. Then m ·n = 1 ·1 = 1 and m + n = 1 + 1 = 2. But 1 % 2, and so m ·n % m + n. (This is one counterexample among many.)

13. (a), (e), (f) 14. (b), (c), (e), (f) 15. a. Partial answer: Every rectangle is a quadrilateral.

b. Partial answer: At least one set has 16 subsets.

16. a. ∀ dinosaurs x, x is extinct. c. ∀ irrational numbers x, x is not an integer. e. ∀ integers x, x2 does not equal 2, 147, 581, 953.

17. a. ∃ an exercise x such that x has an answer. 18. a. ∃s ∈ D such that E(s) and M(s). (Or: ∃s ∈ D such that

E(s) ∧ M(s).) b. ∀s ∈ D, if C(s) then E(s). (Or:∀s ∈ D, C(s) → E(s).) e. (∃s ∈ D such that C(s) ∧ E(s)) ∧ (∃s ∈ D such that

C(s) ∧ ∼E(s)) 19. (b), (d), (e) 20. Partial answer: The square root of a positive real number is

positive. 21. a. The total degree of G is even, for any graph G.

c. p is even, for some prime number p 22. a. ∀x , if x is a Java program, then x has at least 5 lines. 23. a. ∀x if x is an equilateral triangle, then x is isosceles. 24. a. ∃ a hatter x such that x is mad.

∃x such that x is a hatter and x is mad. 25. a. ∀ nonzero fractions x , the reciprocal of x is a fraction.

∀x , if x is a nonzero fraction, then the reciprocal of x is a fraction.

c. ∀ triangles x , the sum of the angles of x is 180◦. ∀x , if x is a triangle, then the sum of the angles of x is 180◦.

e. ∀ even integers x and y, the sum of x and y is even. ∀x and y, if x and y are even integers, then the sum of x and y is even.

26. b. ∀x(Int(x) −→ Ratl(x)) ∧ ∃x(Ratl(x)∧ ∼Int(x)) 27. a. False. Figure b is a circle that is not gray.

b. True. All the gray figures are circles. 28. b. One answer among many: If a real number is negative,

then when its opposite is computed, the result is a posi- tive real number.

This statement is true because for all real numbers x,−(−|x |) = |x | (and any negative real number can be represented as −|x |, for some real number x).

d. One answer among many: There is a real number that is not an integer. This statement is true. For instance, 12 is a real number that is not an integer.

30. b. One answer among many: If an integer is prime, then it is not a perfect square.

This statement is true because a prime number is an integer greater than 1 that is not a product of two smaller positive integers. So a prime number cannot be a perfect square because if it were, it would be a product of two smaller positive integers.

31. Hint: Your answer should have the appearance shown in the following made-up example: Statement: “If a function is differentiable, then it is contin- uous.” Formal version: ∀ functions f , if f is differentiable, then f is continuous. Citation: Calculus by D. R. Mathematician, Best Publish- ing Company, 2004, page 263.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-16 Appendix B Solutions and Hints to Selected Exercises

32. a. True: Any real number that is greater than 2 is greater than 1.

c. False: (−3)2 > 4 but −3 ≯ 2. 33. a. True. Whenever both a and b are positive, so is their

product. b. False. Let a = −2 and b = −3. Then ab = 6, which is

not less than zero.

Section 3.2 1. (a) and (e) are negations. 3. a. ∃ a fish x such that x does not have gills.

c. ∀movies m, m is less than or equal to 6 hours long. (Or: ∀ movies m, m is no more than 6 hours long.)

In 4–6 there are other correct answers in addition to those shown.

4. a. Some dogs are unfriendly. (Or: There is at least one unfriendly dog.)

c. All suspicions were unsubstantiated. (Or: No suspicions were substantiated.)

5. a. There is a valid argument that does not have a true con- clusion. (Or: At least one valid argument does not have a true conclusion.)

6. a. Sets A and B have at least one point in common. 7. The statement is not existential.

Informal negation: There is at least one order from store A for item B. Formal version of statement: ∀ orders x , if x is from store A, then x is not for item B.

9. ∃ a real number x such that x > 3 and x2 ≤ 9. 11. The proposed negation is not correct. Consider the given

statement: “The sum of any two irrational numbers is irra- tional.” For this to be false means that it is possible to find at least one pair of irrational numbers whose sum is ratio- nal. On the other hand, the negation proposed in the exer- cise (“The sum of any two irrational numbers is rational”) means that given any two irrational numbers, their sum is rational. This is a much stronger statement than the actual negation: The truth of this statement implies the truth of the negation (assuming that there are at least two irrational numbers), but the negation can be true without having this statement be true. Correct negation: There are at least two irrational numbers whose sum is rational. Or: The sum of some two irrational numbers is rational.

13. The proposed negation is not correct. There are two mis- takes: The negation of a “for all” statement is not a “for all” statement; and the negation of an if-then statement is not an if-then statement. Correct negation: There exists an integer n such that n2 is even and n is not even.

15. a. True: All the odd numbers in D are positive. c. False: x = 16, x = 26, x = 32, and x = 36 are all

counterexamples.

16. ∃ a real number x such that x2 ≥ 1 and x ≯ 0. In other words, ∃ a real number x such that x2 ≥ 1 and x ≤ 0.

18. ∃ a real number x such that x(x + 1) > 0 and both x ≤ 0 and x ≥ −1.

20. ∃ integers a, b, and c such that a − b is even and b − c is even and a − c is not even.

22. There is an integer such that the square of the integer is odd but the integer is not odd. (Or: At least one integer has an odd square but is not itself odd.)

24. a. If a person is a child in Tom’s family, then the person is female. If a person is a female in Tom’s family, then the person is a child. The second statement is the converse of the first.

25. a. Converse: If n + 1 is an even integer, then n is a prime number that is greater than 2. Counterexample: Let n = 15. Then n + 1 is even but n is not a prime number that is greater than 2.

26. Statement: ∀ real numbers x , if x2 ≥ 1 then x > 0. Contrapositive: ∀ real numbers x , if x ≤ 0 then x2 < 1. Converse: ∀ real numbers x , if x > 0 then x2 ≥ 1. Inverse: ∀ real numbers x , if x2 < 1 then x ≤ 0. The statement and its contrapositive are false. As a coun- terexample, let x = −2. Then x2 = (−2)2 = 4, and so x2 ≥ 1. However x ≯ 0. The converse and the inverse are also false. As a coun- terexample, let x = 1/2. Then x2 = 1/4, and so x > 0 but x2 ' 1.

28. Statement: ∀x ∈ R, if x(x + 1) > 0 then x > 0 or x < −1. Contrapositive: ∀x ∈ R, if x ≤ 0 and x ≥ −1, then x(x + 1) ≤ 0. Converse: ∀x ∈ R, if x > 0 or x < −1 then x(x + 1) > 0. Inverse: ∀x ∈ R, if x(x + 1) ≤ 0 then x ≤ 0 and x ≥ −1. The statement, its contrapositive, its converse, and its inverse are all true.

30. Statement: ∀ integers a, b, and c, if a − b is even and b − c is even, then a − c is even. Contrapositive: ∀ integers a, b, and c, if a − c is not even, then a − b is not even or b − c is not even. Converse: ∀ integers a, b and c, if a − c is even then a − b is even and b − c is even. Inverse: ∀ integers a, b, and c, if a − b is not even or b − c is not even, then a − c is not even. The statement is true, but its converse and inverse are false. As a counterexample, let a = 3, b = 2, and c = 1. Then a − c = 2, which is even, but a − b = 1 and b − c = 1, so it is not the case that both a − b and b − c are even.

32. Statement: If the square of an integer is odd, then the integer is odd. Contrapositive: If an integer is not odd, then the square of the integer is not odd. Converse: If an integer is odd, then the square of the integer is odd. Inverse: If the square of an integer is not odd, then the inte- ger is not odd.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.3 Solutions and Hints to Selected Exercises A-17

The statement, its contrapositive, its converse, and its inverse are all true.

34. a. If n is divisible by some prime number strictly between 1 and

√ n, then n is not prime.

36. a. One possible answer: Let P(x) be “2x ̸= 1.” The state- ment “∀x ∈ Z, 2x ̸= 1” is true, but the statements “∀x ∈Q, 2x ̸= 1” and “∀x ∈ R, 2x ̸= 1” are both false.

37. The claim is “∀x , if x = 1 and x is in the sequence 0204, then x is to the left of all the 0’s in the sequence.” The negation is “∃x such that x = 1 and x is in the sequence 0204, and x is not to the left of all the 0’s in the sequence.” The negation is false because the sequence does not contain the character 1. So the claim is vacuously true (or true by default).

39. If a person earns a grade of C− in this course, then the course counts toward graduation.

41. If a person is not on time each day, then the person will not keep this job.

43. It is not the case that if a number is divisible by 4, then that number is divisible by 8. In other words, there is a number that is divisible by 4 and is not divisible by 8.

45. It is not the case that if a person has a large income, then that person is happy. In other words, there is a person who has a large income and is not happy.

48. No. Interpreted formally, the statement says, “If carriers do not offer the same lowest fare, then you may not select among them,” or, equivalently, “If you may select among carriers, then they offer the same lowest fare.”

Section 3.3 1. a. True: Tokyo is the capital of Japan.

b. False: Athens is not the capital of Egypt. 2. a. True: 22 > 3 b. False: 12 ≯ 1 3. a. y = 12 b. y = −1 4. a. Let n = 16. Then n > x because 16 > 15.83. 5. The statement says that no matter what circle anyone might

give you, you can find a square of the same color. This is true because the only circles are a, c, and b, and given a or c, which are blue, square j is also blue, and given b, which is gray, squares g and h are also gray.

7. This is true because triangle d is above every square. 9. a. There are five elements in D. For each, an element in

E must be found so that the sum of the two equals 0. So: if x = −2, take y = 2; if x = −1, take y = 1; if x = 0, take y = 0; if x = 1, take y = −1; if x = 2, take y = −2.

Alternatively, note that for each integer x in D, the integer −x is also in D, including 0 (because −0 = 0), and for all integers x, x + (−x) = 0.

10. a. True. Every student chose at least one dessert: Uta chose pie, Tim chose both pie and cake, and Yuen chose pie.

c. This statement says that some particular dessert was chosen by every student. This is true: Every student chose pie.

11. a. There is a student who has seen Casablanca. c. Every student has seen at least one movie. d. There is a movie that has been seen by every student.

(There are many other acceptable ways to state these answers.)

12. a. Negation: ∃x in D such that ∀y in E, x + y ̸= 1. The negation is true. When x = −2, the only number y with the property that x + y = 1 is y = 3, and 3 is not in E .

b. Negation: ∀x in D, ∃y in E such that x + y ̸= −y. The negation is true and the original statement is false. To see that the original statement is false, take any x in D and choose y to be any number in E with y ̸= − x2 . Then 2y ̸= −x , and adding x and subtracting y from both sides gives x + y ̸= −y.

In 13–19 there are other correct answers in addition to those shown. 13. a. Statement: For every color, there is an animal of that

color. There are animals of every color.

b. Negation: ∃ a color C such that ∀ animals A, A is not colored C . For some color, there is no animal of that color.

14. Statement: There is a book that all people have read. Negation: There is no book that all people have read. (Or: ∀ books b, ∃ a person p such that p has not read b.)

15. a. Statement: For every odd integer n, there is an integer k such that n = 2k + 1. Given any odd integer, there is another integer for which the given integer equals twice the other integer plus 1. Given any odd integer n, we can find another integer k so that n = 2k + 1. An odd integer is equal to twice some other integer plus 1. Every odd integer has the form 2k + 1 for some integer k.

b. Negation: ∃ an odd integer n such that ∀ integers k, n ̸= 2k + 1. There is an odd integer that is not equal to 2k + 1 for any integer k. Some odd integer does not have the form 2k + 1 for any integer k.

18. a. Statement: For every real number x , there is a real num- ber y such that x + y = 0. Given any real number x , there exists a real number y such that x + y = 0. Given any real number, we can find another real num- ber (possibly the same) such that the sum of the given number plus the other number equals 0. Every real number can be added to some other real num- ber (possibly itself) to obtain 0.

b. Negation: ∃ a real number x such that ∀ real numbers y, x + y ̸= 0.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-18 Appendix B Solutions and Hints to Selected Exercises

There is a real number x for which there is no real num- ber y with x + y = 0. There is a real number x with the property that x + y ̸= 0 for any real number y. Some real number has the property that its sum with any other real number is nonzero.

20. Statement (1) says that no matter what square anyone might give you, you can find a triangle of a different color. This is true because the only squares are e, g, h, and j , and given squares g and h, which are gray, you could take triangle d, which is black; given square e, which is black, you could take either triangle f or i , which are gray; and given square j , which is blue, you could take either triangle f or h, which are gray, or triangle d, which is black.

21. a. (1) The statement “∀ real numbers x, ∃ a real number y such that 2x + y = 7” is true.

(2) The statement “∃ a real number x such that ∀ real numbers y, 2x + y = 7” is false.

b. Both statements (1) “∀ real numbers x, ∃ a real number y such that x + y = y + x” and (2) “∃ a real number x such that ∀ real numbers y, x + y = y + x” are true.

22. a. Given any real number, you can find a real number so that the sum of the two is zero. In other words, every real number has an additive inverse. This statement is true.

b. There is a real number with the following property: No mattter what real number is added to it, the sum of the two will be zero. In other words, there is one particular real number whose sum with any real number is zero. This statement is false; no one number will work for all numbers. For instance, if x + 0 = 0, then x = 0, but in that case x + 1 = 1 ̸= 0.

24. a. ∼(∀x ∈ D(∀y ∈ E(P(x, y)))) ≡ ∃x ∈ D(∼(∀y ∈ E(P(x, y)))) ≡ ∃x ∈ D(∃y ∈ E(∼P(x, y)))

25. This statement says that all of the circles are above all of the squares. This statement is true because the circles are a, b, and c, and the squares are e, g, h, and j , and all of a, b, and c lie above all of e, g, h, and j . Negation: There is a circle x and a square y such that x is not above y. In other words, at least one of the circles is not above at least one of the squares.

27. The statement says that there are a circle and a square with the property that the circle is above the square and has a different color from the square. This statement is true. For example, circle a lies above square e and is differ- ently colored from e. (Several other examples could also be given.)

29. a. Version with interchanged quantifiers: ∃x ∈ R such that ∀y ∈ R, x < y.

b. The given statement says that for any real number x , there is a real number y that is greater than x . This is true: For any real number x , let y = x + 1. Then x < y. The version with interchanged quantifiers says that there

is a real number that is less than every other real number. This is false.

31. ∀ people x, ∃ a person y such that x is older than y. 32. ∃ a person x such that ∀ people y, x is older than y. 33. a. Formal version: ∀ people x, ∃ a person y such that x

loves y. b. Negation: ∃ a person x such that ∀ people y, x does not

love y. In other words, there is someone who does not love anyone.

34. a. Formal version: ∃ a person x such that ∀ people y, x loves y.

b. Negation: ∀ people x, ∃ a person y such that x does not love y. In other words, everyone has someone whom they do not love.

37. a. Statement: ∀ even integers n, ∃ an integer k such that n = 2k.

b. Negation: ∃ an even integer n such that ∀ integers k, n ̸= 2k. There is some even integer that is not equal to twice any other integer.

39. a. Statement: ∃ a program P such that ∀ questions Q posed to P , P gives the correct answer to Q.

b. Negation: ∀ programs P , there is a question Q that can be posed to P such that P does not give the correct answer to Q.

40. a. ∀ minutes m, ∃ a sucker s such that s was born in minute m.

41. a. This statement says that given any positive integer, there is a positive integer such that the first integer is one more than the second integer. This is false. Given the posi- tive integer x = 1, the only integer with the property that x = y + 1 is y = 0, and 0 is not a positive integer.

b. This statement says that given any integer, there is an integer such that the first integer is one more than the second integer. This is true. Given any integer x , take y = x − 1. Then y is an integer, and y + 1 = (x − 1) + 1 = x .

e. This statement says that given any real number, there is a real number such that the product of the two is equal to 1. This is false because 0 · y = 0 ̸= 1 for every number y. So when x = 0, there is no real number y with the property that xy = 1.

42. ∃ε > 0 such that ∀ integers N , ∃ an integer n such that n > N and either L − ε ≥ an or an ≥ L + ε. In other words, there is a positive number ε such that for all inte- gers N , it is possible to find an integer n that is greater than N and has the property that an does not lie between L − ε and L + ε.

44. a. This statement is true. The unique real number with the given property is 1. Note that

1 · y = y for all real numbers y, and if x is any real number such that for instance, x ·2 = 2, then dividing both sides by 2 gives x = 2/2 = 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

3.4 Solutions and Hints to Selected Exercises A-19

46. a. True. Both triangles a and c lie above all the squares. b. Formal version: ∃x(Triangle(x) ∧ (∀y(Square(y)→

Above(x, y)))) c. Formal negation: ∀x(∼Triangle(x) ∨ (∃y (Square (y)∧ ∼Above(x, y))))

48. a. False. There is no square to the right of circle k. b. Formal version: ∀x(Circle(x)→ (∃y(Square(y) ∧

RightOf(y, x)))) c. Formal negation: ∃x(Circle(x) ∧ (∀y(∼Square(y) ∨ ∼RightOf(y, x))))

51. a. False. There is no object that has a different color from every other object.

b. Formal version: ∃y(∀x(x ̸= y →∼SameColor(x, y))) c. Formal negation: ∀y(∃x(x ̸= y ∧ SameColor(x, y)))

53. a. False b. Formal version: ∃x(Circle(x) ∧ (∃y(Square(y) ∧

SameColor(x, y)))) c. Formal negation: ∀x(∼Circle(x) ∨ (∀y(∼Square(y) ∨ ∼SameColor(x, y))))

55. a. No matter what the domain D or the predicates P(x) and Q(x) are, the given statements have the same truth value. If the statement “∀x in D, (P(x) ∧ Q(x))” is true, then P(x) ∧ Q(x) is true for every x in D, which implies that both P(x) and Q(x) are true for every x in D. But then P(x) is true for every x in D, and also Q(x) is true for every x in D. So the statement “(∀x in D, P(x)) ∧ (∀x, in D, Q(x))” is true. Con- versely, if the statement “(∀x in D, P(x)) ∧ (∀x in D, Q(x))” is true, then P(x) is true for every x in D, and also Q(x) is true for every x in D. This implies that both P(x) and Q(x) are true for every x in D, and so P(x) ∧ Q(x) is true for every x in D. Hence the state- ment “∀x in D, (P(x) ∧ Q(x))” is true.

59. a. Yes b. X = w1, X = w2 c. X = b2, X = w2

Section 3.4 1. b. ( fi + f j )2 = f 2i + 2 fi f j + f 2j

c. (3u + 5v)2 = (3u)2 + 2(3u)(5v) + (5v)2 (= 9u2 + 30uv + 25v2)

d. (g(r) + g(s))2 = (g(r))2 + 2g(r)g(s) + (g(s))2 2. 0 is even. 3. 23 +

4 5 =

(2 ·5+3 ·4) (3 ·5)

( = 2215 )

5. 10 is not an irrational number. 7. Invalid; converse error 8. Valid by universal modus ponens (or universal instantia-

tion) 9. Invalid; inverse error

10. Valid by universal modus tollens 16. Invalid; converse error 19. ∀x , if x is a good car, then x is not cheap.

a. Valid, universal modus ponens (or universal instantia- tion)

b. Invalid, converse error

21. Valid. (A valid argument can have false premises and a true conclusion!)

mortals

mice

people

The major premise says the set of people is included in the set of mice. The minor premise says the set of mice is included in the set of mortals. Assuming both of these premises are true, it must follow that the set of people is included in the set of mortals. Since it is impossible for the conclusion to be false if the premises are true, the argument is valid.

23. Valid. The major and minor premises can be diagrammed as follows:

beings who occasionally

make mistakes

teachers

gods

According to the diagram, the set of teachers and the set of gods can have no common elements. Hence, if the premises are true, then the conclusion must also be true, and so the argument is valid.

25. Invalid. Let C represent the set of all college cafeteria food, G the set of all good food, and W the set of all wasted food. Then any one of the following diagrams could represent the given premises.

G

G

C W

WC

1

3

G

C W

2

G

WC

4

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-20 Appendix B Solutions and Hints to Selected Exercises

Only in drawing (1) is the conclusion true. Hence it is possi- ble for the premises to be true while the conclusion is false, and so the argument is invalid.

28. (3) Contrapositive form: If an object is gray, then it is a circle. (2) If an object is a circle, then it is to the right of all the blue objects. (1) If an object is to right of all the blue objects, then it is above all the triangles. ∴ If an object is gray, then it is above all the triangles.

31. 4. If an animal is in the yard, then it is mine. 1. If an animal belongs to me, then I trust it. 5. If I trust an animal, then I admit it into my study. 3. If I admit an animal into my study, then it will beg when

told to do so. 6. If an animal begs when told to do so, then that animal is

a dog. 2. If an animal is a dog, then that animal gnaws bones. ∴ If an animal is in the yard, then that animal gnaws bones;

that is, all the animals in the yard gnaw bones. 33. 2. If a bird is in this aviary, then it belongs to me.

4. If a bird belongs to me, then it is at least 9 feet high. 1. If a bird is at least 9 feet high, then it is an ostrich. 3. If a bird lives on mince pies, then it is not an ostrich.

Contrapositive: If a bird is an ostrich, then it does not live on mince pies.

∴ If a bird is in this aviary, then it does not live on mince pies; that is, no bird in this aviary lives on mince pies.

Section 4.1 1. a. Yes: −17 = 2(−9) + 1

b. Yes: 0 = 2 ·0 c. Yes: 2k − 1 = 2(k − 1) + 1 and k − 1 is an integer

because it is a difference of integers. 2. a. Yes: 6m + 8n = 2(3m + 4n) and (3m + 4n) is an inte-

ger because 3, 4, m, and n are integers, and products and sums of integers are integers.

b. Yes: 10mn + 7 = 2(5mn + 3) + 1 and 5mn + 3 is an integer because 3, 5, m, and n are integers, and products and sums of integers are integers.

c. Not necessarily. For instance, if m = 3 and n = 2, then m2 − n2 = 9− 4 = 5, which is prime. (Note that m2 − n2 is composite for many values of m and n because of the identity m2 − n2 = (m − n)(m + n).)

4. For example, let m = n = 2. Then m and n are inte- gers such that m > 0 and n > 0 and 1m +

1 n =

1 2 +

1 2 = 1,

which is an integer. 7. For example, let n = 7. Then n is an integer such that n > 5

and 2n − 1 = 127, which is prime. 9. For example, 25, 9, and 16 are all perfect squares, because

25 = 52, 9 = 32, and 16 = 42, and 25 = 9 + 16. Thus 25 is a perfect square that can be written as a sum of two other perfect squares.

11. Counterexample: Let a = −2 and b = −1. Then a < b because −2 < −1, but a2 ≮ b2 because (−2)2 = 4 and (−1)2 = 1 and 4 ≮ 1. [So the hypothesis of the statement is true but its conclusion is false.]

14. This property is true for some integers and false for other integers. For instance, if a = 0 and b = 1, the property is true because (0 + 1)2 = 02 + 12, but if a = 1 and b = 1, the property is false because (1 + 1)2 = 4 and 12 + 12 = 2 and 4 ̸= 2.

15. Hint: This property is true for some integers and false for other integers. To justify this answer you need to find exam- ples of both.

17. 2 = 12 + 12, 4 = 22, 6 = 22 + 12 + 12, 8 = 22 + 22, 10 = 32 + 12, 12 = 22 + 22 + 22,

14 = 32 + 22 + 12, 16 = 42, 18 = 32 + 32 = 42 + 12 + 12, 20 = 42 + 22, 22 = 32 + 32 + 22, 24 = 42 + 22 + 22

19. a. ∀ integers m and n, if m is even and n is odd, then m + n is odd. ∀ even integers m and odd integers n, m + n is odd. If m is any even integer and n is any odd integer, then m + n is odd.

b. (a) any odd integer (b) integer r (c) 2r + (2s + 1) (d) m + n is odd

20. a. If an integer is greater than 1, then its reciprocal is between 0 and 1.

b. Start of proof: Suppose m is any integer such that m > 1. Conclusion to be shown: 0 < 1/m < 1.

22. a. If the product of two integers is 1, then either both are 1 or both are −1.

b. Start of proof: Suppose m and n are any integers with mn = 1. Conclusion to be shown: m = n = 1 or m = n = −1.

24. Two versions of a correct proof are given below to illustrate some of the variety that is possible. Proof 1: Suppose n is any [particular but arbitrarily chosen] even integer. [We must show that −n is even.] By definition of even, n = 2k for some integer k. Multiplying both side by −1 gives that

−n = −(2k) = 2(−k).

Let r = −k. Then r is an integer because r = −k = (−1)k, −1 and k are integers, and a product of two integers is an integer. Hence, −n = 2r for some integer r , and so −n is even [as was to be shown]. Proof 2: Suppose n is any even integer. By definition of even, n = 2k for some integer k. Then

−n = −2k = 2(−k).

But −k is an integer because it is a product of integers −1 and k. Thus −n equals twice some integer, and so −n is even by definition of even.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.1 Solutions and Hints to Selected Exercises A-21

25. Proof: Suppose a is any even integer and b is any odd inte- ger. [We must show that a − b is odd.] By definition of even and odd, a = 2r and b = 2s + 1 for some integers r and s. By substitution and algebra,

a − b = 2r − (2s + 1) = 2r − 2s − 1 = 2(r − s − 1) + 1. Let t = r − s − 1. Then t is an integer because differences of integers are integers. Thus a − b = 2t + 1, where t is an integer, and so, by definition of odd, a − b is odd [as was to be shown].

26. Hint: The conclusion to be shown is that a certain quantity is odd. To show this, you need to show that the quantity equals twice some integer plus one.

29. Proof: Suppose n is any [particular but arbitrarily chosen] odd integer. [We must show that 3n + 5 is even.] By defini- tion of odd, there is an integer r such that n = 2r + 1. Then

3n + 5 = 3(2r + 1) + 5 by substitution = 6r + 3 + 5 = 6r + 8 = 2(3r + 4) by algebra.

Let t = 3r + 4. Then t is an integer because products and sums of integers are integers. Hence, 3n + 5 = 2t , where t is an integer, and so, by definition of even, 3n + 5 is even [as was to be shown].

31. Proof: Suppose k is any [particular but arbitrarily chosen] odd integer and m is any even integer. [We must show that k2 + m2 is odd.] By definition of odd and even, k = 2a + 1 and m = 2b for some integers a and b. Then

k2 + m2 = (2a + 1)2 + (2b)2 by substitution = 4a2 + 4a + 1 + 4b2

= 4(a2 + a + b2) + 1 = 2(2a2 + 2a + 2b2) + 1 by algebra.

But 2a2 + 2a + 2b2 is an integer because it is a sum of products of integers. Thus k2 + m2 is twice an integer plus 1, and so k2 + m2 is odd [as was to be shown].

33. Proof: Suppose n is any even integer. Then n = 2k for some integer k. Hence

(−1)n = (−1)2k = ((−1)2)k = 1k = 1 [by the laws of exponents from algebra]. This is what was to be shown.

35. The negation of the statement is “For all integers m ≥ 3, m2 − 1 is not prime.” Proof of the negation: Suppose m is any integer with m ≥ 3. By basic algebra, m2 − 1 = (m − 1)(m + 1). Because m ≥ 3, both m − 1 and m + 1 are positive integers greater than 1, and each is smaller than m2 − 1. So m2 − 1 is a product of two smaller positive integers, each greater than 1, and hence m2 − 1 is not prime.

38. The incorrect proof just shows the theorem to be true in the one case where k = 2. A real proof must show that it is true for all integers k > 0.

39. The mistake in the “proof” is that the same symbol, k, is used to represent two different quantities. By setting m = 2k and n = 2k + 1, the proof implies that n = m + 1, and thus it deduces the conclusion only for this one situ- ation. When m = 4 and n = 17, for instance, the compu- tations in the proof indicate that n − m = 1, but actually n − m = 13. In other words, the proof does not deduce the conclusion for an arbitrarily chosen even integer m and odd integer n, and hence it is invalid.

40. This incorrect proof exhibits circular reasoning. The word since in the third sentence is completely unjustified. The second sentence tells only what happens if k2 + 2k + 1 is composite. But at that point in the proof, it has not been established that k2 + 2k + 1 is composite. In fact, that is exactly what is to be proved.

43. True. Proof: Suppose m and n are any odd integers. [We must show that mn is odd.] By definition of odd, n = 2r + 1 and m = 2s + 1 for some integers r and s. Then

mn = (2r + 1)(2s + 1) by subsitution = 4rs + 2r + 2s + 1 = 2(2rs + r + s) + 1 by algebra.

Now 2rs + r + s is an integer because products and sums of integers are integers and 2, r , and s are all integers. Hence mn = 2 · (some integer) + 1, and so, by definition of odd, mn is odd.

44. True. Proof: Suppose n is any odd integer. [We must show that −n is odd.] By definition of odd, n = 2k + 1 for some integer k. By substitution and algebra,

−n = −(2k + 1) = −2k − 1 = 2(−k − 1) + 1. Let t = −k − 1. Then t is an integer because differences of integers are integers. Thus−n = 2t + 1, where t is an inte- ger, and so, by definition of odd, −n is odd [as was to be shown].

45. False. Counterexample: Both 3 and 1 are odd, but their dif- ference is 3− 1 = 2, which is even.

47. False. Counterexample: Let m = 1 and n = 3. Then m + n = 4 is even, but neither summand m nor summand n is even.

54. Proof: Suppose n is any integer. Then

4(n2 + n + 1)− 3n2 = 4n2 + 4n + 4− 3n2

= n2 + 4n + 4 = (n + 2)2

(by algebra). But (n + 2)2 is a perfect square because n + 2 is an integer (being a sum of n and 2). Hence 4(n2 + n + 1)− 3n2 is a perfect square, as was to be shown.

56. Hint: This is true. 62. Hint: The answer is no.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-22 Appendix B Solutions and Hints to Selected Exercises

Section 4.2 1. −356 = −356 3. 45 +

2 9 =

4 ·9+2 ·5 45 =

46 45

4. Let x = 0.3737373737 . . .. Then 100x = 37.37373737 . . . , and so 100x − x = 37.37373737 . . .− 0.3737373737 . . .. Thus 99x = 37, and hence x = 3799 .

6. Let x = 320.5492492492 . . .. Then 10000x = 3205492.492492 . . ., and 10x = 3205.492492492 . . . , and so 10000x − 10x = 3205492− 3205. Thus 9990x = 3202287, and hence x = 32022879990 .

8. b. ∀ real numbers x and y, if x ̸= 0 and y ̸= 0 then xy ̸= 0. 9. Because a and b are integers, b − a and ab2 are both inte-

gers (since differences and products of integers are inte- gers). Also, by the zero product property, ab2 ̸= 0 because neither a nor b is zero. Hence (b − a)/ab2 is a quotient of two integers with nonzero denominator, and so it is rational.

11. Proof: Suppose n is any [particular but arbitrarily chosen] integer. Then n = n ·1, and so n = n/1 by by dividing both sides by 1. Now n and 1 are both integers, and 1 ̸= 0. Hence n can be written as a quotient of integers with a nonzero denominator, and so n is rational.

12. (a) any [particular but arbitrarily chosen] rational number (b) integers a and b (c) (a/b)2 (d) b2

(e) zero product property (f) r 2 is rational 13. a. ∀ real numbers r , if r is rational then −r is rational.

Or: ∀r , if r is a rational number then −r is rational. Or: ∀ rational numbers r, −r is rational.

b. The statement is true. Proof: Suppose r is a [particular but arbitrarily chosen] rational number. [We must show that −r is rational.] By definition of rational, r = a/b for some integers a and b with b ̸= 0. Then

−r = −a b

by substitution

= −a b

by algebra.

But since a is an integer, so is −a (being the product of −1 and a). Hence −r is a quotient of integers with a nonzero denominator, and so−r is rational [as was to be shown].

15. Proof: Suppose r and s are rational numbers. By definition of rational, r = a/b and s = c/d for some integers a, b, c, and d with b ̸= 0 and d ̸= 0. Then

rs = a b

· c d

by substitution

= ac bd

by the rules of algebra for multiplying fractions.

Now ac and bd are both integers (being products of inte- gers) and bd ̸= 0 (by the zero product property). Hence rs is a quotient of integers with a nonzero denominator, and so, by definition of rational, rs is rational.

16. Hint: Counterexample: Let r be any rational number and s = 0. Then r and s are both rational, but the quotient of r divided by s is undefined and therefore is not a rational number. Revised statement to be proved: For all rational numbers r and s, if s ̸= 0 then r/s is rational.

17. Hint: The conclusion to be shown is that a certain quantity (the difference of two rational numbers) is rational. To show this, you need to show that the quantity can be expressed as a ratio of two integers with a nonzero denominator.

18. Hint: a/b+c/d

2 = (ad + bc)/(bd)

2 = ad + bc

2bd 19. Hint: If a < b then a + a < a + b (by T19 of Appendix

A), or equivalently 2a < a + b. Thus a < a+b2 (by T20 Appendix A).

21. True. Proof: Suppose m is any even integer and n is any odd integer. [We must show that m2 + 3n is odd.] By properties 1 and 3 of Example 4.2.3, m2 is even (because m2 = m ·m) and 3n is odd (because both 3 and n are odd). It follows from property 5 [and the commutative law for addition] that m2 + 3n is odd [as was to be shown].

24. Proof: Suppose r and s are any rational numbers. By Theorem 4.2.1, both 2 and 3 are rational, and so, by exercise 15, both 2r and 3s are rational. Hence, by The- orem 4.2.2, 2r + 3s is rational.

27. Let

x = 1− 1

2n+1

1− 1 2

= 1− 1

2n+1 1 2

= 1− 1

2n+1 1 2

· 2 n+1

2n+1 = 2

n+1− 1 2n

·

But 2n+1 − 1 and 2n are both integers (since n is a non- negative integer) and 2n ̸= 0 by the zero product property. Therefore, x is rational.

31. Proof: Suppose c is a real number such that

r3c3 + r2c2 + r1c + r0 = 0, where r0, r1, r2, and r3 are rational numbers. By defini- tion of rational, r0 = a0/b0, r1 = a1/b1, r2 = a2/b2, and r3 = a3/b3 for some integers, a0, a1, a2, a3, and nonzero integers b0, b1, b2, and b3. By substitution,

r3c3 + r2c2 + r1c + r0

= a3 b3

c3 + a2 b2

c2 + a1 b1

c + a0 b0

= b0b1b2a3 b0b1b2b3

c3 + b0b1b3a2 b0b1b2b3

c2 + b0b2b3a1 b0b1b2b3

c + b1b2b3a0 b0b1b2b3

= 0. Multiplying both sides by b0b1b2b3 gives

b0b1b2a3 ·c3 + b0b1b3a2 ·c2 + b0b2b3a1 ·c + b1b2b3a0 = 0. Let n3 = b0b1b3a3, n2 = b0b1b3a2, n1 = b0b2b3a1, and n0 = b1b2b3a0. Then n0, n1, n2, and n3 are all integers (being products of integers). Hence c satisfies the equation

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.3 Solutions and Hints to Selected Exercises A-23

n3c3 + n2c2 + n1c + n0 = 0. where n0, n1, n2, and n3 are all integers. This is what was to be shown.

33. a. Hint: Note that (x − r)(x − s) = x2 − (r + s)x + rs. If both r and s are odd, then r + s is even and rs is odd. So the coefficient of x2 is 1 (odd), the coefficient of x is even, and the constant coefficient, rs, is odd.

35. This “proof” assumes what is to be proved. 37. By setting both r and s equal to a/b, this incorrect proof

violates the requirement that r and s be arbitrarily chosen rational numbers. If both r and s equal a/b, then r = s.

Section 4.3 1. Yes, 52 = 13 ·4 2. Yes, 56 = 7 ·8 4. Yes, (3k + 1)(3k + 2)(3k + 3) =

3 [(3k + 1)(3k + 2)(k + 1)], and (3k + 1)(3k + 2)(k + 1) is an integer because k is an integer and sums and products of integers are integers.

6. No, 29/3 ∼= 9.67, which is not an integer. 7. Yes, 66 = (−3)(−22). 8. Yes, 6a(a + b) = 3a[2(a + b)], and 2(a + b) is an integer

because a and b are integers and sums and products of inte- gers are integers.

10. No, 34/7 ∼= 4.86, which is not an integer. 12. Yes, n2 − 1 = (4k + 1)2 − 1 = (16k2 + 8k + 1)− 1 =

16k2 + 8k = 8(2k2 + k), and 2k2 + k is an integer because k is an integer and sums and products of integers are inte- gers.

14. (a) a | b (b) b = a ·r (c) −r (d) a | (−b) 15. Proof: Suppose a, b, and c are any integers such that a | b

and a | c. [We must show that a | (b + c).] By definition of divides, b = ar and c = as for some integers r and s. Then

b + c = ar + as = a(r + s) by algebra. Let t = r + s. Then t is an integer (being a sum of inte- gers), and thus b + c = at where t is an integer. By defini- tion of divides, then, a | (b + c) [as was to be shown].

16. Hint: The conclusion to be shown is that a certain quantity is divisible by a. To show this, you need to show that the quantity equals a times some integer.

17. a. ∀ integers n if n is a multiple of 3 then −n is a multiple of 3.

b. The statement is true. Proof: Suppose n is any integer that is a multiple of 3. [We must show that −n is a mul- tiple of 3.] By definition of multiple, n = 3k for some integer k. Then −n = −(3k) by substitution

= 3(−k) by algebra. Hence, by definition of multiple, −n is a multiple of 3 [as was to be shown].

18. Counterexample: Let a = 2 and b = 1. Then a + b = 2 + 1 = 3, and so 3 | (a + b) because 3 = 3 ·1. On the other hand, a − b = 2− 1 = 1, and 3 & 1 because 1/3 is not an integer. Thus 3 & (a − b). [So the hypothesis of the statement is true but its conclusion is false.]

19. Start of proof : Suppose a, b, and c are any integers such that a divides b. [We must show that a divides bc.]

22. Hint: The given statement can be rewritten formally as “∀ integers n, if n is divisible by 6, then n is divisible by 2.” This statement is true.

24. The statement is true. Proof: Suppose a, b, and c are any integers such that a | b and a | c. [We must show that a | (2b − 3c).] By definition of divisibility, we know that b = am and c = an for some integers m and n. It follows that 2b − 3c = 2(am)− 3(an) (by substitution) = a(2m − 3n) (by basic algebra). Let t = 2m − 3n. Then t is an integer because it is a difference of products of integers. Hence 2b − 3c = at , where t is an integer, and so a | (2b − 3c) by definition of divisibility [as was to be shown].

25. The statement is false. Counterexample: Let a = 2, b = 3, and c = 8. Then a | c because 2 divides 8, but ab & c because ab = 6 and 6 does not divide 8.

26. Hint: The statement is true. 27. Hint: The statement is false. 32. No. Each of these numbers is divisible by 3, and so their

sum is also divisible by 3. But 100 is not divisible by 3. Thus the sum cannot equal $100.

36. a. The sum of the digits is 54, which is divisible by 9. Therefore, 637,425,403,705,125 is divisible by 9 and hence also divisible by 3 (by transitivity of divisibil- ity). Because the rightmost digit is 5, then 637,425, 403,705,125 is not divisible by 5. And because the two rightmost digits are 25, which is not divisible by 4, then 637,425,403,705,125 is not divisible by 4.

37. a. 1176 = 23 ·3 ·72 38. a. p2e11 p

2e2 2 . . . p

2ek k

b. n = 42, 25 ·3 ·52 ·73 ·n = 58802 40. a. Because 12a = 25b, the unique factorization theorem

guarantees that the standard factored forms of 12a and 25b must be the same. Thus 25b contains the factors 22 ·3(= 12). But since neither 2 nor 3 divide 25, the fac- tors 22 ·3 must all occur in b, and hence 12 | b. Similarly, 12a contains the factors 52 = 25, and since 5 is not a factor of 12, the factors 52 must occur in a. So 25 | a.

41. Hint: 458 ·885 = (32 ·5)8 · (23 ·11)5 = 316 ·58 ·215 ·115. How many factors of 10 does this number contain?

42. a. 6! = 6 ·5 ·4 ·3 ·2 ·1 = 2 ·3 ·5 ·2 ·2 ·3 ·2 = 24 ·32 ·5 44. Proof: Suppose n is a nonnegative integer whose deci-

mal representation ends in 0. Then n = 10m + 0 = 10m for some integer m. Factoring out a 5 yields n = 10m = 5(2m), and 2m is an integer since m is an integer. Hence 10m is divisible by 5, which is what was to be shown.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-24 Appendix B Solutions and Hints to Selected Exercises

47. Hint: You may take it as a fact that for any positive integer k,

10k = 99 . . . 9︸ ︷︷ ︸ + 1; that is, k of these

10k = 9 ·10k−1 + 9 ·10k−2 + · · · + 9 ·101 + 9 ·100 + 1.

Section 4.4 1. q = 7, r = 7 3. q = 0, r = 36 5. q = −5, r = 10 7. a. 4 b. 7

11. a. When today is Saturday, 15 days from today is two weeks (which is Saturday) plus one day (which is Sun- day). Hence DayN should be 0. According to the for- mula, when today is Saturday, DayT = 6, and so when N = 15,

DayN = (DayT + N ) mod 7 = (6 + 15) mod 7 = 21 mod 7 = 0, which agrees.

13. Solution 1: 30 = 4 ·7 + 2. Hence the answer is two days after Monday, which is Wednesday. Solution 2: By the formula, the answer is (1 + 30) mod 7 = 31 mod 7 = 3, which is Wednesday.

14. Hint: There are two ways to solve this problem. One is to find that 1,000 = 7 ·142 + 6 and note that if today is Tuesday, then 1,000 days from today is 142 weeks plus 6 days from today. The other way is to use the formula DayN = (DayT + N ) mod 7, with DayT = 2 (Tuesday) and N = 1000.

16. Because d | n, n = dq + 0 for some integer q . Thus the remainder is 0.

18. Proof: Suppose n is any odd integer. By definition of odd, n = 2q + 1 for some integer q. Then n2 = (2q + 1)2 = 4q2 + 4q + 1 = 4(q2 + q) + 1 = 4q(q + 1) + 1. By the result of exercise 17, the product q(q + 1) is even, so q(q + 1) = 2m for some integer m. Then, by substitution, n2 = 4 ·2m + 1 = 8m + 1.

20. Because a mod 7 = 4, the remainder obtained when a is divided by 7 is 4, and so a = 7q + 4 for some inte- ger q. Multiplying this equation through by 5 gives that 5a = 35q + 20 = 35q + 14 + 6 = 7(5q + 2) + 6. Because q is an integer, 5q + 2 is also an integer, and so 5a = 7 · (an integer) + 6. Thus, because 0 ≤ 6 < 7, the remain- der obtained when 5a is divided by 7 is 6, and so 5a mod 7 = 6.

23. Proof: Suppose n is any [particular but arbitrarily chosen] integer such that n mod 5 = 3. Then the remainder obtained when n is divided by 5 is 3, and so n = 5q + 3 for some integer q . By substitution,

n2 = (5q + 3)2 = 25q2 + 30q + 9 = 25q2 + 30q + 5 + 4 = 5(5q2 + 6q + 1) + 4.

Because products and sums of integers are integers, 5q2 + 6q + 1 is an integer, and hence n2 = 5 · (an integer) + 4.

Thus, since 0 ≤ 4 < 5, the remainder obtained when n2 is divided by 5 is 4, and so n2 mod 5 = 4.

26. Hint: You need to show that (1) for all nonnegative inte- gers n and positive integers d , if n is divisible by d then n mod d = 0; and (2) for all nonnegative integers n and positive integers d , if n mod d = 0 then n is divisible by d.

27. Proof: Suppose n is any integer. By the quotient-remainder theorem with d = 3, there exist integers q and r such that n = 3q + r and 0 ≤ r < 3. But the only nonnegative inte- gers r that are less than 3 are 0, 1, and 2. Therefore, n = 3q + 0 = 3q, or n = 3q + 1, or n = 3q + 2 for some integer q.

28. a. Proof: Suppose n, n + 1, and n + 2 are any three con- secutive integers. [We must show that n(n + 1)(n + 2) is divisible by 3.] By the quotient-remainder theorem, n can be written in one of the three forms, 3q, 3q + 1, or 3q + 2 for some integer q . We divide into cases accord- ingly. Case 1 (n = 3q for some integer q): In this case, n(n + 1)(n + 2)

= 3q(3q + 1)(3q + 2) by substitution = 3 · [q(3q + 1)(3q + 2)] by factoring out a 3.

Let m = q(3q + 1)(3q + 2). Then m is an integer because q is an integer, and sums and products of inte- gers are integers. By substitution,

n(n + 1)(n + 2) = 3m where m is an integer. And so, by definition of divisible, n(n + 1)(n + 2) is divisible by 3. Case 2 (n = 3q + 1 for some integer q): In this case, n(n + 1)(n + 2)

= (3q + 1)((3q + 1) + 1)((3q + 1) + 2) by substitution

= (3q + 1)(3q + 2)(3q + 3) = (3q + 1)(3q + 2)3(q + 1) = 3 · [(3q + 1)(3q + 2)(q + 1)] by algebra.

Let m = (3q + 1)(3q + 2)(q + 1). Then m is an inte- ger because q is an integer, and sums and products of integers are integers. By substitution,

n(n + 1)(n + 2) = 3m where m is an integer. And so, by definition of divisible, n(n + 1)(n + 2) is divisible by 3. Case 3 (n = 3q + 2 for some integer q): In this case, n(n + 1)(n + 2)

= (3q + 2)((3q + 2) + 1)((3q + 2) + 2) by substitution

= (3q + 2)(3q + 3)(3q + 4) = (3q + 2)3(q + 1)(3q + 4) = 3 · [(3q + 2)(q + 1)(3q + 4)] by algebra

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.5 Solutions and Hints to Selected Exercises A-25

Let m = (3q + 2)(q + 1)(3q + 4). Then m is an inte- ger because q is an integer, and sums and products of integers are integers. By substitution,

n(n + 1)(n + 2) = 3m where m is an integer. And so, by definition of divisible, n(n + 1)(n + 2) is divisible by 3. In each of the three cases, n(n + 1)(n + 2) was seen to be divisible by 3. But by the quotient-remainder theo- rem, one of these cases must occur. Therefore, the prod- uct of any three consecutive integers is divisible by 3.

b. For all integers n, n(n + 1)(n + 2) mod 3 = 0. 29. a. Hint: Given any integer n, begin by using the quotient-

remainder theorem to say that n can be written in one of the three forms: n = 3q, or n = 3q + 1, or n = 3q + 2 for some integer q. Then divide into three cases according to these three possibilities. Show that in each case either n2 = 3k for some integer k, or n2 = 3k + 1 for some integer k. For instance, when n = 3q + 2, then n2 = (3q + 2)2 = 9q2 + 12q + 4 = 3(3q2 + 4q + 1) + 1, and 3q2 + 4q + 1 is an integer because it is a sum of products of integers.

31. b. If m2 − n2 = 56, then 56 = (m + n)(m − n). Now 56 = 23 ·7, and by the unique factorization theorem, this factorization is unique. Hence the only representations of 56 as a product of two positive integers are 56 = 7 ·8 = 14 ·4 = 28 ·2 = 56 ·1. By part (a), m and n must both be odd or both be even. Thus the only solutions are either m + n = 14 and m − n = 4 or m + n = 28 and m − n = 2. This gives either m = 9 and n = 5 or m = 15 and n = 13 as the only solutions.

32. Under the given conditions, 2a − (b + c) is even. Proof: Suppose a, b, and c are any integers such that a − b is even and b − c is even. [We must show that 2a − (b + c) is even.] Note first that 2a − (b + c) = (a − b) + (a − c). Also note that (a − b) + (b − c) is a sum of two even inte- gers and hence is even by Example 4.2.3 #1. But (a − b) + (b − c) = a − c, and so a − c is even. Hence 2a − (b + c) is a sum of two even integers, and thus it is even [as was to be shown].

34. Hint: Express n using the quotient-remainder theorem with d = 3.

36. Hint: Use the quotient-remainder theorem (as in Exam- ple 3.4.5) to say that n = 4q, n = 4q + 1, n = 4q + 2, or n = 4q + 3 and divide into cases accordingly.

38. Hint: Given any integer n, consider the two cases where n is even and where n is odd.

39. Hint: Given any integer n, analyze the sum n + (n + 1) + (n + 2) + (n + 3).

42. Hint: Use the quotient-remainder theorem to say that n must have one of the forms 6q, 6q + 1, 6q + 2, 6q + 3, 6q + 4, or 6q + 5 for some integer q.

44. Hint: There are three cases: Either x and y are both pos- itive, or they are both negative, or one is positive and the other is negative.

47. a. 7609 + 5 = 7614 49. Answer to first question: No. Counterexample: Let m =

1, n = 3, and d = 2. Then m mod d = 1 and n mod d = 1 but m ̸= n. Answer to second question: Yes. Proof: Suppose m, n, and d are integers such that m mod d = n mod d . Let r = m mod d = n mod d. By definition of mod, m = dp + r and n = dq + r for some integers p and q. Then m − n = (dp + r)− (dq + r) = d(p − q). But p − q is an integer (being a difference of integers), and so m − n is divisible by d by definition of divisible.

Section 4.5 1. ⌊37.999⌋ = 37, ⌈37.999⌉ = 38 3. ⌊−14.00001⌋ = −15, ⌈−14.00001⌉ = −14 8. ⌊n/7⌋. The floor notation is more appropriate. If the ceiling

notation is used, two different formulas are needed, depend- ing on whether n/7 is an integer or not. (What are they?)

10. a. (i) (2050 + ⌊

2049 4

⌋ − ⌊

2049 100

⌋ + ⌊

2049 400

⌋) mod 7

= (2050 + 512− 20 + 5) mod 7 = 2547 mod 7 = 6, which corresponds to a Saturday

b. Hint: One day is added every four years, except that each century the day is not added unless the century is a mul- tiple of 400.

12. Proof: Suppose n is any even integer. By definition of even, n = 2k for some integer k. Then ⌊n

2

⌋ = ⌊

2k 2

⌋ = ⌊k⌋ = k because k is an integer

and k ≤ k < k − 1.

But k = n 2

because n = 2k.

Thus, on the one hand, ⌊

n 2

⌋ = k, and on the other hand,

k = n2 . It follows that ⌊

n 2

⌋ = n2 [as was to be shown].

14. False. Counterexample: Let x = 2 and y = 1.9. Then ⌊x − y⌋ = ⌊2− 1.9⌋ = ⌊0.1⌋ = 0, whereas ⌊x⌋ − ⌊y⌋ = ⌊2⌋ − ⌊1.9⌋ = 2 = 1 = 1.

15. True. Proof: Suppose x is any real number. Let m = ⌊x⌋. By definition of floor, m ≤ x < m + 1. Subtracting 1 from all parts of the inequality gives that

m − 1 ≤ x − 1 < m, and so, by definition of floor, ⌊x − 1⌋ = m − 1. It follows by substitution that ⌊x − 1⌋ = ⌊x⌋ − 1.

17. Proof for the case where n mod 3 = 2: In the case where n mod 3 = 2, then n = 3q + 2 for some integer q by definition of mod . By substitution,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-26 Appendix B Solutions and Hints to Selected Exercises

⌊n 3

⌋ = ⌊

3q + 2 3

= ⌊

3q 3

+ 2 3

= ⌊

q + 2 3

⌋ = q because q is an integer and

q ≤ q + 2/3 < q + 1. But

q = n − 2 3

by solving n = 3q + 2 for q .

Thus, on the one hand, ⌊

n 3

⌋ = q, and on the other hand,

q = n−23 . It follows that ⌊

n 3

⌋ = n−23 .

18. Hint: This is false. 19. Hint: This is true. 23. Proof: Suppose x is a real number that is not an integer.

Let ⌊x⌋ = n. Then, by definition of floor and because n is not an integer, n < x < n + 1. Multiplying both sides by −1 gives −n > −x > −n − 1, or equivalently, −n − 1 < −x < −n. Since −n − 1 is an integer, it follows by defini- tion of floor that ⌊−x⌋ = −n − 1. Hence

⌊x⌋+ ⌊−x⌋ = n + (−n − 1) = n − n − 1 = −1, as was to be shown.

25. Hint: Let n = ⌊

x 2

⌋ and consider the two cases: n is even

and n odd. 26. Proof: Suppose x is any real number such that

x − ⌊ x ⌋ < 12 . Multiplying both sides by 2 gives 2x − 2⌊x⌋ < 1, or 2x < 2⌊x⌋+ 1.

Now by definition of floor, ⌊x⌋ ≤ x . Hence, 2⌊x⌋ ≤ 2x . Putting the two inequalities involving 2x together gives

2⌊x⌋ ≤ 2x < 2⌊x⌋+ 1. Thus, by definition of floor (and because 2⌊x⌋ is an inte- ger), ⌊2x⌋ = 2⌊x⌋. This is what was to be shown.

30. This incorrect proof exhibits circular reasoning. The equal- ity ⌊

n 2

⌋ = (n−1)2 is what is to be shown. By substituting

2k + 1 for n into both sides of the equality and working from the result as though it were known to be true, the proof assumes the truth of the conclusion to be proved.

Section 4.6 1. (a) A contradiction

(b) A positive real number (c) x (d) Both sides by 2 (e) Contradiction

3. Proof: Suppose not. That is, suppose there is an integer n such that 3n + 2 is divisible by 3. [We must derive a contra- diction.] By definition of divisibility, 3n + 2 = 3k for some integer k. Subtracting 3n from both sides gives that 2 = 3k − 3n = 3(k − n). So, by definition of divisibility, 3 | 2.

But by Theorem 4.3.1 this implies that 3 ≤ 2, which con- tradicts the fact that 3 > 2. [Thus for all integers n, 3n + 2 is not divisible by 3.]

5. Negation of statement: There is a greatest even integer. Proof of statement: Suppose not. That is, suppose there is a greatest even integer; call it N . Then N is an even inte- ger, and N ≥ n for every even integer n. [We must deduce a contradiction.] Let M = N + 2. Then M is an even inte- ger since it is a sum of even integers, and M > N since M = N + 2. This contradicts the supposition that N ≥ n for every even integer n. [Hence the supposition is false and the statement is true.]

8. (a) a rational number (b) an irrational number (c) ab (d) cd (e) ab −

c d

(f) integers (g) integers (h) zero product property (i) rational

9. a. The mistake in this proof occurs in the second sentence where the negation written by the student is incorrect: Instead of being existential, it is universal. The prob- lem is that if the student proceeds in a logically correct manner, all that is needed to reach a contradiction is one example of a rational and an irrational number whose sum is irrational. To prove the given statement, however, it is necessary to show that there is no rational number and no irrational number whose sum is rational.

10. Proof by contradiction: Suppose not. That is, suppose there is an irrational number x such that the square root of x is rational. [We must derive a contradiction.] By definition of rational,

√ x = ab for some integers a and b with b ̸= 0. By

substitution,

( √

x)2 = (a

b

)2 ,

and so, by algebra,

x = a 2

b2 .

But a2 and b2 are both products of integers and thus are integers, and b2 is nonzero by the zero product property.

Thus a 2

b2 is rational. It follows that x is both irrational and rational, which is a contradiction. [This is what was to be shown.]

11. Proof: Suppose not. That is, suppose ∃ a nonzero rational number x and an irrational number y such that xy is ratio- nal. [We must derive a contradiction.] By definition of ratio- nal, x = a/b and xy = c/d for some integers a, b, c, and d with b ̸= 0 and d ̸= 0. Also a ̸= 0 because x is nonzero. By substitution, xy = (a/b)y = c/d . Solving for y gives y = bc/ad. Now bc and ad are integers (being products of integers) and ad ̸= 0 (by the zero product property). Thus,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.6 Solutions and Hints to Selected Exercises A-27

by definition of rational, y is rational, which contradicts the supposition that y is irrational. [Hence the supposition is false and the statement is true.]

13. Hint: Suppose n2 − 2 is divisible by 4, and consider the two cases where n is even and n is odd. (An alternative solution uses Proposition 4.6.4.)

14. Hint: a2 = c2 − b2 = (c − b)(c + b) 15. Hint: (1) For any integer c, if 2 divides c, then 4 divides c2.

(2) The result of exercise 13 may be helpful. 16. Hint: Suppose a, b, and c are odd integers, z is a solution

to ax2 + bx + c = 0, and z is rational. Then z = p/q for some integers p and q with q ̸= 0. We may assume p and q have no common factor. (Why? If p and q do have a com- mon factor, we can divide out their greatest common factor to obtain two integers p′ and q ′ that (1) have no common factor and (2) satisfy the equation z = p′/q ′. Then we can redefine q = q ′ and p = p′.) Note that because p and q have no common factor, they are not both even. Substi- tute p/q into ax2 + bx + c = 0, and multiply through by q2. Show that (1) the assumption that p is even leads to a contradiction, (2) the assumption that q is even leads to a contradiction, and (3) the assumption that both p and q are odd leads to a contradiction. The only remaining possibility is that both p and q are even, which has been ruled out.

18. a. 5 | n b. 5 | n2 c. 5k d. (5k)2 e. 5 | n2 19. Proof (by contraposition): [To go by contraposition, we must

prove that ∀ positive real numbers, r and s, if r ≤ 10 and s ≤ 10, then rs ≤ 100.] Suppose r and s are positive real numbers and r ≤ 10 and s ≤ 10. By the algebra of inequalities, rs ≤ 100. [To derive this fact, multiply both sides of r ≤ 10 by s to obtatin rs ≤ 10s. And multiply both sides of s ≤ 10 by 10 to obtain 10s ≤ 10 ·10 = 100. By tran- sitivity of ≤, then, rs ≤ 100.] But this is what was to be shown.

21. a. Proof by contradiction: Suppose not. That is, suppose there is an integer n such that n2 is odd and n is even. Show that this supposition leads logically to a contra- diction.

b. Proof by contraposition: Suppose n is any integer such that n is not odd. Show that n2 is not odd.

23. a. The contrapositive is the statement “∀ real numbers x , if −x is not irrational, then x is not irrational.” Equiva- lently (because −(−x) = x), “∀ real numbers x , if x is rational then −x is rational.” Proof by contraposition: Suppose x is any rational num- ber. [We must show that −x is also rational.] By defini- tion of rational, x = a/b for some integers a and b with b ̸= 0. Then x = −(a/b) = (−a)/b. Since both−a and b are integers and b ̸= 0,−x is rational [as was to be shown].

b. Proof by contradiction: Suppose not. [We take the nega- tion and suppose it to be true.] That is, suppose ∃ an irra- tional number x such that−x is rational. [We must derive a contradiction.] By definition of rational, −x = a/b for

some integers a and b with b ̸= 0. Multiplying both sides by −1 gives x = −(a/b) = −a/b. But −a and b are integers (since a and b are) and b ̸= 0. Thus x is a ratio of the two integers −a and b with b ̸= 0. Hence x is rational (by definition of rational), which is a contra- diction. [This contradiction shows that the supposition is false, and so the given statement is true.]

25. Hints: See the answer to exercise 21 and look carefully at the two proofs for Proposition 4.6.4.

26. a. Proof by contraposition: Suppose a, b, and c are any [particular but arbitrarily chosen] integers such that a | b. [We must show that a | bc.] By definition of divides, b = ak for some integer k. Then bc = (ak)c = a(kc). But kc is an integer (because it is a product of the integers k and c). Hence a | bc by definition of divisibility [as was to be shown].

b. Proof by contradiction: Suppose not. [We take the nega- tion and suppose it to be true.] Suppose ∃ integers a, b, and c such that a |/ bc and a | b. Since a | b, there exists an integer k such that b = ak by definition of divides. Then bc = (ak)c = a(kc) [by the associative law of alge- bra]. But kc is an integer (being a product of integers), and so a | bc by definition of divides. Thus a |/ bc and a | bc, which is a contradiction. [This contradiction shows that the supposition is false, and hence the given statement is true.]

27. a. Hint: The contrapositive is “For all integers m and n, if m and n are not both even and m and n are not both odd, then m + n is not even.” Equivalently: “For all integers m and n, if one of m and n is even and the other is odd, then m + n is odd.”

b. Hint: The negation of the given statement is the follow- ing: ∃ integers m and n such that m + n is even, and either m is even and n is odd, or m is odd and n is even.

30. The negation of “Every integer is rational” is “There is at least one integer that is irrational” not “Every integer is irrational.” Deriving a contradiction from an incorrect negation of a statement does not prove the statement is true.

31. a. Proof: Suppose r, s, and n are integers and r > √

n and s >

√ n. Note that r and s are both positive because

√ n

cannot be negative. By multiplying both sides of the first inequality by s and both sides of the second inequal- ity by

√ n (Appendix A, T20), we have that rs >

√ ns

and √

ns > √

n √

n = n. Thus, by the transitive law for inequality (Appendix A, T18), rs > n.

32. a. √

667 ∼= 25.8, and so the possible prime factors to be checked are 2, 3, 5, 7, 11, 13, 17, 19, and 23. Test- ing each in turn shows that 667 is not prime because 667 = 23 ·29.

b. √

557 ∼= 23.6, and so the possible prime factors to be checked are 2, 3, 5, 7, 11, 13, 17, 19, and 23. Testing each in turn shows that none divides 557. Therefore, 557 is prime.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-28 Appendix B Solutions and Hints to Selected Exercises

34. a. √

9269 ∼= 96.3, and so the possible prime factors to be checked are all among those you found for exercise 33. Testing each in turn shows that 9,269 is not prime because 9,269 = 13 ·713.

b. √

9103 ∼= 95.4, and so the possible prime factors to be checked are all among those you found for exercise 33. Testing each in turn shows that none divides 9,103. Therefore, 9,103 is prime.

35. Hint: Is it possible for all three of n − 4, n − 6, and n − 8 to be prime?

Section 4.7 1. The value of

√ 2 given by a calculator is an approximation.

Calculators can give exact values only for numbers that can be represented using at most the number of decimal digits in the calculator display. In particular, every number in a calculator display is rational, but even many rational num- bers cannot be represented exactly. For instance, consider the number formed by writing a decimal point and follow- ing it with the first 1 million digits of

√ 2. By the discussion

in Section 4.2, this number is rational, but you could not infer this from the calculator display.

3. Proof by contradiction: Suppose not. That is, suppose 6− 7 √

2 is rational. [We must prove a contradiction.] By defini- tion of rational, there exist integers a and b ̸= 0 with

6− 7 √

2 = a b

.

Then √

2 = 1−7 (a

b − 6 ) by subtracting 6 from both

sides and dividing both sides by −7

and so √

2 = a − 6b−7b by the rules of algebra. But a − 6b and −7b are both integers (since a and b are integers and products and difference of integers are inte- gers), and−7b ̸= 0 by the zero product property. Hence

√ 2

is a ratio of the two integers a − 6b and−7b with−7b ̸= 0, so √

2 is a rational number (by definition of rational). This contradicts the fact that

√ 2 is irrational, and so the suppo-

sition is false and 6− 7 √

2 is irrational. 5. This is false.

√ 4 = 2 = 2/1, which is rational.

7. Counterexample: Let x = √

2 and let y = − √

2. Then x and y are irrational, but x + y = 0 = 0/1, which is ratio- nal.

9. True. Formal version of the statement: ∀ positive real numbers r , if r is irrational, then

√ r is irrational.

Proof by contraposition: Suppose r is any positive real number such that

√ r is rational. [We must show that r is

rational.] By definition of rational, √

r = ab for some inte- gers a and b with b ̸= 0. Then r =

(√ r )2 = (

a b

) 2 = a

2

b2 .

But both a2 and b2 are integers because they are products of integers, and b2 ̸= 0 by the zero product property. Thus r is rational [as was to be shown]. (The statement may also be proved by contradiction.)

13. Hint: Can you think of any “nice” integers x and y that are greater than 1 and have the property that x2 = y3?

16. a. Proof by contradiction: Suppose not. That is, suppose there is an integer n such that n = 3q1 + r1 = 3q2 + r2, where q1, q2, r1, and r2 are integers, 0 ≤ r1 < 3, 0 ≤ r2 < 3, and r1 ̸= r2. By interchanging the labels for r1 and r2 if necessary, we may assume that r2 > r1. Then 3(q1 − q2) = r2 − r1 > 0, and because both r1 and r2 are less than 3, either r2 − r1 = 1 or r2 − r1 = 2. So either 3(q1 − q2) = 1 or 3(q1 − q2) = 2. The first case implies that 3 | 1, and hence, by Theorem 4.3.1, that 3 ≤ 1, and the second case implies that 3 | 2, and hence, by Theorem 4.3.1, that 3 ≤ 2. These results contradict the fact that 3 is greater than both 1 and 2. Thus in either case we have reached a contradiction, which shows that the supposition is false and the given statement is true.

b. Proof by contradiction: Suppose not. That is, suppose there is an integer n such that n2 is divisible by 3 and n is not divisible by 3. [We must deduce a contradic- tion.] By definition of divisible, n2 = 3q for some inte- ger q, and by the quotient-remainder theorem and part (a), n = 3k + 1 or n = 3k + 2 some integer k. Case 1 (n = 3k + 1 for some integer k): In this case

n2 = (3k + 1)2 = 9k2 + 6k + 1 = 3(3k2 + 2k) + 1. Let s = 3k2 + 2k. Then n2 = 3s + 1, and s is an inte- ger because it is a sum of products of integers. It follows that n2 = 3q = 3s + 1 for some integers q and s, which contradicts the result of part (a). Case 2 (n = 3k + 2 for some integer k): In this case n2 = (3k + 2)2 = 9k2 + 12k + 4 = 3(3k2 + 6k + 1) + 1. Let t = 3k2 + 6k + 1. Then n2 = 3t + 1, and t is an integer because it is a sum of products of integers. It follows that n2 = 3q = 3t + 1 for some integers q and t , which contradicts the result of part (a). Thus in either case, a contradiction is reached, which shows that the supposition is false and the given state- ment is true.

c. Proof by contradiction: Suppose not. That is, suppose√ 3 is rational. By definition of rational,

√ 3 = ab for

some integers a and b with b ̸= 0. Without loss of gen- erality, assume that a and b have no common factor. (If not, divide both a and b by their greatest common fac- tor to obtain integers a′ and b′ with the property that a′

and b′ have no common factor and √

3 = a ′

b′ . Then rede-

fine a = a′ and b = b′.) Squaring both sides of √

3 = ab gives 3 = a

2

b2 , and multiplying both sides by b 2 gives

3b2 = a2(∗). Thus a2 is divisible by 3, and so, by part (b), a is also divisible by 3. By definition of divisibility, then, a = 3k for some integer k, and so

a2 = 9k2(∗∗).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

4.7 Solutions and Hints to Selected Exercises A-29

Substituting equation (**) into equation (∗) gives 3b2 = 9k2, and dividing both sides by 3 yields

b2 = 3k2. Hence b2 is divisible by 3, and so, by part (b), b is also divisible by 3. Consequently, both a and b are divisible by 3, which contradicts the assumption that a and b have no common factor. Thus the supposition is false, and so√

3 is irrational. 18. Hint: The proof is a generalization of the one given in the

solution for exercise 16(a). 19. Hint: (1) The parts of the proof are similar to those in exer-

cise 16(b) and 16(c). (2) Use the result of exercise 18. 20. Hint: This statement is true. If a2 − 3 = 9b, then a2 =

9b + 3 = 3(3b + 1), and so a2 is divisible by 3. Hence, by exercise 16(b), a is divisible by 3. Thus a2 = (3c)2 for some integer c.

21. Proof by contradiction: Suppose not. That is, suppose √

2 is rational. [We will show that this supposition leads to a contra- diction.] By definition of rational, we may write

√ 2 = a/b

for some integers a and b with b ̸= 0. Then 2 = a2/b2, and so a2 = 2b2. Consider the prime factorizations for a2 and for 2b2. By the unique factorization of integers theorem, these factorizations are unique except for the order in which the factors are written. Now because every prime factor of a occurs twice in the prime factorization of a2, the prime factorization of a2 contains an even number of 2’s. (If 2 is a factor of a, then this even number is positive, and if 2 is not a factor of a, then this even number is 0.) On the other hand, because every prime factor of b occurs twice in the prime factorization of b2, the prime factorization of 2b2 contains an odd number of 2’s. Therefore, the equation a2 = 2b2 cannot be true. So the supposition is false, and hence

√ 2 is irrational.

23. Hint: By the result of exercise 22, √

6 is irrational.

25. Hint: 2 ·3 ·5 ·7 + 1

2 = 3 ·5 ·7 + 1

2 and

2 ·3 ·5 ·7 + 1 3

= 2 ·5 ·7 + 1 3

.

26. Hint: You can deduce that p = 3. 27. a. Hint: For example, N4 = 2 ·3 ·5 ·7 + 1 = 211. 29. Hint: By Theorem 4.3.4 (divisibility by a prime) there is a

prime number p such that p | (n!− 1). Show that the suppo- sition that p ≤ n leads to a contradiction. It will then follow that n < p < n!.

30. Hint: Every odd integer can be written as 4k + 1 or as 4k + 3 for some integer k. (Why?) If p1 p2 . . . pn + 1 = 4k + 1, then 4 | p1 p2 . . . pn . Is this possible?

31. a. Hint: Prove the contrapositive: If for some integer n > 2 that is not a power of 2, xn + yn = zn has a positive integer solution, then for some prime number p > 2, x p + y p = z p has a positive integer solution. Note that if n = kp, then xn = xkp = (xk)p .

32. Existence proof: When n = 2, then n2 − 1 = 3, which is prime. Hence there exists a prime number of the form n2 − 1, where n is an integer and n ≥ 2. Uniqueness proof (by contradiction): Suppose to the con- trary that m is another integer satisfying the given con- ditions. That is, m > 2 and m2 − 1 is prime. [We must derive a contradiction.] Factor m2 − 1 to obtain m2 − 1 = (m − 1)(m + 1)). But m > 2, and so m − 1 > 1 and m + 1 > 1. Hence m2 − 1 is not prime, which is a contradic- tion. [This contradiction shows that the supposition is false, and so there is no other integer m > 2 such that n2 − 1 is prime.]

Uniqueness proof (direct): Suppose m is any integer such that m ≥ 2 and m2 − 1 is prime. [We must show that m = 2.] By factoring, m2 − 1 = (m − 1)(m + 1). Since m2 − 1 is prime, either m − 1 = 1 or m + 1 = 1. But m + 1 ≥ 2 + 1 = 3. Hence, by elimination, m − 1 = 1, and so m = 2.

34. Proof (by contradiction): Suppose not. That is, suppose there are two distinct real numbers a1 and a2 such that for all real numbers r ,

(1) a1 + r = r and (2) a2 + r = r Then

a1 + a2 = a2 by (1) with r = a2 and

a2 + a1 = a1 by (2) with r = a1. It follows that

a2 = a1 + a2 = a2 + a1 = a1 which implies that a2 = a1. But this contradicts the suppo- sition that a1 and a2 are distinct. [Thus the supposition is false and there is at most one real number a such that a + r = r for all real numbers r .] Proof (direct): Suppose a1 and a2 are real numbers such that for all real numbers r ,

(1) a1 + r = r and (2) a2 + r = r Then

a1 + a2 = a2 by (1) with r = a2 and

a2 + a1 = a1 by (2) with r = a1. It follows that

a2 = a1 + a2 = a2 + a1 = a1. Hence a2 = a1. [Thus there is at most one real number a such that a + r = r for all real numbers r .]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-30 Appendix B Solutions and Hints to Selected Exercises

Section 4.8 1. z = 0 3. a. z = 18 4. a = 1712 6.

Iteration Number 0 1 2 3

a 26

d 7

q 0 1 2 3

r 26 19 12 5

8. a. A 69 19 9

q 2

d 1

n 1

p 4

9. gcd(27, 72) = 9 10. gcd(5, 9) = 1 13. Divide the larger number, 1,188, by the smaller, 385,

to obtain a quotient of 3 and a remainder of 33. Next divide 385 by 33 to obtain a quotient of 11 and a remainder of 22. Then divide 33 by 22 to obtain a quo- tient of 1 and a remainder of 11. Finally, divide 22 by 11 to obtain a quotient of 2 and a remainder of 0. Thus, by Lemma 4.8.2, gcd(1188, 385) = gcd(385, 33) = gcd(33, 22) = gcd(22, 11) = gcd(11, 0), and by Lemma 4.8.1, gcd(11, 0) = 11. So gcd (1188, 385) = 11.

14. Divide the larger number, 1,177, by the smaller, 509, to obtain a quotient of 2 and a remainder of 159. Next divide 509 by 159 to obtain a quotient of 3 and a remainder of 32. Next divide 159 by 32 to obtain a quotient of 4 and a remainder of 31. Then divide 32 by 31 to obtain a quotient of 1 and a remainder of 1. Finally, divide 31 by 1 to obtain a quotient of 31 and a remainder of 0. Thus, by Lemma 4.8.2, gcd(1177, 509) = gcd(509, 159) = gcd(159, 32) = gcd(32, 31) = gcd(31, 1) = gcd(1, 0), and by Lemma 4.8.1, gcd(1, 0) = 1. So gcd(1177, 509) = 1.

17. A 1,001

B 871

r 130 91 39 13 0

b 871 130 91 39 13 0

a 1,001 871 130 91 39 13

gcd 13

19. Hint: Divide the proof into two parts. In part 1 suppose a and b are any positive integers such that a | b, and derive the conclusion that gcd(a, b) = a. To do this, note that because it is also the case that a | a, a is a common divisor of a and b. Thus, by definition of greatest common divisor, a is less than or equal to the greatest common divisor of a and b. In symbols, a ≤ gcd(a, b). Then show that a ≥ gcd(a, b)

by using Theorem 4.3.1. In part 2 of the proof, suppose a and b are any positive integers such that gcd(a, b) = a, and deduce that a | b.

22. a. Hint 1: If a = dq − r , then −a = −dq + r = −dq − d + d − r = d(−q − 1) + (d − r). Hint 2: If 0 ≤ r < d, then 0 ≥ −r > −d. Add d to all parts of this inequality and see what results.

23. a. Proof: Suppose a, d, q, and r are integers such that a = dq + r and 0 ≤ r < d. [We must show that q =

⌊ a d

and r = a−d ⌊

a d

⌋ .] Solving a = dq + r for r gives

r = a − dq, and substituting into 0 ≤ r < d gives 0 ≤ a − dq < d. Add dq to both sides to obtain dq ≤ a < d + dq = d(q + 1). Then divide through by d to obtain q ≤ ad < q + 1. Therefore, by definition of floor,⌊

a d

⌋ = q. Finally, substitution into a = dq + r gives

a = d ⌊

a d

⌋ + r , and subtracting d

⌊ a d

⌋ from both sides

yields r = a − d ⌊

a d

⌋ [as was to be shown].

24. b. Iteration Number 0 1 2 3 4

a 630 294 294 252 210

b 336 336 42 42 42

gcd

Iteration Number 5 6 7 8 9

a 168 126 84 42 0

b 42 42 42 42 42

gcd 42

25. a. lcm(12, 18) = 36 26. Proof: Part 1: Let a and b be positive integers, and sup-

pose d = gcd(a, b) = 1cm(a, b). By definition of great- est common divisor and least common multiple, d > 0, d | a, d | b, a | d, and b | d. Thus, in particular, a = dm and d = an for some integers m and n. By substitution, a = dm = (an)m = anm. Dividing both sides by a gives 1 = nm. But the only divisors of 1 are 1 and −1 (Theorem 4.3.2), and so m = n = ±1. Since both a and d are positive, m = n = 1, and hence a = d. Similar reasoning shows that b = d also, and so a = b. Part 2: Given any positive integers a and b such that a = b, we have gcd(a, b) = gcd(a, a) = a and 1cm(a, b) = 1cm(a, a) = a, and hence gcd(a, b) = 1cm(a, b).

29. Hint: Divide the proof into two parts. In part 1, suppose a and b are any positive integers, and deduce that

gcd(a, b) · 1cm(a, b) ≤ ab.

Derive this result by showing that 1cm (a, b) ≤ abgcd(a,b) . To do this, show that abgcd(a,b) is a multiple of both

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.1 Solutions and Hints to Selected Exercises A-31

a and b. For instance, to see that abgcd(a,b) is a multiple of

b, note that because gcd (a, b) divides a, a = gcd (a, b) ·k for some integer k, and thus ab = gcd(a, b) ·kb. Divide both sides by gcd(a, b) to obtain abgcd(a,b) = kb. But since k is an integer, this equation implies that abgcd(a,b) is

a multiple of b. The argument that abgcd(a,b) is a mul-

tiple of a is almost identical. In part 2 of the proof, use the definition of least common multiple to show that

ab 1cm(a,b) | a and

ab 1cm(a,b) | b. Conclude that

ab 1cm(a,b) ≤

gcd(a, b) and hence that ab ≤ gcd(a, b) · 1cm(a, b).

Section 5.1 1. 111 ,

2 12 ,

3 13 ,

4 14 3. 1,−13 , 19 ,− 127 5. 0, 0, 2, 2

8. g1 = ⌊log2 1⌋ = 0 g2 = ⌊log2 2⌋ = 1, g3 = ⌊log2 3⌋ = 1 g4 = ⌊log2 4⌋ = 2, g5 = ⌊log2 5⌋ = 2 g6 = ⌊log2 6⌋ = 2, g7 = ⌊log2 7⌋ = 2 g8 = ⌊log2 8⌋ = 3, g9 = ⌊log2 9⌋ = 3

g10 = ⌊log2 10⌋ = 3, g11 = ⌊log2 11⌋ = 3 g12 = ⌊log2 12⌋ = 3, g13 = ⌊log2 13⌋ = 3 g14 = ⌊log2 14⌋ = 3, g15 = ⌊log2 15⌋ = 3 When n is an integral power of 2, gn is the exponent of that power. For instance, 8 = 23 and g8 = 3. More generally, if n = 2k , where k is an integer, then gn = k. All terms of the sequence from gn up to gm , where m = 2k+1 is the next integral power of 2, have the same value as gn , namely k. For instance, all terms of the sequence from g8 through g15 have the value 3.

Exercises 10–16 have more than one correct answer.

10. an = (−1)n , where n is an integer and n ≥ 1. 11. an = (n − 1)(−1)n , where n is an integer and n ≥ 1. 12. an =

n (n + 1)2 , where n is an integer and n ≥ 1

14. an = n2

3n , where n is an integer and n ≥ 1

18. a. 2 + 3 + (−2) + 1 + 0 + (−1) + (−2) = 1 b. a0 = 2 c. a2 + a4 + a6 = −2 + 0 + (−2) = −4 d. 2 ·3 ·(−2) ·1 ·0 · (−1) ·(−2) = 0

19. 2 + 3 + 4 + 5 + 6 = 20 20. 22 ·32 ·42 = 576 23. 1(1 + 1) = 2 27. (

1 1 − 1

2

) + (

1 2 − 1

3

) + (

1 3 − 1

4

) + (

1 4 − 1

5

)

+ (

1 5 − 1

6

) + (

1 6 − 1

7

) + (

1 7 − 1

8

) + (

1 8 − 1

9

)

+ (

1 9 − 1

10

) + (

1 10 − 1

11

) = 1− 1

11 = 10

11

29. (−2)1 + (−2)2 + (−2)3 + · · · + (−2)n = −2 + 22 − 23 + · · · + (−1)n2n

31. n+1∑ k=0

1 k! = 10! + 11! + 12! + · · · + 1(n+1)!

33. 11! = 1 35. (

1 1+1 ) (

2 2+1 ) (

3 3+1 )

= (

1 2

) ( 2 3

) ( 3 4

) = 14

37. k+1∑ k=1

i(i !) = k∑

k=1 i(i !) + (k + 1)(k + 1)!

40. k∑

k=1 i3 + (k + 1)3 =

k+1∑ k=1

i3

Exercises 43–52 have more than one correct answer.

43. 7∑

k=1 (−1)k+1k2 or

6∑

k=0 (−1)k(k + 1)2

46. 6∑

j=2

(−1) j j ( j + 1)( j + 2) or

7∑

k=3

(−1)k+1(k − 1) k(k + 1)

47. 5∑

i=0 (−1)i r i 49.

n∑

k=1 k3

51. n−1∑

i=0 (n − i)

53. When k = 0, then i = 1. When k = 5, then i = 6. Since i = k + 1, then k = i − 1. Thus,

k(k − 1) = (i − 1)((i − 1)− 1) = (i − 1)(i − 2), and so

5∑

k=0 k(k − 1) =

6∑

i=1 (i − 1)(i − 2)

55. When i = 1, then j = 0. When i = n + 1, then j = n. Since j = i − 1, then i = j + 1. Thus,

(i − 1)2 i ·n =

(( j + 1)− 1)2 ( j + 1) ·n =

j2

jn + n .

(Note that n is constant as far as the sum is concerned.)

So ∑n+1

i=1 (i − 1)2

i ·n = ∑n

j=0 j2

jn + n .

56. When i = 3, then j = 2. When i = n then j = n − 1. Since j = i − 1, then i = j + 1. Thus,

n∑

i=3

i i + n − 1 =

n−1∑

j=2

j + 1 ( j + 1) + n − 1

= n−1∑

j=2

j + 1 j + n .

59. n∑

k=1 [3(2k − 3) + (4− 5k)]

= n∑

k=1 [(6k − 9) + (4− 5k)] =

n∑

k=1 (k − 5)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-32 Appendix B Solutions and Hints to Selected Exercises

62. 4 ·3 ·2 ·1 3 ·2 ·1 = 4

65. n(n − 1)(n − 2) · · · 3 ·2 ·1 (n − 1)(n − 2) · · · 3 ·2 ·1 = n

66. (n − 1)(n − 2) · · · 3 ·2 ·1

(n + 1)n(n − 1)(n − 2) · · · 3 ·2 ·1 = 1

n(n + 1)

68. [(n + 1)n(n − 1)(n − 2) · · · 3 ·2 ·1]2

[n(n − 1)(n − 2) · · · 3 ·2 ·1]2 = (n + 1) 2

69. n(n − 1)(n − 2) · · · (n − k + 1)(n − k)(n − k − 1) · · · 2 ·1

(n − k)(n − k − 1) · · · 2 ·1 = n(n − 1)(n − 2) · · · (n − k + 1)

71. (

5 3

) = 5!

(3!)(5−3)! = 5 ·4 ·3 ·2 ·1

(3 ·2 ·1)(2 ·1) = 10

73. (

3 0

) = 3!

(0!)(3−0)! = 3!

(1)(3!) = 1

75. (

n n − 1

) = n!

(n−1)!(n−(n−1))! = n(n−1)!

(n−1)!(n−n+1)! = n 1 = n

77. a. Proof: Let n be an integer such that n ≥ 2. By definition of factorial,

n! =

⎧ ⎨

2 ·1 if n = 2 3 ·2 ·1 if n = 3 n ·(n − 1) · · · 2 ·1 if n > 3.

In each case, n! has a factor of 2, and so n! = 2k for some integer k. Then

n! + 2 = 2k + 2 by substitution = 2(k + 1) by factoring out the 2.

Since k + 1 is an integer, n! + 2 is divisible by 2 [as was to be shown].

c. Hint: Consider the sequence m! + 2, m! + 3, m! + 4, . . . , m! + m.

78. Proof: Suppose n and r are nonnegative integers with r + 1 ≤ n. The right-hand side of the equation to be shown is

n − r r + 1 ·

( n r

) = n − r

r + 1 · n!

r !(n − r)!

= n − r r + 1 ·

n! r !(n − r) ·(n − r − 1)!

= n! (r + 1)! ·(n − r − 1)!

= n! (r + 1)! ·(n − (r + 1))!

= (

n r + 1

) ,

which is the left-hand side of the equation to be shown. 80. a. m − 1, sum +a[i + 1]

81. 0 remainder = r [6] = 1 2 1 remainder = r [5] = 0

2 2 remainder = r [4] = 1 2 5 remainder = r [3] = 1

2 11 remainder = r [2] = 0 2 22 remainder = r [1] = 1

2 45 remainder = r [0] = 0 2 90

Hence 9010 = 10110102. 84. a 23

i 0 1 2 3 4 5

q 23 11 5 2 1 0

r[0] 1

r[1] 1

r[2] 1

r[3] 0

r[4] 1

88. 0 remainder 1 = r [2] = 116 16 1 remainder 1 = r [1] = 116

16 17 remainder 15 = r [0] = F16 16 287

Hence 28710 = 11F16.

Section 5.2 1. Proof: Let P(n) be the property “n cents can be obtained

by using 3-cent and 8-cent coins.” Show that P(14) is true: Fourteen cents can be obtained by using two 3-cent coins and one 8-cent coin.

Show that for all integers k ≥ 14, if P(k) is true, then P(k + 1) is true: Suppose k cents (where k ≥ 14) can be obtained using 3- cent and 8-cent coins. [Inductive hypothesis] We must show that k + 1 cents can be obtained using 3-cent and 8-cent coins. If the k cents includes an 8-cent coin, replace it by three 3-cent coins to obtain a total of k + 1 cents. Other- wise the k cents consists of 3-cent coins exclusively, and so there must be least five 3-cent coins (since the total amount is at least 14 cents). In this case, replace five of the 3- cent coins by two 8-cent coins to obtain a total of k + 1 cents. Thus, in either case, k + 1 cents can be obtained using 3-cent and 8-cent coins. [This is what we needed to show.]

[Since we have proved the basis step and the inductive step, we conclude that the given statement is true for all integers n ≥ 14.]

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.2 Solutions and Hints to Selected Exercises A-33

3. a. P(1) is “12 = 1 · (1+1) · (2 ·1+1)6 .” P(1) is true because 12 = 1 and 1 · (1+1) · (2+1)6 = 2 ·36 = 1 also.

b. P(k) is “12 + 22 + · · · + k2 = k(k+1)(2k+1)6 .”

c. P(k + 1) is “12 + 22 + · · · + (k + 1)2

= (k+1)((k+1)+1)(2 · (k+1)+1)6 .” d. Must show: If for some integer k ≥ 1,

12 + 22 + · · · + k2 = k(k+1)(2k+1)6 , then 12 + 22 + · · · + (k + 1)2

= (k+1)[(k+1)+1][(2(k+1)+1)]6 . 5. a. 12 b. k2

c. 1 + 3 + 5 + · · · + [2(k + 1)− 1] d. (k + 1)2 e. the odd integer just before 2k + 1 is 2k − 1 f. inductive hypothesis

6. Proof: For the given statement, the property P(n) is the equation

2 + 4 + 6 + · · · + 2n = n2 + n. ← P(n) Show that P(1) is true: To prove P(1), we must show that when 1 is substituted into the equation in place of n, the left-hand side equals the right-hand side. But when 1 is substituted for n, the left-hand side is the sum of all the even integers from 2 to 2 ·1, which is just 2, and the right-hand side is 12 + 1, which also equals 2. Thus P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k+1) is true: Let k be any integer with k ≥ 1, and suppose P(k) is true. That is, suppose

2 + 4 + 6 + · · · + 2k = k2 + k. ← P(k) inductive hypothesis

We must show that P(k + 1) is true. That is, we must show that

2 + 4 + 6 + · · · + 2(k + 1) = (k + 1)2 + (k + 1). Because (k + 1)2 + (k + 1) = k2 + 2k + 1 + k + 1 = k2 + 3k + 2, this is equivalent to showing that 2 + 4 + 6 + · · · + 2(k + 1) = k2 + 3k + 2. ← P(k + 1)

But the left-hand side of P(k + 1) is 2 + 4 + 6 + · · · + 2(k + 1)

= 2 + 4 + 6 + · · · + 2k + 2(k + 1) by making the next-to-last term explicit

= (k2 + k) + 2(k + 1) by substitution from the inductive hypothesis

= k2 + 3k + 2, by algebra,

and this is the right-hand side of P(k + 1). Hence P(k + 1) is true. [Since both the basis step and the inductive step have been proved, P(n) is true for all integers n ≥ 1.]

8. Proof: For the given statement, the property P(n) is the equation

1 + 2 + 22 + · · · + 2n = 2n+1 − 1. ← P(n) Show that P(0) is true: The left-hand side of P(0) is 1, and the right-hand side is 20+1 − 1 = 2− 1 = 1 also. Thus P(0) is true. Show that for all integers k ≥ 0, if P(k) is true then P(k+1) is true: Let k be any integer with k ≥ 0, and suppose P(k) is true. That is, suppose

1 + 2 + 22 + · · · + 2k = 2k+1 − 1. ← P(k) inductive hypothesis

We must show that P(k + 1) is true. That is, we must show that

1 + 2 + 22 + · · · + 2k+1 = 2(k+1)+1 − 1, or, equivalently,

1 + 2 + 22 + · · · + 2k+1 = 2k+2 − 1.← P(k + 1) But the left-hand side of P(k + 1) is 1 + 2 + 22 + · · · + 2k+1

= 1 + 2 + 22 + · · · + 2k + 2k+1 by making the next-to-last term explicit

= (2k+1 − 1) + 2k+1 by substitution from the inductive hypothesis

= 2 ·2k+1 − 1 by combining like terms = 2k+2 − 1, by the laws of exponents,

and this is the right-hand side of P(k + 1). Hence the prop- erty is true for n = k + 1. [Since both the basis step and the inductive step have been proved, P(n) is true for all integers n ≥ 0.]

10. Proof: For the given statement, the property is the equation

12 + 22 + 32 + · · · + n2

= n(n + 1)(2n + 1) 6

. ← P(n)

Show that P(1) is true: The left-hand side of P(1) is 12 = 1, and the right-hand side is 1(1+1)(2 ·1+1)6 = 2 ·36 = 1 also. Thus P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k+1) is true: Let k be any integer with k ≥ 1, and suppose P(k) is true. That is, suppose

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-34 Appendix B Solutions and Hints to Selected Exercises

12 + 22 + 32 + · · · + k2

= k(k + 1)(2k + 1) 6

. ← P(k) inductive hypothesis

We must show that P(k + 1) is true. That is, we must show that

12 + 22 + 32 + · · · + (k + 1)2

= (k + 1)((k + 1) + 1)(2(k + 1) + 1) 6

,

or, equivalently,

12 + 22 + 32 + · · · + (k + 1)2

= (k + 1)(k + 2)(2k + 3) 6

. ← P(k + 1)

But the left-hand side of P(k + 1) is 12 + 22 + 32 + · · · + (k + 1)2 = 12 + 22 + 32 + · · · + k2 + (k + 1)2 by making the next-

to-last term explicit

= k(k + 1)(2k + 1) 6

+ (k + 1)2 by substitution from the inductive hypothesis

= k(k + 1)(2k + 1) 6

+ 6(k + 1) 2

6

because 6 6 = 1

= k(k + 1)(2k + 1) + 6(k + 1) 2

6 by adding fractions

= (k + 1)[k(2k + 1) + 6(k + 1)] 6

by factoring out (k + 1)

= (k + 1)(2k 2 + 7k + 6) 6

by multiplying out and combining like terms

= (k + 1)(k + 2)(2k + 3) 6

because (k + 2) (2k + 3)= 2k2 + 7k + 6,

and this is the right-hand side of P(k + 1). Hence the prop- erty is true for n = k + 1. [Since both the basis step and the inductive step have been proved, P(n) is true for all integers n ≥ 1.]

13. Proof: For the given statement, the property P(n) is the equation

n−1∑

i=1 i(i + 1) = n(n − 1)(n + 1)

3 . ← P(n)

Show that P(2) is true: The left-hand side of P(2) is

∑1 i=1 i(i +1) =1·(1+1)=2,

and the right-hand side is 2(2−1)(2+1)3 = 6 3 = 2 also.

Thus P(2) is true.

Show that for all integers k ≥ 2, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 2, and suppose P(k) is true. That is, suppose

k−1∑

i=1 i(i + 1) = k(k − 1)(k + 1)

3 ← P(k) inductive hypothesis

We must show that P(k + 1) is true. That is, we must show that

(k+1)−1∑

i=1 i(i + 1) = (k + 1)((k + 1)− 1)((k + 1) + 1)

3 ,

or, equivalently,

k∑

i=1 i(i + 1) = (k + 1)k(k + 2)

3 . ← P(k + 1)

But the left-hand side of P(k + 1) is k∑

i=1 i(i + 1)

= k−1∑

i=1 i(i + 1) + k(k + 1) by writing the last

term separately

= k(k − 1)(k + 1) 3

+ k(k + 1) by substitution from the inductive hypothesis

= k(k − 1)(k + 1) 3

+ 3k(k + 1) 3

because 3 3 = 1

= k(k − 1)(k + 1) + 3k(k + 1) 3

by adding the fractions

= k(k + 1)[(k − 1) + 3] 3

by factoring out k(k + 1)

= k(k + 1)(k + 2) 3

, by algebra,

and this is the right-hand side of P(k + 1). Hence P(k + 1) is true. [Since both the basis step and the inductive step have been proved, P(n) is true for all integers n ≥ 0.]

15. Hint: To prove the basis step, show that ∑1

i=1 i(i !) = (1 + 1)!− 1. To prove the inductive step, suppose that∑k

i=1 i(i !) = (k + 1)!− 1 for some integer k ≥ 1 and show that ∑k+1

i=1 i(i !) = (k + 2)!− 1. Note that [(k + 1)!− 1] + (k + 1)[(k + 1)!] = (k + 1)![1 + (k + 1)]− 1.

18. Hints: sin2 x + cos2 x = 1, cos(2x) = cos2 x − sin2 x = 1− 2 sin2 x , sin(a + b) = sin a cos b + cos a sin b, sin(2x)= 2 sin x cos x, cos(a + b) = cos a cos b − sin a sin b.

20. 4 + 8 + 12 + 16 + · · · + 200 = 4(1 + 2 + 3 + · · · + 50) = 4 (

50 ·51 2

) = 5100

22. 3 + 4 + 5 + 6 + · · · + 1000 = (1 + 2 + 3 + 4 + · · · + 1000)− (1 + 2) =

( 1000 · 1001

2

) −3 = 500,497

24. (k−1)((k−1)+1)2 = k(k−1)2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Solutions and Hints to Selected Exercises A-35

25. a. 226 − 1 2− 1 = 2

26 − 1 = 67,108,863 b. 2 + 22 + 23 + · · · + 226

= 2(1 + 2 + 22 + · · · + 225) = 2 ·(67,108,863) by part (a) = 134,217,726

28.

( 1 2

)n+1 − 1

1 2 − 1

= 1

2n+1 − 1

−1 2

= (

1 2n+1

− 1 )

(−2)

= − 2 2n+1

+ 2 = 2− 1 2n

30. Hint: c + (c + d) + (c + 2d) + · · · + (c + nd) = (n + 1) c + d · n(n+1)2 .

33. In the inductive step, both the inductive hypothesis and what is to be shown are wrong. The inductive hypothesis should be Suppose that for some integer k ≥ 1,

12 + 22 + · · · + k2 = k(k + 1)(2k + 1) 6

.

And what is to be shown should be

12 + 22 + · · · + (k + 1)2

= (k + 1)((k + 1) + 1)(2(k + 1) + 1) 6

.

34. Hint: See the Caution note for Example 5.1.8. 35. Hint: See the subsection Proving an Equality on page 254. 37. Hint: Form the sum n2 + (n + 1)2 + (n + 2)2 + · · · +

(n + (p − 1))2, and show that it equals pn2 + 2n(1 + 2 + 3 + · · · + (p − 1))

+ (1 + 4 + 9 + 16 + · · · + (p − 1)2).

Section 5.3 1. General formula:

∏n i=2 ( 1− 1i )

= 1n for all integers n ≥ 2. Proof (by mathematical induction): Let the property P(n) be the equation

n∏

i=2

( 1− 1

i

) = 1

n . ← P(n)

Show that P(2) is true:

The left-hand side of P(2) is ∏2

i=2

( 1− 1i )

= 1− 12 = 1 2 ,

which equals the right-hand side. Show that for all integers k ≥ 2, if P(k) is true then P(k + 1) is also true: Suppose that k is any integer with k ≥ 2 such that

k∏

i=2

( 1− 1i )

= 1k . ← P(k) Inductive hypothesis

We must show that k+1∏

i=2

( 1− 1i )

= 1k+1 . ← P(k + 1)

But by the laws of algebra and substitution from the induc- tive hypothesis, the left-hand side of P(k + 1) is

k+1∏

i=2

( 1− 1

i

)

= k∏

i=2

( 1− 1

i

)( 1− 1

k + 1

)

= (

1 k

)( 1− 1

k + 1

) = (

1 k

)( (k + 1)− 1

k + 1

)

= 1 k + 1 which is the right-hand side of P(k + 1)

[as was to be shown].

3. General formula: 11 ·3 + 13 ·5 + · · · + 1(2n−1)(2n+1) = n

2n+1 for all integers n ≥ 1.

Proof (by mathematical induction): Let the property P(n) be the equation

1 1 ·3 + 13 ·5 + · · · + 1(2n−1)(2n+1) = n2n+1 .

Show that P(1) is true:

The left-hand side of P(1) equals 11 ·3 , and the right-hand side equals 12 ·1+1 . But both of these equal 13 , so P(1) is true.

Show that for any integer k ≥ 1, if P(k) is true then P(k + 1) is true: Suppose that k is any integer with k ≥ 1, and

1 1 ·3 +

1 3 ·5 + · · · +

1 (2k − 1)(2k + 1) =

k 2k + 1

↑ P(k) inductive hypothesis

We must show that 1

1 ·3 + 1

3 ·5 + · · · + 1

(2(k + 1)− 1)(2(k + 1) + 1)

= k + 1 2(k + 1) + 1 .

or, equivalently,

1 1 ·3 +

1 3 ·5 + · · · +

1 (2k + 1)(2k + 3) =

k + 1 2k + 3 .

↑ P(k + 1)

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-36 Appendix B Solutions and Hints to Selected Exercises

But the left-hand side of P(k + 1) is 1

1 ·3 + 1

3 ·5 + · · · + 1

(2k + 1)(2k + 3)

= 1 1 ·3 +

1 3 ·5 + · · · +

1 (2k − 1)(2k + 1)

+ 1 (2k + 1)(2k + 3)

= k 2k + 1 +

1 (2k + 1)(2k + 3) by inductivehypothesis

= k(2k + 3) (2k + 1)(2k + 3) +

1 (2k + 1)(2k + 3)

= 2k 2 + 3k + 1

(2k + 1)(2k + 3)

= (2k + 1)(k + 1) (2k + 1)(2k + 3)

= k + 1 2k + 3 by algebra,

and this is the right-hand side of P(k + 1) [as was to be shown].

4. Hint 1: The general formula is

1− 4 + 9− 16 + · · · + (−1)n−1n2 = (−1)n−1(1 + 2 + 3 + · · · + n) in expanded form

Or: n∑

i=1 (−1)i−1i2 = (−1)n−1

( n∑

i=1 i

) in summation notation.

Hint 2: In the proof, use the fact that

1 + 2 + 3 + · · · + n = n∑

i=1 i = n(n + 1)

2 .

6. a. P(0) is “50 − 1 is divisible by 4.” P(0) is true because 50 − 1 = 0, which is divisible by 4.

b. P(k) is “5k − 1 is divisible by 4.” c. P(k + 1) is “5k+1 − 1 is divisible by 4.” d. Must show: If for some integer k ≥ 0, 5k − 1 is divisible

by 4, then 5k+1 − 1 is divisible by 4. 8. Proof (by mathematical induction): For the given state-

ment, the property is the sentence “5n − 1 is divisible by 4.” Show that P(0) is true: P(0) is the sentence “50 − 1 is divisible by 4.” But 50 − 1 = 1− 1 = 0, and 0 is divisible by 4 because 0 = 4 ·0. Thus P(0) is true. Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 0, and suppose P(k) is true. That is, suppose 5k − 1 is divisible by 4. [This is the induc- tive hypothesis.] We must show that P(k + 1) is true. That is, we must show that 5k+1 − 1 is divisible by 4. Now

5k+1 − 1 = 5k ·5− 1 = 5k · (4 + 1)− 1 = 5k ·4 + (5k − 1). (*)

By the inductive hypothesis 5k − 1 is divisible by 4, and so 5k − 1 = 4r for some integer r . By substitution into equa- tion (∗),

5k+1 − 1 = 5k ·4 + 4r = 4(5k + r). But 5k + r is an integer because k and r are integers. Hence, by definition of divisibility, 5k+1 − 1 is divisible by 4 [as was to be shown].

An alternative proof of the inductive step goes as follows: Suppose that for some integer k ≥ 0, 5k − 1 is divisible by 4. Then 5k − 1 = 4r for some integer r , and hence 5k = 4r + 1. It follows that 5k+1 = 5k ·5 = (4r + 1) ·5 = 20r + 5. Sub- tracting 1 from both sides gives that 5k+1 − 1 = 20r + 4 = 4(5r + 1). But 5r + 1 is an integer, and so, by definition of divisibility, 5k+1 − 1 is divisible by 4.

11. Proof (by mathematical induction): For the given state- ment, the property P(n) is the sentence “32n − 1 is divisible by 8.”

Show that P(0) is true:

P(0) is the sentence “32 · 0 − 1 is divisible by 8.” But 32 · 0 − 1 = 1− 1 = 0, and 0 is divisible by 8 because 0 = 8 ·0. Thus P(0) is true. Show that for all integers k ≥ 0, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 0, and suppose P(k) is true. That is, suppose 32k − 1 is divisible by 8. [This is the induc- tive hypothesis.] We must show that P(k + 1) is true. That is, we must show that 32(k+1) − 1 is divisible by 8, or equiv- alently, 32k+2 − 1 is divisible by 8. Now

32k+2 − 1 = 32k ·32 − 1 = 32k ·9− 1 = 32k · (8 + 1)− 1 = 32k ·8 + (32k − 1) · (*)

By the inductive hypothesis 32k − 1 is divisible by 8, and so 32k − 1 = 8r for some integer r . By substitution into equation (∗),

32k+2 − 1 = 32k ·8 + 8r = 8(32k + r).

But 32k + r is an integer because k and r are integers. Hence, by definition of divisibility, 32k+2 − 1 is divisible by 8 [as was to be shown].

13. Hint: xk+1 − yk+1 = xk+1 − x · yk + x · yk − yk+1 = x · (xk − yk) + yk ·(x − y)

14. Hint 1: (k + 1)3 − (k + 1) = k3 + 3k2 + 3k + 1− k − 1 = (k3 − k) + 3k2 + 3k = (k3 − k) + 3k(k + 1)

Hint 2: k(k + 1) is a product of two consecutive integers. By Theorem 4.4.3, one of these must be even.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.3 Solutions and Hints to Selected Exercises A-37

16. Proof (by mathematical induction): For the given state- ment, let the property P(n) be the inequality 2n < (n + 1)!. Show that P(2) is true: P(2) says that 22 < (2 + 1)!. The left-hand side is 22 = 4 and the right-hand side is 3! = 6. So, because 4 < 6, P(2) is true. Show that for all integers k ≥ 2, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 2, and suppose P(k) is true. That is, suppose 2k < (k + 1)!. [This is the induc- tive hypothesis.] We must show that P(k + 1) is true. That is, we must show that 2k+1 < ((k + 1) + 1), or, equiva- lently, 2k+1 < (k + 2)!. By the laws of exponents and the inductive hypothesis,

2k+1 = 2 ·2k < 2(k + 1)!. (*) Since k ≥ 2, then 2 < k + 2, and so

2(k + 1)! < (k + 2)(k + 1)! = (k + 2)!. (**) Combining inequalities (∗) and (∗∗) gives

2k+1 < (k + 2)! [as was to be shown].

19. Proof (by mathematical induction): For the given state- ment, let the property P(n) be the inequality n2 < 2n .

Show that P(5) is true:

P(5) says that 52 < 25. But 52 = 25 and 25 = 32, and 25 < 32. Hence P(5) is true.

Show that for any integer k ≥ 5, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 5, and suppose P(k) is true. That is, suppose k2 < 2k . [This is the inductive hypothesis.] We must show that P(k + 1) is true. That is, we must show that (k + 1)2 < 2k+1. But

(k + 1)2 = k2 + 2k + 1 < 2k + 2k + 1 by inductive hypothesis Also, by Proposition 5.3.2,

2k + 1 < 2k Prop. 5.3.2 applies since k ≥ 5 ≥ 3. Putting these inequalities together gives

(k + 1)2 < 2k + 2k + 1 < 2k + 2k = 2k+1

[as was to be shown]. 24. Proof (by mathematical induction): For the given state-

ment, let the property P(n) be the equation an = 3 ·7n−1. Show that P(1) is true:

The left-hand side of P(1) is a1, which equals 3 by defi- nition of the sequence. The right-hand side is 3 ·71−1 = 3 also. Thus P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true then P(k + 1) is true: Let k be any integer with k ≥ 1, and suppose P(k) is true. That is, suppose ak = 3 ·7k−1. [This is the inductive

hypothesis.] We must show that P(k + 1) is true. That is, we must show that ak+1 = 3 ·7(k+1)−1, or, equivalently, ak+1 = 3 ·7k . But the left-hand side of P(k + 1) is

ak+1 = 7ak by definition of the sequencea1, a2, a3, . . . = 7(3 ·7k−1) by inductive hypothesis = 3 ·7k by the laws of exponents,

and this is the right-hand side of P(k + 1) [as was to be shown].

30. The inductive step fails for going from n = 1 to n = 2, because when k = 1,

A = {a1, a2} and B = {a1}, and no set C can be defined to have the properties claimed for the C in the proof. The reason is that C = {a1} = B, and so an element of A, namely a2, is not in either B or C .

Since the inductive step fails for going from n = 1 to n = 2, the truth of the following statement is never proved: “All the numbers in a set of two numbers are equal to each other.” This breaks the sequence of inductive steps, and so none of the statements for n > 2 is proved true either.

Here is an explanation for what happens in terms of the domino analogy. The first domino is tipped backward (the basis step is proved). Also, if any domino from the second onward tips backward, then it tips the one behind it backward (the inductive step works for n ≥ 2). However, when the first domino is tipped backward, it does not tip the second one backward. So only the first domino falls down; the rest remain standing.

31. Hint: Is the basis step true? 32. Hint: Consider the problem of trying to cover a 3× 3

checkerboard with trominoes. Place a checkmark in certain squares as shown in the following figure.

$ $

$ $ Observe that no two squares containing checkmarks can be covered by the same tromino. Since there are four check- marks, four tromiones would be needed to cover these squares. But, since each tromino covers three squares, four trominoes would cover twelve squares, not the nine squares in this checkerboard. It follows that such a covering is impossible.

34. a. Hint: For the inductive step, note that a 3× (2(k + 1)) checkerboard can be split into a 3× 2k checkerboard and a 3× 2 checkerboard.

35. b. Hint: Consider a 3× 5 checkerboard, and refer to the hint for exercise 32. Figure out a way to place six checkmarks in squares so that no two of the squares that contain checkmarks can be covered by the same tromino.

37. Hint: Use proof by contradiction. If the statement is false, then there exists some ordering of the integers from 1 to 30, say x1, x2, . . . , x30, such that x1 + x2 + x3 < 45,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-38 Appendix B Solutions and Hints to Selected Exercises

x2 + x3 + x4 < 45, . . . , and x30 + x1 + x2 < 45. Evalu- ate the sum of all these inequalities using the fact that∑30

i=1 xi = ∑30

i=1 i and Theorem 4.2.2. 38. Hint: Given k + 1 a’s and k + 1 b’s arrayed around the out-

side of the circle, there has to be at least one location where an a is followed by a b as one travels in the clockwise direc- tion. In the inductive step, temporarily remove such an a and the b that follows it, and apply the inductive hypothesis.

Section 5.4 1. Proof (by strong mathematical induction): Let the property

P(n) be the sentence “an is odd.” Show that P(1) and P(2) are true: Observe that a1 = 1 and a2 = 3 and both 1 and 3 are odd. Thus P(1) and P(2) are true. Show that for any integer k ≥ 2, if P(i) is true for all inte- gers i with 1 ≤ i ≤ k, then P(k + 1) is true: Let k ≥ 2 be any integer, and suppose ai is odd for all integers i with 1 ≤ i ≤ k. [This is the inductive hypothe- sis.] We must show that ak+1 is odd. We know that ak+1 = ak−1 + 2ak by definition of a1, a2, a3, . . . . Moreover, k − 1 is less than k + 1 and is greater than or equal to 1 (because k ≥ 2). Thus, by inductive hypothesis, ak−1 is odd. Also, every term of the sequence is an integer (being a sum of products of integers), and so 2ak is even by definition of even. Hence ak+1 is the sum of an odd integer and an even integer and hence is odd (by exercise 19, in Section 4.1). [This is what was to be shown.]

4. Proof (by strong mathematical induction): Let the property P(n) be the inequality dn ≤ 1. Show that P(1) and P(2) are true:

Observe that d1 = 910 and d2 = 10 11 and both

9 10 ≤ 1 and

10 11 ≤ 1. Thus P(1) and P(2) are true. Show that for any integer k ≥ 2, if P(i) is true for all inte- gers i with 1 ≤ i ≤ k, then P(k + 1) is true: Let k ≥ 2 be any integer, and suppose di ≤ 1 for all integers i with 1 ≤ i ≤ k. [This is the inductive hypoth- esis.] We must show that dk+1 ≤ 1. But, by defini- tion of d1, d2, d3, . . . , dk+1 = dk ·dk−1. Now dk ≤ 1 and dk−1 ≤ 1 by inductive hypothesis [since 1 ≤ k < k + 1 and 1 ≤ k − 1 < k + 1 because k ≥ 2.]. Consequently, dk+1 = dk ·dk−1 ≤ 1 because if two positive numbers are each less than or equal to 1, then their product is less than or equal to 1. [If 0 < a ≤ 1 and 0 < b ≤ 1, then multiplying a ≤ 1 by b gives ab ≤ b, and since b ≤ 1, then by transitivity of order, ab ≤ 1.] This is what was to be shown. [Since we have proved both the basis step and the inductive step, we conclude that dn ≤ 1 for all integers n ≥ 1.]

5. Proof (by strong mathematical induction): Let the property P(n) be the equation en = 5 ·3n + 7 ·2n . Show that P(0) and P(1) are true. We must show that e0 = 5 ·30 + 7 ·20 and e1 = 5 ·31 + 7 ·21. The left-hand side of the first equation is 12 (by

definition of e0, e1, e2, . . .), and its right-hand side is 5 ·1 + 7 ·1 = 12 also. The left-hand side of the second equation is 29 (by definition of e0, e1, e2, . . .), and its right-hand side is 5 ·3 + 7 ·2 = 29 also. Thus P(0) and P(1) are true. Show that for any integer k ≥ 1, if P(i) is true for all inte- gers i with 0 ≤ i ≤ k, then P(k + 1) is true: Let k ≥ 1 be an integer, and suppose ei = 5 ·3i + 7 ·2i for all integers i with 0 ≤ i ≤ k. [Inductive hypothesis] We must show that ek+1 = 5 ·3k+1 + 7 ·2k+1. But

ek+1 = 5ek − 6ek−1 by definition of e0, e1, e2, . . . = 5(5 ·3k + 7 ·2k)− 6(5 ·3k−1 + 7 ·2k−1)

by inductive hypothesis

= 25 ·3k + 35 ·2k − 30 ·3k−1 − 42 ·2k−1 = 25 ·3k + 35 ·2k − 10 ·3 ·3k−1 − 21 ·2 ·2k−1 = 25 ·3k + 35 ·2k − 10 ·3k − 21 ·2k = (25− 10) ·3k + (35− 21) ·2k = 15 ·3k + 14 ·2k = 5 ·3 ·3k + 7 ·2 ·2k = 5 ·3k+1 + 7 ·2k+1 by algebra.

[This is what was to be shown.]

10. Hint: In the basis step, show that P(14), P(15), and P(16) are all true. For the inductive step, note that k + 1 = [(k + 1)− 3] + 3, and if k ≥ 16, then (k + 1)− 3 ≥ 14.

11. Proof (by strong mathematical induction): Let the property P(n) be the sentence

“A jigsaw puzzle consisting of n pieces takes n − 1 steps to put together.”

Show that P(1) is true: A jigsaw puzzle consisting of just one piece does not take any steps to put together. Hence it is correct to say that it takes zero steps to put together. Show that for any integer k ≥ 1, if P(i) is true for all inte- gers i with 1 ≤ i ≤ k then P(k + 1) is true: Let k ≥ 1 be an integer and suppose that for all integers i with 1 ≤ i ≤ k, a jigsaw puzzle consisting of i pieces takes i − 1 steps to put together. [This is the inductive hypothesis.] We must show that a jigsaw puzzle consist- ing of k + 1 pieces takes k steps to put together. Con- sider assembling a jigsaw puzzle consisting of k + 1 pieces. The last step involves fitting together two blocks. Suppose one of the blocks consists of r pieces and the other con- sists of s pieces. Then r + s = k + 1, and 1 ≤ r ≤ k and 1 ≤ s ≤ k. Thus by inductive hypothesis, the numbers of steps required to assemble the blocks are r − 1 and s − 1, respectively. Then the total number of steps required to assemble the puzzle is (r − 1) + (s − 1) + 1 = (r + s)− 1 = (k + 1)− 1 = k [as was to be shown].

12. Hint: For any collection of cans, at least one must contain enough gasoline to enable the car to get to the next can. (Why?) Imagine taking all the gasoline from that can and

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.4 Solutions and Hints to Selected Exercises A-39

pouring it into the can that immediately precedes it in the direction of travel around the track.

13. Sketch of proof: Given any integer k > 1, either k is prime or k is a product of two smaller positive integers, each greater than 1. In the former case, the property is true. In the latter case, the inductive hypothesis ensures that both factors of k are products of primes and hence that k is also a product of primes.

14. Proof (by strong mathematical induction): Let the property P(n) be the sentence “Any product of n odd integers is odd.” Show that P(2) is true: We must show that any product of two odd integers is odd. But this was established in Chapter 4 (exercise 43 of Sec- tion 4.1). Show that for any integer k ≥ 2, if P(i) is true for all inte- gers i with 2 ≤ i ≤ k then P(k + 1) is true: Let k be any integer with k ≥ 2, and suppose that for all integers i with 2 ≤ i ≤ k, any product of i odd integers is odd. [Inductive hypothesis] Consider any product M of k + 1 odd integers. Some multiplication is the final one that is used to obtain M . Thus there are integers A and B such that M = AB, and each of A and B is a product of between 1 and k odd integers. (For instance, if M = ((a1a2)a3)a4, then A = (a1a2)a3 and B = a4.) By inductive hypothesis, each of A and B is odd, and, as in the basis step, we know that any product of two odd integers is odd. Hence M = AB is odd.

16. Hint: Let the property P(n) be the sentence “If n is even, then any sum of n odd integers is even, and if n is odd, then any sum of n odd integers is odd.” For the inductive step, consider any sum S of k + 1 odd integers. Some addition is the final one that is used to obtain S. Thus there are integers A and B such that S = A + B, and A is a sum of r odd integers and B is a sum of (k + 1)− r odd integers. Con- sider the two cases where k + 1 is even and k + 1 is odd, and for each case consider the two subcases where r is even and where r is odd.

17. 41 = 4, 42 = 16, 43 = 64, 44 = 256, 45 = 1024, 46 = 4096, 47 = 16384, and 48 = 65536. Conjecture: The units digit of 4n equals 4 if n is odd and equals 6 if n is even. Proof by strong mathematical induction: Let the property P(n) be the sentence “The units digit of 4n equals 4 if n is odd and equals 6 if n is even.” Show that P(1) and P(2) are true: When n = 1, 4n = 41 = 4, and the units digit is 4. When n = 2, then 4n = 42 = 16, and the units digits is 6. Thus P(1) and P(2) are true. Show that for any integer k ≥ 2, if the property is true for all integers i with 1 ≤ i ≤ k then it is true for k+1: Let k by any integer with k ≥ 2, and suppose that for all integers i with 0 ≤ i ≤ k, the units digit of 4i equals 4 if i is odd and equals 6 if i is even. [Inductive hypothesis] We

must show that the units digit of 4k+1 equals 4 if k + 1 is odd and equals 6 if k + 1 is even. Case 1 (k + 1 is odd): In this case, k is even, and so, by inductive hypothesis, the units digits of 4k is 6. Thus 4k = 10q + 6 for some nonnegative integer q. It follows that 4k+1 = 4k ·4 = (10q + 6) ·4 = 40q + 24 = 10(4q + 2) + 4. Thus the units digit of 4k+1 is 4 [as was to be shown]. Case 2 (k + 1 is even): In this case, k is odd, and so, by inductive hypothesis, the units digit of 4k is 4. Thus 4k = 10q + 4 for some nonnegative integer q. It follows that 4k+1 = 4k ·4 = (10q + 4) ·4 = 40q + 16 = 10(4q + 1) + 6. Thus the units digit of 4k+1 is 6 [as was to be shown].

20. Proof: Let n be any integer greater than 1. Consider the set S of all positive integers other than 1 that divide n. Since n | n and n > 1, there is at least one element in S. Hence, by the well-ordering principle for the integers, S has a smallest element; call it p. We claim that p is prime. For suppose p is not prime. Then there are integers a and b with 1 < a < p, 1 < b < p, and p = ab. By defi- nition of divides, a | p. Also p | n because p is in S and every element in S divides n. Therefore, a | p and p | n, and so, by transitivity of divisibility, a | n. Consequently, a ∈ S. But this contradicts the fact that a < p, and p is the smallest element of S. [This contradiction shows that the supposition that p is not prime is false.] Hence p is prime, and we have shown the existence of a prime number that divides n.

22. a. Proof: Suppose r is any rational number. [We need to show that there is an integer n such that r < n.]

Case 1 (r ≤ 0): In this case, take n = 1. Then r < n. Case 2 (r > 0): In this case, r = ab for some positive integers a and b (by definition of rational and because r is positive). Note that r = ab < n if, and only if, a < nb. Let n = 2a. Multiply both sides of the inequality 1 < 2 by a to obtain a < 2a, and multiply both sides of the inequality 1 < b by 2a to obtain 2a < 2ab = nb. Thus a < 2a < nb, and so, by transitivity of order, a < nb. Dividing both sides by b gives that ab < n, or, equiva- lently, that r < n. Hence, in both cases, r < n [as was to be shown].

23. Hint: If r is any rational number, let S be the set of all inte- gers n such that r < n. Use the results of exercises 22(a), 22(c), and the well-ordering principle for the integers to show that S has a least element, say v, and then show that v − 1 ≤ r < v.

24. Proof: Let S be the set of all integers r such that n = 2i ·r for some integer i . Then n ∈ S because n = 20 ·n, and so S ̸= ∅. Also, since n ≥ 1, each r in S is positive, and so, by the well-ordering principle, S has a least element m. This means that n = 2k ·m (*) for some nonnegative integer k and m ≤ r for every r in S. We claim that m is odd. The reason is that if m were even, then m = 2p for some inte- ger p. Substituting into equation (*) gives

n = 2k ·m = 2k ·2p = (2k ·2)p = 2k+1 · p.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-40 Appendix B Solutions and Hints to Selected Exercises

It follows that p ∈ S and p < m, which contradicts the fact that m is the least element of S. Hence m is odd, and so n = m ·2k for some odd integer m and nonnegative integer k.

29. Hint: In the inductive step, divide into cases depending upon whether k can be written as k = 3x or k = 3x + 1 or k = 3x + 2 for some integer x .

30. Hint: In the inductive step, let an integer k ≥ 0 be given and suppose that there exist integers q ′ and r ′ such that k = dq ′ + r ′ and 0 ≤ r ′ < d. You must show that there exist integers q and r such that

k + 1 = dq + r and 0 ≤ r < d. To do this, consider the two cases r ′ < d − 1 and r ′ = d − 1.

31. Hint: Given a predicate P(n) that satisfies conditions (1) and (2) of the principle of mathematical induction, let S be the set of all integers greater than or equal to a for which P(n) is false. Suppose that S has one or more elements, and use the well-ordering principle to derive a contradiction.

32. Hint: Suppose S is a set containing one or more integers, all of which are greater than or equal to some integer a, and suppose that S does not have a least element. Let the property P(n) be the sentence “i /∈ S for any integer i with a ≤ i ≤ n.” Use mathematical induction to prove that P(n) is true for all integers n ≥ a, and explain how this result contradicts the supposition that S does not have a least element.

Section 5.5 1. Proof: Suppose the predicate m + n = 100 is true before

entry to the loop. Then mold + nold = 100.

After execution of the loop, mnew = mold + 1 and nnew = nold − 1,

so

mnew + nnew = (mold + 1) + (nold − 1) = mold + nold = 100.

3. Proof: Suppose the predicate m3 > n2 is true before entry to the loop. Then

m3old > n 2 old.

After execution of the loop,

mnew = 3 ·mold and nnew = 5 ·nold, so

m3new = (3 ·mold)3 = 27 ·m3old > 27 ·n2old.

But since nnew = 5 ·nold, then nold = 15 nnew. Hence

m3new > 27 ·n2old = 27 · (

1 5

nnew

)2 = 27 · 1

25 n2new

= 27 25

·n2new > n2new.

6. Proof: [The wording of this proof is almost the same as that of Example 5.5.2.]

I. Basis Property: [I (0) is true before the first iteration of the loop.] I (0) is “exp = x0 and i = 0.” According to the pre- condition, before the first iteration of the loop exp = 1 and i = 0. Since x0 = 1, I (0) is evidently true.

II. Inductive Property: [If G ∧ I (k) is true before a loop iteration (where k ≥ 0), then I (k + 1) is true after the loop iteration.]

Suppose k is a nonnegative integer such that G ∧ I (k) is true before an iteration of the loop. Then as execu- tion reaches the top of the loop, i ̸= m, exp = xk , and i = k. Since i ̸= m, the guard is passed and statement 1 is executed. Now before execution of statement 1,

expold = xk,

so execution of statement 1 has the following effect:

expnew = expold · x = xk · x = xk+1. Similarly, before statement 2 is executed,

iold = k,

so after execution of statement 2,

inew = iold + 1 = k + 1. Hence after the loop iteration, the two statements exp = xk+1 and i = k + 1 are true, and so I (k + 1) is true.

III. Eventual Falsity of Guard: [After a finite number of iterations of the loop, G becomes false.]

The guard G is the condition i ̸= m, and m is a non- negative integer. By I and II, it is known that

for all integers n ≥ 0, if the loop is iterated n times, then exp = xn and i = n.

So after m iterations of the loop, i = m. Thus G becomes false after m iterations of the loop.

IV. Correctness of the Post-Condition: [If N is the least number of iterations after which G is false and I (N ) is true, then the value of the algorithm variables will be as specified in the post-condition of the loop.]

According to the post-condition, the value of exp after execution of the loop should be xm . But when G is false, i = m. And when I (N ) is true, i = N and exp = x N . Since both conditions (G false and I (N ) true) are satisfied, m = i = N and exp = xm , as required.

8. Proof: I. Basis Property: I (0) is “i = 1 and sum = A[1].”

According to the pre-condition, this statement is true.

II. Inductive Property: Suppose k is a nonnegative inte- ger such that G ∧ I (k) is true before an iteration of the loop. Then as execution reaches the top of the loop,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.6 Solutions and Hints to Selected Exercises A-41

i ̸= m, i = k + 1, and sum = A[1] + A[2] + · · · + A[k + 1]. Since i ̸= m, the guard is passed and statement 1 is executed. Now before execution of state- ment, 1, iold = k + 1. So after execution of statement 1, inew = iold + 1 = (k + 1) + 1 = k + 2. Also before statement 2 is executed, sumold = A[1] + A[2] + · · · + A[k + 1]. Execution of statement 2 adds A[k + 2] to this sum, and so after statement 2 is executed, sumnew = A[1] + A[2] + · · · + A[k + 1] + A[k + 2]. Thus after the loop iteration, I (k + 1) is true.

III. Eventual Falsity of Guard: The guard G is the con- dition i ̸= m. By I and II, it is known that for all integers n ≥ 1, after n iterations of the loop, I (n) is true. Hence, after m − 1 iterations of the loop, I (m) is true, which implies that i = m and G is false.

IV. Correctness of the Post-Condition: Suppose that N is the least number of iterations after which G is false and I (N ) is true. Then (since G is false) i = m and (since I (N ) is true) i = N + 1 and sum = A[1] + A[2] + · · · + A[N + 1]. Putting these together gives m = N + 1, and so sum = A[1] + A[2] + · · · + A[m], which is the post-condition.

10. Hint: Assume G ∧ I (k) is true for a nonnegative integer k. Then aold ̸= 0 and bold ̸= 0 and (1) aold and bold are nonnegative integers with

gcd(aold, bold) = gcd(A, B). (2) At most one of aold and bold equals 0. (3) 0 ≤ aold + bold ≤ A + B − k.

It must be shown that I (k + 1) is true after the loop itera- tion. That means it is necessary to show that (1) anew and bnew are nonnegative integers with

gcd(anew, bnew) = gcd(A, B). (2) At most one of anew and bnew equals 0. (3) 0 ≤ anew + bnew ≤ A + B − (k + 1).

To show (3), observe that

anew + bnew = {

aold − bold + bold if aold ≥ bold bold − aold + aold if aold < bold

[The reason for this is that when aold ≥ bold, then anew = aold − bold and bnew = b old, and when aold < bold, then bnew = b old − aold and anew = aold.] Thus

anew + bnew = {

aold if aold ≥ bold bold if aold < bold

But since aold ̸= 0 and bold ̸= 0 and a old and bold are nonnegative integers, then aold ≥ 1 and bold ≥ 1. Hence aold − 1 ≥ 0 and b old − 1 ≥ 0 and aold ≤ aold + bold − 1 and bold ≤ bold + aold − 1. It follows that anew + bnew ≤ aold + bold − 1 ≤ (A + B − k)− 1 by the truth of (3) going into the kth iteration. Hence anew + bnew < A + B − (k + 1) by algebraic simplification.

Section 5.6 1. a1 = 1, a2 = 2a1 + 2 = 2 ·1 + 2 = 4,

a3 = 2a2 + 3 = 2 ·4 + 3 = 11, a4 = 2a3 + 4 = 2 ·11 + 4 = 26

3. c0 = 1, c1 = 1 ·(c0)2 = 1 · (1)2 = 1, c2 = 2(c1)2 = 2 ·(1)2 = 2, c3 = 3(c2)2 = 3 ·(2)2 = 12

5. s0 = 1, s1 = 1, s2 = s1 + 2s0 = 1 + 2 ·1 = 3, s3 = s2 + 2s1 = 3 + 2 ·1 = 5

7. u1 = 1, u2 = 1, u3 = 3u2 − u1 = 3 ·1− 1 = 2, u4 = 4u3 − u2 = 4 ·2− 1 = 7

9. By definition of a0, a1, a2, . . ., for each integer k ≥ 1, (*) ak = 3k + 1 and

(**) ak−1 = 3(k − 1) + 1. Then ak−1 + 3

= 3(k − 1) + 1 + 3 = 3k − 3 + 1 + 3 = 3k + 1 = ak

11. By definition of c0, c1, c2, . . ., cn = 2n − 1, for each integer n ≥ 0. Substitute k and k − 1 in place of n to get (*) ck = 2k − 1 and (**) ck−1 = 2k−1 − 1 for all integers k ≥ 1. Then 2ck−1 + 1 = 2(2k−1 − 1) + 1 by substitution from (**)

= 2k − 2 + 1 = 2k − 1 by basic algebra = ck by substitution from (*)

13. By definition of t0, t1, t2, . . ., tn = 2 + n, for each integer n ≥ 0. Substitute k, k − 1, and k − 2 in place of n to get (*) tk = 2 + k, (**) tk−1 = 2 + (k − 1), and (***) tk−2 = 2 + (k − 2) for each integer k ≥ 2. Then 2tk−1 − tk−2

= 2(2 + (k − 1)− (2 + (k − 2)) by substitution from (**) and (***)

= 2(k + 1)− k = 2 + k by basic algebra = tk by substitution

from (*).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-42 Appendix B Solutions and Hints to Selected Exercises

15. Hint: Mathematical induction is not needed for the proof. Start with the right-hand side of the equation and use algebra to transform it into the left-hand side of the equation.

17. a. a1 = 2 a2 = 2 (moves to move the top disk from pole A to

pole C)

+ 1 (move to move the bottom disk from pole A to pole B)

+ 2 (moves to move the top disk from pole C to pole A)

+ 1 (move to move the bottom disk from pole B to pole C)

+ 2 (moves to move top disk from pole A to pole C)

= 8 a3 = 8 + 1 + 8 + 1 + 8 = 26

c. For all integers k ≥ 2. ak = ak−1 (moves to move the top k − 1 disks from

pole A to pole C)

+ 1 (move to move the bottom disk from pole A to pole B)

+ ak−1 (moves to move the top disk from pole C to pole A)

+ 1 (move to move the bottom disks from pole B to pole C)

+ ak−1 (moves to move the top disks from pole A to pole C)

= 3ak−1 + 2. 18. b. b4 = 40

e. Hint: One solution is to use mathematical induction and apply the formula from part (c). Another solution is to prove by mathematical induction that when a most effi- cient transfer of n disks from one end pole to the other end pole is performed, at some point all the disks are on the middle pole.

19. a. s1 = 1, s2 = 1 + 1 + 1 = 3, s3 = s1 + (1 + 1 + 1) + s1 = 5

b. s4 = s2 + (1 + 1 + 1) + s2 = 9 20. b. Call the poles A, B, and C . Compute c2 by using the

following sequence of steps to transfer two disks from A to B: 1 (move to move the top disk for A to B)

+1 (move to move the top disk from B to C) +1 (move to move the bottom disk from A to B) +1 (move to move the top disk from C to A) +1 (move to move the top disk from A to B)

This sequence of steps is the least possible, and so c2 = 5.

A tower of 3 disks can be transferred from A to B by using the following sequence of steps: 1 (move to move the top disk from A to B)

+1 (move to move the top disk from B to C) +1 (move to move the middle disk from A to B) +1 (move to move the top disk from C to A) +1 (move to move the middle disk from B to C) +1 (move to move the top disk from A to B) +1 (move to move the top disk from B to C).

After these 7 steps have been completed, the bottom disk can be moved from A to B. At that point the top two disks are on C , and a modified version of the ini- tial seven steps can be used to move them from C to B. Thus the total number of steps is 7 + 1 + 7 = 15, and 15 < 21 = 4c2 + 1.

21. b. t3 = 14 22. b. r0 = 1, r1 = 1, r2 = 1 + 4 ·1 = 5, r3 = 5 + 4 ·1 = 9,

r4 = 9 + 4 ·5 = 29, r5 = 29 + 4 ·9 = 65, r6 = 65 + 4 ·29 = 181

23. c. There are 904 rabbit pairs, or 1,808 rabbits, after 12 months.

25. a. Each term of the Fibonacci sequence beyond the second equals the sum of the previous two. For any integer k ≥ 1, the two terms previous to Fk+1 are Fk and Fk−1. Hence, for all integers k ≥ 1, Fk+1 = Fk + Fk−1.

26. By repeated use of definition of the Fibonacci sequence, for all integers k ≥ 4,

Fk = Fk−1 + Fk−2 = (Fk−2 + Fk−3) + (Fk−3 + Fk−4) = ((Fk−3 + Fk−4) + Fk−3) + (Fk−3 + Fk−4) = 3Fk−3 + 2Fk−4.

27. For all integers k ≥ 1, F2k − F2k−1 = (Fk − Fk−1)(Fk + Fk−1) by basic algebra (difference

of two squares)

= (Fk − Fk−1)Fk+1 by definition of the Fibonacci sequence

= Fk Fk+1 − Fk−1 Fk+1 32. Hint: Use mathematical induction. In the inductive step, use

Lemma 4.8.2 and the fact that Fk+2 = Fk+1 + Fk to deduce that

gcd(Fk+2, Fk+1) = gcd(Fk+1, Fk).

34. Hint: Let L = lim n→∞

Fn+1 Fn

and show that L = 1L + 1.

Deduce that L = 1+ √

5 2 .

35. Hint: Use the result of exercise 30 to prove that the infi- nite sequence F0F1

, F2 F3

, F4 F5

, . . . is strictly decreasing and that

the infinite sequence F1F2 ,

F3 F4

, F5 F6

, . . . is strictly increasing. The first sequence is bounded below by 0, and the second sequence is bounded above by 1. Deduce that the limits of both sequences exist, and show that they are equal.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solutions and Hints to Selected Exercises A-43

37. a. Because the 4% annual interest is compounded quar- terly, the quarterly interest rate is (4%)/4 = 1%. Then Rk = Rk−1 + 0.01Rk−1 = 1.01Rk−1.

b. Because one year equals four quarters, the amount on deposit at the end of one year is R4 = $5203.02 (rounded to the nearest cent).

c. The annual percentage rate (APR) for the account is $5203.02−$5000.00

$5000.00 = 4.0604%. 39. When one is climbing a staircase consisting of n stairs, the

last step taken is either a single stair or two stairs together. The number of ways to climb the staircase and have the final step be a single stair is cn−1; the number of ways to climb the staircase and have the final step be two stairs is cn−2. Therefore, cn = cn−1 + cn−2. Note also that c1 = 1 and c2 = 2 [because either the two stairs can be climbed one by one or they can be climbed as a unit].

41. Proof (by mathematical induction): Let the property, P(n), be the equation

∑n i=1 cai = c

∑n i=1 ai , where

a1, a2, a3, . . . , an and c are any real numbers.

Show that P(1) is true:

Let a1 and c be any real numbers. By the recursive defi- nition of sum,

∑1 i=1(cai ) = ca1 and

∑1 i=1 ai = a1. There-

fore, ∑1

i=1(cai ) = c ∑1

i=1 ai , and so P(1) is true.

Show that for all integers k ≥ 1, if P(k) is true, then P(k + 1) is true: Let k be any integer with k ≥ 1. Suppose that for any real numbers a1, a2, a3, . . . , ak and c,

∑k i=1(cai ) = c

∑k i=1 ai .

[This is the inductive hypothesis]. [We must show that for any

real numbers a1, a2, a3, . . . ak+1 and c, k+1∑ i=1

(cai ) = c ∑k+1

i=1 ai .]

Let a1, a2, a3, . . . , ak+1 and c be any real numbers. Then

k+1∑

i=1 cai =

k∑

i=1 cai + cak+1 by the recursivedefinition of %

= c k∑

i=1 ai + cak+1 by inductivehypothesis

= c ( k∑

i=1 ai + ak+1

) by the distributive law for the real numbers

= c k+1∑

i=1 ai

by the recursive definition of %.

44. Hint: Let the property be the inequality ∣∣∣∣∣

n∑

i=1 ai

∣∣∣∣∣ ≤ n∑

i=1 |ai |.

To prove the inductive step, note that because ∣∣∑k+1

i=1 ai ∣∣ =∣∣∑k

i=1 ai + ak+1 ∣∣, you can use the triangle inequality for

absolute value (Theorem 4.4.6) to deduce∣∣∑k i=1 ai + ak+1

∣∣ ≤ ∣∣∑k

i=1 ai ∣∣+ |ak+1|.

Section 5.7 1. a. 1 + 2 + 3 + · · · + (k − 1)

= (k − 1)((k − 1) + 1) 2

= (k − 1)k 2

b. 3 + 2 + 4 + 6 + 8 + · · · + 2n = 3 + 2(1 + 2 + 3 + · · · + n)

= 3 + 2 n(n + 1) 2

= 3 + n(n + 1) = n2 + n + 3

2. a. 1 + 2 + 22 + · · · + 2i−1 = 2 (i−1)+1 − 1

2− 1 = 2 i − 1

c. 2n + 2n− 2 ·3 + 2n− 3 ·3 + · · · + 22 ·3 + 2 ·3 + 3 = 2n + 3(2n− 2 + 2n− 3 + · · · + 22 + 2 + 1) = 2n + 3(1 + 2 + 22 + · · · + 2n− 3 + 2n− 2)

= 2n + 3 (

2(n−2)+1 − 1 2− 1

)

= 2n + 3(2n−1 − 1) = 2 ·2n−1 + 3 ·2n−1 − 3 = 5 ·2n−1 − 3

3. a0 = 1 a1 = 1 ·a0 = 1 ·1 = 1 a2 = 2a1 = 2 ·1 a3 = 3a2 = 3 ·2 ·1 a4 = 4a3 = 4 ·3 ·2 ·1

...

Guess: an = n(n − 1) · · · 3 ·2 ·1 = n!

5. c1 = 1 c2 = 3c1 + 1 = 3 ·1 + 1 = 3 + 1 c3 = 3c2 + 1 = 3 · (3 + 1) + 1 = 32 + 3 + 1 c4 = 3c3 + 1 = 3 · (32 + 3 + 1) + 1

= 33 + 32 + 3 + 1 ...

Guess: cn = 3n−1 + 3n−2 + · · · + 33 + 32 + 3 + 1

= 3 n − 1

3− 1 by Theorem 5.2.3 with r = 3

= 3 n − 1

2 6. Hint:

dn = 2n + 2n−2 ·3 + 2n−3 ·3 + · · · + 22 ·3 + 2 ·3 + 3 = 5 ·2n−1 − 3 for all integers n ≥ 1

9. Hint: For any positive real numbers a and b, a b

a b

+ 2 =

a b

a b

+ 2 · b

b = a

a + 2b .

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-44 Appendix B Solutions and Hints to Selected Exercises

10. h0 = 1 h1 = 21 − h0 = 21 − 1 h2 = 22 − h1 = 22 − (21 − 1) = 22 − 21 + 1 h3 = 23 − h2 = 23 − (22 − 21 + 1)

= 23 − 22 + 21 − 1 h4 = 24 − h3 = 24 − (23 − 22 + 22 − 1)

= 24 − 23 + 22 − 21 + 1 ...

Guess:

hn = 2n − 2n−1 + · · · + (−1)n ·1 = (−1)n[1− 2 + 22 − · · · + (−1)n ·2n] = (−1)n[1 + (−2)

+ (−2)2 − · · · + (−2)n] by basic algebra

= (−1)n [

(−2)n+1 − 1 (−2)− 1

] by Theorem 5.2.3

= (−1) n+1 · [(−2)n+1 − 1] (−1) ·(−3)

= 2 n+1 − (−1)n+1

3 by basic algebra

12. s0 = 3 s1 = s0 + 2 ·1 = 3 + 2 ·1 s2 = s1 + 2 ·2 = [3 + 2 ·1] + 2 ·2

= 3 + 2 · (1 + 2) s3 = s2 + 2 ·3 = [3 + 2 · (1 + 2)] + 2 ·3

= 3 + 2 · (1 + 2 + 3) s4 = s3 + 2 ·4 = [3 + 2 · (1 + 2 + 3)] + 2 ·4

= 3 + 2 · (1 + 2 + 3 + 4) ...

Guess:

sn = 3 + 2 · (1 + 2 + 3 + · · · + (n − 1) + n)

= 3 + 2 · n(n + 1) 2

by Theorem 5.2.2

= 3 + n(n + 1) by basic algebra

14. x1 = 1 x2 = 3x1 + 2 = 3 + 2 x3 = 3x2 + 3 = 3(3 + 2) + 3 = 32 + 3 ·2 + 3 x4 = 3x3 + 4 = 3(32 + 3 ·2 + 3) + 4

= 33 + 32 ·2 + 3 ·3 + 4 x5 = 3x4 + 5 = 3(33 + 32 ·2 + 3 ·3 + 4) + 5

= 34 + 33 ·2 + 32 ·3 + 3 ·4 + 5 x6 = 3x5 + 6

= 3(34 + 33 ·2 + 32 ·3 + 4 ·3 + 5) + 6 = 35 + 34 ·2 + 33 ·3 + 32 ·4 + 3 ·5 + 6

...

Guess:

xn = 3n−1 + 3n−2 ·2 + 3n−3 ·3 + · · · + 3(n − 1) + n

= 3n−1 + 3n−2 + 3n−2︸ ︷︷ ︸+ 3 n−3 + 3n−3 + 3n−3︸ ︷︷ ︸ +

2 times 3 times

+ 3 + 3 + · · · + 3︸ ︷︷ ︸+ 1 + 1 + · · · + 1︸ ︷︷ ︸ (n − 1) times n times

= (3n−1 + 3n−2 + · · · + 32 + 3 + 1) + (3n−2 + 3n−3 + · · · + 32 + 3 + 1) + · · ·

+ (32 + 3 + 1) + (3 + 1) + 1

= 3 n − 1

2 + 3

n−1 − 1 2

+ · · · + 3 3 − 1

2

+ 3 2 − 1

2 + 3− 1

2

= 12 [(3 n + 3n−1 + · · · + 32 + 3)− n]

= 12 [3(3 n−1 + 3n−2 + · · · + 3 + 1)− n]

= 12 (

3 (

3n − 1 3− 1

) − n )

= 14 (3 n+1 − 3− 2n)

18. Proof: Let d be any fixed constant, and let a0, a1, a2, . . . be the sequence defined recursively by ak = ak−1 + d for all integers k ≥ 1. The property P(n) is the equation an = a0 + nd. We show by mathematical induction that P(n) is true for all integers n ≥ 0. Show that P(0) is true: When n = 0, the left-hand side of the equation is a0, and the right-hand side is a0 + 0 ·d = a0, which equals the left- hand side. Thus P(0) is true. Show that for all integers k ≥ 0, if P(k) is true, then P(k + 1) is true: Suppose

ak = a0 + kd, for some integer k ≥ 0. [This is the inductive hypothesis.]

We must show that ak+1 = a0 + (k + 1)d . But ak+1 = ak + d by definition of a0, a1, a2, . . .

= [a0 + kd] + d by substitution from the inductive hypothesis

= a0 + (k + 1)d by basic algebra [as was to be shown].

19. Let Un = the number of units produced on day n. Then Uk = Uk−1 + 2 for all integers k ≥ 1, U0 = 170.

Hence U0, U1, U2, . . . is an arithmetic sequence with fixed constant 2. It follows that when n = 30,

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.7 Solutions and Hints to Selected Exercises A-45

Un = U0 + n ·2 = 170 + 2n = 170 + 2 ·30 = 230 units.

Thus the worker must produce 230 units on day 30.

24. 20∑

k=0 5k = 5

21 − 1 4

∼= 1.192× 1014 ∼=

119,200,000,000,000 ∼= 119 trillion people (This is about 20,000 times the current population of the earth!)

26. b. Hint: Before simplification, An = 1000(1.0025)n + 200[(1.0025)n−1 + (1.0025)n−1 + · · · + (1.0025)2 + 1.0025 + 1].

d. A240 ∼= $67,481.15, A480 ∼= $188,527.05 e. Hint: Use logarithms to solve the equation An =

10,000, where An is the expression found (after simpli- fication) in part (b).

27. a. Hint: APR ∼= 19.6% c. Hint: approximately two years

28. Proof: Let a0, a1, a2, . . . be the sequence defined recur- sively by a0 = 1 and ak = kak−1 for all integers k ≥ 1. Let the property P(n) be the equation an = n!. We show by mathematical induction that P(n) is true for all integers n ≥ 0. Show that P(0) is true: When n = 0, the right-hand side of the equation is 0! = 1, and by definition of a0, a1, a2, . . . , the left-hand side of the equation, a0, is also 1. Thus the property is true for n = 0. Show that for all integers k ≥ 0, if P(k) is true, then P(k + 1) is true: Suppose

ak = k! for some integer k ≥ 0. [This is the inductive hypothesis.]

We must show that ak+1 = (k + 1)!. But

ak+1 = (k + 1) ·ak by definition of a0, a1, a2, . . . = (k + 1) ·k! by substitution from the

inductive hypotheses

= (k + 1)! by definition of factorial. [Hence if P(k) is true, then P(k + 1) is true.]

30. Proof: Let c1, c2, c3, . . . be the sequence defined recur- sively by c1 = 1 and ck = 3ck−1 + 1 for all integers k ≥ 2. Let the property P(n) be the equation cn = 3

n−1 2 . We show

by mathematical induction that P(n) is true for all integers n ≥ 1. Show that P(1) is true:

When n = 1, the right-hand side of the equation is 3 1−1 2 =

3−1 2 = 1, and by definition of c1, c2, c3, . . . , the left-hand

side of the equation, c1, is also 1. Thus the property is true for n = 1. Show that for all integers k ≥ 1, if P(k) is true, then P(k + 1) is true:

Suppose that

ck = 3k − 1

2 for some integer k ≥ 1.

[This is the inductive hypothesis.]

We must show that ck+1 = 3k+1 − 1

2 . But

ck+1 = 3ck + 1 by definition of c1, c2, c3, . . .

= 3 (

3k − 1 2

) + 1 by substitution from theinductive hypothesis

= 3 k+1 − 3

2 + 2

2

= 3 k+1 − 1

2 by basic algebra.

35. Hint: 2k+1 − 2 k+1 − (−1)k+1

3

= 3 ·2 k+1

3 − 2

k+1 − (−1)k+1 3

= 2 ·2 k+1 + (−1)k+1

3 = 2

k+2 − (−1)k+2 3

37. Hint: [3 + k(k + 1)] + 2(k + 1) = 3 + k2 + k + 2k + 2 = 3 + [k2 + 3k + 2] = 3 + (k + 1)(k + 2) = 3 + (k + 1)[(k + 1) + 1]

39. Proof: Let x1, x2, x3, . . . be the sequence defined recur- sively by x1 = 1 and xk = 3xk−1 + k for all integers k ≥ 2. Let the property, P(n), be the equation xn = 3

n+1−2n−3 4 .

We show by mathematical induction that P(n) is true for all integers n ≥ 1. Show that P(1) is true: When n = 1, the right-hand side of the equation is 3

1+1−2 ·1−3 4 =

32−2−3 4 = 1, and by definition of

x1, x2, x3, . . . , the left-hand side of the equation, x1, is also 1. Thus P(1) is true. Show that for all integers k ≥ 1, if P(k) is true for, then P(k + 1) is true. Suppose that for some integer k ≥ 0, xk = 3

k+1−2k−3 4 .

[Inductive hypothesis] We must show that

xk+1 = 3(k+1)+1 − 2(k + 1)− 3

4 , or, equivalently,

xk+1 = 3k+2 − 2k − 5

4 . But

xk+1 = 3xk + k by definition of x1, x2, x3,

= 3 (

3k+1 − 2k − 3 4

) + k + 1 by inductivehypothesis

= 3 ·3 k+1 − 3 ·2k − 3 ·3

4 + 4(k + 1)

4

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-46 Appendix B Solutions and Hints to Selected Exercises

= 3 k+2 − 6k − 9 + 4k + 4

4

= 3 k+2 − 2k − 5

4 by algebra.

[This is what was to be shown.]

43. a. a0 = 2

a1 = a0

2a0 − 1 = 2

2 ·2− 1 = 2 3

a2 = a1

2a1 − 1 =

2 3

2 · 23−33 =

2 3 1 3

= 2

a3 = a2

2a2 − 1 = 2

2 ·2− 1 = 2 3

a4 = a3

2a3 − 1 =

2 3

2 · 23 − 3 3

= 2 3 1 3

= 2

Guess: an = {

2 if n is even 2 3 if n is odd

.

b. Proof: Let a0, a1, a2, . . . be the sequence defined recur- sively by x0 = 2 and ak = ak−12ak−1−1 for all integers k ≥ 1. Let the property, P(n), be the equation

an = {

2 if n is even 2 3 if n is odd

.

We show by strong mathematical induction that P(n) is true for all integers n ≥ 1. Show that P(0) and P(1) are true: The results of part (a) show that P(0) and P(1) are true. Show that for all integers k ≥ 0, if P(k) is true for all integers i with 0 ≤ i ≤ k, then P(k + 1) is true: Let k be any integer with k ≥ 0, and suppose that for all integers i with 0 ≤ i ≤ k,

ai = {

2 if i is even 2 3 if i is odd

. [Inductive hypothesis]

We must show that

ak+1 = {

2 if k is even 2 3 if k is odd

.

But

ak+1 = ak

2ak − 1 by definition of a0, a1, a2, . . .

=

⎧ ⎪⎪⎪⎨

⎪⎪⎪⎩

2 2 ·2−1 if k is even

2 3

2 · 23−1 if k is odd

by inductive hypothesis

=

⎧ ⎪⎪⎪⎨

⎪⎪⎪⎩

2 3 if k is even

2 3 1 3

if k is odd

=

⎧ ⎪⎨

⎪⎩

2 3 if k + 1 is odd

2 if k + 1 is even

because k + 1 is odd when k is even

and k + 1 is even when k is odd.

[This is what was to be shown.]

45. v1 = 1 v2 = v⌊2/2⌋ + v⌊3/2⌋ + 2 = v1 + v1 + 2

= 1 + 1 + 2 v3 = v⌊3/2⌋ + v⌊4/2⌋ + 2 = v1 + v2 + 2

= 1 + (1 + 1 + 2) + 2 = 3 + 2 ·2 v4 = v⌊4/2⌋ + v⌊5/2⌋ + 2 = v2 + v2 + 2

= (1 + 1 + 2) + (1 + 1 + 2) + 2 = 4 + 3 ·2

v5 = v⌊5/2⌋ + v⌊6/2⌋ + 2 = v2 + v3 + 2 = (3 + 2 ·2) + (1 + 1 + 2) + 2 = 5 + 4 ·2

v6 = v⌊6/2⌋ + v⌊7/2⌋ + 2 = v3 + v3 + 2 = (3 + 2 ·2) + (3 + 2 ·2) + 2 = 6 + 5 ·2

...

Guess: vn = n + 2(n − 1) = 3n − 2 for all integers n ≥ 1 b. Proof: Let v1, v2, v3, . . . be the sequence defined recur-

sively by v1 = 1 and vk = v⌊k/2⌋ + v⌊(k+1)/2⌋ + 2 for all integers k ≥ 1. Let the property, P(n), be the equation

vn = 3n − 2. We show by strong mathematical induction that P(n) is true for all integers n ≥ 1. Show that P(1) is true:

When n = 1, the right-hand side of the equation is 3 ·1− 2 = 1, which equals v1 by definition of v1, v2, v3, . . . . Thus P(1) is true.

Show that for all integers k ≥ 1, if P(i) is true for all integers i with 0 ≤ i ≤ k, then P(k + 1) is true: Let k be any integer with k ≥ 1, and suppose that for all integers i with 1 ≤ i ≤ k, vi = 3i − 2. [This is the inductive hypothesis.] We must show that vk+1 = 3(k + 1)− 2 = 3k + 1.

vk + 1 = v⌊(k + 1)/2⌋ + v⌊(k + 2)/2⌋ + 2 by definition of v1, v2, v3, . . .

= (

3 ⌊

k+1 2

⌋ −2 )

+ (

3 ⌊

k+2 2

⌋ −2 )

+ 2

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.8 Solutions and Hints to Selected Exercises A-47

= 3 (⌊

k + 1 2

⌋ + ⌊

k + 2 2

⌋) − 2

=

⎧ ⎪⎨

⎪⎩

3 (

k 2 +

k+2 2

) − 2 if k is even

3 (

k+1 2 +

k+1 2

) − 2 if k is odd

= 3 (

2k+2 2

) − 2

= 3(k + 1)− 2 = 3k + 1 by the laws of algebra.

[This is what was to be shown.]

46. Hint: Show that for all integers n ≥ 0, s2n = 2n and s2n+1 = 2n+1. Then combine these formulas using the ceil- ing function to obtain sn = 2⌈n/2⌉.

48. a. Hint: wn =

⎧ ⎪⎨

⎪⎩

( n + 1

2

)2 if n is odd

n 2

( n 2 + 1 )

if n is even

49. a. Hint: Express the answer using the Fibonacci sequence. 50. The sequence does not satisfy the formula. According to

the formula, a4 = (4− 1)2 = 9. But by definition of the sequence, a1 = 0, a2 = 2 ·0 + (2 + 1) = 1, a3 = 2 ·1 + (3− 1) = 4, and so a4 = 2 ·4 + (4− 1) = 11. Hence the sequence does not satisfy the formula for n = 4.

52. a. Hint: The maximum number of regions is obtained when each additional line crosses all the previous lines, but not at any point that is already the inter- section of two lines. When a new line is added, it divides each region through which it passes into two pieces. The number of regions a newly added line passes through is one more than the number of lines it crosses.

53. Hint: The answer involves the Fibonacci numbers!

Section 5.8 1. (a), (d), and (f) 3. a. a0 = C ·20 + D = C + D = 1

a1 = C ·21 + D = 2C + D = 3

}

⇔ {

D = 1− C 2C + (1− C) = 3

} ⇔ {

C = 2 D = −1

a2 = 2 ·22 + (−1) = 7 4. a. b0 = C ·30 + D ·(−2)0 = C + D = 0

b1 = C ·31 + D ·(−2)1 = 3C − 2D = 5

}

⇔ {

D = −C 3C − 2(−C) = 5

} ⇔ {

C = 1 D = −1

b2 = 32 + (−1)(−2)2 = 9− 4 = 5 5. Proof: Given that an = C ·2n + D, then for any choice of

C and D and integer k > 2,

ak = C ·2k + D, ak−1 = C ·2k−1 + D, ak−2 = C ·2k−2 + D.

Hence

3ak−1 − 2ak−2 = 3(C ·2k−1 + D)− 2(C ·2k−2 + D) = 3C ·2k−1 + 3D − 2C ·2k−2 − 2D = 3C ·2k−1 − C ·2k−1 + D = 2C ·2k−1 + D = C ·2k + D = ak .

8. a. If for all k > 2, t k = 2t k−1 + 3t k−2 and t ̸= 0 then t2 = 2t + 3 [by dividing by tk−2], and so t2 − 2t − 3 = 0. But t2 − 2t − 3 = (t − 3)(t + 1); hence t = 3 or t = − 1.

b. It follows from (a) and the distinct roots theorem that for some constants C and D, a0, a1, a2, . . . satisfies the equation

an = C ·3n + D ·(−1)n for all integers n ≥ 0. Since a0 = 1 and a1 = 2, then

a0 = C ·30 + D ·(−1)0 = C + D = 1 a1 = C ·31 + D ·(−1)1 = 3C − D = 2

}

⇔ {

D = 1− C 3C − (1− C) = 2

}

⇔ {

D = 1− C 4C − 1 = 2

}

⇔ {

C = 3/4 D = 1/4

Thus an = 34 (3 n) + 14 (−1)

n for all integers n ≥ 0. 11. Characteristic equation: t2 − 4 = 0. Since t2 − 4 = (t −

2)(t + 2), t = 2 and t = −2 are the roots. By the distinct roots theorem, for some constants C and D

dn = C ·(2n) + D ·(−2)n for all integers n ≥ 0. Since d0 = 1 and d1 = −1, then

d0 = C ·20 + D · (−2)0 = C + D = 1 d1 = C ·21 + D · (−2)1 = 2C − 2D = −1

}

⇔ {

D = 1− C 2C − 2(1− C) = −1

}

⇔ {

D = 1− C 4C − 2 = −1

}

⎧ ⎨

⎩ C = 14 D = 34

Thus dn = 14 (2 n) + 34 (−2)

n for all integers n ≥ 0. 13. Characteristic equation: t2 − 2t + 1 = 0. By the quadratic

formula,

t = 2 ± √

4− 4 ·1 2

= 2 2

= 1.

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-48 Appendix B Solutions and Hints to Selected Exercises

By the single root theorem, for some constants C and D

rn = C · (1n) + Dn · (1n) = C + nD for all integers n ≥ 0.

Since r0 = 1 and r1 = 4, then r0 = C + 0 · D = C = 1 r1 = C + 1 · D = C + D = 4

} ⇔ {

C = 1 1 + D = 4

}

⇔ {

C = 1 D = 3

Thus rn = 1 + 3n for all integers n ≥ 0. 16. Hint: For all integers n ≥ 0,

sn = √

3 + 2 2 √

3

( 1 +

√ 3 )n

+ √

3− 2 2 √

3

( 1−

√ 3 )n

.

19. Proof: Suppose r, s, a0, and a1 are numbers with r ̸= s. Consider the system of equations

C + D = a0 Cr + Ds = a1.

By solving for D and substituting, we find that

D = a0 − C Cr + (a0 − C)s = a1.

Hence

C(r − s) = a1 − a0s. Since r ̸= s, both sides may be divided by r − s. Thus the given system of equations has the unique solution

C = a1 − a0s r − s

and

D = a0 − C = a0 − a1 − a0s

r − s

= a0r − a0s − a1 + a0s r − s =

a0r − a1 r − s .

Alternative solution: Since the determinant of the sys- tem is 1 ·s − r ·1 = s − r and since r ̸= s, the given sys- tem has a nonzero determinant and therefore has a unique solution.

21. Hint: Use strong mathematical induction. First note that the formula holds for n = 0 and n = 1. To prove the inductive step, suppose that for some k ≥ 2, the formula holds for all i with 0 ≤ i ≤ k. Then show that the formula holds for k + 1. Use the proof of Theorem 5.8.3 (the distinct roots theorem) as a model.

22. The characteristic equation is t2 − 2t + 2 = 0. By the quadratic formula, its roots are

t = 2 ± √

4− 8 2

= 2 ± 2i 2

= {

1 + i 1− i .

By the distinct roots theorem, for some constants C and D

an = C(1 + i)n + D(1− i)n

for all integers n ≥ 0. Since a0 = 1 and a1 = 2, then

a0 = C(1 + i)0 + D(1− i)0 = C + D = 1 a1 = C(1 + i)1 + D(1− i)1

= C(1 + i) + D(1− i) = 2

⇔ {

D = 1− C C(1 + i) + (1− C)(1− i) = 2

}

⇔ {

D = 1− C C(1 + i − 1 + i) + 1− i = 2

}

⇔ {

D = 1− C C(2i) = 1 + i

}

⎧ ⎨

D = 1− C C = 1 + i

2i = 1 + i

2i · i

i = i − 1−2 =

1− i 2

⎫ ⎬

⎧ ⎪⎪⎨

⎪⎪⎩

D = 1− 1− i 2

= 2− 1 + i 2

= 1 + i 2

C = 1− i 2

⎫ ⎪⎪⎬

⎪⎪⎭

Thus for all integers n ≥ 0, an = (

1− i 2

) (1 + i)n +

( 1 + i

2

) (1− i)n .

Section 5.9 1. a. (1) p, q, r , and s are Boolean expressions by I.

(2) ∼s is a Boolean expression by (1) and II(c). (3) (r ∨ ∼s) is a Boolean expression by (1), (2), and

II(b). (4) (q ∧ (r ∨ ∼s)) is a Boolean expression by (1), (3),

and II(a). (5) ∼p is a Boolean expression by (1) and II(c). (6) (∼p ∨ (q ∧ (r ∨ ∼s))) is a Boolean expression by

(4), (5), and II(b). 2. a. (1) ϵ ∈ S by I.

(2) a = ϵa ∈ S by (1) and II(a). (3) aa ∈ S by (2) and II(a). (4) aab ∈ S by (3) and II(b).

3. a. (1) M I is in the M IU system by I. (2) M I I is in the M IU system by (1) and II(b). (3) M I I I I is in the M IU system by (3) and II(b). (4) M I I I I I I I I is in the M IU system by (3) and II(b). (5) M IU I I I I is in the M IU system by (4) and II(c). (6) M IUU I is in the M IU system by (5) and II(c). (7) M IU I is in the M IU system by (6) and II(d).

4. a. (1) 2, 0.3, 4.2, and 7 are arithmetic expressions by I. (2) (0.3− 4.2) is an arithmetic expression by (1) and

II(d). (3) (2 ·(0.3− 4.2)) is an arithemetic expression by (1),

(2), and II(e).

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

5.9 Solutions and Hints to Selected Exercises A-49

(4) (−7) is an arithmetic expression by (1) and II(b). (5) ((2 ·(0.3− 4.2)) + (−7)) is an arithmetic expression

by (3), (4), and II(c). 5. Proof by structural induction: Let the property be the fol-

lowing sentence: The string ends in a 1. Show that each object in the BASE for S satisfies the prop- erty: The only object in the base is 1, and the string 1 ends in a 1.

Show that for each rule in the RECURSION for S, if the rule is applied to an object in S that satisfies the property, then the objects defined by the rule also satisfy the prop- erty: The recursion for S consists of two rules denoted II(a) and II(b). Suppose s is a string in S that ends in a 1. In the case where rule II(a) is applied to s, the result is the string 1s, which also ends in a 1. In the case where rule II(b) is applied to s, the result is the string 1s, which also ends in a 1. Thus when each rule in the RECURSION is applied to a string in S that ends in a 1, the result is also a string that ends in a 1.

7. Proof by structural induction: Let the property be the fol- lowing sentence: The string contains an even number of a’s. Show that each object in the BASE for S satisfies the prop- erty: The only object in the base is ϵ, which contains 0 a’s. Because 0 is an even number, ϵ contains an even number of a’s. Show that for each rule in the RECURSION for S, if the rule is applied to an object in S that satisfies the property, then the objects defined by the rule also satisfy the prop- erty: The recursion for S consists of four rules denoted II(a), II(b), II(c), and II(d). Suppose s is a string in S that contains an even number of a’s. In the case where either rule II(a) or rule II(b) is applied to s, the result is the string bs or the string sb, each of which contain the same number of a’s as s and hence an even number of a’s. In the case where either rule II(c) or rule II(d) is applied to s, the result is the string aas or the string saa, each of which contain two more a’s than the number of a’s in s. Because two more than any even integer is an even integer, both aas and saa contain an even number of a’s. Thus when each rule in ‘the RECURSION is applied to a string in S that contains an even number of a’s, the result is also a string that contains even number of a’s.

9. Hint: Let the property be the following sentence: The string represents an odd integer. In the decimal notation, a string represents an odd integer if, and only if, it ends in 1, 3, 5, 7 or 9.

10. Hint: By divisibility results from Chapter 3 (exercises 15 and 16 of Section 3.3), if both s and t are divisible by 5, then so are s + t and s − t .

12. Hint: Can the number of I ’s in a string in the M IU system be a multiple of 3? How do rules II(a)–(d) affect the number of I ’s in a string?

13. a. (1) ( ) is in P by I. (2) (( )) is in P by (1) and II(a). (3) ( )(( )) is in P by (1), (2), and II(b).

14. a. This structure is not in P . Define a function f : P → Z as follows: For each parenthesis structure S in P , let

f (S) = [

the number of left parentheses in S

] − [

the number of right parentheses in S

] .

Observe that for all S in P, f (S) = 0. To see why, use the reasoning of structural induction: 1. The base element of P is sent by f to 0: f [()] =

0 [because there is one left and one right parenthesis in ( )].

2. For all S ∈ P , if f [S] = 0 then f [(S)] = 0 [because if k − m = 0 then (k + 1)− (m + 1) = 0].

3. For all S and T in P , if f [S] = 0 and f [T ] = 0, then f [ST ] = 0 [because if k − m = 0 and n − p = 0, then (k + n)− (m + p) = 0].

Items (1), (2), and (3) show that all parenthesis struc- tures obtainable from the base structure ( ) by repeated application of II(a) and II(b) are sent to 0 by f . But by III (the restriction condition), there are no other ele- ments of P besides those obtainable from the base ele- ment by applying II(a) and II(b). Hence f (S) = 0 for all S ∈ P . Now if ( )(( ) were in P , then it would be sent to 0 by f . But f [( )(( )] = 3− 2 = 1 ̸= 0. Thus ( )(( ) /∈ P .

15. Let S be the set of all strings of 0’s and 1’s with the same number of 0’s and 1’s. The following is a recursive defini- tion of S.

I. BASE: The null string ϵ ∈ S. II. RECURSION: If s ∈ S, then

a. 01s ∈ S b. s01 ∈ S c. 10s ∈ S d. s10 ∈ S e. 0s1 ∈ S f. 1s0 ∈ S

III. RESTRICTION: There are no elements of S other that those obtained from I and II.

17. Let T be the set of all strings of a’s and b’s that contain an odd number of a’s. The following is a recursive definition of T .

I. BASE: The a ∈ T . II. RECURSION: If t ∈ T , then

a. bt ∈ T b. tb ∈ T c. aat ∈ T d. ata ∈ T e. taa ∈ T

III. RESTRICTION: There are no elements of T other than those obtained from I and II.

19. a. M(86) = M(M(97)) since 86 ≤ 100 = M(M(M(108))) since 97 ≤ 100 = M(M(98)) since 108 > 100 = M(M(M(109))) since 98 < 100 = M(M(99)) since 109 > 100 = M(91) by Example 5.9.6

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

A-50 Appendix B Solutions and Hints to Selected Exercises

21. a. A(1, 1) = A(0, A(1, 0)) by (5.9.3) with m = 1 and n = 1

= A(1, 0) + 1 by (5.9.1) with n = A(1, 0) = A(0, 1) + 1 by (5.9.2) with m = 1 = (1 + 1) + 1 by (5.9.1) with n = 1 = 3

Alternative solution:

A(1, 1) = A(0, A(1, 0)) by (5.9.3) with m = 1 and n = 1

= A(0, A(0, 1)) by (5.9.2) with m = 1 = A(0, 2) by (5.9.1) with n = 1 = 3 by (5.9.1) with n = 2

22. a. Proof by mathematical induction: Let the property, P(n), be the equation A(1, n) = n + 2. Show that P(0) is true: When n = 0,

A(1, n) = A(1, 0) by substitution = A(0, 1) by (5.9.2) = 1 + 1 by (5.9.1) = 2.

On the other hand, n + 2 = 0 + 2 also. Thus A(1, n) = n + 2 for n = 0. Show that for all integers k ≥ 0, if P(k) is true, then P(k + 1) is true: Let k be an integer with k ≥ 1 and suppose P(k) is true. In other words, suppose A(1, k) = k + 2. [This is the inductive hypothesis.] We must show that P(k + 1) is true. In other words, we must show that A(1, k + 1) = (k + 1) + 2 = k + 3. But

A(1, k + 1) = A(0, A(1, k)) by (5.9.3) = A(1, k) + 1 by (5.9.1) = (k + 2) + 1 by inductive hypothesis = k + 3.

[This is what was to be shown.] [Since both the basis and the inductive steps have been proved, we conclude that the equation holds for all nonneg- ative integers n.]

24. Suppose F is a function. Then F(1) = 1, F(2) = F(1) = 1, F(3) = 1 + F(5 ·3− 9) = 1 + F(6) = 1 + F(3). Sub- tracting F(3) from the extreme left and extreme right of this sequence of equations gives 1 = 0, which is false. Hence F is not a function.

Section 6.1 1. a. A = {2, {2}, (

√ 2)2} = {2, {2}, 2} = {2, {2}} and B =

{2, {2}, {{2}}}. So A ⊆ B because every element in A is in B, but B ! A because {{2}} ∈ B and {{2}} ̸∈ A. Also A is a proper subset of B because {{2}} is in B but not A.

c. A = {{1, 2}, {2, 3}} and B = {1, 2, 3}. So A ! B because {1, 2} ∈ A and {1, 2} ̸∈ B. Also B ! A because 1 ∈ B and 1 ̸∈ A.

e. A = {√

16, {4} }

= {4, {4}} and B = {4}. Then B ⊆ A because the only element in B is 4 and 4 is in A, but A ! B because {4} ∈ A and {4} ̸∈ B. Also B is a proper subset of A because {4} is in A but not B.

2. Proof That B ⊆ A: Suppose x is a particular but arbitrarily chosen element of B.

[We must show that x ∈ A. By definition of A, this means we must show that x = 2 · (some integer).]

By definition of B, there is an integer b such that x = 2b − 2.

[Given that x = 2b − 2, can x also be expressed as 2 · (some integer)? I.e., is there an integer, say a, such that 2b − 2 = 2a ? Solve for a to obtain a = b − 1. Check to see if this works.]

Let a = b − 1. [First check that a is an integer.]

Then a is an integer because it is a difference of integers. [Then check that x = 2a.]

Also 2a = 2(b − 1) = 2b − 2 = x , Thus, by definition of A, x is an element of A,

[which is what was to be shown].

3. a. No. R ! T because there are elements in R that are not in T . For example, the number 2 is in R but 2 is not in T since 2 is not divisible by 6.

b. Yes. T ⊆ R because every number divisible by 6 is divisible by 2. To see why this is so, suppose n is any number that is divisible by 6. Then n = 6m for some integer m. Since 6m = 2(3m) and since 3m is an integer (being a product of integers), it follows that n = 2 · (some integer), and, hence, that n is divisible by 2.

5. a. C ⊆ D Proof: [We will show that every element of C is in D.] Suppose n is any element of C . Then n = 6r − 5 for some integer r . Let s = 2r − 2. Then s is an integer (because products and differences of integers are inte- gers), and

3s + 1 = 3(2r − 2) + 1 = 6r − 6 + 1 = 6r − 5,

which equals n. Thus n satisfies the condition for being in D. Hence, every element in C is in D.

b. D ! C because there are elements of D that are not in C . For example, 4 is in D because 4 = 3 ·1 + 1. But 4 is not in C because if it were, then 4 = 6r − 5 for some integer r , which would imply that 9 = 6r , or, equiva- lently, that r = 3/2, and this contradicts the fact that r is an integer.

6. c. Sketch of proof that B ⊆ C : If r is any element of B then there is an integer b such that r = 10b − 3. To show that r is in C , you must show that there is an integer c such that r = 10c + 7. In scratch work, assume that c exists and use the information that 10b − 3 would have

Copyright 2010 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

6.1 Solutions and Hints to Selected Exercises A-51

to equal 10c + 7 to deduce the only possible value for ċ. Then show that this value is (1) an integer and (2) satis- fies the equation r = 10c + 7, which will allow you to conclude that r is an element of C . Sketch of proof that C ⊆ B: If s is any element of C then there is an integer c such that s = 10c + 7. To show that s is in B, you must show that there is an integer b such that s = 10c − 3. In scratch work, assume that b exists and use the information that 10c + 7 would have to equal 10b − 3 to deduce the only possible value for b. Then show that this value is (1) an integer and (2) sat- isfies the equation s = 10b − 3, which will allow you to conclude that s is an element of B.

8. a. The set of all x in U such that x is in A and x is in B. The shorthand notation is A ∩ B.

9. a. x ̸∈ A and x ̸∈ B 10. a. {1, 3, 5, 6, 7, 9} b. {3, 9}

c. {1, 2, 3, 4, 5, 6, 7, 8, 9} d. ∅ e. {1, 5, 7} 11. a. A ∪ B = {x ∈ R | 0 < x < 4}

b. A ∩ B = {x ∈ R | 1 ≤ x ≤ 2} c. Ac = {x ∈ R | x ≤ 0 or x > 2} d. A ∪ C = {x ∈ R | 0 < x ≤ 2 or 3 ≤ x < 9} e. A ∩ C = ∅ f. Bc = {x ∈ R | x < 1 or x ≥ 4} g. Ac ∩ Bc = {x ∈ R | x ≤ 0 or x ≥ 4} h. Ac ∪ Bc = {x ∈ R | x < 1 or x > 2} i. (A ∩ B)c = {x ∈ R | x < 1 or x > 2} j. (A ∪ B)c = {x ∈ R | x ≤ 0 or x ≥ 4}

13. b. False. Many negative real numbers are not rational. For example, −

√ 2 ∈ R but −

√ 2 /∈ Q.

d. False. 0 ∈ Z but 0 /∈ Z− ∪ Z+. 14. a.

U B

A C

15. a. U

C

A

B

16. a. A ∪ (B ∩ C) = {a, b, c}, (A ∪ B) ∩ C = {b, c}, and (A ∪ B) ∩ (A ∪ C) = {a, b, c, d} ∩ {a, b, c, e} = {a, b, c}. Hence A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).

17. a.

A B

C

U

18. a. The number 0 is not in ∅ because ∅ has no elements. b. No. The left-hand set is the empty set; it does not have

any elements. The right-hand set is a set with one ele- ment, namely ∅.

19. A1 = {1, 12} = {1}, A2 = {2, 22} = {2, 4}, A3 = {3, 32} = {3, 9}, A4 = {4, 42} = {4, 16}

a. A1 ∪ A2 ∪ A3 ∪ A4 = {1} ∪ {2, 4} ∪ {3, 9} ∪ {4, 16} = {1, 2, 3, 4, 9, 16}

b. A1 ∩ A2 ∩ A3 ∩ A4 = {1} ∩ {2, 4} ∩ {3, 9} ∩ {4, 16} = ∅

c. A1, A2, A3, and A4 are not mutually disjoint because A2 ∩ A4 = {4} = ∅.

21. C0 = {0,−0} = {0}, C1 = {1,−1}, C1 = {2,−2}, C1 = {3,−3}, C1 = {4,−4} a.

4⋃ i=0

Ci = {0} ∪ {1,−1} ∪ {2,−2} ∪ {3,−3} ∪ {4,−4} = {−4,−3,−2,−1, 0, 1, 2, 3, 4}

b. 4⋂

i=0 Ci = {0}∩ {1,−1}∩ {2,−2}∩ {3,−3}∩ {4,−4}

= ∅ c. C0, C1, C2, . . . are mutually disjoint because no two of

the sets have any elements in common.

d. n⋃

i=0 Ci = {−n,−(n − 1), . . . ,−2,−1, 0,