(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

Similar documents
To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

To illustrate what is intended the following are three write ups by students. Diagonalization

AXIOMS FOR THE INTEGERS

Fall Recursion and induction. Stephen Brookes. Lecture 4

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

Answer Key #1 Phil 414 JL Shaheen Fall 2010

Propositional Logic. Andreas Klappenecker

CSE 20 DISCRETE MATH. Winter

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

CSE 20 DISCRETE MATH. Fall

Summary of Course Coverage

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

COT 3100 Spring 2010 Midterm 2

CS103 Spring 2018 Mathematical Vocabulary

4&5 Binary Operations and Relations. The Integers. (part I)

Solutions to In-Class Problems Week 4, Fri

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

CS February 17

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

Computer Science 210 Data Structures Siena College Fall Topic Notes: Recursive Methods

1 / 43. Today. Finish Euclid. Bijection/CRT/Isomorphism. Fermat s Little Theorem. Review for Midterm.

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

NP-Completeness of 3SAT, 1-IN-3SAT and MAX 2SAT

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

2SAT Andreas Klappenecker

Recursively Enumerable Languages, Turing Machines, and Decidability

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

CS 125 Section #4 RAMs and TMs 9/27/16

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Today. Finish Euclid. Bijection/CRT/Isomorphism. Review for Midterm.

Horn Formulae. CS124 Course Notes 8 Spring 2018

P Is Not Equal to NP. ScholarlyCommons. University of Pennsylvania. Jon Freeman University of Pennsylvania. October 1989

NP-Complete Reductions 2

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

1. Chapter 1, # 1: Prove that for all sets A, B, C, the formula

Midterm 2 Solutions. CS70 Discrete Mathematics for Computer Science, Fall 2007

1 Definition of Reduction

Notes for Recitation 8

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Midterm 1

Solutions to the Second Midterm Exam

(Refer Slide Time 6:48)

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules

Divisibility Rules and Their Explanations

Introduction to Sets and Logic (MATH 1190)

Strategies for Proofs

1.4 Normal Forms. We define conjunctions of formulas as follows: and analogously disjunctions: Literals and Clauses

The set consisting of all natural numbers that are in A and are in B is the set f1; 3; 5g;

Discrete Mathematics Lecture 4. Harper Langston New York University

3. According to universal addressing, what is the address of vertex d? 4. According to universal addressing, what is the address of vertex f?

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry.

Mathematical Induction

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Indicate the option which most accurately completes the sentence.

Recursion and Structural Induction

CSE 215: Foundations of Computer Science Recitation Exercises Set #4 Stony Brook University. Name: ID#: Section #: Score: / 4

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

8.1 Polynomial-Time Reductions

Chapter 3. Set Theory. 3.1 What is a Set?

Lecture Notes 15 Number systems and logic CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson

Connecting Statements. Today. First there was logic jumping forward.. ..and then proofs and then induction...

Program Verification & Testing; Review of Propositional Logic

Material from Recitation 1

6.001 Notes: Section 4.1

STABILITY AND PARADOX IN ALGORITHMIC LOGIC

Sets. Margaret M. Fleck. 15 September 2010

Graph Theory Questions from Past Papers

(l) Represent each of the sets A, B and C using bit strings. Then, use bit string representation and bitwise logical operations to find

THE PRINCIPLE OF INDUCTION. MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin

CS 512, Spring 2017: Take-Home End-of-Term Examination

UNIT-II NUMBER THEORY

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

Computer Science 236 Fall Nov. 11, 2010

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

CS446: Machine Learning Fall Problem Set 4. Handed Out: October 17, 2013 Due: October 31 th, w T x i w

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

4.1 Review - the DPLL procedure

CS 456 (Fall 2018) Scribe Notes: 2

HW1. Due: September 13, 2018

Propositional Calculus. Math Foundations of Computer Science

Exact Algorithms Lecture 7: FPT Hardness and the ETH

CS 395T Computational Learning Theory. Scribe: Wei Tang

Section 2.2: Introduction to the Logic of Quantified Statements

Discrete mathematics

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

CS40-S13: Functional Completeness

Ma/CS 6b Class 26: Art Galleries and Politicians

1 Variations of the Traveling Salesman Problem

Introduction to Computer Architecture

Transcription:

CS 70 Discrete Mathematics for CS Fall 2000 Wagner MT1 Sol Solutions to Midterm 1 1. (16 pts.) Theorems and proofs (a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1,a 2,b 1,b 2 as follows: a = a 1 a and b = b 1 2 b. We then substitute these equalities in to ab to get ab = a 1 b 1 2 a 2 b. Because the 2 integers are closed under multiplication the numerator and denominator of the right hand side are integers, and therefore ab is rational. (b) (6 pts) Prove hat if x is irrational, x 1 3 is irrational. The contrapositive, If x 3 1 is rational then x is rational. is logically equivalent to the statement in the problem and straightforward to prove. If x 1 3 is rational then by the first part of this problem, x 1 3 x 1 3 is rational. Then since both x 1 3 and x 1 3 x 1 3 are rational, again by the first part of the problem x 1 3 x 1 3 x 1 3 = x is rational. Many people tried to prove this by contradiction, and everyone should take a minute to try and construct a carefully worded proof by contradiction. (c) (6 pts) Write down the converse of the implication in part (b). State whether the converse is true or false, and prove your assertion. The converse is: if x 1 3 is irrational, then x is irrational. A counter example is x = 2. It is important to note that this requires knowing that 2 1 3 is in fact irrational, which was not proven in class, but can be proven in a similar fashion. This was not required for full credit on the problem, but definitely makes a better answer. 2. (25 pts.) Induction (a) (10) Prove by induction that 5 n 1 is divisible by 4 for all n 1. Base Case: P(1): 5 1 1 = 4 which is clearly divisible by 4. Inductive Step: P(n) = P(n + 1): By the inductive hypothesis 5 n 1 is divisible by 4 so 5 n 1 = 4k for some integer k. Now 5 n+1 1 = 5(5 n 1) + 4 = 5(4k) + 4 = 4(5k + 1) so 4 divides 5 n+1 1. (b) (10) Let S(n) = 1 i=1 i denote the sum of the first n natural numbers. What is wrong with the following proof that S(n) = 1 ( 2 n + 1 2 2) for all n 1. Base Case: The claim is obviously true for n=1. Inductive Step: 1

S(n + 1) = S(n) + (n + 1) = 1 2 (n + 1 2 )2 + n + 1 by inductive hypothesis = 1 2 (n2 + n + 1 4 ) + n + 1 = 1 2 (n2 + 3n + 9 4 ) = 1 2 ((n + 1)2 + 1 2 ) The claim that the base case is obviously true is false because S(1) = 1 i=1 i = 1 9 8 = 1 2 (1+ 1 2 )2. The inductive step is valid. 3. (18 pts.) Satisfiability and All that For each of the following Boolean expressions, decide if it is (i) valid; or (ii) satisfiable but not valid; or (iii) unsatisfiable. Justify all your answers. (a) (6 pts) (A B) (B C) (C A); For A = B = C = F the expression is false, and for A = B = C = T the expression is true, so it is not valid, satisfiable, and not unsatisfiable. (b) (6 pts) (A B) (B C) (C A); For A = T and B = F the expression is true and for A = B = C = F The expression is false, so it is not valid, satisfiable, and not unsatisfiable. (c) (6 pts) A ( A B) ( A B); For the expression to be true, A must be true, and therefore by examining the second clause B must be true. Finally this implies that the third clause is in fact false since A and B are both true. The conclusion is that the expression cannot be true, and is not valid, not satisfiable, and in fact unsatisfiable. This can also be checked directly by a truth table. 4. (24 pts.) Recursion The following algorithm, given as inputs a real number x and a natural number y, is supposed to output the value x y. algorithm exp(x,y) if y = 0 then return(1) else z := exp(x, y 2 ) if y is even then return(z z) else return(x z z) (a) (4 pts) Hand-turn the algorithm to compute exp(3,7). Show your working. The sequence of recursive calls made by the algorithm is as follows: exp(3, 3); exp(3, 1); exp(3, 0). The last of these is the base case, and is immediately evaluated to 1. Unwinding the recursion, the algorithm computes the following successive values of z: 3 1 1 = 3;3 3 3 = 27;3 27 27 = 2187. CS 70, Fall 2000, MT1 Sol 2

This last number is indeed 3 7, as expected. Almost everybody answered this correctly (modulo trivial arithmetic errors). (b) (10 pts) Prove by induction on y that the algorithm is correct. Let P(y) be the proposition Given any input of the form (x,y), where x is a real number, algorithm exp halts and returns the value x y. Our goal is to prove P(y) for all natural numbers y, by strong induction on y. The base case, y = 0, is immediate: here the algorithm returns the value 1, which is correct since x 0 = 1 for all x. Now consider some value y 1. By the strong induction hypothesis, we may assume that a call of the form exp(x,y ), for any y < y, halts and returns the correct value x y. Now since y 1, the algorithm will follow the first else clause and will evaluate the recursive call z = exp(x, y 2 ). But since y 2 is less than y, we may assume that this recursive call returns the correct value, i.e., that z = x y 2. To finish off, we consider two cases (following the algorithm): Case 1 y is even. In this case the algorithm returns z z = (x y ) 2 ( ) 2 = x y 2 2 = x y. Case 2 y is odd. In this case the algorithm returns x z z = x (x y ) 2 ) 2 = x (x y 1 2 2 = xx y 1 = x y. Thus in both cases the algorithm returns the correct value, x y, which completes the proof of P(y) for all y by induction. This part was answered correctly, or almost correctly, by many people. The most common mistake was to try to prove P(y) using P(y 1), or equivalently to prove P(y + 1) using P(y) (i.e., using simple induction rather than strong induction). Note that this is hopeless because the recursive call made by the algorithm involves the parameter y 2, not y 1. An inductive proof of properties of a recursive procedure should always follow the recursive structure of the procedure itself. (c) (10 pts) Prove, also by induction, that the number of multiplications performed by the algorithm is no more than 2b(y), where b(y) is the number of bits in the binary representation of y. Let Q(y) be the proposition Given any input of the form (x,y), where x is a real number, algorithm exp performs at most 2b(y) multiplications. We will prove Q(y) by induction on y, following exactly the same pattern as we did in part (b). The base case is again y = 0. Here the algorithm performs no multiplications, while b(y) = 1. So the base case certainly holds. Actually (as we ll see in a moment) it is convenient to define b(y) = 0 when y = 0. Note that the base case holds even with this more stringent definition of b(0). Now consider y 1. By the strong induction hypothesis, we know that the recursive call exp(x, y 2 ) requires at most 2b( y 2 ) multiplications. Now it is convenient to observe that, for any natural number y, we have b( y 2 ) = b(y) 1. ( ) To see this, just note that the binary representation of y 2 is obtained by simply deleting the least significant bit of y. [Note: To make this correct when y = 1, we need to define b(0) = 0; this is why we did this above. We could avoid this little trick by handling the case y = 1 as an additional base case instead.] CS 70, Fall 2000, MT1 Sol 3

Now we can consider the same two cases as we did in part (b). Case 1 y is even. In this case the number of multiplications performed is at most 2b( y 2 ) + 1, where the first term comes from the recursive call and the extra one is the multiplication to compute z z. Using ( ), this evaluates to 2b( y 2 ) + 1 = 2(b(y) 1) + 1 = 2b(y) 1 < 2b(y). Case 2 y is odd. In this case the number of multiplications is at most 2b( y 2 ) + 2, where again the first term comes from the recursive call and the extra two from the computation x z z. Using ( ) again, this evaluates to 2b( y 2 ) + 2 = 2(b(y) 1) + 2 = 2b(y). Thus in both cases the number of multiplications is at most 2b(y). This completes the proof of Q(y) for all y by induction. People seemed to have a bit more trouble with this part than with part (b). Again, one of the common problems was trying to prove Q(y) using Q(y 1): as in part (b), this is doomed. Other people were confused about the relationship between the number of bits in the binary representations of y and y 2 : see ( ) above. Some people tried to do an induction not on y itself, but on the number of bits in y. In other words, you are proving the proposition R(n), which says Given any input of the form (x,y), where x is a real number and y is a natural number whose binary representation has exactly n bits, algorithm exp performs at most 2n multiplications. This is fine in fact it is arguably more elegant than the above proof. However, you still need to use ( ) to show that in the recursive call the number of bits decreases by one, so that the inductive hypothesis R(n 1) can be applied. This is a simple induction, not a strong induction. 5. (20 pts.) Kowalski Normal Form A Boolean expression is in Kowalski Normal Form (KNF) if it is a conjunction of implications, where the premise of each implication has a conjunction of variables and the conclusion of each implication is a disjunction of variables. (Note: variables, not literals.) For example, the expression (B C) = (A D) is in KNF. (a) Prove that (B C) = (A D) is logically equivalent to (A B C D). (B C) = (A D) (B C) (A D) (defn of = ) ( B C) (A D) (de Morgan) ( B C A D) (associativity) (A B C D) (commutativity) This part was answered very well by almost everybody. (b) Prove by induction that (X 1 The proof is by simple induction on n, the number of variables. P(n) is the assertion that (X 1 Base case: n = 1. The disjunction or conjunction of one expression is logically equivalent to that expression, hence P(1) is the assertion that X 1 X 1, which is true. Inductive step: prove P(n) = P(n + 1). Inductive hypothesis: (X 1 CS 70, Fall 2000, MT1 Sol 4

To prove: (X 1 X n X n+1 ) ( X 1 X n X n+1 ). (X 1 X n X n+1 ) ((X 1 X n ) X n+1 ) (associativity) (X 1 X n ) X n+1 (de Morgan) ( X 1 X n ) X n+1 (inductive hypothesis) ( X 1 X n X n+1 ) (associativity) Almost everyone who did a simple induction on n got this right, although there were some rather Byzantine ways of dividing up n + 1 literals into smaller pieces. Many people tried to do this as an induction over all Boolean expressions, which fails altogether because the assertion is just about a disjunction of variables, not all Boolean expressions. The failure was usually not noticed because the statement of P( ) was omitted; as soon as one tries to state b B P(b), one realizes this doesn t make sense. (c) Now prove that every Boolean expression is logically equivalent to an expression in KNF. The key step is to realize that KNF is a conjunction of implications like the one in part (a). Part (a) shows that the implication can be converted to a disjunction of literals, so we re looking at a conjunction of disjunctions of literals i.e., CNF. The formal argument goes as follows: Every Boolean expression b is equivalent to an expression in CNF, CNF(b), which is a conjunction of clauses C 1 C m. Each clause C i contains positive and negative literals; without loss of generality, call these X 1,...,X k and Y 1,..., Y l. By commutativity, C i can be written as ( Y 1 Y l X 1 X k ). By associativity and the dual version of the result in (b), this is equivalent to (Y 1 Y l ) (X 1 X k ), which in turn is equivalent to (Y 1 Y l ) = (X 1 X k ), i.e., a KNF clause. Hence, every Boolean expression is equivalent to an expression in KNF. Almost everyone who saw the connection to CNF got this right; the only problem was proving in the wrong direction i.e., proving that every KNF expression is equivalent to a CNF expression. Obviously, this could be true even if the set of KNF expressions is empty! Others made valiant attempts to prove the assertion by structural induction over Boolean expressions. This is a proper use of induction in this case, but no one managed to get it quite right. CS 70, Fall 2000, MT1 Sol 5