{VERSION 6 0 "IBM INTEL NT" "6.0" } {USTYLETAB {CSTYLE "2D Output" -1 20 "Times" 1 12 0 0 255 1 0 0 0 2 2 1 0 0 0 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 }{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 }{CSTYLE "_cstyle6" -1 207 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "_cstyle7" -1 208 "Times" 1 12 0 0 255 1 0 0 0 2 2 2 0 0 0 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 } {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 }{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 }{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 }{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 }{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 }} {SECT 0 {EXCHG {PARA 200 "" 0 "" {TEXT 202 31 "Math 365D Lab Three - F all 2007" }{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#% %trueG" }{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#%&falseG" }{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#%%trueG" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 62 "not ( (2+2=4) or (2=2) ); # com pare to the previous expression" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%&falseG" }{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#%&falseG" }{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#%%trueG" } {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 value to a vari able" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"xG%% trueG" }{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-named data structure. Its name should call to mind a physical stack of objects piled one on top of another. Just as with its physical counterpart, 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 to p of the stack (or the whole thing will collapse). In order to remove \+ an object near the bottom of the stack, we must first remove all the o bjects above it. However, we can check the value of an object anywhere in the stack. In the next lab, we will learn about other data structu res that are useful in situations where stacks are awkward." }{TEXT 212 0 "" }{TEXT 212 1 "\n" }}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 56 "s:=stack[new](): # creates a new, empty stack called 's'" } {MPLTEXT 1 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 91 "s tack[push](Euler, s):stack[push](Gauss, s):stack[push](Riemann, s):sta ck[push](Cauchy, s):" }{MPLTEXT 1 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 77 "eval(s); # the 0th element in the table is the n umber of objects in the stack" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 " " {XPPMATH 20 "6#-%&TABLEG6#7'/\"\"!\"\"%/\"\"\"%&EulerG/\"\"#%&GaussG /\"\"$%(RiemannG/F)%'CauchyG" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> \+ " 0 "" {MPLTEXT 1 207 61 "stack[depth](s); # returns the number of obj ects 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#%&G aussG" }{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#%'CauchyG" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 8 "eval(s);" } {MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#-%&TABLEG6#7&/ \"\"!\"\"$/\"\"\"%&EulerG/\"\"#%&GaussG/F)%(RiemannG" }{TEXT 208 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 207 51 "while not stack[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 starting from the \+ top" }{MPLTEXT 1 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%(Riemann G" }{TEXT 208 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%&GaussG" } {TEXT 208 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%&EulerG" }{TEXT 208 0 "" }}}{PARA 204 "" 0 "" {TEXT 209 0 "" }{TEXT 209 10 "\nEXERCISE S" }{TEXT 212 0 "" }{TEXT 212 75 "\n1. Write a procedure that takes tw o 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 expressio n " }{TEXT 211 11 "type(n,odd)" }{TEXT 210 9 " returns " }{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 " otherwise." }{TEXT 212 0 "" } {TEXT 212 108 "\n2. Modify the previous procedure to take three intege rs as its arguments and perform a similar computation." }{TEXT 212 0 " " }{TEXT 212 87 "\n3. Write a procedure that takes 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 returns " }{TEXT 213 4 "true " }{TEXT 214 4 " if " }{TEXT 212 43 "the edges do not share a common v ertex and " }{TEXT 213 5 "false" }{TEXT 214 46 " otherwise. Hint: reca ll 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 " wil l return the second vertex of the fifth edge of G." }{TEXT 212 0 "" } {TEXT 212 135 "\n5. Write a procedure that takes as its arguments a gr aph and a vertex and places the neighbors of that vertex one by one on to a stack." }{TEXT 212 0 "" }{TEXT 212 52 "\n6. Write a procedure tha t takes a positive integer " }{TEXT 213 1 "n" }{TEXT 214 1 " " }{TEXT 212 50 "as its argument and places onto a stack the first " }{TEXT 213 1 "n" }{TEXT 214 67 " prime numbers, with the smallest prime at th e bottom of the stack." }{TEXT 212 0 "" }{TEXT 212 125 "\n7. Modify th e previous procedure so that the primes are placed 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" 31 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }