------------------------------------------------------------------------------ Mohamed G. Gouda CS 311 Fall 2014 Midterm 1 ------------------------------------------------------------------------------ 1. (2 points) Write the Base Case proof that is part of the induction proof for the predicate (All x, x >= 6, 1+2+..+x = x(x+1)/2) where the domain of x is the set of all integers 2. (3 points) Use Equivalence Laws to prove that the following two formulas are equivalent: T --> f(x) f(x) 3. (5 points) Use Equivalence Laws to prove that the following two formulas are equivalent: (f(x) --> g(x)) and (g(x) --> f(x)) (f(x) = g(x)) 4 and 5. (10 points) Let Dx be the set of all non-negative integers Dm be the set of all integers larger than 1 (x mod m) be defined as (the remainder of dividing x by m) 4. (5 points) Use direct inference to prove the following predicate (All x, (0 =< x and x < m) ==> (x = (x mod m))) 5. (5 points) Use guessing to prove the following predicate (Exist x, (x mod m) > ((x+1) mod m) Solutions: 1. Let P(x) be the predicate (1+2+..+x = x(x+1)/2) Base Case: x=6: P(6) <=> {definition of P(6)} 1+2+..+6 = 6(7)/2 <=> {arithmetics} 21 = 3(7) <=> {arthmetics} T 2. T --> f(x) ==> {definition of -->} not(T) or f(x) ==> {truth table of not} F or f(x) ==> {elementary} f(x) 3. (f(x) --> g(x)) and (g(x) --> f(x)) ==> {definiton of -->} (not(f(x)) or g(x)) and (not(g(x)) or f(x)) ==> {distribution of and over or} ((not(f(x)) or g(x)) and not(g(x))) or ((not(f(x)) or g(x)) and f(x)) ==> {distribution of and over or} ((not(f(x)) and not(g(x))) or (g(x) and not(g(x))) or ((not(f(x)) and f(x)) or (g(x) and f(x)) ==> {idempotence} ((not(f(x)) and not(g(x))) or F) or (F or (g(x) and f(x))) ==> {elementary} (not(f(x)) and not(g(x))) or (g(x) and f(x)) ==> {definition of =} f(x) = g(x) 4. (0 =< x and x < m) ==> {definition of remainder} (x = the remainder of dividing x by m) ==> {definition of (x mod m)} (x = x mod m) 5. For x = m-1, (x mod m) = m-1 > 0 = ((x+1) mod m) ----------------------------------------------------------------------------- ------------------------------------------------------------------------------ Mohamed G. Gouda CS 311 Fall 2014 Midterm 1 ------------------------------------------------------------------------------ 1. (2 points) Write the Base Case proof that is part of the induction proof for the predicate (All x, x >= 3, (2^0 + 2^1+..+ 2^x) = (2^(x+1) - 1)) where the domain of x is the set of all integers 2. (3 points) Use Equivalence Laws to prove that the following two formulas are equivalent: (f(x) and not(g(x))) --> F (f(x) --> g(x) 3. (5 points) Use Equivalence Laws to prove that the following two formulas are equivalent: f(x) --> g(x) not(g(x) --> not(f(x)) 4 and 5. (10 points) Let Dx be the set of all non-negative integers Dm be the set of all integers larger than 1 (x mod m) be defined as (the remainder of dividing x by m) 4. (5 points) Use direct inference to prove the following predicate (All x, (0 =< x and x < m) ==> (x = (x mod m))) 5. (5 points) Use direct inference to prove the following predicate (All x, T ==> ((x mod m) = ((x mod m) mod m))) Solutions: 1. Let P(x) be the predicate (2^0 + 2^1 +..+ 2^x = 2^(x+1) - 1) Base Case: x=3: P(3) <=> {definition of P(3)} (1+2+4+8) = (2^4 - 1) <=> {arithmetics} 15 = 16 - 1 <=> {arthmetics} T 2. (f(x) and not(g(x))) --> F ==> {definition of -->} not(f(x) and not(g(x))) or F ==> {elementary} not(f(x) and not(g(x))) ==> {De Morgan's} not(f(x)) or not(not(g(x))) ==> {idempotence of not} not(f(x)) or g(x) ==> {definition of -->} f(x) --> g(x) 3. f(x) --> g(x) ==> {definition of -->} not(f(x)) or g(x) ==> {symmetry of or} g(x) or not(f(x)) ==> {idempotence of not not(not(g(x))) or not(f(x)) ==> {definition of -->} not(g(x)) --> not(f(x)) 4. (0 =< x and x < m) ==> {definition of remainder} (x = the remainder of dividing x by m) ==> {definition of (x mod m)} (x = x mod m) 5. T ==> {definition of (x mod m)} (x mod m) = (remainder of dividing x by m) ==> {definition of remainder} (0 =< (x mod m) and (x mod m) < m) ==> {predicate in Problem 4 above} (x mod m) = ((x mod m) mod m) ----------------------------------------------------------------------------------