Mon Jan 5 00:25:10 MET 1998 anne % axiom Axiom Computer Algebra System (Release 2.1) Digital Unix on DEC Alpha (AXIOM Sockets) The AXIOM server number is undefined. ----------------------------------------------------------------------------- Issue )copyright to view copyright notices. Issue )summary for a summary of useful system commands. Issue )quit to leave AXIOM and return to shell. ----------------------------------------------------------------------------- initial (1) -> -- ----------[ A x i o m ]---------- -- ---------- Initialization ---------- )set messages autoload off )set messages time on )set quit unprotected )set streams calculate 7 -- ---------- Programming and Miscellaneous ---------- -- How easy is it to substitute x for a + b in the following expression? -- => (x + c)^2 + (d - x)^2 expr:= (a + b + c)**2 + (d - a - b)**2 2 2 2 2 (1) d + (- 2b - 2a)d + c + (2b + 2a)c + 2b + 4a b + 2a Type: Polynomial Integer Time: 0.23 (IN) + 0.02 (EV) + 0.18 (OT) + 0.10 (GC) = 0.53 sec subst(expr, a + b = x) >> Error detected within library code: left hand side must be a single kernel initial (2) -> real 3.2 user 1.8 sys 0.2 ------------------------------------------------------------------------------- Mon Jan 5 00:26:00 MET 1998 anne % axiom Axiom Computer Algebra System (Release 2.1) Digital Unix on DEC Alpha (AXIOM Sockets) The AXIOM server number is undefined. ----------------------------------------------------------------------------- Issue )copyright to view copyright notices. Issue )summary for a summary of useful system commands. Issue )quit to leave AXIOM and return to shell. ----------------------------------------------------------------------------- initial (1) -> -- ----------[ A x i o m ]---------- -- ---------- Initialization ---------- )set messages autoload off )set messages time on )set quit unprotected )set streams calculate 7 -- ---------- Programming and Miscellaneous ---------- -- How easy is it to substitute x for a + b in the following expression? -- => (x + c)^2 + (d - x)^2 expr:= (a + b + c)**2 + (d - a - b)**2 2 2 2 2 (1) d + (- 2b - 2a)d + c + (2b + 2a)c + 2b + 4a b + 2a Type: Polynomial Integer Time: 0.25 (IN) + 0.03 (EV) + 0.15 (OT) + 0.07 (GC) = 0.50 sec subst(expr, b = x - a) 2 2 2 (2) 2x + (- 2d + 2c)x + d + c Type: Expression Integer Time: 0.38 (IN) + 0.05 (EV) + 0.17 (OT) + 0.12 (GC) = 0.72 sec )clear properties expr -- How easy is it to substitute r for sqrt(x^2 + y^2) in the following -- expression? => x/r x/sqrt(x**2 + y**2) x (3) ---------- +-------+ | 2 2 \|y + x Type: Expression Integer Time: 0.30 (IN) + 0.07 (EV) + 0.12 (OT) = 0.48 sec subst(%, sqrt(x**2 + y**2) = r) x (4) - r Type: Expression Integer Time: 0.15 (IN) + 0.02 (EV) = 0.17 sec -- 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] q:= (1/r**4 + 1/(r**2 - 2*r*cos(t) + 1)**2 _ - 2*(r - cos(t))/(r**2 * (r**2 - 2*r*cos(t) + 1)**(3/2))) / _ (1/r**4 + 1/(r - 1)**4 - 2*(r - 1)/(r**2 * (r**2 - 2*r + 1)**(3/2))) (5) 6 5 4 3 2 2 (4r - 16r + 24r - 16r + 4r )cos(t) + 7 6 5 4 3 2 8 7 (- 4r + 16r - 28r + 32r - 28r + 16r - 4r)cos(t) + 2r - 8r + 6 5 4 3 2 14r - 16r + 15r - 12r + 8r - 4r + 1 * +-----------+ +--------------------+ | 2 | 2 \|r - 2r + 1 \|- 2r cos(t) + r + 1 + 7 6 5 4 3 2 (- 4r + 16r - 24r + 16r - 4r )cos(t) + 8 7 6 5 4 3 2 9 8 (6r - 24r + 38r - 32r + 18r - 8r + 2r )cos(t) - 2r + 8r + 7 6 5 4 3 - 14r + 16r - 14r + 8r - 2r * +-----------+ | 2 \|r - 2r + 1 / 6 5 4 3 2 2 (8r - 16r + 24r - 16r + 4r )cos(t) + 7 6 5 4 3 2 8 7 (- 8r + 16r - 32r + 32r - 28r + 16r - 4r)cos(t) + 2r - 4r + 6 5 4 3 2 10r - 12r + 15r - 12r + 8r - 4r + 1 * +-----------+ | 2 \|r - 2r + 1 + 7 6 5 4 2 (- 8r + 24r - 24r + 8r )cos(t) + 8 7 6 5 4 3 9 8 7 6 (8r - 24r + 32r - 32r + 24r - 8r )cos(t) - 2r + 6r - 10r + 14r + 5 4 3 2 - 14r + 10r - 6r + 2r * +--------------------+ | 2 \|- 2r cos(t) + r + 1 Type: Expression Integer Time: 0.61 (IN) + 0.28 (EV) + 0.28 (OT) + 0.07 (GC) = 1.25 sec subst(q, cos(t) = (r**2 - u**2 + 1)/(2*r)) (6) +-----------+ 4 3 2 4 8 7 6 5 4 | 2 ((r - 4r + 6r - 4r + 1)u + r - 4r + 6r - 4r + r )\|r - 2r + 1 * +--+ | 2 \|u + 5 4 3 2 4 7 6 5 3 2 2 ((- r + 4r - 6r + 4r - r)u + (- r + 4r - 5r + 5r - 4r + r)u ) * +-----------+ | 2 \|r - 2r + 1 / +-----------+ 4 3 2 4 | 2 (2r - 4r + 6r - 4r + 1)u \|r - 2r + 1 + 5 4 3 2 4 (- 2r + 6r - 6r + 2r )u * +--+ | 2 \|u Type: Expression Integer Time: 0.15 (IN) + 0.17 (EV) + 0.12 (OT) = 0.43 sec (rule sqrt(x**2) == x)(%) (7) 4 3 2 4 5 4 3 2 3 (r - 4r + 6r - 4r + 1)u + (- r + 4r - 6r + 4r - r)u + 7 6 5 3 2 8 7 6 5 4 (- r + 4r - 5r + 5r - 4r + r)u + r - 4r + 6r - 4r + r * +-----------+ | 2 \|r - 2r + 1 / +-----------+ 4 3 2 4 | 2 5 4 3 2 4 (2r - 4r + 6r - 4r + 1)u \|r - 2r + 1 + (- 2r + 6r - 6r + 2r )u Type: Expression Integer Time: 0.07 (IN) + 0.93 (EV) + 0.12 (OT) = 1.12 sec (rule sqrt(r**2 - 2*r + 1) == r - 1)(%) (8) 4 3 2 4 5 4 3 2 3 (r - 4r + 6r - 4r + 1)u + (- r + 4r - 6r + 4r - r)u + 7 6 5 3 2 8 7 6 5 4 (- r + 4r - 5r + 5r - 4r + r)u + r - 4r + 6r - 4r + r / 2 4 (4r - 4r + 1)u Type: Expression Integer Time: 0.03 (IN) + 0.47 (EV) + 0.07 (OT) = 0.57 sec map(factor, % :: Fraction Polynomial Integer) 4 4 3 3 4 (r - 1) (u - r u + (- r + r)u + r ) (9) -------------------------------------- 2 4 (2r - 1) u Type: Fraction Factored Polynomial Integer Time: 0.17 (IN) + 0.25 (EV) + 0.03 (OT) + 0.02 (GC) = 0.47 sec -- Establish a rule to symmetrize a differential operator: [Stanly Steinberg] -- f g'' + f' g' -> (f g')' f:= operator('f); Type: BasicOperator Time: 0.05 (IN) + 0.02 (OT) = 0.07 sec g:= operator('g); Type: BasicOperator Time: 0.03 (IN) = 0.03 sec symmetrize:= rule _ f(x)*D(g(x), x, 2) + D(f(x), x)*D(g(x), x) == D(f(x)*D(g(x), x), x) ,, , , (12) f(x)g (x) + f (x)g (x) + %B == 'D('f(x)'D('g(x),x),x) + %B Type: RewriteRule(Integer,Integer,Expression Integer) Time: 0.62 (IN) + 0.05 (EV) + 0.07 (OT) = 0.73 sec q:= f(x)*D(g(x), x, 2) + D(f(x), x)*D(g(x), x) ,, , , (13) f(x)g (x) + f (x)g (x) Type: Expression Integer Time: 0.03 (IN) + 0.03 (EV) + 0.05 (OT) = 0.12 sec symmetrize q There are no library operations named %diff Use HyperDoc Browse or issue )what op %diff to learn if there is any operation containing " %diff " in its name. Cannot find a definition or applicable library operation named %diff with argument type(s) Expression Integer Variable %%01 Variable x -- => 2 (f g')' + f g symmetrize 2*q + f(x)*g(x) ,, , , (14) 2f(x)g (x) + 2f (x)g (x) + f(x)g(x) Type: Expression Integer Time: 0.05 (IN) + 0.02 (OT) = 0.07 sec )clear properties f g q -- Infinite lists: [1 2 3 4 5 ...] * [1 3 5 7 9 ...] -- => [1 6 15 28 45 66 91 ...] l1:= [i for i in 1..]; Type: Stream PositiveInteger Time: 0.02 (IN) + 0.03 (OT) = 0.05 sec l2:= [2*i-1 for i in 1..]; Type: Stream Integer Time: 0.03 (IN) + 0.02 (EV) = 0.05 sec [l1.i*l2.i for i in 1..] (17) [1,6,15,28,45,66,91,...] Type: Stream Integer Time: 0.02 (IN) + 0.02 (OT) = 0.03 sec )clear properties l1 l2 -- Write a simple program to compute Legendre polynomials p(n, x) == 1/(2**n*factorial(n)) * D((x**2 - 1)**n, x, n) Type: Void Time: 0 sec -- 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 for i in 0..4 repeat _ (output(""); _ output(concat(["p(", string(i), ", x) = "])); _ output(p(i, x)) ) Compiling function p with type (NonNegativeInteger,Variable x) -> Polynomial Fraction Integer p(0, x) = 1 p(1, x) = x p(2, x) = 3 2 1 - x - - 2 2 p(3, x) = 5 3 3 - x - - x 2 2 p(4, x) = 35 4 15 2 3 -- x - -- x + - 8 4 8 Type: Void Time: 0.20 (IN) + 0.08 (EV) + 0.12 (OT) = 0.40 sec -- p[4](1) = 1 eval(p(4, x), x = 1) Compiling function p with type (PositiveInteger,Variable x) -> Polynomial Fraction Integer (20) 1 Type: Polynomial Fraction Integer Time: 0.63 (IN) + 0.02 (EV) + 0.12 (OT) = 0.77 sec -- Now, perform the same computation using a recursive definition pp(0, x) == 1 Type: Void Time: 0.02 (OT) = 0.02 sec pp(1, x) == x Type: Void Time: 0 sec pp(n, x) == ((2*n - 1)*x*pp(n - 1, x) - (n - 1)*pp(n - 2, x))/n Type: Void Time: 0 sec for i in 0..4 repeat _ (output(""); _ output(concat(["pp(", string(i), ", x) = "])); _ output(pp(i, x)) ) Compiling function pp with type (Integer,Variable x) -> Polynomial Fraction Integer pp(0, x) = 1 pp(1, x) = x pp(2, x) = 3 2 1 - x - - 2 2 pp(3, x) = 5 3 3 - x - - x 2 2 pp(4, x) = 35 4 15 2 3 -- x - -- x + - 8 4 8 Type: Void Time: 0.33 (IN) + 0.03 (EV) + 0.05 (OT) = 0.42 sec pp(4, 1) Compiling function pp with type (Integer,Integer) -> Fraction Integer +++ |*2;pp;1;initial| redefined (25) 1 Type: Fraction Integer Time: 0.08 (IN) + 0.05 (OT) = 0.13 sec )clear properties p pp Compiled code for p has been cleared. Compiled code for pp has been cleared. -- Iterative computation of Fibonacci numbers myfib(n) == ( _ local i, j, k, f; _ if n < 0 then _ error("undefined") _ else if n < 2 then _ n _ else _ (j:= 0, k:= 1, _ for i in 2..n repeat _ (f:= j + k, j:= k, k:= f), _ return(f))); Type: Void Time: 0.02 (IN) = 0.02 sec -- Convert the function into FORTRAN syntax outputAsFortran(myfib) There are 4 exposed and 0 unexposed library operations named outputAsFortran having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op outputAsFortran to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named outputAsFortran with argument type(s) FunctionCalled myfib -- Create a list of the first 11 values of the function. [myfib(i) for i in 0..10] Compiling function myfib with type NonNegativeInteger -> Any (27) [0,1,1,2,3,5,8,13,21,34,55] Type: List Any Time: 0.22 (IN) + 0.07 (OT) = 0.28 sec )clear properties myfib Compiled code for myfib has been cleared. -- 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] p(x) == x**2 - 4*x + 7 Type: Void Time: 0 sec p(2 + %i*sqrt(3)) Compiling function p with type Expression Complex Integer -> Expression Complex Integer (29) 0 Type: Expression Complex Integer Time: 0.43 (IN) + 0.08 (EV) + 0.12 (OT) + 0.03 (GC) = 0.67 sec p(matrix([[1, -2], [2, 3]])) There are 11 exposed and 5 unexposed library operations named + having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op + to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named + with argument type(s) Matrix Integer PositiveInteger AXIOM will attempt to step through and interpret the code. +0 0+ (30) | | +0 0+ Type: SquareMatrix(2,Integer) Time: 0.22 (IN) + 0.03 (EV) + 0.03 (OT) + 0.05 (GC) = 0.33 sec )clear properties p Compiled code for p has been cleared. -- Define a function to be the result of a calculation -log(x**2 - 2**(1/3)*x + 2**(2/3))/(6 * 2**(2/3)) _ + atan((2*x - 2**(1/3))/(2**(1/3) * sqrt(3))) / (2**(2/3) * sqrt(3)) _ + log(x + 2**(1/3))/(3 * 2**(2/3)) (31) 3+-+2 +-+ +-+ 3+-+2 3+-+ 2 +-+ 3+-+ (x \|2 - 1)\|3 - \|3 log(\|2 - x\|2 + x ) + 2\|3 log(\|2 + x) + 6atan(-----------------) 3 ----------------------------------------------------------------------------- 3+-+2 +-+ 6\|2 \|3 Type: Expression Integer Time: 0.65 (IN) + 0.55 (EV) + 0.13 (OT) = 1.33 sec function(%, f, x) (32) f Type: Symbol Time: 0.08 (IN) + 0.03 (EV) = 0.12 sec expr:= f(y) Compiling function f with type Variable y -> Expression Integer (33) 3+-+2 +-+ +-+ 3+-+2 3+-+ 2 +-+ 3+-+ (y \|2 - 1)\|3 - \|3 log(\|2 - y\|2 + y ) + 2\|3 log(\|2 + y) + 6atan(-----------------) 3 ----------------------------------------------------------------------------- 3+-+2 +-+ 6\|2 \|3 Type: Expression Integer Time: 0.23 (IN) + 0.22 (EV) + 0.17 (OT) = 0.62 sec -- Display the top-level structure of a nasty expression, hiding the -- lower-level details. name(mainKernel(expr)) (34) log Type: Symbol Time: 0 sec )clear properties expr f Compiled code for f has been cleared. -- Convert the following expression into TeX or LaTeX y = sqrt((exp(x**2) + exp(-x**2))/(sqrt(3)*x - sqrt(2))) +-------------+ | 2 2 | x - x |%e + %e (35) y= |------------- | +-+ +-+ \| x\|3 - \|2 Type: Equation Expression Integer Time: 0.20 (IN) + 0.07 (EV) + 0.05 (OT) = 0.32 sec outputAsTex(%) $$ y={\sqrt {{{{e \sp {x \sp 2}}+{e \sp {\left( -{x \sp 2} \right)}}} \over {{x \ {\sqrt {3}}} -{\sqrt {2}}}}}} \leqno(36) $$ Type: Void Time: 0.07 (IN) + 0.03 (EV) = 0.10 sec -- ---------- Quit ---------- )quit real 29.9 user 14.9 sys 0.7