% You are about to see a demonstration of the REDUCE 3.4 Computer Algebra
% System.
%  The demonstration is in 9 sections:

%   1) Hardware configuration         2) Basic Algebra
%   3) Differentiation, Integration   4) Matrices
%   5) Solutions of equations         6) Groebner Bases
%   7) Big Floats                     8) Algebraic Numbers
%   9) Other Facilities

%
%                                1
%                               11
%                                1
%                                1
%                                1
%                                1
%                               111
%                                                                      

% REDUCE is one of the most portable programs and versions of it run on nearly
% every significant computer in existence.  In addition, a Common Lisp version
% is available for those machines for which a customized implementation does
% not exist.  A copy of the current information package may be obtained by
% sending the message "send info-package" to any of the available REDUCE
% Network Library servers (such as reduce-netlib@rand.org).

%                               222
%                              2   2
%                                  2
%                                 2
%                               2
%                              2
%                              22222
%     An introduction to the basic REDUCE algebraic capabilities.

%                                SYNTAX
% REDUCE's syntax is close to that of most conventional programming languages
% with + - * / and ^ for addition, subtraction, multiplication, division and
% exponentiation.  In the next few frames we examine some of these
% capabilities.

%                           Exact Arithmetic
% Unlike conventional programming systems, REDUCE can compute expressions
% exactly, with no round-off, and with symbols when quantities are undefined.
% exponentiation. For example, the following numeric values are computed
% exactly:

1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20*21;
2/6 - 1/4;
711/347 - 15333555/(37666* (3/5));


%                         Mathematical Library
% REDUCE also has a full numeric library with trigonometric and logarithmic
% functions. The REDUCE syntax for function calls only requires parentheses
% for multiple argument functions. In the following example, I try to get
% the cosine of pi. REDUCE likes to work with exact number so it obligingly
% converts my inaccurate pi into a rational and then can't do much with it.

cos 3.14159;
cos pi;


% To get REDUCE to compute the actual number and leave the floating-point
% pi alone, we tell it to use floating-point (rounded) arithmetic.

on rounded;
cos 3.14159;
sqrt 3.2;
off rounded;

% REDUCE also supports arbitrary precision floating-point where numbers
% are stored with as many digits in the mantissa and exponent as your machine
% can store. This capability package is included in the standard distribution
% and is demonstrated in section 7.


%                            Basic Algebra
% REDUCE works with expressions in which not all variables have values
% associated with them.  The expressions are expanded where possible removing
% exponentiation and multiplication where possible.

x + 1;
(x + y)*(x - y);
(x + 1)^10;


%                              Canonical Forms
% REDUCE tries to keep algebraic forms in the lowest possible terms. In the
% process of simplifying terms, expressions are reordered and reconstructed
% into an internal "canonical form" bearing little resemblance to their
% external representation. Likewise, quotients are kept in lowest terms by
% canceling greatest common divisors as shown in the following examples:

(x+1)^2 / (1+x);
sqrt((x + 1)^4) / (cos x)*(x + 1);
x^2*(y^2+2*y) + x*(y^2+z) / (2*x);


%                             Basic Assignment
% Unlike conventional programming languages, REDUCE allows you to store an
% expression in a variable.  In the following example, we exercise this
% capability to create a large expression.

var1 := (x^2 + 3*x*y - 3*y^3 - x) / (3*cos x);
var2 := (cos x) / (x + 1);
var1 * var2 + x;
clear var1, var2;

%                             Basic Substitution
% Even more powerful, is REDUCE's ability to substitute for complex
% expressions. In the following example, we use the LET substitution statement
% to simplify an expression of x, y, and z in which it is known that
% x + z = 0.

var1 := 3*(x+y)^2  * (x - 2*z)^2 + x*y*z^3 + x*z;
let x+z=0;
var1;
clear var1, x+z;


%                            Extended Substitution
% The previous substitution example works only for specific variables.
% REDUCE's powerful pattern matching capabilities allows you to create
% complicated algebraic rules that apply to many situations.  In the
% following example we create an operator f which is defined as its argument
% cubed plus one, or, if its argument is a variable less one, it is equal
% to 3.  We then compute an expression with applications of this function.

operator f;
for all x let f(x) = x^3 + 1,
              f(x-1) = 3;
f(y^2 + 1) - 2*f(y^3-1)^2;
for all x clear f(x);


%                       Conditional Substitution
% Even more powerful is the capability to make conditional substitutions.
% In the following example, we define the Gamma function as a set of
% patterns. Though this is less efficient than the usual procedural
% definition, it has the advantage of leaving the Gamma operator for
% unevaluated non-integer arguments.

operator gamma,gamma_error;

gamma_rules :=
  {gamma(~x)=>sqrt(pi)/2 when x=1/2,
   gamma(~n)=>factorial(n-1) when fixp n and n>0,
   gamma(~n)=>gamma_error(n) when fixp n,
   gamma(~x)=>(x-1)*gamma(x-1) when fixp(2*x) and x>1,
   gamma(~x)=>gamma(x+1)/x when fixp(2*x)};

let gamma_rules;

gamma 10;

gamma(a+b);

gamma (-2);

clear gamma,gamma_error,gamma_rules;

%                            Greatest Common Divisors
% REDUCE facilities for canceling common factors in numerators and
% denominators are available to the user and are either automatic or
% specifiable by the user. Two levels of GCD calculation are available: the
% built-in version being a simple check for square-free factors, and a more
% complicated version (not shown in this demonstration) called the EZGCD
% algorithm is loadable on user demand. The following examples demonstrate
% the built-in GCD function.

gcd(x^2 + 2x + 1, x^2 + 3x + 2);
gcd(2x^2 - 2y^2, 4x + 4y);
gcd(x^2 + y^2, x - y);

%                            Complex Coefficients
% Although REDUCE routinely treats the square of the variable I as equivalent
% to -1, this is not sufficient to reduce expressions involving I to lowest
% terms. When the COMPLEX switch is turned on, full complex arithmetic is
% carried out as shown in the following examples. The GCD switch removes
% common factors in quotients when results aren't expanded.

on complex, gcd;
(x**3-7*x**2+x-7)/(x**2+(3+i)*x+3*i);
off gcd;
sqrt(x**4+14*i*x**3-51*x**2-14*i*x+1);
off complex;

%                             Complex Arithmetic
% It is possible to combine the complex evaluation with numeric operations to
% obtain complex floating point.  The following examples demonstrate this
% facility.

on complex, rounded;
(3.25 + 8.5i) + (6.75 - 8.5i);
(19.8 + 28.4*i)/(-5.6 + 7.8*i);
(-7.0 + 24.0*i)**(1/2);
asin(1.0 + 1.0*i);
log(1.0 + 1.0*i);
off complex, rounded;

%                               333
%                              3   3
%                                  3
%                                33
%                                  3
%                              3   3
%                               333

% REDUCE has extensive analytic differentiation and integration facilities.
% In addition to differentiation of polynomials with rational coefficients,
% the transcendental functions are also supported.  The system supports
% multiple differentiation and differentiation by multiple variables.  Users
% may also enter patterns for differentiating unsupported functions.

% The REDUCE integrator supports both pattern driven and Risch algorithm
% integration for transcendental functions such as logs and exponentials.
% A second package (not demonstrated here) supports integration of
% expressions involving square roots.

%                           Simple Differentiation
% The REDUCE DF function differentiates its first argument with respect to
% the variable listed as the second.  To differentiate the basic quadratic
% expression with respect to x you enter:

df(a*x^2 + b*x + c, x);

%... to differentiate multiple times:

df(a*x^2 + b*x + c, x, 2);

% ... or with respect to multiple variables:

df(x^2*y^2*z + 3*x*y*z - 4*x*y*z^3, x, y, z);

%                                Dependencies
% There are several facilities in REDUCE, such as differentiation and linear
% operators, that can utilize knowledge of the dependencies between
% variables or kernels (expressions with a single top level main function).
% In this case, the differentiation function leaves the variable
% undifferentiated.

depend x, y;
df(x * cos x^2 * a, y);
nodepend x, y;

%                                 An Example
% In this longer example, we demonstrate the computation of f and g series
% in astronomy (see Sconzo, P., Leschack, A. R. and Tobey, R. G., Astronomical
% Journal, Vol. 70, May 1965). On this first page we set up a number of
% variables. By using the dollar sign terminator, we avoid printing the values
% computed as they aren't essential to the computation.

deps:= -sig*(mu+2*eps)$
dmu:= -3*mu*sig$
dsig:= eps-2*sig^2$
f1:= 1$
g1:= 0$

% We now compute values of f1, and g1 repeatedly using differentiation
% and the REDUCE FOR loop. The REDUCE WRITE statement is used to display
% values, and the << ... >> brackets to delineate a block of executable code.
% The output from this example takes several pages.

for i:= 1:8 do
 << f2:= -mu*g1 + deps*df(f1,eps) + dmu*df(f1,mu) + dsig*df(f1,sig);
    write "F(",i,") := ",f2;
    g2:= f1 + deps*df(g1,eps) + dmu*df(g1,mu) + dsig*df(g1,sig);
    write "G(",i,") := ",g2;
    f1:=f2;
    g1:=g2 >>;
clear f1, f2, g1, g2, mu, deps, dmu, sig, dsig, eps;

%                              Another Example
% Suppose we need a function P(N,X) which, for any positive integer N, is the
% Legendre polynomial of order N. We can define this operator using the
% formula of Rodrigues:

algebraic procedure p(n,x);
  df((x^2 - 1)^n, x, n) / (2^n * factorial n)$

% Calling p with different values of n gives the first few of these Legendre
% polynomials:

p(1, x);
p(3, x);
p(5, x);
clear p;

%                        Adding Differentiation Rules
% The LET statement used earlier can also be used for the introduction of
% rules differentiation of user defined operators.  For example,
% differentiation of the dilog function is defined by the following rule
% in the current REDUCE:

for all x let df(dilog x,x)=-log x/(x-1);
df(dilog y, y);
df(x * dilog x * log x, x);

% We often introduce differentiation rules to help the REDUCE integrator.
% Examples of this activity will be presented in the integration section.

%                                Integration
% The REDUCE integrator is based on the revised integration method of Risch
% and Norman, and also supports pattern matching. The INT operator accepts
% an expression and an integration variable and can successfully compute
% the indefinite integral for expressions comprising polynomials, log
% functions, exponential functions, most circular functions. The arbitrary
% constant is not represented.

int(x, x);
int(x^5*log(x)^3, x);

%                               More Examples

int(1/sin x, x);
int(1/(x^8-1), x);

%                          Unsuccessful Integration
% If the integral cannot be done in closed terms, it is returned in its
% original form (or as a combination of other INT terms). For example:

int(e^(-x^2),x);
df(int(e^(-x^2), x), x);

%                           Patterns and Integration
% The integrator can also make use of patterns both as INT patterns and to
% meet the requirements for the differentiation of a function.  For example,
% the differentiation of DILOG given earlier allows us to integrate
% expressions using it.

for all a let df(dilog a, a) = log(a) / (a+1);
int(x*dilog(x), x);

%                             Risch Integration
% The following two integrations are difficult to perform without the Risch
% Integration code.

int(log(2+3*x**2),x);
int(2*x*e**(x**2)*log(x)+e**(x**2)/x+(log(x)-2)/(log(x)**2+x)**2+
    ((2/x)*log(x)+(1/x)+1)/(log(x)**2+x),x);

%                         Pattern Driven Integration
% Like differentiation, it is possible to define patterns for integration. As
% shown previously, some forms require you provide a pattern for
% differentiation. In this example, we show the integration of forms
% resulting in a function foo.

operator foo;
for all m,n let
 int(k1**m*log(k1)**n/(p**2-k1**2),k1)=foo(m,n),
  int(k1*log(k1)**n/(p**2-k1**2),k1)=foo(1,n),
  int(k1**m*log(k1)/(p**2-k1**2),k1)=foo(m,1),
  int(k1*log(k1)/(p**2-k1**2),k1)=foo(1,1),
  int(log(k1)**n/(k1*(p**2-k1**2)),k1)=foo(-1,n);
int(k1**2*log(k1)/(p**2-k1**2),k1);
for all m,n clear int(k1**m*log(k1)**n/(p**2-k1**2),k1),
       int(k1*log(k1)**n/(p**2-k1**2),k1),
       int(k1**m*log(k1)/(p**2-k1**2),k1),
       int(k1*log(k1)/(p**2-k1**2),k1),
       int(log(k1)**n/(k1*(p**2-k1**2)),k1);

%                               A Harder Example
% This example is difficult without the Risch integration code.

factor int;   % This makes the output more appealing.

int((12*log(s/mc**2)*s**2*pi**2*mc**3*(-8*s-12*mc**2+3*mc)
 + pi**2*(12*s**4*mc+3*s**4+176*s**3*mc**3-24*s**3*mc**2
 -144*s**2*mc**5-48*s*mc**7+24*s*mc**6+4*mc**9-3*mc**8))
  /(384*e**(s/y)*s**2), s);


%                             4  4
%                             4  4
%                             4  4
%                             44444
%                                4
%                                4
%                                4

%                        Matrix Operations

% A very powerful feature of the REDUCE system is the ease with which matrix
% calculations can be performed.  Matrices can be added, subtracted,
% multiplied, divided, and raised to a power (the inverse of a matrix is
% calculated by raising it to the -1 power).  The system can compute the
% determinant of a square matrix, the transpose of any matrix, and the
% trace of a matrix.  Likewise, you can compute the eigenvalue equation and
% corresponding eigenvectors of a matrix.

%                                Matrix Input
% Matrices are created directly with the MAT function. For example, the matrix
%               -         -
%               | A  B  C |
%               | D  E  F |
%               -         -
% is created and displayed by REDUCE as follows:

mat((a,b,c), (d,e,f));

%                              Matrix Creation
% Empty matrices can also be created as can matrices with whose size will be
% declared later. In the following example, I create a 2x2 identity matrix.

matrix m(2, 2);
for i:=1:2 do m(i,i) := 1$
m;
clear m;

%                            Matrix Arithmetic
% Matrix addition and subtraction is on an element by element basis between
% matrices of identical size. As usual, the elements of the matrix can be
% algebraic expressions of any complexity. Matrix multiplication between
% conformal matrices is conventional.

mat((a + b, c), (1, cos x)) * mat((1, 2), (3, x));

%                         Matrix Division - Inverse
% For two matrices A and B, A/B is interpreted as A times the inverse of B.
% REDUCE can also compute the determinant of a matrix or raise a matrix to an
% integer power. The following example performs matrix inversion,
% multiplication, and exponentiation:

mat((a, b), (c, d))^2 / mat((a, b), (c, d));

%                                 An Example
% The display of three dimensional objects on a two dimensional surface is
% accomplished by the perspective transformation of the points representing
% the three dimensional surface. Similarly, the points of the 3D object can
% be moved, rotated, and scaled by other transformations. Combining the
% perspective transformation with a translation, rotation and scale is
% accomplished in the following code. The result is a mapping of three space
% coordinates x, y, and z into 2 space coordinates x2, and y2.  Here xt, yt,
% and zt translations; xm, ym, and zm are scale factors, xa, ya, and za are
% rotations about the x, y, and z axes; and d the distance from the eye to the
% projection plane.  The following lines build the translation, scale,
% rotation, and projection transformation matrices.

translate := mat((1,0,0,0), (0,1,0,0), (0,0,1,0), (xt,yt,zt,1))$
scale := mat((xm,0,0,0), (0,ym,0,0), (0,0,zm,0),(0,0,0,1))$
rotatex := mat((1,0,0,0),(0,cos xa,sin xa,0),(0,-sin xa,cos xa,0),(0,0,0,1))$
rotatey := mat((cos ya,0,-sin ya,0),(0,1,0,0),(sin ya,0,cos ya,0),(0,0,0,1))$
rotatez := mat((cos za,sin za,0,0),(-sin za,cos za,0,0),(0,0,1,0),(0,0,0,1))$
project := mat((1,0,0,0),(0,1,0,0),(0,0,1,1/d),(0,0,0,0))$

%                             3D -> 2D (continued)
% We now construct the equations for three space x3, y3, and z3 by applying
% all the transformations to the three space point (x,y,z,1).  This involves
% multiplying the matrix (x,y,z,1) by the product of all transformations (the
% order is important).  The value of x2 and y2 are computed from the
% resulting vector by dividing out the 4th dimension.

result := mat((x,y,z,1)) * project * rotatez * rotatey * rotatex *
    translate * scale$
x2 := result(1,1) / result(1,4);
y2 := result(1,2) / result(1,4);

%                            3D -> 2D (continued)
% Our ultimate purpose is to construct a Fortran program to perform the trans-
% formation. The fort flag signals all output to be in Fortran statements.

on fort;
x2 := result(1,1) / result(1,4);
y2 := result(1,2) / result(1,4);

% REDUCE contains a more advanced output package named GENTRAN which is
% capable of generating C and Fortran output as well as automatically placing
% the generated statements into a template program. This and other packages
% such as SCOPE can also  restructure the output expression to minimize
% the number of continuation lines (some compilers have a restriction).

off fort;
clear scale, translate, rotatex, rotatey, rotatez, project, result, x2, y2;


%                              55555
%                              5
%                              5
%                              5555
%                                  5
%                              5   5
%                               555
%                     Solutions of Equations

% The SOLVE operator is used for solving one or more simultaneous algebraic
% equations.  The function can accept a single equation (with or without the
% equals sign) or a list of equations enclosed in curly brackets {...}.  In
% fact REDUCE has full list processing capabilities in algebraic mode
% including such operators as FIRST, SECOND, THIRD, REST, LENGTH, REVERSE,
% and APPEND.  In symbolic mode, REDUCE has the semantics of the Lisp on
% which it is implemented.  All the functions of the particular
% implementation are available.

%                              Simple Equations
% SOLVE is capable of solving various equations for named variables. The
% following examples demonstrate some of the capabilities.

solve(a*x^2 + b*x + c, x);

%                          SOLVE - Harder problems
% Here, SOLVE uses square-free factorization together with recursive use of
% quadratic and binomial solutions. The multiplicities!* variable contains a
% list with the multiplicity of each root. The system obligingly locates the
% unknown variable. The output from this example is three pages long.

solve((x^6 - x^3 - 1)*(x^5 - 1)^2 * x^2);
multiplicities!*;

%                            Solving Exponentials
% Here we see an example with the variable as an exponent. There are many
% solutions which the system indicates with ARBINT(n) where n is used to
% separate different occurrences of the integer.

solve(a^(2*x) - 3*a^x + 2, x);

%                       Solving with Respect to Kernels
% It is also possible to solve equations with respect to some equations as
% shown in this implicit differentiation example. Here w is made to depend on
% the variables x, y. We differentiate the equation f and solve for the
% partials left laying around.

depend w, x, y;
f := 3x^2 + 2y^2 + 6w^2 - x + y - 12$
solve(df(f, x), df(w, x));
solve(df(f, y), df(w, y));

% A second implicit differentiation example.

f := e^(x*y*w)*sin(x*y)*cos(2*x*w) - 4$
solve(df(f, x), df(w, x));
solve(df(f, y), df(w, y));
nodepend w;
clear f;

%                         Systems of Linear Equations
% The solve routines can also work with regular, over-determined,
% inconsistent, and under-determined systems of linear equations.  We give
% the list of equations as the first argument, and the list of variables to
% solve for as the second.  For example, we solve some regular systems of
% linear equations.

solve({3x + 2y = 36, 2x - y = 17}, {x, y});
solve({2*x1+x2+3*x3-9, x1-2*x2+x3+2, 3*x1+2*x2+2*x3-7}, {x1, x2, x3});

%                      Under and Over determined Systems
% The system can also work with under- and over-determined sets of equations.
% Of course an under-determined set has lots of solutions.

on solvesingular;
solve({x1-4x2+2x3+1, 2x1-3x2-x3-5x4+7, 3x1-7x2+x3-5x4+8}, {x1,x2,x3,x4});
multiplicities!*;

% An over determined system of linear equations.

solve({x1-x2+x3-12, 2x1+3x2-x3-13, 3x2+4x3-5, -3x1+x2+4x3+20}, {x1,x2,x3});


%                                6
%                               6
%                              6
%                              6666
%                              6   6
%                              6   6
%                               666

%                    Groebner Bases Calculations


% The REDUCE GROEBNER package computes the Groebner Basis of a set of
% equations with respect to a given set of variables.  The computed basis is
% a function of the user-selected term ordering mode and the variable
% order.  The GROEBNER function computes this basis and returns it as a list.

%                          Calculating the Basis
% The GROEBNER function calculates the Groebner Basis of the given set of
% expressions with respect to the given set of variables.  The order
% defaults to the system order but special orderings are possible as the
% computer time and storage used are highly sensitive to the ordering.

load_package groebner;
groebner({3x^2y + 2x*y + y + 9x^2 + 5x - 3,
          2x^3y - x*y - y + 6x^3 - 2x^2 - 3x + 3,
          x^3y + x^2y + 3x^3 + 2x^2});

%                  Groebner Bases Calculations (continued)
% The GREDUCE function converts a list of expressions to a Groebner Basis and
% then reduces the given expression modulo that basis. For example:

greduce(5y^2 +2x^2y + 5/2x*y + 3/2y + 8x^2 +3/2x - 9/2,
        {3x^2y + 2x*y + y + 9x^2 + 5x - 3,
         2x^3y - x*y - y + 6x^3 - 2x^2 - 3x + 3,
         x^3y + x^2y + 3x^3 + 2x^2});

%                 Groebner Bases Calculations (continued)
% The operators defined in this package can operate over any polynomial
% coefficient domain supported by REDUCE. For example, the following computes
% the Groebner Basis over ratios of gaussian integers using a different
% ordering.

torder revgradlex;
on complex;
groebner({3*x^2*y + 2*i*x*y + y + 9*x^2 + 5*x = 3,
          2*x^3*y - x*y - y + 6*i*x^3 - 2*x^2 - 3*x = -3,
          x^3*y + x^2*y + 3*x^3 + 2*x^2},
          {x, y});
off complex;


%                              77777
%                                  7
%                                 7
%                                7
%                               7
%                              7
%                              7

%                Arbitrary Precision Floating Point

% Arbitrary precision floating point is an extension to the default fixed
% precision floating-point arithmetic.  Here the number of digits of
% accuracy is set before a computation begins and all computations are
% carried through to this accuracy.

%                         "Bigfloat" Evaluation
% Here we signal that computations are to be numerically evaluated to the
% default precision, then 25 digits.

on rounded;
cos 1.0;
sqrt 2;
precision 25;
cos 1.0;
sqrt 2;

%                                    An Example
% Here we see the power of the big float system.  With the default precision
% ("precision 1;" achieves this) we create some values:

precision 1;
let xx=e**(pi*sqrt(163));

% Notice that xx looks like an integer:

xx;

% But it's of course an illusion...

precision 40;
xx;
off rounded;
clear xx;


%                               888
%                              8   8
%                              8   8
%                               888
%                              8   8
%                              8   8
%                               888

%                      Algebraic Number Fields

% Algebraic numbers are the solutions of an irreducible polynomial over some
% ground domain. The arithmetic of algebraic numbers can be viewed as
% polynomial arithmetic modulo the defining polynomial.

%                         Introducing Algebraic Numbers
% We first introduce an algebraic number with the defpoly operator. This
% sqrt2 number is used in subsequent operations.

load_package arnum;
defpoly sqrt2^2 - 2;
1/(sqrt2 + 1);
sqrt(x^2 - 2*sqrt2*x*y + 2*y^2);

%                     Working with multiple Algebraic Numbers
% We work with multiple algebraic numbers by defining multiple polynomials.

defpoly sqrt2^2-2, cbrt5^3-5;
sqrt2;
sqrt2^2;


%                               999
%                              9   9
%                              9   9
%                               9999
%                                  9
%                                 9
%                                9

%                        Other Features

% 1) Extended Factorization and GCD computations.
% 2) Exterior Calculus.
% 3) Symmetries of Partial Differential Equations.
% 4) High Energy Physics Computations.


%                                Factorization
% REDUCE is capable of factorizing univariate and multivariate polynomials
% that have integer coefficients, finding all factors that also have integer
% coefficients. The FACTORIZE function returns a list of factors of its
% argument:

factorize(x^2 - x*y^2 + x*y - y^3);

% The prime factors of integer factors can also be expanded:

on ifactor;
factorize(12x^2 - 12);

% Factorization can be performed with modular polynomial coefficients:

setmod 7;
on modular;
factorize(x^4 + 1);

%                                Exterior Calculus

% The EXCALC package is designed for easy use by those familiar with the
% calculus of Modern Differential Geometry. The package makes a great many
% additions to the set of REDUCE operators, including: ^ wedge, @ partial
% differentiation, exterior differentiation, _| inner product, |_ Lie
% derivative, # Hodge duality operator, and other extensions.


%              Determining Symmetries of Partial Differential Equations

% The SPDE package provides a set of functions for determining the symmetry
% group of Lie- or point-symmetries of a partial differential equations.

%                        High Energy Physics Calculations
% The REDUCE High Energy Physics package introduces operators for gamma
% matrices, vector expressions, Dirac expressions, Trace calculations, and
% mass declarations.  The following example is taken from the REDUCE test
% file and computes the Compton scattering cross-section.

on div;
mass ki= 0, kf= 0, p1= m, pf= m;
vector ei,ef;
mshell ki,kf,p1,pf;
let p1.ei= 0, p1.ef= 0, p1.pf= m**2+ki.kf, p1.ki= m*k,p1.kf=
    m*kp, pf.ei= -kf.ei, pf.ef= ki.ef, pf.ki= m*kp, pf.kf=
    m*k, ki.ei= 0, ki.kf= m*(k-kp), kf.ef= 0, ei.ei= -1, ef.ef=
    -1;
operator gp;
for all p let gp(p)= g(l,p)+m;
gp(pf)*(g(l,ef,ei,ki)/(2*ki.p1) + g(l,ei,ef,kf)/(2*kf.p1))
  * gp(p1)*(g(l,ki,ei,ef)/(2*ki.p1) + g(l,kf,ef,ei)/(2*kf.p1))$
write "The Compton cross-section is ",ws;

% There are many more facilities in REDUCE that I have not discussed.
% Please consult the REDUCE User's Manual and supporting documentation for
% further details.

end;
