{VERSION 4 0 "APPLE_PPC_MAC" "4.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 "Hyperlink" -1 17 "" 0 1 0 128 128 1 2 0 1 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 "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 35 "" 0 1 104 64 92 1 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 0 2 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 1 0 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 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 1 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 0 }{CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE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0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 331 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 332 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 333 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 334 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 335 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 336 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 337 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 338 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 339 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 } {CSTYLE "" -1 340 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 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 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Bullet \+ Item" -1 15 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 3 3 1 0 1 0 2 2 15 2 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Author" -1 19 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 8 8 1 0 1 0 2 2 0 1 }{PSTYLE "Normal " -1 256 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 } 1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 18 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 "Normal" -1 258 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 259 1 {CSTYLE "" -1 -1 "Times" 1 24 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 "Normal" -1 260 1 {CSTYLE "" -1 -1 "T imes" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "" 0 261 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 262 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT 256 10 "Lecture 10" }}{PARA 19 " " 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 257 "" 0 "" {TEXT 263 5 "evalb" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 13 " The function " }{TEXT 35 6 "evalb " }{TEXT -1 27 "evaluates an express ion to " }{TEXT 264 4 "true" }{TEXT -1 2 ", " }{TEXT 265 5 "false" } {TEXT -1 107 ", or if it cannot tell, it just returns the command as i s. This is best understood by looking at examples:" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 15 "" 0 "" {TEXT -1 6 "Since " }{TEXT 260 5 "e valb" }{TEXT -1 187 " does not simplify expressions, it may return fal se to a relation which is actually true. In such a case, appropriate s implification must be applied to the relation before evalb is used. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "x = x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "evalb(x = \+ x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "evalb(1 < 2);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "evalb(sqrt(2) < sin(3));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "evalb(evalf(sqrt(2)) < ev alf(sin(3)));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 306 5 "evalb" }{TEXT -1 42 " can also be used to test for equality of " }{TEXT 308 4 "sets " }{TEXT -1 5 " and " }{TEXT 309 5 "lists" }{TEXT -1 33 ". But for mat rices we need to us " }{TEXT 310 13 "linalg[equal]" }{TEXT -1 25 ". He re are some examples." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "ev alb([1,2,3]=[1,2,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "ev alb([2,2,3] = [2,3,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 " evalb(\{2,2,3\}=\{2,3,3\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "A:=matrix([[1,2],[3,4]]);\nB:=matrix(2,2,[1,2,3,4]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "evalb(A=B);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 19 "linalg[equal](A,B);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 25 "Let's create a procedure " }{TEXT 261 4 "test" }{TEXT -1 42 " that has as input two arguments x and y. " }{TEXT 262 4 "test " }{TEXT -1 67 "(x,y) will return true if x < y and false if x is not \+ less than y. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "test:=(x,y )->evalb(x < y);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "test(1, 1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "test(1,2);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 98 "Let's now create a procedure test2 whose input will be two list L and M. We want test2(L,M) to be " } {TEXT 266 4 "true" }{TEXT -1 23 " if L[2] < = M[2] and " }{TEXT 267 5 "false" }{TEXT -1 11 " otherwise." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "test2:=(L,M)-> evalb(L[2] <= M[2]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "test2([1,2,3],[2,3,5]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "test2([1,2],[1,2]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "test2([1,4],[0,3]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 5 "sort " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 257 5 " sort " }{TEXT -1 51 "can be applied to a list or an algebraic expressi on" }{TEXT 258 2 ". " }{TEXT -1 81 " You can specify how you want thin gs to be sorted in some cases, as we shall see." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Lists are " }{TEXT 259 6 "sorted" }{TEXT -1 69 " into ascending or der by default and the original list is left as is." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L1:=[5,3,4,1,2];\nL2:=sort(L1);\nL1:=L1; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 146 "Polynomials are sorted into \+ descending order of the term degrees: In the case of polynomials they \+ are sorted in place. The old order is destroyed." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "p1:= 1+3*x+5*x^3+49*x^2;" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 13 "p2:=sort(p1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "p1:=p1;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 3 "Do " } {TEXT 270 5 "?sort" }{TEXT -1 81 " to see the various ways Maple provi des to sort polynomials in several variables." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 159 "One can sort \+ lists in various ways by inserting an optional second parameter which \+ is a boolean function F of two variables: Such a F can be created by \+ using " }{TEXT 268 5 "evalb" }{TEXT -1 136 ". For example, the followi ng gives a boolean function G(x,y) which is true if x >=y: Using this \+ we can sort lists into descending order:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "G:=(x,y)->evalb(x >=y);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "G(1,2);\nG(2,1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 46 "L1:=[1,5,2,4,3];\nL2:=sort(L1);\nL3:=sort(L1,G);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "It is often more convenient to use unnamed functions for the second variable in " }{TEXT 269 4 "sort" } {TEXT -1 10 " as below:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 " L1:=[seq(i^3 mod 10,i=1..10)];\nL2:=sort(L1, (x,y)->evalb(x>=y));" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 156 "We may also use this method to so rt lists of lists on the i-th coordinate of the lists in the big list , as follows: We first create a random list of lists:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "die:=rand(1..8):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L1:=[seq([die(),die(),die()],i=1..8)];" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "We sort the small lists on thei r second coordinates:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L2 :=sort(L1,(x,y)->evalb(x[2]<=y[2]));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 56 "Sort will sort words into alphabetical (lexorder) order:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "restart:\nsort([ beth, carl, aaron, Betty, Aaron,Carla,6,7,10,0 ] );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 88 "Note that nu mbers come first , then capitalized words and finally non-capitalized \+ words" }}{PARA 0 "" 0 "" {TEXT -1 1 "." }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 27 "select, remove, member, has" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 20 "What the procedures " } {TEXT 273 22 "select, remove, member" }{TEXT -1 6 ", and " }{TEXT 274 3 "has" }{TEXT -1 43 " do is evident from the following examples:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 23 "L1:=[seq(i,i=1..100)];\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "L2:=select(isprime,L1);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "L3:=remove(isprime,L1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "die:=rand(1..4):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "L4:=[seq([die(),die(),die()],i=1..15)];" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "L5:=select(x->evalb(1<=x[3] \+ and x[3]<=2),L4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "L6:=re move(x->evalb(x[1]=2),L5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "" 0 "" {TEXT 272 6 "member" }{TEXT -1 52 "(x,S) is tr ue if x is in S where S is a set or list." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "S:=[seq(i^3 mod 11, i=1..12)];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(1,S);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(5,S);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 117 "If there i s a third argument for member, it will store the position of the first x in S, as in the following example." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "member(5,S,'x');\nx;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 271 3 "has" }{TEXT -1 168 " is similar to member but more extens ive. Also, it should not be used when member will do as well, since it takes more time to return a value: Here are some examples: " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "restart:\nL1:=[seq(i^5 mod 1 3, i=5..15)];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "has(L1,1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "has(L1,10);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "p:=x^3+b*x^3*z^5+2+1 +x^(y^(z^w))+ sin(x);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "has(p,w);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "has(p,3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "has(p,z^w);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "has(p,sin);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "has(p,q );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L4:=[1+x^5, sin(3), e xp(y^2)+sin(1)];\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "L7:=s elect(has,L4,2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 20 "This is the s ame as:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "select(u->has(u, 2),L4);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 16 "nops, op, subsop" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 256 "" 0 "" {TEXT 275 12 "The command " } {TEXT 276 2 "op" }{TEXT 277 34 " extracts the various components (" } {TEXT 278 8 "operands" }{TEXT 280 33 ") of an expression, the function " }{TEXT 281 4 "nops" }{TEXT 282 39 " returns the number of component s, and " }{TEXT 290 6 "subsop" }{TEXT 291 70 " is used to substitute t hings for given components of the expression.\n" }}{PARA 256 "" 0 "" {TEXT 283 84 "Let's look at examples. Some, we have already seen when \+ dealing with sets and lists:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "L:=[1,2,3, 4,5,x,y,z];\nS:=\{6,7,8,9, x^2+1,matrix([[1,2],[3,4]])\};" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "nL:=nops(L);\nnS:=nops(S);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "op(L);\nop(S);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op(2,L);\nL[2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op(2,S);\nS[2];" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 33 "seq(op(i,L),i=1..nops(L));\nop(L);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "op(-1,L);\nL[-1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "op(2..4,L);\nL[2..4];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "p:= (x^7+8*x^6)/(x^2-9);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(p);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "nops(p);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "T:=op(p);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "T[1];" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "nops(T[1]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "TZ:=op(T[1]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "op(TZ[1]);\nop(TZ[2]);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 15 "e:=p^(x^2+x+1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(e);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(e);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "Y:=op(e);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "q:=Y[1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "op(q);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "Note that " }{XPPEDIT 18 0 "1/(x^2-9);" "6#*&\"\"\"F$,&*$%\"xG \"\"#F$\"\"*!\"\"F*" }{TEXT -1 14 " is stored as " }{XPPEDIT 18 0 "(x^ 2-9)^(-1);" "6#),&*$%\"xG\"\"#\"\"\"\"\"*!\"\",$F(F*" }{TEXT -1 47 " a nd both have type ^. So the two operands are " }{XPPEDIT 18 0 "x^2-9; " "6#,&*$%\"xG\"\"#\"\"\"\"\"*!\"\"" }{TEXT -1 9 " and -1. " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "TW:=op(2,q);\nop(TW);\nwhatt ype(TW);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "q; " }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 41 "Various parts can be selected as f ollows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "op([2,1],q);" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op([2,1,1],q);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op([2,1,2],q);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 16 "op([2,1,1,2],q);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 279 16 "op(0,expre ssion)" }{TEXT -1 73 " has a special meaning: For example; For many ex pressions it returns the " }{TEXT 311 4 "type" }{TEXT -1 49 ", for \"f unctions\" it is the name of the function:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "A:=matrix([[1,2], [3,4]]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op(0,eval(A)); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op(0,x^2+y+1);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "nops(igcd(x,y));\nop(0,igcd( x,y));\nop(1,igcd(x,y));\nop(2,igcd(x,y));\n" }}}{EXCHG {PARA 0 "" 0 " " {TEXT 284 23 "subsop(i = whatever, p)" }{TEXT -1 72 " will substitut e whatever in the place of the i=th component of p. Like " }{TEXT 312 4 "subs" }{TEXT -1 29 " it does not change p itself." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "p;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "op(p);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "op([1,2],p );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "p1:=subsop( [1,2]=W, \+ p );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "p;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "op([2,1,2],p);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "subsop( [2,1,2]=0, p );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 8 "lhs, rhs" }}{PARA 0 "" 0 "" {TEXT -1 13 "The commands " }{TEXT 285 3 "lhs" }{TEXT -1 5 " and " }{TEXT 286 3 "rhs" }{TEXT -1 84 ": These commands pick out the left hand side and the right hand side of an equation:" }{TEXT 287 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 29 "equation1:=sin(x)+x = cos(x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "a:=lhs(equation1);\nb:=rhs(equation1);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "map(lhs,[1=z,w=t,f=u]);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "map(rhs,[1=z,w=t,f=u]);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 12 "numer, denom" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "The c ommands " }{TEXT 288 5 "numer" }{TEXT -1 5 " and " }{TEXT 289 5 "denom " }{TEXT -1 72 " allow one to give names to the numerator and denomina tor of a fraction:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "numer (3/7);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "denom(3/7);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "f:=(2*x^3+y*z+ exp(tan(x)))/ (sin(x*y*z)+w*r+2);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "X1:= numer(f);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "X2:=denom(f); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 46 "quotes \", `, ' \+ as used for names, strings, etc" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "restart" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "The following i s taken mostly from the Maple online help:" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 15 "" 0 "" {TEXT -1 83 "Three different types o f quotes are used in Maple for three different purposes: as " }{TEXT 292 6 "string" }{TEXT -1 16 " delimiters; as " }{TEXT 293 6 "symbol" } {TEXT -1 31 " delimiters; and as a means of " }{TEXT 294 19 "delaying \+ evaluation" }{TEXT -1 19 " of an expression. " }}{PARA 15 "" 0 "" {TEXT -1 4 "The " }{TEXT 295 12 "double-quote" }{TEXT -1 27 " symbol ( \") is used as the " }{HYPERLNK 17 "string" 2 "string" "" }{TEXT -1 12 " delimiter. " }}{PARA 15 "" 0 "" {TEXT -1 4 "The " }{TEXT 296 10 " back-quote" }{TEXT -1 30 " symbol (`) is used to form a " }{HYPERLNK 17 "symbol" 2 "symbol" "" }{TEXT -1 2 ". " }}{PARA 15 "" 0 "" {TEXT -1 2 "A " }{TEXT 297 21 "pair of single quotes" }{TEXT -1 70 " (' ') i s used to delay evaluation of the enclosed expression --- see " } {HYPERLNK 17 "uneval" 2 "uneval" "" }{TEXT -1 1 " " }}{PARA 15 "" 0 " " {TEXT -1 70 "In earlier versions of Maple, the double-quote symbol w as used as the " }{HYPERLNK 17 "ditto" 2 "ditto" "" }{TEXT -1 64 " ope rator. This facility is now provided by the percent symbol. " }}{PARA 0 "" 0 "" {TEXT -1 2 "A " }{TEXT 298 6 "string" }{TEXT -1 127 " is a s equence of characters that has no value other than itself. It cannot b e assigned to, and will always evaluate to itself." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "s:=\"This is a string\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(s);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 2 "A " }{TEXT 35 4 "name" }{TEXT -1 300 " is usually a symbol , which in its simplest form is a letter followed by zero or more lett ers, digits, and underscores, with lowercase and uppercase letters dis tinct. A name may also be formed by enclosing any sequence of characte rs in a pair of backquotes. What we usually thing of as variables are \+ " }{TEXT 299 5 "names" }{TEXT -1 30 ".\n A key difference between a " }{TEXT 300 4 "name" }{TEXT -1 7 " and a " }{TEXT 301 6 "string" } {TEXT -1 9 " is that " }{TEXT 302 58 "any value may be assigned to a n ame, but not to a string. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "`this is a variable with a long name`:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "`this is a variable with a long name`*3;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "\"this is a string\":=2;" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 172 "A name need not be enclosed by b ack-quotes if it begins with a letter and contains no spaces. In this \+ case the name is the same whether or not the back-quotes are included. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "this_is_a_name:=2;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "`this_is_a_name` - this_is_a _name;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "We have seen the use of a pair of single quotes before. I will recall some of those uses her e:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "x:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "x:='x':" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 2 "x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "sum ('i^2','i'=1..n);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "f:=pro c(x) if x < 0 then RETURN(-x); else RETURN(x); fi; end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "plot(f(x),x=-1..1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "plot('f(x)',x=-1..1, title=\"absolu te value of x\");" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 103 "But note th at in the title ` `will also sometimes work but as we see below can so metimes lead to error:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "p lot('f(x)',x=-1..1, title=`absolute value of x`);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 69 "`constant1`:=5:\nplot(sin(`constant1`*x),x=0 ..1, title = `constant1`);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "`constant1`:=5:\nplot(sin(`constant1`*x),x=0..1, title = \"constan t1\");" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "Sometimes it is conveni ent to use " }{TEXT 313 14 "convert/string" }{TEXT -1 14 ". For exampl e:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "a:=5:\nplot(sin(a*x), x=0..2*Pi,title = convert(sin(a*x),string));" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 54 "Recall also the use of \" \" in the formating part of a " }{TEXT 314 6 "printf" }{TEXT -1 11 " statement:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "printf(\"The result is x = %d \\n\", 987); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 46 "converting text to numbers and numbers to text" }}{PARA 0 "" 0 "" {TEXT -1 7 "We can " }{TEXT 303 7 "convert" }{TEXT -1 75 " strings or names (i.e., t ext) to a list of numbers by using the procedure " }{TEXT 304 13 "conv ert/bytes" }{TEXT -1 257 " as in the following examples. Each symbol \+ (letters of the alphabet, punctuation mark, etc) corresponds to a numb er from 1 to 255. Although the documentation does not say, this appea rs to be essentially the so-called ASCII (ask-key) code in decimal for m. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "convert(\"a\",bytes); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "convert([97],bytes);" } {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 124 "Note that double quotes, \", within a string will cause confusion unless you repeat th em twice, as in the following example. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 77 "Text:=\"General Washington said, \"Attack at dawn!\", before he went to sleep.\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 79 "Text:=\"General Washington said, \"\"Attack at dawn!\"\", before he went to sleep.\";" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "Numbers:=convert(Text,bytes) ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "convert(Numbers,bytes) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 100 "We can also convert text to a list of the symbols in the text, for various types of word processi ng:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "List:=convert(Text,l ist);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "nops(List);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 32 "We get the same value by use of " }{TEXT 307 6 "length" }{TEXT -1 1 ":" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "length(Text);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "The procedure cat may be used to concatenate several strings, tha t is, put them together to form a single string. Here's an example:" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "s1:=\"What\";\ns2:=\" \"; \ns3:=\"is\";\ns4:=\"this\";\ns5:=\"?\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "cat(s1,s2,s3,s2,s4,s5);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 215 "We can get a list of all symbols as follows. Note that t here are many squares in the list. Apparently these are symbols not pr intable by Maple's interface, yet they are still considered as distinc t, as we shall see." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L:=[ seq(convert([i],bytes),i=0..255)];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "LL:=cat(op(L));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "convert(LL,bytes);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "S:=convert(%,set):\nnops(S);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "\{seq(i,i=1..255)\} minus S;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 84 "On my Mac both 10 and 13 convert to \"\\n\". This may not be the case on all platforms." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "convert([10,13],bytes);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "convert(%,bytes);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 37 "substring, \+ SearchText, and searchtext" }}{PARA 0 "" 0 "" {TEXT 315 23 "substring( string, a..b)" }{TEXT -1 121 " extracts from the substring starting wi th the a-th character and ending with the b-th character. Here are som e examples:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "text:=\"abcde fghijk\";" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "substring(text , 1...3);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "substring(text ,-3..-1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "substring(text , 4..7);" }}}{EXCHG {PARA 15 "" 0 "" {TEXT 316 10 "SearchText" }{TEXT -1 5 " and " }{TEXT 317 10 "searchtext" }{TEXT -1 20 " are very simila r. " }{TEXT 318 10 "SearchText" }{TEXT -1 71 " searches for the patte rn in the string looking for exact matches. The " }{TEXT 319 11 "searc htext " }{TEXT -1 112 "function does the same searching, but it is cas e insensitive; that is, upper/lower case differences are ignored." }} {PARA 15 "" 0 "" {TEXT -1 192 "If the pattern is found, both functions return an integer which indicates the position of the first character that matched. If the pattern is not found in the string, these functi ons return 0." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "searchtext(\"cde\", \"ABCDEFcde\");" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "SearchText(\"cde\", \"ABCDEFcde\"); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "SearchText(\"cab\", \"A BCDEFcde\");" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 29 "Assignment 10 Due Next Monday" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT 305 11 "Problem 1. " }{TEXT -1 71 " Let J = \{ 0,1,2,...,255\}. For each element a o f J define the mapping " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" } {TEXT -1 13 " by the rule " }{XPPEDIT 18 0 "proc (x) options operator, arrow; `mod`(ax,256) end proc;" "6#R6#%\"xG7\"6$%)operatorG%&arrowG6 \"-%$modG6$%#axG\"$c#F*F*F*" }{TEXT -1 3 ". \n" }}{PARA 0 "" 0 "" {TEXT -1 62 "(a) Find using Maple, for which values of a in J the map ping " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" }{TEXT -1 20 " is 1-1 and onto. " }{TEXT 340 66 "Put the values in a list. Don't print the m out in a vertical line." }{TEXT -1 66 " Can you give a simple criter ion for a number to be in the list? " }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 18 "(b) Show that if " }{XPPEDIT 18 0 "f [a];" "6#&%\"fG6#%\"aG" }{TEXT -1 51 " is 1-1 for a in J then its inve rse is of the form " }{XPPEDIT 18 0 "f[b];" "6#&%\"fG6#%\"bG" }{TEXT -1 68 " for some b in J. Make a list of the pairs of the form [a,b] wh ere " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" }{TEXT -1 13 " is 1-1 \+ and " }{XPPEDIT 18 0 "f[b];" "6#&%\"fG6#%\"bG" }{TEXT -1 19 " is the \+ inverse of " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" }{TEXT -1 71 ". \+ It will look like this: [ [1,1], [3,171], [5, 205],..., [255,255]]. \+ " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 1 "[" }{TEXT 329 11 "Some Hints:" }{TEXT -1 45 " The \"obvi ous\" way to define the functions " }{XPPEDIT 18 0 "f[a](x);" "6#-&%\" fG6#%\"aG6#%\"xG" }{TEXT -1 56 " is the following. But as you can see, it doesn't work. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "f[a]: =proc(x) a*x mod 256; end:\nf[13](1);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-&%\"fG6#\"#86#\"\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 29 "Clear ly this is wrong since " }{XPPEDIT 18 0 "f[13](1) = 13;" "6#/-&%\"fG6 #\"#86#\"\"\"F(" }{TEXT -1 87 ". So we must try something else. One wa y is to define f as a function of two variables:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "f:=proc(x,a) a*x mod 256; end:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "f(1,13);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#8" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 260 "" 0 "" {TEXT -1 56 "Or you might get by without givi ng the functions a name!" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 72 "To show that a function f: J->J i s one-to-one and onto we need to show " }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 13 "(1) that if " }{XPPEDIT 18 0 "x <> y ;" "6#0%\"xG%\"yG" }{TEXT -1 6 " then " }{XPPEDIT 18 0 "f(x) <> f(y); " "6#0-%\"fG6#%\"xG-F%6#%\"yG" }{TEXT -1 5 " and " }}{PARA 0 "" 0 "" {TEXT -1 55 "(2) that for every y in J there is an x in J such that " }{XPPEDIT 18 0 "f(x) = y;" "6#/-%\"fG6#%\"xG%\"yG" }{TEXT -1 3 ". " } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 330 17 "For a f inite set " }{TEXT -1 119 "J if (1) holds then so does (2) and vice ve rsa. So we only need to show that f is onto. That is, f(J) = J. The u se of " }{TEXT 331 3 "map" }{TEXT -1 11 " may help. " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 13 "To show that " }{XPPEDIT 18 0 "g = f^(-1);" "6#/%\"gG)%\"fG,$\"\"\"!\"\"" }{TEXT -1 84 " we need to show that for all x in J: f(g(x)) = x AND g(f(x)) = \+ x. But since J is " }{TEXT 332 6 "finite" }{TEXT -1 86 ", it suffices \+ to show just one of these equations. There are several ways to do this . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 36 "For (b) you might write a procedure " }{TEXT 326 12 "InverseCheck" } {TEXT -1 31 " with input a and b such that " }{TEXT 325 17 "InverseCh eck(a,b)" }{TEXT -1 9 " returns " }{TEXT 327 4 "true" }{TEXT -1 4 " if " }{XPPEDIT 18 0 "f[a](f[b](x)) = x;" "6#/-&%\"fG6#%\"aG6#-&F&6#%\"bG 6#%\"xGF/" }{TEXT -1 29 " for all x in J and returns " }{TEXT 328 5 " false" }{TEXT -1 120 " if not. Then for each a go through a loop chec king each b till you find one such that InverseCheck(a,b) returns true .]" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 320 9 "Problem 2" }{TEXT -1 2 ". " }}{PARA 0 "" 0 "" {TEXT -1 74 "I used the following method to encrypt a message. I chose at rand om some " }{TEXT 336 1 "a" }{TEXT -1 36 " in the set \{1,2,...,255\} s uch that " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" }{TEXT -1 16 " is \+ 1-1 and onto" }{TEXT -1 58 ". I next converted the message to a list o f numbers using " }{TEXT 322 7 "convert" }{TEXT -1 13 ". Then using " }{TEXT 323 3 "map" }{TEXT -1 25 ", I applied the function " }{XPPEDIT 18 0 "f[a];" "6#&%\"fG6#%\"aG" }{TEXT -1 59 " to each element in the l ist to obtain the list of numbers:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 193 "[49, 85, 218, 125, 198, 155, 188, 55, 22 8, 155, 188, 115, 85, 218, 65, 219, 96, 195, 85, 55, 96, 248, 155, 178 , 135, 96, 22, 198, 85, 105, 135, 218, 96, 188, 248, 135, 96, 145, 85, 12, 135, 26]" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 31 "What was my original message? " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 333 4 "Hint" }{TEXT -1 48 ". The messa ge contains the word \"the\". So using " }{TEXT 334 10 "searchtext" } {TEXT -1 122 " can help you pick out the correctly decrypted message a s you apply all possible b's. Or, you could use some other method." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 324 21 "[COPYING AND PASTING:" }{TEXT -1 411 " I have found that when attempting to co py and paste text such as the list of numbers above into an input fiel d of Maple, sometimes I can make it work by copying and pasting first \+ into a word processor. Then, from there, copy and paste into a Maple i nput region. On some platforms you may be able to do it directly. On \+ others, when you paste into a Maple input region the material is conv erted to Maple text.]" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 321 10 "Problem 3." }{TEXT -1 2 " (" }{TEXT 339 27 "This counts as two problems" }{TEXT -1 197 ". ) If you cannot do part (1) send me an email and I will send a program to do it. This will cost you 1/2 out of a possible 2 pts for Problem \+ 3, but should allow you to the rest of problem 3. ) See " }{TEXT 335 5 "Hints" }{TEXT -1 26 " following the text below." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 12 "Using Maple " }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 170 "(1) Make a list \+ of the distinct word in the following text (which is the second paragr aph of the Declaration of Independence). [If you put the text in a var iable called " }{TEXT 338 5 "text " }{TEXT -1 75 "then you can remove \+ all comma, periods, etc, by use of the following code. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 261 "" 0 "" {TEXT -1 99 "> T1:=convert(text ,list):\n> T2:=remove(x->evalb(member(x,\{\".\",\",\",\";\",\":\"\})), T1):\n> T:=cat(op(T2));" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 48 "(2) Find the total number of words in the text. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 37 " ( a) counting repetitions, and" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 37 " (b) not counting repetitions." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 266 "(3) Find the n umber of words in the text of each length from 1 to the maximum length word. If a word occurrs k times it should add k to the count. For ex ample, since \"a\" occurrs 4 times and it is the only word of length 1 , we will say there are 4 words of length 1." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 171 "(4). For each letter of the al phabet a through z determine the number of words in the text containin g the letter. Do not distinguish between upper and lower case letters. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 262 "" 0 "" {TEXT -1 16 "He re's the text:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1624 "We hold these truths to be self-evident, that all men a re created equal, that they are endowed by their Creator with certain \+ unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governe d, That whenever any Form of Government becomes destructive of these e nds, it is the Right of the People to alter or to abolish it, and to i nstitute new Government, laying its foundation on such principles and \+ organizing its powers in such form, as to them shall seem most likely \+ to effect their Safety and Happiness. Prudence, indeed, will dictate t hat Governments long established should not be changed for light and t ransient causes; and accordingly all experience hath shewn, that manki nd are more disposed to suffer, while evils are sufferable, than to ri ght themselves by abolishing the forms to which they are accustomed. B ut when a long train of abuses and usurpations, pursuing invariably th e same Object evinces a design to reduce them under absolute Despotism , it is their right, it is their duty, to throw off such Government, a nd to provide new Guards for their future security. Such has been the \+ patient sufferance of these Colonies; and such is now the necessity wh ich constrains them to alter their former Systems of Government. The h istory of the present King of Great Britain is a history of repeated i njuries and usurpations, all having in direct object the establishment of an absolute Tyranny over these States. To prove this, let Facts be submitted to a candid world." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT 337 5 "Hint:" }{TEXT -1 288 " Here are the words and symbols (in jumbled order --including names of variables) I used \+ in my programs to do this problem: (What you can get out of this mess \+ is some of the procedures that may be useful in solving this problem. \+ I would not suggest trying to get too much more out of it.)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 467 "for, =, >, >0 ),Words));od;, Alphabet, L:=map(length,Words);, T:=substring(T,i+1..n) ;, T:=text:, Words:=NULL:, Words:=Words,substring(T,1..i-1):, Words:=[ Words];nops(Words);, break;, do, do, do, fi;, for, from, i, i, i:=sear chtext(,T);, if, in, max(op(L));, n, n:=length(T):while, n:=length(T); , nops(Alphabet);, nops(select(x->evalb(x=i),L)));, od:, od; Alphabet: =[seq(convert([i],bytes),i=97..122)];, print(i,, then, to, x, x, nops( select(u->evalb(searchtext(x,u)];" }}}}}{MARK "10" 0 }{VIEWOPTS 0 0 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 1 1 1 33 1 1 }