Final practice CS1050: Understanding and Constructing Proofs Spring 2006 Final practice This work is carried by Jarek Rossignac and one of his PhD students, Jason Williams Jarek Rossignac
Logical operators Sets Propositions Bit strings n for each n n for at least one n empty set sS s is an element of S sS s is an element of S S, !S elements not in S ST elements in S and T ST elements in S or T S–T ST ST (ST) – (ST) S=T S equals T S T S included in T S T S properly in T S T Cartesian product Propositions T, F true, false ¬p, !p, p not p pq p and q pq p or q p q, p ≠ q p xor q p q p implies q p q, p==q p same as q p q, p q p equivalent to q therefore Bit strings S | T bitwise OR S & T bitwise AND S << n shift left by n bits
Logic When is (pq) (rs) true? When is (p q) true? When is “If today is Friday, then 2+3=4” true? What is the contrapositive of (p q)? Express “You may access the Internet (a) only if you are a computer science major (c) or if you are not a freshman (f).” as a logic statement
Logic Solution When is (pq) (rs) true? When is (p q) true? When 1 or 3 are false When is (p q) true? When q is true and when (q is faslse and p true) When is “If today is Friday, then 2+3=4” true? Everyday except Friday What is the contrapositive of (p q)? q p Express “You may access the Internet (a) only if you are a computer science major (c) or if you are not a freshman (f).” as a logic statement (a c f)
What is the list of rules of inference? Addition p pq Simplification pq p Conjunction (p)(q) pq Modus ponens p(p q) q Modus tollens ¬q(p q) ¬p Hypothetical syllogism (pq)(qr) (pr) Disjunctive syllogism (pq)¬p q Resolution (pq)(¬pr) (qr)
Quantifiers and arguments For what universe of discourse is (x, x<x2) true? G(t) means teacher t is great. Translate “All teachers are great” into logic. Ten write its negation. Assume “If you send me email (p), I will finish the program (q). Otherwise I will go to bed early (r)”. “If I go to bed early, I will wake up happy (s)”. Prove “If I do not finish the program, I will wake up happy”
Quantifiers and arguments solutions For what universe of discourse is (x, x<x2) true? x<0 or x>1 G(t) means teacher t is great. Translate “All teachers are great” into logic. Ten write its negation. t G(t) t G(t) Assume “If you send me email (p), I will finish the program (q). Otherwise I will go to bed early (r)”. “If I go to bed early, I will wake up happy (s)”. Prove “If I do not finish the program, I will wake up happy” p q Hypothesis ¬q ¬p Contrapositive ¬p r Hypothesis ¬q r Hypothetical Syllogism from 2) and 3) r s Hypothesis ¬q s Hypothetical Syllogism
More proofs Prove C from H1 and H2 H1: “If you do all the exercises (p), then you will get an A (q)” H2: “You got an A (q)” C: “You did all the exercises (p)” Prove: “If n is an odd integer, then n2 is an odd integer”
More proofs solutions Prove C from H1 and H2 H1: “If you do all the exercises (p), then you will get an A (q)” H2: “You got an A (q)” C: “You did all the exercises (p)” Cannot! This is a fallacy of affirming the conclusion: (pq)q p Maybe you got an A because you are a genius! Prove: “If n is an odd integer, then n2 is an odd integer” Suppose that n is odd. Then, there is an integer k such that n=2k+1. Hence, n2=(2k+1)2 = 4k2+4k+1 = 2(2k2+2k) +1 Thus n2 is odd.
Indirect proofs Prove “If 3n+2 is odd, then n is odd” Prove “n integer and n2 odd n odd”
Indirect proofs solutions Prove “If 3n+2 is odd, then n is odd” Suppose that n not odd (i.e., n is even). Then there is an integer k such that n=2k. Hence, 3n+2 = 3(2k)+2 = 2(3k+1) Thus 3n+2 is not odd. Prove “n integer and n2 odd n odd” Assume n is even: k n=2k Then n2=2(2k2) Hence n2 is not odd
Sets and CSG C A B What are De-morgan laws Prove A(BC)=(AB)(AC) CSG expression S for the figure Convert S to positive form Compute the path of A Compute the active zone for a primitive Render the active zone A B
Sets and CSG solutions C A B C A B What are De-morgan laws !(AB) = !A!B , !(AB) = !A!B Prove A(BC)=(AB)(AC) CSG expression S for the figure S = A – (B – C) Convert S to positive form S=A(B’+C) Compute the path of A Root Compute the active zone for a primitive Z= B’+C Render the active zone A B C A B
Sorting Code for bubble sort for (i=0; i<n-1; i++) { for (j=0; j<n-1-i; j++) if (a[j+1] < a[j]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } // next j } // next i Produce a balanced search tree for 1,3,4,6,7,8,9 and explain the search steps for 5.
Complexity Prove that log2n is O(n) When is a problem tracktable? n < 2n log2n < n log22 = n (taking the log2 on both sides) hence log2n is O(n) When is a problem tracktable? When is it solvable in polynomial time When is a problem NP? When we believe that the problem is not tractable but can check a solution in polynomial time When is a problem NP complete? When it falls in a class of NP problems such that if a polynomial solution exists for one, then there exist polynomial solutions for the others Give an example of an NP complete problem Find whether a Boolean function in n variables can be satisfied
Graphs How to compute the graph-distance from a vertex s? What is the complexity of that algorithm?
Integers Prove that if a divides b and c, it divides their sum a | b xZ b=xa , a | c yZ c=ya, b+c=xa+ya=(x+y)a What is the fundamental thorem of arithmetic Every integer greater than 1 can be written uniquely as a product of one or more primes (“divisors”) of non-decreasing size What are (–11 div 3) and (–11 mod 3) ? –4 (a=dq+r with 0≤r<d : –11=3(–4)+1) 1 (a=dq+r with 0≤r<d : –11=3(–4)+1) What is the binary expansion of 241? 11110001 Use the euclidean algorithm to compute gcd(662,414) Use gcd(bq+r,b)=gcd(b,r) gcd(662,414)=gcd(414•1+248,414) gcd(414,248)=gcd(248•1+166, 248) gcd(248,166)=gcd(248=166•1+82 ,166) gcd(166,82)=gcd(82•2+2,82) gcd(82,2)=gcd(2•41+0, 2)= 2
Coordinates and matrices How to change coordinate systems? How to express these changes using matrices?
Change of coordinate system v = p – o x = v i y = v j o i j p x y xo yo xi yi yp xp Local Global p = o + xi + yj matrix form with homogeneous coordinates 1 yp xp yo xo yj xj yi xi = y x
Sequences Formulae and sums for arithmetic / geometric progressions
Sequences solutions Formulae and sums for arithmetic / geometric progressions {a+nd}, ∑k=0n(k) = (n+1)n/2 {arn}, ∑k=0n(rk) = (rn+1–1)/(r–1) for r≠1