#OK to Post #1: Sample of Examples from pages 30-60 of Garvan's booklet #Data Types: #SEQUENCE: Finding nth roots of unity s:=seq(x^i-1, i=1..5); for i from 1 to 5 do factor(s[i]) end do; for i from 1 to 5 do fsolve(s[i],x, complex) end do; #SET: Inclusion-Exclusion a:={1,2,3,4}; b:={1,4,6,8}; c:={1,2,3,7}; nops(a union b union c); nops(a)+nops(b)+nops(c)-nops(a intersect b)-nops(a intersect c)-nops(b intersect c)+nops(a intersect b intersect c); #LIST: Converting sequence to list: M:=[s]; #TABLE: Converting list to table: table(M); #ARRAY: C:=array(1..2,1..3): for i from 1 to 3 do C[1,i]:=i: od: for i from 1 to 3 do C[2,i]:=i+3 od: op(C); whattype(C); #----------------------------- #Summation and Product: i:='i'; Sum(f(i), i=1..n); sum(i^3, i=1..10); Product(q^i+2, i=1..4); value(%); #Limits, Differentiation,Extrema: Limit((f(x+h)-f(x))/(h), x=h); Limit(x/(x-3), x=3, right); f:=1/(sqrt(x^3+3)); diff(f, x); g:=cos(x); h=(f@g)(x); diff(h, x); x:='x'; maximize(sin(2*x)+cos(x)); maximize(sin(2*x)+cos(x), x=0..2); #THIS APPEARS TO HAVE CHANGED FROM WHEN THE MANUAL WAS WRITTEN readlib(extrema): f:=2*x^2+y+y^2; g:=x^3-2; extrema(f, g, {x,y}); #Integration & Related Techniques: Int(x^3/sqrt(1-x^4), x); value(%); Int(e^(-x^2), x=0..infinity); value(%); with(IntegrationTools): Int(x*cos(5*x), x); Parts(%, x); #MAY ALSO BE DIFFERENT FROM MANUAL #Partial Fractions rat:=(6*x^8+4*x^3-2*x^2+x-2)/(x+1)/(x^2-x+1)^2: convert(rat, parfrac, x); #Taylor Series y:=1/sqrt(1-x^2); taylor(y,x=0,9); time(%); #------------------------------ #2: Read Lecture Note on Euler's Theorem and RSA: a large-number example with(NumberTheory): e:='e'; p:=ithprime(300); q:=ithprime(500); e:=ithprime(200); n:=p*q; P:=Totient(n); op(P); gcd(P, e); #these are relatively prime #want to find d such that de == 1 mod P d:=1/e mod P; #suppose encrypted message is 2974943580924492084. M:=2974943580924492084; gcd(M, n); M&^d mod n; #The decrypted message is 5651777 #------------------------------ #3: Factorization Algorithm and Time Comparison Help:=proc(): print(`MyIfactor(n)`): end: #MyIfactor(n): inputs an integer n and returns its prime factors #with primes in weakly increasing order with(NumberTheory): beep; MyIfactor:=proc(n) local i: i:=2; while i<=n do if n mod i =0 and isprime(i) then return i; else i:=nextprime(i); fi: od: end: PrimeFacs:=proc(n) local fac, p, k; fac:=[]; #dummy variable k is important for the iteration step below k:=n; while k>1 do p:=MyIfactor(k); fac:=[op(fac), p]; k:=k/p; od: fac; end: