{VERSION 6 0 "SGI MIPS UNIX" "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 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 257 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 258 "" 0 1 0 0 0 0 1 0 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 "" 0 1 0 0 0 0 1 0 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 1 0 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 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 266 "" 0 1 0 0 0 0 1 0 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 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 270 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 271 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 0 0 -1 0 }{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" 7 9 1 {CSTYLE "" -1 -1 "" 0 1 64 128 64 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 "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 11 12 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plot" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "T itle" 0 18 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 1 0 0 0 0 0 0 1 }3 0 0 -1 12 12 0 0 0 0 0 0 19 0 }{PSTYLE "" 0 256 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 46 "MAPLE Notes for MACM 442 \+ / MATH 800 / CMPT 881" }}}{EXCHG {PARA 256 "" 0 "" {TEXT -1 133 "Micha el Monagan\nDepartment of Mathematics\nSimon Fraser University\nAugust , 1998.\nUpdated August 2002, September 2004, September 2006." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 216 "These notes are for Maple V Release 10. They are platform independent, i.e., they are the same for the Macintosh, PC, \+ and Unix versions of Maple. These notes should be backwards compatibl e with Maple 8 and Maple 9." }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 21 "M aple as a Calculator" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 141 "Input of \+ a numerical calculation uses +, -, *, /, and ^ for addition, subtracti on, multiplication, division, and exponentiation respectively." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "1+2*3-2;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "2^3; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\")" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "120/105;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6##\"\")\" \"(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 252 "Because the input involve d integers, not decimal numbers, Maple calculates the exact fraction w hen there is a division, automatically cancelling out the greatest com mon divisor (GCD). In this case the GCD is 15, which you can calculat e specifically as" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "igcd(1 20,105);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#:" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 230 "Observe that every command ends with a semicolon \+ ; This is a gramatical requirement of Maple. If you forget, Maple w ill assume that the comand is not complete. This allows you to break \+ long commands across a line. For example" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 6 "1+2*3/" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "(2+3);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6##\"#6\"\"&" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 237 "For some analysis with probabilities, we will need to \+ use decimal arithmetic. The presence of a decimal point . in a numbe r means that the number is a decimal number and Maple will, by default , do all calculations to 10 decimal places." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "120/105.0;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"+ Vr&G9\"!\"*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "sqrt(2.0);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"+iN@99!\"*" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "sqrt(2);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#*$ \"\"##\"\"\"F$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 135 "Notice the dif ference caused by the presence of a decimal point in these examples. \+ Now, if you have input an exact quantity, like the " }{XPPEDIT 18 0 "s qrt(2);" "6#-%%sqrtG6#\"\"#" }{TEXT -1 186 " above, and you now want \+ to get a numerical value to 3 decimal digits, use the evalf command to evaluate to floating point. Use the % character to refer to the prev ious Maple output. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "eva lf(%,3);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"$T\"!\"#" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 44 "To input a formula, just use a symbol, e. g. " }{XPPEDIT 18 0 "x;" "6#%\"xG" }{TEXT -1 107 " and the arithmetic \+ operators and functions known to Maple. For example, here is a quarti c polynomial in " }{XPPEDIT 18 0 "x;" "6#%\"xG" }{TEXT -1 2 " ." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "x^4-3*x+2;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,(*$)%\"xG\"\"%\"\"\"F(*&\"\"$F(F&F(!\"\"\"\"#F(" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 89 "We are going to use this polynomi al for a few calculations. We want to give it the name " }{XPPEDIT 18 0 "f;" "6#%\"fG" }{TEXT -1 92 " so we can refer to it later. We do this using the assignment operation in Maple as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "f := x^4-3*x+2;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%\"fG,(*$)%\"xG\"\"%\"\"\"F**&\"\"$F*F(F*!\"\"\"\"#F *" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 9 "The name " }{XPPEDIT 18 0 "f; " "6#%\"fG" }{TEXT -1 69 " is now a variable. It refers to the polyno mial. Here is it's value" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "f;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,(*$)%\"xG\"\"%\"\"\"F(*&\"\"$F (F&F(!\"\"\"\"#F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 44 "To evaluate \+ this as a function at the point " }{XPPEDIT 18 0 "x = 3;" "6#/%\"xG\" \"$" }{TEXT -1 32 " use the eval command as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "eval(f,x=3);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#u" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 37 "The follow ing commands differentiate " }{TEXT 257 2 "f " }{TEXT -1 16 "with resp ect to " }{TEXT 258 2 "x " }{TEXT -1 11 "and factor " }{TEXT 256 1 "f " }{TEXT -1 61 " into irreducible factors over the field of rational n umbers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "diff(f,x);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#,&*&\"\"%\"\"\")%\"xG\"\"$F&F&F)!\"\" " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "factor(f);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#*&,&%\"xG\"\"\"F&!\"\"F&,**$)F%\"\"$F&F&*$)F%\" \"#F&F&F%F&F.F'F&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 79 "You can grap h functions using the plotting commands. The basic syntax for the " } {TEXT 259 4 "plot" }{TEXT -1 67 " command for a function of one variab le is illustrated as follows: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "plot(f,x=0.5..1.5);" }} {PARA 13 "" 1 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "In the graph I can see a local minimum near x=0.9. We can find this \+ point using calculus. The command " }{TEXT 306 6 "fsolve" }{TEXT -1 40 "( f(x)=0, x ), on input of a polynomial " }{TEXT 307 4 "f(x)" } {TEXT -1 66 " computes 10 digit numerical approximations for the real \+ roots of " }{TEXT 308 4 "f(x)" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "fsolve(diff(f,x)=0,x);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"+kHg&3*!#5" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 172 " We have used the name f as variable to refer to formulae and the symbo ls x for an uknown in a formula. Often you will have assigned to a name like we have done here to " }{XPPEDIT 18 0 "f;" "6#%\"fG" } {TEXT -1 34 " but you want now to use the name " }{XPPEDIT 18 0 "f;" " 6#%\"fG" }{TEXT -1 87 " as a symbol again, not as a variable. You can unassign the value of a name as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "f;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,(*$)%\"xG\"\"% \"\"\"F(*&\"\"$F(F&F(!\"\"\"\"#F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "f := 'f';" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGF$ " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "f;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%\"fG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 119 "To find \+ out how to use Maple commands, such as plot, factor, eval, and diff, g o to the Maple help page by typing ?plot" }}{PARA 0 "" 0 "" {TEXT -1 112 "and look at the examples. Do this now if you are using Maple for the first time. You will get a \"help window\"." }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 5 "?eval" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "?plot" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "?diff" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "?fsolve" }}}{EXCHG }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 8 "Integers" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 363 "Here are some c ommands which do integer calculations that we will use in the course. \+ Integers in Maple are not limited to the precision of the hardware on your computer. They are limited by an internal limit of Maple to app roximately half a million digits. Any calculations that you do with l arge integers though will take longer for larger integers. Here is " }{XPPEDIT 18 0 "2^100;" "6#*$\"\"#\"$+\"" }{TEXT -1 2 " ." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "2^100;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"@w`?.n\\,%H#G-g]wE\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 156 " The command irem(a,b) computes the integer remainder of a divided by b . The command iquo(a,b) computes the integer quotient of a divided by b. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "a := 20 ;\nb := 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"aG\"#?" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%\"bG\"\"(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "r := irem(a,b);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"rG\"\"'" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "q := iquo(a,b) ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG\"\"#" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 28 "It should be the case that " }{TEXT 260 12 "a = b q + r " }{TEXT -1 14 ". Let's check" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "a = b*q + r;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"#? F$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 134 "The commands igcd(a,b) and ilcm(a,b) compute the greatest common divisor and least common multip le of integers a and b, respectively. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "igcd(6,4);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "ilcm(6,4);" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#\"#7" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "The command " }{TEXT 261 6 "igcdex" }{TEXT -1 1 "(" }{TEXT 262 11 "a,b,' s','t'" }{TEXT -1 12 ") outputs " }{XPPEDIT 18 0 "g = GCD(a,b);" "6# /%\"gG-%$GCDG6$%\"aG%\"bG" }{TEXT -1 21 " . It also assigns " } {XPPEDIT 18 0 "s,t;" "6$%\"sG%\"tG" }{TEXT -1 35 " integers satisfyin g the equation " }{XPPEDIT 18 0 "s*a+t*b = g;" "6#/,&*&%\"sG\"\"\"%\"a GF'F'*&%\"tGF'%\"bGF'F'%\"gG" }{TEXT -1 17 " and satisfying " } {XPPEDIT 18 0 "abs(s) < abs(b);" "6#2-%$absG6#%\"sG-F%6#%\"bG" }{TEXT -1 6 " and " }{XPPEDIT 18 0 "abs(t) < abs(a);" "6#2-%$absG6#%\"tG-F%6 #%\"aG" }{TEXT -1 77 " . So this command implements the extended Eucl idean algorithm. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "g := igcdex(3,5,'s','t');" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"gG\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "s;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "t;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#!\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "s*3+t*5;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# \"\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 263 7 "isprime" }{TEXT -1 1 "(" }{TEXT 264 1 "n" }{TEXT -1 19 ") outpu ts false if " }{TEXT 265 1 "n" }{TEXT -1 26 " is composite and true if " }{TEXT 266 1 "n" }{TEXT -1 25 " is prime. \nThe command " }{TEXT 267 7 "ifactor" }{TEXT -1 1 "(" }{TEXT 268 1 "n" }{TEXT -1 53 ") compu tes the integer factorization of an integer. " }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 13 "isprime(997);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%trueG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "isprime(1001) ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%&falseG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ifactor(1001);" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#*(-%!G6#\"\"(\"\"\"-F%6#\"#6F(-F%6#\"#8F(" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 78 "For the RSA cryptosystem we need large primes, 100 digi t primes. The command " }{TEXT 305 9 "nextprime" }{TEXT -1 71 "(n) ou tputs the first prime greater than or equal to n and the command " } {TEXT 309 9 "prevprime" }{TEXT -1 86 "(n) finds the first prime less t han or equal to n. Here is the first 100 digit prime." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "prevprime(10^100);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"_q.#******************************************** *****************************************************" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 420 "Several of the cryptosystems require tha t we generate random primes, or primes with certain properties. This \+ needs to be done with some care. For example, the prime we just gene rated is not a good prime simply because of the way we created it. We need a random prime. Note, Maple's random number generator rand(...) is a \"pseudo-random-number-generator\". It will always create the s ame sequence of random numbers. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "R := rand(0..10^10-1);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"RGf*6\"F&F&F&-f*F&F&6#%(builtinGF&\"$\"RF&F&F&%%FAILG6%\"\"' \",+++++\"\"#MF&F&F&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 116 "So R is \+ the random number generator. It's a Maple procedure. You call it wi th no arguments to get random numbers." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "R();" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"*-$p=e" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "R();" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"+\"Rb7;%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "For \+ a list of integer commands see" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "?integer" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 0 {PARA 3 "" 0 "" {TEXT -1 5 "Lists" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 226 "The simplest data structure in Maple is a list. The ele ments of a list may be of any type. To create a list of values enclo se them in square brackets [, ]. Lists may be nested of course and th e entries may be of any type. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "restart;\n" }}}{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 23 "M := [[1,2,3],[x,y,z]];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"MG7$7%\"\"\"\"\"#\"\"$7%%\"xG%\"yG%\"zG " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "To count the number of entrie s in a list use nops(L) command." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"&" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "nops(M);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 114 "To acces s the i'th element of a list (counting from 1) use a subscript. A neg ative subscript counts from the end." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "L[3];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#!\"$" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "L[-1];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "M[2 ];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7%%\"xG%\"yG%\"zG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "M[2][2];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%\"yG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "Use the f ollowing 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 following. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "op(L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'\"\"\"\"\"#!\"$\"\"%F#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "[op(L),5];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7(\"\" \"\"\"#!\"$\"\"%F$\"\"&" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "To tes t if an element is in a list use" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "member(2,L);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%tru eG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 5 "Loops" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 " restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 232 "To do a sequence of \+ calculations it will be handy to know how to use some of Maple's loopi ng commands and also the if command. To execute a command in Maple co nditionally use the if command which has either of the following forms \n\n" }{TEXT 279 4 " " }{TEXT 286 2 "if" }{TEXT 287 13 " " }{TEXT 280 4 "then" }{TEXT 288 14 " " }{TEXT 281 4 "e lse" }{TEXT 289 14 " " }{TEXT 282 2 "fi" }{TEXT 290 1 "\n " }{TEXT -1 14 "\nor just\n\n " }{TEXT 283 2 "if" }{TEXT 291 13 " < condition> " }{TEXT 284 4 "then" }{TEXT 292 14 " " } {TEXT 285 3 "fi\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "if 2>1 then print(good) else print(bad) fi;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%goodG" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "To execute one or \+ more statements zero or more times in a loop use the for command. It \+ has the following form\n\n" }{TEXT 272 4 " " }{TEXT 293 3 "for" } {TEXT 294 12 " " }{TEXT 273 4 "from" }{TEXT 295 9 " " }{TEXT 274 2 "to" }{TEXT 296 7 " " }{TEXT 275 2 "do" }{TEXT 297 14 " " }{TEXT 276 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 "" {TEXT -1 93 "To execute some statements while a condition is true use the while loop. It has the syntax\n\n" }{TEXT 269 4 " " } {TEXT 298 5 "while" }{TEXT 299 13 " " }{TEXT 270 2 "do" } {TEXT 300 14 " " }{TEXT 271 3 "od " }{TEXT 301 2 "\n\n" } {TEXT -1 80 "In the following example we repeatedly divide an integer \+ n by 2 until it is odd." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 " n := 12; while irem(n,2) = 0 do n := iquo(n,2); od;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%\"nG\"#7" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG \"\"'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"\"$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 52 "Here is a loop to calculate the GCD of two inte gers " }{XPPEDIT 18 0 "a;" "6#%\"aG" }{TEXT -1 5 " and " }{XPPEDIT 18 0 "b;" "6#%\"bG" }{TEXT -1 110 " using Euclid's algorithm. Notice tha t this loop has three statements in the body of the loop - between the " }{TEXT 277 3 "do " }{TEXT -1 4 "... " }{TEXT 278 2 "od" }{TEXT -1 111 ", each of which is terminated by a semicolon. You don't have to \+ put them on the same line as I have done here." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 17 "a := 64; b := 20;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"aG\"#k" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"bG\"# ?" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "while b <> 0 do" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 " r := irem(a,b); a := b; b := r; " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "od;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"aG\" #?" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"bG\"\"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"aG\" \"%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"bG\"\"!" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 52 "Thus 4 should be the GCD(64,20). A check with Ma ple" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "igcd(64,20);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 44 "Two other useful looping constructs are the " }{TEXT 340 3 "map" }{TEXT -1 17 " command and the " }{TEXT 341 3 "seq" }{TEXT -1 50 " 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 17 "seq( f(n), n=L );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'-%\"fG6#\"\"\"-F$6#\"\"#-F$6#\"\"$-F$6#\"\"%-F$6#\" \"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "seq( isprime(n), n=L );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6'%&falseG%%trueGF$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 "" {TEXT -1 60 "Read the help files for these comm ands, they 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 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 18 "Modular Arithmetic" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 129 "Modu lar arithmetic is done using the mod operator in Maple. By default, Maple uses the positive range for the integers modulo " }{XPPEDIT 18 0 "m;" "6#%\"mG" }{TEXT -1 49 ", that is, the result is calculated in \+ the range " }{XPPEDIT 18 0 "0 .. m-1;" "6#;\"\"!,&%\"mG\"\"\"F'!\"\"" }{TEXT -1 2 ". " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "12 mod 7;" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#\"\"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "2+3*3 mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 11 "To compute " }{XPPEDIT 18 0 "a^(-1);" "6# )%\"aG,$\"\"\"!\"\"" }{TEXT -1 4 "mod " }{XPPEDIT 18 0 "m;" "6#%\"mG" }{TEXT -1 36 ", you can do either of the following" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "2^(-1) mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "1/2 mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 11 "To compute " }{XPPEDIT 18 0 "a^n;" "6#)%\"aG%\"nG" } {TEXT -1 5 " mod " }{XPPEDIT 18 0 "m;" "6#%\"mG" }{TEXT -1 18 " you ca n do either" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "2 ^ 200 mod \+ 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "2 &^ 200 mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #\"\"%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 71 "Use the latter. The di fference is that in the first case, the integer " }{XPPEDIT 18 0 "2^20 0;" "6#*$\"\"#\"$+#" }{TEXT -1 34 " was computed then reduced modulo \+ " }{XPPEDIT 18 0 "m;" "6#%\"mG" }{TEXT -1 57 " . In the second case, \+ all products were reduced modulo " }{XPPEDIT 18 0 "m;" "6#%\"mG" } {TEXT -1 31 " so no large integers occured." }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 77 "We will use a loop to verify that Fermat's (little) the orem holds for p = 7." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "p := 7;\nfor i from 0 to p-1 do (i^p mod p) = i od;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%\"pG\"\"(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"! F$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"\"F$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"#F$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"$F$" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"%F$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"&F$" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/\"\"'F$" } }}{EXCHG }{EXCHG {PARA 0 "" 0 "" {TEXT -1 67 "We can solve equations a nd systems of equations modulo n using the " }{TEXT 382 6 "msolve" } {TEXT -1 9 " command." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "ms olve( 6*x=4, 13 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<#/%\"xG\"\"&" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "msolve( 6*x=4, 26 );" }} {PARA 11 "" 1 "" {XPPMATH 20 "6$<#/%\"xG\"\"&<#/F%\"#=" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "msolve( \{24*a+b=5, 4*a+b=9, 18*a+b =1\}, 26 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#<$/%\"aG,&\"#=\"\"\"*& \"#8F(%%_Z2|irGF(F(/%\"bG\"#:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 " The variable _Z2~ means any integer so the solutions are \{b = 15, a = 18\} and \{b = 15, a = 5\}." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 13 "Number Theory" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 110 "Some relevant integer functions \+ are available in the number theory package.\nThis shows how to load a \+ package." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "restart;\nwith( numtheory);" }}{PARA 7 "" 1 "" {TEXT -1 69 "Warning, the protected nam e order has been redefined and unprotected\n" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#7Q%&GIgcdG%)bigomegaG%&cfracG%)cfracpolG%+cyclotomicG%) divisorsG%)factorEQG%*factorsetG%'fermatG%)imagunitG%&indexG%/integral _basisG%)invcfracG%'invphiG%*issqrfreeG%'jacobiG%*kroneckerG%'lambdaG% )legendreG%)mcombineG%)mersenneG%(migcdexG%*minkowskiG%(mipolysG%%mlog G%'mobiusG%&mrootG%&msqrtG%)nearestpG%*nthconverG%)nthdenomG%)nthnumer G%'nthpowG%&orderG%)pdexpandG%$phiG%#piG%*pprimrootG%)primrootG%(quadr esG%+rootsunityG%*safeprimeG%&sigmaG%*sq2factorG%(sum2sqrG%$tauG%%thue G" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 339 3 " phi" }{TEXT -1 13 "(n) computes " }{XPPEDIT 18 0 "phi(n);" "6#-%$phiG6 #%\"nG" }{TEXT -1 40 " , the number of integers between 1 and " } {TEXT 321 1 "n" }{TEXT -1 21 " relatively prime to " }{TEXT 322 1 "n" }{TEXT -1 54 ". \nNote this command is expensive because it factors \+ " }{TEXT 320 1 "n" }{TEXT -1 1 "." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "phi(15);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\")" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 379 8 "mcombi ne" }{TEXT -1 65 "(m1,u1,m2,u2) does Chinese remaindering to calculate the integer " }{XPPEDIT 18 0 "u;" "6#%\"uG" }{TEXT -1 12 " satisfying " }{XPPEDIT 18 0 "u = `mod`(u[i],m[i]);" "6#/%\"uG-%$modG6$&F$6#%\"iG &%\"mG6#F*" }{TEXT -1 7 " , for " }{XPPEDIT 18 0 "i = 1 .. 2;" "6#/%\" iG;\"\"\"\"\"#" }{TEXT -1 14 ". For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "u := mcombine(5,4,7,3);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"uG\"#C" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "u mod 5;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "u mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# \"\"$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "The command " }{TEXT 310 5 "msqrt" }{TEXT -1 32 "(x,n) computes a square root of " }{TEXT 311 1 "x" }{TEXT -1 8 " modulo " }{TEXT 312 1 "n" }{TEXT -1 69 " if it exists and outputs FAIL otherwise. Note this command factors " } {TEXT 313 1 "n" }{TEXT -1 30 " so this is also expensive if " }{TEXT 314 1 "n" }{TEXT -1 15 " is not prime. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "p := 11;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"pG\"#6 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "msqrt(2,p);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%%FAILG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "msqrt(3,p);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"& " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "5^2 mod p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "T he command " }{TEXT 319 4 "mlog" }{TEXT -1 44 "(x,m,n) computes the di screte logarithm of " }{TEXT 316 1 "x" }{TEXT -1 6 " base " }{TEXT 317 1 "m" }{TEXT -1 8 " modulo " }{TEXT 318 1 "n" }{TEXT -1 13 ", i.e. finds " }{TEXT 315 2 "y " }{TEXT -1 10 "such that " }{XPPEDIT 18 0 "` mod`(y^m,n) = x;" "6#/-%$modG6$)%\"yG%\"mG%\"nG%\"xG" }{TEXT -1 138 " \+ . Note this command is expensive. Like integer factorization, no pol ynomial time algorithm is known for the discrete logarithm problem." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "x := 2 &^ 5 mod p;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"#5" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 12 "mlog(x,2,p);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\" \"&" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 7 "Strings" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 64 "A string is input as text inside \" (string) quotes. For example" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "restart;\nA := \"hello\";\nB := \"there\";" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"AGQ&hello6\"" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"BGQ&there6\"" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 49 "The number of characters in a string is given by \+ " }{TEXT 387 6 "length" }{TEXT -1 4 "(s)." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 10 "length(A);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"& " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 82 "The empty string is \"\". To access the i'th character from a string use A[i], e.g." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "A[1]; A[2];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"h6\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"e6\"" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 114 "Negative subscripts count from th e end of the string where position -1 refers to the last character in \+ the string." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "A[-1]; A[-2] ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"o6\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q\"l6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 102 "If A i s a string the notation A[i..j] selects the substring of characters fr om position i to j from A." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "A[1..2]; A[-2..-1];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q#he6\"" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#Q#lo6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 384 3 "cat" }{TEXT -1 41 "(s1,s2,... ,sn) joins n strings together." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "cat(A,\" \",B);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q,hello~the re6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 4 "The " }{TEXT 386 4 "seq \+ " }{TEXT -1 116 "command can be used to extract the sequence of charac ters from a string and we can put them back together using the " } {TEXT 385 3 "cat" }{TEXT -1 9 " command." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "C := seq( A[i], i=1..length(A) );" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%\"CG6'Q\"h6\"Q\"eF'Q\"lF'F)Q\"oF'" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "cat( C );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q&hello6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Here is how you \+ would extract all trigrams from a string." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 35 "seq( A[i..i+2], i=1..length(A)-2 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%Q$hel6\"Q$ellF$Q$lloF$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "There is more if you need it. See" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 7 "?string" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "?StringTools" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "wit h(StringTools):" }}{PARA 7 "" 1 "" {TEXT -1 58 "Warning, the assigned \+ name Group now has a global binding\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "A;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q&hello6\"" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "Search(\"l\",A);\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "SearchAll(\"l\",A);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6$\"\"$\" \"%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 57 "Hence the frequency of the letter \"l\" in the string A is " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "nops([SearchAll(\"l\",A)]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }} }}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 30 "Maple Functions and Procedures " }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 115 "A simple function, like the f unction ek(x) = a*x+b mod n may be input using the arrow notation in M aple, as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "ek := x -> 3*x+5 mod 26;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#ekGf*6#%\"xG6 \"6$%)operatorG%&arrowGF(-%$modG6$,&*&\"\"$\"\"\"9$F2F2\"\"&F2\"#EF(F( F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ek(1); ek(7);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\")" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"!" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "We create the inverse function" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "1/3*(y-5) mod \+ 26;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,&*&\"\"*\"\"\"%\"yGF&F&\"\"(F& " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "dk := y -> 9*y+7 mod 26 ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#dkGf*6#%\"yG6\"6$%)operatorG%& arrowGF(-%$modG6$,&*&\"\"*\"\"\"9$F2F2\"\"(F2\"#EF(F(F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "dk(8); dk(0);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"(" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 124 "So if we have encoded some text \+ \"BUYIBM\" as a list of integers [1,20,24,8,1,12] we can encrypt it an d decrypt it as follows." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "plaintext := [1,20,24,8,1,12];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%* plaintextG7(\"\"\"\"#?\"#C\"\")F&\"#7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "ciphertext := map(ek,plaintext);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%+ciphertextG7(\"\")\"#8\"#D\"\"$F&\"#:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "map(dk,ciphertext);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#7(\"\"\"\"#?\"#C\"\")F$\"#7" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 153 "For the Hill cipher, we which takes two inputs x1 a nd x2 and outputs two outputs y1 and y2 we will use a Maple procedure \+ rather than the arrow functions." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "A procedure in Maple takes the form\n\n " }{TEXT 323 4 " " } {TEXT 324 4 "proc" }{TEXT 325 21 "( p1, p2, ... )\n " }{TEXT 326 5 "local" }{TEXT 327 20 " l1, l2, ... ;\n " }{TEXT 328 6 "global" }{TEXT 329 23 " g, g2, ... ;\n " }{TEXT 332 10 "statement1" } {TEXT 333 11 ";\n " }{TEXT 334 10 "statement2" }{TEXT 335 25 " ;\n ....\n " }{TEXT 336 11 " statementn" }{TEXT 337 5 ";\n " }{TEXT 330 10 " end proc" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 409 "There may be zero or more parameters, on e or more locals, one or more globals and one or more statements in th e procedure body.\nThe local and global statements are optional. Vari ables in the procedure body that are not explicitly declared as parame ters, locals, or globals are declared to be local automatically if ass igned to, otherwise they are global. The value returned by the proced ure is the value of " }{TEXT 331 10 "statementn" }{TEXT -1 206 ", the \+ last statement in the body of the procedure or the value of an explici t return statement. Type declarations for parameters and local variab les need not be explicitly given. Some 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 "Warning, `y` is implicitly d eclared local to procedure `f`\n" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"fGf*6#%\"xG6#%\"yG6\"F*C$>8$*$)9$\"\"#\"\"\",&F-F2F2!\"\"F*F*F*" }}} {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(!\"\"" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 253 "This next example searches a st ring s for the letter x. It outputs the position of the first occurren ce of x in s and 0 otherwise. I am also telling Maple that the inputs should be of type string. Below is an example with inputs of type in teger. See " }{TEXT 383 5 "?type" }{TEXT -1 76 " for how to specify t ypes and for what types are available if you need them." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 157 "position := proc(x::string,s::stri ng) local i;\n for i from 1 to length(s) do if s[i]=x then return i \+ fi; od;\n 0; # meaning x is not in the list\nend proc;" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%)positionGf*6$'%\"xG%'stringG'%\"sGF)6#%\"iG6 \"F.C$?(8$\"\"\"F2-%'lengthG6#9%%%trueG@$/&F66#F19$OF1\"\"!F.F.F." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "position(\"U\",\"BUYIBM\"); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"#" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 23 "position(\"V\",\"BUYIBM\");" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"!" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "pos ition(5,\"BUYIBM\");" }}{PARA 8 "" 1 "" {TEXT -1 111 "Error, (in posit ion) invalid input: position expects its 1st argument, x, to be of typ e string, but received 5\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 130 "Ok ay, now let's code the Hill cipher. It is a function of two arguments x1 and x2 (integers) and it outputs two values y1 and y2." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 110 "e := proc(x1,x2) local y1,y2;\n \+ y1 := 11*x1+3*x2 mod 26;\n y2 := 8*x1+7*x2 mod 26;\n (y1,y2); \nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "x := plainte xt;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG7(\"\"\"\"#?\"#C\"\")F&\" #7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "e(x[1],x[2]);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6$\"#>\"#=" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "ciphertext := [seq( e(x[2*i+1],x[2*i+2]), i=0..iquo(n ops(x),2)-1 )];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%+ciphertextG7(\"# >\"#=\"\"#\"#9\"#@F)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 111 "Now to d ecrypt we need the inverse of this function. We compute the inverse o f the corresponding matrix mod 26" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "A := Matrix([[11,3],[8,7]]);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"AG-%'RTABLEG6%\"*![x#p#-%'MATRIXG6#7$7$\"#6\"\"$7$ \"\")\"\"(%'MatrixG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "Inve rse(A) mod 26;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%'RTABLEG6%\"*Gzfp# -%'MATRIXG6#7$7$\"\"(\"#B7$\"#=\"#6%'MatrixG" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 149 "For the decryption function I'll use Maple's -> notati on instead of a procedure. Let's check that d is the inverse of e the n decrypt the ciphertext." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "d := (y1,y2) -> (7*y1+23*y2 mod 26, 18*y1+11*y2 mod 26);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"dGf*6$%#y1G%#y2G6\"6$%)operatorG%&arrowG F)6$-%$modG6$,&*&\"\"(\"\"\"9$F4F4*&\"#BF49%F4F4\"#E-F/6$,&*&\"#=F4F5F 4F4*&\"#6F4F8F4F4F9F)F)F)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "d(e(x1,x2));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6$%#x1G%#x2G" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "e(d(x1,x2));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6$%#x1G%#x2G" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "y := ciphertext;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"yG7(\" #>\"#=\"\"#\"#9\"#@F)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "[s eq( d(y[2*i+1],y[2*i+2]), i=0..2 )];" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#7(\"\"\"\"#?\"#C\"\")F$\"#7" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 68 " This last example is an implementation of the Euclidean algorithm." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 165 "EuclideanAlgorithm := pr oc(a::integer,b::integer) local c,d,r;\n (c,d) := (abs(a),abs(b)); \n while d <> 0 do r := irem(c,d); (c,d) := (d,r); od;\n c;\nend proc;" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%3EuclideanAlgorithmGf*6$'% \"aG%(integerG'%\"bGF)6%%\"cG%\"dG%\"rG6\"F0C%>6$8$8%6$-%$absG6#9$-F86 #9%?(F0\"\"\"F?F00F5\"\"!C$>8&-%%iremGF3>F36$F5FDF4F0F0F0" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "EuclideanAlgorithm(24,210);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 224 "Procedures may be nested, nested lexical scoping is used (a la Pascal). \nProcedures may be returned and passed freely as par ameters. \nThe simplest debugging tool is to insert print statements \+ in the procedure. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 175 "EuclideanAlgorithm := proc(a::integer,b::integer) local c,d,r ;\n (c,d) := (abs(a),abs(b));\n while d <> 0 do r := irem(c,d); \+ print(r); (c,d) := (d,r); od;\n c;\nend proc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "EuclideanAlgorithm(24,210);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#C" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#=" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 95 "The next simplest debugging tool is the trace comm and. All assigment statements are displayed." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "trace(EuclideanAlgorithm);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#%3EuclideanAlgorithmG" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "EuclideanAlgorithm(24,210);" }}{PARA 9 "" 1 "" {TEXT -1 45 "\{--> enter EuclideanAlgorithm, args = 24, 210" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>6$%\"cG%\"dG6$\"#C\"$5#" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG\"#C" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#C" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>6$%\"cG%\"dG6$\"$5#\"#C" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%\"rG\"#=" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\" #=" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>6$%\"cG%\"dG6$\"#C\"#=" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG\"\"'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>6$%\"cG%\"dG6 $\"#=\"\"'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>6$%\" cG%\"dG6$\"\"'\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}{PARA 9 "" 1 "" {TEXT -1 51 "<-- exit EuclideanAlgorithm (now at top level) \+ = 6\}" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 21 "There is more. See " }{TEXT 338 5 "?proc" }{TEXT -1 45 " if you need more information or more tools." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 38 "Subscripted Names and String Utilities" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 113 "Variables may be subscripted. For example, here is a po lynomial in x1,x2,x3. You can assign to the subscripts." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{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 178 "There may be more than one subscript and the subscripts may be an y value. For example, we may wish to record the numerical code for ea ch letter of an alphabet. We could do this" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "code[\"A\"] := 0;\ncode[\"B\"] := 1;" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>&%%codeG6#Q\"A6\"\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%%codeG6#Q\"B6\"\"\"\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "etc. Basically, code is now a table (a hash table) with two entries. We can access an entry as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "code[\"B\"];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "code[\"C\"];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#&%%codeG6#Q\"C6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 106 "So given the following alphabet we can define \+ the code of each letter in a loop. We also do the opposite." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "alphabet := \"ABCDEFGHIJKLMN OPQRSTUVWXYZ\";" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%)alphabetGQ;ABCDE FGHIJKLMNOPQRSTUVWXYZ6\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "N := length(alphabet);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"NG\"#E " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 89 "for i from 0 to N-1 do \+ \n x := alphabet[i+1];\n code[x] := i; \n char[i] := x;\n od: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 19 "We give procedures " }{TEXT 380 6 "encode" }{TEXT -1 5 " and " }{TEXT 381 6 "decode" }{TEXT -1 49 " to convert a string to a list of codes and back." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 79 "encode := proc(s::string) local i;\n [seq ( code[s[i]], i=1..length(s) )];\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 108 "decode := proc(x::list(integer)) local i,n;\n n := nops(x);\n cat( seq( char[x[i]], i=1..nops(x) ) );\nend:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "c := encode(\"BUYIBM\");" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"cG7(\"\"\"\"#?\"#C\"\")F&\"#7" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "decode(c);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#Q'BUYIBM6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 " We can use tables to count the frequency of each letter in a piece of \+ plaintext s as follows. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "s := \"THISISTHEDAYTHATTHELORDHASMADE\";" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"sGQ?THISISTHEDAYTHATTHELORDHASMADE6\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 73 "First we initialize the table entries to \+ 0. Then compute the frequencies" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 79 "F := table(): # create an empty table\nfor i from 0 t o 25 do F[char[i]] := 0 od:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "n := length(s);\nfor i to n do x := s[i..i]; F[x] := F[x]+1; od: \+ " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"#I" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 258 "Now we convert to a list and use the sort command t o sort in decreasing order. How to do this. We create a list of the f orm [ [x1,f1], [x2,f2], ... ] where each x is a letter and the f it's corresponding frequency then sort it then covert to probabilities." } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "T := [seq( [char[i],F[char [i]]], i=0..25)];" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%\"TG7<7$Q\"A6\" \"\"%7$Q\"BF(\"\"!7$Q\"CF(F,7$Q\"DF(\"\"$7$Q\"EF(F17$Q\"FF(F,7$Q\"GF(F ,7$Q\"HF(\"\"&7$Q\"IF(\"\"#7$Q\"JF(F,7$Q\"KF(F,7$Q\"LF(\"\"\"7$Q\"MF(F D7$Q\"NF(F,7$Q\"OF(FD7$Q\"PF(F,7$Q\"QF(F,7$Q\"RF(FD7$Q\"SF(F17$Q\"TF(F :7$Q\"UF(F,7$Q\"VF(F,7$Q\"WF(F,7$Q\"XF(F,7$Q\"YF(FD7$Q\"ZF(F," }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "sort(T, proc(x,y) if x[2]>y[ 2] then true else false fi end);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#7< 7$Q\"T6\"\"\"&7$Q\"HF&F'7$Q\"AF&\"\"%7$Q\"SF&\"\"$7$Q\"EF&F/7$Q\"DF&F/ 7$Q\"IF&\"\"#7$Q\"YF&\"\"\"7$Q\"RF&F97$Q\"OF&F97$Q\"MF&F97$Q\"LF&F97$Q \"ZF&\"\"!7$Q\"XF&FD7$Q\"WF&FD7$Q\"VF&FD7$Q\"UF&FD7$Q\"QF&FD7$Q\"PF&FD 7$Q\"NF&FD7$Q\"KF&FD7$Q\"JF&FD7$Q\"GF&FD7$Q\"FF&FD7$Q\"CF&FD7$Q\"BF&FD " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "q := [seq( char[i-1]=ev alf(T[i][2]/n,3), i=1..26 )];" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%\"q G7/Q\"UF(F./Q\"VF(F./Q\"WF(F./Q\"XF(F./Q\"YF(FK/Q\"ZF(F ." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 " " 0 "" {TEXT -1 29 "Polynomials and Finite Fields" }}{EXCHG {PARA 0 " " 0 "" {TEXT -1 94 "Polynomials in Maple are simply input as formulae \+ using the arithmetic operators. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "restart;\nx^4-3*x^2+12;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,(*$)%\"xG\"\"%\"\"\"F(*&\"\"$F()F&\"\"#F(!\"\"\"#7F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 33 "is a polynomial in one variable , " }{XPPEDIT 18 0 "x;" "6#%\"xG" }{TEXT -1 68 " with integer coeffici ents. Here is a polynomial in two variables. " }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 31 "a := (x-y)*(x^2-y^2)*(x^3-y^3);" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%\"aG*(,&%\"xG\"\"\"%\"yG!\"\"F(,&*$)F'\"\"#F(F (*$)F)F.F(F*F(,&*$)F'\"\"$F(F(*$)F)F4F(F*F(" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 68 "To multiply the factors of the polynomial out use the e xpand command" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "expand(a); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,.*$)%\"xG\"\"'\"\"\"F(*&)F&\"\"%F ()%\"yG\"\"#F(!\"\"*&F&F()F-\"\"&F(F(*&F-F()F&F2F(F/*&)F-F+F()F&F.F(F( *$)F-F'F(F/" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 92 "To factor the poly nomial into prime factors with integer coefficients use the factor com mand" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "factor(a);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#,$*(),&%\"yG\"\"\"%\"xG!\"\"\"\"$F(,&F 'F(F)F(F(,(*$)F'\"\"#F(F(*&F'F(F)F(F(*$)F)F0F(F(F(F*" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 77 "We will only need polynomials in one variable \+ and mostly work in the ring " }{TEXT 374 1 "Z" }{TEXT -1 2 "p[" } {TEXT 375 1 "x" }{TEXT -1 9 "] where " }{XPPEDIT 18 0 "p;" "6#%\"pG" }{TEXT -1 66 " will be a prime integer. In what follows we show opera tions for " }{TEXT 370 1 "Z" }{TEXT -1 2 "p[" }{TEXT 372 1 "x" }{TEXT -1 11 "] and also " }{TEXT 368 1 "Q" }{TEXT -1 1 "[" }{TEXT 369 1 "x" }{TEXT -1 88 "]. For help for operations for polynomials see ?polynomi al. For help for operations in " }{TEXT 371 1 "Z" }{TEXT -1 2 "p[" } {TEXT 373 1 "x" }{TEXT -1 36 "] see ?mod.\nHere are two polynomials" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "a := 2*x^6-3*x^5+3*x+3;" } }{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"aG,**&\"\"#\"\"\")%\"xG\"\"'F(F(* &\"\"$F()F*\"\"&F(!\"\"*&F-F(F*F(F(F-F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "b := 3*x^4-4*x^3+1;" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#>%\"bG,(*$)%\"xG\"\"%\"\"\"\"\"$*&F)F*)F(F+F*!\"\"F*F*" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 376 4 "eval" }{TEXT -1 67 "( a(x), x=k ) evaluates the polynomial a(x) at x = k. The comm and " }{TEXT 377 4 "Eval" }{TEXT -1 11 "( a, x=k ) " }{TEXT 378 3 "mod " }{TEXT -1 36 " p does this modulo p . For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "eval( a, x=2 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"#T" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "Eval ( a, x=2 ) mod 7;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"'" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 76 "Here is how we can tabulate the values of this polynomial for all values in " }{XPPEDIT 18 0 "Z[7];" "6#&%\"ZG6 #\"\"(" }{TEXT -1 39 ". We conclude that a(x) has no roots. " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "seq( Eval(a,x=i) mod 7, i=0. .6 );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6)\"\"$\"\"&\"\"'F%\"\"%F&F$" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 59 "We can interpolate a polynomial \+ from it's values as follows" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "a;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,**&\"\"#\"\"\")%\"xG\"\"'F&F &*&\"\"$F&)F(\"\"&F&!\"\"*&F+F&F(F&F&F+F&" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 21 "X := [seq(i,i=0..8)];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"XG7+\"\"!\"\"\"\"\"#\"\"$\"\"%\"\"&\"\"'\"\"(\"\")" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "Y := [seq( eval(a,x=i), i=0. .8 )];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"YG7+\"\"$\"\"&\"#T\"$T( \"%N^\"&$*=#\"&0+(\"',\\=\"'6gU" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "interp(X,Y,p);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,**&\"\"#\" \"\")%\"pG\"\"'F&F&*&\"\"$F&)F(\"\"&F&!\"\"*&F+F&F(F&F&F+F&" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "The command " }{TEXT 342 6 "expan d" }{TEXT -1 1 "(" }{TEXT 347 3 "a*b" }{TEXT -1 30 ") multiplies out \+ the product " }{XPPEDIT 18 0 "a*b;" "6#*&%\"aG\"\"\"%\"bGF%" }{TEXT -1 15 ". The command " }{TEXT 343 6 "Expand" }{TEXT -1 1 "(" }{TEXT 346 3 "a*b" }{TEXT -1 2 ") " }{TEXT 344 3 "mod" }{TEXT -1 1 " " } {TEXT 345 1 "p" }{TEXT -1 25 " does the product modulo " }{XPPEDIT 18 0 "p;" "6#%\"pG" }{TEXT -1 75 ", that is, all coefficients in the resu lting polynomial are reduced modulo " }{XPPEDIT 18 0 "p;" "6#%\"pG" } {TEXT -1 15 " . For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "p := 5;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"pG\"\"&" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "expand(a*b);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,4*$)%\"xG\"#5\"\"\"\"\"'*&\"# " 0 "" {MPLTEXT 1 0 18 "Expand(a*b) mod p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6 #,4*$)%\"xG\"#5\"\"\"F(*&\"\"$F()F&\"\"*F(F(*&\"\"#F()F&\"\"'F(F(*&F.F ()F&\"\")F(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 15 "The operations " } {TEXT 348 3 "rem" }{TEXT -1 12 "(a,b,x) and " }{TEXT 349 3 "quo" } {TEXT -1 45 "(a,b,x) compute, respectively, the remainder " }{XPPEDIT 18 0 "r;" "6#%\"rG" }{TEXT -1 14 " and quotient " }{XPPEDIT 18 0 "q;" "6#%\"qG" }{TEXT -1 4 " of " }{XPPEDIT 18 0 "a;" "6#%\"aG" }{TEXT -1 11 "divided by " }{XPPEDIT 18 0 "b;" "6#%\"bG" }{TEXT -1 12 " satisfyi ng " }{XPPEDIT 18 0 "a = b*q+r;" "6#/%\"aG,&*&%\"bG\"\"\"%\"qGF(F(%\"r GF(" }{TEXT -1 7 " with " }{XPPEDIT 18 0 "r = 0;" "6#/%\"rG\"\"!" } {TEXT -1 4 " or " }{XPPEDIT 18 0 "deg(r) < deg(b);" "6#2-%$degG6#%\"rG -F%6#%\"bG" }{TEXT -1 36 ". The corresponding operations for " } {XPPEDIT 18 0 "Z[p];" "6#&%\"ZG6#%\"pG" }{TEXT -1 5 " are " }{TEXT 352 3 "Rem" }{TEXT -1 8 "(a,b,x) " }{TEXT 353 3 "mod" }{TEXT 350 1 " \+ " }{TEXT -1 8 "p and " }{TEXT 354 3 "Quo" }{TEXT -1 8 "(a,b,x) " } {TEXT 355 3 "mod" }{TEXT -1 17 " p . For example" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 16 "r := rem(a,b,x);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG,*#\"#&)\"#F\"\"\"*&#\"#G\"\"*F)%\"xGF)F)*&#\"\"# \"\"$F)*$)F.F1F)F)!\"\"*&#\"#;F(F)*$)F.F2F)F)F5" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 16 "q := quo(a,b,x);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG,(*$)%\"xG\"\"#\"\"\"#F)\"\"$*&#F*\"\"*F*F(F*!\"\"#\"\"%\" #FF0" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "expand( a = b*q+r ) ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/,**$)%\"xG\"\"'\"\"\"\"\"#*&\"\" $F))F'\"\"&F)!\"\"*&F,F)F'F)F)F,F)F$" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "r := Rem(a,b,x) mod p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"rG,(*$)%\"xG\"\"$\"\"\"\"\"#*$)F(F+F*F**&F+F*F(F*F*" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "q := Quo(a,b,x) mod p;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"qG,(*$)%\"xG\"\"#\"\"\"\"\"%F(F*\" \"$F*" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "Expand( a = b*q+r \+ ) mod p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/,**$)%\"xG\"\"'\"\"\"\"\" #*&F*F))F'\"\"&F)F)*&\"\"$F)F'F)F)F/F)F$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 13 "The commands " }{TEXT 364 3 "gcd" }{TEXT -1 10 "(a,b) and " }{TEXT 365 3 "lcm" }{TEXT -1 136 "(a,b) compute, respectively the g reatest common divisor and least common multiple of two polynomials. \+ The corresponding operations for " }{XPPEDIT 18 0 "Z[p];" "6#&%\"ZG6#% \"pG" }{TEXT -1 5 " are " }{TEXT 360 3 "Gcd" }{TEXT -1 6 "(a,b) " } {TEXT 363 3 "mod" }{TEXT -1 7 " p and " }{TEXT 361 3 "Lcm" }{TEXT -1 6 "(a,b) " }{TEXT 362 3 "mod" }{TEXT -1 16 " p. For example" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "gcd(x^4-2*x^2+2,x^4+1);" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "Gcd(x^4-2*x^2+2,x^4+1) mod p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,&*$)%\"xG\"\"#\"\"\"F(F'F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 351 5 "gcdex" }{TEXT -1 24 "(a,b,x,' s','t') outputs " }{XPPEDIT 18 0 "g = GCD(a,b);" "6#/%\"gG-%$GCDG6$%\" aG%\"bG" }{TEXT -1 49 " . It also outputs through the input parameter s " }{XPPEDIT 18 0 "s,t;" "6$%\"sG%\"tG" }{TEXT -1 35 " integers sati sfying the equation " }{XPPEDIT 18 0 "s*a+t*b = g;" "6#/,&*&%\"sG\"\" \"%\"aGF'F'*&%\"tGF'%\"bGF'F'%\"gG" }{TEXT -1 17 " and satisfying " } {XPPEDIT 18 0 "deg(s) < deg(b);" "6#2-%$degG6#%\"sG-F%6#%\"bG" }{TEXT -1 6 " and " }{XPPEDIT 18 0 "deg(t) < deg(a);" "6#2-%$degG6#%\"tG-F%6 #%\"aG" }{TEXT -1 35 " . The corresponding command for " }{XPPEDIT 18 0 "Z[p];" "6#&%\"ZG6#%\"pG" }{TEXT -1 45 " is Gcdex(a,b,x,'s','t') mod p. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "gcd ex(a,b,x,'s','t');" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "s;" }}}{EXCHG {PARA 11 "" 1 " " {XPPMATH 20 "6#,.#\"%C]\"&lb#\"\"\"*&#\"$,#F&F'%\"xGF'!\"\"*&#\"%e\\ F&F')F+\"\"$F'F'*&#\"%MZF&F'*$)F+\"\"#F'F'F,*&#\"%3AF&F')F+\"\"&F'F'*& #\"%)=\"\"%8^F'*$)F+\"\"%F'F'F," }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "expand( s*a+t*b );" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "Gcdex(a,b,x,'s','t') mod \+ p;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,(*$)%\"xG\"\"#\"\"\"F(*&\"\"$F( F&F(F(F(F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2 "s;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,&%\"xG\"\"\"\"\"%F%" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 2 "t;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,**$)%\"x G\"\"$\"\"\"F(*&F'F()F&\"\"#F(F(*&F'F(F&F(F(\"\"%F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Expand(a*s+t*b) mod p;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#,(*$)%\"xG\"\"#\"\"\"F(*&\"\"$F(F&F(F(F(F(" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 12 "The command " }{TEXT 356 7 "irredu c" }{TEXT -1 35 "(a) outputs true if the polynomial " }{XPPEDIT 18 0 " a(x);" "6#-%\"aG6#%\"xG" }{TEXT -1 32 " is irreducible and the command " }{TEXT 357 6 "factor" }{TEXT -1 34 "(a) outputs the factorization \+ of " }{XPPEDIT 18 0 "a(x);" "6#-%\"aG6#%\"xG" }{TEXT -1 77 " into irre ducible factors over the integers. The corresponding commands for " } {XPPEDIT 18 0 "Z[p];" "6#&%\"ZG6#%\"pG" }{TEXT -1 7 " are " }{TEXT 358 7 "Irreduc" }{TEXT -1 4 "(a) " }{TEXT 366 3 "mod" }{TEXT -1 8 " p \+ and " }{TEXT 359 6 "Factor" }{TEXT -1 4 "(a) " }{TEXT 367 3 "mod" } {TEXT -1 16 " p. For example" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "factor(a);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,**$)%\"xG\"\"'\" \"\"\"\"#*&\"\"$F()F&\"\"&F(!\"\"*&F+F(F&F(F(F+F(" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 10 "factor(b);" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#*&,(*$)%\"xG\"\"#\"\"\"\"\"$*&F(F)F'F)F)F)F)F)),&F'F)F)!\"\"F(F)" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "Factor(a) mod 5;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,$*&,&%\"xG\"\"\"F'F'F'),&F&F'\"\"%F'\"\"&F' \"\"#" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "Factor(b) mod 5;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,$*&),&%\"xG\"\"\"\"\"%F(\"\"#F(,(*$ )F'F*F(F(*&F)F(F'F(F(F*F(F(\"\"$" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 15 "The polynomial " }{XPPEDIT 18 0 "x^2+x+1;" "6#,(*$%\"xG\"\"#\"\"\" F%F'F'F'" }{TEXT -1 27 " is irreducible modulo 2 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Factor(x^2+x+1) mod 2;" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#,(*$)%\"xG\"\"#\"\"\"F(F&F(F(F(" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 143 "and hence the finite field of 4 elements can be r epresented by polynomials of degree < 2 over the integers modulo 2, i. e. the polynomials R = " }{XPPEDIT 18 0 "\{0, 1, x+1, x\};" "6#<&\"\" !\"\"\",&%\"xGF%F%F%F'" }{TEXT -1 79 " . We construct the multiplic ation table M for this finite field as follows." }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 35 "R := [0,1,x,x+1];\nM := matrix(4,4);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"RG7&\"\"!\"\"\"%\"xG,&F(F'F'F'" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"MG-%&arrayG6%;\"\"\"\"\"%F(7\"" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 81 "for i to 4 do \n for j to 4 do M[i,j] := Rem(R[i]*R[j],x^2+x+1,x) mod 2 od;\nod;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "print(M);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#-%'matrixG6#7&7&\"\"!F(F(F(7&F(\"\"\"%\"xG,&F+F*F*F*7&F (F+F,F*7&F(F,F*F+" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 5 "See " } {TEXT 388 4 "?mod" }{TEXT -1 66 " for other operations on polynomials over the integers modulo p ." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}{MARK "0 0 0" 46 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 } {PAGENUMBERS 0 1 2 33 1 1 }