{VERSION 3 0 "SGI MIPS UNIX" "3.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "" -1 256 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 257 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 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 0 "" 0 "" {TEXT 256 49 "Assignments in Maple, seq uences, lists, and sets." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 41 "Assigning a value to a variable in Maple:" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A:=3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "B:=4;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 56 "You can assign two (or more) variables at the same time:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "A,B := 5, 7;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 118 "Simulta neously assigning several variables at the same time is convenient if \+ you want to switch the values of A and B:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 11 "A,B := B,A;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 77 "Variables can also be used even when they have not yet been assigned a value:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "x;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "y;" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "P:=x^3+x^5+12*x;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 244 "When x is not assigned, you can s till use x. Here P is a polynomial in x. If x had a value, say, an int eger, then P wouldn't have become a polynomial but it would have been \+ an integer. You can compute values of P at x = 1, 2, 3 by substitution :" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "subs(x=1,P);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "subs(x=2,P);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "subs(x=3,P);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 56 "or with the eval command (eval is short for: evaluat ion)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "eval(P, x=3);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 140 "We could do this sequence of subs titutions by the command seq (stands for sequence) as follows. Lets sa y we want to substitute i=1..6 for x:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "seq( subs(x=i,P) ,i=1..6);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "seq(i, i=1..6);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 129 "The output of the seq command is a datastructure that's called a sequence in Maple. In Maple a sequence is something of the form:" } }{PARA 0 "" 0 "" {TEXT -1 42 " expression, expression, ..., expressi on" }}{PARA 0 "" 0 "" {TEXT -1 52 "So it is a bunch of expressions sep erated by commas." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "Instead of computing the sequence subs(x=1,P), subs(x=2, P), .. we can also compute the sum: subs(x=1,P)+subs(x=2,P)+..." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "add( subs(x=i,P), i=1..6);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "add(i, i=1..100);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 15 "Multiplication:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "mul(x-i, i=1..5);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 16 "mul(i, i=1..30);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "30! ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "if actor(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "The command ifactor stands for integer factorization. Every Maple command must be ended w ith ; or with :" }}{PARA 0 "" 0 "" {TEXT -1 44 "Lets look at the diffe rence between the two." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A: =2;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 43 "View the contents of varia ble A as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 56 "Now end the command with a colon i nstead of a semi-colon" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "A: =12^12:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 122 "You see that with a c olon, Maple prints nothing. However, the command (in this case, an ass ignment) did get executed, see:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 70 "In Maple, every comm and is followed by a colon : or by a semi-colon ;" }}{PARA 0 "" 0 "" {TEXT -1 154 "If you use : or ; that makes no difference for what Mapl e does, the only difference is that ; causes something to be written t o the screen and : does not." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 85 "Lets look some more at sequences in Maple. The \+ following is an example of a sequence:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "A := 3,4,5,2,3,3,3,1;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 82 "Now you can extend the sequence to the left, or to the ri ght, or both, as follows:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "A:=A,20,30;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "A:=hello ,how,are,you,A,1000;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A[1] ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A[2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "A[3];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 101 "There is one special sequence in Maple, namely the empty sequence , denoted by NULL. See what happens:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "A:=NULL,NULL,A,NULL;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 337 "Maple sequences are very handy. There is one small probl em though, and that is if you have a sequence with just 1 element, you can't really tell whether this was just an element, or a sequence whi ch happens to have just one element. Because of that, it is often more convenient to work with lists in Maple than with sequences. In Maple, " }{TEXT 257 52 "a list is a sequence with square brackets around it. " }{TEXT -1 50 " We can make a list of A by the following command:" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "A:=[A];" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 130 "We can again look at individual elements, A[1], A [2] and such. The following command tells you the number of elements i n the list:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(A);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A[15];" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 11 "A[nops(A)];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 170 "To get the last element, you can do A[nops(A)]; A shorter syn tax, which does exactly the same, is A[-1], which gives you the last e lement. A[-2] is the second last, etc." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A[-1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A[ -2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "A[-3];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 130 "The command seq can be used to do a cert ain computation on all elements of the list. For example, compute the \+ sequence of squares:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "seq (i^2, i=A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 23 "Or the list of squ ares:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "[seq(i^2, i=A)];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 266 "Or the set of squares. A set i n Maple is a sequence with curly brackets \{\} around it. Of course, i f you have elements that appear more than once, the extra ones will be removed, and also the order has no meaning for sets so the ordening o f the elements could change." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "\{seq(i^2, i=A)\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "We ca n use the A[-1], A[-2], construction to reverse the list:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "[ seq(A[-i], i=1..nops(A)) ];" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 258 "We have seen how you can convert \+ a sequence to a list, with [ ], or to a set, with \{\}. The converse i s also possible. You can remove the [ ] or the \{ \} brackets by the o p command. This is also useful if you want to convert a list to a set \+ or a set to a list." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "B:=op(A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "C:=\{op(A)\};" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 17 "nops(A), nops(C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "nops([B]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 444 "As you can see, w e converted list A to a sequence B, and to a set C. Since C had fewer \+ elements than A, we can see that A must have elements that appear more than once. Note that nops does not work for a sequence, but it does w ork for lists and sets. So, to count the number of elements in a seque nce, we have to put brackets [ ] around it before we can count with no ps. Given a list, we can compute sublists as follows, using the double dot .." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "A[1..1];" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "A[1..4];" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 9 "A[1..-1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A[-3..-1];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A[13..15];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A[13..-1] ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "A[-3..15];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "C[1..4];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "C minus C[1..4];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 55 "The commands minus and union can only be used for sets." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "B;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "B[4 ..6];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 153 "We have seen before tha t if you have an expression involving a variable x, you can replace x \+ by something else with a subs. How to do that for sequences?" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "P;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "subs(x=0,P);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "subs(x=1,P);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "subsop(1=Hi,A); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 152 "Note that this subsop command doesn't actually ch ange A, it just returns A with its first entry replaced by Hi. To chan ge A we have to do an assignment:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "A := subsop(1=Hi,A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "A := subsop(2=there, A);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 22 "A := subsop(3=fox, A);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 21 "A:=subsop(4=NULL, A);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(A);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 154 "Here I replaced entry A[4] by the empty sequence NULL, so this is the way \+ you can remove an entry from a list. For sets there are different ways to do it." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "subs(hello=NULL,C);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "C;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "C minus \{hello\};" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "\{hello,Hello\} minus C;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 249 "In Maple, the variable Hello is different from hello, so lower case and upper case, that makes a difference. As another exampl e of sets, lets compute all numbers that are a square of a positive in teger <= 100, and that are also a sum of two squares:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "squares:=\{seq(i^2,i=1..100)\}:" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "sum_squares := \{ seq(seq( \+ i+j ,i=squares),j=squares) \}:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 200 "I used a colon instead of semi-colon to end the command, to preve nt Maple from printing lots of numbers. To find the answer to the ques tion, we will have to compute the intersection of those two sets:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "squares intersect sum_square s;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 120 "We want to sort this set s o it's easier to read. However, sets don't have an order. To sort it w e should make it a list:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "[op(squares intersect sum_squares)];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "sort( % );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 166 "T he percentage sign % in Maple V release 5 refers to the last thing Map le evaluated. And %% means the one before that, and %%% the one before that (there is no %%%%)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "a:=1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "b:=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "c:=3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "d:=4;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "%%; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 54 "At this point, the second las t is no longer 3, it's 4." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "%%;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "a;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "b;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "c;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "%%%;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "%%%;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "%%%;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "a;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "b;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "c;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "%;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "%%%;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "0 2 0" 41 } {VIEWOPTS 1 1 0 1 1 1803 }