{VERSION 6 0 "IBM INTEL LINUX" "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 "2D Output" 2 20 "" 0 1 0 0 255 1 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 0 }{CSTYLE "" -1 257 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 261 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 262 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 266 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 267 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 269 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 270 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 271 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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 "Text Output" -1 6 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 2 2 2 2 2 1 2 1 3 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Warning" -1 7 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 2 2 2 2 2 1 1 1 3 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Error " 7 8 1 {CSTYLE "" -1 -1 "" 0 1 255 0 255 1 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Diagnostic" -1 9 1 {CSTYLE "" -1 -1 "Courier" 1 10 64 128 64 1 2 2 2 2 2 1 1 1 3 1 }1 1 0 0 0 0 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 "Maple Plot" -1 13 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 }{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 "Normal" -1 256 1 {CSTYLE "" -1 -1 "Ti mes" 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 18 "" 0 "" {TEXT -1 32 "Programming in Maple: Som e Notes" }}}{EXCHG {PARA 256 "" 0 "" {TEXT -1 76 "Michael Monagan\nDep artment of Mathematics\nSimon Fraser University\nFall 2013." }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 59 "These notes will work in any versi on of Maple from Maple 6." }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 5 "List s" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 180 "The simplest data structure \+ in Maple is a list. The elements of a list may be of any type. To c reate a list of values enclose them in square brackets [, ]. Lists ma y be nested." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "E := []; # \+ the empty list" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"EG7\"" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "L := [1,2,-3,4,1];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7'\"\"\"\"\"#!\"$\"\"%F&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "M := [[1,2,3],[x-1,x^2-1,x^3-1]];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"MG7$7%\"\"\"\"\"#\"\"$7%,&%\"xGF 'F'!\"\",&*$)F,F(F'F'F'F-,&*$)F,F)F'F'F'F-" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "To count the number of entries in a list use nops(L) comm and." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 71 "To access the i'th element of a list (counting from 1) use a subsc ript." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "L[3];" }{TEXT -1 0 "" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#!\"$" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 5 "M[2];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7%,&%\"xG\" \"\"F&!\"\",&*$)F%\"\"#F&F&F&F',&*$)F%\"\"$F&F&F&F'" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "M[2][2];" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#,&*$)%\"xG\"\"#\"\"\"F(F(!\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 71 "A negative subscript counts from the end. So here is the last ele ment." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "L[-1];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 " Use the following to extract a sublist" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "L[2..3];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7$\"\"#!\" $" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "L[2..-1];" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#7&\"\"#!\"$\"\"%\"\"\"" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 57 "To append (prepend) elements to a list use the followin g." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "op(L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'\"\"\"\"\"#!\"$\"\"%F#" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 15 "L := [op(L),5];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# >%\"LG7(\"\"\"\"\"#!\"$\"\"%F&\"\"&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "To test if an element is in a list use" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "member(2," }{TEXT -1 0 "" }{MPLTEXT 1 0 3 "L);" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 199 "Lists are used by many Maple commands. For example, man y of the graphing commands takes lists of points or lists of functions as inputs. For example, to plot sin(x) and cos(x) on the same graph do" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "L := [sin(x),cos(x)] ;" }}{P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}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 204 "Although you can assign to an entry of a list \+ (as if it were an array) if the list has less than 100 elements, do n ot do this. It creates a copy of the entire list. So it's not effici ent. Use Arrays ." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "L[2] \+ := 10;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"LG6#\"\"#\"#5" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "L;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7$-%$sinG6#%\"xG\"#5" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 4 "Sets" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 336 "Maple also su pports sets. Maple uses squiggley brackets \{ \} for sets. For exampl e \{1,3,5\}. Sets differ from lists in that the only one copy of eac h element is kept and the elements are sorted. Otherwise many of the commands that work for lists, such as subscripts, also work exactly t he same way for sets. Here are some examples. " }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 15 "S := \{1,5,3,1\};" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"SG<%\"\"\"\"\"$\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "T := \{2,3,4\};" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"TG<%\"\"#\"\"$\"\"%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "S[2 ];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 47 "The number of elements of a set |S| is given by" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(S);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "To test i f an element x is in a set use member" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(5,S);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%tru eG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "The set operations union, i ntersection and set difference are" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "S union T;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<'\"\" \"\"\"#\"\"$\"\"%\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "S intersect T;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<#\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "S minus T;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<$\"\"\"\"\"&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 14 "T he empty set " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "phi := \{ \};" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%$phiG<\"" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 12 "phi union S;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<%\"\"\"\"\"$\"\"&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 "You c an insert a new element in a set in two ways, either using union or, l ike lists, using op" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "S un ion \{9\};" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<&\"\"\"\"\"$\"\"&\"\"* " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "\{op(S),9\};" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<&\"\"\"\"\"$\"\"&\"\"*" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 69 "The elements of a set may be of any type. Here is a set of equations" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "eqns := \{ x+2*y=1, 3*x-z=2, x+y+z=0 \};" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#>%%eqnsG<%/,&%\"xG\"\"\"*&\"\"#F)%\"yGF)F)F)/,&*&\"\"$F)F(F)F)%\"zG! \"\"F+/,(F(F)F,F)F1F)\"\"!" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 204 "Ma ny Maple commands take sets of objects as input. For example, the so lve command takes a set (or list) of equations as input and a set of u nknowns to solve for and outputs the solution as a set (list)." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "sol := solve( eqns, \{x,y,z \} );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%$solG<%/%\"xG#\"\"$\"\"(/% \"yG#\"\"#F*/%\"zG#!\"&F*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 22 "Conditional statements" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 104 "To execute a command in Maple conditionally use t he if command which has either of the following forms\n\n" }{TEXT 293 4 " " }{TEXT 300 2 "if" }{TEXT 301 13 " " }{TEXT 294 4 "then" }{TEXT 302 14 " " }{TEXT 295 4 "else" }{TEXT 303 14 " " }{TEXT 296 2 "fi" }{TEXT 304 1 "\n" }{TEXT -1 14 " \nor just\n\n " }{TEXT 297 2 "if" }{TEXT 305 13 " " } {TEXT 298 4 "then" }{TEXT 306 14 " " }{TEXT 299 3 "fi\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "For example, " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "x := 2;\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "if x>1 th en print(good); else print(bad); fi;" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#%%goodG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 44 "The if statement can be nested. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "if x>1 then if x>2 then print(\"x > 2\"); else print(\"x > 1\"); fi; \+ else print(\"x < 2\"); fi; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q&x~>~1 6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 131 "Although you can put it a ll on one line like that it's best to split it accross multiple lines. Use SHIFT-ENTER to get a new line." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 101 "if x>1 then\n if x>2 then print(\"x > 2\");\n el se print(\"x > 1\");\n fi;\nelse\n print(\"x < 2\");\nfi;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#Q&x~>~16\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "The boolean operators in Maple are and, or, and not. Th e relational operators in Maple are =, >, <, >=, <=, and <> for not e quals." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "x := 2;\nif x >= \+ 1 and x <= 3 then x := x+1; fi;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"xG\"\"#" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 5 "Loops" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 51 "To execute one or more statementsi n a loop use the " }{TEXT 314 3 "for" }{TEXT -1 38 " command. It has \+ the following form\n\n" }{TEXT 259 4 " " }{TEXT 264 3 "for" }{TEXT 265 12 " " }{TEXT 260 4 "from" }{TEXT 266 9 " " } {TEXT 261 2 "to" }{TEXT 267 7 " " }{TEXT 262 2 "do" }{TEXT 268 14 " " }{TEXT 263 3 "od\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "for i from 1 to 5 do i^2; od;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#D" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 39 "for i from 1 to 5 do i; isprime(i); od;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%&falseG" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#%%trueG" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$ " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%&falseG" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 93 "To execute some sta tements while a condition is true use the while loop. It has the synt ax\n\n" }{TEXT 256 4 " " }{TEXT 269 5 "while" }{TEXT 270 13 " " }{TEXT 257 2 "do" }{TEXT 271 14 " " }{TEXT 258 3 "od " }{TEXT 272 2 "\n\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "i := 1;\nwhile i <= 5 do i^2; i := i+1; od;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\" " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"#" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"$" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"&" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# \"#D" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"iG\"\"'" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 321 "There is quite a bit of output there. You can see each assignment and each square displayed. To suppress the outpu t of a loop (or any Maple statement) use : instead of ; But then we w on't see any output. We can override the : by using print(i^2) to see the squares like this. Notice I put a : on the i := 1: as well." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "i := 1:\nwhile i<=5 do print (i^2); i := i+1; od:" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#D" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "As a secon d example, we find the first prime bigger than 2. We only consider th e odd integers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "p := 33; \nwhile not isprime(p) do p := p+2; od:\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"pG\"#L" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#P" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 67 " In a Maple for loop, you can count by a different valu e using the " }{TEXT 315 2 "by" }{TEXT -1 34 " clause. The general fo rm is this" }{TEXT 312 16 "\n\n for" }{TEXT -1 12 " " }{TEXT 308 4 "from" }{TEXT -1 9 " " }{TEXT 307 2 "by" } {TEXT -1 13 " " }{TEXT 309 2 "to" }{TEXT -1 7 " " } {TEXT 310 2 "do" }{TEXT -1 14 " " }{TEXT 311 3 "od\n" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "Also handy is that you can exit a \+ loop using the " }{TEXT 316 5 "break" }{TEXT -1 63 " command. Here we find the first prime bigger than 31 using a " }{TEXT 317 3 "for" } {TEXT -1 7 " loop.\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 86 "for p from 33 by 2 do\n print(testing(p));\n if isprime(p) then bre ak; fi;\nod:\np; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%(testingG6#\"#L " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%(testingG6#\"#N" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%(testingG6#\"#P" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#P" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 31 "Notice that I didn't s pecify a " }{TEXT 318 2 "to" }{TEXT -1 64 " clause . All the clauses \+ are optional. The defaults are\n\n " }{TEXT 313 34 " from 1\n \+ to infinity\n by 1" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "As a fi nal example here is a loop that generates some polynomials" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "for n to 6 do n = factor(x^n-1) od; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"\",&%\"xGF$F$!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"#*&,&%\"xG\"\"\"F(!\"\"F(,&F'F(F(F(F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"$*&,&%\"xG\"\"\"F(!\"\"F(,(*$)F '\"\"#F(F(F'F(F(F(F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"%*(,&%\"x G\"\"\"F(!\"\"F(,&F'F(F(F(F(,&*$)F'\"\"#F(F(F(F(F(" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#/\"\"&*&,&%\"xG\"\"\"F(!\"\"F(,,*$)F'\"\"%F(F(*$)F'\" \"$F(F(*$)F'\"\"#F(F(F'F(F(F(F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\" \"'**,&%\"xG\"\"\"F(!\"\"F(,&F'F(F(F(F(,(*$)F'\"\"#F(F(F'F(F(F(F(,(F,F (F'F)F(F(F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "Three other useful looping constructs are the " }{TEXT 289 3 "map" }{TEXT -1 17 " comman d and the " }{TEXT 290 3 "seq" }{TEXT -1 17 " command and the " } {TEXT 291 4 "add " }{TEXT -1 49 "command. The examples show what the \+ commands do." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "L := [1,2,3 ,4,5];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7'\"\"\"\"\"#\"\"$\"\" %\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "map( f, L );" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#7'-%\"fG6#\"\"\"-F%6#\"\"#-F%6#\"\"$-F %6#\"\"%-F%6#\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "map( \+ isprime, L );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7'%&falseG%%trueGF%F$ F%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "seq( i^2, i=1..5 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'\"\"\"\"\"%\"\"*\"#;\"#D" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "seq( L[i], i=1..nops(L) );" }} {PARA 11 "" 1 "" {XPPMATH 20 "6'\"\"\"\"\"#\"\"$\"\"%\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "seq( isprime(L[i]), i=1..nops(L) ); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6'%&falseG%%trueGF$F#F$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "seq( L[i]*x^(i-1), i=1..nops(L) ); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6'\"\"\",$*&\"\"#F#%\"xGF#F#,$*&\"\" $F#)F'F&F#F#,$*&\"\"%F#)F'F*F#F#,$*&\"\"&F#)F'F.F#F#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "L := [seq( n^2, n=L )];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7'\"\"\"\"\"%\"\"*\"#;\"#D" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "add( f(i), i=1..5 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,,-%\"fG6#\"\"\"F'-F%6#\"\"#F'-F%6#\"\"$F'-F%6#\"\"%F'- F%6#\"\"&F'" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "add( i^2, i= 1..5 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#b" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 20 "add( x[i], i=0..5 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,.&%\"xG6#\"\"!\"\"\"&F%6#F(F(&F%6#\"\"#F(&F%6#\"\"$F(& F%6#\"\"%F(&F%6#\"\"&F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 " add( x^i, i=0..5 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,.\"\"\"F$%\"xG F$*$)F%\"\"#F$F$*$)F%\"\"$F$F$*$)F%\"\"%F$F$*$)F%\"\"&F$F$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "Read the help files for these commands, t hey are very handy." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "?map " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "?seq" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "?add" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 30 "Maple Functions and \+ Procedures" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 66 "Maple has a special \+ syntax for inputting a simple function like " }{XPPEDIT 18 0 "f(x) = x^2+1;" "6#/-%\"fG6#%\"xG,&*$F'\"\"#\"\"\"F+F+" }{TEXT -1 63 ". You \+ may input using the arrow notation in Maple, as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "f := x" }{TEXT -1 0 "" }{MPLTEXT 1 0 10 " -> x^2+1;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGj+6#%\"xG6\" 6$%)operatorG%&arrowGF(,&*$)9$\"\"#\"\"\"F1F1F1F(F(F(6#\"\"!" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "Now you can apply the function to \+ values in the usual notation" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(2);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "f(0.5);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #$\"$D\"!\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(z);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#,&*$)%\"zG\"\"#\"\"\"F(F(F(" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "A procedure in Maple takes the for m\n\n " }{TEXT 273 4 " " }{TEXT 274 4 "proc" }{TEXT 275 21 "( p1, p 2, ... )\n " }{TEXT 276 5 "local" }{TEXT 277 20 " l1, l2, ... ;\n \+ " }{TEXT 278 6 "global" }{TEXT 279 23 " g, g2, ... ;\n " } {TEXT 282 10 "statement1" }{TEXT 283 11 ";\n " }{TEXT 284 10 " statement2" }{TEXT 285 25 ";\n ....\n " }{TEXT 286 11 " statementn" }{TEXT 287 5 ";\n " }{TEXT 280 10 " end proc" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 409 "There ma y be zero or more parameters, one or more locals, one or more globals \+ and one or more statements in the procedure body.\nThe local and globa l statements are optional. Variables in the procedure body that are n ot explicitly declared as parameters, locals, or globals are declared \+ to be local automatically if assigned to, otherwise they are global. \+ The value returned by the procedure is the value of " }{TEXT 281 10 "s tatementn" }{TEXT -1 206 ", the last statement in the body of the proc edure or the value of an explicit return statement. Type declarations for parameters and local variables need not be explicitly given. Som e examples will help. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "f := proc(x) y := x^2; y+1; end proc;" }}{PARA 7 "" 1 "" {TEXT -1 59 "W arning, `y` is implicitly declared local to procedure `f`\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGj+6#%\"xG6#%\"yG6\"F*C$>8$*$)9$\"\"#\" \"\",&F-F2F2F2F*F*F*6#\"\"!" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "f(2);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 5 "f(z);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,&*$ )%\"zG\"\"#\"\"\"F(F(F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 218 "Notic e that Maple made the variable y local for us. To avoid the warning, \+ we should declare it local ourselves. Also, you can break a procedure over more than one line - and you should unless it is a simple functi on." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "f := proc(x) \nlocal y; \n y := x^2;\n y+1;\nend proc;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGj+6#%\"xG6#%\"yG6\"F*C$>8$*$)9$\"\"#\"\"\",&F-F2F2F2F*F*F* 6#\"\"!" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 178 "This next example sea rches a list L for the value x. It outputs the position of the first \+ occurrence of x in L and 0 otherwise. The example also uses an explic it return. When " }{TEXT 319 8 "return x" }{TEXT -1 53 " is executed, Maple immediately returns the value of " }{TEXT 321 1 "x" }{TEXT -1 90 " as the result of the procedure. I've also used a Maple comment. \+ Anything following the " }{TEXT 320 1 "#" }{TEXT -1 67 " character on a line is treated as a comment and ignored by Maple.\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 150 "position := proc(x,L) local i;\n \+ for i from 1 to nops(L) do \n if L[i]=x then return i fi;\n o d;\n 0; # meaning x is not in the list\nend proc;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%)positionGj+6$%\"xG%\"LG6#%\"iG6\"F+C$?(8$\"\"\"F/- %%nopsG6#9%%%trueG@$/&F36#F.9$OF.\"\"!F+F+F+6$F;F;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "position(x,[u,v,w,x,y,z]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "position(y,[u,v,w]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"!" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 212 "This next example is a Maple pr ocedure which returns the next prime bigger than the input. I am also telling Maple that the input parameter n must be an integer. If it's not, an error will be generated. See " }{TEXT 322 5 "?type" }{TEXT -1 37 " for a list of other allowable types." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 117 "NextPrime := proc(n::integer)\nlocal x;\n \+ x := n+1;\n while not isprime(x) do x := x+1; od;\n x;\nend \+ proc;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%*NextPrimeGj+6#'%\"nG%(inte gerG6#%\"xG6\"F,C%>8$,&9$\"\"\"F2F2?(F,F2F2F,4-%(isprimeG6#F/>F/,&F/F2 F2F2F/F,F,F,6#\"\"!" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "Next Prime(2);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "NextPrime(1000);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "Nex tPrime(2/3);" }}{PARA 8 "" 1 "" {TEXT -1 101 "Error, invalid input: Ne xtPrime expects its 1st argument, n, to be of type integer, but receiv ed 2/3\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 274 "Now I'm going to red o this example. The first difference is that I'm going to use a : on \+ the end proc: to suprress the output. The second difference is that I 'm going to count by 2 (because that's more efficient). So I need to \+ start with the first odd number bigger than " }{TEXT 323 1 "n" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 156 "NextPrime := pr oc(n::integer)\nlocal x;\n if irem(n,2)=0 then x := n+1; else x : = n+2; fi;\n while not isprime(x) do x := x+2; od;\n x;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "NextPrime(1000); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 303 "There is one major difference between Maple and most oth er programming languages like C and Java. The parameters to a procedu re cannot be used like local variables. You cannot assign to paramete rs. If you try to, you will get an error. Let's redo the NextPrime e xample where we simply add 1 or 2 to " }{TEXT 326 1 "n" }{TEXT -1 41 " to make it the next odd number then use " }{TEXT 327 1 "n" }{TEXT -1 48 " in the procedure instead of the local variable " }{TEXT 328 2 "x. " }{TEXT -1 39 " You may have wondered why I did that." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 147 "NextPrime := proc(n::integer)\n \+ if irem(n,2)=0 then n := n+1; else n := n+2; fi;\n while not i sprime(x) do n := n+2; od;\n n;\nend proc:" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 16 "NextPrime(1000);" }}{PARA 8 "" 1 "" {TEXT -1 56 "Error, (in NextPrime) illegal use of a formal parameter\n" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "The error occurs because when Mapl e executes " }{TEXT 324 8 "n := n+1" }{TEXT -1 181 " it substitutes \+ the parameter 1000 for n and tries to execute 1000 := 1000+1 which doe sn't make any sense. Well, that's the way Maple does it. So we need \+ to use a local variable " }{TEXT 325 1 "x" }{TEXT -1 12 " like I did. " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 178 "Procedures may be nested. \+ \nProcedures may be returned and passed freely as parameters. \nThe s implest debugging tool is to insert print statements in the procedure. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 166 "NextPrime := proc(n::integer)\nlocal x;\n if irem(n,2)=0 then x := n+1; el se x := n+2; fi;\n while not isprime(x) do print(x); x := x+2; od ;\n x;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "N extPrime(1000);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%,5" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#\"%.5" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%05" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%25" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "The next simplest \+ debugging tool is the trace command. All assigment statements are dis played." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "trace(NextPrime) ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%*NextPrimeG" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 16 "NextPrime(1000);" }}{PARA 9 "" 1 "" {TEXT -1 33 "\{--> enter NextPrime, args = 1000" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"%,5" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%,5" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"%.5" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%.5" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"%05" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%05" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"%25" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%25" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"%45" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}{PARA 9 "" 1 "" {TEXT -1 45 "<-- exit NextPrime (now at to p level) = 1009\}" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 269 "The printf command can be used to print \+ more detailed information in a controlled format. It works just like \+ the printf command in the C language. The main difference is the %a o ption for printing algebraic objects like polynomials. But %a works f or anything. E.g." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "prin tf( \"A polynomial %a\\n\", x^2-2*y*x );" }}{PARA 6 "" 1 "" {TEXT -1 22 "A polynomial x^2-2*y*x" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 215 "NextPrime := proc(n::integer)\nlocal x;\n if irem(n,2)=0 the n x := n+1; else x := n+2; fi;\n while not isprime(x) do \n \+ printf(\"%a is not prime\\n\",x); \n x := x+2;\n od; \n x;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "Ne xtPrime(1000);" }}{PARA 6 "" 1 "" {TEXT -1 17 "1001 is not prime" }} {PARA 6 "" 1 "" {TEXT -1 17 "1003 is not prime" }}{PARA 6 "" 1 "" {TEXT -1 17 "1005 is not prime" }}{PARA 6 "" 1 "" {TEXT -1 17 "1007 is not prime" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"%45" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 64 "There is more. But this should be enough for t he course. See " }{TEXT 288 5 "?proc" }{TEXT -1 45 " if you need mo re information or more tools." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 32 "Subscripted Variables \+ and Arrays" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 69 "Variables may be sub scripted. For example, here is a polynomial in " }{XPPEDIT 18 0 "x[1 ],x[2],x[3];" "6%&%\"xG6#\"\"\"&F$6#\"\"#&F$6#\"\"$" }{TEXT -1 37 ". \+ You can assign to the subscripts." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "f := 1-x[1]*x[2]*x[3];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "x[1] \+ := 3;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fG,&\"\"\"F&*(&%\"xG6#F&F &&F)6#\"\"#F&&F)6#\"\"$F&!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&% \"xG6#\"\"\"\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "f;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#,&\"\"\"F$*(\"\"$F$&%\"xG6#\"\"#F$&F(6 #F&F$!\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 203 "There may be more \+ than one subscript and the subscripts may be any value. \nArrays are l ike arrays from computing science. Here is how to create a one-dimens ional array A with values indexed from 1 to 5." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 17 "A := Array(1..5);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"AG-%'RTABLEG6%\"*7\\]m\"-%'VECTORG6#7'\"\"!F-F-F-F- %&ArrayG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "By default, the entri es in the array A are initialized to 0." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A[1] := 3;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG 6#\"\"\"\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A[1];" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "for i from 2 to 5 do A[i] := 3*A[i-1] od;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"#\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"$\"#F" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#> &%\"AG6#\"\"%\"#\")" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"& \"$V#" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 115 "Often you will want to \+ convert an Array to a list or a list to an Array. Use the following. \+ For Array to list use" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "L := convert(A,list);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7'\"\"$ \"\"*\"#F\"#\")\"$V#" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 21 "For list \+ to Array use" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "A := Array( 1..5,L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"AG-%'RTABLEG6%\"*Wqhm \"-%'VECTORG6#7'\"\"$\"\"*\"#F\"#\")\"$V#%&ArrayG" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 36 "Oh, they look the same. Let's check" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "whattype(L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%listG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "w hattype(A);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%&ArrayG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "So what's the difference? In an Array yo u can change a value in constant time. So when we do " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "A[3] := 10;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"$\"#5" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 108 "It doesn't matter how long the Array is, this takes a fixed amoun t of time. This is not the case for lists." }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 124 "The last thing I want to mention is that you should no t build up a list of items one at a time. For example, do not do this " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "L := []:\nfor i from 1 \+ to 6 do\n L := [op(L),i^2];\nod;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #>%\"LG7#\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7$\"\"\"\"\"% " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7%\"\"\"\"\"%\"\"*" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7&\"\"\"\"\"%\"\"*\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7'\"\"\"\"\"%\"\"*\"#;\"#D" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7(\"\"\"\"\"%\"\"*\"#;\"#D\"#O" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 274 "Why not? Because each time you add the \+ next square to the list, Maple makes a copy of all the previous elemen ts. So the amount of space that it uses is 1 + 2 + 3 + 4 + 5 + 6 word s. If we keep doing this we will use a quadratic amount of space beca use the sum of the first" }{TEXT 329 3 " n " }{TEXT -1 12 "integers is " }{XPPEDIT 18 0 "1/2*n*(n+1);" "6#**\"\"\"F$\"\"#!\"\"%\"nGF$,&F'F$F $F$F$" }{TEXT -1 91 ". Instead, use an Array like this and then conve rt the Array to a list if you want a list." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 77 "A := Array(1..6):\nfor i from 1 to 6 do A[i] := i^2 ; od;\nL := convert(A,list);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"A G6#\"\"\"F'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"#\"\"%" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"$\"\"*" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>&%\"AG6#\"\"%\"#;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #>&%\"AG6#\"\"&\"#D" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%\"AG6#\"\"' \"#O" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"LG7(\"\"\"\"\"%\"\"*\"#;\" #D\"#O" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 54 "I'm going to time this \+ (in CPU seconds) for the first " }{TEXT 330 2 "n " }{TEXT -1 39 "integ ers so you can see the difference." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "n := 5000;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG \"%+]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "st := time():\nL : = []:\nfor i to n do L := [op(L),i^2] od:\ntime()-st;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"$X\"!\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 94 "st := time():\nA := Array(1..n):\nfor i to n do A[i] := i^2 od :\nL := convert(A,list):\ntime()-st;" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#$\"\")!\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}} {MARK "8 0 0" 21 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }