Sat Feb 27 17:48:58 MST 1999 aquarius% maple |\^/| Maple V Release 5.1 (WMI Campus Wide License) ._|\| |/|_. Copyright (c) 1981-1998 by Waterloo Maple Inc. All rights \ MAPLE / reserved. Maple and Maple V are registered trademarks of <____ ____> Waterloo Maple Inc. | Type ? for help. # ----------[ M a p l e ]---------- #interface(echo = 3); # ---------- Initialization ---------- > readlib(showtime): > _Envadditionally:= true: > on; # ---------- Programming and Miscellaneous ---------- O1 := with(share): See ?share and ?share,contents for information about the share library time = 0.06, bytes = 59714 # How easy is it to substitute x for a + b in the following expression? # => (x + c)^2 + (d - x)^2 O2 := expr:= (a + b + c)^2 + (d - a - b)^2; 2 2 (a + b + c) + (d - a - b) time = 0.03, bytes = 13962 O3 := subs(a + b = x, expr); 2 2 (a + b + c) + (d - a - b) time = 0.01, bytes = 4886 O4 := subs(b = x - a, expr); 2 2 (x + c) + (d - x) time = 0.00, bytes = 4746 O5 := simplify(expr, {a + b = x}); 2 2 2 c + d + (-2 d + 2 c) x + 2 x time = 0.36, bytes = 461398 O6 := algsubs(a + b = x, expr); 2 2 (x + c) + (d - x) time = 0.03, bytes = 42590 O7 := expr:= 'expr': time = 0.00, bytes = 4746 # How easy is it to substitute r for sqrt(x^2 + y^2) in the following # expression? => x/r O8 := x/sqrt(x^2 + y^2); x ------------ 2 2 1/2 (x + y ) time = 0.04, bytes = 29666 O9 := subs(sqrt(x^2 + y^2) = r, %); x ------------ 2 2 1/2 (x + y ) time = 0.01, bytes = 7038 O10 := 1/subs(sqrt(x^2 + y^2) = r, 1/%); x/r time = 0.00, bytes = 7094 O11 := algsubs(sqrt(x^2 + y^2) = r, %); Error, no variables in pattern time = 0.02, bytes = 13014 # Change variables so that the following transcendental expression is # converted into a rational expression [Vernor Vinge] # => (r - 1)^4 (u^4 - r u^3 - r^3 u + r u + r^4)/[u^4 (2 r - 1)^2] O12 := q:= (1/r^4 + 1/(r^2 - 2*r*cos(t) + 1)^2 O12 := - 2*(r - cos(t))/(r^2 * (r^2 - 2*r*cos(t) + 1)^(3/2))) / O12 := (1/r^4 + 1/(r - 1)^4 - 2*(r - 1)/(r^2 * (r^2 - 2*r + 1)^(3/2))); 1 1 r - cos(t) ---- + ---------------------- - 2 --------------------------- 4 2 2 2 2 3/2 r (r - 2 r cos(t) + 1) r (r - 2 r cos(t) + 1) ------------------------------------------------------------- 1 1 r - 1 ---- + -------- - 2 -------------------- 4 4 2 2 3/2 r (r - 1) r (r - 2 r + 1) time = 0.06, bytes = 38174 O13 := assume(r > 1): bytes used=1137700, alloc=982860, time=0.86 time = 0.17, bytes = 231798 O14 := assume(u >= r - 1): time = 0.02, bytes = 13418 O15 := subs({r^2 - 2*r*cos(t) + 1 = u^2, cos(t) = (r^2 - u^2 + 1)/(2*r)}, q); 2 2 r~ - u~ + 1 r~ - 1/2 ------------- 1 1 r~ --- + --- - 2 ---------------------- 4 4 2 2 3/2 r~ u~ r~ (u~ ) ------------------------------------------- 1 1 r~ - 1 --- + --------- - 2 ----------------------- 4 4 2 2 3/2 r~ (r~ - 1) r~ (r~ - 2 r~ + 1) time = 0.01, bytes = 6262 O16 := factor(subs({signum(r - 1) = 1, signum(u) = 1}, simplify(%))); 4 4 3 3 4 (u~ + r~ - r~ u~ - r~ u~ + r~ u~) (r~ - 1) ----------------------------------------------- 4 2 u~ (2 r~ - 1) time = 0.41, bytes = 459634 O17 := r:= 'r': time = 0.00, bytes = 4622 O18 := u:= 'u': time = 0.01, bytes = 4586 # Establish a rule to symmetrize a differential operator: [Stanly Steinberg] # f g'' + f' g' -> (f g')' O19 := symmetrize:= proc(q) local m; O19 := if match(q = f(x)*diff(g(x), x$2) + O19 := diff(f(x), x)*diff(g(x), x), x, 'm') then O19 := subs(m, 'diff(f(x)*diff(g(x), x), x)') O19 := else O19 := q O19 := fi O19 := end: time = 0.05, bytes = 45658 O20 := q:= f(x)*diff(g(x), x$2) + diff(f(x), x)*diff(g(x), x); / 2 \ |d | /d \ /d \ f(x) |--- g(x)| + |-- f(x)| |-- g(x)| | 2 | \dx / \dx / \dx / time = 0.01, bytes = 6874 O21 := symmetrize(q); d /d \ -- f(x) |-- g(x)| dx \dx / time = 0.02, bytes = 64282 # => 2 (f g')' + f g O22 := symmetrize(2*q + f(x)*g(x)); bytes used=2394036, alloc=1638100, time=1.92 / 2 \ |d | /d \ /d \ 2 f(x) |--- g(x)| + 2 |-- f(x)| |-- g(x)| + f(x) g(x) | 2 | \dx / \dx / \dx / time = 0.57, bytes = 665454 O23 := q:= f(y)*diff(g(y), y$2) + diff(f(y), y)*diff(g(y), y); / 2 \ |d | /d \ /d \ f(y) |--- g(y)| + |-- f(y)| |-- g(y)| | 2 | \dy / \dy / \dy / time = 0.01, bytes = 4718 O24 := symmetrize(q); / 2 \ |d | /d \ /d \ f(y) |--- g(y)| + |-- f(y)| |-- g(y)| | 2 | \dy / \dy / \dy / time = 0.01, bytes = 12598 O25 := q:= 'q': time = 0.01, bytes = 3362 # Infinite lists: [1 2 3 4 5 ...] * [1 3 5 7 9 ...] # => [1 6 15 28 45 66 91 ...] O26 := l1:= [1, 2, 3, 4, 5]: time = 0.02, bytes = 11334 O27 := l2:= [1, 3, 5, 7, 9]: time = 0.00, bytes = 4222 O28 := [l1[i] * l2[i] $ i = 1..nops(l1)]; [1, 6, 15, 28, 45] time = 0.01, bytes = 4874 O29 := l1:= 'l1': time = 0.01, bytes = 3994 O30 := l2:= 'l2': time = 0.00, bytes = 3566 # Write a simple program to compute Legendre polynomials O31 := p:= proc(n, x) O31 := if n = 0 then O31 := 1 O31 := else O31 := normal(1/(2^n*n!) * diff((x^2 - 1)^n, x$n)) O31 := fi O31 := end: time = 0.05, bytes = 29074 # p[0](x) = 1, p[1](x) = x, p[2](x) = (3 x^2 - 1)/2, # p[3](x) = (5 x^3 - 3 x)/2, p[4](x) = (35 x^4 - 30 x^2 + 3)/8 O32 := for i from 0 to 4 do print('p'(i, x) = p(i, x)) od; p(0, x) = 1 p(1, x) = x 2 p(2, x) = 3/2 x - 1/2 3 p(3, x) = 5/2 x - 3/2 x 4 2 p(4, x) = 35/8 x - 15/4 x + 3/8 time = 0.02, bytes = 35986 # p[4](1) = 1 O33 := subs(x = 1, p(4, x)); 1 time = 0.01, bytes = 7714 # An operator version of the above O34 := p:= unapply('normal'(1/(2^n*n!) * D[2$n]((n, x) -> (x^2 - 1)^n)(n, x)), n, x); 2 n D[2 $ n]((n, x) -> (x - 1) )(n, x) (n, x) -> normal(-----------------------------------) n 2 n! time = 0.02, bytes = 14714 O35 := for i from 0 to 4 do print('p'(i, x) = p(i, x)) od; p(0, x) = 1 p(1, x) = x 2 p(2, x) = 3/2 x - 1/2 3 p(3, x) = 5/2 x - 3/2 x 4 2 p(4, x) = 35/8 x - 15/4 x + 3/8 time = 0.25, bytes = 296142 O36 := subs(x = 1, p(4, x)); 1 time = 0.12, bytes = 124762 # Now, perform the same computation using a recursive definition O37 := pp:= proc(n, x) option remember; O37 := normal(((2*n - 1)*x*pp(n - 1, x) - (n - 1)*pp(n - 2, x))/n) O37 := end: time = 0.01, bytes = 15482 O38 := pp(0, x):= 1: time = 0.00, bytes = 4458 O39 := pp(1, x):= x: time = 0.00, bytes = 4154 O40 := for i from 0 to 4 do print('pp'(i, x) = pp(i, x)) od; pp(0, x) = 1 pp(1, x) = x 2 pp(2, x) = 3/2 x - 1/2 3 pp(3, x) = 5/2 x - 3/2 x 4 2 pp(4, x) = 35/8 x - 15/4 x + 3/8 time = 0.02, bytes = 25930 O41 := subs(x = 1, pp(4, x)); 1 time = 0.01, bytes = 3886 O42 := p:= 'p': time = 0.00, bytes = 3810 O43 := pp:= 'pp': time = 0.01, bytes = 3954 # Iterative computation of Fibonacci numbers O44 := myfib:= proc(n) local i, j, k, f; O44 := if n < 0 then O44 := ERROR(`undefined`) O44 := elif n < 2 then O44 := n O44 := else O44 := j:= 0; k:= 1; O44 := for i from 2 to n do O44 := f:= j + k; j:= k; k:= f; O44 := od; O44 := f O44 := fi O44 := end: time = 0.10, bytes = 54266 # Convert the function into FORTRAN syntax O45 := fortran(myfib); integer function myfib(n) real n integer f integer i integer j integer k if (n .lt. 0) then write(6,*) 'undefined' call exit(0) else if (n .lt. 2) then myfib = n return else j = 0 k = 1 do 1000 i = 2,n,1 f = j+k j = k k = f 1000 continue myfib = f return endif endif end time = 0.47, bytes = 258446 # Create a list of the first 11 values of the function. O46 := [myfib(i) $ i = 0..10]; Error, wrong number (or type) of parameters in function $ time = 0.01, bytes = 7274 O47 := [seq(myfib(i), i = 0..10)]; [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] time = 0.01, bytes = 5226 O48 := myfib:= 'myfib': time = 0.01, bytes = 3318 # Define the function p(x) = x^2 - 4 x + 7 such that p(lambda) = 0 for # lambda = 2 +- i sqrt(3) and p(A) = [[0 0], [0 0]] for A = [[1 -2], [2 3]] # (the lambda are the eigenvalues and p(x) is the characteristic polynomial of # A) [Johnson and Reiss, p. 184] O49 := p:= x -> x^2 - 4*x + 7; 2 x -> x - 4 x + 7 time = 0.02, bytes = 17214 O50 := simplify(p(2 + I*sqrt(3))); 0 time = 0.03, bytes = 28090 O51 := simplify(p(matrix([[1, -2], [2, 3]]))); 2 b - 4 b + 7 time = 0.03, bytes = 25042 O52 := evalm(p(matrix([[1, -2], [2, 3]]))); [0 0] [ ] [0 0] time = 0.11, bytes = 134174 O53 := p:= 'p': time = 0.01, bytes = 3414 # Define a function to be the result of a calculation O54 := -log(x^2 - 2^(1/3)*x + 2^(2/3))/(6 * 2^(2/3)) O54 := + arctan((2*x - 2^(1/3))/(2^(1/3) * sqrt(3))) / (2^(2/3) * sqrt(3)) O54 := + log(x + 2^(1/3))/(3 * 2^(2/3)); 2 1/3 2/3 1/3 - 1/12 ln(x - 2 x + 2 ) 2 1/3 2/3 1/2 1/3 1/2 1/3 1/3 + 1/6 arctan(1/6 (2 x - 2 ) 2 3 ) 2 3 + 1/6 ln(x + 2 ) 2 time = 0.04, bytes = 31730 O55 := f:= unapply(%, x); 2 1/3 2/3 1/3 x -> - 1/12 ln(x - 2 x + 2 ) 2 1/3 2/3 1/2 1/3 1/2 1/3 1/3 + 1/6 arctan(1/6 (2 x - 2 ) 2 3 ) 2 3 + 1/6 ln(x + 2 ) 2 time = 0.00, bytes = 5034 O56 := expr:= f(y); 2 1/3 2/3 1/3 - 1/12 ln(y - 2 y + 2 ) 2 1/3 2/3 1/2 1/3 1/2 1/3 1/3 + 1/6 arctan(1/6 (2 y - 2 ) 2 3 ) 2 3 + 1/6 ln(y + 2 ) 2 time = 0.01, bytes = 4710 # Display the top-level structure of a nasty expression, hiding the # lower-level details. O57 := [op(0, expr), nops(expr)]; [+, 3] time = 0.02, bytes = 10662 O58 := map(q -> [op(0, q), nops(q)], [op(expr)]); [[*, 3], [*, 4], [*, 3]] time = 0.01, bytes = 4218 O59 := expr:= 'expr': time = 0.01, bytes = 3426 O60 := f:= 'f': time = 0.00, bytes = 3566 # Convert the following expression into TeX or LaTeX O61 := y = sqrt((exp(x^2) + exp(-x^2))/(sqrt(3)*x - sqrt(2))); / 2 2 \1/2 |exp(x ) + exp(-x )| y = |------------------| | 1/2 1/2 | \ 3 x - 2 / time = 0.11, bytes = 95958 O62 := latex(%); y=\sqrt {{\frac {{e^{{x}^{2}}}+{e^{-{x}^{2}}}}{\sqrt {3}x-\sqrt {2}}}} time = 0.13, bytes = 151482 # ---------- Quit ---------- O63 := quit bytes used=4082020, alloc=1965720, time=3.81 real 5.48 user 3.87 sys 1.08