6 Pages

pset2_sol

Course: CS 103, Fall 2009
School: Stanford
Rating:
 
 
 
 
 

Word Count: 2215

Document Preview

Discrete CS103X: Structures Homework Assignment 2: Solutions Due February 1, 2008 Exercise 1 (10 Points). Prove or give a counterexample for the following: Use the Fundamental Theorem of Arithmetic to prove that for n N, n is irrational unless n is a perfect square, that is, unless there exists a N for which n = a2 . Solution: We will prove the statement by contradiction. Assume n N is not a perfect square,...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> Stanford >> CS 103

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Discrete CS103X: Structures Homework Assignment 2: Solutions Due February 1, 2008 Exercise 1 (10 Points). Prove or give a counterexample for the following: Use the Fundamental Theorem of Arithmetic to prove that for n N, n is irrational unless n is a perfect square, that is, unless there exists a N for which n = a2 . Solution: We will prove the statement by contradiction. Assume n N is not a perfect square, yet its square root is a rational number p for coprime integers p, q, q where q = 0. So n = p or n = ( p )2 . Without loss of generality, we can assume both q q p and q are non-negative. If p = 0, then n = 0 which is a perfect square, contradicting our assumption. So we can assume both p and q are positive. By the Fundamental Theorem of Arithmetic, we can uniquely write both p and q as products of primes, say p = p1 p2 . . . pm and q = q1 q2 . . . qn . Since p and q are coprime, they have no common factors, so pi = qj for all 1 i m, 1 j n. We have: p2 = (p1 p2 . . . pm )2 = p2 p2 . . . p2 1 2 m and 2 2 2 q 2 = (q1 q2 . . . qn )2 = q1 q2 . . . qn Now p2 andq 2 cannot have any common factors > 1 if they did have a common factor d > 1, any prime factor f of d (and there must be at least one such) must also be a common prime factor of p2 and q 2 (transitivity of divisibility). By the Fundamental Theorem of Arithmetic, p2 p2 . . . p2 is the unique prime factorization of p, so f 1 2 m must be one of the primes p1 , p2 , . . . , pm . Similarly, f must also be one of the primes q1 , q2 , . . . , qn . But this contradicts our statement that no pi = qj . So p2 and q 2 are coprime. A ratio of natural numbers in lowest terms is itself a natural number if and only if its denominator is 1. Since n N , we must have q 2 = 1, which implies q = 1. But then n must be the perfect square p2 , which contradicts our assumption. The statement is thus proved by contradiction. Exercise 2 (20 Points). Prove or disprove, for integers a, b, c and d: (a) If a|b and a|c, then a|(b + c). (b) If a|bc and gcd(a, b) = 1, then a|c. (c) If a and b are perfect squares and a|b, then 1 a| b. (d) If ab|cd, then a|c or a|d. Solution: (a) If a|b then b = ma for some integer m and if a|c then c = na for some integer n. Thus, (b + c) = ma + na = (m + n)a. Since m + n is an integer, a|(b + c) (b) The proof is essentially identical to that of Theorem 5.1.1.a. Since gcd(a, b) = 1, there exist integers u, v with au + bv = 1. Multiply both sides by c to get c = auc + bcv (by the result of the first part of this exercise). We know that a|bc so a|bcv and of course a|auc, so a|(auc + bcv). Thus a|c. (c) Proof by contradiction: Assume b is not divisible by a. Consider the prime factorizations of a and b - there must be some prime p that appears m times in the prime factorization of a and n times in the prime factorization of b with m > n. The prime factorizations of perfect squares include every element of their square roots factorization twice, so p must occur 2m times in the prime factorization of a and 2n times in the prime factorization of b. But 2m > 2n, which implies that b is not divisible by a, a contradiction. Therefore a| b. (d) False. One possible counterexample is a = 10, b = 1, c = 4, d = 25. Exercise 3 (25 Points). On Euclids algorithm: (a) Write the algorithm in pseudo-code. (10 points) (b) Prove that Euclids Algorithm correctly finds the GCD of a and b in a finite number of steps. (10 points) (c) Use the algorithm to calculate gcd(1247, 899). Write out the complete sequence of derivations. (5 points) Solution: (a) Procedure GCD-Euclid Input: Integers a, b, not both 0. i. a = |a|, b = |b| ii. If b > a then swap a and b first iii. If b = 0, then return a iv. q = ba/bc (Quotient) v. r = a - q b (Remainder) vi. If r = 0, then return b vii. Return GCD-Euclid(b, r) 2 The first three lines are needed only for the recursive call and can be factored out with a second procedure. The following nonrecursive version also works: Procedure GCD-Euclid-Nonrecursive Input: Integers a, b, not both 0. i. a = |a|, b = |b| ii. If b > a then swap a and b iii. If b = 0, then return a iv. Do v. q = ba/bc (Quotient) vi. r = a - q b (Remainder) vii. If r = 0, then return b viii. a = b ix. b = r x. Loop (b) Theorem. Euclid's Algorithm correctly finds the GCD of a and b in a finite number of steps. Proof. We will prove the correctness of the algorithm in the context of the recursive listing above. The proof for the non-recursive version is identical except that it is slightly more difficult to phrase correctly. The first couple of lemmas help to justify the assumption a > b > 0 in the lecture notes. Lemma 1. d|a if and only if d | |a|. Proof. First we show that if d|x, then d| - x. By the Division Algorithm, x = qd for some integer q, so -x = -qd = (-q)d. Since -q is obviously integral since q is (and the Division Algorithm guarantees that this is an unique representation given x, d), d divides -x. So if d|a, then |a| is either a, which is trivially divisible by d, or -a, which by the above reasoning is also divisible by d. Similarly, if d | |a|, then a is either |a| or -|a|, both of which are divisible by d as above. This proves the result. Lemma 2. gcd(a, b) = gcd(|a|, |b|) = gcd(|b|, |a|) Proof. Let d = gcd(a, b). Since d = gcd(a, b), d|a and d|b, so by Lemma 1, d | |a| and d | |b|, i.e. d is a common divisor of --a-- and --b--. Now we prove by contradiction that d is the greatest such divisor. Assume there is some c > d such that c | |a| and c | |b|. Then by Lemma 1, c|a and c|b. So c is a common divisor of a and b strictly greater than the GCD of a and b, which contradicts the definition of the GCD. Therefore we must have gcd(a, b) = gcd(|a|, |b|). Also, the definition of gcd(x, y) is clearly symmetric in x and y, so gcd(|a|, |b|) = gcd(|b|, |a|). Hence proved. 3 Back to the original problem. Let P (n) be the following statement: "Euclids Algorithm finds the correct GCD of a and b in a finite number of steps, for all 0 a, b n (a and b not both 0)." will We prove P (n) holds for all positive integers n by induction. We assume a b: if not, the first couple of steps of the algorithm will take their absolute values and swap them if necessary so the relation holds, and by Lemma 2 the GCD of these two new values is precisely the same as the GCD of the original values. The base case, n = 1, has two possibilities: a = 1, b = 0, or a = 1, b = 1. In the first case, the third line of the algorithm returns the correct GCD 1, and in the second case r evaluates to 0 before any recursive calls, so the correct GCD b = 1 is returned, in a finite number of steps (no recursive calls, so at most 6 lines of pseudocode). Now assume P (n) is true and consider P (n + 1), where we allow the values of a and b to be at most n + 1. If b = 0, the third line returns the correct GCD, a. If b|a, gcd(a, b) = b, which is the value returned by the algorithm since r evaluates to 0. Otherwise, the algorithm recursively computes and returns gcd(b, r). Now by Lemma 4.3.1 in the lecture notes, gcd(a, b) = gcd(b, r). Also, since 0 r < b n + 1, r and b are both at most n (if b was n + 1, a would also be n + 1, which implies b|a, which is a case we have already handled) and not both zero. Hence by the inductive hypothesis, Euclids Algorithm correctly computes gcd(b, r) in a finite number of steps, which implies that it also correctly computes gcd(a, b) in a finite number of steps, since the sequence of steps before the recursive call adds only a finite overhead. Hence P (n + 1) is true. This proves the claim by induction. The truth of P (n) for all n N+ obviously implies the theorem. (c) The first step of the algorithm swaps 1247 and 899 so a = 1247, b = 899. We tabulate the values of a, b and r in each successive iteration until r = 0: Iteration a b r 1 1247 899 348 2 899 348 203 3 348 203 145 4 203 145 58 5 145 58 29 The value of b when r is zero is 29, so this is the GCD. Exercise 4 (20 Points) Some prime facts: (a) Prove that for every positive integer n, there exist at least n consecutive composite numbers. (10 points) 4 (b) Prove that if an integer n 2 is such that there is no prime p n, then n is a prime. (10 points) Solution: n that divides (a) Recall the definition n! = 1 2 3 n for any positive integer n. Consider the consecutive positive integers (n + 1)! + 2, (n + 1)! + 3, . . . (n + 1)! + (n + 1). By definition of factorial, all integers from 2 to (n+1) divide (n+1)!, so 2|((n+1)!+2), 3|((n + 1)! + 3), and so on up to (n + 1)|((n + 1)! + (n + 1)) (remember the property of divisibility proved in Exercise 3a.) Thus all members of this sequence are composite, making n consecutive composite numbers. This sequence can be generated for any n, so for all n there exists at least n consecutive composite numbers. (b) Proof by contradiction: Assume n is not prime. By Theorem 5.1.2, n = p1 p2 . . . pk for primes p1 p2 . . . pk , and since n is not prime k 2. Since no prime less than or equal to n divides n, n < p1 p2 . Then p1 p2 > n, so n = p1 p2 . . . pk > n, a contradiction. Thus our assumption was false and n must be prime. Exercise 5 (25 Points) A fun game: To start with, there is a chart with numbers 1211 and 1729 written on it. Now you and I take turns and you go first. On each players turn, he or she must write a new positive integer on the board that is the difference of two numbers that are already there. The first person who cannot create a new number loses the game. For example, your first move must be 1729 - 1211 = 518. Then I could play either 1211 - 518 = 693 or 1729 - 518 = 1211, and so forth. (a) Prove every...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Columbia - JM - 3058
As a post-doctoral fellow at Columbia University under Professor Michael Weinstein, the applicant will pursue further studies of linear and nonlinear dispersive equations. Such studies will include stability theory of solitons, describing the spectru
Columbia - IEOR - 3106
IEOR 3106: Introduction to Operations Research: Stochastic Models Fall 2006, Professor Whitt, Final Exam Chapters 4-7 and 10 in Ross, Tuesday, December 19, 4:10pm-7:00pm Open Book: but only the Ross textbook, three 8 11 pages of notes, and the class
Columbia - MH - 2078
IEOR E4706: Financial Eng: Discrete-Time Asset PricingColumbia University Instructor: Martin Haugh Midterm Examination October 26th 2004 Total Marks: 100 Time: 2 hours Notes that are on either side of a single letter size sheet of paper may be used
Columbia - MH - 2078
Financial Engineering I, IEOR E4706, Fall 2003Columbia University Instructor: Martin Haugh Final Examination, December 16th 2003 Total Marks: 100 Time: 3 hours Notes that are on both sides of a single sheet of A4 paper may be used during the exam. Q
Columbia - FE - 2078
Financial Engineering I, IEOR E4706, Fall 2003Columbia University Instructor: Martin Haugh Final Examination, December 16th 2003 Total Marks: 100 Time: 3 hours Notes that are on both sides of a single sheet of A4 paper may be used during the exam. Q
Stanford - EE - 392
Ellipsoid Method ellipsoid method convergence proof inequality constraints feasibility problemsProf. S. Boyd, EE392o, Stanford UniversityChallenges in cutting-plane methods can be difficult to compute appropriate next query point localiza
Stanford - MSANDE - 310
Yinyu Ye, MS&amp;E, StanfordMS&amp;E310 Lecture Note: Ellipsoid Method1The Ellipsoid (Kachiyan) MethodYinyu Ye Department of Management Science and Engineering Stanford University Stanford, CA 94305, U.S.A.http:/www.stanford.edu/ yyyeYinyu Ye, MS
SUNY Buffalo - UB - 2020
ITSM Tool Selection#3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.1 3.3.1.1 3.3.1.2 3.3.1.3 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.3.3.1 3.3.3.2 3.3.3.3 3.3.4 3.3.4.1 3.3.4.2 3.3.4.3 3.3.4.4 3.3.4.5 3.3.4.6 3.4.1G
Colorado - WP - 05
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 05-07 Environmental Injustice and Residential Segregation: Investigating the LinkJosh SidonUniversity of Colorado at Boulder Boulder, ColoradoOctober 24, 2005Center for Economic Analysis Departm
Colorado - WP - 03
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 03-19Estimating Stochastic Frontier Tax Potential: Can Indonesian Local Governments Increase Tax Revenues Under Decentralization?Luky AlfirmanDepartment of Economics, University of Colorado at Boul
Colorado - WP - 03
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 03-12U.S. Affiliates, Infrastructure and Growth: A Simultaneous Investigation of Critical MassDerek K. KellenbergDepartment of Economics, University of Colorado at Boulder Boulder, ColoradoOctobe
Colorado - WP - 03
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 03-03 Anarchy and Demand for the State in a Trade EnvironmentAnna Rubinchik-PessachDepartment of Economics, University of Colorado at Boulder Boulder, ColoradoRoberto M. SamaniegoDepartment of Ec
Colorado - WP - 07
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 07-08Intrametropolitan Decentralization: Overlapping Jurisdictions and Efficient Local Public Good ProvisionStephen BillingsUniversity of ColoradoNovember 15, 2007Center for Economic Analysis
Colorado - WP - 04
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 04-05On the Efficacy of Reforms: Policy Tinkering, Institutional Change, and EntrepreneurshipMurat IyigunDepartment of Economics, University of Colorado at Boulder Boulder, ColoradoDani RodrikJo
Colorado - WP - 08
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 08-04Multinationals and the Shutdown of State-Owned EnterprisesGrzegorz PacUniversity of ColoradoOctober 2008Center for Economic Analysis Department of EconomicsUniversity of Colorado at Bou
Colorado - WP - 03
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 03-13Modeling Network Externalities, Network Effects, and Product Compatibility with Logit Demand(Revision of Working Paper No. 03-06) Collin StarkweatherDepartment of Economics, University of Colo
Colorado - WP - 05
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 05-08 IPRs and Tariff Policies: East-West Joint VenturesXiaofei Vivian YangUniversity of Colorado at Boulder Boulder, ColoradoNovember 9, 2005Center for Economic Analysis Department of Economics
Colorado - WP - 05
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 05-04Community Income Distributions in a Metropolitan AreaCharles A. M. de BartolomeUniversity of Colorado at Boulder andStephen L. RossUniversity of ConnecticutJuly 2005Center for Economic
Colorado - WP - 04
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 04-01Building the Family Nest: A Collective Household Model with Competing Pre-marital Investments and Spousal MatchingMurat F. IyigunDepartment of Economics, University of Colorado at Boulder Boul
Colorado - WP - 05
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 05-06An Explanation of OECD Factor Trade with Knowledge Capital and the HOV ModelShuichiro Nishioka University of Colorado at BoulderOctober, 2005 Revised: October, 2006Center for Economic Anal
Colorado - WP - 04
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 04-04Marketing InnovationYongmin ChenDepartment of Economics, University of Colorado at Boulder Boulder, ColoradoFebruary 2004Center for Economic Analysis Department of EconomicsUniversity of
Colorado - WP - 04
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 04-02Stated Preference Analysis of Public Goods: Are we asking the right question?Nicholas E. FloresDepartment of Economics, University of Colorado at Boulder Boulder, ColoradoAaron StrongDepart
Colorado - WP - 07
DISCUSSION PAPERS IN ECONOMICSWorking Paper No. 07-04Does Access to Family Planning Services Improve Women's Welfare? Evidence on Dowries and IntraHousehold Bargaining in BangladeshChristina PetersUniversity of ColoradoOctober 2007Center fo
Colorado - STANDARDS - 2007
Colorado - MCEN - 3021
FALL 2006MCEN 3021Syllabus for Fluid MechanicsInstructor: Patrick Weidman (ECME 216, 492-4684, weidman@colorado.edu) Assistants: Shanon McIntyre (ECME 215, Shanon.McIntyre@colorado.edu) Scott Reckinger (ECME 215, Scott.Reckinger@Colorado.edu) H
Colorado - MCEN - 4173
Finite Element Analysis(MCEN 4173/5173)Instructor: Dr. H. Jerry Qi Fall, 2006What is Finite Element Analysis (FEA)?- A numerical method. - Traditionally, a branch of Solid Mechanics. - Nowadays, a commonly used method for multiphysics problems.
Colorado - CHEM - 5181
Interviews with HP 5989 ESI UsersMatt Fete Matt Fete, a member of the Michl physical-organic research group, is a regular user of the HP5989 ESI-QMS. In general, the group specializes in the synthesis of organic and organometallic compounds whose p
Colorado - PHYS - 1110
Physics 1110Fall 2004Lecture 30 Announcements3 November 2004 Reading Assignment for Fri, Nov. 5: Knight (11.7-11.9)Calculating WorkIn the last lecture, we learned how to calculate the work for a constant force acting along a straight-line
Colorado - ECON - 8231
University of Colorado - Boulder Department of EconomicsProf. Jeffrey S. Zax zax@colorado.edu 303-492-8268 Economics 8231 Syllabus and Schedule 14 January 2008Welcome. I am Prof. Jeffrey S. Zax. This is Economics 8231, Local Public Economics. This
Colorado - ECON - 8231
University of Colorado - Boulder Department of EconomicsProf. Jeffrey S. Zax zax@colorado.edu 303-492-8268 Economics 8231 Syllabus and Schedule 30 August 2006Welcome. I am Prof. Jeffrey S. Zax. This is Economics 8231, Local Public Economics. This
Colorado - ECON - 8231
University of Colorado - Boulder Department of EconomicsProf. Jeffrey S. Zax zax@colorado.edu 303-492-8268 Economics 8231 Syllabus and Schedule 16 April 2005Welcome. I am Prof. Jeffrey S. Zax. This is Economics 8231, Local Public Economics. This c