UU UI UI I IUUI I I UI I UUI I U I UU U I UU uu 10 01 000 01100 1 100 010 0 0 0 0 01 0 1 0 11 00 1 101111 11 11 10 100 01 10 0 100 111 0 1 0 1 11 0 1 1 11 1, 1 01,100 10 01 11 111 10 11 1 011 101 1 1 1 1 10 1 1 1 00 10 0 010011 1 10 01 011 11 01 1 111 1 010 1 0 1 0 0 1 1 0 1 101100011 1 11 10 100 01 00 0 100 0 110 0 1 0 1 11 0 0 0 1 011111110 0 01 10 111 10 11 011 0 100 1 1 1 11 1 1 1 1 010 11101 0 00 0 00 011 10 11 011 1 001 1 0 1 0011 1 0 101 10 01 0 10 1 01 000 01 00 100 1 010 0 1 0 1010011 111 11 1 1 10 1 10 00 001 10 100 0 110 0 1 011100111 0 1 0 1 1 0 01 0 101 1 110 10 011 1 101 1 0 100101000 1 0 0 0 10 0 010 1 111 01 111 1 011 1 00100011001 1 1 1 10 0 110 0 001 00 100 0 110 00 00011110111 0 0 1 011101 1 110 00 011 0 111 1 01 1 111101110 1 0 010011 1 110 11 0 1 1 0011 00 1 10001 000 1 1 000010 000 01 0 0 0 1101 00 0 0110 11 0 1 11 0011001 1 00 1 0 11 0 11 0 1 1 0 0 01 1011000011 0 0 0 1 0 0 0 0 0 0 01 001 0011 0 1 0 1 0 1 1 10 0101 1100 1 0 0 0 0 1 11 1011 1110 0 0 01 11101 0011 1 1 10 01001 1101 0 1 11 1 11 1100 0 01 1 111 0 11 1 0 0 01 0 11 1 1 0 1 1 00 0 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 A Mathematical Foundation for Computer Science PRELIMINARY EDITION David Mix Barrington Kendall Hunt publishing co mp any All chapter heading quotes are taken from Monty Python's Flying Circus: All the Words (Volumes 1 and 2) (New York: Pantheon Books, 1989) and Monty Python and The Holy Grail (Book) [M0nti Pyth0n ik den H0lie Grailen (B0k)J (New York, Methuen Inc., 1979). Excursion 1.11 uses text from Through the Looking Glass, and What Alice Found There by Lewis Carroll (London, McMillan, 1871) and Fox in Socks by Dr. Seuss (New York, Random House, 1965). Problems 2.6.2 and 2.6.3 use text from The Number oft he Beast by Robert A. Heinlein (New York: Fawcett, 1980). There are many references in the text to Godel, Escher, Bach: An Eternal Golden Braid by Douglas R. Hofstadter (New York: Basic Books, 1979). Cover image of Stalker Castle, Scotland, by Frank Parolek © Shutterstock, Inc. Kendall Hunt publish in g company www.kendallhunt.com Send all inquiries to: 4050 Westmark Drive Dubuque, IA 52004-1840 Copyright© 2019 by Kendall Hunt Publishing Company ISBN 978-1-7924-0564-8 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the copyright owner. Published in the United States of America PRELIMINARY EDITION CONTENTS Chapter 1: Sets, Propositions, and Predicates 1-1 1.1: Sets 1-2 1.2: Strings and String Operations 1-11 1.3: Excursion: What is a Proof? 1-20 1.4: Propositions and Boolean Operations 1-24 1.5: Set Operations and Propositions About Sets 1-34 1.6: Truth-Table Proofs 1-45 1.7: Rules for Propositional Proofs 1-52 1.8: Propositional Proof Strategies 1-59 1.9: Excursion: A Murder Mystery 1-65 1. 10: Predicates 1-68 1.11: Excursion: Translating Predicates 1-75 Glossary for Chapter 1 1-78 Chapter 2: Quantifiers and Predicate Calculus 2-1 2.1: Relations 2-2 2.2: Excursion: Relational Databases 2-8 2.3: Quantifiers 2-10 2.4: Excursion: Translating Quantifiers 2-17 2.5: Operations on Languages 2-19 2.6: Proofs With Quantifiers 2-25 2.7: Excursion: Practicing Proofs 2-32 2.8: Properties of Binary Relations 2-34 2.9: Functions 2-41 2.10: Partial Orders 2-48 2.11: Equivalence Relations 2-55 Glossary for Chapter 2 2-62 Chapter 3: Number Theory 3-1 3 .1: Divisibility and Primes 3-2 3.2: Excursion: Playing With Numbers 3-11 3.3: Modular Arithmetic 3-14 3.4: There are Infinitely Many Primes 3-23 3.5: The Chinese Remainder Theorem 3-28 3.6: The Fundamental Theorem of Arithmetic 3-35 3.7: Excursion: Expressing Predicates in Number Theory 3-43 3.8: The Ring of Congruence Classes 3-46 3.9: Finite Fields and Modular Exponentiation 3-52 3.10: Excursion: Certificates of Primality 3-58 3.11: The RSA Cryptosystem 3-61 Glossary for Chapter 3 3-71 Chapter 4: Recursion and Proof by Induction 4-1 4.1: Recursive Definition 4-2 4.2: Excursion: Recursive Algorithms 4-10 4.3: Proof By Induction for Naturals 4-13 4.4: Variations on Induction for Naturals 4-20 4.5: Excursion: Fibonacci Numbers 4-27 4.6: Proving the Basic Facts of Arithmetic 4-30 4.7: Recursive Definition for Strings 4-37 4.8: Excursion: Naturals and Strings 4-45 4.9: Graphs and Paths 4-47 4.10: Trees and Lisp Lists 4-56 4.11: Induction for Problem Solving 4-66 Glossary for Chapter 4 4-75 S.1: Solutions to Exercises from Chapter 1 S-1 S.2: Solutions to Exercises from Chapter 2 S-16 S.3: Solutions to Exercises from Chapter 3 S-32 S.4: Solutions to Exercises from Chapter 4 S-48 FULL VERSION CONTENTS Chapter 1: Sets, Propositions and Predicates Chapter 2: Quantifiers and Predicate Calculus Chapter 3: Number Theory Chapter 4: Recursion and Proof By Induction Chapter 5: Regular Expressions and Other Recursive Systems Chapter 6: Fundamental Counting Problems Chapter 7: Further Topics in Combinatorics Chapter 8: Graphs Chapter 9: Trees and Searching Chapter 10: Discrete Probability Chapter 11: Reasoning About Uncertainty Chapter 12: Markov Processes and Classical Games Chapter 13: Information Theory Chapter 14: Finite-State Machines Chapter 15: A Brief Tour of Formal Language Theory AUTHOR'S NOTE • This Preliminary Edition contains the first four of the entire book's fifteen chapters, which form the first half of the text for COMPSCI 250 at UMass Amherst in Fall 2019. The final version will include all eight chapters used in 250 and seven others which could be used in COMPSCI 240. • Each chapter has eight ordinary sections and three Excursions. In COMPSCI 250 the 50-minute lectures cover one or sometimes two ordinary sections, and Excursions are used for team problem-solving sessions in the weekly discussion sections. Each ordinary section contains ten Exercises (with solutions in the back) and ten Problems (suitable for homework assignments). Grateful Thanks to: • First and foremost, my wife Jessica and daughter Julia. • The many teachers who helped form me as a mathematician, including David Cox, the late Jim Mauldon, and especially Mark Kidwell at Amherst College, Adrian Mathias at Cambridge University, and Mike Sipser at M.I.T. • Colleagues at UMass who helped form me as a teacher and COMPSCI 250 as a course, including Amy Rosenberg, Neil Immerman, Hava Siegelmann, Marius Minea, and dozens of graduate and undergraduate teaching assistants. • My students in this and other courses. • Emma Strubell, who made most of the diagrams in Chapters 1 and 2. • Bev Kraus and Lenell Wyman at Kendall Hunt. Chapter 1: Sets, Propositions, and Predicates "I came here for a good argument. " "No you didn't, you came here for an argument. " "Well, an argument's not the same as contradiction." "It can be." "No it can't. An argument is a connected series of statements intended to establish a definite proposition." "No it isn't. " "Yes it is. It isn't just contradiction." "Look, if I argue with you I must take up a contrary position. " "But it isn't just saying 'No, it isn't'." "Yes it is." "No it isn't, argument is an intellectual process ... contradiction is just the automatic gainsaying of anything the other person says." "No it isn't. " Our overall goal is to become familiar with a variety of mathematical objects, and learn to both make and prove precise statements about them. In this opening chapter, we will define some of the objects, develop the necessary language and vocabulary to make these statements, and begin to see how to prove them. More specifically, we will: • Give definitions and examples of the most basic objects of discrete mathematics: sets, strings, and formal languages. • Define propositions (boolean variables) and consider the propositional calculus, a method of making, manipulating, and proving combinations of propositions. • Define predicates, functions that take arguments of some type and return propositions. Pred icates can be used to model more complicated English statements within the propositional calculus. 1-1