{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 1 12 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 270 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 271 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 272 "" 0 1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 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" -1 256 1 {CSTYLE "" -1 -1 "Time s" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 8 4 1 0 1 0 2 2 0 1 } {PSTYLE "Normal" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 12 "Assignment 2" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 268 5 "Note:" }{TEXT 287 1 " " }{TEXT 288 106 "While w riting any procedure, you'd better declare local variables in the body of the procedure and end the" }{TEXT -1 0 "" }{TEXT 282 35 " procedur e definition with a colon." }{TEXT 260 2 "\n\n" }}{PARA 0 "" 0 "" {TEXT 290 10 "Problem 1." }{TEXT -1 61 " \n(a) Write a program (not n ecessarily a procedure) using a " }{TEXT 276 7 "do loop" }{TEXT -1 20 " to compute the sum " }{XPPEDIT 18 0 "sum((2/3)^n,n = 2 .. 100);" "6# -%$sumG6$)*&\"\"#\"\"\"\"\"$!\"\"%\"nG/F,;F(\"$+\"" }{TEXT -1 9 ". Ap ply " }{TEXT 261 5 "evalf" }{TEXT -1 54 " to obtain a floating point a pproximation to the sum.\n" }{MPLTEXT 1 0 0 "" }{TEXT -1 70 "\n(b) Wri te a program (not necessarily a procedure) that will find the " } {TEXT 262 3 "set" }{TEXT -1 107 " S of all positive integers less than 1000 that have 11 as a factor. [n has 11 as a factor if and only if \+ " }{XPPEDIT 18 0 "`mod`(n,11) = 0;" "6#/-%$modG6$%\"nG\"#6\"\"!" } {TEXT -1 2 ".]" }}{PARA 0 "" 0 "" {TEXT 258 1 "\n" }}{PARA 0 "" 0 "" {TEXT 289 11 "Problem 2. " }{TEXT -1 20 "\n\nWrite a procedure " } {TEXT 269 7 "ISPRIME" }{TEXT -1 57 " whose input is a positive integer n and whose output is " }{TEXT 274 4 "true" }{TEXT -1 19 " if n is pr ime and " }{TEXT 275 5 "false" }{TEXT -1 58 " otherwise. Test the pro cedure on the following numbers: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 45 "1, 2, 3, 4, 11, 111, 531, 7919, 15689, 26 2681" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 21 "T he answers should be" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {XPPEDIT 18 0 "false,true,true,false,true,false,false,true,false,tru e;" "6,%&falseG%%trueGF$F#F$F#F#F$F#F$" }{TEXT 264 1 "." }}{PARA 0 "" 0 "" {TEXT 286 6 "\nHint:" }{TEXT -1 36 " Here's a start for the progr am:\n\n> " }{MPLTEXT 1 0 111 " ISPRIME:=proc(n)\n local d;\n if n \+ < 2 then return false; end if;\n if n = 2 then return true; end if; \n \n" }{TEXT -1 13 "Note that if " }{XPPEDIT 18 0 "n;" "6#%\"nG" } {TEXT -1 33 " < 2 then the third line causes " }{TEXT 270 10 "ISPRIME (n)" }{TEXT -1 21 " to return false. If " }{XPPEDIT 18 0 "n;" "6#%\"nG " }{TEXT -1 33 " = 2 then the fourth line causes " }{TEXT 271 7 "ISPRI ME" }{TEXT -1 246 " to return true. If neither is true then n is at le ast 3. So now you only need to handle in the rest of the program the \+ case that n is at least 3. This can be done by using a loop to check w hether or not n is divisible by an integer d from 2 to " }{XPPEDIT 18 0 "n-1;" "6#,&%\"nG\"\"\"F%!\"\"" }{TEXT -1 175 ". If you find such a \+ value of d you want to return false. If the loop is completed without \+ finding any such d then you should return true. You may be able to imp rove on this.\n" }}{PARA 0 "" 0 "" {TEXT 263 6 "Remark" }{TEXT -1 48 " . Maple actually has a built-in procedure named " }{TEXT 267 7 "isprim e" }{TEXT -1 47 " which performs the same task as the procedure " } {TEXT 272 7 "ISPRIME" }{TEXT -1 16 " in Problem 2. " }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 18 "Maple's procedure " } {TEXT 279 7 "isprime" }{TEXT -1 13 " is really a " }{TEXT 281 31 "prob abilistic primality tester." }{TEXT -1 5 " See " }{TEXT 280 8 "?isprim e" }{TEXT -1 28 ". To see how the procedure " }{TEXT 278 7 "isprime" }{TEXT -1 36 " is constructed execute the command " }{TEXT 277 19 "sho wstat(isprime); " }{TEXT -1 145 "However, it is not easy to see what t he program is doing. So I don't recommend spending a lot of time on tr ying to figure it out unless you have " }{TEXT 283 4 "lots" }{TEXT -1 48 " of experience in programming and number theory." }}{PARA 0 "" 0 " " {TEXT -1 1 "\n" }{TEXT 259 10 "Problem 3." }{TEXT -1 27 " \n\n(a) W rite a procedure, " }{TEXT 256 8 "primesum" }{TEXT -1 36 ", whose inpu t is a positive integer " }{XPPEDIT 18 0 "n;" "6#%\"nG" }{TEXT -1 43 " and whose output is the sum of all primes " }{XPPEDIT 18 0 "p;" "6#% \"pG" }{TEXT -1 11 " such that " }{XPPEDIT 18 0 "p <= n;" "6#1%\"pG%\" nG" }{TEXT -1 37 ". You may use either your procedure " }{TEXT 273 7 "ISPRIME" }{TEXT -1 42 " from problem 2 or the built-in procedure " } {TEXT 257 9 "isprime. " }{TEXT -1 23 "Test the procedure for " } {XPPEDIT 18 0 "n;" "6#%\"nG" }{TEXT -1 22 " = 2, 4, 10, and 1000." }} {PARA 0 "" 0 "" {TEXT -1 25 "\n (b) Write a procedure, " }{TEXT 265 8 "primeset" }{TEXT -1 37 ", whose input is a positive integer " } {XPPEDIT 18 0 "n;" "6#%\"nG" }{TEXT -1 25 " and whose output is the " }{TEXT 291 3 "set" }{TEXT -1 15 " of all primes " }{XPPEDIT 18 0 "p;" "6#%\"pG" }{TEXT -1 11 " such that " }{XPPEDIT 18 0 "p <= n;" "6#1%\"p G%\"nG" }{TEXT -1 87 ". You may use either your procedure ISPRIME fro m problem 2 or the built-in procedure " }{TEXT 266 9 "isprime. " } {TEXT -1 23 "Test the procedure for " }{XPPEDIT 18 0 "n;" "6#%\"nG" } {TEXT -1 22 " = 2, 4, 10, and 1000." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 292 9 "Problem 4" }}{PARA 0 "" 0 "" {TEXT -1 93 "You should remember from your algebra classes that q uadratic equations have the general form " }{XPPEDIT 18 0 "a*x^2+b*x+c = 0;" "6#/,(*&%\"aG\"\"\"*$)%\"xG\"\"#F'F'F'*&%\"bGF'F*F'F'%\"cGF'\" \"!" }{TEXT -1 55 ", and the solutions are given by the quadratic form ula:" }}{PARA 0 "" 0 "" {TEXT -1 20 " " }{XPPEDIT 18 0 "x = (-b+sqrt(b^2-4*a*c))/(2*a);" "6#/%\"xG*&,&%\"bG!\"\"-%%sqrtG 6#,&*$)F'\"\"#\"\"\"F0*(\"\"%F0%\"aGF0%\"cGF0F(F0F0*&F/F0%\"aGF0F(" } {TEXT -1 5 " and " }{XPPEDIT 18 0 "x = (-b-sqrt(b^2-4*a*c))/(2*a);" "6 #/%\"xG*&,&%\"bG!\"\"-%%sqrtG6#,&*$)F'\"\"#\"\"\"F0*(\"\"%F0%\"aGF0%\" cGF0F(F(F0*&F/F0F3F0F(" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 99 "Write a prcedure cal led QSOLVER that receives the values of a,b,and c and outputs the two \+ solutions" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 284 13 "Extra Credit." }{TEXT -1 26 " \nThree positive integers " } {XPPEDIT 18 0 "x,y;" "6$%\"xG%\"yG" }{TEXT -1 5 " and " }{XPPEDIT 18 0 "z;" "6#%\"zG" }{TEXT -1 28 " form a Pathagorean triple (" } {XPPEDIT 18 0 "x,y,z;" "6%%\"xG%\"yG%\"zG" }{TEXT -1 5 ") if " } {XPPEDIT 18 0 "x^2+y^2 = z^2;" "6#/,&*$%\"xG\"\"#\"\"\"*$%\"yGF'F(*$% \"zGF'" }{TEXT -1 66 ". For example, (3,4,5) is a Pathagorean triple. \+ Write a procedure " }{TEXT 285 20 "Pathagoreantripleset" }{TEXT -1 36 ", whose input is a positive integer " }{XPPEDIT 18 0 "n;" "6#%\"nG" } {TEXT -1 57 " and whose output is the set of all Pathagorean triples ( " }{XPPEDIT 18 0 "x,y,z;" "6%%\"xG%\"yG%\"zG" }{TEXT -1 7 ") with " } {XPPEDIT 18 0 "z <= n;" "6#1%\"zG%\"nG" }{TEXT -1 25 ". Test the proce dure for " }{XPPEDIT 18 0 "n = 10,20,30;" "6%/%\"nG\"#5\"#?\"#I" } {TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 1 "\n" }}{PARA 257 "" 0 "" {TEXT -1 7 "- End -" }{MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 1 "\004" }{MPLTEXT 1 0 0 "" }}}}{MARK "1 24 0" 99 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 1 1 2 33 1 1 }