Fri Jan  9 15:07:24 MST 1998
aquarius% reduce
REDUCE 3.6, 15-Jul-95, patched to 15 Apr 96 ...

1: % ----------[ R e d u c e ]----------
% ---------- Initialization ----------
on time;


Time: 0 ms

% ---------- Programming and Miscellaneous ----------
% How easy is it to substitute x for a + b in the following expression?
% => (x + c)^2 + (d - x)^2
off exp;


Time: 10 ms

xpr:= (a + b + c)^2 + (d - a - b)^2;


                  2              2
xpr := (b + c + a)  + (b - d + a)

Time: 0 ms

sub(a + b = x, xpr);


***** a + b invalid as kernel

Cont? (Y or N)


?y
Time: 10 ms

sub(b = x - a, xpr);


       2          2
(c + x)  + (d - x)

Time: 0 ms

clear xpr;


Time: 0 ms

on exp;


Time: 0 ms

% 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
---------------
       2    2
 sqrt(x  + y )

Time: 10 ms

sub(sqrt(x^2 + y^2) = r, ws);


 x
---
 r

Time: 10 ms

% 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]
off exp;


Time: 0 ms

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)));


            2                                                        2       2
q := (((2*(r  + 1 - 2*cos(t)*r)*(cos(t) - r) + sqrt( - 2*cos(t)*r + r  + 1)*r )

         2                         2        2                  2         6
       *r  + sqrt( - 2*cos(t)*r + r  + 1)*(r  + 1 - 2*cos(t)*r) )*(r - 1)

                                          2
      *abs(r - 1))/(sqrt( - 2*cos(t)*r + r  + 1)*(

              2                        2            5   2
           ((r  - 2*r + 1)*abs(r - 1)*r  - 2*(r - 1) )*r

                2                   4               2                  2
            + (r  - 2*r + 1)*(r - 1) *abs(r - 1))*(r  + 1 - 2*cos(t)*r) )

Time: 150 ms

sub(cos(t) = (r^2 - u^2 + 1)/(2*r), q);


        2        2   2           3              4         6
( - (((u  - 1 + r )*u  - abs(u)*r )*r - abs(u)*u )*(r - 1) *abs(r - 1))/((

         2                        2            5   2
      ((r  - 2*r + 1)*abs(r - 1)*r  - 2*(r - 1) )*r

           2                   4                     4
       + (r  - 2*r + 1)*(r - 1) *abs(r - 1))*abs(u)*u )

Time: 20 ms

ws where abs(~e) => e;


        2        2       3       4         5
  - (((u  - 1 + r )*u - r )*r - u )*(r - 1)
---------------------------------------------
             3      2             4
         (4*r  - 8*r  + 5*r - 1)*u

Time: 10 ms

on factor;


Time: 0 ms

ws;


        2    2           3       4         4
  - (((r  + u  - 1)*u - r )*r - u )*(r - 1)
---------------------------------------------
                         2  4
                (2*r - 1) *u

Time: 50 ms

off factor;


Time: 0 ms

on exp;


Time: 10 ms

% Establish a rule to symmetrize a differential operator:   [Stanly Steinberg]
% f g'' + f' g' -> (f g')'
operator f, g, !~f, !~g;


Time: 0 ms

symmetrize:= ~f(~x)*df(~g(~x), ~x, 2) + df(~f(~x), ~x)*df(~g(~x), ~x) =>
             df(f(x)*df(g(x), x), x);


symmetrize := 

~(f (~ x))*df(~(g (~ x)),~x,2) + df(~(f (~ x)),~x)*df(~(g (~ x)),~x)

 => df(f(x)*df(g(x),x),x)

Time: 0 ms

q:= f(x)*df(g(x), x, 2) + df(f(x), x)*df(g(x), x);


q := df(f(x),x)*df(g(x),x) + df(g(x),x,2)*f(x)

Time: 0 ms

q where symmetrize;


***** df(f(x)*df(g(x),x),x) invalid as rule

Cont? (Y or N)


?y
Time: 0 ms

% => 2 (f g')' + f g
2*q + f(x)*g(x) where symmetrize;


***** df(f(x)*df(g(x),x),x) invalid as rule

Cont? (Y or N)


?y
Time: 0 ms

clear f, g, q;


Time: 0 ms

% Infinite lists: [1 2 3 4 5 ...] * [1 3 5 7 9 ...]
% => [1 6 15 28 45 66 91 ...]
l1:= {1, 2, 3, 4, 5}$


Time: 10 ms

l2:= {1, 3, 5, 7, 9}$


Time: 0 ms

for i:= 1:length(l1) collect part(l1, i)*part(l2, i);


{1,6,15,28,45}

Time: 0 ms

clear l1, l2;


Time: 0 ms

% Write a simple program to compute Legendre polynomials
procedure p(n, x);
   1/(2^n*factorial(n)) * df((x^2 - 1)^n, x, n)$


Time: 10 ms

% 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:= 0:4 do write("p(", i, ", x) = ", p(i, x));


p(0, x) = 1

p(1, x) = x

              2
           3*x  - 1
p(2, x) = ----------
              2

                 2
           x*(5*x  - 3)
p(3, x) = --------------
                2

               4       2
           35*x  - 30*x  + 3
p(4, x) = -------------------
                   8

Time: 20 ms

% p[4](1) = 1
sub(x = 1, p(4, x));


1

Time: 0 ms

% Now, perform the same computation using a recursive definition
procedure pp(n, x);
   if n = 0 then
      1
   else if n = 1 then
      x
   else
      ((2*n - 1)*x*pp(n - 1, x) - (n - 1)*pp(n - 2, x))/n$

*** Function `pp' has been redefined

Time: 10 ms

for i:= 0:4 do write("pp(", i, ", x) = ", pp(i, x));


pp(0, x) = 1

pp(1, x) = x

               2
            3*x  - 1
pp(2, x) = ----------
               2

                  2
            x*(5*x  - 3)
pp(3, x) = --------------
                 2

                4       2
            35*x  - 30*x  + 3
pp(4, x) = -------------------
                    8

Time: 10 ms

pp(4, 1);


1

Time: 0 ms

clear p, pp;


Time: 0 ms

% Iterative computation of Fibonacci numbers
on fort;


Time: 0 ms

procedure myfib(n);
   begin scalar i, j, k, f;
   if n < 0 then
      error('undefined)
   else if n < 2 then
      return(n)
   else
     <<j:= 0,   k:= 1,
       for i:=2:n do
         <<f:= j + k;   j:= k;   k:= f>>;
       return(f)>>
   end$


Time: 0 ms

% Convert the function into FORTRAN syntax
off fort;


Time: 0 ms

% Create a list of the first 11 values of the function.
for i:= 0:10 collect
   myfib(i);


{0,1,1,2,3,5,8,13,21,34,55}

Time: 20 ms

clear myfib;


Time: 0 ms

% 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]
procedure p(x);
   x^2 - 4*x + 7$


Time: 10 ms

p(2 + i*sqrt(3));


0

Time: 0 ms

p(mat((1, -2), (2, 3)));


***** Matrix mismatch 

Cont? (Y or N)


?y
Time: 20 ms

clear p;


Time: 0 ms

% Define a function to be the result of a calculation
operator f;


Time: 0 ms

-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));


              1/3
             2    - 2*x                   2/3    1/3      2
( - 6*atan(--------------) - sqrt(3)*log(2    - 2   *x + x )
             1/3
            2   *sqrt(3)

                   1/3           2/3
  + 2*sqrt(3)*log(2    + x))/(6*2   *sqrt(3))

Time: 20 ms

for all x let f(x) = ws;


Time: 10 ms

xpr:= f(y);


                     1/3
                    2    - 2*y                   2/3    1/3      2
xpr := ( - 6*atan(--------------) - sqrt(3)*log(2    - 2   *y + y )
                    1/3
                   2   *sqrt(3)

                          1/3           2/3
         + 2*sqrt(3)*log(2    + y))/(6*2   *sqrt(3))

Time: 30 ms

% Display the top-level structure of a nasty expression, hiding the
% lower-level details.
structr(xpr);


  - 6*ans1 - ans2*ans3 + 2*ans2*ans4
-------------------------------------
                       2
            6*ans2*ans5

   where

      ans4 := log(ans5 + y)

                   2/3             2
      ans3 := log(2    - ans5*y + y )

               1/2
      ans2 := 3

                     ans5 - 2*y
      ans1 := atan(--------------)
                    ans5*sqrt(3)

               1/3
      ans5 := 2

Time: 10 ms

clear xpr, f;


Time: 0 ms

% Convert the following expression into TeX or LaTeX
sqrt((exp(x^2) + exp(-x^2))/(sqrt(3)*x - sqrt(2)));


                   2
                2*x
               e     + 1
sqrt(-----------------------------)
        2               2
       x               x
      e  *sqrt(3)*x - e  *sqrt(2)

Time: 20 ms

load_package(rlfi)$


Time: 10 ms

on latex;

\documentstyle{article}
\begin{document}

Time: 0 ms

sqrt((exp(x^2) + exp(-x^2))/(sqrt(3)*x - sqrt(2)));

\begin{displaymath}
\sqrt {\left(e^{2 x^{2}}+1\right)/\left(e^{x^{2}} \sqrt {3} x-e^{x^{2}} 
\sqrt {2}\right)}
\end{displaymath}

Time: 20 ms

off lasimp;


Time: 0 ms

sqrt((exp(x^2) + exp(-x^2))/(sqrt(3)*x - sqrt(2)));

\begin{displaymath}
\sqrt {\left(\exp \left(x^{2}\right)+\exp \left(-x^{2}\right)\right)/\left(
\sqrt {3} x-\sqrt {2}\right)}
\end{displaymath}

Time: 0 ms

off latex;

\end{document}

Time: 0 ms

load_package(tri)$

% TeX-REDUCE-Interface 0.50
% set greek asserted
% set lowercase asserted
% \tolerance 10
% \hsize=150mm

Time: 20 ms

on TeXIndent;


Time: 0 ms

y = sqrt((exp(x^2) + exp(-x^2))/(sqrt(3)*x - sqrt(2)));

$$\displaylines{\qdd
y=
\[\sqrt{
        \frac{e^{2\cdot x^{2}}
              +1}{
              e^{x^{2}}\cdot 
              \sqrt{3}\cdot x
              -e^{x^{2}}\cdot 
              \sqrt{2}}}
\]
\cr}$$

Time: 40 ms

off TeXIndent;


Time: 0 ms

% ---------- Quit ----------
quit;

Quitting

real 10.37
user 0.68
sys 1.26
