{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 2 1 2 2 2 2 0 0 0 1 }{CSTYLE "_cstyle5" -1 206 "Courier" 1 12 255 0 0 1 0 1 0 2 1 2 0 0 0 1 }{CSTYLE "_cstyle6" -1 207 "Times" 1 12 0 0 255 1 0 0 0 2 2 2 0 0 0 1 }{CSTYLE "_cstyle7" -1 208 "Courier" 1 12 255 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 } {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 "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 "_pstyle6" -1 205 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 30 "Math 365D Lab Four - Fa ll 2007" }{TEXT 203 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 204 4 "SETS " }{TEXT 203 0 "" }{TEXT 203 34 "\nAs you remember from Math s21, a " }{TEXT 205 3 "set" }{TEXT 203 108 " is an unordered collection of dist inct objects. Thus, the sets \{a,b\}, \{b,a\}, and \{b,a,a,a\} are all equal. " }{TEXT 203 0 "" }{TEXT 203 139 "\nMaple has many commands f or manipulating sets, some of which are shown below. Note that we use \+ braces \{\} to enclose the elements of a set." }{TEXT 203 0 "" }} {PARA 201 "" 0 "" {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 24 "A:=\{2,3,5,11\}; B:=\{3,7\};" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"AG<&\"\"#\"\"$\"\"&\"#6" }{TEXT 207 0 "" }} {PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"BG<$\"\"$\"\"(" }{TEXT 207 0 "" } }}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 79 "A:=A union \{7\}; # we need the \{\} around the 7 to make the second argument a set" } {MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"AG<'\"\"#\" \"$\"\"&\"\"(\"#6" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 18 "C:=A intersect B; " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"CG<$\"\"$\"\"(" }{TEXT 207 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 13 "E:=A minus B;" } {MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"EG<%\"\"#\" \"&\"#6" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 69 "member(11,E); # tests if the first argument is a member of the sec ond" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%%trueG" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 82 "A[3]; # though Maple claims sets are unordered, it lets us ask for the nth \+ element" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"& " }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 49 "S:= \{\}; # this is how we initialize a set as empty" }{MPLTEXT 1 206 0 " " }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>%\"SG<\"" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 203 109 "When we want to use a loop to \+ do something for each element in a set, the following alternate versio n of the " }{TEXT 205 9 "for...do " }{TEXT 203 123 "syntax can be very convenient as it eliminates the need to count the number of elements \+ in the set (as we had to do in the " }{TEXT 205 13 "twoneighbors " } {TEXT 203 24 "procedure from Lab Two)." }{TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 13 "for x in A do" }{MPLTEXT 1 206 0 "" } {MPLTEXT 1 206 18 "\n print(x);" }{MPLTEXT 1 206 0 "" } {MPLTEXT 1 206 8 "\nend do;" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"#" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"$" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"&" } {TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"(" }{TEXT 207 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"#6" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 204 5 "LISTS" }{TEXT 203 0 "" }{TEXT 203 17 " \nUnlike a set, a " }{TEXT 205 4 "list" }{TEXT 203 274 " is an ordered sequence of objects which do not need to be distinct. Thus, the lists [a,b], [b,a], and [b,a,a,a] are all different from one another. Lists are enclosed in brackets []. Lists are not sets, so the notions of un ion, intersection and the like are not applicable." }{TEXT 203 0 "" } {TEXT 203 1 "\n" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 15 "L:=[5,3,a,5, C]:" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 47 "L[2]; # displays the 2nd element from the start" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"$" }{TEXT 207 0 "" }}} {EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 46 "L[-2]; # displays the 2n d element from the end" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"&" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 64 "L[5]; # an element of a list may be a set, a list, \+ or any object" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6 #<$\"\"$\"\"(" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 59 "L[5][1]; # displays the 1st element of the 5th element of L " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"$" } {TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 83 "conver t(L, 'set'); # it's sometimes useful to convert one data structure to \+ another" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#<&\" \"$\"\"&<$F$\"\"(%\"aG" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 60 "M:=[seq(0, i=1..20)]; # this is one way to initiali ze a list" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#>% \"MG76\"\"!F&F&F&F&F&F&F&F&F&F&F&F&F&F&F&F&F&F&F&" }{TEXT 207 0 "" }}} {EXCHG {PARA 201 "" 0 "" {TEXT 204 6 "ARRAYS" }{TEXT 203 0 "" }{TEXT 203 98 "\nSo far, the data structures we have seen (stacks, sets, list s) have all been one-dimensional. An " }{TEXT 205 5 "array" }{TEXT 203 24 " is a special form of a " }{TEXT 205 6 "table " }{TEXT 203 255 "(a structure that contains rows and columns - see Help for detail s on tables if you're interested). Like a list, an array is ordered an d allows for repeated elements. (Of course, an array may contain just \+ one row, in which case it looks much like a list.)" }{TEXT 203 0 "" } {TEXT 203 1 "\n" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 64 "a:=array([[2 ,3,5,7],[b,c,d,e]]): # creates and fills a 2x4 array" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 29 "eval(a); # displ ays our array" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6 #-%'matrixG6#7$7&\"\"#\"\"$\"\"&\"\"(7&%\"bG%\"cG%\"dG%\"eG" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 60 "a[2,3]:=geor ge: eval(a); # assign a new value to one element" }{MPLTEXT 1 206 0 " " }}{PARA 203 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7$7&\"\"#\"\"$\"\"&\" \"(7&%\"bG%\"cG%'georgeG%\"eG" }{TEXT 207 0 "" }}}{EXCHG {PARA 204 "" 1 "" {TEXT 208 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 10 "Using th e " }{TEXT 205 3 "op " }{TEXT 203 233 "command, we can determine vario us attributes of a data structure. Below, we show how to find the numb er of rows and columns as this will be useful to us in the future. For information on returning other attributes, see the Help menu." } {TEXT 203 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 81 "op(2,eval(a)); # the 2 indicates we want \+ the bounds (0 would give the type, etc.)" }{MPLTEXT 1 206 0 "" }} {PARA 203 "" 1 "" {XPPMATH 20 "6$;\"\"\"\"\"#;F$\"\"%" }{TEXT 207 0 " " }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 58 "op(2,eval(a))[1]; # this gives just the bounds on the rows" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#;\"\"\"\"\"#" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 67 "op(2,op(2,eval(a))[1]); # and t his finally gives the number of rows" }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#\"\"#" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 50 "b:=array(1..4, 1..2): # creates an empty \+ 4x2 array" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 9 "eval(b); " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7&7$&%\"?G6$\"\"\"F+&F)6$F+\"\"#7$&F)6$F.F+ &F)6$F.F.7$&F)6$\"\"$F+&F)6$F7F.7$&F)6$\"\"%F+&F)6$F=F." }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 204 26 "NETWORKS PACKAGE, PART TW O" }{TEXT 203 0 "" }{TEXT 203 100 "\nNow that we know the difference b etween sets and lists, we can add some new features to our graphs." } {TEXT 203 0 "" }}{PARA 202 "> " 0 "" {MPLTEXT 1 206 15 "with(networks) :" }{MPLTEXT 1 206 0 "" }{MPLTEXT 1 206 81 "\nG:=graph( \{a,b,c\}, \{ \+ \{a,b\}, [b,c] \} ): # the second edge is DIRECTED from b to c" } {MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 50 "h ead(e2, G); # returns the head of a directed edge" }{MPLTEXT 1 206 0 " " }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%\"cG" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 51 "tail(e2, G); # returns the tail of a directed edge " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6#%\"bG" }{TEXT 207 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 74 "H:=graph( \{a,b,c\}, \{ \{a,b\}, \{b,c\} \} , weigh ts=[5,7] ): # weights the edges" }{MPLTEXT 1 206 0 "" }}}{EXCHG {PARA 202 "> " 0 "" {MPLTEXT 1 206 48 "eweight(e1, H); # returns the weight \+ of an edge " }{MPLTEXT 1 206 0 "" }}{PARA 203 "" 1 "" {XPPMATH 20 "6# \"\"&" }{TEXT 207 0 "" }}}{EXCHG {PARA 201 "" 0 "" {TEXT 203 47 "It's \+ also possible to weight the vertices; see " }{TEXT 205 8 "vweight " } {TEXT 203 39 "in the Help menu if you are interested." }{TEXT 203 0 " " }}}{PARA 205 "" 0 "" {TEXT 209 0 "" }{TEXT 209 10 "\nEXERCISES" } {TEXT 210 0 "" }{TEXT 210 131 "\n1. Write a procedure that takes three sets as its arguments and returns a set that contains the elements co mmon to all three sets." }{TEXT 210 0 "" }{TEXT 210 157 "\n2. Write a \+ procedure which takes two sets as its arguments and then indicates whe ther the first set is a subset of the second. Do this using a loop and the " }{TEXT 211 7 "member " }{TEXT 210 37 "command rather than by us ing Maple's " }{TEXT 211 7 "subset " }{TEXT 210 8 "command." }{TEXT 212 0 "" }{TEXT 212 168 "\n3. Write a procedure that takes a graph and two vertices as its arguments and returns a set containing only the v ertices that are neighbors of both the given vertices." }{TEXT 212 0 " " }{TEXT 212 52 "\n4. Write a procedure that takes a positive integer \+ " }{TEXT 213 1 "n" }{TEXT 214 1 " " }{TEXT 212 48 "as its argument and returns a list of the first " }{TEXT 213 1 "n" }{TEXT 214 27 " primes in ascending order." }{TEXT 212 0 "" }{TEXT 212 81 "\n5. Write a proc edure that takes a graph as its argument and returns a list, the " } {TEXT 213 1 "i" }{TEXT 214 51 "th element of which is the set of neigh bors of the " }{TEXT 213 1 "i" }{TEXT 214 23 "th vertex of the graph. " }{TEXT 212 0 "" }{TEXT 212 269 "\n6. Write a procedure that takes a \+ graph as its argument and returns an array, the first row of which con tains the vertices of the graph. Under each of these vertices should b e displayed all of its neighbors, but not as sets. For example, if the first vertex is called " }{TEXT 213 1 "b" }{TEXT 214 23 " and its nei ghbors are " }{TEXT 213 1 "c" }{TEXT 214 5 " and " }{TEXT 213 1 "m" } {TEXT 214 49 ", then the first column of the array should have " } {TEXT 213 1 "b" }{TEXT 214 19 " in the first row, " }{TEXT 213 1 "c" } {TEXT 214 20 " in the second, and " }{TEXT 213 1 "m" }{TEXT 214 14 " i n the third." }{TEXT 212 1 " " }{TEXT 212 0 "" }{TEXT 212 143 "\n7. Wr ite a procedure that takes a graph as its argument and returns a set c ontaining all the vertices that are the heads of at least one edge." } {TEXT 212 0 "" }{TEXT 212 109 "\n8. Write a procedure that takes a gra ph with weighted edges as its argument and displays the minimum weight ." }{TEXT 212 0 "" }{TEXT 212 104 "\n9. Modify your previous procedure so that it also displays the set of edges having that minimum weight. " }{TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 328 "10. Write a proce dure that takes two one-dimensional arrays as its arguments and, treat ing them as vectors, returns their dot product. Do this with a loop ra ther than any built-in Maple function. See the notes on arrays above f or information on determining the length of the vectors. We will use t his procedure again in Lab Six." }{TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT 212 0 "" }}{PARA 205 "" 0 "" {TEXT -1 0 "" }}}{MARK "0 0 0" 30 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }