{VERSION 6 1 "Windows XP" "6.1" } {USTYLETAB {PSTYLE "Warning" -1 7 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }1 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "Dash Item" -1 16 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 3 }{PSTYLE "Heading 4" -1 20 1 {CSTYLE "" -1 -1 "MS Serif" 1 12 0 0 0 0 1 0 0 2 2 2 0 0 0 1 }1 1 0 -1 0 0 1 0 1 0 2 2 -1 1 }{PSTYLE "Heading 3" -1 5 1 {CSTYLE "" -1 -1 " MS Serif" 1 14 0 0 0 0 1 1 0 2 2 2 0 0 0 1 }1 1 0 -1 0 0 1 0 1 0 2 2 -1 1 }{PSTYLE "Error" -1 8 1 {CSTYLE "" -1 -1 "Courier" 1 12 255 0 255 1 0 0 0 2 2 1 0 0 0 1 }1 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "A uthor" -1 19 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }3 1 0 -1 8 8 1 0 1 0 2 2 -1 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "MS Serif" 1 16 0 0 0 0 0 1 0 2 2 2 0 0 0 1 }1 1 0 -1 8 2 1 0 1 0 2 2 -1 1 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }1 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "MS Serif" 1 18 0 0 0 0 0 1 0 2 2 2 0 0 0 1 }1 1 0 -1 8 4 1 0 1 0 2 2 -1 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{PSTYLE "Maple Plot" -1 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "Line Printed Output" -1 6 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }1 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 0 0 1 1 2 2 2 0 0 0 1 }3 1 0 -1 12 12 1 0 1 0 2 2 -1 1 }{PSTYLE "Map le Output" -1 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{PSTYLE "List Item" -1 14 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 5 }{PSTYLE "Bullet Item" -1 15 1 {CSTYLE "" -1 -1 "Ti mes" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }1 1 0 -1 3 3 1 0 1 0 2 2 -1 2 } {CSTYLE "Maple Input" -1 0 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "2D Input" -1 19 "Times" 1 12 255 0 0 1 0 0 0 2 1 2 0 0 0 1 }{CSTYLE "Hyperlink" -1 17 "MS Serif" 1 12 0 128 128 1 0 0 1 2 2 2 0 0 0 1 }{CSTYLE "Text" -1 200 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 1 12 0 0 0 1 0 0 0 2 2 2 0 0 0 1 } {CSTYLE "Dictionary Hyperlink" -1 45 "MS Serif" 1 12 147 0 15 1 0 0 1 2 2 2 0 0 0 1 }{CSTYLE "Maple Input Placeholder" -1 201 "Courier" 1 12 200 0 200 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "2D Output" -1 20 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }{CSTYLE "Page Number" -1 33 "Times " 1 10 0 0 0 0 0 0 2 2 2 2 0 0 0 1 }{PSTYLE "_pstyle1" -1 200 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 0 0 1 }3 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{CSTYLE "_cstyle1" -1 202 "Times" 1 16 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle2" -1 203 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{PSTYLE "_pstyle2" -1 201 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 } {CSTYLE "_cstyle3" -1 204 "Times" 1 14 0 0 0 1 2 1 1 2 2 2 0 0 0 1 } {CSTYLE "_cstyle4" -1 205 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 } {CSTYLE "_cstyle5" -1 206 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 } {PSTYLE "_pstyle3" -1 202 1 {CSTYLE "" -1 -1 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 1 0 0 1 }1 1 0 0 0 0 2 0 2 0 2 2 -1 1 }{CSTYLE "_cstyle6" -1 207 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{PSTYLE "_pstyle4 " -1 203 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 1 }3 3 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{CSTYLE "_cstyle7" -1 208 "Times" 1 12 0 0 255 1 0 0 0 2 2 2 0 0 0 1 }{PSTYLE "_pstyle5" -1 204 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }0 0 0 -1 -1 -1 1 0 1 0 2 2 -1 1 }{CSTYLE "_cstyle8" -1 209 "Times" 1 14 0 0 0 1 2 1 1 2 2 2 0 0 0 1 }{CSTYLE "_cstyle9" -1 210 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle10" -1 211 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle11" -1 212 "Times" 0 1 0 0 0 0 0 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle12" -1 213 "Times" 0 1 0 0 0 0 1 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle13" -1 214 "Times" 0 1 0 0 0 0 2 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle14" -1 215 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle15" -1 216 "Times" 0 1 0 0 0 0 2 1 0 2 2 2 0 0 0 1 }} {SECT 0 {EXCHG {PARA 200 "" 0 "" {TEXT 202 31 "Math 365D Lab Three - F all 2005" }{TEXT 203 0 "" }{TEXT 203 1 "\n" }}{PARA 201 "" 0 "" {TEXT 204 19 "BOOLEAN EXPRESSIONS" }{TEXT 203 0 "" }{TEXT 203 51 "\nA Boolea n expression is one whose value is either " }{TEXT 205 5 "true " } {TEXT 203 3 "or " }{TEXT 205 5 "false" }{TEXT 203 19 " (but not both) \+ or " }{TEXT 205 4 "FAIL" }{TEXT 203 96 " if its truth or falsity is un known. One example we have seen so far is the return value of the " } {TEXT 206 8 "isprime " }{TEXT 203 8 "command." }{TEXT 203 0 "" }{TEXT 203 1 "\n" }{TEXT 203 151 "\nIn Math s21, we learned how to construct \+ Boolean expressions using disjunction (\"inclusive or\"), conjunction \+ (\"and\"), and negation (\"not\"). The words " }{TEXT 206 2 "or" } {TEXT 203 2 ", " }{TEXT 206 3 "and" }{TEXT 203 6 ", and " }{TEXT 206 3 "not" }{TEXT 203 95 " are used in Maple in exactly the same way. In \+ addition, Maple has an \"exclusive or\" operator, " }{TEXT 206 3 "xor" }{TEXT 203 27 ", which returns a value of " }{TEXT 205 4 "true" } {TEXT 203 58 " if and only if exactly one of its two arguments is fals e." }{TEXT 203 0 "" }{TEXT 203 1 "\n" }{TEXT 203 79 "\nThe following s imple examples illustrate the use of these logical expressions." } {TEXT 203 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 17 "(2=3) \+ or (2+2=4);" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I %trueGI*protectedGF$" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 18 "(2=3) and (2+2=4);" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&falseGI*protectedGF$" }{TEXT 208 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 21 "not (2+2=4) or (2=2);" } {MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I%trueGI*protec tedGF$" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 62 "not ( (2+2=4) or (2=2) ); # compare to the previous expression" } {MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&falseGI*prote ctedGF$" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 16 "(1=1) xor (1<2);" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&falseGI*protectedGF$" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 31 "not ( (1=2) or (2=3) or (3=4)); " }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I%trueGI*pro tectedGF$" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 80 "x:= (1=2) or (1=1 and isprime(3)); # we can assign a Boolean v alue to a variable" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>I\"xG6\"I%trueGI*protectedGF'" }{TEXT 208 0 "" }}}{PARA 204 "" 0 "" {TEXT 209 0 "" }{TEXT 209 7 "\nSTACKS" }{TEXT 210 0 "" }{TEXT 210 3 "\nA " }{TEXT 211 5 "stack" }{TEXT 210 253 " is a very aptly-nam ed data structure. Its name should call to mind a physical stack of ob jects piled one on top of another. Just as with its physical counterpa rt, a stack in Maple operates on a last-in, first-out (LIFO) principle - we can only insert (" }{TEXT 211 4 "push" }{TEXT 211 2 ") " }{TEXT 210 12 "and remove (" }{TEXT 211 3 "pop" }{TEXT 211 2 ") " }{TEXT 210 363 "objects from the very top of the stack (or the whole thing will c ollapse). In order to remove an object near the bottom of the stack, w e must first remove all the objects above it. However, we can check th e value of an object anywhere in the stack. In the next lab, we will l earn about other data structures that are useful in situations where s tacks are awkward." }{TEXT 212 0 "" }{TEXT 212 1 "\n" }}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 56 "s:=stack[new](): # creates a new, emp ty stack called 's'" }{MPLTEXT 1 207 0 "" }}}{EXCHG {PARA 202 "> " 0 " " {MPLTEXT 1 207 91 "stack[push](Euler, s):stack[push](Gauss, s):stack [push](Riemann, s):stack[push](Cauchy, s):" }{MPLTEXT 1 207 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 77 "eval(s); # the 0th eleme nt in the table is the number of objects in the stack" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#-I&TABLEGI*protectedGF%6#7 '/\"\"!\"\"%/\"\"\"I&EulerG6\"/\"\"#I&GaussGF./\"\"$I(RiemannGF./F*I'C auchyGF." }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 61 "stack[depth](s); # returns the number of objects in the stack" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"%" } {TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 71 "s[2]; \+ # returns the second object from the bottom but doesn't remove it" } {MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&GaussG6\"" } {TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 54 "stack[ pop](s); # returns the top object AND removes it" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I'CauchyG6\"" }{TEXT 208 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 8 "eval(s);" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#-I&TABLEGI*protectedGF%6#7 &/\"\"!\"\"$/\"\"\"I&EulerG6\"/\"\"#I&GaussGF./F*I(RiemannGF." }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 51 "while not st ack[empty](s) do stack[pop](s); end do;" }{MPLTEXT 1 207 0 "" } {MPLTEXT 1 207 68 "\n# a loop to pop all the objects off the stack sta rting from the top" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I(RiemannG6\"" }{TEXT 208 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 " 6#I&GaussG6\"" }{TEXT 208 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#I&Eu lerG6\"" }{TEXT 208 0 "" }}}{PARA 204 "" 0 "" {TEXT 209 0 "" }{TEXT 209 10 "\nEXERCISES" }{TEXT 212 0 "" }{TEXT 212 75 "\n1. Write a proce dure that takes two integers as its arguments and returns " }{TEXT 213 4 "true" }{TEXT 214 38 " if both are even or both are odd and " } {TEXT 213 5 "false" }{TEXT 214 12 " otherwise. " }{TEXT 210 29 "Hint: \+ the Boolean expression " }{TEXT 211 11 "type(n,odd)" }{TEXT 210 9 " re turns " }{TEXT 215 4 "true" }{TEXT 210 4 " if " }{TEXT 215 1 "n" } {TEXT 210 12 " is odd and " }{TEXT 215 5 "false" }{TEXT 210 11 " other wise." }{TEXT 212 0 "" }{TEXT 212 108 "\n2. Modify the previous proced ure to take three integers as its arguments and perform a similar comp utation." }{TEXT 212 0 "" }{TEXT 212 87 "\n3. Write a procedure that t akes as its arguments a graph and two vertices and returns " }{TEXT 213 4 "true" }{TEXT 214 4 " if " }{TEXT 212 70 "the vertex degrees are of the same parity (both even or both odd) and " }{TEXT 213 5 "false" }{TEXT 214 11 " otherwise." }{TEXT 212 0 "" }{TEXT 212 84 "\n4. Write a procedure that takes as its arguments a graph and two edges and ret urns " }{TEXT 213 4 "true" }{TEXT 214 4 " if " }{TEXT 212 43 "the edge s do not share a common vertex and " }{TEXT 213 5 "false" }{TEXT 214 46 " otherwise. Hint: recall the networks command " }{TEXT 216 5 "ends " }{TEXT 214 27 "from Lab Two. For example, " }{TEXT 216 13 "ends(e5, G)[2]" }{TEXT 214 54 " will return the second vertex of the fifth edge of G." }{TEXT 212 0 "" }{TEXT 212 135 "\n5. Write a procedure that ta kes as its arguments a graph and a vertex and places the neighbors of \+ that vertex one by one onto a stack." }{TEXT 212 0 "" }{TEXT 212 52 " \n6. Write a procedure that takes a positive integer " }{TEXT 213 1 "n " }{TEXT 214 1 " " }{TEXT 212 50 "as its argument and places onto a st ack the first " }{TEXT 213 1 "n" }{TEXT 214 67 " prime numbers, with t he smallest prime at the bottom of the stack." }{TEXT 212 0 "" }{TEXT 212 125 "\n7. Modify the previous procedure so that the primes are pla ced onto a stack in the opposite order. Hint: use a second stack." } {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT 212 0 "" }}{PARA 204 "" 0 "" {TEXT -1 0 "" }}}{MARK "0 0 0" 0 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }