#$+ KIDENTIFIER				type

 Identifiers in REDUCE consist of one or more alphanumeric characters, of which the first must be alphabetical. The maximum number of characters allowed is system dependent, but is usually over 100. However, printing is simplified if they are kept under 25 characters. 

You can also use special characters in your identifiers, but each must be preceded by an exclamation point !  as an escape character. Useful special characters are  # $ % ^ & * - + = ? < > ~ | / !  and the space. Note that the use of the exclamation point as a special character requires a second exclamation point as an escape character. The underscore _  is special in this regard. It must be preceded by an escape character in the first position in an identifier, but is treated like a normal letter within an identifier. 

Other characters, such as ( ) # ; ` ' "  can also be used if preceded by a ! , but as they have special meanings to the Lisp reader it is best to avoid them to avoid confusion. 

Many system identifiers have * before or after their names, or - between words. If you accidentally pick one of these names for your own identifier, it could have disastrous effects. For this reason it is wise not to include * or - anywhere in your identifiers. 

You will notice that REDUCE does not use the escape characters when it prints identifiers containing special characters; however, you still must use them when you refer to these identifiers. Be careful when editing statements containing escaped special characters to treat the character and its escape as an inseparable pair. 

Identifiers are used for variable names, labels for go to  statements, and names of arrays, matrices, operators, and procedures. Once an identifier is used as a matrix, array, scalar or operator identifier, it may not be used again as a matrix, array or operator. An operator or array identifier may later be used as a scalar without problems, but a matrix identifier cannot be used as a scalar. All procedures are entered into the system as operators, so the name of a procedure may not be used as a matrix, array, or operator identifier either.  

#$+ KKERNEL				type

 A kernel  is a form that cannot be modified further by the REDUCE canonical simplifier. Scalar variables are always kernels. The other important class of kernels are operators with their arguments. Some examples should help clarify this concept: 

        Expression                     Kernel? 
 
          x                              Yes 
          varname                        Yes 
          cos(a)                         Yes 
          log(sin(x**2))                 Yes 
          a*b                            No 
          (x+y)**4                       No 
          matrix-identifier              No 
Many REDUCE operators expect kernels among their arguments. Error messages result from attempts to use non-kernel expressions for these arguments.  

#$+ KSTRING				type

 A string  is any collection of characters enclosed in double quotation marks (" ). It may be used as an argument for a variety of commands and operators, such as in , rederr  and write .  
examples: 
 
write "this is a string";  
 
  this is a string  

write a, " ", b, " ",c,"!";  
 
  A B C! 

#$+Concepts

	IDENTIFIER type
	KERNEL type
	STRING type

#$+ KASSUMPTIONS				variable

After solving a linear or polynomial equation system with parameters, the variable assumptions  contains a list of side relations for the parameters. The solution is valid only as long as none of these expression is zero.  
examples: 
 
solve({a*x-b*y+x,y-c},{x,y}); 
 
       b*c 
  {{x=-----,y=c}}  
      a + 1 

assumptions;  
 
  {a + 1} 

#$+ KCARD‑NO				variable

card_no sets the total number of cards allowed in a Fortran output statement when fort  is on. Default is 20. 

examples: 
 
on fort;  
 
card_no := 4;  
 
  CARD_NO=4.  

z := (x + y)**15;  
 
        ANS1=5005.*X**6*Y**9+3003.*X**5*Y**10+1365.*X**4*Y** 
       . 11+455.*X**3*Y**12+105.*X**2*Y**13+15.*X*Y**14+Y**15 
        Z=X**15+15.*X**14*Y+105.*X**13*Y**2+455.*X**12*Y**3+  
       . 1365.*X**11*Y**4+3003.*X**10*Y**5+5005.*X**9*Y**6+ 
       . 6435.*X**8*Y**7+6435.*X**7*Y**8+ANS1 
 
Twenty total cards means 19 continuation cards. You may set it for more if your Fortran system allows more. Expressions are broken apart in a Fortran-compatible way if they extend for more than card_no  continuation cards. 

#$+ KE				constant

 The constant e  is reserved for use as the base of the natural logarithm. Its value is approximately 2.71828284590, which REDUCE gives to the current decimal precision when the switch rounded  is on. 

e may be used as an iterative variable in a for  statement, or as a local variable or a procedure . If e  is defined as a local variable inside the procedure, the normal definition as the base of the natural logarithm would be suspended inside the procedure. 

#$+ KEVAL‑MODE				variable

The system variable eval_mode  contains the current mode, either algebraic  or symbolic . 

examples: 
 
EVAL‑MODE;  
 
  ALGEBRAIC 
 
Some commands do not behave the same way in algebraic and symbolic modes. 

#$+ KFORT‑WIDTH				variable

The fort_width  variable sets the number of characters in a line of Fortran-compatible output produced when the fort  switch is on. Default is 70. 

examples: 
 
fort_width := 30;  
 
  FORT_WIDTH := 30   

on fort;  
 
df(sin(x**3*y),x);  
 
        ANS=3.*COS(X 
       . **3*Y)*X**2* 
       . Y 
 
fort_width includes the usually blank characters at the beginning of the card. As you may notice above, it is conservative and makes the lines even shorter than it was told. 

#$+ KHIGH‑POW				variable

The variable high_pow  is set by coeff  to the highest power of the variable of interest in the given expression. You can access this variable for use in further computation or display. 

examples: 
 
coeff((x+1)^5*(x*(y+3)^2)^2,x);  
 
  {0, 
   0, 
    4       3       2 
   Y  + 12*Y  + 54*Y  + 108*Y + 81, 
       4       3       2 
   5*(Y  + 12*Y  + 54*Y  + 108*Y + 81), 
        4       3       2 
   10*(Y  + 12*Y  + 54*Y  + 108*Y + 81), 
        4       3       2 
   10*(Y  + 12*Y  + 54*Y  + 108*Y + 81), 
       4       3       2 
   5*(Y  + 12*Y  + 54*Y  + 108*Y + 81), 
    4       3       2 
   Y  + 12*Y  + 54*Y  + 108*Y + 81} 

high_pow;  
 
  7 

#$+ KI				constant

REDUCE knows i  is the square root of -1,  and that i^2 = -1. 

examples: 
 
(a + b*i)*(c + d*i);  
 
  A*C + A*D*I + B*C*I - B*D  

i**2;  
 
  -1 
 
i cannot be used as an identifier. It is all right to use i  as an index variable in a for  loop, or as a local (scalar ) variable inside a begin...end  block, but it loses its definition as the square root of -1 inside the block in that case. 

Only the simplest properties of i are known by REDUCE unless the switch complex  is turned on, which implements full complex arithmetic in factoring, simplification, and functional values. complex  is ordinarily off. 

#$+ KINFINITY				constant

 The name infinity  is used to represent the infinite positive number. However, at the present time, arithmetic in terms of this operator reflects finite arithmetic, rather than true operations on infinity. 

#$+ KLOW‑POW				variable

The variable low_pow  is set by coeff  to the lowest power of the variable of interest in the given expression. You can access this variable for use in further computation or display. 

examples: 
 
coeff((x+2*y)**6,y);  
 
    6 
  {X , 
       5 
   12*X , 
       4 
   60*X , 
        3 
   160*X , 
        2 
   240*X , 
   192*X, 
   64} 

low_pow;  
 
  0  

coeff(x**2*(x*sin(y) + 1),x);  

 
  {0,0,1,SIN(Y)}  

low_pow;  
 
  2 

#$+ KNIL				constant

nil represents the truth value false in symbolic mode, and is a synonym for 0 in algebraic mode. It cannot be used for any other purpose, even inside procedures or for  loops. 

#$+ KPI				constant

 The identifier pi  is reserved for use as the circular constant. Its value is given by 3.14159265358..., which REDUCE gives to the current decimal precision when REDUCE is in a floating-point mode. 

pi may be used as a looping variable in a for  statement, or as a local variable in a procedure . Its value in such cases will be taken from the local environment. 

#$+ KREQUIREMENTS				variable

After an attempt to solve an inconsistent equation system with parameters, the variable requirements  contains a list of expressions. These expressions define a set of conditions implicitly equated with zero. Any solution to this system defines a setting for the parameters sufficient to make the original system consistent.  
examples: 
 
solve({x-a,x-y,y-1},{x,y});  
 
  {} 

requirements; 
 
  {a - 1} 

#$+ KROOT‑MULTIPLICITIES				variable

The root_multiplicities  variable is set to the list of the multiplicities of the roots of an equation by the solve  operator. 

solve returns its solutions in a list. The multiplicities of each solution are put in the corresponding locations of the list root_multiplicities . 

#$+ KT				constant

 The constant t  stands for the truth value true. It cannot be used as a scalar variable in a block , as a looping variable in a for  statement or as an operator  name. 

#$+Variables

	assumptions variable
	CARD‑NO variable
	E constant
	EVAL‑MODE variable
	FORT‑WIDTH variable
	HIGH‑POW variable
	I constant
	INFINITY constant
	LOW‑POW variable
	NIL constant
	PI constant
	requirements variable
	ROOT‑MULTIPLICITIES variable
	T constant

#$+ K;	SEMICOLON				command

 The semicolon is a statement delimiter, indicating results are to be printed when used in interactive mode. 

examples: 
 
(x+1)**2;  
 
   2 
  X  + 2*X + 1  

df(x**2 + 1,x);  
 
  2*X 
 
Entering a Return  without a semicolon or dollar sign results in a prompt on the following line. A semicolon or dollar sign can be added at this point to execute the statement. In interactive mode, a statement that is ended with a semicolon and Return  has its results printed on the screen. 

Inside a group statement << ...>>  or a begin ...end  block, a semicolon or dollar sign separates individual REDUCE statements. Since results are not printed from a block without a specific return  statement, there is no difference between using the semicolon or dollar sign. In a group statement, the last value produced is the value returned by the group statement. Thus, if a semicolon or dollar sign is placed between the last statement and the ending brackets, the group statement returns the value 0 or nil, rather than the value of the last statement. 

#$+ K$	DOLLAR				command

 The dollar sign is a statement delimiter, indicating results are not to be printed when used in interactive mode. 

examples: 

(x+1)**2$ The workspace is set to x^2 + 2x + 1  but nothing shows on the screen 

ws;  
 
   2 
  X   + 2*X + 1 

Entering a Return  without a semicolon or dollar sign results in a prompt on the following line. A semicolon or dollar sign can be added at this point to execute the statement. In interactive mode, a statement that ends with a dollar sign $  and a Return  is executed, but the results not printed. 

Inside a group  statement << ...>>  or a begin ...end  block , a semicolon or dollar sign separates individual REDUCE statements. Since results are not printed from a block  without a specific return 

statement, there is no difference between using the semicolon or dollar sign. 

In a group statement, the last value produced is the value returned by the group statement. Thus, if a semicolon or dollar sign is placed between the last statement and the ending brackets, the group statement returns the value 0 or nil, rather than the value of the last statement. 

#$+ K%	PERCENT				command

 The percent sign is used to precede comments; everything from a percent to the end of the line is ignored. 

examples: 

df(x**3 + y,x); This is a comment {Return}  

     2 
  3*X   

int(3*x**2,x) This is a comment; {Return}  
A prompt is given, waiting for the semicolon that was not detected in the comment 

Statement delimiters ;  and $  are not detected between a percent sign and the end of the line. 

#$+ K.	DOT				operator

The . (dot) infix binary operator adds a new item to the beginning of an existing list . In high energy physics expressions, it can also be used to represent the scalar product of two Lorentz four-vectors. 

syntax: 
<item> .  <list> 

<item> can be any REDUCE scalar expression, including a list; <list> must be a list  to avoid producing an error message. The dot operator is right associative. 

examples: 

liss := a . {};  
 
  LISS := {A}  

liss := b . liss;  
 
  LISS := {B,A}  

newliss := liss . liss;  
 
  NEWLISS := {{B,A},B,A}  

firstlis := a . b . {c};  
 
  FIRSTLIS := {A,B,C}  

secondlis := x . y . {z};  
 
  SECONDLIS := {X,Y,Z}  

for i := 1:3 sum part(firstlis,i)*part(secondlis,i); 

 
  A*X + B*Y + C*Z 

#$+ K:=	ASSIGN				operator

The :=  is the assignment operator, assigning the value on the right-hand side to the identifier or other valid expression on the left-hand side. 

syntax: 
<restricted‑expression> :=  <expression> 

<restricted‑expression> is ordinarily a single identifier, though simple expressions may be used (see Comments below). <expression> is any valid REDUCE expression. If <expression> is a matrix  identifier, then <restricted‑expression> can be a matrix identifier (redimensioned if necessary) which has each element set to the corresponding elements of the identifier on the right-hand side. 

examples: 
 
a := x**2 + 1;  
 
        2 
  A := X   + 1  

a;  
 
   2 
  X  + 1  

first := second := third;  
 
  FIRST := SECOND := THIRD  

first;  
 
  THIRD  

second;  
 
  THIRD  

b := for i := 1:5 product i;  
 
  B := 120  

b;  
 
  120  

w + (c := x + 3) + z;  
 
  W + X + Z + 3  

c;  
 
  X + 3  

y + b := c;  
 
  Y + B := C  

y;  
 
  - (B - C) 
 
The assignment operator is right associative, as shown in the second and third examples. A string of such assignments has all but the last item set to the value of the last item. Embedding an assignment statement in another expression has the side effect of making the assignment, as well as causing the given replacement in the expression. 

Assignments of values to expressions rather than simple identifiers (such as in the last example above) can also be done, subject to the following remarks: 

	(i) If the left-hand side is an identifier, an operator, or a power, the substitution rule is added to the rule table. 

	(ii) If the operators - + /  appear on the left-hand side, all but the first term of the expression is moved to the right-hand side. 

	(iii) If the operator *  appears on the left-hand side, any constant terms are moved to the right-hand side, but the symbolic factors remain. 

Assignment is valid for array  elements, but not for entire arrays. The assignment operator can also be used to attach functionality to operators. 

A recursive construction such as a := a + b  is allowed, but when a  is referenced again, the process of resubstitution continues until the expression stack overflows (you get an error message). Recursive assignments can be done safely inside controlled loop expressions, such as for ... or repeat ...until . 

#$+ K=	EQUALSIGN				operator

 The =  operator is a prefix or infix equality comparison operator. 

syntax: 
= (<expression>, <expression>)  or  <expression> =  <expression> 

<expression> can be any REDUCE scalar expression. 

examples: 
 
a := 4;  
 
  A := 4  

if =(a,10) then write "yes" else write "no"; 

 
  no  

b := c;  
 
  B := C  

if b = c then write "yes" else write "no"; 

 
  yes  

on rounded;  
 
if 4.0 = 4 then write "yes" else write "no"; 

 
  yes 
 
This logical equality operator can only be used inside a conditional statement, such as if ...then ...else  or repeat ...until . In other places the equal sign establishes an algebraic object of type equation . 

#$+ K=>	REPLACE				operator

The =>  operator is a binary operator used in rule  lists to denote replacements. 

examples: 
 
operator f;  
 
let f(x) => x^2;  
 
f(x);  
 
   2 
  x 

#$+ K+	PLUSSIGN				operator

 The +  operator is a prefix or infix n-ary addition operator. 

syntax: 
<expression> {+ <expression>}+ 

or + (<expression> {,<expression>}+) 

<expression> may be any valid REDUCE expression. 

examples: 
 
x**4 + 4*x**2 + 17*x + 1;  
 
   4      2 
  X  + 4*X  + 17*X + 1  

14 + 15 + x;  
 
  X + 29  

+(1,2,3,4,5);  
 
  15 
 
+ is also valid as an addition operator for matrix  variables that are of the same dimensions and for equation s. 

#$+ K-	MINUSSIGN				operator

 The -  operator is a prefix or infix binary subtraction operator, as well as the unary minus operator. 

syntax: 
<expression> -  <expression> or - (<expression>,<expression>) 

<expression> may be any valid REDUCE expression. 

examples: 
 
15 - 4;  
 
  11  

x*(-5);  
 
  - 5*X  

a - b - 15;  
 
  A - B - 15  

-(a,4);  
 
  A - 4 
 
The subtraction operator is left associative, so that a - b - c is equivalent to (a - b) - c, as shown in the third example. The subtraction operator is also valid with matrix  expressions of the correct dimensions and with equation s. 

#$+ K*	ASTERISK				operator

 The *  operator is a prefix or infix n-ary multiplication operator. 

syntax: 
<expression> {*  <expression>}+ 

or * (<expression> {,<expression>}+) 

<expression> may be any valid REDUCE expression. 

examples: 
 
15*3;  
 
  45  

24*x*yvalue*2;  
 
  48*X*YVALUE  

*(6,x);  
 
  6*X  

on rounded;  
 
3*1.5*x*x*x;  
 
       3 
  4.5*X   

off rounded;  
 
2x**2;  
 
     2 
  2*X 
 
REDUCE assumes you are using an implicit multiplication operator when an identifier is preceded by a number, as shown in the last line above. Since no valid identifiers can begin with numbers, there is no ambiguity in making this assumption. 

The multiplication operator is also valid with matrix  expressions of the proper dimensions: matrices A and B can be multiplied if A is n x m and B is m x p. Matrices and equation s can also be multiplied by scalars: the result is as if each element was multiplied by the scalar. 

#$+ K/	SLASH				operator

 The /  operator is a prefix or infix binary division operator or prefix unary recip rocal operator. 

syntax: 
<expression>/ <expression> or  / <expression> 

or / (<expression>,<expression>) 

<expression> may be any valid REDUCE expression. 

examples: 
 
20/5;  
 
  4   

100/6;  
 
  50 
  --  
  3 

16/2/x;  
 
  8 
  -  
  X 

/b;  
 
  1 
  -  
  B 

/(y,5);  
 
  Y 
  -  
  5 

on rounded;  
 
35/4;  
 
  8.75  

/20;  
 
  0.05 
 
The division operator is left associative, so that a/b/c  is equivalent to (a/b)/c . The division operator is also valid with square matrix  expressions of the same dimensions: With A and B both n x n matrices and B invertible, A/B is given by A*B^-1. Division of a matrix by a scalar is defined, with the results being the division of each element of the matrix by the scalar. Division of a scalar by a matrix is defined if the matrix is invertible, and has the effect of multiplying the scalar by the inverse of the matrix. When /  is used as a reciprocal operator for a matrix, the inverse of the matrix is returned if it exists. 

#$+ K**	POWER				operator

 The **  operator is a prefix or infix binary exponentiation operator. 

syntax: 
<expression> ** <expression>  or ** (<expression>,<expression>) 

<expression> may be any valid REDUCE expression. 

examples: 
 
x**15;  
 
   15 
  X    

x**y**z;  
 
   Y*Z 
  X     

x**(y**z);  
 
    Z 
   Y 
  X    

 **(y,4);  
 
   4 
  Y   

on rounded;  
 
2**pi;  
 
  8.82497782708 
 
The exponentiation operator is left associative, so that a**b**c  is equivalent to (a**b)**c , as shown in the second example. Note that this is not a**(b**c) , which would be right associative. 

When nat  is on (the default), REDUCE output produces raised exponents, as shown. The symbol ^ , which is the upper-case 6 on most keyboards, may be used in the place of ** . 

A square matrix  may also be raised to positive and negative powers with the exponentiation operator (negative powers require the matrix to be invertible). Scalar expressions and equation s may be raised to fractional and floating-point powers. 

#$+ K^	CARET				operator

 The ^  operator is a prefix or infix binary exponentiation operator. It is equivalent to power  or **. 

syntax: 
<expression> ^ <expression>  or ^ (<expression>,<expression>) 

<expression> may be any valid REDUCE expression. 

examples: 
 
x^15;  
 
   15 
  X    

x^y^z;  
 
   Y*Z 
  X     

x^(y^z);  
 
    Z 
   Y 
  X    

^(y,4);  
 
   4 
  Y   

on rounded;  
 
2^pi;  
 
  8.82497782708 
 
The exponentiation operator is left associative, so that a^b^c  is equivalent to (a^b)^c , as shown in the second example. Note that this is <not> a^(b^c) , which would be right associative. 

When nat  is on (the default), REDUCE output produces raised exponents, as shown. 

A square matrix  may also be raised to positive and negative powers with the exponentiation operator (negative powers require the matrix to be invertible). Scalar expressions and equation s may be raised to fractional and floating-point powers. 

#$+ K>=	GEQSIGN				operator

 >=  is an infix binary comparison operator, which returns true if its first argument is greater than or equal to its second argument. 

syntax: 
<expression> >=  <expression> 

<expression> must evaluate to an integer or floating-point number. 

examples: 
 
if (3 >= 2) then yes;  
 
  yes  

a := 15;  
 
  A := 15  

if a >= 20 then big else small; 

  small  
 
The binary comparison operators can only be used for comparisons between numbers or variables that evaluate to numbers. The truth values returned by such a comparison can only be used inside programming constructs, such as if ...then ...else  or repeat ...until  or while ...do . 

#$+ K>	GREATER				operator

 The >  is an infix binary comparison operator that returns  true if its first argument is strictly greater than its second. 

syntax: 
<expression> >  <expression> 

<expression> must evaluate to a number, e.g., integer, rational or floating point number. 

examples: 
 
on rounded;  
 
if 3.0 > 3 then write "different" else write "same";  

  same  

off rounded;  
 
a := 20;  
 
  A := 20  

if a > 20 then write "bigger" else write "not bigger";  

  not bigger  
 
The binary comparison operators can only be used for comparisons between numbers or variables that evaluate to numbers. The truth values returned by such a comparison can only be used inside programming constructs, such as if ...then ...else  or repeat ...until  or while ...do . 

#$+ K<=	LEQSIGN				operator

 <=  is an infix binary comparison operator that returns  true if its first argument is less than or equal to its second argument. 

syntax: 
<expression> <=  <expression> 

<expression> must evaluate to a number, e.g., integer, rational or floating point number. 

examples: 
 
a := 10;  
 
  A := 10  

if a <= 10 then true;  
 
  true 
 
The binary comparison operators can only be used for comparisons between numbers or variables that evaluate to numbers. The truth values returned by such a comparison can only be used inside programming constructs, such as if ...then ...else  or repeat ...until  or while ...do . 

#$+ K<	LESS				operator

 <  is an infix binary logical comparison operator that returns true if its first argument is strictly less than its second argument. 

syntax: 
<expression> <  <expression> 

<expression> must evaluate to a number, e.g., integer, rational or floating point number. 

examples: 
 
f := -3;  
 
  F := -3  

if f < -3 then write "yes" else write "no";  

  no 
 
The binary comparison operators can only be used for comparisons between numbers or variables that evaluate to numbers. The truth values returned by such a comparison can only be used inside programming constructs, such as if ...then ...else  or repeat ...until  or while ...do . 

#$+ K~	TILDE				operator

 The ~  is used as a unary prefix operator in the left-hand sides of rule s to mark free variable s. A double tilde marks an optional free variable . 

#$+ K<<	GROUP				command

 The << ...>>  command is a group statement, used to group statements together where REDUCE expects a single statement. 

syntax: 
<< <statement>{; <statement> or   <statement>}* >>  

<statement> may be any valid REDUCE statement or expression. 

examples: 
 
a := 2;  
 
  A := 2  

if a < 5 then <<b := a + 10; write b>>;  

  12  

<<d := c/15; f := d + 3; f**2>>; 

   2 
  C  + 90*C + 202 
  ---------------- 
        225 
 
The value returned from a group statement is the value of the last individual statement executed inside it. Note that when a semicolon is placed between the last statement and the closing brackets, 0 or  nil is returned. Group statements are often used in the consequence portions of if ...then , repeat ...until , and while ...do  clauses. They may also be used in interactive operation to execute several statements at one time. Statements inside the group statement are separated by semicolons or dollar signs. 

#$+ KAND				operator

 The and  binary logical operator returns true if both of its arguments are true. 

syntax: 
<logical‑expression> and  <logical‑expression> 

<logical‑expression> must evaluate to true or nil. 

examples: 
 
a := 12;  
 
  A := 12  

if numberp a and a < 15 then write a**2 else write "no"; 

 
  144  

clear a;  
 
if numberp a and a < 15 then write a**2 else write "no"; 

 
  no 
 
Logical operators can only be used inside conditional statements, such as while ...do  or if ...then ...else . and  examines each of its arguments in order, and quits, returning nil, on finding an argument that is not true. An error results if it is used in other contexts. 

and is left associative: x and y and z  is equivalent to (x and y) and z . 

#$+ KBEGIN				command

 begin  is used to start a block  statement, which is closed with end . 

syntax: 
begin <statement>{;  <statement>}* end  

<statement> is any valid REDUCE statement. 

examples: 
 
begin for i := 1:3 do write i end;  

  1 
  2 
  3      

begin scalar n;n:=1;b:=for i:=1:4 product(x-i);return n end; 

 
  1  

b;  
 
   4        3        2 
  X   - 10*X   + 35*X   - 50*X  + 24 
 
A begin ...end  block can do actions (such as write ), but does not return a value unless instructed to by a return  statement, which must be the last statement executed in the block. It is unnecessary to insert a semicolon before the end . 

Local variables, if any, are declared in the first statement immediately after begin , and may be defined as scalar, integer,  or real . array  variables declared within a begin ...end  block are global in every case, and let  statements have global effects. A let  statement involving a formal parameter affects the calling parameter that corresponds to it. let  statements involving local variables make global assignments, overwriting outside variables by the same name or creating them if they do not exist. You can use this feature to affect global variables from procedures, but be careful that you do not do it inadvertently. 

#$+ KBLOCK				command

 A block  is a sequence of statements enclosed by commands begin  and end . 

syntax: 
begin <statement>{;  <statement>}* end  

For more details see begin . 

#$+ KCOMMENT				command

 Beginning with the word comment , all text until the next statement terminator (;  or $ ) is ignored. 

examples: 

x := a**2 comment--a is the velocity of the particle;; 

 
        2 
  X := A 
 
Note that the first semicolon ends the comment and the second one terminates the original REDUCE statement. 

Multiple-line comments are often needed in interactive files. The comment  command allows a normal-looking text to accompany the REDUCE statements in the file. 

#$+ KCONS				operator

 The cons  operator adds a new element to the beginning of a list . Its operation is identical to the symbol dot  (dot). It can be used infix or prefix. 

syntax: 
cons (<item>,<list>) or <item> cons  <list> 

<item> can be any REDUCE scalar expression, including a list; <list> must be a list. 

examples: 

liss := cons(a,{b});  
 
  {A,B}  

 
liss := c cons liss;  
 
  {C,A,B}  

 
newliss := for each y in liss collect cons(y,list x); 

 
  NEWLISS := {{C,X},{A,X},{B,X}}  

 
for each y in newliss sum (first y)*(second y); 

 
  X*(A + B + C) 
 
If you want to use cons  to put together two elements into a new list, you must make the second one into a list with curly brackets or the list  command. You can also start with an empty list created by {} . 

The cons  operator is right associative: a cons b cons c  is valid if c  is a list; b  need not be a list. The list produced is {a,b,c} . 

#$+ KEND				command

 The command end  has two main uses: 

	(i) as the ending of a begin ...end  block ; and 
	(ii) to end input from a file. 

In a begin ...end  block , there need not be a delimiter (;  or $ ) before the end , though there must be one after it, or a right bracket matching an earlier left bracket. 

Files to be read into REDUCE should end with end; , which must be preceded by a semicolon (usually the last character of the previous line). The additional semicolon avoids problems with mistakes in the files. If you have suspended file operation by answering n  to a pause  command, you are still, technically speaking, ``in" the file. Use end  to exit the file. 

An end  at the top level of a program is ignored. 

#$+ KEQUATION				type

An equation  is an expression where two algebraic expressions are connected by the (infix) operator equal  or by = . For access to the components of an equation  the operators lhs , rhs  or part  can be used. The evaluation of the left-hand side of an equation  is controlled by the switch evallhseqp , while the right-hand side is evaluated unconditionally. When an equation  is part of a logical expression, e.g. in a if  or while  statement, the equation is evaluated by subtracting both sides can comparing the result with zero. 

Equations occur in many contexts, e.g. as arguments of the sub  operator and in the arguments and the results of the operator solve . An equation can be member of a list  and you may assign an equation to a variable. Elementary arithmetic is supported for equations: if evallhseqp  is on, you may add and subtract equations, and you can combine an equation with a scalar expression by addition, subtraction, multiplication, division and raise an equation to a power.  
examples: 
 
on evallhseqp; 
 
u:=x+y=1$ 
 
v:=2x-y=0$ 
 
2*u-v;  
 
  - 3*y=-2 

ws/3;  
 
    2 
  y=-- 
    3 

Important: the equation must occur in the leftmost term of such an expression. For other operations, e.g. taking function values of both sides, use the map  operator. 

#$+ KFIRST				operator

The first  operator returns the first element of a list .  
syntax: 

first (<list>) or first  <list> 

<list> must be a non-empty list to avoid an error message. 

examples: 
 
alist := {a,b,c,d};  
 
  ALIST := {A,B,C,D}  

first alist;  
 
  A  

blist := {x,y,{ww,aa,qq},z};  
 
  BLIST := {X,Y,{WW,AA,QQ},Z}  

first third blist;  
 
  WW 

#$+ KFOR				command

The for  command is used for iterative loops. There are many possible forms it can take. 

                   /                    
   /               |STEP <number> UNTIL|         
   |<var>:=<number>|                   |<number>| 
FOR|               |         :         |        |<action> <exprn> 
   |                                  /        | 
   |EACH <var> IN <list>                        | 
                                               / 
 
 where <action> ::= DO|PRODUCT|SUM|COLLECT|JOIN. 
<var> can be any valid REDUCE identifier except t  or nil , <inc>, <start> and <stop> can be any expression that evaluates to a positive or negative integer. <list> must be a valid list  structure. The action taken must be one of the actions shown above, each of which is followed by a single REDUCE expression, statement or a group  (<< ...>> ) or block  (begin ...end ) statement. 

examples: 
 
for i := 1:10 sum i;                                     

 
  55  

for a := -2 step 3 until 6 product a; 

 
  -8  

a := 3;  
 
  A := 3  

for iter := 4:a do write iter;  
 
m := 0;  
 
  M := 0  

for s := 10 step -1 until 3 do <<d := 10*s;m := m + d>>;  
 
m;  
 
  520  

for each x in {q,r,s} sum x**2;  
 
   2    2    2 
  Q  + R  + S   

for i := 1:4 collect 1/i;                               

 
     1 1 1 
  {1,-,-,-}  
     2 3 4 

for i := 1:3 join list solve(x**2 + i*x + 1,x);          

 
        SQRT(3)*I + 1 
  {{X= --------------, 
              2 
        SQRT(3)*I - 1 
    X= --------------} 
              2 
   {X=-1}, 
         SQRT(5) + 3   SQRT(5) - 3 
   {X= - -----------,X=-----------}} 
              2             2 
 
The behavior of each of the five action words follows: 

                           Action Word Behavior 
Keyword   Argument Type                    Action 
   do    statement, command, group   Evaluates its argument once 
         or block                    for each iteration of the loop, 
                                     not saving results 
collect expression, statement,       Evaluates its argument once for 
        command, group, block, list  each iteration of the loop, 
                                     storing the results in a list 
                                     which is returned by the for 
                                     statement when done 
 join   list or an operator which    Evaluates its argument once for 
        produces a list              each iteration of the loop, 
                                     appending the elements in each 
                                     individual result list onto the 
                                     overall result list 
product expression, statement,       Evaluates its argument once for 
        command, group or block      each iteration of the loop, 
                                     multiplying the results together 
                                     and returning the overall product 
  sum   expression, statement,       Evaluates its argument once for 
        command, group or block      each iteration of the loop, 
                                     adding the results together and 
                                     returning the overall sum 
For number-driven for  statements, if the ending limit is smaller than the beginning limit (larger in the case of negative steps) the action statement is not executed at all. The iterative variable is local to the for  statement, and does not affect the value of an identifier with the same name. For list-driven for  statements, if the list is empty, the action statement is not executed, but no error occurs. 

You can use nested for  statements, with the inner for  statement after the action keyword. You must make sure that your inner statement returns an expression that the outer statement can handle. 

#$+ KFOREACH				command

foreach is a synonym for the for each  variant of the for  construct. It is designed to iterate down a list, and an error will occur if a list is not used. The use of for each  is preferred to foreach . 

syntax: 
foreach <variable> in <list> <action> <expression> 

where <action> ::= do | product | sum | collect | join  

 
examples: 
 
foreach x in {q,r,s} sum x**2;  
 
   2    2    2 
  Q  + R  + S 

#$+ KGEQ				operator

 The geq  operator is a binary infix or prefix logical operator. It returns true if its first argument is greater than or equal to its second argument. As an infix operator it is identical with >= .  
syntax: 

geq (<expression>,<expression>) or <expression> geq  <expression> 

<expression> can be any valid REDUCE expression that evaluates to a number. 

examples: 
 
a := 20;  
 
  A := 20  

if geq(a,25) then write "big" else write "small"; 

 
  small  

if a geq 20 then write "big" else write "small"; 

 
  big   

if (a geq 18) then write "big" else write "small"; 

 
  big 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or repeat ...until . 

#$+ KGOTO				command

 Inside a begin ...end  block , goto , or preferably, go to , transfers flow of control to a labeled statement.  
syntax: 

go to <labeled_statement> or goto  <labeled_statement> 

<labeled_statement> is of the form <label> : <statement> 

examples: 
 
     procedure dumb(a); 
        begin scalar q; 
           go to lab; 
           q := df(a**2 - sin(a),a); 
           write q; 
      lab: return a 
        end; 

  DUMB  

 
dumb(17);  
 
  17 
 
go to can only be used inside a begin ...end  block , and inside the block only statements at the top level can be labeled, not ones inside << ...>> , while ...do , etc. 

#$+ KGREATERP				operator

 The greaterp  logical operator returns true if its first argument is strictly greater than its second argument. As an infix operator it is identical with > .  
syntax: 

greaterp (<expression>,<expression>) or <expression> greaterp  <expression> 

<expression> can be any valid REDUCE expression that evaluates to a number. 

examples: 

a := 20;  
 
  A := 20  

if greaterp(a,25) then write "big" else write "small"; 

 
  small  

if a greaterp 20 then write "big" else write "small"; 

 
  small  

if (a greaterp 18) then write "big" else write "small"; 

 
  big 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or repeat ...while . 

#$+ KIF				command

 The if  command is a conditional statement that executes a statement if a condition is true, and optionally another statement if it is not.  
syntax: 

if <condition> then  <statement>  	option(else  <statement>) 

<condition> must be a logical or comparison operator that evaluates to a boolean value . <statement> must be a single REDUCE statement or a group  (<< ...>> ) or block  (begin ...end ) statement. 

examples: 
 
if x = 5 then a := b+c else a := d+f; 

 
  D + F  

x := 9;  
 
  X := 9  

if numberp x and x<20 then y := sqrt(x) else write "illegal"; 

 
  3   

clear x;  
 
if numberp x and x<20 then y := sqrt(x) else write "illegal"; 

 
  illegal  

x := 12;  
 
  X := 12  

a := if x < 5 then 100 else 150; 

 
  A := 150  

b := u**(if x < 10 then 2); 

  B := 1  

bb := u**(if x > 10 then 2); 

         2 
  BB := U 
 
An if  statement may be used inside an assignment statement and sets its value depending on the conditions, or used anywhere else an expression would be valid, as shown in the last example. If there is no  else  clause, the value is 0 if a number is expected, and nothing otherwise. 

The else  clause may be left out if no action is to be taken if the condition is false. 

The condition may be a compound conditional statement using and  or or . If a non-conditional statement, such as a constant, is used by accident, it is assumed to have value true.  

Be sure to use group  or block  statements after  then  or else . 

The if  operator is right associative. The following constructions are examples: 

	(1)  
syntax: 

if <condition> then  if  <condition> then   <action> else  <action> 

which is equivalent to  
syntax: 

if <condition> then  (if  <condition>  then  <action> else  <action>); 

	(2)  
syntax: 

if <condition> then  <action> else if   <condition> then  <action> else  <action> 

which is equivalent to  
syntax: 

if <condition> then  <action> else  

(if  <condition> then  <action>  else  <action>). 

#$+ KLIST				operator

The list  operator constructs a list from its arguments.  
syntax: 

list (<item> {,<item>}*) or  list () to construct an empty list. 

<item> can be any REDUCE scalar expression, including another list. Left and right curly brackets can also be used instead of the operator list  to construct a list. 

examples: 
 
liss := list(c,b,c,{xx,yy},3x**2+7x+3,df(sin(2*x),x)); 

 
                            2 
  LISS := {C,B,C,{XX,YY},3*X  + 7*X + 3,2*COS(2*X)}  

length liss;  
 
  6  

liss := {c,b,c,{xx,yy},3x**2+7x+3,df(sin(2*x),x)}; 

 
                            2 
  LISS := {C,B,C,{XX,YY},3*X  + 7*X + 3,2*COS(2*X)}  

emptylis := list();  
 
  EMPTYLIS := {}  

a . emptylis;  
 
  {A} 
 
Lists are ordered, hierarchical structures. The elements stay where you put them, and only change position in the list if you specifically change them. Lists can have nested sublists to any (reasonable) level. The part  operator can be used to access elements anywhere within a list hierarchy. The length  operator counts the number of top-level elements of its list argument; elements that are themselves lists still only count as one element. 

#$+ KOR				operator

 The or  binary logical operator returns true if either one or both of its arguments is true.  
syntax: 

<logical expression> or  <logical expression> 

<logical expression> must evaluate to true or nil. 

examples: 
 
a := 10;  
 
  A := 10  

if a<0 or a>140 then write "not a valid human age" else 
   write "age = ",a; 

 
 
  age = 10  

a := 200;  
 
  A := 200  

if a < 0 or a > 140 then write "not a valid human age"; 

 
  not a valid human age 
 
The or  operator is left associative: x or y or z  is equivalent to (x or y)  or z . 

Logical operators can only be used in conditional expressions, such as 

if ...then ...else  and while ...do . or  evaluates its arguments in order and quits, returning true, on finding the first true statement. 

#$+ KPROCEDURE				command

 The procedure  command allows you to define a mathematical operation as a function with arguments.  
syntax: 

	<option> procedure  <identifier>  (<arg>{,<arg>}+); <body> 

The <option> may be algebraic  or symbolic , indicating the mode under which the procedure is executed, or real  or integer , indicating the type of answer expected. The default is algebraic. Real or integer procedures are subtypes of algebraic procedures; type-checking is done on the results of integer procedures, but not on real procedures (in the current REDUCE release). <identifier> may be any valid REDUCE identifier that is not already a procedure name, operator, array  or matrix . <arg> is a formal parameter that may be any valid REDUCE identifier. <body> is a single statement (a group  or block  statement may be used) with the desired activities in it. 

examples: 
 
procedure fac(n); 
   if not (fixp(n) and n>=0) 
     then rederr "Choose nonneg. integer only" 
    else for i := 0:n-1 product i+1; 

 
  FAC  

fac(0);  
 
  1  

fac(5);  
 
  120  

fac(-5);  
 
  ***** choose nonneg. integer only 
 
Procedures are automatically declared as operators upon definition. When REDUCE has parsed the procedure definition and successfully converted it to a form for its own use, it prints the name of the procedure. Procedure definitions cannot be nested. Procedures can call other procedures, or can recursively call themselves. Procedure identifiers can be cleared as you would clear an operator. Unlike let  statements, new definitions under the same procedure name replace the previous definitions completely. 

Be careful not to use the name of a system operator for your own procedure. REDUCE may or may not give you a warning message. If you redefine a system operator in your own procedure, the original function of the system operator is lost for the remainder of the REDUCE session. 

Procedures may have none, one, or more than one parameter. A REDUCE parameter is a formal parameter only; the use of x as a parameter in a procedure  definition has no connection with a value of x in the REDUCE session, and the results of calling a procedure have no effect on the value of x. If a procedure is called with x as a parameter, the current value of x is used as specified in the computation, but is not changed outside the procedure. Making an assignment statement by :=  with a formal parameter on the left-hand side only changes the value of the calling parameter within the procedure. 

Using a let  statement inside a procedure always changes the value globally: a let  with a formal parameter makes the change to the calling parameter. let  statements cannot be made on local variables inside begin ...end  block s . When clear  statements are used on formal parameters, the calling variables associated with them are cleared globally too. The use of let  or clear  statements inside procedures should be done with extreme caution. 

Arrays and operators may be used as parameters to procedures. The body of the procedure can contain statements that appropriately manipulate these arguments. Changes are made to values of the calling arrays or operators. Simple expressions can also be used as arguments, in the place of scalar variables. Matrices may not be used as arguments to procedures. 

A procedure that has no parameters is called by the procedure name, immediately followed by empty parentheses. The empty parentheses may be left out when writing a procedure with no parameters, but must appear in a call of the procedure. If this is a nuisance to you, use a let  statement on the name of the procedure (i.e., let noargs = noargs() ) after which you can call the procedure by just its name. 

Procedures that have a single argument can leave out the parentheses around it both in the definition and procedure call. (You can use the parentheses if you wish.) Procedures with more than one argument must use parentheses, with the arguments separated by commas. 

Procedures often have a begin ...end  block in them. Inside the block, local variables are declared using scalar , real  or integer  declarations. The declarations must be made immediately after the word begin , and if more than one type of declaration is made, they are separated by semicolons. REDUCE currently does no type checking on local variables; real  and integer  are treated just like scalar . Actions take place as specified in the statements inside the block statement. Any identifiers that are not formal parameters or local variables are treated as global variables, and activities involving these identifiers are global in effect. 

If a return value is desired from a procedure call, a specific return  command must be the last statement executed before exiting from the procedure. If no return  is used, a procedure returns a zero or no value. 

Procedures are often written in a file using an editor, then the file is input using the command in . This method allows easy changes in development, and also allows you to load the named procedures whenever you like, by loading the files that contain them. 

#$+ KREPEAT				command

The repeat  command causes repeated execution of a statement  until 

the given condition is found to be true. The statement is always executed at least once.  
syntax: 

repeat <statement> until  <condition> 

<statement> can be a single statement, group  statement, or a begin ...end  block . <condition> must be a logical operator that evaluates to true or nil. 

examples: 
 
<<m := 4; repeat <<write 100*x*m;m := m-1>> until m = 0>>; 

 
  400*X 
  300*X 
  200*X 
  100*X 

 
<<m := -1; repeat <<write m; m := m-1>> until m <= 0>>; 

 
  -1 
 
repeat must always be followed by an until  with a condition. Be careful not to generate an infinite loop with a condition that is never true. In the second example, if the condition had been m = 0 , it would never have been true since m  already had value -2 when the condition was first evaluated. 

#$+ KREST				operator

The rest  operator returns a list  containing all but the first element of the list it is given.  
syntax: 

rest (<list>) or rest  <list> 

<list> must be a non-empty list, but need not have more than one element. 

examples: 
 
alist := {a,b,c,d};  
 
  ALIST := {A,B,C,D};  

rest alist;  
 
  {B,C,D}  

blist := {x,y,{aa,bb,cc},z};  
 
  BLIST := {X,Y,{AA,BB,CC},Z}  

second rest blist;  
 
  {AA,BB,CC}  

clist := {c};  
 
  CLIST := C  

rest clist;  
 
  {} 

#$+ KRETURN				command

 The return  command causes a value to be returned from inside a begin ...end  block . 

syntax: 
begin <statements> return  <(expression)>  end 

<statements> can be any valid REDUCE statements. The value of <expression> is returned. 

examples: 
 
begin write "yes"; return a end;  
 
  yes 
  A 

procedure dumb(a); 
  begin if numberp(a) then return a else return 10 end; 

 
  DUMB  

dumb(x);  
 
  10  

dumb(-5);  
 
  -5   

procedure dumb2(a); 
  begin c := a**2 + 2*a + 1; d := 17; c*d; return end; 

  DUMB2  

dumb2(4);  
 
c;  
 
  25  

d;  
 
  17 
 
Note in dumb2  above that the assignments were made as requested, but the product c*d  cannot be accessed. Changing the procedure to read return c*d  would remedy this problem. 

The return  statement is always the last statement executed before leaving the block. If return  has no argument, the block is exited but no value is returned. A block statement does not need a return  ; the statements inside terminate in their normal fashion without one. In that case no value is returned, although the specified actions inside the block take place. 

The return  command can be used inside << ...>>  group  statements and if ...then ...else  commands that are inside begin ...end  block s. It is not valid in these constructions that are not inside a begin ...end   block. It is not valid inside for , repeat ...until  or while ...do   loops in any construction. To force early termination from loops, the go to (goto ) command must be used. When you use nested block statements, a return  from an inner block exits returning a value to the next-outermost block, rather than all the way to the outside. 

#$+ KREVERSE				operator

The reverse  operator returns a list  that is the reverse of the list it is given.  
syntax: 

reverse (<list>) or reverse  <list> 

<list> must be a list . 

examples: 
 
aa := {c,b,a,{x**2,z**3},y};  
 
                 2  3 
  AA := {C,B,A,{X ,Z },Y}  

reverse aa;  
 
       2  3 
  {Y,{X ,Z },A,B,C}  

reverse(q . reverse aa);  
 
           2  3 
  {C,B,A,{X ,Z },Y,Q} 
 
reverse and cons  can be used together to add a new element to the end of a list (.  adds its new element to the beginning). The reverse  operator uses a noticeable amount of system resources, especially if the list is long. If you are doing much heavy-duty list manipulation, you should probably design your algorithms to avoid much reversing of lists. A moderate amount of list reversing is no problem. 

#$+ KRULE				type

A rule  is an instruction to replace an algebraic expression or a part of an expression by another one.  
syntax: 

<lhs> => <rhs> or <lhs> => <rhs> when  <cond> 

<lhs> is an algebraic expression used as search pattern and <rhs> is an algebraic expression which replaces matches of <rhs>. =>  is the operator replace . 

<lhs> can contain free variable s which are symbols preceded by a tilde ~  in their leftmost position in <lhs>. A double tilde marks an optional free variable . If a rule has a when  <cond> part it will fire only if the evaluation of <cond> has a result true . <cond> may contain references to free variables of <lhs>. 

Rules can be collected in a list  which then forms a  rule list . Rule lists  can be used to collect algebraic knowledge for a specific evaluation context. 

Rules and rule lists  are globally activated and deactivated by let , forall , clearrules . For a single evaluation they can be locally activate by where . The active rules for an operator can be visualized by showrules . 

examples: 
 
operator f,g,h;  
 
let f(x) => x^2;  
 
f(x);  
 
   2 
  x 

g_rules:={g(~n,~x)=>h(n/2,x) when evenp n, 
 
g(~n,~x)=>h((1-n)/2,x) when not evenp n}$ 
 
let g_rules; 
 
g(3,x);  
 
  h(-1,x) 

#$+ KFREE VARIABLE				type

A variable preceded by a tilde is considered as free variable  and stands for an arbitrary part in an algebraic form during pattern matching. Free variables occur in the left-hand sides of rule s, in the side relations for compact  and in the first arguments of map  and select  calls. See rule  for examples. 

In rules also optional free variable s may occur. 

#$+ KOPTIONAL FREE VARIABLE				type

A variable preceded by a double tilde is considered as optional free variable 

and stands for an arbitrary part part in an algebraic form during pattern matching. In contrast to ordinary free variable s an operator pattern with an optional free variable  matches also if the operand for the variable is missing. In such a case the variable is bound to a neutral value. Optional free variables can be used as 

term in a sum: set to 0 if missing, 

factor in a product: set to 1 if missing, 

exponent: set to 1 if missing 

examples: 
Optional free variables are allowed only in the left-hand sides of rule s. 

#$+ KSECOND				operator

The second  operator returns the second element of a list.  
syntax: 

second (<list>) or second  <list> 

<list> must be a list with at least two elements, to avoid an error message. 

examples: 
 
alist := {a,b,c,d};  
 
  ALIST := {A,B,C,D}  

second alist;  
 
  B  

blist := {x,{aa,bb,cc},z};  
 
  BLIST := {X,{AA,BB,CC},Z}  

second second blist;  
 
  BB 

#$+ KSET				operator

The set  operator is used for assignments when you want both sides of the assignment statement to be evaluated.  
syntax: 

set (<restricted‑expression>,<expression>) 

<expression> can be any REDUCE expression; <restricted‑expression> must be an identifier or an expression that evaluates to an identifier. 

examples: 
 
a := y;  
 
  A := Y  

set(a,sin(x^2));  
 
       2 
  SIN(X )  

a;  
 
       2 
  SIN(X )  

y;  
 
       2 
  SIN(X )  

a := b + c;  
 
  A := B + C  

set(a-c,z);  
 
  Z  

b;  
 
  Z 
 
Using an array  or matrix  reference as the first argument to set  has the result of setting the contents of the designated element to set 's second argument. You should be careful to avoid unwanted side effects when you use this facility. 

#$+ KSETQ				operator

The setq  operator is an infix or prefix binary assignment operator. It is identical to := .  
syntax: 

setq (<restricted‑expression>,<expression>) or 

<restricted‑expression> setq  <expression> 

<restricted expression> is ordinarily a single identifier, though simple expressions may be used (see Comments below). <expression> can be any valid REDUCE expression. If <expression> is a matrix  identifier, then <restricted‑expression> can be a matrix identifier (redimensioned if necessary), which has each element set to the corresponding elements of the identifier on the right-hand side. 

examples: 
 
setq(b,6);  
 
  B := 6  

c setq sin(x);  
 
  C := SIN(X)  

w + setq(c,x+3) + z;  
 
  W + X + Z + 3  

c;  
 
  X + 3  

setq(a1 + a2,25);  
 
  A1 + A2 := 25  

a1;  
 
  - (A2 - 25) 
 
Embedding a setq  statement in an expression has the side effect of making the assignment, as shown in the third example above. 

Assignments are generally done for identifiers, but may be done for simple expressions as well, subject to the following remarks: 

	(i) If the left-hand side is an identifier, an operator, or a power, the rule is added to the rule table. 

	(ii) If the operators - + /  appear on the left-hand side, all but the first term of the expression is moved to the right-hand side. 

	(iii) If the operator *  appears on the left-hand side, any constant terms are moved to the right-hand side, but the symbolic factors remain. 

Be careful not to make a recursive setq  assignment that is not controlled inside a loop statement. The process of resubstitution continues until you get a stack overflow message. setq  can be used to attach functionality to operators, as the :=  does. 

#$+ KTHIRD				operator

The third  operator returns the third item of a list .  
syntax: 

third (<list>) or third  <list> 

<list> must be a list containing at least three items to avoid an error message. 

examples: 
 
alist := {a,b,c,d};  
 
  ALIST := {A,B,C,D}  

third alist;  
 
  C  

blist := {x,{aa,bb,cc},y,z};  
 
  BLIST := {X,{AA,BB,CC},Y,Z};  

third second blist;  
 
  CC  

third blist;  
 
  Y 

#$+ KWHEN				operator

The when  operator is used inside a rule  to make the execution of the rule depend on a boolean condition which is evaluated at execution time. For the use see rule . 

#$+Syntax

	semicolon command  (;)
	dollar command  ($)
	percent command  (%)
	dot operator  (.)
	assign operator  (: =)
	equalsign operator  (=)
	replace operator  (= >)
	plussign operator  (+)
	minussign operator  (-)
	asterisk operator  (*)
	slash operator  (/)
	power operator  (* *)
	caret operator  (^)
	geqsign operator  (> =)
	greater operator  (>)
	leqsign operator  (< =)
	less operator  (<)
	tilde operator  (~)
	group command  (< <)
	AND operator
	BEGIN command
	block command
	COMMENT command
	CONS operator
	END command
	EQUATION type
	FIRST operator
	FOR command
	FOREACH command
	GEQ operator
	GOTO command
	GREATERP operator
	IF command
	LIST operator
	OR operator
	PROCEDURE command
	REPEAT command
	REST operator
	RETURN command
	REVERSE operator
	RULE type
	Free Variable type
	Optional Free Variable type
	SECOND operator
	SET operator
	SETQ operator
	THIRD operator
	WHEN operator

#$+ KARITHMETIC‑OPERATIONS				introduction

 This section considers operations defined in REDUCE that concern numbers, or operators that can operate on numbers in addition, in most cases, to more general expressions. 

#$+ KABS				operator

The abs  operator returns the absolute value of its argument. 

syntax: 
abs (<expression>) 

<expression> can be any REDUCE scalar expression. 

examples: 
 
abs(-a);  
 
  ABS(A)  

abs(-5);  
 
  5  

a := -10;  
 
  A := -10  

abs(a);  
 
  10  

abs(-a);  
 
  10 
 
If the argument has had no numeric value assigned to it, such as an identifier or polynomial, abs  returns an expression involving abs  of its argument, doing as much simplification of the argument as it can, such as dropping any preceding minus sign. 

#$+ KADJPREC				switch

When a real number is input, it is normally truncated to the precision  in effect at the time the number is read. If it is desired to keep the full precision of all numbers input, the switch adjprec  (for <adjust precision>) can be turned on. While on, adjprec  will automatically increase the precision, when necessary, to match that of any integer or real input, and a message printed to inform the user of the precision increase. 

examples: 
 
on rounded;  
 
1.23456789012345;  
 
  1.23456789012  

on adjprec;  
 
1.23456789012345;  
 
*** precision increased to 15  

#$+ KARG				operator

If complex  and rounded  are on, and arg evaluates to a complex number, arg  returns the polar angle of arg, measured in radians. Otherwise an expression in arg is returned. 

examples: 
 
arg(3+4i)  
 
  ARG(3 + 4*I)  

on rounded, complex;  
 
ws;  
 
  0.927295218002  

arg a;  
 
  ARG(A) 

#$+ KCEILING				operator

 
syntax: 
ceiling (<expression>) 

This operator returns the ceiling (i.e., the least integer greater than or equal to its argument) if its argument has a numerical value. For negative numbers, this is equivalent to fix . For non-numeric arguments, the value is an expression in the original operator. 

examples: 
 
ceiling 3.4;  
 
  4  

fix 3.4;  
 
  3  

ceiling(-5.2);  
 
  -5  

fix(-5.2);  
 
  -5  

ceiling a;  
 
  CEILING(A) 

#$+ KCHOOSE				operator

 choose (<m>,<m>) returns the number of ways of choosing <m> objects from a collection of <n> distinct objects --- in other words the binomial coefficient. If <m> and <n> are not positive integers, or m > n, the expression is returned unchanged. than or equal to  
examples: 
 
choose(2,3);  
 
  3  

choose(3,2);  
 
  CHOOSE(3,2)  

choose(a,b);  
 
  CHOOSE(A,B) 

#$+ KDEG2DMS				operator

 
syntax: 
deg2dms (<expression>) 

In rounded  mode, if <expression> is a real number, the operator deg2dms  will interpret it as degrees, and convert it to a list containing the equivalent degrees, minutes and seconds. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
deg2dms 60;  
 
  DEG2DMS(60)  

on rounded;  
 
ws;  
 
  {60,0,0}  

deg2dms 42.4;  
 
  {42,23,60.0}  

deg2dms a;  
 
  DEG2DMS(A) 

#$+ KDEG2RAD				operator

 
syntax: 
deg2rad (<expression>) 

In rounded  mode, if <expression> is a real number, the operator deg2rad  will interpret it as degrees, and convert it to the equivalent radians. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
deg2rad 60;  
 
  DEG2RAD(60)  

on rounded;  
 
ws;  
 
  1.0471975512  

deg2rad a;  
 
  DEG2RAD(A) 

#$+ KDIFFERENCE				operator

 The difference  operator may be used as either an infix or prefix binary subtraction operator. It is identical to -  as a binary operator. 

syntax: 
difference (<expression>,<expression>) or 

<expression> difference  <expression>  {difference  <expression>}* 

<expression> can be a number or any other valid REDUCE expression. Matrix expressions are allowed if they are of the same dimensions. 

examples: 

difference(10,4);  
 
  6  

 
15 difference 5 difference 2;  
 
  8  

 
a difference b;  
 
  A - B 
 
The difference  operator is left associative, as shown in the second example above. 

#$+ KDILOG				operator

The dilog  operator is known to the differentiation and integration operators, but has numeric value attached only at dilog(0) . Dilog is defined by 

dilog(x) = -int(log(x),x)/(x-1) 

examples: 
 
df(dilog(x**2),x);  
 
           2 
    2*LOG(X )*X 
  - ------------ 
       2 
      X   - 1 

 
int(dilog(x),x);  
 
  DILOG(X)*X - DILOG(X) + LOG(X)*X - X  

 
dilog(0);  
 
    2 
  PI 
  ---- 
   6 

#$+ KDMS2DEG				operator

 
syntax: 
dms2deg (<list>) 

In rounded  mode, if <list> is a list of three real numbers, the operator dms2deg  will interpret the list as degrees, minutes and seconds and convert it to the equivalent degrees. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
dms2deg {42,3,7};  
 
  DMS2DEG({42,3,7})  

on rounded;  
 
ws;  
 
  42.0519444444  

dms2deg a;  
 
  DMS2DEG(A) 

#$+ KDMS2RAD				operator

 
syntax: 
dms2rad (<list>) 

In rounded  mode, if <list> is a list of three real numbers, the operator dms2rad  will interpret the list as degrees, minutes and seconds and convert it to the equivalent radians. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
dms2rad {42,3,7};  
 
  DMS2RAD({42,3,7})  

on rounded;  
 
ws;  
 
  0.733944887421  

dms2rad a;  
 
  DMS2RAD(A) 

#$+ KFACTORIAL				operator

 
syntax: 
factorial (<expression>) 

If the argument of factorial  is a positive integer or zero, its factorial is returned. Otherwise the result is expressed in terms of the original operator. For more general operations, the gamma  operator is available in the Special Function Package . 

examples: 
 
factorial 4;  
 
  24  

factorial 30 ;  
 
  265252859812191058636308480000000  

#$+ KFIX				operator

 
syntax: 
fix (<expression>) 

The operator fix  returns the integer part of its argument, if that argument has a numerical value. For positive numbers, this is equivalent to floor , and, for negative numbers, ceiling . For non-numeric arguments, the value is an expression in the original operator. 

examples: 
 
fix 3.4;  
 
  3  

floor 3.4;  
 
  3  

ceiling 3.4;  
 
  4  

fix(-5.2);  
 
  -5  

floor(-5.2);  
 
  -6  

ceiling(-5.2);  
 
  -5  

fix(a);  
 
  FIX(A) 

#$+ KFIXP				operator

The fixp  logical operator returns true if its argument is an integer.  
syntax: 

fixp (<expression>) or fixp  <simple‑expression> 

<expression> can be any valid REDUCE expression, <simple‑expression> must be a single identifier or begin with a prefix operator. 

examples: 
 
if fixp 1.5 then write "ok" else write "not"; 

 
  not  

if fixp(a) then write "ok" else write "not"; 

 
  not  

a := 15;  
 
  A := 15  

if fixp(a) then write "ok" else write "not"; 

 
  ok 
 
Logical operators can only be used inside conditional expressions such as if ...then  or while ...do . 

#$+ KFLOOR				operator

 
syntax: 
floor (<expression>) 

This operator returns the floor (i.e., the greatest integer less than or equal to its argument) if its argument has a numerical value. For positive numbers, this is equivalent to fix . For non-numeric arguments, the value is an expression in the original operator. 

examples: 
 
floor 3.4;  
 
  3  

fix 3.4;  
 
  3  

floor(-5.2);  
 
  -6  

fix(-5.2);  
 
  -5  

floor a;  
 
  FLOOR(A) 

#$+ KEXPT				operator

 The expt  operator is both an infix and prefix binary exponentiation operator. It is identical to ^  or ** .  
syntax: 

expt (<expression>,<expression>)  or <expression> expt  <expression> 

 
examples: 
 
a expt b;  
 
   B 
  A   

expt(a,b);  
 
   B 
  A   

(x+y) expt 4;  
 
   4      3        2  2        3    4 
  X  + 4*X *Y + 6*X *Y  + 4*X*Y  + Y 
 
Scalar expressions may be raised to fractional and floating-point powers. Square matrix expressions may be raised to positive powers, and also to negative powers if non-singular. 

expt is left associative. In other words, a expt b expt c  is equivalent to a expt (b*c) , not a expt (b expt c) , which would be right associative. 

#$+ KGCD				operator

The gcd  operator returns the greatest common divisor of two polynomials.  
syntax: 

gcd (<expression>,<expression>) 

<expression> must be a polynomial (or integer), otherwise an error occurs. 

examples: 
 
gcd(2*x**2 - 2*y**2,4*x + 4*y);  
 
  2*(X + Y)  

gcd(sin(x),x**2 + 1);  
 
  1   

gcd(765,68);  
 
  17 
 
The operator gcd  described here provides an explicit means to find the gcd of two expressions. The switch gcd  described below simplifies expressions by finding and canceling gcd's at every opportunity. When the switch ezgcd  is also on, gcd's are figured using the EZ GCD algorithm, which is usually faster. 

#$+ KLN				operator

 
syntax: 
ln (<expression>) 

<expression> can be any valid scalar REDUCE expression. 

The ln  operator returns the natural logarithm of its argument. However, unlike log , there are no algebraic rules associated with it; it will only evaluate when rounded  is on, and the argument is a real number. 

examples: 
 
ln(x);  
 
  LN(X)  

ln 4;  
 
  LN(4)  

ln(e);  
 
  LN(E)  

df(ln(x),x);  
 
  DF(LN(X),X)  

on rounded;  
 
ln 4;  
 
  1.38629436112  

ln e;  
 
  1 
 
Because of the restricted algebraic properties of ln , users are advised to use log  whenever possible. 

#$+ KLOG				operator

The log  operator returns the natural logarithm of its argument.  
syntax: 

log (<expression>) or log  <expression> 

<expression> can be any valid scalar REDUCE expression. 

examples: 
 
log(x);  
 
  LOG(X)  

log 4;  
 
  LOG(4)  

log(e);  
 
  1  

on rounded;  
 
log 4;  
 
  1.38629436112 
 
log returns a numeric value only when rounded  is on. In that case, use of a negative argument for log  results in an error message. No error is given on a negative argument when REDUCE is not in that mode. 

#$+ KLOGB				operator

 
syntax: 
logb (<expression>,<integer>) 

<expression> can be any valid scalar REDUCE expression. 

The logb  operator returns the logarithm of its first argument using the second argument as base. However, unlike log , there are no algebraic rules associated with it; it will only evaluate when rounded  is on, and the first argument is a real number. 

examples: 
 
logb(x,2);  
 
  LOGB(X,2)  

logb(4,3);  
 
  LOGB(4,3)  

logb(2,2);  
 
  LOGB(2,2)  

df(logb(x,3),x);  
 
  DF(LOGB(X,3),X)  

on rounded;  
 
logb(4,3);  
 
  1.26185950714  

logb(2,2);  
 
  1 

#$+ KMAX				operator

The operator max  is an n-ary prefix operator, which returns the largest value in its arguments.  
syntax: 

max (<expression>{,<expression>}*) 

<expression> must evaluate to a number. max  of an empty list returns 0. 

examples: 
 
max(4,6,10,-1);  
 
  10  

<<a := 23;b := 2*a;c := 4**2;max(a,b,c)>>; 

 
  46  

max(-5,-10,-a);  
 
  -5 

#$+ KMIN				operator

The operator min  is an n-ary prefix operator, which returns the smallest value in its arguments.  
syntax: 

min (<expression>{,<expression>}*) 

<expression> must evaluate to a number. min  of an empty list returns 0.  
examples: 
 
min(-3,0,17,2);  
 
  -3  

<<a := 23;b := 2*a;c := 4**2;min(a,b,c)>>; 

 
  16  

min(5,10,a);  
 
  5 

#$+ KMINUS				operator

 The minus  operator is a unary minus, returning the negative of its argument. It is equivalent to the unary - .  
syntax: 

minus (<expression>) 

<expression> may be any scalar REDUCE expression. 

examples: 
 
minus(a);  
 
  - A  

minus(-1);  
 
  1  

minus((x+1)**4);  
 
      4      3      2 
  - (X  + 4*X  + 6*X  + 4*X + 1) 

#$+ KNEXTPRIME				operator

 
syntax: 
nextprime (<expression>) 

If the argument of nextprime  is an integer, the least prime greater than that argument is returned. Otherwise, a type error results. 

examples: 
 
nextprime 5001;  
 
  5003   

nextprime(10^30);  
 
  1000000000000000000000000000057  

nextprime a;  
 
  ***** A invalid as integer 

#$+ KNOCONVERT				switch

 Under normal circumstances when rounded  is on, REDUCE converts the number 1.0 to the integer 1. If this is not desired, the switch noconvert  can be turned on.  
examples: 
 
on rounded;  
 
1.0000000000001;  
 
  1  

on noconvert;  
 
1.0000000000001;  
 
  1.0  

#$+ KNORM				operator

 
syntax: 
norm (<expression>) 

If rounded  is on, and the argument is a real number, <norm> returns its absolute value. If complex  is also on, <norm> returns the square root of the sum of squares of the real and imaginary parts of the argument. In all other cases, a result is returned in terms of the original operator. 

examples: 
 
norm (-2);  
 
  NORM(-2)  

on rounded; 
 
ws;  
 
  2.0  

norm(3+4i);  
 
  NORM(4*I+3)  

on complex; 
 
ws;  
 
  5.0 

#$+ KPERM				operator

 
syntax: 
perm(<expression1>,<expression2>) 

If <expression1> and <expression2> evaluate to positive integers, perm  returns the number of permutations possible in selecting <expression1> objects from <expression2> objects. In other cases, an expression in the original operator is returned. 

examples: 
 
perm(1,1);  
 
  1  

perm(3,5);  
 
  60  

perm(-3,5);  
 
  PERM(-3,5)  

perm(a,b);  
 
  PERM(A,B) 

#$+ KPLUS				operator

 The plus  operator is both an infix and prefix n-ary addition operator. It exists because of the way in which REDUCE handles such operators internally, and is not recommended for use in algebraic mode programming. plussign , which has the identical effect, should be used instead.  
syntax: 

plus (<expression>,<expression>{,<expression>} *) or 

<expression> plus  <expression> {plus  <expression>}* 

<expression> can be any valid REDUCE expression, including matrix expressions of the same dimensions. 

examples: 
 
a plus b plus c plus d;  
 
  A + B + C + D  

4.5 plus 10;  
 
  29 
  --  
  2 

 
plus(x**2,y**2);  
 
   2    2 
  X  + Y 

#$+ KQUOTIENT				operator

 The quotient  operator is both an infix and prefix binary operator that returns the quotient of its first argument divided by its second. It is also a unary recip rocal operator. It is identical to /  and slash .  
syntax: 

quotient (<expression>,<expression>) or <expression> quotient  <expression> or quotient (<expression>) or quotient  <expression> 

<expression> can be any valid REDUCE scalar expression. Matrix expressions can also be used if the second expression is invertible and the matrices are of the correct dimensions.  
examples: 
 
quotient(a,x+1);  
 
    A 
  -----  
  X + 1 

7 quotient 17;  
 
  7 
  --  
  17 

on rounded;  
 
4.5 quotient 2;  
 
  2.25  

quotient(x**2 + 3*x + 2,x+1);  
 
  X + 2  

matrix m,inverse;  
 
m := mat((a,b),(c,d));  
 
  M(1,1) := A; 
  M(1,2) := B; 
  M(2,1) := C 
  M(2,2) := D 

 
inverse := quotient m;  
 
                      D 
  INVERSE(1,1) := ---------- 
                  A*D - B*C 
                        B 
  INVERSE(1,2) := - ---------- 
                    A*D - B*C 
                        C 
  INVERSE(2,1) := - ---------- 
                    A*D - B*C 
                      A 
  INVERSE(2,2) := ---------- 
                  A*D - B*C 

The quotient  operator is left associative: a quotient b quotient c  is equivalent to (a quotient b) quotient c . 

If a matrix argument to the unary quotient  is not invertible, or if the second matrix argument to the binary quotient is not invertible, an error message is given. 

#$+ KRAD2DEG				operator

 
syntax: 
rad2deg (<expression>) 

In rounded  mode, if <expression> is a real number, the operator rad2deg  will interpret it as radians, and convert it to the equivalent degrees. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
rad2deg 1;  
 
  RAD2DEG(1)  

on rounded;  
 
ws;  
 
  57.2957795131  

rad2deg a;  
 
  RAD2DEG(A) 

#$+ KRAD2DMS				operator

 
syntax: 
rad2dms (<expression>) 

In rounded  mode, if <expression> is a real number, the operator rad2dms  will interpret it as radians, and convert it to a list containing the equivalent degrees, minutes and seconds. In all other cases, an expression in terms of the original operator is returned. 

examples: 
 
rad2dms 1;  
 
  RAD2DMS(1)  

on rounded;  
 
ws;  
 
  {57,17,44.8062470964}  

rad2dms a;  
 
  RAD2DMS(A) 

#$+ KRECIP				operator

 recip  is the alphabetical name for the division operator /  or slash  used as a unary operator. The use of /  is preferred. 

examples: 
 
recip a;  
 
  1 
  -  
  A 

recip 2;  
 
  1 
  -- 
  2 

#$+ KREMAINDER				operator

The remainder  operator returns the remainder after its first argument is divided by its second argument. 

syntax: 
remainder (<expression>,<expression>) 

<expression> can be any valid REDUCE polynomial, and is not limited to numeric values. 

examples: 
 
remainder(13,6);  
 
  1  

remainder(x**2 + 3*x + 2,x+1);  
 
  0   

remainder(x**3 + 12*x + 4,x**2 + 1);  

  11*X + 4  

remainder(sin(2*x),x*y);  
 
  SIN(2*X) 
 
In the default case, remainders are calculated over the integers. If you need the remainder with respect to another domain, it must be declared explicitly. 

If the first argument to remainder  contains a denominator not equal to 1, an error occurs. 

#$+ KROUND				operator

 
syntax: 
round (<expression>) 

If its argument has a numerical value, round  rounds it to the nearest integer. For non-numeric arguments, the value is an expression in the original operator. 

examples: 
 
round 3.4;  
 
  3  

round 3.5;  
 
  4  

round a;  
 
  ROUND(A) 

#$+ KSETMOD				command

The setmod  command sets the modulus value for subsequent modular  arithmetic.  
syntax: 

setmod <integer> 

<integer> must be positive, and greater than 1. It need not be a prime number. 

examples: 
 
setmod 6;  
 
  1  

on modular;  
 
16;  
 
  4  

x^2 + 5x + 7;  
 
   2 
  X  + 5*X + 1  

x/3;  
 
  X 
  -  
  3 

setmod 2;  
 
  6  

(x+1)^4;  
 
   4 
  X  + 1  

x/3;  
 
  X 
 
setmod returns the previous modulus, or 1 if none has been set before. setmod  only has effect when modular  is on. 

Modular operations are done only on numbers such as coefficients of polynomials, not on the exponents. The modulus need not be prime. Attempts to divide by a power of the modulus produces an error message, since the operation is equivalent to dividing by 0. However, dividing by a factor of a non-prime modulus does not produce an error message. 

#$+ KSIGN				operator

 
syntax: 
sign <expression> 

sign tries to evaluate the sign of its argument. If this is possible sign  returns one of 1, 0 or -1. Otherwise, the result is the original form or a simplified variant. 

examples: 
 
        sign(-5)  
 
  -1 

        sign(-a^2*b)  
 
  -SIGN(B) 
 
Even powers of formal expressions are assumed to be positive only as long as the switch complex  is off. 

#$+ KSQRT				operator

The sqrt  operator returns the square root of its argument.  
syntax: 

sqrt (<expression>) 

<expression> can be any REDUCE scalar expression. 

examples: 
 
sqrt(16*a^3);  
 
  4*SQRT(A)*A  

sqrt(17);  
 
  SQRT(17)  

on rounded;  
 
sqrt(17);  
 
  4.12310562562  

off rounded;  
 
sqrt(a*b*c^5*d^3*27);  
 
                                             2 
  3*SQRT(D)*SQRT(C)*SQRT(B)*SQRT(A)*SQRT(3)*C *D 
 
sqrt checks its argument for squared factors and removes them. 

Numeric values for square roots that are not exact integers are given only when rounded  is on. 

Please note that sqrt(a**2)  is given as a , which may be incorrect if a  eventually has a negative value. If you are programming a calculation in which this is a concern, you can turn on the precise  switch, which causes the absolute value of the square root to be returned. 

#$+ KTIMES				operator

 The times  operator is an infix or prefix n-ary multiplication operator. It is identical to * .  
syntax: 

<expression> times  <expression> {times  <expression>}* 

or times (<expression>,<expression> {,<expression>}*) 

<expression> can be any valid REDUCE scalar or matrix expression. Matrix expressions must be of the correct dimensions. Compatible scalar and matrix expressions can be mixed. 

examples: 
 
var1 times var2;  
 
  VAR1*VAR2  

times(6,5);  
 
  30  

matrix aa,bb;  
 
aa := mat((1),(2),(x))  
 
bb := mat((0,3,1))  
 
aa times bb times 5;  
 
  [0   15    5 ] 
  [            ] 
  [0   30   10 ] 
  [            ] 
  [0  15*X  5*X] 

#$+Arithmetic Operations

	ARITHMETIC‑OPERATIONS introduction
	ABS operator
	ADJPREC switch
	ARG operator
	CEILING operator
	CHOOSE operator
	DEG2DMS operator
	DEG2RAD operator
	DIFFERENCE operator
	DILOG operator
	DMS2DEG operator
	DMS2RAD operator
	FACTORIAL operator
	FIX operator
	FIXP operator
	FLOOR operator
	EXPT operator
	GCD operator
	LN operator
	LOG operator
	LOGB operator
	MAX operator
	MIN operator
	MINUS operator
	NEXTPRIME operator
	NOCONVERT switch
	NORM operator
	PERM operator
	PLUS operator
	QUOTIENT operator
	RAD2DEG operator
	RAD2DMS operator
	RECIP operator
	REMAINDER operator
	ROUND operator
	SETMOD command
	SIGN operator
	SQRT operator
	TIMES operator

#$+ KBOOLEAN VALUE

 There are no extra symbols for the truth values true and false. Instead, nil  and the number zero are interpreted as truth value false in algebraic programs (see false ), while any different value is considered as true (see true ). 

#$+ KEQUAL				operator

The operator equal  is an infix binary comparison operator. It is identical with = . It returns true  if its two arguments are equal. 

syntax: 
<expression> equal  <expression> 

Equality is given between floating point numbers and integers that have the same value. 

examples: 
 
on rounded;  
 
a := 4;  
 
  A := 4  

b := 4.0;  
 
  B := 4.0  

if a equal b then write "true" else write "false"; 

 
  true  

if a equal 5 then write "true" else write "false"; 

 
  false  

if a equal sqrt(16) then write "true" else write "false"; 

 
  true 
 
Comparison operators can only be used as conditions in conditional commands such as if ...then  and repeat ...until . <equal> can also be used as a prefix operator. However, this use is not encouraged. 

#$+ KEVENP				operator

 The evenp  logical operator returns true  if its argument is an even integer, and nil  if its argument is an odd integer. An error message is returned if its argument is not an integer. 

syntax: 
evenp (<integer>) or evenp  <integer> 

<integer> must evaluate to an integer. 

examples: 
 
aa := 1782;  
 
  AA := 1782  

if evenp aa then yes else no;  
 
  YES  

if evenp(-3) then yes else no;  
 
  NO  
 
Although you would not ordinarily enter an expression such as the last example above, note that the negative term must be enclosed in parentheses to be correctly parsed. The evenp  operator can only be used in conditional statements such as if ...then ...else  or while ...do . 

#$+ KFALSE

 The symbol nil  and the number zero are considered as boolean value  false if used in a place where a boolean value is required. Most builtin operators return nil  as false value. Algebraic programs use better zero. Note that nil  is not printed when returned as result to a top level evaluation. 

#$+ KFREEOF				operator

 The freeof  logical operator returns true  if its first argument does not contain its second argument anywhere in its structure.  
syntax: 

freeof (<expression>,<kernel>) or <expression> freeof  <kernel> 

<expression> can be any valid scalar REDUCE expression, <kernel> must be a kernel expression (see kernel ). 

examples: 
 
a := x + sin(y)**2 + log sin z; 

 
                           2 
  A := LOG(SIN(Z)) + SIN(Y)   + X  

if freeof(a,sin(y)) then write "free" else write "not free"; 

 
  not free  

if freeof(a,sin(x)) then write "free" else write "not free"; 

 
  free  

if a freeof sin z then write "free" else write "not free"; 

 
  not free 
 
Logical operators can only be used in conditional expressions such as 

if ...then  or while ...do . 

#$+ KLEQ				operator

 The leq  operator is a binary infix or prefix logical operator. It returns true  if its first argument is less than or equal to its second argument. As an infix operator it is identical with <= .  
syntax: 

leq (<expression>,<expression>) or <expression> leq  <expression> 

<expression> can be any valid REDUCE expression that evaluates to a number. 

examples: 
 
a := 15;  
 
  A := 15  

if leq(a,25) then write "yes" else write "no"; 

 
  yes  

if leq(a,15) then write "yes" else write "no"; 

 
  yes  

if leq(a,5) then write "yes" else write "no"; 

 
  no 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or while ...do . 

#$+ KLESSP				operator

 The lessp  operator is a binary infix or prefix logical operator. It returns true  if its first argument is strictly less than its second argument. As an infix operator it is identical with < .  
syntax: 

lessp (<expression>,<expression>) or <expression> lessp  <expression> 

<expression> can be any valid REDUCE expression that evaluates to a number. 

examples: 
 
a := 15;  
 
  A := 15  

if lessp(a,25) then write "yes" else write "no"; 

 
  yes  

if lessp(a,15) then write "yes" else write "no"; 

 
  no  

if lessp(a,5) then write "yes" else write "no"; 

 
  no 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or while ...do . 

#$+ KMEMBER				operator

 
syntax: 
<expression> member  <list> 

member is an infix binary comparison operator that evaluates to true  if <expression> is equal  to a member of the list  <list>. 

examples: 
 
if a member {a,b} then 1 else 0;  
 
  1  

if 1 member(1,2,3) then a else b;  
 
  a  

if 1 member(1.0,2) then a else b;  
 
  b 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or while ...do . <member> can also be used as a prefix operator. However, this use is not encouraged. Finally, equal  (= ) is used for the test within the list, so expressions must be of the same type to match. 

#$+ KNEQ				operator

 The operator neq  is an infix binary comparison operator. It returns true  if its two arguments are not equal . 

syntax: 
<expression> neq  <expression> 

An inequality is satisfied between floating point numbers and integers that have the same value. 

examples: 
 
on rounded;  
 
a := 4;  
 
  A := 4  

b := 4.0;  
 
  B := 4.0  

if a neq b then write "true" else write "false"; 

 
  false  

if a neq 5 then write "true" else write "false"; 

 
  true 
 
Comparison operators can only be used as conditions in conditional commands such as if ...then  and repeat ...until . <neq> can also be used as a prefix operator. However, this use is not encouraged. 

#$+ KNOT				operator

 The not  operator returns true  if its argument evaluates to nil , and nil  if its argument is true .  
syntax: 

not (<logical expression>) 

 
examples: 
 
if not numberp(a) then write "indeterminate" else write a; 

 
  indeterminate;  

a := 10;  
 
  A := 10  

if not numberp(a) then write "indeterminate" else write a; 

 
  10  

if not(numberp(a) and a < 0) then write "positive number"; 

 
  positive number 
 
Logical operators can only be used in conditional statements such as 

if ...then ...else  or while ...do . 

#$+ KNUMBERP				operator

 The numberp  operator returns true  if its argument is a number, and nil  otherwise.  
syntax: 

numberp (<expression>) or numberp  <expression> 

<expression> can be any REDUCE scalar expression. 

examples: 
 
cc := 15.3;  
 
  CC := 15.3  

if numberp(cc) then write "number" else write "nonnumber";  

  number  

if numberp(cb) then write "number" else write "nonnumber";  

  nonnumber 
 
Logical operators can only be used in conditional expressions, such as 

if ...then ...else  and while ...do . 

#$+ KORDP				operator

The ordp  logical operator returns true  if its first argument is ordered ahead of its second argument in canonical internal ordering, or is identical to it.  
syntax: 

ordp (<expression1>,<expression2>) 

<expression1> and <expression2> can be any valid REDUCE scalar expression. 

examples: 
 
if ordp(x**2 + 1,x**3 + 3) then write "yes" else write "no"; 

 
  no  

if ordp(101,100) then write "yes" else write "no"; 

 
  yes  

if ordp(x,x) then write "yes" else write "no"; 

 
  yes 
 
Logical operators can only be used in conditional expressions, such as 

if ...then ...else  and while ...do . 

#$+ KPRIMEP				operator

 
syntax: 
primep (<expression>) or primep  <simple‑expression> 

If <expression> evaluates to a integer, primep  returns true  

if <expression> is a prime number and nil  otherwise. If <expression> does not have an integer value, a type error occurs. 

examples: 
 
if primep 3 then write "yes" else write "no";  

  YES  

if primep a then 1;  
 
  ***** A invalid as integer 

#$+ KTRUE

Any value of the boolean part of a logical expression which is neither nil  nor 0  is considered as true . Most builtin test and compare functions return t  for true  and nil  for false . 

examples: 
 
if member(3,{1,2,3}) then 1 else -1; 

  1 

if floor(1.7) then 1 else -1;  
 
  1  

if floor(0.7) then 1 else -1;  
 
  -1 

#$+Boolean Operators

	boolean value concept
	EQUAL operator
	EVENP operator
	false concept
	FREEOF operator
	LEQ operator
	LESSP operator
	MEMBER operator
	NEQ operator
	NOT operator
	NUMBERP operator
	ORDP operator
	PRIMEP operator
	TRUE concept

#$+ KBYE				command

 The bye  command ends the REDUCE session, returning control to the program (e.g., the operating system) that called REDUCE. When you are at the top level, the bye  command exits REDUCE. quit  is a synonym for bye . 

#$+ KCONT				command

 The command cont  returns control to an interactive file after a pause  command that has been answered with n . 

examples: 
Suppose you are in the middle of an interactive file.  

 
  factorize(x**2 + 17*x + 60);  

  
 
  {X + 5,X + 12}  

   pause;  
 
  Cont? (Y or N)  

n  
 
saveas results;  
 
factor1 := first results;  
 
  FACTOR1 := X + 5  

factor2 := second results;  
 
  FACTOR2 := X + 12  

cont;  the file resumes 

A pause  allows you to enter your own REDUCE commands, change switch values, inquire about results, or other such activities. When you wish to resume operation of the interactive file, use cont . 

#$+ KDISPLAY				command

When given a numeric argument <n>, display  prints the <n> most recent input statements, identified by prompt numbers. If an empty pair of parentheses is given, or if <n> is greater than the current number of statements, all the input statements since the beginning of the session are printed. 

syntax: 
display (<n>) or display () 

<n> should be a positive integer. However, if it is a real number, the truncated integer value is used, and if a non-numeric argument is used, all the input statements are printed. 

The statements are displayed in upper case, with lines split at semicolons or dollar signs, as they are in editing. If long files have been input during the session, the display  command is slow to format these for printing. 

#$+ KLOAD‑PACKAGE				command

The load_package  command is used to load REDUCE packages, such as gentran  that are not automatically loaded by the system.  
syntax: 

load_package " <package‑name>"  

A package is only loaded once; subsequent calls of load_package  for the same package name are ignored. 

#$+ KPAUSE				command

The pause  command, given in an interactive file, stops operation and asks if you want to continue or not. 

examples: 
An interactive file is running, and at some point you see the question  
 
				   Cont? (Y or N)  
If you type  
 
y{Return} 
the file continues to run until the next pause or the end.  
If you type   
 
n{Return}  
you will get a numbered REDUCE prompt, and be allowed to enter and execute any REDUCE statements. If you later wish to continue with the file, type  
 
cont;  
and the file resumes. 

To use pause  in your own interactive files, type 

pause; in the file wherever you want it. 

pause does not allow you to continue without typing either y  or n . Its use is to slow down scrolling of interactive files, or to let you change parameters or switch settings for the calculations. 

If you have stopped an interactive file at a pause,  and do not wish to resume the file, type end; . This does not end the REDUCE session, but stops input from the file. A second end;  ends the REDUCE session. However, if you have pauses from more than one file stacked up, an end;  brings you back to the top level, not the file directly above. 

A pause  typed from the terminal has no effect. 

#$+ KQUIT				command

 The quit  command ends the REDUCE session, returning control to the program (e.g., the operating system) that called REDUCE. When you are at the top level, the quit  command exits REDUCE. bye  is a synonym for quit . 

#$+ KRECLAIM				operator

REDUCE's memory is in a storage structure called a heap. As REDUCE statements execute, chunks of memory are used up. When these chunks are no longer needed, they remain idle. When the memory is almost full, the system executes a garbage collection, reclaiming space that is no longer needed, and putting all the free space at one end. Depending on the size of the image REDUCE is using, garbage collection needs to be done more or less often. A larger image means fewer but longer garbage collections. Regardless of memory size, if you ask REDUCE to do something ridiculous, like factorial(2000) , it may garbage collect many times. 

#$+ KREDERR				command

The rederr  command allows you to print an error message from inside a procedure  or a block  statement. The calculation is gracefully terminated.  
syntax: 

rederr <message> 

<message> is an error message, usually inside double quotation marks (a string ). 

examples: 
 
procedure fac(n); 
   if not (fixp(n) and n>=0) 
     then  rederr "Choose nonneg. integer only" 
    else for i := 0:n-1 product i+1; 

  fac  

fac a;  
 
  	   ***** Choose nonneg. integer only  

fac 5;  
 
  120 
 
The above procedure finds the factorial of its argument. If n is not a positive integer or 0, an error message is returned. 

If your procedure is executed in a file, the usual error message is printed, followed by Cont? (Y or N) , just as any other error does from a file. Although the procedure is gracefully terminated, any switch settings or variable assignments you made before the error occurred are not undone. If you need to clean up such items before exiting, use a group statement, with the rederr  command as its last statement. 

#$+ KRETRY				command

The retry  command allows you to retry the latest statement that resulted in an error message. 

examples: 
 
matrix a;  
 
det a;  
 
  ***** Matrix A not set  

a := mat((1,2),(3,4));  
 
  A(1,1) := 1 
  A(1,2) := 2 
  A(2,1) := 3 
  A(2,2) := 4 

retry;  
 
  -2 
 
retry remembers only the most recent statement that resulted in an error message. It allows you to stop and fix something obvious, then continue on your way without retyping the original command. 

#$+ KSAVEAS				command

 The saveas  command saves the current workspace under the name of its argument.  
syntax: 

saveas <identifier> 

<identifier> can be any valid REDUCE identifier. 

examples: 
(The numbered prompts are shown below, unlike in most examples) 
 
1: solve(x^2-3); 
 
  {x=sqrt(3),x= - sqrt(3)} 

2: saveas rts(0) 
 
3: rts(0); 
 
  {x=sqrt(3),x= - sqrt(3)} 

saveas works only for the current workspace, the last algebraic expression produced by REDUCE. This allows you to save a result that you did not assign to an identifier when you originally typed the input. For access to previous output use ws . 

#$+ KSHOWTIME				command

The showtime  command prints the elapsed system time since the last call of this command or since the beginning of the session, if it has not been called before. 

examples: 
 
showtime;  
 
  Time: 1020 ms  

factorize(x^4 - 8x^4 + 8x^2 - 136x - 153); 

 
          2 
  {X - 9,X  + 17,X + 1}  

showtime;  
 
  Time: 920 ms 
 
The time printed is either the elapsed cpu time or the elapsed wall clock time, depending on your system. showtime  allows you to see the system time resources REDUCE uses in its calculations. Your time readings will of course vary from this example according to the system you use. 

#$+ KWRITE				command

The write  command explicitly writes its arguments to the output device (terminal or file).  
syntax: 

write <item>{,<item>}* 

<item> can be an expression, an assignment or a string  enclosed in double quotation marks (" ). 

examples: 
 
write a, sin x, "this is a string";  

  ASIN(X)this is a string  

write a," ",sin x," this is a string";  

  A SIN(X) this is a string  

if not numberp(a) then write "the symbol ",a; 

 
  the symbol A  

array m(10);  
 
for i := 1:5 do write m(i) := 2*i;  

  M(1) := 2 
  M(2) := 4 
  M(3) := 6 
  M(4) := 8 
  M(5) := 10 

m(4);  
 
  8 
 
The items specified by a single write  statement print on a single line unless they are too long. A printed line is always ended with a carriage return, so the next item printed starts a new line. 

When an assignment statement is printed, the assignment is also made. This allows you to get feedback on filling slots in an array with a for   statement, as shown in the last example above. 

#$+General Commands

	BYE command
	CONT command
	DISPLAY command
	LOAD‑PACKAGE command
	PAUSE command
	QUIT command
	RECLAIM operator
	REDERR command
	RETRY command
	SAVEAS command
	SHOWTIME command
	WRITE command

#$+ KAPPEND				operator

The append  operator constructs a new list  from the elements of its two arguments (which must be lists). 

syntax: 
append (<list>,<list>) 

<list> must be a list, though it may be the empty list ({} ). Any arguments beyond the first two are ignored. 

examples: 
 
alist := {1,2,{a,b}};  
 
  ALIST := {1,2,{A,B}}  

blist := {3,4,5,sin(y)};  
 
  BLIST := {3,4,5,SIN(Y)}  

append(alist,blist);  
 
  {1,2,{A,B},3,4,5,SIN(Y)}  

append(alist,{});  
 
  {1,2,{A,B}}  

append(list z,blist);  
 
  {Z,3,4,5,SIN(Y)} 
 
The new list consists of the elements of the second list appended to the elements of the first list. You can append  new elements to the beginning or end of an existing list by putting the new element in a list (use curly braces or the operator list ). This is particularly helpful in an iterative loop. 

#$+ KARBINT				operator

The operator arbint  is used to express arbitrary integer parts of an expression, e.g. in the result of solve  when allbranch  is on.  
examples: 

solve(log(sin(x+3)),x);  
 
  {X=2*ARBINT(1)*PI - ASIN(1) - 3, 
   X=2*ARBINT(1)*PI + ASIN(1) + PI - 3} 

#$+ KARBCOMPLEX				operator

The operator arbcomplex  is used to express arbitrary scalar parts of an expression, e.g. in the result of solve  when the solution is parametric in one of the variable.  
examples: 

solve({x+3=y-2z,y-3x=0},{x,y,z});  

     2*ARBCOMPLEX(1) + 3 
  {X=-------------------, 
              2 
      3*ARBCOMPLEX(1) + 3 
    Y=-------------------, 
               2 
    Z=ARBCOMPLEX(1)} 

#$+ KARGLENGTH				operator

The operator arglength  returns the number of arguments of the top-level operator in its argument. 

syntax: 
arglength (<expression>) 

<expression> can be any valid REDUCE algebraic expression. 

examples: 
 
arglength(a + b + c + d);  
 
  4  

arglength(a/b/c);  
 
  2  

arglength(log(sin(df(r**3*x,x))));  

  1 
 
In the first example, +  is an n-ary operator, so the number of terms is returned. In the second example, since /  is a binary operator, the argument is actually (a/b)/c, so there are two terms at the top level. In the last example, no matter how deeply the operators are nested, there is still only one argument at the top level. 

#$+ KCOEFF				operator

The coeff  operator returns the coefficients of the powers of the specified variable in the given expression, in a list . 

syntax: 
coeff (<expression>, <variable>) 

<expression> is expected to be a polynomial expression, not a rational expression. Rational expressions are accepted when the switch ratarg  is on. <variable> must be a kernel. The results are returned in a list. 

examples: 
 
coeff((x+y)**3,x);  
 
    3     2 
  {Y  ,3*Y  ,3*Y,1}  

coeff((x+2)**4 + sin(x),x);  
 
  {SIN(X) + 16,32,24,8,1}  

high_pow;  
 
  4  

low_pow;  
 
  0  

ab := x**9 + sin(x)*x**7 + sqrt(y);  

 
                          7     9 
  AB := SQRT(Y) + SIN(X)*X   + X 

coeff(ab,x);  
 
  {SQRT(Y),0,0,0,0,0,0,SIN(X),0,1} 
 
The variables high_pow  and low_pow  are set to the highest and lowest powers of the variable, respectively, appearing in the expression. 

The coefficients are put into a list, with the coefficient of the lowest (constant) term first. You can use the usual list access methods (first , second , third , rest , length , and part ) to extract them. If a power does not appear in the expression, the corresponding element of the list is zero. Terms involving functions of the specified variable but not including powers of it (for example in the expression x**4 + 3*x**2 + tan(x) ) are placed in the constant term. 

Since the coeff  command deals with the expanded form of the expression, you may get unexpected results when exp  is off, or when factor  or ifactor  are on. 

If you want only a specific coefficient rather than all of them, use the coeffn  operator. 

#$+ KCOEFFN				operator

The coeffn  operator takes three arguments: an expression, a kernel, and a non-negative integer. It returns the coefficient of the kernel to that integer power, appearing in the expression. 

syntax: 
coeffn (<expression>,<kernel>,<integer>) 

<expression> must be a polynomial, unless ratarg  is on which allows rational expressions. <kernel> must be a kernel, and <integer> must be a non-negative integer. 

examples: 

ff := x**7 + sin(y)*x**5 + y**4 + x + 7;  

                5     7         4 
  FF := SIN(Y)*X   + X   + X + Y   + 7  

coeffn(ff,x,5);  
 
  SIN(Y)  

coeffn(ff,z,3);  
 
  0  

coeffn(ff,y,0);  
 
          5     7 
  SIN(Y)*X   + X   + X + 7  

 
rr := 1/y**2+y**3+sin(y);  
 
                2     5 
        SIN(Y)*Y   + Y   + 1 
  RR := --------------------  
                  2 
                 Y 

on ratarg;  

coeffn(rr,y,-2);  
 
  ***** -2 invalid as COEFFN index  

 
coeffn(rr,y,5);  
 
  1 
  --- 
   2 
  Y 
 
If the given power of the kernel does not appear in the expression, coeffn  returns 0. Negative powers are never detected, even if they appear in the expression and ratarg  are on. coeffn  with an integer argument of 0 returns any terms in the expression that do not contain the given kernel. 

#$+ KCONJ				operator

 
syntax: 
conj (<expression>) or conj  <simple‑expression> 

This operator returns the complex conjugate of an expression, if that argument has an numerical value. A non-numerical argument is returned as an expression in the operators repart  and impart . 

examples: 
 
conj(1+i);  
 
  1-I  

conj(a+i*b);  
 
  REPART(A) - REPART(B)*I - IMPART(A)*I - IMPART(B) 

#$+ KCONTINUED_FRACTION				operator

 
syntax: 
continued_fraction (<num>) or continued_fraction ( <num>,<size>) 

This operator approximates the real number <num> ( rational  number, rounded  number) into a continued fraction. The result is a list of two elements: the first one is the rational value of the approximation, the second one is the list of terms of the continued fraction which represents the same value according to the definition t0 +1/(t1 + 1/(t2 + ...)) . Precision: the second optional parameter <size> is an upper bound for the absolute value of the result denominator. If omitted, the approximation is performed up to the current system precision. 

examples: 
 
continued_fraction pi; 

   1146408 
  {-------,{3,7,15,1,292,1,1,1,2,1}}  
   364913 

continued_fraction(pi,100); 

   22 
  {--,{3,7}}  
   7 

#$+ KDECOMPOSE				operator

The decompose  operator takes a multivariate polynomial as argument, and returns an expression and a list  of equation s from which the original polynomial can be found by composition. 

syntax: 
decompose (<expression>) or decompose   <simple‑expression> 

 
examples: 
 
decompose(x^8-88*x^7+2924*x^6-43912*x^5+263431*x^4- 
          218900*x^3+65690*x^2-7700*x+234) 

 
   2                  2            2 
  U  + 35*U + 234, U=V  + 10*V, V=X  - 22*X  

     decompose(u^2+v^2+2u*v+1)  
 
   2 
  W   + 1, W=U + V 
 
Unlike factorization, this decomposition is not unique. Further details can be found in V.S. Alagar, M.Tanh, <Fast Polynomial Decomposition>, Proc. EUROCAL 1985, pp 150-153 (Springer) and J. von zur Gathen, <Functional> <Decomposition of Polynomials: the Tame Case>, J. Symbolic Computation (1990) 9, 281-299. 

#$+ KDEG				operator

The operator deg  returns the highest degree of its variable argument found in its expression argument. 

syntax: 
deg (<expression>,<kernel>) 

<expression> is expected to be a polynomial expression, not a rational expression. Rational expressions are accepted when the switch ratarg  is on. <variable> must be a kernel . The results are returned in a list. 

examples: 

deg((x+y)**5,x);  
 
  5  

 
deg((a+b)*(c+2*d)**2,d);  
 
  2  

 
deg(x**2 + cos(y),sin(x));  

deg((x**2 + sin(x))**5,sin(x));  
 
  5 

#$+ KDEN				operator

The den  operator returns the denominator of its argument. 

syntax: 
den (<expression>) 

<expression> is ordinarily a rational expression, but may be any valid scalar REDUCE expression. 

examples: 

a := x**3 + 3*x**2 + 12*x;  
 
           2 
  A := X*(X   + 3*X + 12)  

 
b := 4*x*y + x*sin(x);  
 
  B := X*(SIN(X) + 4*Y)  

 
den(a/b);  
 
  SIN(X) + 4*Y  

 
den(aa/4 + bb/5);  
 
  20  

 
den(100/6);  
 
  3  

 
den(sin(x));  
 
  1 
 
den returns the denominator of the expression after it has been simplified by REDUCE. As seen in the examples, this includes putting sums of rational expressions over a common denominator, and reducing common factors where possible. If the expression does not have any other denominator, 1 is returned. 

Switch settings, such as mcd  or rational , have an effect on the denominator of an expression. 

#$+ KDF				operator

The df  operator finds partial derivatives with respect to one or more variables. 

syntax: 
df (<expression>, <var> 	 [, <number>]  {, <var> [ , <number>] }) 

<expression> can be any valid REDUCE algebraic expression. <var> must be a kernel , and is the differentiation variable. <number> must be a non-negative integer. 

examples: 

df(x**2,x);  
 
  2*X  

 
df(x**2*y + sin(y),y);  
 
            2 
  COS(Y) + X   

 
df((x+y)**10,z);  
 
  0  

 
 
df(1/x**2,x,2);  
 
  6 
  --- 
   4 
  X 

 
df(x**4*y + sin(y),y,x,3);  
 
  24*X  

 
for all x let df(tan(x),x) = sec(x)**2;  

df(tan(3*x),x);  
 
            2 
  3*SEC(3*X) 
 
An error message results if a non-kernel is entered as a differentiation operator. If the optional number is omitted, it is assumed to be 1. See the declaration depend  to establish dependencies for implicit differentiation. 

You can define your own differentiation rules, expanding REDUCE's capabilities, using the let  command as shown in the last example above. Note that once you add your own rule for differentiating a function, it supersedes REDUCE's normal handling of that function for the duration of the REDUCE session. If you clear the rule (clearrules ), you don't get back to the previous rule. 

#$+ KEXPAND‑CASES				operator

When a root_of  form in a result of solve  has been converted to a one_of  form, expand_cases  can be used to convert this into form corresponding to the normal explicit results of solve . See root_of . 

#$+ KEXPREAD				operator

 
syntax: 
expread () 

expread reads one well-formed expression from the current input buffer and returns its value. 

examples: 
 
expread(); a+b;  
 
  A + B 

#$+ KFACTORIZE				operator

The factorize  operator factors a given expression.  
syntax: 

factorize (<expression>) 

<expression> should be a polynomial, otherwise an error will result. 

examples: 

fff := factorize(x^3 - y^3);  
 
          2          2 
  {X - Y,X  + X*Y + Y }  

fac1 := first fff;  
 
  FAC1 := X - Y  

factorize(x^15 - 1);  
 
   {X - 1, 
     2 
    X  + X + 1, 
     4    3    2 
    X  + X  + X  + X + 1, 
     8    7    6    5    4 
    X  - X  + X  - X  + X  - X + 1} 

lastone := part(ws,length ws);  
 
              8    7    6    5    4 
  LASTONE := X  - X  + X  - X  + X  - X + 1  

setmod 2;  
 
  1  

on modular;  
 
factorize(x^15 - 1);  
 
  {X + 1, 
    2 
   X  + X + 1, 
    4 
   X  + X + 1, 
    4    3 
   X  + X  + 1, 
    4    3    2 
   X  + X  + X  + X + 1} 
 
The factorize  command returns the factors it finds as a list . You can therefore use the usual list access methods (first , second , third , rest , length  and part ) to extract the factors. 

If the <expression> given to factorize  is an integer, it will be factored into its prime components. To factor any integer factor of a non-numerical expression, the switch ifactor  should be turned on. Its default is off. ifactor  has effect only when factoring is explicitly done by factorize , not when factoring is automatically done with the factor  switch. If full factorization is not needed the switch limitedfactors  allows you to reduce the computing time of calls to factorize . 

Factoring can be done in a modular domain by calling factorize  when modular  is on. You can set the modulus with the setmod  command. The last example above shows factoring modulo 2. 

For general comments on factoring, see comments under the switch factor . 

#$+ KHYPOT				operator

 
syntax: 
hypot(<expression>,<expression>) 

If rounded  is on, and the two arguments evaluate to numbers, this operator returns the square root of the sums of the squares of the arguments in a manner that avoids intermediate overflow. In other cases, an expression in the original operator is returned. 

examples: 
 
hypot(3,4);  
 
  HYPOT(3,4)  

on rounded;  
 
ws;  
 
  5.0  

hypot(a,b);  
 
  HYPOT(A,B) 

#$+ KIMPART				operator

 
syntax: 
impart (<expression>) or impart  <simple‑expression> 

This operator returns the imaginary part of an expression, if that argument has an numerical value. A non-numerical argument is returned as an expression in the operators repart  and impart .  
examples: 
 
impart(1+i);  
 
  1  

impart(a+i*b);  
 
  REPART(B) + IMPART(A) 

#$+ KINT				operator

The int  operator performs analytic integration on a variety of functions. 

syntax: 
int (<expression>,<kernel>) 

<expression> can be any scalar expression. involving polynomials, log functions, exponential functions, or tangent or arctangent expressions. int  attempts expressions involving error functions, dilogarithms and other trigonometric expressions. Integrals involving algebraic extensions (such as square roots) may not succeed. <kernel> must be a REDUCE kernel . 

examples: 
 
int(x**3 + 3,x);  
 
      3 
  X*(X  + 12) 
  -----------  
       4 

 
int(sin(x)*exp(2*x),x); 

     2*X 
    E   *(COS(X) - 2*SIN(X)) 
  - ------------------------  
               5 

int(1/(x^2-2),x); 

  SQRT(2)*(LOG( - SQRT(2) + X) - LOG(SQRT(2) + X)) 
  ------------------------------------------------  
                         4 

int(sin(x)/(4 + cos(x)**2),x); 

         COS(X) 
    ATAN(------) 
           2 
  - ------------  
         2 

 
int(1/sqrt(x^2-x),x);  
 
      SQRT(X)*SQRT(X - 1) 
  INT(-------------------,X) 
              2 
             X -X 
 
Note that REDUCE couldn't handle the last integral with its default integrator, since the integrand involves a square root. However, the integral can be found using the algint  package. Alternatively, you could add a rule using the let  statement to evaluate this integral. 

The arbitrary constant of integration is not shown. Definite integrals can be found by evaluating the result at the limits of integration (use rounded ) and subtracting the lower from the higher. Evaluation can be easily done by the sub  operator. 

When int  cannot find an integral it returns an expression involving formal int  expressions unless the switch failhard  has been set. If not all of the expression can be integrated, the switch nolnr  controls whether a partially integrated result should be returned or not. 

#$+ KINTERPOL				operator

interpol generates an interpolation polynomial.  
syntax: 

interpol(<values>,<variable>,<points>) 

<values> and <points> are list s of equal length and <variable> is an algebraic expression (preferably a kernel ). The interpolation polynomial is generated in the given variable of degree length(<values>)-1. The unique polynomial f  is defined by the property that for corresponding elements v  of <values> and p  of <points> the relation f(p)=v  holds. 

examples: 
 
f := for i:=1:4 collect(i**3-1);  
 
  F := 0,7,26,63  

p := {1,2,3,4};  
 
  P := 1,2,3,4  

interpol(f,x,p);  
 
   3 
  X  - 1 
 
The Aitken-Neville interpolation algorithm is used which guarantees a stable result even with rounded numbers and an ill-conditioned problem. 

#$+ KLCOF				operator

The lcof  operator returns the leading coefficient of a given expression with respect to a given variable.  
syntax: 

lcof (<expression>,<kernel>) 

<expression> is ordinarily a polynomial. If ratarg  is on, a rational expression may also be used, otherwise an error results. <kernel> must be a kernel . 

examples: 
 
lcof((x+2*y)**5,y);  
 
  32  

lcof((x + y*sin(x))**2 + cos(x)*sin(x)**2,sin(x)); 

 
        2 
  COS(X)  + Y  

lcof(x**2 + 3*x + 17,y);  
 
   2 
  X  + 3*X + 17 
 
If the kernel does not appear in the expression, lcof  returns the expression. 

#$+ KLENGTH				operator

The length  operator returns the number of items in a list , the number of terms in an expression, or the dimensions of an array or matrix.  
syntax: 

length (<expr>) or length  <expr> 

<expr> can be a list structure, an array, a matrix, or a scalar expression. 

examples: 
 
alist := {a,b,{ww,xx,yy,zz}};  
 
  ALIST := {A,B,{WW,XX,YY,ZZ}}  

length alist;  
 
  3   

length third alist;  
 
  4   

dlist := {d};  
 
  DLIST := {D}  

length rest dlist;  
 
  0   

matrix mmm(4,5);  
 
length mmm;  
 
  {4,5}  

array aaa(5,3,2);  
 
length aaa;  
 
  {6,4,3}  

eex := (x+3)**2/(x-y);  
 
          2 
         X  + 6*X + 9 
  EEX := ------------  
            X - Y 

length eex;  
 
  5 
 
An item in a list that is itself a list only counts as one item. An error message will be printed if length  is called on a matrix which has not had its dimensions set. The length  of an array includes the zeroth element of each dimension, showing the full number of elements allocated. (Declaring an array A with n elements allocates A(0),A(1),...,A(n).) The length  of an expression is the total number of additive terms appearing in the numerator and denominator of the expression. Note that subtraction of a term is represented internally as addition of a negative term. 

#$+ KLHS				operator

The lhs  operator returns the left-hand side of an equation , such as those returned in a list by solve .  
syntax: 

lhs (<equation>) or lhs  <equation> 

<equation> must be an equation of the form 

left-hand side = right-hand side . 

examples: 
 
polly := (x+3)*(x^4+2x+1);  
 
            5      4      2 
  POLLY := X  + 3*X  + 2*X  + 7*X + 3  

pollyroots := solve(polly,x);  
 
  POLLYROOTS := {X=ROOT F(X3 - X2 + X + 1,X , 
                       O                   ) 
                 X=-1, 
                 X=-3} 

variable := lhs first pollyroots;  
 
  VARIABLE := X 

#$+ KLIMIT				operator

LIMITS is a fast limit package for REDUCE for functions which are continuous except for computable poles and singularities, based on some earlier work by Ian Cohen and John P. Fitch. The Truncated Power Series package is used for non-critical points, at which the value of the function is the constant term in the expansion around that point. l'Hopital's rule is used in critical cases, with preprocessing of 1-1 forms and reformatting of product forms in order to apply l'Hopital's rule. A limited amount of bounded arithmetic is also employed where applicable. 

syntax: 
limit (<expr>,<var>,<limpoint>) or 

limit!+ (<expr>,<var>,<limpoint>) or 

limit!- (<expr>,<var>,<limpoint>) 

where <expr> is an expression depending of the variable <var> (a kernel ) and <limpoint> is the limit point. If the limit depends upon the direction of approach to the <limpoint>, the operators limit!+  and limit!-  may be used. 

examples: 
 
limit(x*cot(x),x,0); 
 
  0 

limit((2x+5)/(3x-2),x,infinity); 
 
  2 
  -- 
  3 

#$+ KLPOWER				operator

The lpower  operator returns the leading power of an expression with respect to a kernel. 1 is returned if the expression does not depend on the kernel.  
syntax: 

lpower (<expression>,<kernel>) 

<expression> is ordinarily a polynomial. If ratarg  is on, a rational expression may also be used, otherwise an error results. <kernel> must be a kernel . 

examples: 
 
lpower((x+2*y)**6,y);  
 
   6 
  Y   

lpower((x + cos(x))**8 + df(x**2,x),cos(x)); 

 
        8 
  COS(X)   

lpower(x**3 + 3*x,y);  
 
  1 

#$+ KLTERM				operator

The lterm  operator returns the leading term of an expression with respect to a kernel. The expression is returned if it does not depend on the kernel.  
syntax: 

lterm (<expression>,<kernel>) 

<expression> is ordinarily a polynomial. If ratarg  is on, a rational expression may also be used, otherwise an error results. <kernel> must be a kernel . 

examples: 
 
lterm((x+2*y)**6,y);  
 
      6 
  64*Y   

lterm((x + cos(x))**8 + df(x**2,x),cos(x)); 

 
        8 
  COS(X)   

lterm(x**3 + 3*x,y);  
 
   3 
  X  + 3X 

#$+ KMAINVAR				operator

The mainvar  operator returns the main variable (in the system's internal representation) of its argument.  
syntax: 

mainvar (<expression>) 

<expression> is usually a polynomial, but may be any valid REDUCE scalar expression. In the case of a rational function, the main variable of the numerator is returned. The main variable returned is a kernel . 

examples: 
 
test := (a + b + c)**2;  
 
           2                    2            2 
  TEST := A  + 2*A*B + 2*A*C + B  + 2*B*C + C   

mainvar(test);  
 
  A  

korder c,b,a;  
 
mainvar(test);  
 
  C  

mainvar(2*cos(x)**2);  
 
  COS(X)  

mainvar(17);  
 
  0 
 
The main variable is the first variable in the canonical ordering of kernels. Generally, alphabetically ordered functions come first, then alphabetically ordered identifiers (variables). Numbers come last, and as far as mainvar  is concerned belong in the family 0 . The canonical ordering can be changed by the declaration korder , as shown above. 

#$+ KMAP				operator

The map  operator applies a uniform evaluation pattern to all members of a composite structure: a matrix , a list  or the arguments of an operator  expression. The evaluation pattern can be a unary procedure, an operator, or an algebraic expression with one free variable.  
syntax: 

map (<function>,<object>) 

<object> is a list, a matrix or an operator expression. 

<function> is the name of an operator for a single argument: the operator  is evaluated once with each element of <object> as its single argument, 

or an algebraic expression with exactly one free variable , that is a variable preceded by the tilde symbol: the expression  is evaluated for each element of <object> where the element is  substituted for the free variable, 

or a replacement rule  of the form  
syntax: 

var => rep  

where <var> is a variable (a <kernel> without subscript)  and <rep> is an expression which contains <var>.  Here rep  is evaluated for each element of <object> where  the element is substituted for var . var  may be  optionally preceded by a tilde. 

The rule form for <function> is needed when more than one free variable occurs. 

examples: 
 
map(abs,{1,-2,a,-a});  
 
  1,2,abs(a),abs(a)  

map(int(~w,x), mat((x^2,x^5),(x^4,x^5)));  

          [  3     6 ] 
          [ x     x  ] 
          [----  ----] 
          [ 3     6  ] 
          [          ] 
          [  5     6 ] 
          [ x     x  ] 
          [----  ----] 
  	[ 5     6  ] 

map(~w*6, x^2/3 = y^3/2 -1);  
 
     2     3 
  2*x =3*(y -2) 
 
You can use map  in nested expressions. It is not allowed to apply map  for a non-composed object, e.g. an identifier or a number. 

#$+ KMKID				command

The mkid  command constructs an identifier, given a stem and an identifier or an integer.  
syntax: 

mkid (<stem>,<leaf>) 

<stem> can be any valid REDUCE identifier that does not include escaped special characters. <leaf> may be an integer, including one given by a local variable in a for  loop, or any other legal group of characters. 

examples: 
 
mkid(x,3);  
 
  X3  

factorize(x^15 - 1);  
 
  {X - 1, 
    2 
   X  + X + 1, 
    4    3    2 
   X  + X  + X  + X + 1, 
    8    7    5    4    3 
   X  - X  + X  - X  + X   - X + 1} 

 
for i := 1:length ws do write set(mkid(f,i),part(ws,i)); 

 
   8    7    5    4    3 
  X  - X  + X  - X  + X  - X + 1 
   4    3    2 
  X  + X  + X  + X + 1 
   2 
  X  + X + 1 
  X - 1 
 
You can use mkid  to construct identifiers from inside procedures. This allows you to handle an unknown number of factors, or deal with variable amounts of data. It is particularly helpful to attach identifiers to the answers returned by factorize  and solve . 

#$+ KNPRIMITIVE				operator

 
syntax: 
nprimitive (<expression>) or nprimitive   <simple‑expression> 

This operator returns the numerically-primitive part of any scalar expression. In other words, any overall integer factors in the expression are removed. 

examples: 
 
nprimitive((2x+2y)^2);  
 
   2            2 
  X  + 2*X*Y + Y   

nprimitive(3*a*b*c);  
 
  3*A*B*C 

#$+ KNUM				operator

The num  operator returns the numerator of its argument.  
syntax: 

num (<expression>) or num  <simple‑expression> 

<expression> can be any valid REDUCE scalar expression. 

examples: 
 
num(100/6);  
 
  50  

num(a/5 + b/6);  
 
  6*A + 5*B  

num(sin(x));  
 
  SIN(X) 
 
num returns the numerator of the expression after it has been simplified by REDUCE. As seen in the examples, this includes putting sums of rational expressions over a common denominator, and reducing common factors where possible. If the expression is not a rational expression, it is returned unchanged. 

#$+ KODESOLVE				operator

The odesolve  package is a solver for ordinary differential equations. At the present time it has still limited capabilities: 

1. it can handle only a single scalar equation presented as an  algebraic expression or equation, and 

2. it can solve only first-order equations of simple types, linear  equations with constant coefficients and Euler equations. 

These solvable types are exactly those for which Lie symmetry techniques give no useful information. 

syntax: 
odesolve (<expr>,<var1>,<var2>) 

<expr> is a single scalar expression such that <expr>=0 is the ordinary differential equation (ODE for short) to be solved, or is an equivalent equation . 

<var1> is the name of the dependent variable, <var2> is the name of the independent variable. 

A differential in <expr> is expressed using the df  operator. Note that in most cases you must declare explicitly <var1> to depend of <var2> using a depend  declaration -- otherwise the derivative might be evaluated to zero on input to odesolve . 

The returned value is a list containing the equation giving the general solution of the ODE (for simultaneous equations this will be a list of equations eventually). It will contain occurrences of the operator arbconst  for the arbitrary constants in the general solution. The arguments of arbconst  should be new. A counter !!arbconst  is used to arrange this. 

examples: 
 
depend y,x; 
 
 A first-order linear equation, with an initial condition 
 
ode:=df(y,x) + y * sin x/cos x - 1/cos x$ 
 
odesolve(ode,y,x);  
 
  {y=arbconst(1)*cos(x) + sin(x)} 

#$+ KONE‑OF				type

 The operator one_of  is used to represent an indefinite choice of one element from a finite set of objects.  
examples: 
 
x=one_of{1,2,5} 
this equation encodes that x can take one of the values 1,2 or 5 
 REDUCE generates a one_of  form in cases when an implicit root_of  expression could be converted to an explicit solution set. A one_of  form can be converted to a solve  solution using expand_cases . See root_of . 

#$+ KPART				operator

The operator part  permits the extraction of various parts or operators of expressions and list s .  
syntax: 

part (<expression,integer>{,<integer>}*) 

<expression> can be any valid REDUCE expression or a list, integer may be an expression that evaluates to a positive or negative integer or 0. A positive integer <n> picks up the n th term, counting from the first term toward the end. A negative integer n picks up the n th term, counting from the back toward the front. The integer 0 picks up the operator (which is LIST  when the expression is a list ). 

examples: 
 
part((x + y)**5,4);  
 
      2  3 
  10*X *Y   

part((x + y)**5,4,2);  
 
   2 
  X   

part((x + y)**5,4,2,1);  
 
  X  

part((x + y)**5,0);  
 
  PLUS  

part((x + y)**5,-5);  
 
        4 
  5*X *Y   

part((x + y)**5,4) := sin(x);  
 
   5      4         3  2                 4    5 
  X  + 5*X *Y + 10*X *Y  + SIN(X) + 5*X*Y  + Y   

alist := {x,y,{aa,bb,cc},x**2*sqrt(y)};  

                                        2 
  			 ALIST := {X,Y,{AA,BB,CC},SQRT(Y)*X }  

part(alist,3,2);  
 
  BB  

part(alist,4,0);  
 
  TIMES 
 
Additional integer arguments after the first one examine the terms recursively, as shown above. In the third line, the fourth term is picked from the original polynomial, 10x^2y^3, then the second term from that, x^2, and finally the first component, x. If an integer's absolute value is too large for the appropriate expression, a message is given. 

part works on the form of the expression as printed, or as it would have been printed at that point of the calculation, bearing in mind the current switch settings. It is important to realize that the switch settings change the operation of part . pri  must be on when part  is used. 

When part  is used on a polynomial expression that has minus signs, the +  is always returned as the top-level operator. The minus is found as a unary operator attached to the negative term. 

part can also be used to change the relevant part of the expression or list as shown in the sixth example line. The part  operator returns the changed expression, though original expression is not changed. You can also use part  to change the operator. 

#$+ KPF				operator

 
syntax: 
pf(<expression>,<variable>) 

pf transforms <expression> into a list  of partial fraction s with respect to the main variable, <variable>. pf  does a complete partial fraction decomposition, and as the algorithms used are fairly unsophisticated (factorization and the extended Euclidean algorithm), the code may be unacceptably slow in complicated cases.  
examples: 
 
pf(2/((x+1)^2*(x+2)),x);  
 
      2    -2        2 
  	{-----,-----,------------}  
    X + 2 X + 1  2 
                X  + 2*X + 1 

off exp;  
 
pf(2/((x+1)^2*(x+2)),x); 

     2    - 2     2 
  {-----,-----,--------}  
   X + 2 X + 1        2 
               (X + 1) 

for each j in ws sum j;  
 
         2 
  ---------------- 
                2 
  ( + 2)*(X + 1) 

If you want the denominators in factored form, turn exp  off, as shown in the second example above. As shown in the final example, the for  each  construct can be used to recombine the terms. Alternatively, one can use the operations on lists to extract any desired term. 

#$+ KPROD				operator

The operator prod  returns the indefinite or definite product of a given expression. 

syntax: 
prod (<expr>,<k>[,<lolim> [,<uplim> ]]) 

where <expr> is the expression to be multiplied, <k> is the control variable (a kernel ), and <lolim> and <uplim> uplim are the optional lower and upper limits. If <uplim> is not supplied the upper limit is taken as <k>. The Gosper algorithm is used. If there is no closed form solution, the operator returns the input unchanged. 

examples: 
 
prod(k/(k-2),k); 
 
  k*( - k + 1) 

#$+ KREDUCT				operator

The reduct  operator returns the remainder of its expression after the leading term with respect to the kernel in the second argument is removed.  
syntax: 

reduct (<expression>,<kernel>) 

<expression> is ordinarily a polynomial. If ratarg  is on, a rational expression may also be used, otherwise an error results. <kernel> must be a kernel . 

examples: 
 
reduct((x+y)**3,x);  
 
        2            2 
  Y*(3*X  + 3*X*Y + Y )  

reduct(x + sin(x)**3,sin(x));  
 
  X  

reduct(x + sin(x)**3,y);  
 
  0 
 
If the expression does not contain the kernel, reduct  returns 0. 

#$+ KREPART				operator

 
syntax: 
repart (<expression>) or repart  <simple‑expression> 

This operator returns the real part of an expression, if that argument has an numerical value. A non-numerical argument is returned as an expression in the operators repart  and impart .  
examples: 
 
repart(1+i);  
 
  1  

repart(a+i*b);  
 
  REPART(A) - IMPART(B) 

#$+ KRESULTANT				operator

The resultant  operator computes the resultant of two polynomials with respect to a given variable. If the resultant is 0, the polynomials have a root in common.  
syntax: 

resultant (<expression>,<expression>,<kernel>) 

<expression> must be a polynomial containing <kernel> ; <kernel> must be a kernel . 

examples: 
 
resultant(x**2 + 2*x + 1,x+1,x);  
 
  0  

resultant(x**2 + 2*x + 1,x-3,x);  
 
  16  

resultant(z**3 + z**2 + 5*z + 5, 
          z**4 - 6*z**3 + 16*z**2 - 30*z + 55, 
          z); 

  0  

resultant(x**3*y + 4*x*y + 10,y**2 + 6*y + 4,y);  

   6       5        4        3        2 
  Y  + 18*Y  + 120*Y  + 360*Y  + 480*Y  + 288*Y + 64 
 
The resultant is the determinant of the Sylvester matrix, formed from the coefficients of the two polynomials in the following way: 

Given two polynomials: 

    n       n-1  
 a x  + a1 x     + ... + an 
 
and 

    m       m-1  
 b x  + b1 x     + ... + bm 
 
form the (m+n)x(m+n-1) Sylvester matrix by the following means: 

   0.......0 a  a1 .......... an 
   0....0 a  a1 .......... an  0 
       .    .   .   .   
   a0 a1 .......... an 0.......0 
   0.......0 b  b1 .......... bm 
   0....0 b  b1 .......... bm  0 
       .    .   .   .   
   b  b1 .......... bm 0.......0   
 
If the determinant of this matrix is 0, the two polynomials have a common root. Finding the resultant of large expressions is time-consuming, due to the time needed to find a large determinant. 

The sign conventions resultant  uses are those given in the article, ``Computing in Algebraic Extensions,'' by R. Loos, appearing in <Computer Algebra--Symbolic and Algebraic Computation>, 2nd ed., edited by B. Buchberger, G.E. Collins and R. Loos, and published by Springer-Verlag, 1983. These are: 

  resultant(p(x),q(x),x) = (-1)^{deg p(x)*deg q(x)} * resultant(q(x),p(x),x), 
  resultant(a,p(x),x)    = a^{deg p(x)}, 
  resultant(a,b,x)       = 1 
where p(x) and q(x) are polynomials which have x as a variable, and a and b are free of x. 

Error messages are given if resultant  is given a non-polynomial expression, or a non-kernel variable. 

#$+ KRHS				operator

The rhs  operator returns the right-hand side of an equation , such as those returned in a list  by solve .  
syntax: 

rhs (<equation>) or rhs  <{equation> 

<equation> must be an equation of the form left-hand side = right-hand side. 

examples: 
 
roots := solve(x**2 + 6*x*y + 5x + 3y**2,x);  

                              2 
                     SQRT(24*Y  + 60*Y + 25) + 6*Y + 5 
      ROOTS := {X= - ---------------------------------, 
                                     2 
                             2 
                    SQRT(24*Y  + 60*Y + 25) - 6*Y - 5 
                 X= ---------------------------------} 
                                    2 

root1 := rhs first roots;  
 
                      2 
             SQRT(24*Y  + 60*Y + 25) + 6*Y + 5 
  ROOT1 := - ---------------------------------  
                             2 

root2 := rhs second roots;  
 
                    2 
           SQRT(24*Y  + 60*Y + 25) - 6*Y - 5 
  ROOT2 := ---------------------------------- 
                           2 
 
An error message is given if rhs  is applied to something other than an equation. 

#$+ KROOT‑OF				operator

When the operator solve  is unable to find an explicit solution or if that solution would be too complicated, the result is presented as formal root expression using the internal operator root_of  and a new local variable. An expression with a top level root_of  is implicitly a list with an unknown number of elements since we can't always know how many solutions an equation has. If a substitution is made into such an expression, closed form solutions can emerge. If this occurs, the root_of  construct is replaced by an operator one_of . At this point it is of course possible to transform the result if the original solve  operator expression into a standard solve  solution. To effect this, the operator expand_cases  can be used. 

examples: 
 
solve(a*x^7-x^2+1,x); 
 
                 7     2 
  {x=root_of(a*x_  - x_  + 1,x_)} 

sub(a=0,ws); 
 
  {x=one_of(1,-1)} 

expand_cases ws; 
 
  x=1,x=-1 
 
The components of root_of  and one_of  expressions can be processed as usual with operators arglength  and part . A higher power of a root_of  expression with a polynomial as first argument is simplified by using the polynomial as a side relation. 

#$+ KSELECT				operator

The select  operator extracts from a list or from the arguments of an n--ary operator elements corresponding to a boolean predicate. The predicate pattern can be a unary procedure, an operator or an algebraic expression with one free variable .  
syntax: 

select (<function>,<object>) 

<object> is a list . 

<function> is the name of an operator for a single argument: the operator  is evaluated once with each element of <object> as its single argument, 

or an algebraic expression with exactly one free variable , that is a variable preceded by the tilde symbol: the expression  is evaluated for each element of <object> where the element is  substituted for the free variable, 

or a replacement rule  of the form  
syntax: 

var => rep  

where <var> is a variable (a <kernel> without subscript)  and <rep> is an expression which contains <var>.  Here rep  is evaluated for each element of <object> where  the element is substituted for var . var  may be  optionally preceded by a tilde. 

The rule form for <function> is needed when more than one free variable occurs. The evaluation result of <function> is interpreted as boolean value  corresponding to the conventions of REDUCE. The result value is built with the leading operator of the input expression.  
examples: 
 
  select( ~w>0 , {1,-1,2,-3,3})  
 
  {1,2,3}  

  q:=(part((x+y)^5,0):=list) 
 
  select(evenp deg(~w,y),q); 
 
    5      3   2       4 
  {x  ,10*x  *y  ,5*x*y  } 

  select(evenp deg(~w,x),2x^2+3x^3+4x^4); 

    2   4 
  2x +4x 

#$+ KSHOWRULES				operator

 
syntax: 
showrules (<expression>) or  showrules  <simple‑expression> 

showrules returns in rule -list  form any operator  rules associated with its argument. 

examples: 
 
showrules log;  
 
  {LOG(E) => 1, 
   LOG(1) => 0, 
        ~X 
   LOG(E   ) => ~X, 
                     1 
   DF(LOG(~X),~X) => --} 
                     ~X 
 
Such rules can then be manipulated further as with any list . For example rhs first ws;  has the value 1. 

An operator may have properties that cannot be displayed in such a form, such as the fact it is an odd  function, or has a definition defined as a procedure. 

#$+ KSOLVE				operator

The solve  operator solves a single algebraic equation  or a system of simultaneous equations. 

syntax: 
solve (<expression> [ , <kernel>]) or 

solve ({<expression>,...} [ ,{ <kernel> ,...}] ) 

If the number of equations equals the number of distinct kernels, the optional kernel argument(s) may be omitted. <expression> is either a scalar expression or an equation . When more than one expression is given, the list  of expressions is surrounded by curly braces. The optional list of kernel s follows, also in curly braces. 

examples: 
 
sss := solve(x^2 + 7);  
 
  Unknown: X 
  SSS := {X= - SQRT(7)*I, 
          X=SQRT(7)*I} 

rhs first sss;  
 
  - SQRT(7)*I  

solve(sin(x^2*y),y);  
 
     2*ARBINT(1)*PI 
  {Y=--------------- 
            2 
           X 
     PI*(2*ARBINT(1) + 1) 
   Y=--------------------} 
               2 
              X 

off allbranch;  
 
solve(sin(x**2*y),y);  
 
  {Y=0}  

solve({3x + 5y = -4,2*x + y = -10},{x,y}); 

 
         22   46 
  {{X= - --,Y=--}}  
         7    7 

solve({x + a*y + z,2x + 5},{x,y}); 

 
         5      2*Z - 5 
  {{X= - -,Y= - -------}}  
         2        2*A 

ab := (x+2)^2*(x^6 + 17x + 1); 

         8      7      6       3       2 
  AB := X  + 4*X  + 4*X  + 17*X  + 69*X  + 72*X + 4  

www := solve(ab,x);  
 
  {X=ROOT F(X6 + 17*X + 1),X=-2}  
         O             

root_multiplicities;  
 
  {1,2} 
 
Results of the solve  operator are returned as equation s  in a list . You can use the usual list access methods (first , second , third , rest  and part ) to extract the desired equation, and then use the operators rhs  and lhs  to access the right-hand or left-hand expression of the equation. When solve  is unable to solve an equation, it returns the unsolved part as the argument of root_of , with the variable renamed to avoid confusion, as shown in the last example above. 

For one equation, solve  uses square-free factorization, roots of unity, and the known inverses of the log , sin , cos , acos , asin , and exponentiation operators. The quadratic, cubic and quartic formulas are used if necessary, but these are applied only when the switch fullroots  is set on; otherwise or when no closed form is available the result is returned as root_of  expression. The switch trigform  determines which type of cubic and quartic formula is used. The multiplicity of each solution is given in a list as the system variable root_multiplicities . For systems of simultaneous linear equations, matrix inversion is used. For nonlinear systems, the Groebner basis method is used. 

Linear equation system solving is influenced by the switch cramer . 

Singular systems can be solved when the switch solvesingular  is on, which is the default setting. An empty list is returned the system of equations is inconsistent. For a linear inconsistent system with parameters the variable requirements  constraints conditions for the system to become consistent. 

For a solvable linear and polynomial system with parameters the variable assumptions  contains a list side relations for the parameters: the solution is valid only as long as none of these expressions is zero. 

If the switch varopt  is on (default), the system rearranges the variable sequence for minimal computation time. Without varopt  the user supplied variable sequence is maintained. 

If the solution has free variables (dimension of the solution is greater than zero), these are represented by arbcomplex  expressions as long as the switch arbvars  is on (default). Without arbvars  no explicit equations are generated for free variables. 

 
related: 

	allbranch switch 
	arbvars  switch 
	assumptions  variable 
	fullroots  switch 
	requirements  variable 
	roots  operator 
	root_of  operator 
	trigform  switch 
	varopt  switch 

#$+ KSORT				operator

The sort  operator sorts the elements of a list according to an arbitrary comparison operator.  
syntax: 

sort (<lst>,<comp>) 

<lst> is a list  of algebraic expressions. <comp> is a comparison operator which defines a partial ordering among the members of <lst>. <comp> may be one of the builtin comparison operators like < (lessp ), <= (leq ) etc., or <comp> may be the name of a comparison procedure. Such a procedure has two arguments, and it returns true  if the first argument ranges before the second one, and 0 or nil  otherwise. The result of sort  is a new list which contains the elements of <lst> in a sequence corresponding to <comp>.  
examples: 
 
 procedure ce(a,b); 
 
   if evenp a and not evenp b then 1 else 0; 
 
for i:=1:10 collect random(50)$ 
 
sort(ws,>=);  
 
  {41,38,33,30,28,25,20,17,8,5} 

sort(ws,<);  
 
  {5,8,17,20,25,28,30,33,38,41} 

sort(ws,ce);  
 
  {8,20,28,30,38,5,17,25,33,41} 

  procedure cd(a,b); 
 
  if deg(a,x)>deg(b,x) then 1 else 
 
  if deg(a,x)<deg(b,x) then 0 else 
 
  if deg(a,y)>deg(b,y) then 1 else 0; 
 
sort({x^2,y^2,x*y},cd); 
 
    2      2 
  {x ,x*y,y } 

#$+ KSTRUCTR				operator

The structr  operator breaks its argument expression into named subexpressions. 

syntax: 
structr (<expression> [,<identifier>[,<identifier> ...]]) 

<expression> may be any valid REDUCE scalar expression. <identifier> may be any valid REDUCE identifier . The first identifier is the stem for subexpression names, the second is the name to be assigned to the structured expression. 

examples: 
 
structr(sqrt(x**2 + 2*x) + sin(x**2*z));  

  ANS1 + ANS2 
      where 
                       2 
          ANS2 := SIN(X *Z) 
                             1/2 
          ANS1 := ((X + 2)*X) 

ans3;  
 
  ANS3  

on fort;  
 
structr((x+1)**5 + tan(x*y*z),var,aa);  

  VAR1=TAN(X*Y*Z) 
  AA=VAR1+X**5+5.*X**4+10.*X**3+10.X**2+5.*X+1 
 
The second argument to structr  is optional. If it is not given, the default stem ANS  is used by REDUCE to construct names for the subexpression. The names are only for display purposes: REDUCE does not store the names and their values unless the switch savestructr  is on. 

If a third argument is given, the structured expression as a whole is named by this argument, when fort  is on. The expression is not stored under this name. You can send these structured Fortran expressions to a file with the out  command. 

#$+ KSUB				operator

The sub  operator substitutes a new expression for a kernel in an expression.  
syntax: 

sub (<kernel>= <expression> 	 {,<kernel>= <expression>}*, 	 <expression>) or 

sub ({<kernel>= <expression>*, 	 <kernel>= expression },<expression>) 

<kernel> must be a kernel , <expression> can be any REDUCE scalar expression. 

examples: 
 
sub(x=3,y=4,(x+y)**3);  
 
  343  

x;  
 
  X  

sub({cos=sin,sin=cos},cos a+sin b}  

  COS(B) + SIN(A) 
 
Note in the second example that operators can be replaced using the sub  operator. 

#$+ KSUM				operator

The operator sum  returns the indefinite or definite summation of a given expression. 

syntax: 
sum (<expr>,<k>[,<lolim> [,<uplim> ]]) 

where <expr> is the expression to be added, <k> is the control variable (a kernel ), and <lolim> and <uplim> are the optional lower and upper limits. If <uplim> is not supplied the upper limit is taken as <k>. The Gosper algorithm is used. If there is no closed form solution, the operator returns the input unchanged. 

examples: 
 
sum(4n**3,n);  
 
   2    2 
  n  *(n   + 2*n + 1) 

sum(2a+2k*r,k,0,n-1); 
 
  n*(2*a + n*r - r) 

#$+ KWS				operator

The ws  operator alone returns the last result; ws  with a number argument returns the results of the REDUCE statement executed after that numbered prompt.  
syntax: 

ws or ws (<number>) 

<number> must be an integer between 1 and the current REDUCE prompt number. 

examples: 
(In the following examples, unlike most others, the numbered prompt is shown.)  
 
1: df(sin y,y);  
 
  COS(Y)  

2: ws^2;  
 
        2 
  COS(Y)   

3: df(ws 1,y);  
 
  -SIN(Y) 

ws and ws ( <number>)  can be used anywhere the expression they stand for can be used. Calling a number for which no result was produced, such as a switch setting, will give an error message. 

The current workspace always contains the results of the last REDUCE command that produced an expression, even if several input statements that do not produce expressions have intervened. For example, if you do a differentiation, producing a result expression, then change several switches, the operator ws;  returns the results of the differentiation. The current workspace (ws ) can also be used inside files, though the numbered workspace contains only the in  command that input the file. 

There are three history lists kept in your REDUCE session. The first stores raw input, suitable for the statement editor. The second stores parsed input, ready to execute and accessible by input . The third stores results, when they are produced by statements, which are accessible by the ws < n> operator. If your session is very long, storage space begins to fill up with these expressions, so it is a good idea to end the session once in a while, saving needed expressions to files with the saveas  and out  commands. 

An error message is given if a reference number has not yet been used. 

#$+Algebraic Operators

	APPEND operator
	ARBINT operator
	ARBCOMPLEX operator
	ARGLENGTH operator
	COEFF operator
	COEFFN operator
	CONJ operator
	CONTINUED_FRACTION operator
	DECOMPOSE operator
	DEG operator
	DEN operator
	DF operator
	EXPAND‑CASES operator
	EXPREAD operator
	FACTORIZE operator
	HYPOT operator
	IMPART operator
	INT operator
	INTERPOL operator
	LCOF operator
	LENGTH operator
	LHS operator
	LIMIT operator
	LPOWER operator
	LTERM operator
	MAINVAR operator
	MAP operator
	MKID command
	NPRIMITIVE operator
	NUM operator
	ODESOLVE operator
	ONE‑OF type
	PART operator
	PF operator
	PROD operator
	REDUCT operator
	REPART operator
	RESULTANT operator
	RHS operator
	ROOT‑OF operator
	SELECT operator
	SHOWRULES operator
	SOLVE operator
	SORT operator
	STRUCTR operator
	SUB operator
	SUM operator
	WS operator

#$+ KALGEBRAIC				command

The algebraic  command changes REDUCE's mode of operation to algebraic. When algebraic  is used as an operator (with an argument inside parentheses) that argument is evaluated in algebraic mode, but REDUCE's mode is not changed. 

examples: 
 
algebraic;  
 
symbolic;  
 
  NIL  

algebraic(x**2);  
 
   2 
  X   

x**2;  
 
    ***** The symbol X has no value. 
 
REDUCE's symbolic mode does not know about most algebraic commands. Error messages in this mode may also depend on the particular Lisp used for the REDUCE implementation. 

#$+ KANTISYMMETRIC				declaration

 When an operator is declared antisymmetric , its arguments are reordered to conform to the internal ordering of the system. If an odd number of argument interchanges are required to do this ordering, the sign of the expression is changed. 

syntax: 
antisymmetric <identifier>{, <identifier>}* 

<identifier> is an identifier that has been declared as an operator. 

examples: 
 
operator m,n;  
 
antisymmetric m,n;  
 
m(x,n(1,2));  
 
  - M( - N(2,1),X)  

operator p;  
 
antisymmetric p;  
 
p(a,b,c);  
 
  P(A,B,C)  

p(b,a,c);  
 
  - P(A,B,C) 
 
If <identifier> has not been declared an operator, the flag antisymmetric  is still attached to it. When <identifier> is subsequently used as an operator, the message Declare  <identifier>  operator? (Y or N)  is printed. If the user replies y , the antisymmetric property of the operator is used. 

Note in the first example, identifiers are customarily ordered alphabetically, while numbers are ordered from largest to smallest. The operators may have any desired number of arguments (less than 128). 

#$+ KARRAY				declaration

 The array  declaration declares a list of identifiers to be of type array , and sets all their entries to 0.  
syntax: 

array <identifier>(<dimensions>)  {, <identifier>(<dimensions>)}* 

<identifier> may be any valid REDUCE identifier. If the identifier was already an array, a warning message is given that the array has been redefined. <dimensions> are of form  <integer>{,<integer>}*. 

examples: 
 
array a(2,5),b(3,3,3),c(200);  
 
array a(3,5);  
 
  *** ARRAY A REDEFINED  

a(3,4);  
 
  0  

length a;  
 
  4,6 
 
Arrays are always global, even if defined inside a procedure or block statement. Their status as an array remains until the variable is reset by clear . Arrays may not have the same names as operators, procedures or scalar variables. 

Array elements are referred to by the usual notation: a(i,j)  returns the jth element of the ith row. The assign ment operator :=  is used to put values into the array. Arrays as a whole cannot be subject to assignment by let  or :=  ; the assignment operator :=  is only valid for individual elements. 

When you use let  on an array element, the contents of that element become the argument to let . Thus, if the element contains a number or some other expression that is not a valid argument for this command, you get an error message. If the element contains an identifier, the identifier has the substitution rule attached to it globally. The same behavior occurs with clear . If the array element contains an identifier or simple_expression, it is cleared. Do <not> use clear  to try to set an array element to 0. Because of the side effects of either let  or clear , it is unwise to apply either of these to array elements. 

Array indices always start with 0, so that the declaration array a(5)  sets aside 6 units of space, indexed from 0 through 5, and initializes them to 0. The length  command returns a list of the true number of elements in each dimension. 

#$+ KCLEAR				command

 The clear  command is used to remove assignments or remove substitution rules from any expression. 

syntax: 
clear <identifier>{,<identifier>}+ or 

<let-type statement> clear  <identifier> 

<identifier> can be any scalar , matrix , or array  variable or procedure  name. <let-type statement> can be any general or specific let  statement (see below in Comments). 

examples: 
 
array a(2,3);  
 
a(2,2) := 15;  
 
  A(2,2) := 15  

clear a;  
 
a(2,2);  
 
  Declare A operator? (Y or N)  

let x = y + z;  
 
sin(x);  
 
  SIN(Y + Z)  

clear x;  
 
sin(x);  
 
  SIN(X)  

let x**5 = 7;  
 
clear x;  
 
x**5;  
 
  7  

clear x**5;  
 
x**5;  
 
   5 
  X 
 
Although it is not a good idea, operators of the same name but taking different numbers of arguments can be defined. Using a clear  statement on any of these operators clears every one with the same name, even if the number of arguments is different. 

The clear  command is used to ``forget" matrices, arrays, operators and scalar variables, returning their identifiers to the pristine state to be used for other purposes. When clear  is applied to array elements, the contents of the array element becomes the argument for clear . Thus, you get an error message if the element contains a number, or some other expression that is not a legal argument to clear . If the element contains an identifier, it is cleared. When clear is applied to matrix elements, an error message is returned if the element evaluates to a number, otherwise there is no effect. Do  not try to use clear  to set array or matrix elements to 0. You will not be pleased with the results. 

If you are trying to clear power or product substitution rules made with either let  or forall ...let , you must reproduce the rule, exactly as you typed it with the same arguments, up to but not including the equal sign, using the word clear  instead of the word let . This is shown in the last example. Any other type of let  or forall ...let  substitution can be cleared with just the variable or operator name. match  behaves the same as let  in this situation. There is a more complicated example under forall . 

#$+ KCLEARRULES				command

 
syntax: 
clearrules <list>{,<list>}+ 

The operator clearrules  is used to remove previously defined rule  lists from the system. <list> can be an explicit rule list, or evaluate to a rule list. 

examples: 
 
trig1 := {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2, 
	  cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2, 
	  sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2, 
	  cos(~x)^2       => (1+cos(2*x))/2, 
	  sin(~x)^2       => (1-cos(2*x))/2}$  
 
let trig1; 
cos(a)*cos(b);  
 
  COS(A - B) + COS(A + B) 
  -----------------------  
             2 

clearrules trig1; 
cos(a)*cos(b);  
 
  COS(A)*COS(B) 

#$+ KDEFINE				command

 The command define  allows you to supply a new name for an identifier or replace it by any valid REDUCE expression. 

syntax: 
define <identifier>= <substitution>  {, <identifier>= <substitution>}* 

<identifier> is any valid REDUCE identifier, <substitution> can be a number, an identifier, an operator, a reserved word, or an expression. 

examples: 

define is= :=, xx=y+z;  

a is 10;  
 
  A := 10  

 
xx**2;  
 
   2             2 
  Y   + 2*Y*Z + Z   

 
xx := 10;  
 
  Y + Z := 10 
 
The renaming is done at the input level, and therefore takes precedence over any other replacement or substitution declared for the same identifier. It remains in effect until the end of the REDUCE session. Be careful with it, since you cannot easily undo it without ending the session. 

#$+ KDEPEND				declaration

depend declares that its first argument depends on the rest of its arguments. 

syntax: 
depend <kernel>{, <kernel>}+ 

<kernel> must be a legal variable name or a prefix operator (see kernel ). 

examples: 

depend y,x;  

df(y**2,x);  
 
  2*DF(Y,X)*Y  

 
depend z,cos(x),y;  

df(sin(z),cos(x));  
 
  COS(Z)*DF(Z,COS(X))  

 
df(z**2,x);  
 
  2*DF(Z,X)*Z  

 
nodepend z,y;  

df(z**2,x);  
 
  2*DF(Z,X)*Z  

 
cc := df(y**2,x);  
 
  CC := 2*DF(Y,X)*Y  

 
y := tan x;  
 
  Y := TAN(X);  

 
cc;  
 
                  2 
  2*TAN(X)*(TAN(X)   + 1) 
 
Dependencies can be removed by using the declaration nodepend . The differentiation operator uses this information, as shown in the examples above. Linear operators also use knowledge of dependencies (see linear ). Note that dependencies can be nested: Having declared y to depend on x, and z to depend on y, we see that the chain rule was applied to the derivative of a function of z with respect to x. If the explicit function of the dependency is later entered into the system, terms with DF(Y,X) , for example, are expanded when they are displayed again, as shown in the last example. The boolean operator freeof  allows you to check the dependency between two algebraic objects. 

#$+ KEVEN				declaration

syntax: 

even <identifier>{,<identifier>}* 

This declaration is used to declare an operator even in its first argument. Expressions involving an operator declared in this manner are transformed if the first argument contains a minus sign. Any other arguments are not affected.  
examples: 
 
	even f;  
 
	f(-a)  
 
  F(A)  

	f(-a,-b)  
 
  F(A,-B) 

#$+ KFACTOR				declaration

When a kernel is declared by factor , all terms involving fixed powers of that kernel are printed as a product of the fixed powers and the rest of the terms.  
syntax: 

factor <kernel> {, <kernel>}* 

<kernel> must be a kernel  or a list  of kernel s. 

examples: 
 
a := (x + y + z)**2;  
 
        2                    2            2 
  A := X  + 2*X*Y + 2*X*Z + Y  + 2*Y*Z + Z   

factor y;  
 
a;  
 
   2                  2            2 
  Y  + 2*Y*(X + Z) + X  + 2*X*Z + Z   

factor sin(x);  
 
c := df(sin(x)**4*x**2*z,x);  
 
               4               3         2 
  C := 2*SIN(X) *X*Z + 4*SIN(X) *COS(X)*X *Z  

remfac sin(x);  
 
c;  
 
          3 
  2*SIN(X) *X*Z*(2*COS(X)*X + SIN(X)) 
 
Use the factor  declaration to display variables of interest so that you can see their powers more clearly, as shown in the example. Remove this special treatment with the declaration remfac . The factor  declaration is only effective when the switch pri  is on. 

The factor  declaration is not a factoring command; to factor expressions use the factor  switch or the factorize  command. 

The factor  declaration is helpful in such cases as Taylor polynomials where the explicit powers of the variable are expected at the top level, not buried in various factored forms. 

#$+ KFORALL				command

The forall  or (preferably) for all  command is used as a modifier for let  statements, indicating the universal applicability of the rule, with possible qualifications.  
syntax: 

for all <identifier>{,<identifier>}* let  <let statement> 

or 

for all <identifier>{,<identifier>}*  such that  <condition> let  <let statement> 

<identifier> may be any valid REDUCE identifier, <let statement> can be an operator, a product or power, or a group or block statement. <condition> must be a logical or comparison operator returning true or false. 

examples: 
 
for all x let f(x) = sin(x**2); 

 
  Declare F operator ? (Y or N)  

y  
 
f(a);  
 
       2 
  SIN(A )  

operator pos;  
 
for all x such that x>=0 let pos(x) = sqrt(x + 1);  
 
pos(5);  
 
  SQRT(6)  

pos(-5);  
 
  POS(-5)  

clear pos;  
 
pos(5);  
 
  Declare POS operator ? (Y or N)  

for all a such that numberp a let x**a = 1;  
 
x**4;  
 
  1  

clear x**a;  
 
  *** X**A not found  

for all a  clear x**a;  
 
x**4;  
 
  1  

for all a such that numberp a clear x**a;  
 
x**4;  
 
   4 
  X 
 
Substitution rules defined by for all  or forall ...such that  commands that involve products or powers are cleared by reproducing the command, with exactly the same variable names used, up to but not including the equal sign, with clear  replacing let , as shown in the last example. Other substitutions involving variables or operator names can be cleared with just the name, like any other variable. 

The match  command can also be used in product and power substitutions. The syntax of its use and clearing is exactly like let . A match  substitution only replaces the term if it is exactly like the pattern, for example match x**5 = 1  replaces only terms of x**5  and not terms of higher powers. 

It is easier to declare your potential operator before defining the for all  rule, since the system will ask you to declare it an operator anyway. Names of declared arrays or matrices or scalar variables are invalid as operator names, to avoid ambiguity. Either for all ...let  statements or procedures are often used to define operators. One difference is that procedures implement ``call by value" meaning that assignments involving their formal parameters do not change the calling variables that replace them. If you use assignment statements on the formal parameters in a for all ...let  statement, the effects are seen in the calling variables. Be careful not to redefine a system operator unless you mean it: the statement for all x letsin(x)=0;  has exactly that effect, and the usual definition for sin(x) has been lost for the remainder of the REDUCE session. 

#$+ KINFIX				declaration

infix declares identifiers to be infix operators.  
syntax: 

infix <identifier>{,<identifier>}* 

<identifier> can be any valid REDUCE identifier, which has not already been declared an operator, array or matrix, and is not reserved by the system. 

examples: 
 
infix aa;  
 
for all x,y let aa(x,y) = cos(x)*cos(y) - sin(x)*sin(y);  
 
x aa y;  
 
  COS(X)*COS(Y) - SIN(X)*SIN(Y)  

pi/3 aa pi/2;  
 
    SQRT(3) 
  - -------  
       2 

aa(pi,pi);  
 
  1 
 
A let  statement must be used to attach functionality to the operator. Note that the operator is defined in prefix form in the let  statement. After its definition, the operator may be used in either prefix or infix mode. The above operator aa finds the cosine of the sum of two angles by the formula 

cos(x+y) = cos(x)*cos(y) - sin(x)*sin(y). 

Precedence may be attached to infix operators with the precedence  declaration. 

User-defined infix operators may be used in prefix form. If they are used in infix form, a space must be left on each side of the operator to avoid ambiguity. Infix operators are always binary. 

#$+ KINTEGER				declaration

 The integer  declaration must be made immediately after a begin  (or other variable declaration such as real  and scalar ) and declares local integer variables. They are initialized to 0.  
syntax: 

integer <identifier>{,<identifier>}* 

<identifier> may be any valid REDUCE identifier, except t  or nil . 

Integer variables remain local, and do not share values with variables of the same name outside the begin ...end  block. When the block is finished, the variables are removed. You may use the words real  or scalar  in the place of integer . integer  does not indicate typechecking by the current REDUCE; it is only for your own information. Declaration statements must immediately follow the begin , without a semicolon between begin  and the first variable declaration. 

Any variables used inside begin ...end  blocks that were not declared scalar , real  or integer  are global, and any change made to them inside the block affects their global value. Any array  or matrix  declared inside a block is always global. 

#$+ KKORDER				declaration

The korder  declaration changes the internal canonical ordering of kernels.  
syntax: 

korder <kernel>{, <kernel>}* 

<kernel> must be a REDUCE kernel  or a list  of kernel s. 

The declaration korder  changes the internal ordering, but not the print ordering, so the effects cannot be seen on output. However, in some calculations, the order of the variables can have significant effects on the time and space demands of a calculation. If you are doing a demanding calculation with several kernels, you can experiment with changing the canonical ordering to improve behavior. 

The first kernel in the argument list is given the highest priority, the second gets the next highest, and so on. Kernels not named in a korder  ordering otherwise. A new korder  declaration replaces the previous one. To return to canonical ordering, use the command korder nil . 

To change the print ordering, use the declaration order . 

#$+ KLET				command

The let  command defines general or specific substitution rules.  
syntax: 

let <identifier> =  <expression>{,<identifier> =  <expression>}* 

<identifier> can be any valid REDUCE identifier except an array, and in some cases can be an expression; <expression> can be any valid REDUCE expression. 

examples: 
 
let a = sin(x);  
 
b := a;  
 
  B := SIN X;  

let c = a;  
 
exp(a);  
 
   SIN(X) 
  E        

a := x**2;  
 
        2 
  A := X   

exp(a);  
 
    2 
   X 
  E    

exp(b);  
 
   SIN(X) 
  E        

exp(c);  
 
    2 
   X 
  E    

let m + n = p;  
 
(m + n)**5;  
 
   5 
  P   

operator h;  
 
let h(u,v) = u - v;  
 
h(u,v);  
 
  U - V  

h(x,y);  
 
  H(X,Y)  

array q(10);  
 
let q(1) = 15;  
 
  ***** Substitution for 0 not allowed 
 
The let  command is also used to activate a rule sets .  
syntax: 

let <list>{,<list>}+ 

<list> can be an explicit rule  list , or evaluate to a rule list. 

examples: 
 
trig1 := {cos(~x)*cos(~y) => (cos(x+y)+cos(x-y))/2, 
	  cos(~x)*sin(~y) => (sin(x+y)-sin(x-y))/2, 
	  sin(~x)*sin(~y) => (cos(x-y)-cos(x+y))/2, 
	  cos(~x)^2       => (1+cos(2*x))/2, 
	  sin(~x)^2       => (1-cos(2*x))/2}$  
 
let trig1; 
cos(a)*cos(b);  
 
  COS(A - B) + COS(A + B) 
  ------------------------ 
             2 
 
A let  command returns no value, though the substitution rule is entered. Assignment rules made by assign  and let  rules are at the same level, and cancel each other. There is a difference in their operation, however, as shown in the first example: a let  assignment tracks the changes in what it is assigned to, while a :=  assignment is fixed at the value it originally had. 

The use of expressions as left-hand sides of let  statements is a little complicated. The rules of operation are: 

	(i) Expressions of the form A*B = C do not change A, B or C, but set A*B to C. 

	(ii) Expressions of the form A+B = C substitute C - B for A, but do not change B or C. 

	(iii) Expressions of the form A-B = C substitute B + C for A, but do not change B or C. 

	(iv) Expressions of the form A/B = C substitute B*C for A, but do not change B or C. 

	(v) Expressions of the form A**N = C substitute C for A**N in every expression of a power of A to N or greater. An asymptotic command such as A**N = 0 sets all terms involving A to powers greater than or equal to N to 0. Finite fields may be generated by requiring modular arithmetic (the modular  switch) and defining the primitive polynomial via a let  statement. 

let substitutions involving expressions are cleared by using the clear  command with exactly the same expression. 

Note when a simple let  statement is used to assign functionality to an operator, it is valid only for the exact identifiers used. For the use of the let  command to attach more general functionality to an operator, see forall . 

Arrays as a whole cannot be arguments to let  statements, but matrices as a whole can be legal arguments, provided both arguments are matrices. However, it is important to note that the two matrices are then linked. Any change to an element of one matrix changes the corresponding value in the other. Unless you want this behavior, you should not use let  for matrices. The assignment operator assign  can be used for non-tracking assignments, avoiding the side effects. Matrices are redimensioned as needed in let  statements. 

When array or matrix elements are used as the left-hand side of let  statements, the contents of that element is used as the argument. When the contents is a number or some other expression that is not a valid left-hand side for let , you get an error message. If the contents is an identifier or simple expression, the let  rule is globally attached to that identifier, and is in effect not only inside the array or matrix, but everywhere. Because of such unwanted side effects, you should not use let  with array or matrix elements. The assignment operator :=  can be used to put values into array or matrix elements without the side effects. 

Local variables declared inside begin ...end  blocks cannot be used as the left-hand side of let  statements. However, begin ...end  blocks themselves can be used as the right-hand side of let  statements. The construction:  
syntax: 

for all <vars>  let <operator>(<vars>)= <block> 

is an alternative to the  
syntax: 

procedure <name>(<vars>); <block> 

construction. One important difference between the two constructions is that the <vars> as formal parameters to a procedure have their global values protected against change by the procedure, while the <vars> of a let  statement are changed globally by its actions. 

Be careful in using a construction such as let x = x + 1  except inside a controlled loop statement. The process of resubstitution continues until a stack overflow message is given. 

The let  statement may be used to make global changes to variables from inside procedures. If x  is a formal parameter to a procedure, the command let x =  ... makes the change to the calling variable. For example, if a procedure was defined by  
        procedure f(x,y); 
        let x = 15; 

and the procedure was called as  
        f(a,b); 

a would have its value changed to 15. Be careful when using let  statements inside procedures to avoid unwanted side effects. 

It is also important to be careful when replacing let  statements with other let  statements. The overlapping of these substitutions can be unpredictable. Ordinarily the latest-entered rule is the first to be applied. Sometimes the previous rule is superseded completely; other times it stays around as a special case. The order of entering a set of related let  expressions is very important to their eventual behavior. The best approach is to assume that the rules will be applied in an arbitrary order. 

#$+ KLINEAR				declaration

An operator can be declared linear in its first argument over powers of its second argument by the declaration linear.   
syntax: 

linear <operator>{, <operator>}* 

<operator> must have been declared to be an operator. Be careful not to use a system operator name, because this command may change its definition. The operator being declared must have at least two arguments, and the second one must be a kernel . 

examples: 
 
operator f;  
 
linear f;  
 
f(0,x);  
 
  0  

f(-y,x);  
 
  - F(1,X)*Y  

f(y+z,x);  
 
  F(1,X)*(Y + Z)  

f(y*z,x);  
 
  F(1,X)*Y*Z  

depend z,x;  
 
f(y*z,x);  
 
  F(Z,X)*Y  

f(y/z,x);  
 
    1 
  F(-,X)*Y  
    Z 

depend y,x;  
 
f(y/z,x);  
 
    Y 
  F(-,X)  
    Z 

nodepend z,x;  
 
f(y/z,x);  
 
  F(Y,X) 
  ------  
    Z 

f(2*e**sin(x),x);  
 
       SIN(X) 
  2*F(E      ,X) 
 
Even when the operator has not had its functionality attached, it exhibits linear properties as shown in the examples. Notice the difference when dependencies are added. Dependencies are also in effect when the operator's first argument contains its second, as in the last line above. 

For a fully-developed example of the use of linear operators, refer to the article in the <Journal of Computational Physics>, Vol. 14 (1974), pp. 301-317, ``Analytic Computation of Some Integrals in Fourth Order Quantum Electrodynamics," by J.A. Fox and A.C. Hearn. The article includes the complete listing of REDUCE procedures used for this work. 

#$+ KLINELENGTH				declaration

The linelength  declaration sets the length of the output line. Default is 80.  
syntax: 

linelength <expression> 

To change the linelength, <expression> must evaluate to a positive integer less than 128 (although this varies from system to system), and should not be less than 20 or so for proper operation. 

linelength returns the previous linelength. If you want the current linelength value, but not change it, say linelength nil . 

#$+ KLISP				command

 The lisp  command changes REDUCE's mode of operation to symbolic. When lisp  is followed by an expression, that expression is evaluated in symbolic mode, but REDUCE's mode is not changed. This command is equivalent to symbolic . 

examples: 
 
lisp;  
 
  NIL  

car '(a b c d e);  
 
  A   

algebraic;  
 
c := (lisp car '(first second))**2;  

 
            2 
  C := FIRST 

#$+ KLISTARGP				declaration

 
syntax: 
listargp <operator>{, <operator>}* 

If an operator other than those specifically defined for lists is given a single argument that is a list , then the result of this operation will be a list in which that operator is applied to each element of the list. This process can be inhibited for a specific operator, or list of operators, by using the declaration listargp . 

examples: 
 
log {a,b,c};  
 
  LOG(A),LOG(B),LOG(C)  

listargp log;  
 
log {a,b,c};  
 
  LOG(A,B,C) 
 
It is possible to inhibit such distribution globally by turning on the switch listargs . In addition, if an operator has more than one argument, no such distribution occurs, so listargp  has no effect. 

#$+ KNODEPEND				declaration

The nodepend  declaration removes the dependency declared with depend .  
syntax: 

nodepend <dep-kernel>{,<kernel>}+ 

<dep-kernel> must be a kernel that has had a dependency declared upon the one or more other kernels that are its other arguments. 

examples: 
 
depend y,x,z;  
 
df(sin y,x);  
 
  COS(Y)*DF(Y,X)  

df(sin y,x,z);  
 
  COS(Y)*DF(Y,X,Z) - DF(Y,X)*DF(Y,Z)*SIN(Y)  

nodepend y,z;  
 
df(sin y,x);  
 
  COS(Y)*DF(Y,X)  

df(sin y,x,z);  
 
  0 
 
A warning message is printed if the dependency had not been declared by depend . 

#$+ KMATCH				command

The match  command is similar to the let  command, except that it matches only explicit powers in substitution.  
syntax: 

match <expr> =  <expression>{,<expr>  = <expression>}* 

<expr> is generally a term involving powers, and is limited by the rules for the let  command. <expression> may be any valid REDUCE scalar expression. 

examples: 
 
match c**2*a**2 = d; 
(a+c)**4;  
 
   4       3          3    4 
  A   + 4*A *C + 4*A*C  + C  + 6*D  

match a+b = c;  
 
a + 2*b;  
 
  B + C  

(a + b + c)**2;  
 
   2     2               2 
  A   - B   + 2*B*C + 3*C   

clear a+b;  
 
(a + b + c)**2;  
 
    2                    2            2 
  A   + 2*A*B + 2*A*C + B  + 2*B*C + C   

let p*r = s;  
 
match p*q = ss;  
 
(a + p*r)**2;  
 
   2            2 
  A  + 2*A*S + S   

(a + p*q)**2;  
 
   2              2  2 
  A   + 2*A*SS + P *Q 
 
Note in the last example that a + b  has been explicitly matched after the squaring was done, replacing each single power of a  by c - b . This kind of substitution, although following the rules, is confusing and could lead to unrecognizable results. It is better to use match  with explicit powers or products only. match  should not be used inside procedures for the same reasons that let  should not be. 

Unlike let  substitutions, match  substitutions are executed after all other operations are complete. The last example shows the difference. match  commands can be cleared by using clear , with exactly the expression that the original match  took. match  commands can also be done more generally with for all  or forall ...such that  commands. 

#$+ KNONCOM				declaration

noncom declares that already-declared operators are noncommutative under multiplication.  
syntax: 

noncom <operator>{,<operator>}* 

<operator> must have been declared an operator , or a warning message is given. 

examples: 
 
operator f,h;  
 
noncom f;  
 
f(a)*f(b) - f(b)*f(a);  
 
  F(A)*F(B) - F(B)*F(A)  

h(a)*h(b) - h(b)*h(a);  
 
  0  

operator comm;  
 
for all x,y such that x neq y and ordp(x,y) 
        let f(x)*f(y) = f(y)*f(x) + comm(x,y); 

f(1)*f(2);  
 
  F(1)*F(2)  

f(2)*f(1);  
 
  COMM(2,1) + F(1)*F(2) 
 
The last example introduces the commutator of f(x) and f(y) for all x and y. The equality check is to prevent an infinite loop. The operator f can have other functionality attached to it if desired, or it can remain an indeterminate operator. 

#$+ KNONZERO				declaration

 
syntax: 
nonzero <identifier>{,<identifier>}* 

If an operator  f  is declared odd , then f(0)  is replaced by zero unless f  is also declared non zero by the declaration nonzero .  
examples: 
 
	odd f;  
 
	f(0)  
 
  0  

	nonzero f;  
 
	f(0)  
 
  F(0) 

#$+ KODD				declaration

 
syntax: 
odd <identifier>{,<identifier>}* 

This declaration is used to declare an operator odd in its first argument. Expressions involving an operator declared in this manner are transformed if the first argument contains a minus sign. Any other arguments are not affected.  
examples: 
 
	odd f;  
 
	f(-a)  
 
  -F(A)  

	f(-a,-b)  
 
  -F(A,-B)  

	f(a,-b)  
 
  F(A,-B) 

If say f  is declared odd, then f(0)  is replaced by zero unless f  is also declared non zero by the declaration nonzero . 

#$+ KOFF				command

The off  command is used to turn switches off.  
syntax: 

off <switch>{,<switch>}* 

<switch> can be any switch  name. There is no problem if the switch is already off. If the switch name is mistyped, an error message is given. 

#$+ KON				command

The on  command is used to turn switches on.  
syntax: 

on <switch>{,<switch>}* 

<switch> can be any switch  name. There is no problem if the switch is already on. If the switch name is mistyped, an error message is given. 

#$+ KOPERATOR				declaration

 Use the operator  declaration to declare your own operators.  
syntax: 

operator <identifier>{,<identifier>}* 

<identifier> can be any valid REDUCE identifier, which is not the name of a matrix , array , scalar variable or previously-defined operator. 

examples: 
 
operator dis,fac;  
 
let dis(~x,~y) = sqrt(x^2 + y^2);  
 
dis(1,2);  
 
  SQRT(5)  

dis(a,10);  
 
        2 
  SQRT(A  + 100)  

on rounded;  
 
dis(1.5,7.2);  
 
  7.35459040329 

let fac(~n) = if n=0 then 1 
               else if not(fixp n and n>0) 
                then rederr "choose non-negative integer" 
               else for i := 1:n product i; 

fac(5);  
 
  120  

fac(-2);  
 
  ***** choose non-negative integer 
 
The first operator is the Euclidean distance metric, the distance of point (x,y) from the origin. The second operator is the factorial. 

Operators can have various properties assigned to them; they can be declared infix , linear , symmetric , antisymmetric , or noncom mutative . The default operator is prefix, nonlinear, and commutative. Precedence can also be assigned to operators using the declaration precedence . 

Functionality is assigned to an operator by a let  statement or a forall ...let  statement, (or possibly by a procedure with the name of the operator). Be careful not to redefine a system operator by accident. REDUCE permits you to redefine system operators, giving you a warning message that the operator was already defined. This flexibility allows you to add mathematical rules that do what you want them to do, but can produce odd or erroneous behavior if you are not careful. 

You can declare operators from inside procedure s, as long as they are not local variables. Operators defined inside procedures are global. A formal parameter may be declared as an operator, and has the effect of declaring the calling variable as the operator. 

#$+ KORDER				declaration

The order  declaration changes the order of precedence of kernels for display purposes only.  
syntax: 

order <identifier>{,<identifier>}* 

<kernel> must be a valid kernel  or operator  name complete with argument or a list  of such objects. 

examples: 
 
x + y + z + cos(a);  
 
  COS(A) + X + Y + Z  

order z,y,x,cos(a);  
 
x + y + z + cos(a);  
 
  Z + Y + X + COS(A)  

(x + y)**2;  
 
   2            2 
  Y  + 2*Y*X + X   

order nil;  
 
(z + cos(z))**2;  
 
        2                 2 
  COS(Z)  + 2*COS(Z)*Z + Z 
 
order affects the printing order of the identifiers only; internal order is unchanged. Change internal order of evaluation with the declaration korder . You can use order  to feature variables or functions you are particularly interested in. 

Declarations made with order  are cumulative: kernels in new order declarations are ordered behind those in previous declarations, and previous declarations retain their relative order. Of course, specific kernels named in new declarations are removed from previous ones and given the new priority. Return to the standard canonical printing order with the statement order nil . 

The print order specified by order  commands is not in effect if the switch pri  is off. 

#$+ KPRECEDENCE				declaration

The precedence  declaration attaches a precedence to an infix operator.  
syntax: 

precedence <operator>,<known‑operator> 

<operator> should have been declared an operator but may be a REDUCE identifier that is not already an operator, array, or matrix. <known‑operator> must be a system infix operator or have had its precedence already declared. 

examples: 
 
operator f,h;  
 
precedence f,+;  
 
precedence h,*;  
 
a + f(1,2)*c;  
 
  (1 F 2)*C + A  

a + h(1,2)*c;  
 
  1 H 2*C + A  

a*1 f 2*c;  
 
  A F 2*C  

a*1 h 2*c;  
 
  1 H 2*A*C 
 
The operator whose precedence is being declared is inserted into the infix operator precedence list at the next higher place than <known‑operator>. 

Attaching a precedence to an operator has the side effect of declaring the operator to be infix. If the identifier argument for precedence  has not been declared to be an operator, an attempt to use it causes an error message. After declaring it to be an operator, it becomes an infix operator with the precedence previously given. Infix operators may be used in prefix form; if they are used in infix form, a space must be left on each side of the operator to avoid ambiguity. Declared infix operators are always binary. 

To see the infix operator precedence list, enter symbolic mode and type preclis!*; . The lowest precedence operator is listed first. 

All prefix operators have precedence higher than infix operators. 

#$+ KPRECISION				declaration

The precision  declaration sets the number of decimal places used when rounded  is on. Default is system dependent, and normally about 12.  
syntax: 

precision (<integer>) or precision  <integer> 

<integer> must be a positive integer. When <integer> is 0, the current precision is displayed, but not changed. There is no upper limit, but precision of greater than several hundred causes unpleasantly slow operation on numeric calculations. 

examples: 
 
on rounded;  
 
7/9;  
 
  0.777777777778  

precision 20;  
 
  20  

7/9;  
 
  0.77777777777777777778  

sin(pi/4);  
 
  0.7071067811865475244 
 
Trailing zeroes are dropped, so sometimes fewer than 20 decimal places are printed as in the last example. Turn on the switch fullprec  if you want to print all significant digits. The rounded  mode carries calculations to two more places than given by precision , and rounds off. 

#$+ KPRINT‑PRECISION				declaration

 
syntax: 
print_precision (<integer>)  or print_precision  <integer> 

In rounded  mode, numbers are normally printed to the specified precision. If the user wishes to print such numbers with less precision, the printing precision can be set by the declaration print_precision . 

examples: 
 
on rounded;  
 
1/3;  
 
  0.333333333333  

print_precision 5;  
 
1/3  
 
  0.33333 

#$+ KREAL				declaration

 The real  declaration must be made immediately after a begin  (or other variable declaration such as integer  and scalar ) and declares local integer variables. They are initialized to zero.  
syntax: 

real <identifier>{,<identifier>}* 

<identifier> may be any valid REDUCE identifier, except t  or nil . 

Real variables remain local, and do not share values with variables of the same name outside the begin ...end  block. When the block is finished, the variables are removed. You may use the words integer  or scalar  in the place of real . real  does not indicate typechecking by the current REDUCE; it is only for your own information. Declaration statements must immediately follow the begin , without a semicolon between begin  and the first variable declaration. 

Any variables used inside a begin ...end  block  that were not declared scalar , real  or integer  are global, and any change made to them inside the block affects their global value. Any array  or matrix  declared inside a block is always global. 

#$+ KREMFAC				declaration

The remfac  declaration removes the special factoring treatment of its arguments that was declared with factor .  
syntax: 

remfac <kernel>{,<kernel>}+ 

<kernel> must be a kernel  or operator  name that was declared as special with the factor  declaration. 

#$+ KSCALAR				declaration

 The scalar  declaration must be made immediately after a begin  (or other variable declaration such as integer  and real ) and declares local scalar variables. They are initialized to 0.  
syntax: 

scalar <identifier>{,<identifier>}* 

<identifier> may be any valid REDUCE identifier, except t  or nil . 

Scalar variables remain local, and do not share values with variables of the same name outside the begin ...end  block . When the block is finished, the variables are removed. You may use the words real  or integer  in the place of scalar . real  and integer  do not indicate typechecking by the current REDUCE; they are only for your own information. Declaration statements must immediately follow the begin , without a semicolon between begin  and the first variable declaration. 

Any variables used inside begin ...end  blocks that were not declared scalar , real  or integer  are global, and any change made to them inside the block affects their global value. Arrays declared inside a block are always global. 

#$+ KSCIENTIFIC‑NOTATION				declaration

 
syntax: 
scientific_notation (<m>) or scientific_notation ({<m>,<n>}) 

<m> and <n> are positive integers. scientific_notation  controls the output format of floating point numbers. At the default settings, any number with five or less digits before the decimal point is printed in a fixed-point notation, e.g., 12345.6. Numbers with more than five digits are printed in scientific notation, e.g., 1.234567E+5. Similarly, by default, any number with eleven or more zeros after the decimal point is printed in scientific notation. 

When scientific_notation  is called with the numerical argument  m a number with more than m digits before the decimal point, or m or more zeros after the decimal point, is printed in scientific notation. When scientific_notation  is called with a list {<m>,<n>}, a number with more than m digits before the decimal point, or n or more zeros after the decimal point is printed in scientific notation. 

examples: 

on rounded; 

12345.6; 
 
  12345.6 

 
123456.5; 
 
  1.234565e+5 

 
0.00000000000000012; 
 
  1.2e-16 

 
scientific_notation 20; 
 
  5,11 

 
5: 123456.7; 
 
  123456.7 

 
0.00000000000000012; 
 
  0.00000000000000012 

#$+ KSHARE				declaration

 The share  declaration allows access to its arguments by both algebraic and symbolic modes.  
syntax: 

share <identifier>{,<identifier>}* 

<identifier> can be any valid REDUCE identifier. 

Programming in symbolic  as well as algebraic mode allows you a wider range of techniques than just algebraic mode alone. Expressions do not cross the boundary since they have different representations, unless the share  declaration is used. For more information on using symbolic mode, see the <REDUCE User's Manual>, and the <Standard Lisp Report>. 

You should be aware that a previously-declared array is destroyed by the share  declaration. Scalar variables retain their values. You can share a declared matrix  that has not yet been dimensioned so that it can be used by both modes. Values that are later put into the matrix are accessible from symbolic mode too, but not by the usual matrix reference mechanism. In symbolic mode, a matrix is stored as a list whose first element is MAT , and whose next elements are the rows of the matrix stored as lists of the individual elements. Access in symbolic mode is by the operators first , second , third  and rest . 

#$+ KSYMBOLIC				command

 The symbolic  command changes REDUCE's mode of operation to symbolic. When symbolic  is followed by an expression, that expression is evaluated in symbolic mode, but REDUCE's mode is not changed. It is equivalent to the lisp  command. 

examples: 
 
symbolic;  
 
  NIL  

cdr '(a b c);  
 
  (B C)  

algebraic;  
 
x + symbolic car '(y z);  
 
  X + Y 

#$+ KSYMMETRIC				declaration

When an operator is declared symmetric , its arguments are reordered to conform to the internal ordering of the system.  
syntax: 

symmetric <identifier>{,<identifier>}* 

<identifier> is an identifier that has been declared an operator. 

examples: 
 
operator m,n;  
 
symmetric m,n;  
 
m(y,a,sin(x));  
 
  M(SIN(X),A,Y)  

n(z,m(b,a,q));  
 
  N(M(A,B,Q),Z) 
 
If <identifier> has not been declared to be an operator, the flag symmetric  is still attached to it. When <identifier> is subsequently used as an operator, the message Declare <identifier>  operator ? (Y or N)  is printed. If the user replies y , the symmetric property of the operator is used. 

#$+ KTR				declaration

The tr  declaration is used to trace system or user-written procedures. It is only useful to those with a good knowledge of both Lisp and the internal formats used by REDUCE. 

syntax: 
tr <name>{,<name>}* 

<name> is the name of a REDUCE system procedure or one of your own procedures. 

examples: 
The system procedure prepsq  is traced, 	 which prepares REDUCE standard forms for printing by converting them to a Lisp prefix form.  
 
tr prepsq;  
 
  (PREPSQ)  

x**2 + y;  
 
  PREPSQ entry: 
    Arg 1: (((((X . 2) . 1) ((Y . 1) . 1)) . 1) 
  PREPSQ return value = (PLUS (EXPT X 2) Y) 
  PREPSQ entry: 
    Arg 1: (1 . 1) 
  PREPSQ return value = 1 
   2 
  X  + Y 

untr prepsq;  
 
  (PREPSQ) 

This example is for a PSL-based system; the above format will vary if other Lisp systems are used. 

When a procedure is traced, the first lines show entry to the procedure and the arguments it is given. The value returned by the procedure is printed upon exit. If you are tracing several procedures, with a call to one of them inside the other, the inner trace will be indented showing procedure nesting. There are no trace options. However, the format of the trace depends on the underlying Lisp system used. The trace can be removed with the command untr . Note that trace , below, is a matrix operator, while tr  does procedure tracing. 

#$+ KUNTR				declaration

The untr  declaration is used to remove a trace from system or user-written procedures declared with tr . It is only useful to those with a good knowledge of both Lisp and the internal formats used by REDUCE. 

syntax: 
untr <name>{,<name>}* 

<name> is the name of a REDUCE system procedure or one of your own procedures that has previously been the argument of a tr  declaration. 

#$+ KVARNAME				declaration

 The declaration varname  instructs REDUCE to use its argument as the default Fortran (when fort  is on) or structr  identifier and identifier stem, rather than using ANS .  
syntax: 

varname <identifier> 

<identifier> can be any combination of one or more alphanumeric characters. Try to avoid REDUCE reserved words. 

examples: 
 
varname ident;  
 
  IDENT  

on fort;  
 
x**2 + 1;  
 
  IDENT=X**2+1.  

off fort,exp;  
 
structr(((x+y)**2 + z)**3);  
 
        3 
  IDENT2 
      where 
                         2 
         IDENT2 := IDENT1  + Z 
  IDENT1 := X + Y 
 
exp was turned off so that structr  could show the structure. If exp  had been on, the expression would have been expanded into a polynomial. 

#$+ KWEIGHT				command

 The weight  command is used to attach weights to kernels for asymptotic constraints.  
syntax: 

weight <kernel> = <number> 

<kernel> must be a REDUCE kernel , <number> must be a positive integer, not 0. 

examples: 
 
a := (x+y)**4;  
 
        4      3        2  2        3    4 
  A := X  + 4*X *Y + 6*X *Y  + 4*X*Y  + Y   

weight x=2,y=3;  
 
wtlevel 8;  
 
a;  
 
   4 
  X   

wtlevel 10;  
 
a;  
 
   2     2             2 
  X *(6*Y  + 4*X*Y  + X )  

int(x**2,x);  
 
  ***** X invalid as KERNEL 
 
Weights and wtlevel  are used for asymptotic constraints, where higher-order terms are considered insignificant. 

Weights are originally equivalent to 0 until set by a weight  command. To remove a weight from a kernel, use the clear  command. Weights once assigned cannot be changed without clearing the identifier. Once a weight is assigned to a kernel, it is no longer a kernel and cannot be used in any REDUCE commands or operators that require kernels, until the weight is cleared. Note that terms are ordered by greatest weight. 

The weight level of the system is set by wtlevel , initially at 2. Since no kernels have weights, no effect from wtlevel  can be seen. Once you assign weights to kernels, you must set wtlevel  correctly for the desired operation. When weighted variables appear in a term, their weights are summed for the total weight of the term (powers of variables multiply their weights). When a term exceeds the weight level of the system, it is discarded from the result expression. 

#$+ KWHERE				operator

The where  operator provides an infix notation for one-time substitutions for kernels in expressions.  
syntax: 

<expression> where  <kernel>  = <expression> 	 {,<kernel> = <expression>}* 

<expression> can be any REDUCE scalar expression, <kernel> must be a kernel . Alternatively a rule  or a rule list  can be a member of the right-hand part of a where  expression. 

examples: 
 
x**2 + 17*x*y + 4*y**2 where x=1,y=2;  

  51  

for i := 1:5 collect x**i*q where q= for j := 1:i product j; 

 
        2    3     4      5 
  {X,2*X ,6*X ,24*X ,120*X }  

x**2 + y + z where z=y**3,y=3;  
 
   2    3 
  X  + Y  + 3 
 
Substitution inside a where  expression has no effect upon the values of the kernels outside the expression. The where  operator has the lowest precedence of all the infix operators, which are lower than prefix operators, so that the substitutions apply to the entire expression preceding the where  operator. However, where  is applied before command keywords such as then , repeat , or do . 

A rule  or a rule set  in the right-hand part of the where  expression act as if the rules were activated by let  immediately before the evaluation of the expression and deactivated by clearrules  immediately afterwards. 

where gives you a natural notation for auxiliary variables in expressions. As the second example shows, the substitute expression can be a command to be evaluated. The substitute assignments are made in parallel, rather than sequentially, as the last example shows. The expression resulting from the first round of substitutions is not reexamined to see if any further such substitutions can be made. where  can also be used to define auxiliary variables in procedure  definitions. 

#$+ KWHILE				command

The while  command causes a statement to be repeatedly executed until a given condition is true. If the condition is initially false, the statement is not executed at all.  
syntax: 

while <condition> do  <statement> 

<condition> is given by a logical operator, <statement> must be a single REDUCE statement, or a group  (<< ...>> ) or begin ...end  block . 

examples: 
 
a := 10;  
 
  A := 10  

while a <= 12 do <<write a; a := a + 1>>; 

 
  10  

                                          11  
 
                                          12  
 
while a < 5 do <<write a; a := a + 1>>; 

 
      nothing is printed 

#$+ KWTLEVEL				command

 In conjunction with weight , wtlevel  is used to implement asymptotic constraints. Its default value is 2.  
syntax: 

wtlevel <expression> 

To change the weight level, <expression> must evaluate to a positive integer that is the greatest weight term to be retained in expressions involving kernels with weight assignments. wtlevel  returns the new weight level. If you want the current weight level, but not change it, say wtlevel nil . 

examples: 
 
(x+y)**4;           

   4      3        2  2        3    4 
  X  + 4*X *Y + 6*X *Y  + 4*X*Y  + Y   

weight x=2,y=3;  
 
wtlevel 8;  
 
(x+y)**4;  
 
   4 
  X   

wtlevel 10;  
 
(x+y)**4;  
 
   2     2            2 
  X *(6*Y  + 4*X*Y + X )  

int(x**2,x);  
 
  ***** X invalid as KERNEL 
 
wtlevel is used in conjunction with the command weight  to enable asymptotic constraints. Weight of a term is computed by multiplying the weights of each variable in it by the power to which it has been raised, and adding the resulting weights for each variable. If the weight of the term is greater than wtlevel , the term is dropped from the expression, and not used in any further computation involving the expression. 

Once a weight has been attached to a kernel , it is no longer recognized by the system as a kernel, though still a variable. It cannot be used in REDUCE commands and operators that need kernels. The weight attachment can be undone with a clear  command. wtlevel  can be changed as desired. 

#$+Declarations

	ALGEBRAIC command
	ANTISYMMETRIC declaration
	ARRAY declaration
	CLEAR command
	CLEARRULES command
	DEFINE command
	DEPEND declaration
	EVEN declaration
	FACTOR declaration
	FORALL command
	INFIX declaration
	INTEGER declaration
	KORDER declaration
	LET command
	LINEAR declaration
	LINELENGTH declaration
	LISP command
	LISTARGP declaration
	NODEPEND declaration
	MATCH command
	NONCOM declaration
	NONZERO declaration
	ODD declaration
	OFF command
	ON command
	OPERATOR declaration
	ORDER declaration
	PRECEDENCE declaration
	PRECISION declaration
	PRINT‑PRECISION declaration
	REAL declaration
	REMFAC declaration
	SCALAR declaration
	SCIENTIFIC‑NOTATION declaration
	SHARE declaration
	SYMBOLIC command
	SYMMETRIC declaration
	TR declaration
	UNTR declaration
	VARNAME declaration
	WEIGHT command
	WHERE operator
	WHILE command
	WTLEVEL command

#$+ KIN				command

The in  command takes a list of file names and inputs each file into the system.  
syntax: 

in <filename>{,<filename>}* 

<filename> must be in the current directory, or be a valid pathname. If the file name is not an identifier, double quote marks (" ) are needed around the file name. 

A message is given if the file cannot be found, or has a mistake in it. 

Ending the command with a semicolon causes the file to be echoed to the screen; ending it with a dollar sign does not echo the file. If you want some but not all of a file echoed, turn the switch echo  on or off in the file. 

An efficient way to develop procedures in REDUCE is to write them into a file using a system editor of your choice, and then input the files into an active REDUCE session. REDUCE reparses the procedure as it takes information from the file, overwriting the previous procedure definition. When it accepts the procedure, it echoes its name to the screen. Data can also be input to the system from files. 

Files to be read in should always end in end ;  to avoid end-of-file problems. Note that this is an additional end;  to any ending procedures in the file. 

#$+ KINPUT				command

The input  command returns the input expression to the REDUCE numbered prompt that is its argument.  
syntax: 

input (<number>) or input  <number> 

<number> must be between 1 and the current REDUCE prompt number. 

An expression brought back by input  can be reexecuted with new values or switch settings, or used as an argument in another expression. The command ws  brings back the results of a numbered REDUCE statement. Two lists contain every input and every output statement since the beginning of the session. If your session is very long, storage space begins to fill up with these expressions, so it is a good idea to end the session once in a while, saving needed expressions to files with the saveas  and out  commands. 

Switch settings and let  statements can also be reexecuted by using input . 

An error message is given if a number is called for that has not yet been used. 

#$+ KOUT				command

The out  command directs output to the filename that is its argument, until another out  changes the output file, or shut  closes it.  
syntax: 

out <filename> or out " <pathname> "  or out t  

<filename> must be in the current directory, or be a valid complete file description for your system. If the file name is not in the current directory, quote marks are needed around the file name. If the file already exists, a message is printed allowing you to decide whether to supersede the contents of the file with new material. 

To restore output to the terminal, type out t , or shut  the file. When you use out t , the file remains available, and if you open it again (with another out ), new material is appended rather than overwriting. 

To write a file using out  that can be input at a later time, the switch nat  must be turned off, so that the standard linear form is saved that can be read in by in . If nat  is on, exponents are printed on the line above the expression, which causes trouble when REDUCE tries to read the file. 

There is a slight complication if you are using the out  command from inside a file to create another file. The echo  switch is normally off at the top-level and on while reading files (so you can see what is being read in). If you create a file using out  at the top-level, the result lines are printed into the file as you want them. But if you create such a file from inside a file, the echo  switch is on, and every line is echoed, first as you typed it, then as REDUCE parsed it, and then once more for the file. Therefore, when you create a file from a file, you need to turn echo  off explicitly before the out  command, and turn it back on when you shut  the created file, so your executing file echoes as it should. This behavior also means that as you watch the file execute, you cannot see the lines that are being put into the out  file. As soon as you turn echo  on, you can see output again. 

#$+ KSHUT				command

The shut  command closes output files.  
syntax: 

shut <filename>{,<filename>}* 

<filename> must have been a file opened by out . 

A file that has been opened by out  must be shut  before it is brought in by in . Files that have been opened by out  should always be shut  before the end of the REDUCE session, to avoid either loss of information or the printing of extraneous information into the file. In most systems, terminating a session by bye  closes all open output files. 

#$+Input and Output

	IN command
	INPUT command
	OUT command
	SHUT command

#$+ KACOS				operator

The acos  operator returns the arccosine of its argument. 

syntax: 
acos (<expression>) or acos  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
acos(ab);  
 
  ACOS(AB)  

acos 15;  
 
  ACOS(15)  

df(acos(x*y),x);  
 
           2  2 
  SQRT( - X *Y  + 1)*Y 
  --------------------  
        2  2 
       X *Y  - 1 

on rounded;  
 
res := acos(sqrt(2)/2);  
 
  RES := 0.785398163397  

res-pi/4;  
 
  0 
 
An explicit numeric value is not given unless the switch rounded  is on and the argument has an absolute numeric value less than or equal to 1. 

#$+ KACOSH				operator

acosh represents the hyperbolic arccosine of its argument. It takes an arbitrary scalar expression as its argument. The derivative of acosh  is known to the system. Numerical values may also be found by turning on the switch rounded . 

syntax: 
acosh (<expression>) or acosh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
acosh a;  
 
  ACOSH(A)  

acosh(0);  
 
  ACOSH(0)  

df(acosh(a**2),a);  
 
          4 
  2*SQRT(A  - 1)*A 
  ----------------  
        4 
       A  - 1 

int(acosh(x),x);  
 
  INT(ACOSH(X),X) 
 
You may attach functionality by defining acosh  to be the inverse of cosh . This is done by the commands  
        put('cosh,'inverse,'acosh); 
        put('acosh,'inverse,'cosh); 

You can write a procedure to attach integrals or other functions to acosh . You may wish to add a check to see that its argument is properly restricted. 

#$+ KACOT				operator

acot represents the arccotangent of its argument. It takes an arbitrary scalar expression as its argument. The derivative of acot  is known to the system. Numerical values may also be found by turning on the switch rounded . 

syntax: 
acot (<expression>) or acot  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. You can add functionality yourself with let  and procedures. 

#$+ KACOTH				operator

acoth represents the inverse hyperbolic cotangent of its argument. It takes an arbitrary scalar expression as its argument. The derivative of acoth  is known to the system. Numerical values may also be found by turning on the switch rounded . 

syntax: 
acoth (<expression>) or acoth  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. You can add functionality yourself with let  and procedures. 

#$+ KACSC				operator

The acsc  operator returns the arccosecant of its argument. 

syntax: 
acsc (<expression>) or acsc  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
acsc(ab);  
 
  ACSC(AB)  

acsc 15;  
 
  ACSC(15)  

df(acsc(x*y),x);  
 
         2  2 
  -SQRT(X *Y  - 1) 
  ----------------  
       2  2 
   X*(X *Y  - 1) 

on rounded;  
 
res := acsc(2/sqrt(3));  
 
  RES := 1.0471975512  

res-pi/3;  
 
  0 
 
An explicit numeric value is not given unless the switch rounded  is on and the argument has an absolute numeric value less than or equal to 1. 

#$+ KACSCH				operator

The acsch  operator returns the hyperbolic arccosecant of its argument. 

syntax: 
acsch (<expression>) or acsch  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
acsch(ab);  
 
  ACSCH(AB)  

acsch 15;  
 
  ACSCH(15)  

df(acsch(x*y),x);  
 
         2  2 
  -SQRT(X *Y  + 1) 
  ----------------  
       2  2 
   X*(X *Y  + 1) 

on rounded;  
 
res := acsch(3);  
 
  RES := 0.327450150237 
 
An explicit numeric value is not given unless the switch rounded  is on and the argument has an absolute numeric value less than or equal to 1. 

#$+ KASEC				operator

The asec  operator returns the arccosecant of its argument. 

syntax: 
asec (<expression>) or asec  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
asec(ab);  
 
  ASEC(AB)  

asec 15;  
 
  ASEC(15)  

df(asec(x*y),x);  
 
        2  2 
  SQRT(X *Y  - 1) 
  ---------------  
       2  2 
   X*(X *Y  - 1) 

on rounded;  
 
res := asec sqrt(2);  
 
  RES := 0.785398163397  

res-pi/4;  
 
  0 
 
An explicit numeric value is not given unless the switch rounded  is on and the argument has an absolute numeric value greater or equal to 1. 

#$+ KASECH				operator

asech represents the hyperbolic arccosecant of its argument. It takes an arbitrary scalar expression as its argument. The derivative of asech  is known to the system. Numerical values may also be found by turning on the switch rounded . 

syntax: 
asech (<expression>) or asech  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
asech a;  
 
  ASECH(A)  

asech(1);  
 
  0  

df(acosh(a**2),a);  
 
            4 
  2*SQRT(- A  + 1) 
  ----------------  
         4 
     A*(A  - 1) 

int(asech(x),x);  
 
  INT(ASECH(X),X) 
 
You may attach functionality by defining asech  to be the inverse of sech . This is done by the commands  
        put('sech,'inverse,'asech); 
        put('asech,'inverse,'sech); 

You can write a procedure to attach integrals or other functions to asech . You may wish to add a check to see that its argument is properly restricted. 

#$+ KASIN				operator

The asin  operator returns the arcsine of its argument. 

syntax: 
asin (<expression>) or asin  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
asin(givenangle);  
 
  ASIN(GIVENANGLE)  

asin(5);  
 
  ASIN(5)  

df(asin(2*x),x);  
 
                 2 
    2*SQRT( - 4*X  + 1)) 
  - --------------------  
             2 
          4*X  - 1 

on rounded;  
 
asin .5;  
 
  0.523598775598  

asin(sqrt(3));  
 
  ASIN(1.73205080757)  

asin(sqrt(3)/2);  
 
  1.04719755120  
 
A numeric value is not returned by asin  unless the switch rounded  is on and its argument has an absolute value less than or equal to 1. 

#$+ KASINH				operator

The asinh  operator returns the hyperbolic arcsine of its argument. The derivative of asinh  and some simple transformations are known to the system. 

syntax: 
asinh (<expression>) or asinh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
asinh d;  
 
  ASINH(D)  

asinh(1);  
 
  ASINH(1)  

df(asinh(2*x),x);  
 
            2 
  2*SQRT(4*X  + 1)) 
  -----------------  
         2 
      4*X  + 1 
 
You may attach further functionality by defining asinh  to be the inverse of sinh . This is done by the commands  
        put('sinh,'inverse,'asinh); 
        put('asinh,'inverse,'sinh); 

A numeric value is not returned by asinh  unless the switch rounded  is on and its argument evaluates to a number. 

#$+ KATAN				operator

The atan  operator returns the arctangent of its argument. 

syntax: 
atan (<expression>) or atan  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
atan(middle);  
 
  ATAN(MIDDLE)  

on rounded;  
 
atan 45;  
 
  1.54857776147  

off rounded;  
 
int(atan(x),x);  
 
                     2 
  2*ATAN(X)*X - LOG(X  + 1) 
  -------------------------  
              2 

df(atan(y**2),y);  
 
   2*Y 
  ------- 
   4 
  Y  + 1 
 
A numeric value is not returned by atan  unless the switch rounded  is on and its argument evaluates to a number. 

#$+ KATANH				operator

The atanh  operator returns the hyperbolic arctangent of its argument. The derivative of asinh  and some simple transformations are known to the system. 

syntax: 
atanh (<expression>) or atanh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
atanh aa;  
 
  ATANH(AA)  

atanh(1);  
 
  ATANH(1)  

df(atanh(x*y),y);  
 
     - X 
  ---------- 
   2  2 
  X *Y  - 1 
 
A numeric value is not returned by asinh  unless the switch rounded  is on and its argument evaluates to a number. You may attach additional functionality by defining atanh  to be the inverse of tanh . This is done by the commands 

        put('tanh,'inverse,'atanh); 
        put('atanh,'inverse,'tanh); 

#$+ KATAN2				operator

 
syntax: 
atan2 (<expression>,<expression>) 

<expression> is any valid scalar REDUCE expression. In rounded  mode, if a numerical value exists, atan2  returns the principal value of the arc tangent of the second argument divided by the first in the range [-pi,+pi] radians, using the signs of both arguments to determine the quadrant of the return value. An expression in terms of atan2  is returned in other cases. 

examples: 
 
atan2(3,2);  
 
  ATAN2(3,2);  

on rounded;  
 
atan2(3,2);  
 
  0.982793723247  

atan2(a,b);  
 
  ATAN2(A,B);  

atan2(1,0);  
 
  1.57079632679 
 
atan2 returns a numeric value only if rounded  is on. Then atan2  is calculated to the current degree of floating point precision. 

#$+ KCOS				operator

 The cos  operator returns the cosine of its argument. 

syntax: 
cos (<expression>) or cos  <simple‑expression> 

<expression> is any valid scalar REDUCE expression, <simple‑expression> is a single identifier or begins with a prefix operator name. 

examples: 

 
cos abc;  
 
  COS(ABC)  

 
cos(pi);  
 
  -1  

 
cos 4;  
 
  COS(4)  

 
on rounded;  

cos(4);  
 
  - 0.653643620864  

 
cos log 5;  
 
  - 0.0386319699339 
 
cos returns a numeric value only if rounded  is on. Then the cosine is calculated to the current degree of floating point precision. 

#$+ KCOSH				operator

The cosh  operator returns the hyperbolic cosine of its argument. The derivative of cosh  and some simple transformations are known to the system. 

syntax: 
cosh (<expression>) or cosh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 

cosh b;  
 
  COSH(B)  

 
cosh(0);  
 
  1  

 
df(cosh(x*y),x);  
 
  SINH(X*Y)*Y  

 
int(cosh(x),x);  
 
  SINH(X) 
 
You may attach further functionality by defining its inverse (see acosh ). A numeric value is not returned by cosh  unless the switch rounded  is on and its argument evaluates to a number. 

#$+ KCOT				operator

 cot  represents the cotangent of its argument. It takes an arbitrary scalar expression as its argument. The derivative of acot  and some simple properties are known to the system. 

syntax: 
cot (<expression>) or cot  <simple‑expression> 

<expression> may be any scalar REDUCE expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
cot(a)*tan(a);  
 
  COT(A)*TAN(A))  

cot(1);  
 
  COT(1)  

df(cot(2*x),x);  
 
               2 
  - 2*(COT(2*X)   + 1) 
 
Numerical values of expressions involving cot  may be found by turning on the switch rounded . 

#$+ KCOTH				operator

The coth  operator returns the hyperbolic cotangent of its argument. The derivative of coth  and some simple transformations are known to the system. 

syntax: 
coth (<expression>) or coth  <simple‑expression> 

<expression> may be any scalar REDUCE expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
df(coth(x*y),x);  
 
                2 
  - Y*(COTH(X*Y)   - 1)  

 
coth acoth z;  
 
  Z 
 
You can write let  statements and procedures to add further functionality to coth  if you wish. Numerical values of expressions involving coth  may also be found by turning on the switch rounded . 

#$+ KCSC				operator

The csc  operator returns the cosecant of its argument. The derivative of csc  and some simple transformations are known to the system. 

syntax: 
csc (<expression>) or csc  <simple‑expression> 

<expression> may be any scalar REDUCE expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 

csc(q)*sin(q);  
 
  CSC(Q)*SIN(Q)  

 
df(csc(x*y),x);  
 
  -COT(X*Y)*CSC(X*Y)*Y 
 
You can write let  statements and procedures to add further functionality to csc  if you wish. Numerical values of expressions involving csc  may also be found by turning on the switch rounded . 

#$+ KCSCH				operator

The cosh  operator returns the hyperbolic cosecant of its argument. The derivative of csch  and some simple transformations are known to the system. 

syntax: 
csch (<expression>) or csch  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 

csch b;  
 
  CSCH(B)  

 
csch(0);  
 
  0  

 
df(csch(x*y),x);  
 
  - COTH(X*Y)*CSCH(X*Y)*Y  

 
int(csch(x),x);  
 
  INT(CSCH(X),X) 
 
A numeric value is not returned by csch  unless the switch rounded  is on and its argument evaluates to a number. 

#$+ KERF				operator

The erf  operator represents the error function, defined by 

erf(x) = (2/sqrt(pi))*int(e^(-x^2),x) 

A limited number of its properties are known to the system, including the fact that it is an odd function. Its derivative is known, and from this, some integrals may be computed. However, a complete integration procedure for this operator is not currently included. 

examples: 
 
erf(0);  
 
  0  

erf(-a);  
 
  - ERF(A)  

df(erf(x**2),x);  
 
  4*SQRT(PI)*X 
  ------------  
       4 
      X 
     E  *PI 

 
int(erf(x),x);  
 
    2 
   X 
  E  *ERF(X)*PI*X + SQRT(PI) 
  --------------------------- 
              2 
             X 
            E  *PI 

#$+ KEXP				operator

The exp  operator returns e  raised to the power of its argument.  
syntax: 

exp (<expression>) or exp  <simple‑expression> 

<expression> can be any valid REDUCE scalar expression. <simple‑expression> must be a single identifier or begin with a prefix operator. 

examples: 
 
exp(sin(x));  
 
   SIN X 
  E       

exp(11);  
 
   11 
  E    

on rounded;  
 
exp sin(pi/3);  
 
  2.37744267524 
 
Numeric values are returned only when rounded  is on. The single letter e  with the exponential operator ^  or **  may be substituted for exp  without change of function. 

#$+ KSEC				operator

 The sec  operator returns the secant of its argument. 

syntax: 
sec (<expression>) or sec  <simple‑expression> 

<expression> is any valid scalar REDUCE expression, <simple‑expression> is a single identifier or begins with a prefix operator name. 

examples: 

 
sec abc;  
 
  SEC(ABC)  

 
sec(pi);  
 
  -1  

 
sec 4;  
 
  SEC(4)  

 
on rounded;  

sec(4);  
 
  - 1.52988565647  

 
sec log 5;  
 
  - 25.8852966005 
 
sec returns a numeric value only if rounded  is on. Then the secant is calculated to the current degree of floating point precision. 

#$+ KSECH				operator

The sech  operator returns the hyperbolic secant of its argument. 

syntax: 
sech (<expression>) or sech  <simple‑expression> 

<expression> is any valid scalar REDUCE expression, <simple‑expression> is a single identifier or begins with a prefix operator name. 

examples: 
 
sech abc;  
 
  SECH(ABC)  

 
sech(0);  
 
  1  

 
sech 4;  
 
  SECH(4)  

 
on rounded;  

sech(4);  
 
  0.0366189934737  

 
sech log 5;  
 
  0.384615384615 
 
sech returns a numeric value only if rounded  is on. Then the expression is calculated to the current degree of floating point precision. 

#$+ KSIN				operator

The sin  operator returns the sine of its argument.  
syntax: 

sin (<expression>) or sin  <simple‑expression> 

<expression> is any valid scalar REDUCE expression, <simple‑expression> is a single identifier or begins with a prefix operator name. 

examples: 
 
sin aa;  
 
  SIN(AA)  

sin(pi/2);  
 
  1  

on rounded;  
 
sin 3;  
 
  0.14112000806  

sin(pi/2);  
 
  1.0 
 
sin returns a numeric value only if rounded  is on. Then the sine is calculated to the current degree of floating point precision. The argument in this case is assumed to be in radians. 

#$+ KSINH				operator

The sinh  operator returns the hyperbolic sine of its argument. The derivative of sinh  and some simple transformations are known to the system. 

syntax: 
sinh (<expression>) or sinh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 

sinh b;  
 
  SINH(B)  

 
sinh(0);  
 
  0  

df(sinh(x**2),x);  
 
          2 
  2*COSH(X )*X  

int(sinh(4*x),x);  
 
  COSH(4*X) 
  ---------  
      4 

on rounded;  
 
sinh 4;  
 
  27.2899171971 
 
You may attach further functionality by defining its inverse (see asinh ). A numeric value is not returned by sinh  unless the switch rounded  is on and its argument evaluates to a number. 

#$+ KTAN				operator

 The tan  operator returns the tangent of its argument.  
syntax: 

tan (<expression>) or tan  <simple‑expression> 

<expression> is any valid scalar REDUCE expression, <simple‑expression> is a single identifier or begins with a prefix operator name. 

examples: 
 
tan a;  
 
  TAN(A)  

tan(pi/5);  
 
      PI 
  TAN(--)  
      5 

on rounded; 
tan(pi/5);  
 
  0.726542528005 
 
tan returns a numeric value only if rounded  is on. Then the tangent is calculated to the current degree of floating point accuracy. 

When rounded  is on, no check is made to see if the argument of tan  is a multiple of pi/2, for which the tangent goes to positive or negative infinity. (Of course, since REDUCE uses a fixed-point representation of pi/2, it produces a large but not infinite number.) You need to make a check for multiples of pi/2 in any program you use that might possibly ask for the tangent of such a quantity. 

#$+ KTANH				operator

The tanh  operator returns the hyperbolic tangent of its argument. The derivative of tanh  and some simple transformations are known to the system. 

syntax: 
tanh (<expression>) or tanh  <simple‑expression> 

<expression> may be any scalar REDUCE expression, not an array, matrix or vector expression. <simple‑expression> must be a single identifier or begin with a prefix operator name. 

examples: 
 
tanh b;  
 
  TANH(B)  

tanh(0);  
 
  0  

df(tanh(x*y),x);  
 
                 2 
  Y*( - TANH(X*Y)  + 1)  

int(tanh(x),x);  
 
       2*X 
  LOG(E    + 1) - X  

on rounded; tanh 2;  
 
  0.964027580076 
 
You may attach further functionality by defining its inverse (see atanh ). A numeric value is not returned by tanh  unless the switch rounded  is on and its argument evaluates to a number. 

#$+Elementary Functions

	ACOS operator
	ACOSH operator
	ACOT operator
	ACOTH operator
	ACSC operator
	ACSCH operator
	ASEC operator
	ASECH operator
	ASIN operator
	ASINH operator
	ATAN operator
	ATANH operator
	ATAN2 operator
	COS operator
	COSH operator
	COT operator
	COTH operator
	CSC operator
	CSCH operator
	ERF operator
	EXP operator
	SEC operator
	SECH operator
	SIN operator
	SINH operator
	TAN operator
	TANH operator

#$+ KSWITCHES				introduction

 Switches are set on or off using the commands on  or off , respectively. The default setting of the switches described in this section is off  unless stated otherwise. 

#$+ KALGINT				switch

When the algint  switch is on, the algebraic integration module (which must be loaded from the REDUCE library) is used for integration. 

Loading algint  from the library automatically turns on the algint  switch. An error message will be given if algint  is turned on when the algint  has not been loaded from the library. 

#$+ KALLBRANCH				switch

 When allbranch  is on, the operator solve  selects all branches of solutions. When allbranch  is off, it selects only the principal branches. Default is on . 

examples: 

solve(log(sin(x+3)),x);  
 
  {X=2*ARBINT(1)*PI - ASIN(1) - 3, 
   X=2*ARBINT(1)*PI + ASIN(1) + PI - 3} 

off allbranch;  
 
solve(log(sin(x+3)),x);  
 
  X=ASIN(1) - 3 
 
arbint (1) indicates an arbitrary integer, which is given a unique identifier by REDUCE, showing that there are infinitely many solutions of this type. When allbranch  is off, the single canonical solution is given. 

#$+ KALLFAC				switch

The allfac  switch, when on, causes REDUCE to factor out automatically common products in the output of expressions. Default is on . 

examples: 
 
x + x*y**3 + x**2*cos(z);  
 
                 3 
  X*(COS(Z)*X + Y   + 1)  

off allfac;  
 
x + x*y**3 + x**2*cos(z);  
 
          2      3 
  COS(Z)*X  + X*Y   + X 
 
The allfac  switch has no effect when pri  is off. Although the switch setting stays as it was, printing behavior is as if it were off. 

#$+ KARBVARS				switch

When arbvars  is on, the solutions of singular or underdetermined systems of equations are presented in terms of arbitrary complex variables (see arbcomplex ). Otherwise, the solution is parametrized in terms of some of the input variables. Default is on . 

examples: 
 
solve({2x + y,4x + 2y},{x,y});  
 
         arbcomplex(1) 
  {{x= - -------------,y=arbcomplex(1)}}  
               2 

solve({sqrt(x)+ y**3-1},{x,y});				 

                            6       3 
  		   {{y=arbcomplex(2),x=y   - 2*y   + 1}}  

off arbvars;  
 
solve({2x + y,4x + 2y},{x,y});  
 
         y 
  {{x= - -}}  
         2 

solve({sqrt(x)+ y**3-1},{x,y});				 

            6       3 
  		   {{x=y   - 2*y   + 1}}  
 
With arbvars  off, the return value {{}}  means that the equations given to solve  imply no relation among the input variables. 

#$+ KBALANCED‑MOD				switch

modular numbers are normally produced in the range [0,...<n>), where <n> is the current modulus. With balanced_mod  on, the range [-<n>/2,<n>/2] is used instead. 

examples: 
 
setmod 7;  
 
  1  

on modular;  
 
4;  
 
  4  

on balanced_mod;  
 
4;  
 
  -3 

#$+ KBFSPACE				switch

Floating point numbers are normally printed in a compact notation (either fixed point or in scientific notation if SCIENTIFIC_NOTATION  has been used). In some (but not all) cases, it helps comprehensibility if spaces are inserted in the number at regular intervals. The switch bfspace , if on, will cause a blank to be inserted in the number after every five characters.  
examples: 
 
on rounded;  
 
1.2345678;  
 
  1.2345678  

on bfspace;  
 
1.2345678;  
 
  1.234 5678 

bfspace is normally off. 

#$+ KCOMBINEEXPT				switch

REDUCE is in general poor at surd simplification. However, when the switch combineexpt  is on, the system attempts to combine exponentials whenever possible. 

examples: 
 
3^(1/2)*3^(1/3)*3^(1/6);  
 
           1/3  1/6 
  SQRT(3)*3   *3     

on combineexpt;  
 
ws;  
 
  1 

#$+ KCOMBINELOGS				switch

In many cases it is desirable to expand product arguments of logarithms, or collect a sum of logarithms into a single logarithm. Since these are inverse operations, it is not possible to provide rules for doing both at the same time and preserve the REDUCE concept of idempotent evaluation. As an alternative, REDUCE provides two switches expandlogs  and combinelogs  to carry out these operations.  
examples: 
 
on expandlogs;  
 
log(x*y);  
 
  LOG(X) + LOG(Y)  

on combinelogs;  
 
ws;  
 
  LOG(X*Y) 

At the present time, it is possible to have both switches on at once, which could lead to infinite recursion. However, an expression is switched from one form to the other in this case. Users should not rely on this behavior, since it may change in the next release. 

#$+ KCOMP				switch

When comp  is on, any succeeding function definitions are compiled into a faster-running form. Default is off . 

examples: 
The following procedure finds Fibonacci numbers recursively. Create a new file ``refib" in your current directory with the following lines in it:  
 
procedure refib(n); 
   if fixp n and n >= 0 then 
     if n <= 1 then 1 
       else refib(n-1) + refib(n-2) 
    else rederr "nonnegative integer only"; 
 
end; 
 
Now load REDUCE and run the following: 
 
on time;  
 
  Time: 100 ms  

 
in "refib"$  
 
  Time: 0 ms  

 

  REFIB  

 

  Time: 260 ms  

 

  Time: 20 ms  

 
refib(80);  
 
  37889062373143906  

 

  Time: 14840 ms  

 
on comp;  
 
  Time: 80 ms  

 
in "refib"$  
 
  Time: 20 ms  

 

  REFIB  

 

  Time: 640 ms  

 
refib(80);  
 
  37889062373143906  

 

  Time: 10940 ms 

Note that the compiled procedure runs faster. Your time messages will differ depending upon which system you have. Compiled functions remain so for the duration of the REDUCE session, and are then lost. They must be recompiled if wanted in another session. With the switch time  on as shown above, the CPU time used in executing the command is returned in milliseconds. Be careful not to leave comp  on unless you want it, as it makes the processing of procedures much slower. 

#$+ KCOMPLEX				switch

When the complex  switch is on, full complex arithmetic is used in simplification, function evaluation, and factorization. Default is off . 

examples: 

factorize(a**2 + b**2);  
 
    2     2 
  {A   + B  }  

on complex;  

factorize(a**2 + b**2);  
 
  {A - I*B,A + I*B}  

 
(x**2 + y**2)/(x + i*y);  
 
  X - I*Y  

 
on rounded;  
 
      *** Domain mode COMPLEX changed to COMPLEX_FLOAT  

 
sqrt(-17);  
 
  4.12310562562*I  

 
log(7*i);  
 
  1.94591014906 + 1.57079632679*I 
 
Complex floating-point can be done by turning on rounded  in addition to complex . With complex  off however, REDUCE knows that i is the square root of -1 but will not carry out more complicated complex operations. If you want complex denominators cleared by multiplication by their conjugates, turn on the switch rationalize . 

#$+ KCREF				switch

The switch cref  invokes the CREF cross-reference program that processes a set of procedure definitions to produce a summary of their entry points, undefined procedures, non-local variables and so on. The program will also check that procedures are called with a consistent number of arguments, and print a diagnostic message otherwise. 

The output is alphabetized on the first seven characters of each function name. 

To invoke the cross-reference program, cref  is first turned on. This causes the program to load and the cross-referencing process to begin. After all the required definitions are loaded, turning cref  off will cause a cross-reference listing to be produced. 

Algebraic procedures in REDUCE are treated as if they were symbolic, so that algebraic constructs will actually appear as calls to symbolic functions, such as aeval . 

#$+ KCRAMER				switch

When the cramer  switch is on, matrix  inversion and linear equation solving (operator solve ) is done by Cramer's rule, through exterior multiplication. Default is off . 

examples: 
 
on time;  
 
  Time: 80 ms  

off output;  
 
  Time: 100 ms  

mm := mat((a,b,c,d,f),(a,a,c,f,b),(b,c,a,c,d), (c,c,a,b,f), 
          (d,a,d,e,f)); 

  Time: 300 ms  

inverse := 1/mm;  
 
  Time: 18460 ms  

on cramer;  
 
  Time: 80 ms  

cramersinv := 1/mm;  
 
  Time: 9260 ms 
 
Your time readings will vary depending on the REDUCE version you use. After you invert the matrix, turn on output  and ask for one of the elements of the inverse matrix, such as cramersinv(3,2) , so that you can see the size of the expressions produced. 

Inversion of matrices and the solution of linear equations with dense symbolic entries in many variables is generally considerably faster with cramer  on. However, inversion of numeric-valued matrices is slower. Consider the matrices you're inverting before deciding whether to turn cramer  on or off. A substantial portion of the time in matrix inversion is given to formatting the results for printing. To save this time, turn output  off, as shown in this example or terminate the expression with a dollar sign instead of a semicolon. The results are still available to you in the workspace associated with your prompt number, or you can assign them to an identifier for further use. 

#$+ KDEFN				switch

When the switch defn  is on, the Standard Lisp equivalent of the input statement or procedure is printed, but not evaluated. Default is off . 

examples: 

on defn;  

17/3;  
 
  (AEVAL (LIST 'QUOTIENT 17 3))  

 
df(sin(x),x,2);           

  (AEVAL (LIST 'DF (LIST 'SIN 'X) 'X 2))  

procedure coshval(a); 
   begin scalar g; 
      g := (exp(a) + exp(-a))/2; 
      return g 
   end; 

  (AEVAL  
    (PROGN  
      (FLAG '(COSHVAL) 'OPFN)  
      (DE COSHVAL (A)  
        (PROG (G)  
          (SETQ G  
            (AEVAL  
               (LIST  
                  'QUOTIENT  
                  (LIST  
                     'PLUS  
                     (LIST 'EXP A)  
                     (LIST 'EXP (LIST 'MINUS A)))  
                  2)))  
         (RETURN G)))) )  

 
coshval(1);  
 
  (AEVAL (LIST 'COSHVAL 1))  

 
off defn;  

coshval(1);  
 
  Declare COSHVAL operator? (Y or N)  

 
n  
 
procedure coshval(a); 
   begin scalar g; 
      g := (exp(a) + exp(-a))/2; 
      return g 
   end; 

  COSHVAL  

 
on rounded;  

coshval(1);  
 
  1.54308063482 
 
The above function coshval  finds the hyperbolic cosine (cosh) of its argument. When defn  is on, you can see the Standard Lisp equivalent of the function, but it is not entered into the system as shown by the message Declare COSHVAL operator? . It must be reentered with defn  off to be recognized. This procedure is used as an example; a more efficient procedure would eliminate the unnecessary local variable with  
      procedure coshval(a); 
         (exp(a) + exp(-a))/2; 

#$+ KDEMO				switch

The demo  switch is used for interactive files, causing the system to pause after each command in the file until you type a Return . Default is off . 

The switch demo  has no effect on top level interactive statements. Use it when you want to slow down operations in a file so you can see what is happening. 

You can either include the on demo  command in the file, or enter it from the top level before bringing in any file. Unlike the pause  command, on demo  does not permit you to interrupt the file for questions of your own. 

#$+ KDFPRINT				switch

When dfprint  is on, expressions in the differentiation operator df  are printed in a more ``natural'' notation, with the differentiation variables appearing as subscripts. In addition, if the switch noarg  is on (the default), the arguments of the differentiated operator are suppressed. 

examples: 
 
operator f;  
 
df(f x,x);  
 
  DF(F(X),X);  

on dfprint;  
 
ws;  
 
  F   
   X 

df(f(x,y),x,y);  
 
  F   
   Y 

off noarg;  
 
ws;  
 
  F(X,Y) 
        X 

#$+ KDIV				switch

When div  is on, the system divides any simple factors found in the denominator of an expression into the numerator. Default is off . 

examples: 

on div;  

a := x**2/y**2;  
 
        2   -2 
  A := X  *Y    

 
b := a/(3*z);  
 
       1  2   -2    -1 
  B := -*X  *Y    *Z    
       3 

 
off div;  

a;  
 
   2 
  X 
  --- 
   2 
  Y 

 
b;  
 
     2 
    X 
  -------                                        
     2 
  3*Y  *Z 
 
The div  switch only has effect when the pri  switch is on. When pri  is off, regardless of the setting of div , the printing behavior is as if div  were off. 

#$+ KECHO				switch

The echo  switch is normally off for top-level entry, and on when files are brought in. If echo  is turned on at the top level, your input statements are echoed to the screen (thus appearing twice). Default off  (but note default on  for files). 

If you want to display certain portions of a file and not others, use the commands off echo  and on echo  inside the file. If you want no display of the file, use the input command 

	in  filename$  

rather than using the semicolon delimiter. 

Be careful when you use commands within a file to generate another file. Since echo  is on for files, the output file echoes input statements (unlike its behavior from the top level). You should explicitly turn off echo  when writing output, and turn it back on when you're done. 

#$+ KERRCONT				switch

When the errcont  switch is on, error conditions do not stop file execution. Error messages will be printed whether errcont  is on or off. 

Default is off . 

The following describes what happens when an error occurs in a file under each setting of errcont  and int : 

Both off: Message is printed and parsing continues, but no further statements are executed; no commands from keyboard accepted except bye or end; 

errcont off, int  on: Message is printed, and you are asked if you wish to continue. (This is the default behavior); 

errcont on, int  off: Message is printed, and file continues to execute without pause; 

Both on: Message is printed, and file continues to execute without pause. 

#$+ KEVALLHSEQP				switch

Under normal circumstances, the right-hand-side of an equation  is evaluated but not the left-hand-side. This also applies to any substitutions made by the sub  operator. If both sides are to be evaluated, the switch evallhseqp  should be turned on. 

#$+ KEXP				switch

When the exp  switch is on, powers and products of expressions are expanded. Default is on . 

examples: 
 
(x+1)**3;  
 
   3      2 
  X  + 3*X  + 3*X + 1  

(a + b*i)*(c + d*i);  
 
  A*C + A*D*I + B*C*I - B*D  

off exp;  
 
(x+1)**3;  
 
         3 
  (X + 1)   

(a + b*i)*(c + d*i);  
 
  (A + B*I)*(C + D*I)  

length((x+1)**2/(y+1));  
 
  2 
 
Note that REDUCE knows that i^2 = -1. When exp  is off, equivalent expressions may not simplify to the same form, although zero expressions still simplify to zero. Several operators that expect a polynomial argument behave differently when exp  is off, such as length . Be cautious about leaving exp  off. 

#$+ KEXPANDLOGS				switch

In many cases it is desirable to expand product arguments of logarithms, or collect a sum of logarithms into a single logarithm. Since these are inverse operations, it is not possible to provide rules for doing both at the same time and preserve the REDUCE concept of idempotent evaluation. As an alternative, REDUCE provides two switches expandlogs  and combinelogs  to carry out these operations. Both are off by default.  
examples: 
 
on expandlogs;  
 
log(x*y);  
 
  LOG(X) + LOG(Y)  

on combinelogs;  
 
ws;  
 
  LOG(X*Y) 

At the present time, it is possible to have both switches on at once, which could lead to infinite recursion. However, an expression is switched from one form to the other in this case. Users should not rely on this behavior, since it may change in the next release. 

#$+ KEZGCD				switch

When ezgcd  and gcd  are on, greatest common divisors are computed using the EZ GCD algorithm that uses modular arithmetic (and is usually faster). Default is off . 

As a side effect of the gcd calculation, the expressions involved are factored, though not the heavy-duty factoring of factorize . The EZ GCD algorithm was introduced in a paper by J. Moses and D.Y.Y. Yun in <Proceedings of the ACM>, 1973, pp. 159-166. 

Note that the gcd  switch must also be on for ezgcd  to have effect. 

#$+ KFACTOR				switch

When the factor  switch is on, input expressions and results are automatically factored. 

examples: 

on factor;  

aa := 3*x**3*a + 6*x**2*y*a + 3*x**3*b + 6*x**2*y*b 
 
+ x*y*a + 2*y**2*a + x*y*b + 2*y**2*b; 

 
                    2 
  AA := (A + B)*(3*X  + Y)*(X + 2*Y)  

off factor;  
 
aa;  
 
       3        2                  2         3        2 
  3*A*X  + 6*A*X *Y + A*X*Y + 2*A*Y   + 3*B*X  + 6*B*X *Y 

+ B*X*Y + 2*B*Y^{2}  
 
on factor;  
 
ab := x**2 - 2;  
 
         2 
  AB := X  - 2 
 
REDUCE factors univariate and multivariate polynomials with integer coefficients, finding any factors that also have integer coefficients. The factoring is done by reducing multivariate problems to univariate ones with symbolic coefficients, and then solving the univariate ones modulo small primes. The results of these calculations are merged to determine the factors of the original polynomial. The factorizer normally selects evaluation points and primes using a random number generator. Thus, the detailed factoring behavior may be different each time any particular problem is tackled. 

When the factor  switch is turned on, the exp  switch is turned off, and when the factor  switch is turned off, the exp  switch is turned on, whether it was on previously or not. 

When the switch trfac  is on, informative messages are generated at each call to the factorizer. The trallfac  switch causes the production of a more verbose trace message. It takes precedence over trfac  if they are both on. 

To factor a polynomial explicitly and store the results, use the operator factorize . 

#$+ KFAILHARD				switch

When the failhard  switch is on, the integration operator int  terminates with an error message if the integral cannot be done in closed terms. Default is off. 

Use the failhard  switch when you are dealing with complicated integrals and want to know immediately if REDUCE was unable to handle them. The integration operator sometimes returns a formal integration form that is more complicated than the original expression, when it is unable to complete the integration. 

#$+ KFORT				switch

When fort  is on, output is given Fortran-compatible syntax. Default is off . 

examples: 
 
on fort;  
 
df(sin(7*x + y),x);  
 
  ANS=7.*COS(7*X+Y)  

on rounded;  
 
b := log(sin(pi/5 + n*pi));  
 
  	       B=LOG(SIN(3.14159265359*N+0.628318530718)) 
 
REDUCE results can be written to a file (using out ) and used as data by Fortran programs when fort  is in effect. fort  knows about correct statement length, continuation characters, defining a symbol when it is first used, and other Fortran details. 

The GENTRAN  package offers many more possibilities than the fort  switch. It produces Fortran (or C or Ratfor) code from REDUCE procedures or structured specifications, including facilities for producing double precision output. 

#$+ KFORTUPPER				switch

When fortupper  is on, any Fortran-style output appears in upper case. Default is off . 

examples: 
 
on fort;  
 
df(sin(7*x + y),x);  
 
  ans=7.*cos(7*x+y)  

on fortupper;  
 
df(sin(7*x + y),x);  
 
  ANS=7.*COS(7*X+Y)  

#$+ KFULLPREC				switch

Trailing zeroes of rounded numbers to the full system precision are normally not printed. If this information is needed, for example to get a more understandable indication of the accuracy of certain data, the switch fullprec  can be turned on. 

examples: 
 
on rounded;  
 
1/2;  
 
  0.5  

on fullprec;  
 
ws;  
 
  0.500000000000 
 
This is just an output options which neither influences the accuracy of the computation nor does it give additional information about the precision of the results. See also scientific_notation . 

#$+ KFULLROOTS				switch

Since roots of cubic and quartic polynomials can often be very messy, a switch fullroots  controls the production of results in closed form. solve  will apply the formulas for explicit forms for degrees 3 and 4 only if fullroots  is on . Otherwise the result forms are built using root_of . Default is off . 

#$+ KGC				switch

With the gc  switch, you can turn the garbage collection messages on or off. The form of the message depends on the particular Lisp used for the REDUCE implementation. 

See reclaim  for an explanation of garbage collection. REDUCE does garbage collection when needed even if you have turned the notices off. 

#$+ KGCD				switch

When gcd  is on, common factors in numerators and denominators of expressions are canceled. Default is off . 

examples: 

(2*(f*h)**2 - f**2*g*h - (f*g)**2 - f*h**3 + f*h*g**2 
   - h**4 + g*h**3)/(f**2*h - f**2*g - f*h**2 + 2*f*g*h 
   - f*g**2 - g*h**2 + g**2*h); 

   2  2    2          2  2      2        3      3    4 
  F *G  + F *G*H - 2*F *H  - F*G *H + F*H  - G*H  + H 
  ----------------------------------------------------  
    2      2        2                2    2        2 
   F *G - F *H + F*G  - 2*F*G*H + F*H  - G *H + G*H 

on gcd;  
 
ws;  
 
                 2 
  F*G + 2*F*H + H 
  ----------------  
       F + G 

e2 := a*c + a*d + b*c + b*d;  
 
  E2 := A*C + A*D + B*C + B*D  

off exp;  
 
e2;  
 
  (A + B)*(C + D) 
 
Even with gcd  off, a check is automatically made for common variable and numerical products in the numerators and denominators of expression, and the appropriate cancellations made. Thus the example demonstrating the use of gcd  is somewhat complicated. Note when exp  is off, gcd  has the side effect of factoring the expression. 

#$+ KHORNER				switch

When the horner  switch is on, polynomial expressions are printed in Horner's form for faster and safer numerical evaluation. Default is off . The leading variable of the expression is selected as Horner variable. To select the Horner variable explicitly use the korder  declaration. 

examples: 
 
on horner; 
 
(13p-4q)^3; 
 
           3            2 
  ( - 64)*q   + p*(624*q   + p*(( - 2028)*q + p*2197)) 

korder q; 
 
ws; 
 
        3                  2 
  2197*p   + q*(( - 2028)*p   + q*(624*p + q*(-64))) 

#$+ KIFACTOR				switch

When the ifactor  switch is on, any integer terms appearing as a result of the factorize  command are factored themselves into primes. Default is off . If the argument of factorize  is an integer, ifactor  has no effect, since the integer is always factored. 

examples: 
 
factorize(4*x**2 + 28*x + 48);  
 
  {4,X + 3,X + 4}  

factorize(22587);  
 
  {3,7529}  

on ifactor;  
 
factorize(4*x**2 + 28*x + 48);  
 
  {2,2,X + 4,X + 3}  

factorize(22587);  
 
  {3,7529} 
 
Constant terms that appear within nonconstant polynomial factors are not factored. 

The ifactor  switch affects only factoring done specifically with factorize , not on factoring done automatically when the factor  switch is on. 

#$+ KINT				switch

The int  switch specifies an interactive mode of operation. Default on . 

There is no reason to turn int  off during interactive calculations, since there are no benefits to be gained. If you do have int  off while inputting a file, and REDUCE finds an error, it prints the message ``Continuing with parsing only." In this state, REDUCE accepts only end ;  or bye ;  from the keyboard; everything else is ignored, even the command on int . 

#$+ KINTSTR				switch

If intstr  (for ``internal structure'') is on, arguments of an operator are printed in a more structured form. 

examples: 
 
operator f;  
 
f(2x+2y);  
 
  F(2*X + 2*Y)  

on intstr;  
 
ws;  
 
  F(2*(X + Y)) 

#$+ KLCM				switch

The lcm  switch instructs REDUCE to compute the least common multiple of denominators whenever rational expressions occur. Default is on . 

examples: 
 
off lcm;  
 
z := 1/(x**2 - y**2) + 1/(x-y)**2;   

 
              2*X*(X - Y) 
  Z := -------------------------  
        4      3          3    4 
       X  - 2*X *Y + 2*X*Y  - Y 

on lcm;  
 
z;  
 
         2*X*(X - Y) 
  -------------------------  
   4      3          3    4 
  X  - 2*X *Y + 2*X*Y  - Y 

zz := 1/(x**2 - y**2) + 1/(x-y)**2; 

 
                 2*X 
  ZZ := ---------------------  
         3    2        2    3 
        X  - X *Y - X*Y  + Y 

on gcd;  
 
z;  
 
           2*X 
  ---------------------- 
   3    2        2    3 
  X  - X *Y - X*Y  + Y 
 
Note that lcm  has effect only when rational expressions are first combined. It does not examine existing structures for simplifications on display. That is shown above when z is entered with lcm  off. It remains unsimplified even after lcm  is turned back on. However, a new variable containing the same expression is simplified on entry. The switch gcd  does examine existing structures, as shown in the last example line above. 

Full greatest common divisor calculations become expensive if work with large rational expressions is required. A considerable savings of time can be had if a full gcd check is made only when denominators are combined, and only a partial check for numerators. This is the effect of the lcm  switch. 

#$+ KLESSSPACE				switch

You can turn on the switch lessspace  if you want fewer blank lines in your output. 

#$+ KLIMITEDFACTORS				switch

To get limited factorization in cases where it is too expensive to use full multivariate polynomial factorization, the switch limitedfactors  can be turned on. In that case, only ``inexpensive'' factoring operations, such as square-free factorization, will be used when factorize  is called. 

examples: 
 
a := (y-x)^2*(y^3+2x*y+5)*(y^2-3x*y+7)$  
 
factorize a;  
 
  { - X + Y, 
   X - Y, 
            3 
   2*X*Y + Y  + 5, 
            2 
   3*X*Y - Y  - 7} 

on limitedfactors;  
 
factorize a;  
 
  { - X + Y, 
   X - Y, 
      2  2        4        3          5      3      2 
   6*X *Y  + 3*X*Y  - 2*X*Y  + X*Y - Y  - 7*Y  - 5*Y  - 35} 

#$+ KLIST				switch

 The list  switch causes REDUCE to print each term in any sum on separate lines. 

examples: 
 
x**2*(y**2 + 2*y) + x*(y**2 + z)/(2*a); 

 
            2              2 
  X*(2*A*X*Y  + 4*A*X*Y + Y  +Z) 
  ------------------------------  
               2*A 

on list;  
 
ws;  
 
             2 
  (X*(2*A*X*Y 
    + 4*A*X*Y 
       2 
    + Y 
    + Z))/(2*A) 

#$+ KLISTARGS				switch

If an operator other than those specifically defined for lists is given a single argument that is a list, then the result of this operation will be a list in which that operator is applied to each element of the list. This process can be inhibited globally by turning on the switch listargs . 

examples: 
 
log {a,b,c};  
 
  LOG(A),LOG(B),LOG(C)  

on listargs;  
 
log {a,b,c};  
 
  LOG(A,B,C) 
 
It is possible to inhibit such distribution for a specific operator by using the declaration listargp . In addition, if an operator has more than one argument, no such distribution occurs, so listargs  has no effect. 

#$+ KMCD				switch

When mcd  is on, sums and differences of rational expressions are put on a common denominator. Default is on . 

examples: 
 
a/(x+1) + b/5;  
 
  5*A + B*X + B 
  -------------  
    5*(X + 1) 

off mcd;  
 
a/(x+1) + b/5;  
 
         -1 
  (X + 1)  *A + 1/5*B  

1/6 + 1/7;  
 
  13/42 
 
Even with mcd  off, rational expressions involving only numbers are still put over a common denominator. 

Turning mcd  off is useful when explicit negative powers are needed, or if no greatest common divisor calculations are desired, or when differentiating complicated rational expressions. Results when mcd  is off are no longer in canonical form, and expressions equivalent to zero may not simplify to 0. Some operations, such as factoring cannot be done while mcd  is off. This option should therefore be used with some caution. Turning mcd  off is most valuable in intermediate parts of a complicated calculation, and should be turned back on for the last stage. 

#$+ KMODULAR				switch

When modular  is on, polynomial coefficients are reduced by the modulus set by setmod . If no modulus has been set, modular  has no effect. 

examples: 
 
setmod 2;  
 
  1  

on modular;  
 
(x+y)**2;  
 
   2    2 
  X  + Y   

145*x**2 + 20*x**3 + 17 + 15*x*y; 

 
   2 
  X  + X*Y + 1 
 
Modular operations are only conducted on the coefficients, not the exponents. The modulus is not restricted to being prime. When the modulus is prime, division by a number not relatively prime to the modulus results in a <Zero divisor> error message. When the modulus is a composite number, division by a power of the modulus results in an error message, but division by an integer which is a factor of the modulus does not. The representation of modular number can be influenced by balanced_mod . 

#$+ KMSG				switch

When msg  is off, the printing of warning messages is suppressed. Error messages are still printed. 

Warning messages include those about redimensioning an array  or declaring an operator  where one is expected. 

#$+ KMULTIPLICITIES				switch

When solve  is applied to a set of equations with multiple roots, solution multiplicities are normally stored in the global variable root_multiplicities  rather than the solution list. If you want the multiplicities explicitly displayed, the switch multiplicities  should be turned on. In this case, root_multiplicities  has no value. 

examples: 
 
solve(x^2=2x-1,x);  
 
  X=1  

root_multiplicities;  
 
  2  

on multiplicities;  
 
solve(x^2=2x-1,x);  
 
  X=1,X=1  

root_multiplicities;  

#$+ KNAT				switch

When nat  is on, output is printed to the screen in natural form, with raised exponents. nat  should be turned off when outputting expressions to a file for future input. Default is on . 

examples: 
 
(x + y)**3;  
 
   3      2          2    3 
  X  + 3*X *Y + 3*X*Y  + Y   

off nat;  
 
(x + y)**3;  
 
  X**3 + 3*X**2*Y + 3*X*Y**2 + Y**3$  

on fort;  
 
(x + y)**3;  
 
  ANS=X**3+3.*X**2*Y+3.*X*Y**2+Y**3 
 
With nat  off, a dollar sign is printed at the end of each expression. An output file written with nat  off is ready to be read into REDUCE using the command in . 

#$+ KNERO				switch

When nero  is on, zero assignments (such as matrix elements) are not printed. 

examples: 
 
matrix a; 
a := mat((1,0),(0,1));  
 
  A(1,1) := 1 
  A(1,2) := 0 
  A(2,1) := 0 
  A(2,2) := 1 

on nero;  
 
a;  
 
  MAT(1,1) := 1 
  MAT(2,2) := 1 

a(1,2); nothing is printed. 

b := 0; nothing is printed. 

off nero;  
 
b := 0;  
 
  B := 0 

nero is often used when dealing with large sparse matrices, to avoid being overloaded with zero assignments. 

#$+ KNOARG				switch

When dfprint  is on, expressions in the differentiation operator df  are printed in a more ``natural'' notation, with the differentiation variables appearing as subscripts. When noarg  is on (the default), the arguments of the differentiated operator are also suppressed. 

examples: 
 
operator f;  
 
df(f x,x);  
 
  DF(F(X),X);  

on dfprint;  
 
ws;  
 
  F   
   X 

off noarg;  
 
ws;  
 
  F(X) 
      X 

#$+ KNOLNR				switch

When nolnr  is on, the linear properties of the integration operator int  are suppressed if the integral cannot be found in closed terms. 

REDUCE uses the linear properties of integration to attempt to break down an integral into manageable pieces. If an integral cannot be found in closed terms, these pieces are returned. When the nolnr  switch is off, as many of the pieces as possible are integrated. When it is on, if any piece fails, the rest of them remain unevaluated. 

#$+ KNOSPLIT				switch

Under normal circumstances, the printing routines try to break an expression across lines at a natural point. This is a fairly expensive process. If you are not overly concerned about where the end-of-line breaks come, you can speed up the printing of expressions by turning off the switch nosplit . This switch is normally on. 

#$+ KNUMVAL				switch

With rounded  on, elementary functions with numerical arguments will return a numerical answer where appropriate. If you wish to inhibit this evaluation, numval  should be turned off. It is normally on. 

examples: 
 
on rounded;  
 
cos 3.4;  
 
  - 0.966798192579  

off numval;  
 
cos 3.4;  
 
  COS(3.4) 

#$+ KOUTPUT				switch

When output  is off, no output is printed from any REDUCE calculation. The calculations have their usual effects other than printing. Default is on . 

Turn output off  if you do not wish to see output when executing large files, or to save the time REDUCE spends formatting large expressions for display. Results are still available with ws , or in their assigned variables. 

#$+ KOVERVIEW				switch

When overview  is on, the amount of detail reported by the factorizer switches trfac  and trallfac  is reduced. 

#$+ KPERIOD				switch

When period  is on, periods are added after integers in Fortran-compatible output (when fort  is on). There is no effect when fort  is off. Default is on . 

#$+ KPRECISE				switch

When the precise  switch is on, simplification of roots of even powers returns absolute values, a more precise answer mathematically. Default is on . 

examples: 
 
sqrt(x**2);  
 
  X  

(x**2)**(1/4);  
 
  SQRT(X)  

on precise;  
 
sqrt(x**2);  
 
  ABS(X)  

(x**2)**(1/4);  
 
  SQRT(ABS(X)) 
 
In many types of mathematical work, simplification of powers and surds can proceed by the fastest means of simplifying the exponents arithmetically. When it is important to you that the positive root be returned, turn precise  on. One situation where this is important is when graphing square-root expressions such as sqrt(x^2+y^2) to avoid a spike caused by REDUCE simplifying sqrt(y^2) to y when x is zero. 

#$+ KPRET				switch

When pret  is on, input is printed in standard REDUCE format and then evaluated. 

examples: 
 
on pret;  
 
 (x+1)^3;  
 
   (x + 1)**3; 
   3      2 
  X  + 3*X  + 3*X + 1 

 
procedure fac(n); 
   if not (fixp(n) and n>=0) 
     then rederr "Choose nonneg. integer only" 
    else for i := 0:n-1 product i+1; 

  procedure fac n; 
     if not (fixp n and n>=0) 
       then rederr "Choose nonneg. integer only" 
      else for i := 0:n - 1 product i + 1; 
  FAC 

 
fac 5;  
 
  fac 5; 
  120 
 
Note that all input is converted to lower case except strings (which keep the same case) all operators with a single argument have had the parentheses removed, and all infix operators have had a space added on each side. In addition, syntactical constructs like if ...then ...else  are printed in a standard format. 

#$+ KPRI				switch

When pri  is on, the declarations order  and factor  can be used, and the switches allfac , div , rat , and revpri  take effect when they are on. Default is on . 

Printing of expressions is faster with pri  off. The expressions are then returned in one standard form, without any of the display options that can be used to feature or display various parts of the expression. You can also gain insight into REDUCE's representation of expressions with pri  off. 

#$+ KRAISE				switch

When raise  is on, lower case letters are automatically converted to upper case on input. raise  is normally on. 

This conversion affects the internal representation of the letter, and is independent of the case with which a letter is printed, which is normally lower case. 

#$+ KRAT				switch

When the rat  switch is on, and kernels have been selected to display with the factor  declaration, the denominator is printed with each term rather than one common denominator at the end of an expression. 

examples: 
 
(x+1)/x + x**2/sin y;         

                       3 
  SIN(Y)*X + SIN(Y) + X 
  ---------------------- factor x;  
         SIN(Y)*X 

(x+1)/x + x**2/sin y;         

   3 
  X  + X*SIN(Y) + SIN(Y) 
  ---------------------- on rat;   
         X*SIN(Y) 

(x+1)/x + x**2/sin y;        

     2 
    X           -1 
  ------ + 1 + X 
  SIN(Y) 
 
The rat  switch only has effect when the pri  switch is on. When pri  is off, regardless of the setting of rat , the printing behavior is as if rat  were off. rat  only has effect upon the display of expressions, not their internal form. 

#$+ KRATARG				switch

When ratarg  is on, rational expressions can be given to operators such as coeff  and lterm  that normally require polynomials in one of their arguments. When ratarg  is off, rational expressions cause an error message. 

examples: 
 
aa := x/y**2 + 1/x + y/x**2;  

         3      2    3 
        X  + X*Y  + Y 
  AA := --------------  
             2  2 
            X *Y 

coeff(aa,x);  
 
         3      2    3 
        X  + X*Y  + Y 
  ***** -------------- invalid as POLYNOMIAL 
             2  2 
            X *Y 

on ratarg;  
 
coeff(aa,x);                 

   Y  1      1 
  {--,--,0,-----} 
    2  2    2  2 
   X  X    X *Y 

#$+ KRATIONAL				switch

When rational  is on, polynomial expressions with rational coefficients are produced. 

examples: 
 
x/2 + 3*y/4;  
 
  2*X + 3*Y 
  ---------  
      4 

(x**2 + 5*x + 17)/2;  
 
   2 
  X  + 5*X + 17 
  -------------  
        2 

on rational;  
 
x/2 + 3y/4;  
 
  1      3 
  -*(X + -*Y)  
  2      2 

(x**2 + 5*x + 17)/2;  
 
  1   2 
  -*(X  + 5*X + 17) 
  2 
 
By using rational , polynomial expressions with rational coefficients can be used in some commands that expect polynomials. With rational  off, such a polynomial becomes a rational expression, with denominator the least common multiple of the denominators of the rational number coefficients. 

#$+ KRATIONALIZE				switch

When the rationalize  switch is on, denominators of rational expressions that contain complex numbers or root expressions are simplified by multiplication by their conjugates. 

examples: 
 
qq := (1+sqrt(3))/(sqrt(3)-7);  
 
        SQRT(3) + 1 
  QQ := -----------  
        SQRT(3) - 7 

on rationalize;  
 
qq;  
 
  - 4*SQRT(3) - 5 
  ---------------  
        23 

2/(4 + 6**(1/3));  
 
   2/3      1/3 
  6    - 4*6    + 16 
  ------------------  
          35 

(i-1)/(i+3);  
 
  2*I - 1 
  -------  
     5 

off rationalize;  
 
(i-1)/(i+3);  
 
  I - 1 
  ------ 
  I + 3 

#$+ KRATPRI				switch

When the ratpri  switch is on, rational expressions and fractions are printed as two lines separated by a fraction bar, rather than in a linear style. Default is on . 

examples: 
 
3/17;  
 
  3 
  --  
  17 

2/b + 3/y;  
 
  3*B + 2*Y 
  ---------  
     B*Y 

off ratpri;  
 
3/17;  
 
  3/17  

2/b + 3/y;  
 
  (3*B + 2*Y)/(B*Y) 

#$+ KREVPRI				switch

When the revpri  switch is on, terms are printed in reverse order from the normal printing order. 

examples: 
 
x**5 + x**2 + 18 + sqrt(y);  
 
             5    2 
  SQRT(Y) + X  + X  + 18  

a + b + c + w;  
 
  A + B + C + W  

on revpri;  
 
x**5 + x**2 + 18 + sqrt(y);  
 
        2    5 
  17 + X  + X  + SQRT(Y)  

a + b + c + w;  
 
  W + C + B + A 
 
Turn revpri  on when you want to display a polynomial in ascending rather than descending order. 

#$+ KRLISP88				switch

Rlisp '88 is a superset of the Rlisp that has been traditionally used for the support of REDUCE. It is fully documented in the book Marti, J.B., ``RLISP '88: An Evolutionary Approach to Program Design and Reuse'', World Scientific, Singapore (1993). It supports different looping constructs from the traditional Rlisp, and treats ``-'' as a letter unless separated by spaces. Turning on the switch rlisp88  converts to Rlisp '88 parsing conventions in symbolic mode, and enables the use of Rlisp '88 extensions. Turning off the switch reverts to the traditional Rlisp and the previous mode ( (symbolic  or algebraic ) in force before rlisp88  was turned on. 

#$+ KROUNDALL				switch

In rounded  mode, rational numbers are normally converted to a floating point representation. If roundall  is off, this conversion does not occur. roundall  is normally on . 

examples: 
 
on rounded;  
 
1/2;  
 
  0.5  

off roundall;  

#$+ KROUNDBF				switch

 When rounded  is on, the normal defaults cause underflows to be converted to zero. If you really want the small number that results in such cases, roundbf  can be turned on. 

examples: 
 
on rounded;  
 
exp(-100000.1^2);  
 
  0  

on roundbf;  
 
exp(-100000.1^2);  
 
  1.18441281937E-4342953505 
 
If a polynomial is input in rounded  mode at the default precision into any roots  function, and it is not possible to represent any of the coefficients of the polynomial precisely in the system floating point representation, the switch roundbf  will be automatically turned on. All rounded computation will use the internal bigfloat representation until the user subsequently turns roundbf  off. (A message is output to indicate that this condition is in effect.) 

#$+ KROUNDED				switch

When rounded  is on, floating-point arithmetic is enabled, with precision initially at a system default value, which is usually 12 digits. The precise number can be found by the command precision (0).  
examples: 
 
pi;  
 
  PI  

35/217;  
 
  5 
  --  
  31 

on rounded;  
 
pi;  
 
  3.14159265359  

35/217;  
 
  0.161  

sqrt(3);  
 
  1.73205080756 

If more than the default number of decimal places are required, use the precision  command to set the required number. 

#$+ KSAVESTRUCTR				switch

When savestructr  is on, results of the structr  command are returned as a list whose first element is the representation for the expression and the remaining elements are equations showing the relationships of the generated variables. 

examples: 
 
off exp;  
 
structr((x+y)^3 + sin(x)^2);  
 
  ANS3 
     where 
                    3       2 
        ANS3 := ANS1  + ANS2 
        ANS2 := SIN(X) 
        ANS1 := X + Y 

ans3;  
 
  ANS3  

on savestructr;  
 
structr((x+y)^{3} + sin(x)^{2});  
 
                3       2 
  ANS3,ANS3=ANS1  + ANS2 ,ANS2=SIN(X),ANS1=X + Y  

ans3 where rest ws;  
 
         3         2 
  (X + Y)  + SIN(X) 
 
In normal operation, structr  is only a display command. With savestructr  on, you can access the various parts of the expression produced by structr . 

The generic system names use the stem ANS . You can change this to your own stem by the command varname . REDUCE adds integers to this stem to make unique identifiers. 

#$+ KSOLVESINGULAR				switch

When solvesingular  is on, singular or underdetermined systems of linear equations are solved, using arbitrary real, complex or integer variables in the answer. Default is on . 

examples: 
 
solve({2x + y,4x + 2y},{x,y});  
 
         ARBCOMPLEX(1) 
  {{X= - -------------,Y=ARBCOMPLEX(1)}}  
               2 

solve({7x + 15y - z,x - y - z},{x,y,z});  

      8*ARBCOMPLEX(3) 
  {{X=---------------- 
            11 
         3*ARBCOMPLEX(3) 
    Y= - ---------------- 
               11 
    Z=ARBCOMPLEX(3)}} 

off solvesingular;  
 
solve({2x + y,4x + 2y},{x,y});  
 
  ***** SOLVE given singular equations  

solve({7x + 15y - z,x - y - z},{x,y,z});  

  ***** SOLVE given singular equations 
 
The integer following the identifier arbcomplex  above is assigned by the system, and serves to identify the variable uniquely. It has no other significance. 

#$+ KTIME				switch

When time  is on, the system time used in executing each REDUCE statement is printed after the answer is printed. 

examples: 
 
on time;  
 
  Time: 4940 ms  

df(sin(x**2 + y),y);  
 
            2 
  COS(X  + Y ) 
  Time: 180 ms 

solve(x**2 - 6*y,x);  
 
  {X= - SQRT(Y)*SQRT(6), 
   X=SQRT(Y)*SQRT(6)} 
  Time: 320 ms 
 
When time  is first turned on, the time since the beginning of the REDUCE session is printed. After that, the time used in computation, (usually in milliseconds, though this is system dependent) is printed after the results of each command. Idle time or time spent typing in commands is not counted. If time  is turned off, the first reading after it is turned on again gives the time elapsed since it was turned off. The time printed is CPU or wall clock time, depending on the system. 

#$+ KTRALLFAC				switch

When trallfac  is on, a more detailed trace of factorizer calls is generated. 

The trallfac  switch takes precedence over trfac  if they are both on. trfac  gives a factorization trace with less detail in it. When the factor  switch is on also, all input polynomials are sent to the factorizer automatically and trace information is generated. The out  command saves the results of the factoring, but not the trace. 

#$+ KTRFAC				switch

When trfac  is on, a narrative trace of any calls to the factorizer is generated. Default is off . 

When the switch factor  is on, and trfac  is on, every input polynomial is sent to the factorizer, and a trace generated. With factor  off, only polynomials that are explicitly factored with the command factorize  generate trace information. 

The out  command saves the results of the factoring, but not the trace. The trallfac  switch gives trace information to a greater level of detail. 

#$+ KTRIGFORM				switch

When fullroots  is on, solve  will compute the roots of a cubic or quartic polynomial is closed form. When trigform  is on, the roots will be expressed by trigonometric forms. Otherwise nested surds are used. Default is on . 

#$+ KTRINT				switch

When trint  is on, a narrative tracing various steps in the integration process is produced. 

The out  command saves the results of the integration, but not the trace. 

#$+ KTRNONLNR				switch

When trnonlnr  is on, a narrative tracing various steps in the process for solving non-linear equations is produced. 

trnonlnr can only be used after the solve package has been loaded (e.g., by an explicit call of load_package ). The out  command saves the results of the equation solving, but not the trace. 

#$+ KVAROPT				switch

When varopt  is on, the sequence of variables is optimized by solve  with respect to execution speed. Otherwise, the sequence given in the call to solve  is preserved. Default is on . 

In combination with the switch arbvars , varopt  can be used to control variable elimination. 

examples: 
 
off arbvars;  
 
solve({x+2z,x-3y},{x,y,z});				 
 
           x      x 
  		   {{y=-,z= - -}}  
           3      2 

solve({x*y=1,z=x},{x,y,z});				 
 
               1 
  		   {{z=x,y=-}}  
               x 

off varopt;  
 
solve({x+2z,x-3y},{x,y,z});				 
 
                       2*z 
  		   {{x= - 2*z,y= - ---}}  
                        3 

solve({x*y=1,z=x},{x,y,z});				 
 
           1 
  		   {{y=-,x=z}}  
           z 

#$+General Switches

	SWITCHES introduction
	ALGINT switch
	ALLBRANCH switch
	ALLFAC switch
	ARBVARS switch
	BALANCED‑MOD switch
	BFSPACE switch
	COMBINEEXPT switch
	COMBINELOGS switch
	COMP switch
	COMPLEX switch
	CREF switch
	CRAMER switch
	DEFN switch
	DEMO switch
	DFPRINT switch
	DIV switch
	ECHO switch
	ERRCONT switch
	EVALLHSEQP switch
	EXP switch
	EXPANDLOGS switch
	EZGCD switch
	FACTOR switch
	FAILHARD switch
	FORT switch
	FORTUPPER switch
	FULLPREC switch
	FULLROOTS switch
	GC switch
	GCD switch
	HORNER switch
	IFACTOR switch
	INT switch
	INTSTR switch
	LCM switch
	LESSSPACE switch
	LIMITEDFACTORS switch
	LIST switch
	LISTARGS switch
	MCD switch
	MODULAR switch
	MSG switch
	MULTIPLICITIES switch
	NAT switch
	NERO switch
	NOARG switch
	NOLNR switch
	NOSPLIT switch
	NUMVAL switch
	OUTPUT switch
	OVERVIEW switch
	PERIOD switch
	PRECISE switch
	PRET switch
	PRI switch
	RAISE switch
	RAT switch
	RATARG switch
	RATIONAL switch
	RATIONALIZE switch
	RATPRI switch
	REVPRI switch
	RLISP88 switch
	ROUNDALL switch
	ROUNDBF switch
	ROUNDED switch
	SAVESTRUCTR switch
	SOLVESINGULAR switch
	TIME switch
	TRALLFAC switch
	TRFAC switch
	TRIGFORM switch
	TRINT switch
	TRNONLNR switch
	VAROPT switch

#$+ KCOFACTOR				operator

The operator cofactor  returns the cofactor of the element in row <row> and column <column> of a matrix . Errors occur if <row> or <column> do not evaluate to integer expressions or if the matrix is not square. 

syntax: 
cofactor (<matrix‑expression>,<row>,<column>) 

 
examples: 
 
cofactor(mat((a,b,c),(d,e,f),(p,q,r)),2,2);  

  A*R - C*P  

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

  ***** non-square matrix 

#$+ KDET				operator

The det  operator returns the determinant of its (square matrix ) argument. 

syntax: 
det (<expression>) or det  <expression> 

<expression> must evaluate to a square matrix. 

examples: 

matrix m,n;  

m := mat((a,b),(c,d));  
 
  M(1,1) := A 
  M(1,2) := B 
  M(2,1) := C 
  M(2,2) := D 

 
det m;  
 
  A*D - B*C  

n := mat((1,2),(1,2));  
 
  N(1,1) := 1 
  N(1,2) := 2 
  N(2,1) := 1 
  N(2,2) := 2 

 
 
det(n);  
 
  0  

 
det(5);  
 
  5 
 
Given a numerical argument, det  returns the number. However, given a variable name that has not been declared of type matrix, or a non-square matrix, det  returns an error message. 

#$+ KMAT				operator

The mat  operator is used to represent a two-dimensional matrix .  
syntax: 

mat ((<expr>{,<expr>}*) {(<expr>{, <expr>}*)}*) 

<expr> may be any valid REDUCE scalar expression. 

examples: 
 
mat((1,2),(3,4));  
 
  MAT(1,1) := 1 
  MAT(2,3) := 2 
  MAT(2,1) := 3 
  MAT(2,2) := 4 

mat(2,1);  
 
  ***** Matrix mismatch 
  Cont? (Y or N)  

matrix qt;  
 
qt := ws;  
 
  QT(1,1) := 1 
  QT(1,2) := 2 
  QT(2,1) := 3 
  QT(2,2) := 4  

matrix a,b;  
 
a := mat((x),(y),(z));  
 
  A(1,1) := X 
  A(2,1) := Y 
  A(3,1) := Z  

b := mat((sin x,cos x,1));  
 
  B(1,1) := SIN(X) 
  B(1,2) := COS(X) 
  B(1,3) := 1 
 
Matrices need not have a size declared (unlike arrays). mat  redimensions a matrix variable as needed. It is necessary, of course, that all rows be the same length. An anonymous matrix, as shown in the first example, must be named before it can be referenced (note error message). When using mat  to fill a 1 x n matrix, the row of values must be inside a second set of parentheses, to eliminate ambiguity. 

#$+ KMATEIGEN				operator

The mateigen  operator calculates the eigenvalue equation and the corresponding eigenvectors of a matrix .  
syntax: 

mateigen (<matrix-id>,<tag-id>) 

<matrix-id> must be a declared matrix of values, and <tag-id> must be a legal REDUCE identifier. 

examples: 
 
aa := mat((2,5),(1,0))  
 
mateigen(aa,alpha);  
 
         2 
  {{ALPHA  - 2*ALPHA - 5, 
    1, 
                5*ARBCOMPLEX(1) 
    MAT(1,1) := ---------------,  
                   ALPHA - 2 
  \ 
    MAT(2,1) := ARBCOMPLEX(1) 
    }} 
 
charpoly := first first ws;  
 
                   2 
  CHARPOLY := ALPHA  - 2*ALPHA - 5  

bb := mat((1,0,1),(1,1,0),(0,0,1))  
 
mateigen(bb,lamb);  
 
  {{LAMB - 1,3, 
    [      0      ] 
    [ARBCOMPLEX(2)] 
    [      0      ] 
    }} 
 
The mateigen  operator returns a list of lists of three elements. The first element is a square free factor of the characteristic polynomial; the second element is its multiplicity; and the third element is the corresponding eigenvector. If the characteristic polynomial can be completely factored, the product of the first elements of all the sublists will produce the minimal polynomial. You can access the various parts of the answer with the usual list access operators. 

If the matrix is degenerate, more than one eigenvector can be produced for the same eigenvalue, as shown by more than one arbitrary variable in the eigenvector. The identification numbers of the arbitrary complex variables shown in the examples above may not be the same as yours. Note that since lambda  is a reserved word in REDUCE, you cannot use it as a tag-id for this operator. 

#$+ KMATRIX				declaration

 Identifiers are declared to be of type matrix .  
syntax: 

matrix <identifier> 	option (<index>,<index>) 

{,<identifier> 	option  (<index>,<index>)}* 

<identifier> must not be an already-defined operator or array or the name of a scalar variable. Dimensions are optional, and if used appear inside parentheses. <index> must be a positive integer. 

examples: 
 
matrix a,b(1,4),c(4,4);  
 
b(1,1);  
 
  0  

a(1,1);  
 
  ***** Matrix A not set  

a := mat((x0,y0),(x1,y1));  
 
  A(1,1) := X0 
  A(1,2) := Y0 
  A(2,1) := X0 
  A(2,2) := X1 

length a;  
 
  {2,2}  

b := a**2;  
 
              2 
  B(1,1) := X0  + X1*Y0 
  B(1,2) := Y0*(X0 + Y1) 
  B(2,1) := X1*(X0 + Y1) 
                      2 
  B(2,2) := X1*Y0 + Y1 
 
When a matrix variable has not been dimensioned, matrix elements cannot be referenced until the matrix is set by the mat  operator. When a matrix is dimensioned in its declaration, matrix elements are set to 0. Matrix elements cannot stand for themselves. When you use let  on a matrix element, there is no effect unless the element contains a constant, in which case an error message is returned. The same behavior occurs with clear . Do <not> use clear  to try to set a matrix element to 0. let  statements can be applied to matrices as a whole, if the right-hand side of the expression is a matrix expression, and the left-hand side identifier has been declared to be a matrix. 

Arithmetical operators apply to matrices of the correct dimensions. The operators +  and -  can be used with matrices of the same dimensions. The operator *  can be used to multiply m x n matrices by n x p matrices. Matrix multiplication is non-commutative. Scalars can also be multiplied with matrices, with the result that each element of the matrix is multiplied by the scalar. The operator /  applied to two matrices computes the first matrix multiplied by the inverse of the second, if the inverse exists, and produces an error message otherwise. Matrices can be divided by scalars, which results in dividing each element of the matrix. Scalars can also be divided by matrices when the matrices are invertible, and the result is the multiplication of the scalar by the inverse of the matrix. Matrix inverses can by found by 1/A  or /A , where A  is a matrix. Square matrices can be raised to positive integer powers, and also to negative integer powers if they are nonsingular. 

When a matrix variable is assigned to the results of a calculation, the matrix is redimensioned if necessary. 

#$+ KNULLSPACE				operator

 
syntax: 
nullspace (<matrix‑expression>) 

<nullspace> calculates for its matrix  argument, a , a list of linear independent vectors (a basis) whose linear combinations satisfy the equation a x = 0. The basis is provided in a form such that as many upper components as possible are isolated. 

examples: 
 
nullspace mat((1,2,3,4),(5,6,7,8));  

         { 
           [ 1  ] 
           [    ] 
           [ 0  ] 
           [    ] 
           [ - 3] 
           [    ] 
           [ 2  ] 
           , 
           [ 0  ] 
           [    ] 
           [ 1  ] 
           [    ] 
           [ - 2] 
           [    ] 
           [ 1  ] 
  	} 
 
Note that with b := nullspace a , the expression length b  is the nullity/ of A, and that second length a - length b  calculates the rank/ of A. The rank of a matrix expression can also be found more directly by the rank  operator. 

In addition to the REDUCE matrix form, nullspace  accepts as input a matrix given as a list  of lists, that is interpreted as a row matrix. If that form of input is chosen, the vectors in the result will be represented by lists as well. This additional input syntax facilitates the use of nullspace  in applications different from classical linear algebra. 

#$+ KRANK				operator

 
syntax: 
rank (<matrix‑expression>) 

rank calculates the rank of its matrix argument. 

examples: 
 
rank mat((a,b,c),(d,e,f));  
 
  2 
 
The argument to rank  can also be a list  of lists, interpreted either as a row matrix or a set of equations. If that form of input is chosen, the vectors in the result will be represented by lists as well. This additional input syntax facilitates the use of rank  in applications different from classical linear algebra. 

#$+ KTP				operator

The tp  operator returns the transpose of its matrix   argument.  
syntax: 

tp <identifier> or tp (<identifier>) 

<identifier> must be a matrix, which either has had its dimensions set in its declaration, or has had values put into it by mat . 

examples: 
 
matrix m,n;  
 
m := mat((1,2,3),(4,5,6))$  
 
n := tp m;  
 
  N(1,1) := 1 
  N(1,2) := 4 
  N(2,1) := 2 
  N(2,2) := 5 
  N(3,1) := 3 
  N(3,2) := 6 
 
In an assignment statement involving tp , the matrix identifier on the left-hand side is redimensioned to the correct size for the transpose. 

#$+ KTRACE				operator

The trace  operator finds the trace of its matrix  argument.  
syntax: 

trace (<expression>) or trace  <simple‑expression> 

<expression> or <simple‑expression> must evaluate to a square matrix. 

examples: 
 
matrix a;  
 
a := mat((x1,y1),(x2,y2))  
 
trace a;  
 
  X1 + Y2 
 
The trace is the sum of the entries along the diagonal of a square matrix. Given a non-matrix expression, or a non-square matrix, trace  returns an error message. 

#$+Matrix Operations

	COFACTOR operator
	DET operator
	MAT operator
	MATEIGEN operator
	MATRIX declaration
	NULLSPACE operator
	RANK operator
	TP operator
	TRACE operator

#$+ KGROEBNER BASES				introduction

 The GROEBNER package calculates Groebner bases  using the  Buchberger algorithm  and provides related algorithms for arithmetic with ideal bases, such as ideal quotients, Hilbert polynomials ( Hollmann algorithm ), basis conversion (  Faugere-Gianni-Lazard-Mora algorithm ), independent variable set ( Kredel-Weispfenning algorithm ). 

Some routines of the Groebner package are used by solve  - in that context the package is loaded automatically. However, if you want to use the package by explicit calls you must load it by  
    load_package groebner; 

For the common parameter setting of most operators in this package see ideal parameters . 

#$+ KIDEAL PARAMETERS

Most operators of the Groebner  package compute expressions in a polynomial ring which given as <R>[<var>,<var>,...] where <R> is the current REDUCE coefficient domain. All algebraically exact domains of REDUCE are supported. The package can operate over rings and fields. The operation mode is distinguished automatically. In general the ring mode is a bit faster than the field mode. The factoring variant can be applied only over domains which allow you factoring of multivariate polynomials. 

The variable sequence <var> is either declared explicitly as argument in form of a list  in torder , or it is extracted automatically from the expressions. In the second case the current REDUCE system order is used (see korder ) for arranging the variables. If some kernels should play the role of formal parameters (the ground domain <R> then is the polynomial ring over these), the variable sequences must be given explicitly. 

All REDUCE kernel s can be used as variables. But please note, that all variables are considered as independent. E.g. when using sin(a)  and cos(a)  as variables, the basic relation sin(a)^2+cos(a)^2-1=0  must be explicitly added to an equation set because the Groebner operators don't include such knowledge automatically. 

The terms (monomials) in polynomials are arranged according to the current term order . Note that the algebraic properties of the computed results only are valid as long as neither the ordering nor the variable sequence changes. 

The input expressions <exp> can be polynomials <p>, rational functions <n>/<d> or equations <lh>=<rh> built from polynomials or rational functions. Apart from the tracing  algorithms groebnert  and preducet , where the equations have a specific meaning, equations are converted to simple expressions by taking the difference of the left-hand and right-hand sides <lh>-<rh>=><p>. Rational functions are converted to polynomials by converting the expression to a common denominator form first, and then using the numerator only <n>=><p>. So eventual zeros of the denominators are ignored. 

A basis on input or output of an algorithm is coded as list  of expressions {<exp>,<exp>,...} . 

#$+ KTERM ORDER				introduction

For all Groebner  operations the polynomials are represented in distributive form: a sum of terms (monomials). The terms are ordered corresponding to the actual term order  which is set by the torder  operator, and to the actual variable sequence which is either given as explicit parameter or by the system kernel  order. 

#$+ KTORDER				operator

 The operator torder  sets the actual variable sequence and term order. 

1. simple term order:  
syntax: 

torder (<vl>, <m>) 

where <vl> is a list  of variables (kernel s) and <m> is the name of a simple term order  mode lex term order , gradlex term order , revgradlex term order  or another implemented parameterless mode. 

2. stepped term order:  
syntax: 

torder (<vl>,<m>,<n>) 

where <m> is the name of a two step term order, one of gradlexgradlex term order , gradlexrevgradlex term order , lexgradlex term order  or lexrevgradlex term order , and <n> is a positive integer. 

3. weighted term order  
syntax: 

torder (<vl>, weighted , <n>,<n>,...); 

where the <n> are positive integers, see weighted term order . 

4. matrix term order  
syntax: 

torder (<vl>, matrix , <m>); 

where <m> is a matrix with integer elements, see torder_compile . 

5. compiled term order  
syntax: 

torder (<vl>, co ); 

where <co> is the name of a routine generated by torder_compile . 

torder sets the variable sequence and the term order mode. If the an empty list is used as variable sequence, the automatic variable extraction is activated. The defaults are the empty variable list an the lex term order . The previous setting is returned as a list. 

Alternatively to the above syntax the arguments of torder  may be collected in a list  and passed as one argument to torder . 

#$+ KTORDER_COMPILE				operator

A matrix can be converted into a compilable LISP program for faster execution by using  
syntax: 

torder_compile (<name>,<mat>) 

where <name> is an identifier for the new term order and <mat> is an integer matrix to be used as matrix term order . Afterwards the term order can be activated by using <name> in a torder  expression. The resulting program is compiled if the switch comp  is on, or if the torder_compile  expression is part of a compiled module. 

#$+ KLEX TERM ORDER

The terms are ordered lexicographically: two terms t1 t2 are compared for their degrees along the fixed variable sequence: t1 is higher than t2 if the first different degree is higher in t1. This order has the elimination property  for groebner basis  calculations. If the ideal has a univariate polynomial in the last variable the groebner basis will contain such polynomial. Lex  is best suited for solving of polynomial equation systems. 

#$+ KGRADLEX TERM ORDER

The terms are ordered first with their total degree, and if the total degree is identical the comparison is lex term order . With groebner  basis calculations this term order produces polynomials of lowest degree. 

#$+ KREVGRADLEX TERM ORDER

The terms are ordered first with their total degree (degree sum), and if the total degree is identical the comparison is the inverse of lex term order . With groebner  and groebnerf  calculations this term order is similar to gradlex term order ; it is known as most efficient ordering with respect to computing time. 

#$+ KGRADLEXGRADLEX TERM ORDER

The terms are separated into two groups where the second parameter of the torder  call determines the length of the first group. For a comparison first the total degrees of both variable groups are compared. If both are equal gradlex term order  comparison is applied to the first group, and if that does not decide gradlex term order  is applied for the second group. This order has the elimination property for the variable groups. It can be used e.g. for separating variables from parameters. 

#$+ KGRADLEXREVGRADLEX TERM ORDER

Similar to gradlexgradlex term order , but using revgradlex term order  for the second group. 

#$+ KLEXGRADLEX TERM ORDER

Similar to gradlexgradlex term order , but using lex term order  for the first group. 

#$+ KLEXREVGRADLEX TERM ORDER

Similar to gradlexgradlex term order , but using lex term order  for the first group revgradlex term order  for the second group. 

#$+ KWEIGHTED TERM ORDER

establishes a graduated ordering similar to gradlex term order , where the exponents first are multiplied by the given weights. If there are less weight values than variables, the weight list is extended by ones. If the weighted degree comparison is not decidable, the lex term order  is used. 

#$+ KGRADED TERM ORDER

establishes a cascaded term ordering: first a graduated ordering similar to gradlex term order  is used, where the exponents first are multiplied by the given weights. If there are less weight values than variables, the weight list is extended by ones. If the weighted degree comparison is not decidable, the term ordering described in the following parameters of the torder  command is used. 

#$+ KMATRIX TERM ORDER

Any arbitrary term order mode can be installed by a matrix with integer elements where the row length corresponds to the variable number. The matrix must have at least as many rows as columns. It must have full rank, and the top nonzero element of each column must be positive. 

The matrix term order mode  defines a term order where the exponent vectors of the monomials are first multiplied by the matrix and the resulting vectors are compared lexicographically. 

If the switch comp  is on, the matrix is converted into a compiled LISP program for faster execution. A matrix can also be compiled explicitly, see torder_compile . 

#$+Term order

	Term order introduction
	TORDER operator
	torder_compile operator
	lex term order concept
	gradlex term order concept
	revgradlex term order concept
	gradlexgradlex term order concept
	gradlexrevgradlex term order concept
	lexgradlex term order concept
	lexrevgradlex term order concept
	weighted term order concept
	graded term order concept
	matrix term order concept

#$+ KGVARS				operator

syntax: 

gvars ({<exp>,<exp>,... }) 

where <exp> are expressions or equation s. 

gvars extracts from the expressions the kernel s  which can play the role of variables for a groebner  or groebnerf  calculation. 

#$+ KGROEBNER				operator

 
syntax: 
groebner ({exp , ...}) 

where {exp , ... }is a list of expressions or equations. 

The operator groebner  implements the Buchberger algorithm for computing Groebner bases for a given set of expressions with respect to the given set of variables in the order given. As a side effect, the sequence of variables is stored as a REDUCE list in the shared variable gvarslast  - this is important in cases where the algorithm rearranges the variable sequence because groebopt  is on . 

examples: 
 
   groebner({x**2+y**2-1,x-y})  
 
  {X - Y,2*Y**2 -1} 

related: 

	groebnerf operator 
	 gvarslast  variable 
	 groebopt  switch 
	 groebprereduce  switch 
	 groebfullreduction  switch 
	 gltbasis  switch 
	 gltb  variable 
	 glterms  variable 
	 groebstat  switch 
	 trgroeb  switch 
	 trgroebs  switch 
	 groebprot  switch 
	 groebprotfile  variable 
	 groebnert  operator 

#$+ KGROEBOPT				switch

 If groebopt  is set ON, the sequence of variables is optimized with respect to execution speed of groebner  calculations; note that the final list of variables is available in gvarslast . By default groebopt  is off, conserving the original variable sequence. 

An explicitly declared dependency using the depend  declaration supersedes the variable optimization.  
examples: 

guarantees that a will be placed in front of x and y. 

#$+ KGVARSLAST				variable

 After a groebner  or groebnerf  calculation the actual variable sequence is stored in the variable gvarslast . If groebopt  is on  gvarslast  shows the variable sequence after reordering. 

#$+ KGROEBPREREDUCE				switch

 If groebprereduce  set ON, groebner  and groebnerf  try to simplify the input expressions: if the head term of an input expression is a multiple of the head term of another expression, it can be reduced; these reductions are done cyclicly as long as possible in order to shorten the main part of the algorithm. 

By default groebprereduce  is off. 

#$+ KGROEBFULLREDUCTION				switch

 If groebfullreduction  set off, the polynomial reduction steps during groebner  and groebnerf  are limited to the pure head term reduction; subsequent terms are reduced otherwise. 

By default groebfullreduction  is on. 

#$+ KGLTBASIS				switch

 If gltbasis  set on, the leading terms of the result basis of a groebner  or groebnerf  calculation are extracted. They are collected as a basis of monomials, which is available as value of the global variable gltb . 

#$+ KGLTB				variable

 See gltbasis  

#$+ KGLTERMS				variable

 If the expressions in a groebner  or groebnerf  call contain parameters (symbols which are not member of the variable list), the share variable glterms  is set to a list of expression which during the calculation were assumed to be nonzero. The calculated bases are valid only under the assumption that all these expressions do not vanish. 

#$+ KGROEBSTAT				switch

 if groebstat  is on, a summary of the groebner  or groebnerf  computation is printed at the end including the computing time, the number of intermediate H polynomials and the counters for the criteria hits. 

#$+ KTRGROEB				switch

 if trgroeb  is on, intermediate H polynomials are printed during a groebner  or groebnerf  calculation. 

#$+ KTRGROEBS				switch

 if trgroebs  is on, intermediate H and S polynomials are printed during a groebner  or groebnerf  calculation. 

#$+ KGZERODIM?				operator

syntax: 

gzerodim!? (<basis>) 

where <bas> is a Groebner basis in the current term order  with the actual setting (see ideal parameters ). 

gzerodim!? tests whether the ideal spanned by the given basis has dimension zero. If yes, the number of zeros is returned, nil  otherwise. 

#$+ KGDIMENSION				operator

 
syntax: 
gdimension (<bas>) 

where <bas> is a groebner  basis in the current term order (see ideal parameters ). gdimension  computes the dimension of the ideal spanned by the given basis and returns the dimension as an integer number. The Kredel-Weispfenning algorithm is used: the dimension is the length of the longest independent variable set, see gindependent_sets  

#$+ KGINDEPENDENT‑SETS				operator

 
syntax: 
gindependent_sets (<bas>) 

where <bas> is a groebner  basis in any term order  (which must be the current term order ) with the specified variables (see ideal parameters ). 

Gindependent_sets computes the maximal left independent variable sets of the ideal, that are the variable sets which play the role of free parameters in the current ideal basis. Each set is a list which is a subset of the variable list. The result is a list of these sets. For an ideal with dimension zero the list is empty. The Kredel-Weispfenning algorithm is used. 

#$+ KDD_GROEBNER				operator

 For a homogeneous system of polynomials under graded term order , gradlex term order , revgradlex term order  

or weighted term order  a Groebner Base can be computed with limiting the grade of the intermediate S polynomials:  
syntax: 

dd_groebner (<d1>,<d2>,<plist>) 

where <d1> is a non negative integer and <d2> is an integer or ``infinity". A pair of polynomials is considered only if the grade of the lcm of their head terms is between <d1> and <d2>. For the term orders graded  or weighted  the (first) weight vector is used for the grade computation. Otherwise the total degree of a term is used. 

#$+ KGLEXCONVERT				operator

 
syntax: 
glexconvert (<bas>[,<vars>][,MAXDEG=<mx>] [,NEWVARS=<nv>]) 

where <bas> is a groebner  basis in the current term order, <mx> (optional) is a positive integer and <nvl> (optional) is a list of variables (see ideal parameters ). 

The operator glexconvert  converts the basis of a zero-dimensional ideal (finite number of isolated solutions) from arbitrary ordering into a basis under lex term order . 

The parameter <newvars> defines the new variable sequence. If omitted, the original variable sequence is used. If only a subset of variables is specified here, the partial ideal basis is evaluated. 

If <newvars> is a list with one element, the minimal  univariate polynomial  is computed. 

<maxdeg> is an upper limit for the degrees. The algorithm stops with an error message, if this limit is reached. 

A warning occurs, if the ideal is not zero dimensional. 

During the call the term order  of the input basis must be active. 

#$+ KGREDUCE				operator

syntax: 

greduce (exp, {exp1, exp2, ... , expm}) 

where exp is an expression, and {exp1, exp2, ... , expm} is a list of expressions or equations. 

greduce is functionally equivalent with a call to groebner  and then a call to preduce . 

#$+ KPREDUCE				operator

syntax: 

preduce (<p>, {<exp>, ... }) 

where <p> is an expression, and {<exp>, ... }is a list of expressions or equations. 

preduce computes the remainder of exp  modulo the given set of polynomials resp. equations. This result is unique (canonical) only if the given set is a groebner  basis under the current term order  

see also: preducet  operator. 

#$+ KIDEALQUOTIENT				operator

syntax: 

idealquotient ({<exp>, ...}, <d>) 

where {<exp>,...} is a list of expressions or equations, <d> is a single expression or equation. 

idealquotient computes the ideal quotient: ideal spanned by the expressions {<exp>,...} divided by the single polynomial/expression <f>. The result is the groebner  basis of the quotient ideal. 

#$+ KHILBERTPOLYNOMIAL				operator

 
syntax: 
hilbertpolynomial(<bas>) 

where <bas> is a groebner  basis in the current term order . 

The degree of the Hilbert polynomial  is the dimension of the ideal spanned by the basis. For an ideal of dimension zero the Hilbert polynomial is a constant which is the number of common zeros of the ideal (including eventual multiplicities). The Hollmann algorithm  is used. 

#$+Basic Groebner operators

	GVARS operator
	GROEBNER operator
	groebopt switch
	gvarslast variable
	groebprereduce switch
	groebfullreduction switch
	gltbasis switch
	gltb variable
	glterms variable
	groebstat switch
	trgroeb switch
	trgroebs switch
	gzerodim? operator
	gdimension operator
	gindependent‑sets operator
	dd_groebner operator
	glexconvert operator
	greduce operator
	preduce operator
	idealquotient operator
	hilbertpolynomial operator

#$+ KGROEBNERF				operator

syntax: 

groebnerf ({<exp>, ...}[,{},{<nz>, ... }]); 

where {<exp>, ... }is a list of expressions or equations, and {<nz>,... }is an optional list of polynomials to be considered as non zero for this calculation. An empty list must be passed as second argument if the non-zero list is specified. 

groebnerf tries to separate polynomials into individual factors and to branch the computation in a recursive manner (factorization tree). The result is a list of partial Groebner bases. Multiplicities (one factor with a higher power, the same partial basis twice) are deleted as early as possible in order to speed up the calculation. 

The third parameter of groebnerf  declares some polynomials nonzero. If any of these is found in a branch of the calculation the branch is canceled. 

example: 
 
groebnerf({ 3*x**2*y+2*x*y+y+9*x**2+5*x = 3,   
            2*x**3*y-x*y-y+6*x**3-2*x**2-3*x = -3,  
            x**3*y+x**2*y+3*x**3+2*x**2 }, {y,x}); 
 
       {{Y - 3,X}, 
 
                      2 
    {2*Y + 2*X - 1,2*X  - 5*X - 5}} 
 
related: 

	groebresmax variable 
	 groebmonfac  variable 
	 groebrestriction  variable 
	 groebner  operator 
	 gvarslast  variable 
	 groebopt  switch 
	 groebprereduce  switch 
	 groebfullreduction  switch 
	 gltbasis  switch 
	 gltb  variable 
	 glterms  variable 
	 groebstat  switch 
	 trgroeb  switch 
	 trgroebs  switch 
	 groebnert  operator 

#$+ KGROEBMONFAC				variable

 The variable groebmonfac  is connected to the handling of monomial factors. A monomial factor is a product of variable powers as a factor, e.g. x**2*y in x**3*y - 2*x**2*y**2. A monomial factor represents a solution of the type  x = 0 or y = 0 with a certain multiplicity. With groebnerf  the multiplicity of monomial factors is lowered to the value of the shared variable groebmonfac  which by default is 1 (= monomial factors remain present, but their multiplicity is brought down). With groebmonfac := 0 the monomial factors are suppressed completely. 

#$+ KGROEBRESMAX				variable

 The variable groebresmax  controls during groebnerf  calculations the number of partial results. Its default value is 300. If more partial results are calculated, the calculation is terminated. 

#$+ KGROEBRESTRICTION				variable

 During groebnerf  calculations irrelevant branches can be excluded by setting the variable groebrestriction . The following restrictions are implemented:  
syntax: 

groebrestriction := nonnegative  

groebrestriction := positive  

groebrestriction := zeropoint  

With nonnegative  branches are excluded where one polynomial has no nonnegative real zeros; with positive  the restriction is sharpened to positive zeros only. The restriction zeropoint  excludes all branches which do not have the origin (0,0,...0) in their solution set. 

#$+Factorizing Groebner bases

	groebnerf operator
	groebmonfac variable
	groebresmax variable
	groebrestriction variable

#$+ KGROEBPROT				switch

 If groebprot  is ON  the computation steps during preduce , greduce  and groebner  are collected in a list which is assigned to the variable groebprotfile . 

#$+ KGROEBPROTFILE				variable

 See groebprot  switch. 

#$+ KGROEBNERT				operator

syntax: 

groebnert ({<v>=<exp>,...}) 

where <v> are kernel s  (simple or indexed variables), <exp> are polynomials. 

groebnert is functionally equivalent to a groebner  call for {<exp>,...}, but the result is a set of equations where the left-hand sides are the basis elements while the right-hand sides are the same values expressed as combinations of the input formulas, expressed in terms of the names <v>  
example: 
 
    groebnert({p1=2*x**2+4*y**2-100,p2=2*x-y+1}); 
 
   GB1 := {2*X - Y + 1=P2, 
 
           2 
        9*Y  - 2*Y - 199= - 2*X*P2 - Y*P2 + 2*P1 + P2} 

#$+ KPREDUCET				operator

syntax: 

preduce (<p>,{<v>=<exp>...}) 

where <p> is an expression, <v> are kernels (simple or indexed variables), exp  are polynomials. 

preducet computes the remainder of <p> modulo {<exp>,...} similar to preduce , but the result is an equation which expresses the remainder as combination of the polynomials.  
example: 

   GB2 := {G1=2*X - Y + 1,G2=9*Y**2  - 2*Y - 199} 
   preducet(q=x**2,gb2); 
 
 - 16*Y + 208= - 18*X*G1 - 9*Y*G1 + 36*Q + 9*G1 - G2 

#$+Tracing Groebner bases

	groebprot switch
	groebprotfile variable
	groebnert operator
	preducet operator

#$+ KMODULE

 Given a polynomial ring, e.g. R=Z[x,y,...] and an integer n>1. The vectors with n elements of R form a free MODULE under elementwise addition and multiplication with elements of R. 

For a submodule given by a finite basis a Groebner basis can be computed, and the facilities of the GROEBNER package are available except the operators groebnerf  and groesolve . The vectors are encoded using auxiliary variables which represent the unit vectors in the module. These are declared in the share variable gmodule . 

#$+ KGMODULE				variable

 The vectors of a free module  over a polynomial ring R are encoded as linear combinations with unit vectors of M which are represented by auxiliary variables. These must be collected in the variable gmodule  before any call to an operator of the Groebner package. 

   torder({x,y,v1,v2,v3})$ 
   gmodule := {v1,v2,v3}$ 
   g:=groebner({x^2*v1 + y*v2,x*y*v1 - v3,2y*v1 + y*v3}); 
compute the Groebner basis of the submodule 

      ([x^2,y,0],[xy,0,-1],[0,2y,y]) 
The members of the list gmodule  are automatically appended to the end of the variable list, if they are not yet members there. They take part in the actual term ordering. 

#$+Groebner Bases for Modules

	Module concept
	gmodule variable

#$+ KGSORT				operator

 
syntax: 
gsort (<p>) 

where <p> is a polynomial or a list of polynomials. 

The polynomials are reordered and sorted corresponding to the current term order .  
examples: 

  torder lex; 
   
  gsort(x**2+2x*y+y**2,{y,x});  
 
  y**2+2y*x+x**2 

#$+ KGSPLIT				operator

 
syntax: 
gsplit (<p>[,<vars>]); 

where <p> is a polynomial or a list of polynomials. 

The polynomial is reordered corresponding to the the current term order  and then separated into leading term and reductum. Result is a list with the leading term as first and the reductum as second element.  
examples: 

  torder lex; 
   
  gsplit(x**2+2x*y+y**2,{y,x});  
 
  {y**2,2y*x+x**2} 

#$+ KGSPOLY				operator

 
syntax: 
gspoly (<p1>,<p2>); 

where <p1> and <p2> are polynomials. 

The subtraction  polynomial of p1 and p2 is computed corresponding to the method of the Buchberger algorithm for computing groebner bases : p1 and p2 are multiplied with terms such that when subtracting them the leading terms cancel each other. 

#$+Computing with distributive polynomials

	gsort operator
	gsplit operator
	gspoly operator

#$+Groebner package

	Groebner bases introduction
	Ideal Parameters concept
	Term order
	Basic Groebner operators
	Factorizing Groebner bases
	Tracing Groebner bases
	Groebner Bases for Modules
	Computing with distributive polynomials

#$+ KHEPHYS				introduction

 The High-energy Physics package is historic for REDUCE, since REDUCE originated as a program to aid in computations with Dirac expressions. The commutation algebra of the gamma matrices is independent of their representation, and is a natural subject for symbolic mathematics. Dirac theory is applied to beta decay and the computation of cross-sections and scattering. The high-energy physics operators are available in the REDUCE main program, rather than as a module which must be loaded. 

#$+ K.	HE-DOT				operator

 The . operator is used to denote the scalar product of two Lorentz four-vectors.  
syntax: 

<vector> .  <vector> 

<vector> must be an identifier declared to be of type vector  to have the scalar product definition. When applied to arguments that are not vectors, the cons  operator is used, whose symbol is also ``dot.'' 

examples: 
 
vector aa,bb,cc;  
 
let aa.bb = 0;  
 
aa.bb;  
 
  0  

aa.cc;  
 
  AA.CC  

q := aa.cc;  
 
  Q := AA.CC  

q;  
 
  AA.CC 
 
Since vectors are special high-energy physics entities that do not contain values, the . product will not return a true scalar product. You can assign a scalar identifier to the result of a . operation, or assign a . operation to have the value of the scalar you supply, as shown above. Note that the result of a . operation is a scalar, not a vector. 

The metric tensor g(u,v) can be represented by u.v . If contraction over the indices is required, u  and v  should be declared to be of type index . 

The dot operator has the highest precedence of the infix operators, so expressions involving . and other operators have the scalar product evaluated first before other operations are done. 

#$+ KEPS				operator

 The eps  operator denotes the completely antisymmetric tensor of order 4 and its contraction with Lorentz four-vectors, as used in high-energy physics calculations.  
syntax: 

eps (<vector-expr>,<vector-expr>,<vector-expr>, <vector-expr>) 

<vector-expr> must be a valid vector expression, and may be an index. 

examples: 
 
vector g0,g1,g2,g3;  
 
eps(g1,g0,g2,g3);  
 
  - EPS(G0,G1,G2,G3);  

eps(g1,g2,g0,g3);  
 
  EPS(G0,G1,G2,G3);  

eps(g1,g2,g3,g1);  
 
  0 
 
Vector identifiers are ordered alphabetically by REDUCE. When an odd number of transpositions is required to restore the canonical order to the four arguments of eps , the term is ordered and carries a minus sign. When an even number of transpositions is required, the term is returned ordered and positive. When one of the arguments is repeated, the value 0 is returned. A contraction of the form eps(_i j mu nu p_mu q_nu) is represented by eps(i,j,p,q)  when i  and j  have been declared to be of type index . 

#$+ KG				operator

 g  is an n-ary operator used to denote a product of gamma matrices contracted with Lorentz four-vectors, in high-energy physics.  
syntax: 

g (<identifier>,<vector-expr> {,<vector-expr>}*) 

<identifier> is a scalar identifier representing a fermion line identifier, <vector-expr> can be any valid vector expression, representing a vector or a gamma matrix. 

examples: 
 
vector aa,bb,cc;  
 
vector a;  
 
g(line1,aa,bb);  
 
  AA.BB  

g(line2,aa,a);  
 
  0  

g(id,aa,bb,cc);  
 
  0  

g(li1,aa,bb) + k;  
 
  AA.BB + K  

let aa.bb = m*k;  
 
g(ln1,aa)*g(ln1,bb);  
 
  K*M  

g(ln1,aa)*g(ln2,bb);  
 
  0 
 
The vector A  is reserved in arguments of g  to denote the special gamma matrix gamma_5. It must be declared to be a vector before you use it. 

Gamma matrix expressions are associated with fermion lines in a Feynman diagram. If more than one line occurs in an expression, the gamma matrices involved are separate (operating in independent spin space), as shown in the last two example lines above. A product of gamma matrices associated with a single line can be entered either as a single g  command with several vector arguments, or as products of separate g  commands each with a single argument. 

While the product of vectors is not defined, the product, sum and difference of several gamma expressions are defined, as is the product of a gamma expression with a scalar. If an expression involving gamma matrices includes a scalar, the scalar is treated as if it were the product of itself with a unit 4 x 4 matrix. 

Dirac expressions are evaluated by computing the trace of the expression using the commutation algebra of gamma matrices. The algorithms used are described in articles by J. S. R. Chisholm in <Il Nuovo Cimento X,> Vol. 30, p. 426, 1963, and J. Kahane, <Journal of Mathematical Physics>, Vol. 9, p. 1732, 1968. The trace is then divided by 4 to distinguish between the trace of a scalar and the trace of an expression that is the product of a scalar with a unit 4 x 4 matrix. 

Trace calculations may be prevented over any line identifier by declaring it to be nospur . If it is later desired to evaluate these traces, the declaration can be undone with the spur  declaration. 

The notation of Bjorken and Drell, <Relativistic Quantum Mechanics,> 1964, is assumed in all operations involving gamma matrices. For an example of the use of g  in a calculation, see the <REDUCE User's Manual>. 

#$+ KINDEX				declaration

 The declaration index  flags a four-vector as an index for subsequent high-energy physics calculations.  
syntax: 

index <vector-id>{,<vector-id>}* 

<vector-id> must have been declared of type vector . 

examples: 
 
vector aa,bb,cc;  
 
index uu;  
 
let aa.bb = 0;  
 
(aa.uu)*(bb.uu);  
 
  0  

(aa.uu)*(cc.uu);  
 
  AA.CC 
 
Index variables are used to represent contraction over components of vectors when scalar products are taken by the . operator, as well as indicating contraction for the eps  operator or metric tensor. 

The special status of a vector as an index can be revoked with the declaration remind . The object remains a vector, however. 

#$+ KMASS				command

 The mass  command associates a scalar variable as a mass with the corresponding vector variable, in high-energy physics calculations.  
syntax: 

mass <vector-var>= <scalar-var> {,<vector-var>= <scalar-var>}* 

<vector-var> can be a declared vector variable; mass  will declare it to be of type vector  if it is not. This may override an existing matrix variable by that name. <scalar-var> must be a scalar variable. 

examples: 
 
vector bb,cc;  
 
mass cc=m;  
 
mshell cc;  
 
cc.cc;  
 
   2 
  M 
 
Once a mass has been attached to a vector with a mass  declaration, the mshell  declaration puts the associated particle ``on the mass shell.'' Subsequent scalar (.) products of the vector with itself will be replaced by the square of the mass expression. 

#$+ KMSHELL				command

 The mshell  command puts particles on the mass shell in high-energy physics calculations.  
syntax: 

mshell <vector-var>{,<vector-var>}* 

<vector-var> must have had a mass attached to it by a mass  declaration. 

examples: 
 
vector v1,v2;  
 
mass v1=m,v2=q;  
 
mshell v1;  
 
v1.v1;  
 
   2 
  M   

v2.v2;  
 
  V2.V2  

mshell v2;  
 
v1.v1*v2.v2;  
 
   2  2 
  M *Q 
 
Even though a mass is attached to a vector variable representing a particle, the replacement does not take place until the mshell  declaration is given for that vector variable. 

#$+ KNOSPUR				declaration

 The nospur  declaration prevents the trace calculation over the given line identifiers in high-energy physics calculations.  
syntax: 

nospur <line-id>{,<line-id>}* 

<line-id> is a scalar identifier that will be used as a line identifier. 

examples: 
 
vector a1,b1,c1;  
 
g(line1,a1,b1)*g(line2,b1,c1);  
 
  A1.B1*B1.C1  

nospur line2;  
 
g(line1,a1,b1)*g(line2,b1,c1);  
 
  A1.B1*G(LINE2,B1,C1) 
 
Nospur declarations can be removed by making the declaration spur . 

#$+ KREMIND				declaration

 The remind  declaration removes the special status of its arguments as indices, which was set in the index  declaration, in high-energy physics calculations.  
syntax: 

remind <identifier>{,<identifier>}* 

<identifier> must have been declared to be of type index . 

#$+ KSPUR				declaration

 The spur  declaration removes the special exemption from trace calculations that was declared by nospur , in high-energy physics calculations.  
syntax: 

spur <line-id>{,<line-id>}* 

<line-id> must be a line-identifier that has previously been declared nospur . 

#$+ KVECDIM				command

 The command vecdim  changes the vector dimension from 4 to an arbitrary integer or symbol. Used in high-energy physics calculations.  
syntax: 

vecdim <dimension> 

<dimension> must be either an integer or a valid scalar identifier that does not have a floating-point value. 

The eps  operator and the gamma_5 symbol (A ) are not properly defined in anything except four dimensions and will print an error message if you use them that way. The other high-energy physics operators should work without problem. 

#$+ KVECTOR				declaration

 The vector  declaration declares that its arguments are of type vector .  
syntax: 

vector <identifier>{,<identifier>}* 

<identifier> must be a valid REDUCE identifier. It may have already been used for a matrix, array, operator or scalar variable. After an identifier has been declared to be a vector, it may not be used as a scalar variable. 

Vectors are special entities for high-energy physics calculations. You cannot put values into their coordinates; they do not have coordinates. They are legal arguments for the high-energy physics operators eps , g  and .  (dot). Vector variables are used to represent gamma matrices and gamma matrices contracted with Lorentz 4-vectors, since there are no Dirac variables per se in the system. Vectors do follow the usual vector rules for arithmetic operations: +  and -  operate upon two or more vectors, producing a vector; *  and /  cannot be used between vectors; the scalar product is represented by the . operator; and the product of a scalar and vector expression is well defined, and is a vector. 

You can represent components of vectors by including representations of unit vectors in your system. For instance, letting E0  represent the unit vector (1,0,0,0), the command 

V1.E0 := 0; would set up the substitution of zero for the first component of the vector V1 . 

Identifiers that are declared by the index  and mass  declarations are automatically declared to be vectors. 

The following errors can occur in calculations using the high energy physics package: 

A represents only gamma5 in vector expressions You have tried to use A in some way other than gamma5 in a high-energy physics expression. 

Gamma5 not allowed unless vecdim is 4 You have used gamma_5 in a high-energy physics computation involving a vector dimension other than 4. 

<ID> has no mass  

One of the arguments to mshell  has had no mass assigned to it, in high-energy physics calculations. 

Missing arguments for G operator A line symbol is missing in a gamma matrix expression in high-energy physics calculations. 

Unmatched index <list> 

The parser has found unmatched indices during the evaluation of a gamma matrix expression in high-energy physics calculations. 

#$+High Energy Physics

	HEPHYS introduction
	HE-dot operator
	EPS operator
	G operator
	INDEX declaration
	MASS command
	MSHELL command
	NOSPUR declaration
	REMIND declaration
	SPUR declaration
	VECDIM command
	VECTOR declaration

#$+ KNUMERIC PACKAGE				introduction

 The numeric package supplies algorithms based on approximation techniques of numerical mathematics. The algorithms use the rounded  mode arithmetic of REDUCE, including the variable precision feature which is exploited in some algorithms in an adaptive manner in order to reach the desired accuracy. 

#$+ KINTERVAL				type

 Intervals are generally coded as lower bound and upper bound connected by the operator .. , usually associated to a variable in an equation. 

syntax: 
<var> = (<low> .. <high>) 

where <var> is a kernel  and <low>, <high> are numbers or expression which evaluate to numbers with <low><=<high>. 

examples: 
means that the variable x is taken in the range from 2.5 up to 3.5. 

#$+ KNUMERIC ACCURACY

 The keyword parameters accuracy=a  and iterations=i , where a and i  must be positive integer numbers, control the iterative algorithms: the iteration is continued until the local error is below 10**-a; if that is impossible within i  steps, the iteration is terminated with an error message. The values reached so far are then returned as the result. 

#$+ KTRNUMERIC				switch

 Normally the algorithms produce only a minimum of printed output during their operation. In cases of an unsuccessful or unexpected long operation a trace of the iteration  can be printed by setting trnumeric  on . 

#$+ KNUM_MIN				operator

The Fletcher Reeves version of the steepest descent  algorithms is used to find the minimum  of a function of one or more variables. The function must have continuous partial derivatives with respect to all variables. The starting point of the search can be specified; if not, random values are taken instead. The steepest descent algorithms in general find only local minima.  

syntax: 
num_min (<exp>,  <var>[=<val>] [,<var>[=<val>] ...  [,accuracy=<a>] [,iterations=<i>]) 

or 

num_min (exp, { <var>[=<val>] [,<var>[=<val>] ...] } [,accuracy=<a>] [,iterations=<i>]) 

where <exp> is a function expression, <var> are the variables in <exp> and <val> are the (optional) start values. For <a> and <i> see numeric accuracy . 

Num_min tries to find the next local minimum along the descending path starting at the given point. The result is a list  with the minimum function value as first element followed by a list of equation s , where the variables are equated to the coordinates of the result point. 

examples: 
 
num_min(sin(x)+x/5, x) 
 
  {4.9489585606,{X=29.643767785}} 

num_min(sin(x)+x/5, x=0) 
 
  { - 1.3342267466,{X= - 1.7721582671}} 

#$+ KNUM_SOLVE				operator

An adaptively damped Newton iteration is used to find an approximative root of a function (function vector) or the solution of an equation  (equation system). The expressions must have continuous derivatives for all variables. A starting point for the iteration can be given. If not given random values are taken instead. When the number of forms is not equal to the number of variables, the Newton method cannot be applied. Then the minimum of the sum of absolute squares is located instead. 

With complex  on, solutions with imaginary parts can be found, if either the expression(s) or the starting point contain a nonzero imaginary part. 

syntax: 
num_solve (<exp>, <var>[=<val>][,accuracy=<a>][,iterations=<i>]) 

or 

num_solve ({<exp>,...,<exp>}, <var>[=<val>],...,<var>[=<val>]  [,accuracy=<a>][,iterations=<i>]) 

or 

num_solve ({<exp>,...,<exp>}, {<var>[=<val>],...,<var>[=<val>]}  [,accuracy=<a>][,iterations=<i>])  

where <exp> are function expressions,  <var> are the variables,  <val> are optional start values. For <a> and <i> see numeric accuracy .  

num_solve tries to find a zero/solution of the expression(s). Result is a list of equations, where the variables are equated to the coordinates of the result point.  

The Jacobian matrix  is stored as side effect the shared variable jacobian . 

examples: 
 
num_solve({sin x=cos y, x + y = 1},{x=1,y=2}); 

  {X= - 1.8561957251,Y=2.856195584} 

jacobian; 
 
      [COS(X)  SIN(Y)] 
      [              ] 
      [  1       1   ] 

#$+ KNUM_INT				operator

For the numerical evaluation of univariate integrals over a finite interval the following strategy is used: If int  finds a formal antiderivative  which is bounded in the integration interval, this  is evaluated and the end points and the difference  is returned. Otherwise a Chebyshev fit  is computed,  starting with order 20, eventually up to order 80.  If that is recognized as sufficiently convergent  it is used for computing the integral by directly  integrating the coefficient sequence. If none of these methods is successful, an  adaptive multilevel quadrature algorithm is used. 

For multivariate integrals only the adaptive quadrature is used. This algorithm tolerates isolated singularities. The value iterations  here limits the number of local interval intersection levels. <a> is a measure for the relative total discretization error (comparison of order 1 and order 2 approximations). 

syntax: 
num_int (<exp>,<var>=(<l> .. <u>)  [,<var>=(<l> .. <u>),...]  [,accuracy=<a>][,iterations=<i>]) 

where <exp> is the function to be integrated, <var> are the integration variables, <l> are the lower bounds, <u> are the upper bounds.  

Result is the value of the integral.  

examples: 
 
num_int(sin x,x=(0 .. 3.1415926)); 
 
  2.0000010334 

#$+ KNUM_ODESOLVE				operator

The Runge-Kutta  method of order 3 finds an approximate graph for the solution of real ODE initial value problem .  

syntax: 
num_odesolve (<exp>,<depvar>=<start>,  <indep>=(<from> .. <to>)  [,accuracy=<a>][,iterations=<i>]) 

or 

num_odesolve ({<exp>,<exp>,...},  {<depvar>=<start>,<depvar>=<start>,...}  <indep>=(<from> .. <to>)  [,accuracy=<a>][,iterations=<i>]) 

where <depvar> and <start> specify the dependent variable(s) and the starting point value (vector), <indep>, <from> and <to> specify the independent variable and the integration interval (starting point and end point), <exp> are equations or expressions which contain the first derivative of the independent variable with respect to the dependent variable.  

The ODEs are converted to an explicit form, which then is used for a Runge Kutta iteration over the given range. The number of steps is controlled by the value of <i> (default: 20). If the steps are too coarse to reach the desired accuracy in the neighborhood of the starting point, the number is increased automatically.  

Result is a list of pairs, each representing a point of the approximate solution of the ODE problem. 

examples: 
 
depend(y,x); 
 
num_odesolve(df(y,x)=y,y=1,x=(0 .. 1), iterations=5); 

  ,{0.2,1.2214},{0.4,1.49181796},{0.6,1.8221064563}, 
    {0.8,2.2255208258},{1.0,2.7182511366}} 
 
In most cases you must declare the dependency relation between the variables explicitly using depend ; otherwise the formal derivative might be converted to zero. 

The operator solve  is used to convert the form into an explicit ODE. If that process fails or if it has no unique result, the evaluation is stopped with an error message. 

#$+ KBOUNDS				operator

Upper and lower bounds of a real valued function over an interval  or a rectangular multivariate domain are computed by the operator bounds . The algorithmic basis is the computation with inequalities: starting from the interval(s) of the variables, the bounds are propagated in the expression using the rules for inequality computation. Some knowledge about the behavior of special functions like ABS, SIN, COS, EXP, LOG, fractional exponentials etc. is integrated and can be evaluated if the operator bounds  is called with rounded mode on (otherwise only algebraic evaluation rules are available).  

If bounds  finds a singularity within an interval, the evaluation is stopped with an error message indicating the problem part of the expression.  

syntax: 
bounds (<exp>,<var>=(<l> .. <u>)  [,<var>=(<l> .. <u>) ...]) 

or 

bounds (<exp>,{<var>=(<l> .. <u>)  [,<var>=(<l> .. <u>) ...]}) 

where <exp> is the function to be investigated, <var> are the variables of <exp>, <l> and <u> specify the area as set of interval s . 

bounds computes upper and lower bounds for the expression in the given area. An interval  is returned.  

examples: 
 
bounds(sin x,x=(1 .. 2)); 
 
  -1 .. 1 

on rounded; 
 
bounds(sin x,x=(1 .. 2)); 
 
  0.84147098481 .. 1 

bounds(x**2+x,x=(-0.5 .. 0.5)); 
 
  - 0.25 .. 0.75 

#$+ KCHEBYSHEV FIT

The operator family Chebyshev_...  implements approximation and evaluation of functions by the Chebyshev method. Let T(n,a,b,x)  be the Chebyshev polynomial of order n  transformed to the interval (a,b) . Then a function f(x)  can be approximated in (a,b)  by a series 

  for i := 0:n sum c(i)*T(i,a,b,x) 
The operator chebyshev_fit  computes this approximation and returns a list, which has as first element the sum expressed as a polynomial and as second element the sequence of Chebyshev coefficients. Chebyshev_df  and Chebyshev_int  transform a Chebyshev coefficient list into the coefficients of the corresponding derivative or integral respectively. For evaluating a Chebyshev approximation at a given point in the basic interval the operator Chebyshev_eval  can be used. Chebyshev_eval  is based on a recurrence relation which is in general more stable than a direct evaluation of the complete polynomial. 

syntax: 
chebyshev_fit (<fcn>,<var>=(<lo> .. <hi>),<n>) 

chebyshev_eval (<coeffs>,<var>=(<lo> .. <hi>),  <var>=<pt>) 

chebyshev_df (<coeffs>,<var>=(<lo> .. <hi>)) 

chebyshev_int (<coeffs>,<var>=(<lo> .. <hi>)) 

where <fcn> is an algebraic expression (the target function), <var> is the variable of <fcn>, <lo> and <hi> are numerical real values which describe an interval  <lo> < <hi>, the integer <n> is the approximation order (set to 20 if missing), <pt> is a number in the interval and <coeffs> is a series of Chebyshev coefficients. 

examples: 

on rounded; 

w:=chebyshev_fit(sin x/x,x=(1 .. 3),5); 

                 3            2 
  w := {0.03824*x   - 0.2398*x   + 0.06514*x + 0.9778, 
        {0.8991,-0.4066,-0.005198,0.009464,-0.00009511}}                     

chebyshev_eval(second w, x=(1 .. 3), x=2.1); 

  0.4111 

#$+ KNUM_FIT				operator

The operator num_fit  finds for a set of points the linear combination of a given set of functions (function basis) which approximates the points best under the objective of the least squares  criterion (minimum of the sum of the squares of the deviation). The solution is found as zero of the gradient vector of the sum of squared errors. 

syntax: 
num_fit (<vals>,<basis>,<var>=<pts>) 

where <vals> is a list of numeric values, <var> is a variable used for the approximation, <pts> is a list of coordinate values which correspond to <var>, <basis> is a set of functions varying in var  which is used  for the approximation.  

The result is a list containing as first element the function which approximates the given values, and as second element a list of coefficients which were used to build this function from the basis.  

examples: 

pts:=for i:=1 step 1 until 5 collect i$ 
 
vals:=for i:=1 step 1 until 5 collect 
 
            for j:=1:i product j$ 
 
num_fit(vals,{1,x,x**2},x=pts); 
 
                     2 
      {14.571428571*X   - 61.428571429*X + 54.6,{54.6, 
           - 61.428571429,14.571428571}} 

#$+Numeric Package

	Numeric Package introduction
	Interval type
	numeric accuracy concept
	TRNUMERIC switch
	num_min operator
	num_solve operator
	num_int operator
	num_odesolve operator
	bounds operator
	Chebyshev fit concept
	num_fit operator

#$+ KROOTS PACKAGE				introduction

The root finding package is designed so that it can be used to find some or all of the roots of univariate polynomials with real or complex coefficients, to the accuracy specified by the user. 

Not all operators of roots package  are described here. For using the operators 

isolater (intervals isolating real roots) 

rlrootno (number of real roots in an interval) 

rootsat-prec (roots at system precision) 

rootval (result in equation form) 

firstroot (computing only one root) 

getroot (selecting roots from a collection) 

please consult the full documentation of the package. 

#$+ KMKPOLY				operator

Given a roots list as returned by roots , the operator mkpoly  constructs a polynomial which has these numbers as roots.  
syntax: 

mkpoly <rl> 

where <rl> is a list  with equations, which all have the same kernel  on their left-hand sides and numbers as right-hand sides. 

examples: 
 
mkpoly{x=1,x=-2,x=i,x=-i}; 
 
  x**4 + x**3 - x**2 + x - 2 
 
Note that this polynomial is unique only up to a numeric factor. 

#$+ KNEARESTROOT				operator

The operator nearestroot  finds one root of a polynomial with an iteration using a given starting point. 

syntax: 
nearestroot (<p>,<pt>) 

where <p> is a univariate polynomial and <pt> is a number. 

examples: 
 
nearestroot(x^2+2,2); 
 
  {x=1.41421*i} 
 
The minimal accuracy of the result values is controlled by rootacc . 

#$+ KREALROOTS				operator

The operator realroots  finds that real roots of a polynomial to an accuracy that is sufficient to separate them and which is a minimum of 6 decimal places. 

syntax: 
realroots (<p>) or 

realroots (<p>,<from>,<to>) 

where <p> is a univariate polynomial. The optional parameters <from> and <to> classify an interval: if given, exactly the real roots in this interval will be returned. <from> and <to> can also take the values infinity  or -infinity . If omitted all real roots will be returned. Result is a list  of equations which represent the roots of the polynomial at the given accuracy. 

examples: 
 
realroots(x^5-2); 
 
  {x=1.1487} 

realroots(x^3-104*x^2+403*x-300,2,infinity); 

  {x=3.0,x=100.0} 

realroots(x^3-104*x^2+403*x-300,-infinity,2); 

  {x=1} 
 
The minimal accuracy of the result values is controlled by rootacc . 

#$+ KROOTACC				operator

The operator rootacc  allows you to set the accuracy up to which the roots package computes its results.  
syntax: 

rootacc (<n>) 

Here <n> is an integer value. The internal accuracy of the roots  package is adjusted to a value of max(6,n) . The default value is 6 . 

#$+ KROOTS				operator

The operator roots  is the main top level function of the roots package. It will find all roots, real and complex, of the polynomial p to an accuracy that is sufficient to separate them and which is a minimum of 6 decimal places. 

syntax: 
roots (<p>) 

where <p> is a univariate polynomial. Result is a list  of equations which represent the roots of the polynomial at the given accuracy. In addition, roots  stores separate lists of real roots and complex roots in the global variables rootsreal  and rootscomplex . 

examples: 
 
roots(x^5-2); 
 
  {x=-0.929316 + 0.675188*i, 
    x=-0.929316 - 0.675188*i, 
    x=0.354967 + 1.09248*i, 
    x=0.354967 - 1.09248*i,  
    x=1.1487} 
 
The minimal accuracy of the result values is controlled by rootacc . 

#$+ KROOT‑VAL				operator

The operator root_val  computes the roots of a univariate polynomial at system precision (or greater if required for root separation) and presents its result as a list of numbers.  
syntax: 

roots (<p>) 

where <p> is a univariate polynomial. 

examples: 
 
root_val(x^5-2); 
 
  {-0.929316490603 + 0.6751879524*i, 
   -0.929316490603 - 0.6751879524*i, 
   0.354967313105 + 1.09247705578*i, 
   0.354967313105 - 1.09247705578*i, 
   1.148698355} 

#$+ KROOTSCOMPLEX				variable

When the operator roots  is called the complex roots are collected in the global variable rootscomplex  as list . 

#$+ KROOTSREAL				variable

When the operator roots  is called the real roots are collected in the global variable rootreal  as list . 

#$+Roots Package

	Roots Package introduction
	MKPOLY operator
	NEARESTROOT operator
	REALROOTS operator
	ROOTACC operator
	ROOTS operator
	ROOT‑VAL operator
	ROOTSCOMPLEX variable
	ROOTSREAL variable

#$+ KSPECIAL FUNCTION PACKAGE				introduction

 The REDUCE Special Function Package  supplies extended algebraic and numeric support for a wide class of objects. This package was released together with REDUCE 3.5 (October 1993) for the first time, a major update is released with REDUCE 3.6. 

The functions included in this package are in most cases (unless otherwise stated) defined and named like in the book by Abramowitz and Stegun: Handbook of Mathematical Functions, Dover Publications. 

The aim is to collect as much information on the special functions and simplification capabilities as possible, i.e. algebraic simplifications and numeric (rounded mode) code, limits of the functions together with the definitions of the functions, which are in most cases a power series, a (definite) integral and/or a differential equation. 

What can be found: Some famous constants, a variety of Bessel functions, special polynomials, the Gamma function, the (Riemann) Zeta function, Elliptic Functions, Elliptic Integrals, 3J symbols (Clebsch-Gordan coefficients) and integral functions. 

What is missing: Mathieu functions, LerchPhi, etc.. The information about the special functions which solve certain differential equation is very limited. In several cases numerical approximation is restricted to real arguments or is missing completely. 

The implementation of this package uses REDUCE rule sets to a large extent, which guarantees a high 'readability' of the functions definitions in the source file directory. It makes extensions to the special functions code easy in most cases too. To look at these rules it may be convenient to use the showrules operator e.g. 

showrules Besseli; 

. 

Some evaluations are improved if the special function package is loaded, e.g. some (infinite) sums and products leading to expressions including special functions are known in this case. 

Note: The special function package has to be loaded explicitly by calling  
   load_package specfn; 

The functions MeijerG  and hypergeometric  require additionally  
   load_package specfn2; 

#$+ KCONSTANTS

There are a few constants known to the special function package, namely 

Euler's constant (which can be computed as -Psi (1)) and 

Khinchin's constant (which is defined in Khinchin's book 

	``Continued Fractions'') and 

Golden_Ratio (which can be computed as (1 + sqrt 5)/2) and 

Catalan's constant (which is known as an infinite sum of reciprocal powers) 

examples: 
 
on rounded; 
Euler_Gamma;  
 
  0.577215664902  

Khinchin;  
 
  2.68545200107  

Catalan  
 
  0.915965594177  

Golden_Ratio  
 
  1.61803398875 

#$+ KBERNOULLI				operator

 The bernoulli  operator returns the nth Bernoulli number. 

syntax: 
Bernoulli (<integer>) 

 
examples: 
 
bernoulli 20;  
 
  - 174611 / 330  

bernoulli 17;  
 
  0 
 
All Bernoulli numbers with odd indices except for 1 are zero. 

#$+ KBERNOULLIP				operator

 The BernoulliP  operator returns the nth Bernoulli Polynomial evaluated at x. 

syntax: 
BernoulliP (<integer>,<expression>) 

 
examples: 
 
BernoulliP(3,z);  
 
        2 
  z*(2*z   - 3*z + 1)/2 

 
BernoulliP(10,3);  
 
  338585 / 66 
 
The value of the nth Bernoulli Polynomial at 0 is the nth Bernoulli number. 

#$+ KEULER				operator

 The EULER  operator returns the nth Euler number. 

syntax: 
Euler (<integer>) 

 
examples: 
 
Euler 20;  
 
  370371188237525  

Euler 0;  
 
  1 
 
The Euler  numbers are evaluated by a recursive algorithm which makes it hard to compute Euler numbers above say 200. 

Euler numbers appear in the coefficients of the power series representation of 1/cos(z). 

#$+ KEULERP				operator

 The EulerP  operator returns the nth Euler Polynomial. 

syntax: 
EulerP (<integer>,<expression>) 

 
examples: 
 
EulerP(2,xx);  
 
  xx*(xx - 1)  

EulerP(10,3);  
 
  2046 
 
The Euler numbers are the values of the Euler Polynomials at 1/2 multiplied by 2**n. 

#$+ KZETA				operator

 The Zeta  operator returns Riemann's Zeta function, 

Zeta (z) := sum(1/(k**z),k,1,infinity) 

syntax: 
Zeta (<expression>) 

 
examples: 
 
Zeta(2);  
 
    2 
  pi  / 6  

on rounded;  
 
Zeta 1.01;  
 
  100.577943338 
 
Numerical computation for the Zeta function for arguments close to 1 are tedious, because the series is converging very slowly. In this case a formula (e.g. found in Bender/Orzag: Advanced Mathematical Methods for Scientists and Engineers, McGraw-Hill) is used. 

No numerical approximation for complex arguments is done. 

#$+Bernoulli Euler Zeta

	BERNOULLI operator
	BERNOULLIP operator
	EULER operator
	EULERP operator
	ZETA operator

#$+ KBESSELJ				operator

 The BesselJ  operator returns the Bessel function of the first kind. 

syntax: 
BesselJ (<order>,<argument>) 

 
examples: 
 
BesselJ(1/2,pi);  
 
  0  

on rounded;  
 
BesselJ(0,1);  
 
  0.765197686558   

#$+ KBESSELY				operator

The BesselY  operator returns the Bessel function of the second kind.  
syntax: 

BesselY (<order>,<argument>) 

 
examples: 
 
BesselY (1/2,pi);  
 
  - sqrt(2) / pi  

on rounded;  
 
BesselY (1,3);  
 
  0.324674424792 
 
The operator BesselY  is also called Weber's function. 

#$+ KHANKEL1				operator

 The Hankel1  operator returns the Hankel function of the first kind. 

syntax: 
Hankel1 (<order>,<argument>) 

 
examples: 
 
on complex;  
 
Hankel1 (1/2,pi);  
 
  - i * sqrt(2) / pi  

Hankel1 (1,pi);  
 
  besselj(1,pi) + i*bessely(1,pi) 
 
The operator Hankel1  is also called Bessel function of the third kind. There is currently no numeric evaluation of Hankel functions. 

#$+ KHANKEL2				operator

 The Hankel2  operator returns the Hankel function of the second kind. 

syntax: 
Hankel2 (<order>,<argument>) 

 
examples: 
 
on complex;  
 
Hankel2 (1/2,pi);  
 
  - i * sqrt(2) / pi  

Hankel2 (1,pi);  
 
  besselj(1,pi) - i*bessely(1,pi) 
 
The operator Hankel2  is also called Bessel function of the third kind. There is currently no numeric evaluation of Hankel functions. 

#$+ KBESSELI				operator

 The BesselI  operator returns the modified Bessel function I. 

syntax: 
BesselI (<order>,<argument>) 

 
examples: 
 
on rounded;  
 
Besseli (1,1);  
 
  0.565159103992 
 
The knowledge about the operator BesselI  is currently fairly limited. 

#$+ KBESSELK				operator

 The BesselK  operator returns the modified Bessel function K. 

syntax: 
BesselK (<order>,<argument>) 

 
examples: 
 
df(besselk(0,x),x);  
 
  - besselk(1,x) 
 
There is currently no numeric support for the operator BesselK . 

#$+ KSTRUVEH				operator

 The StruveH  operator returns Struve's H function. 

syntax: 
StruveH (<order>,<argument>) 

 
examples: 
 
struveh(-3/2,x);  
 
  - besselj(3/2,x) / i 

#$+ KSTRUVEL				operator

 The StruveL  operator returns the modified Struve L function . 

syntax: 
StruveL (<order>,<argument>) 

 
examples: 
 
struvel(-3/2,x);  
 
  besseli(3/2,x) 

#$+ KKUMMERM				operator

The KummerM  operator returns Kummer's M function. 

syntax: 
KummerM (<parameter>,<parameter>,<argument>) 

 
examples: 
 
kummerm(1,1,x);  
 
   x 
  e   

on rounded;  
 
kummerm(1,3,1.3);  
 
  1.62046942914 
 
Kummer's M function is one of the Confluent Hypergeometric functions. For reference see the hypergeometric  operator. 

#$+ KKUMMERU				operator

The KummerU  operator returns Kummer's U function. 

syntax: 
KummerU (<parameter>,<parameter>,<argument>) 

 
examples: 
 
df(kummeru(1,1,x),x)  
 
  - kummeru(2,2,x) 
 
Kummer's U function is one of the Confluent Hypergeometric functions. For reference see the hypergeometric  operator. 

#$+ KWHITTAKERW				operator

The WhittakerW  operator returns Whittaker's W function. 

syntax: 
WhittakerW (<parameter>,<parameter>,<argument>) 

 
examples: 
 
WhittakerW(2,2,2);  
 
                    1 
  4*sqrt(2)*kummeru(-,5,2) 
                    2 
  ------------------------- 
             e 
 
Whittaker's W function is one of the Confluent Hypergeometric functions. For reference see the hypergeometric  operator. 

#$+Bessel Functions

	BESSELJ operator
	BESSELY operator
	HANKEL1 operator
	HANKEL2 operator
	BESSELI operator
	BESSELK operator
	StruveH operator
	StruveL operator
	KummerM operator
	KummerU operator
	WhittakerW operator

#$+ KAIRY_AI				operator

 The Airy_Ai  operator returns the Airy Ai function for a given argument. 

syntax: 
Airy_Ai (<argument>) 

 
examples: 
 
on complex; 
on rounded; 
Airy_Ai(0);  

  0.355028053888           

Airy_Ai(3.45 + 17.97i);  
 
  - 5.5561528511e+9 - 8.80397899932e+9*i   

#$+ KAIRY_BI				operator

 The Airy_Bi  operator returns the Airy Bi function for a given argument. 

syntax: 
Airy_Bi (<argument>) 

 
examples: 
 
Airy_Bi(0);  
 
  0.614926627446           

Airy_Bi(3.45 + 17.97i);  
 
  8.80397899932e+9 - 5.5561528511e+9*i    

#$+ KAIRY_AIPRIME				operator

 The Airy_Aiprime  operator returns the Airy Aiprime function for a given argument. 

syntax: 
Airy_Aiprime (<argument>) 

 
examples: 
 
Airy_Aiprime(0);  
 
  - 0.258819403793            

Airy_Aiprime(3.45+17.97i); 
 
  - 3.83386421824e+19 + 2.16608828136e+19*i  

#$+ KAIRY_BIPRIME				operator

 The Airy_Biprime  operator returns the Airy Biprime function for a given argument. 

syntax: 
Airy_Biprime (<argument>) 

 
examples: 
 
Airy_Biprime(0);  

Airy_Biprime(3.45 + 17.97i);  
 
  3.84251916792e+19 - 2.18006297399e+19*i 

#$+Airy Functions

	Airy_Ai operator
	Airy_Bi operator
	Airy_Aiprime operator
	Airy_Biprime operator

#$+ KJACOBISN				operator

 The Jacobisn  operator returns the Jacobi Elliptic function sn. 

syntax: 
Jacobisn (<expression>,<integer>) 

 
examples: 
 
Jacobisn(0.672, 0.36)  
 
  0.609519691792  

Jacobisn(1,0.9)  
 
  0.770085724907881  

#$+ KJACOBICN				operator

 The Jacobicn  operator returns the Jacobi Elliptic function cn. 

syntax: 
Jacobicn (<expression>,<integer>) 

 
examples: 
 
Jacobicn(7.2, 0.6)  
 
  0.837288298482018   

Jacobicn(0.11, 19)  
 
  0.994403862690043 - 1.6219006985556e-16*i   

#$+ KJACOBIDN				operator

 The Jacobidn  operator returns the Jacobi Elliptic function dn. 

syntax: 
Jacobidn (<expression>,<integer>) 

 
examples: 
 
Jacobidn(15, 0.683)  
 
  0.640574162024592  

Jacobidn(0,0)  
 
  1  

#$+ KJACOBICD				operator

 The Jacobicd  operator returns the Jacobi Elliptic function cd. 

syntax: 
Jacobicd (<expression>,<integer>) 

 
examples: 
 
Jacobicd(1, 0.34)  
 
  0.657683337805273  

Jacobicd(0.8,0.8)  
 
  0.925587311582301  

#$+ KJACOBISD				operator

 The Jacobisd  operator returns the Jacobi Elliptic function sd. 

syntax: 
Jacobisd (<expression>,<integer>) 

 
examples: 
 
Jacobisd(12, 0.4)  
 
  0.357189729437272     

Jacobisd(0.35,1)  
 
  - 1.17713873203043   

#$+ KJACOBIND				operator

 The Jacobind  operator returns the Jacobi Elliptic function nd. 

syntax: 
Jacobind (<expression>,<integer>) 

 
examples: 
 
Jacobind(0.2, 17)  
 
  1.46553203037507 + 0.0000000000334032759313703*i  

Jacobind(30, 0.001)  
 
  1.00048958438   

#$+ KJACOBIDC				operator

 The Jacobidc  operator returns the Jacobi Elliptic function dc. 

syntax: 
Jacobidc (<expression>,<integer>) 

 
examples: 
 
Jacobidc(0.003,1)  
 
  1  

Jacobidc(2, 0.75)  
 
  6.43472885111   

#$+ KJACOBINC				operator

 The Jacobinc  operator returns the Jacobi Elliptic function nc. 

syntax: 
Jacobinc (<expression>,<integer>) 

 
examples: 
 
Jacobinc(1,0)  
 
  1.85081571768093  

Jacobinc(56, 0.4387)  
 
  39.304842663512   

#$+ KJACOBISC				operator

 The Jacobisc  operator returns the Jacobi Elliptic function sc. 

syntax: 
Jacobisc (<expression>,<integer>) 

 
examples: 
 
Jacobisc(9, 0.88)  
 
  - 1.16417697982095   

Jacobisc(0.34, 7)  
 
  0.305851938390775 - 9.8768100944891e-12*i  

#$+ KJACOBINS				operator

 The Jacobins  operator returns the Jacobi Elliptic function ns. 

syntax: 
Jacobins (<expression>,<integer>) 

 
examples: 
 
Jacobins(3, 0.9)  
 
  1.00945801599785  

Jacobins(0.887, 15)  
 
  0.683578280513975 - 0.85023411082469*i  

#$+ KJACOBIDS				operator

 The Jacobisn  operator returns the Jacobi Elliptic function ds. 

syntax: 
Jacobids (<expression>,<integer>) 

 
examples: 
 
Jacobids(98,0.223)  
 
  - 1.061253961477  

Jacobids(0.36,0.6)  
 
  2.76693172243692  

#$+ KJACOBICS				operator

 The Jacobics  operator returns the Jacobi Elliptic function cs. 

syntax: 
Jacobics (<expression>,<integer>) 

 
examples: 
 
Jacobics(0, 0.767)  
 
  infinity    

Jacobics(1.43, 0)  
 
  0.141734127352112  

#$+ KJACOBIAMPLITUDE				operator

 The JacobiAmplitude  operator returns the amplitude of u.  
syntax: 

JacobiAmplitude (<expression>,<integer>) 

 
examples: 
 
JacobiAmplitude(7.239, 0.427)  
 
  0.0520978301448978  

JacobiAmplitude(0,0.1)  
 
  0  
 
Amplitude u = asin(Jacobisn(u,m) ) 

#$+ KAGM_FUNCTION				operator

 The AGM_function  operator returns a list of (N, AGM,  list of aNtoa0, list of bNtob0, list of cNtoc0) where a0, b0 and c0 are the initial values; N is the index number of the last term used to generate the AGM. AGM is the Arithmetic Geometric Mean. 

syntax: 
AGM_function (<integer>,<integer>,<integer>) 

 
examples: 
 
AGM_function(1,1,1)  
 
  1,1,1,1,1,1,0,1   

AGM_function(1, 0.1, 1.3)  
 
  {6, 
   2.27985615996629,  
   {2.27985615996629, 2.27985615996629, 
    2.2798561599706, 2.2798624278857,  
    2.28742283656583, 2.55, 1}, 
   {2.27985615996629, 2.27985615996629, 
    2.27985615996198, 2.2798498920555,  
    2.27230201920557, 2.02484567313166, 4.1}, 
   {0, 4.30803136219904e-12, 0.0000062679151007581, 
    0.00756040868012758, 0.262577163434171, - 1.55, 5.9}} 
 
The other Jacobi functions use this function with initial values a0=1, b0=sqrt(1-m), c0=sqrt(m). 

#$+ KLANDENTRANS				operator

 The landentrans  operator generates the descending landen transformation of the given imput values, returning a list of these values; initial to final in each case.  
syntax: 

landentrans (<expression>,<integer>) 

 
examples: 
 
landentrans(0,0.1)  
 
  {{0,0,0,0,0},{0.1,0.0025041751943776,  

  
 
  0.00000156772498954046,6.1444078 9914461e-13,0}}   
 
The first list ascends in value, and the second descends in value. 

#$+ KELLIPTICF				operator

 The EllipticF  operator returns the Elliptic Integral of the First Kind.  
syntax: 

EllitpicF (<expression>,<integer>) 

 
examples: 
 
EllipticF(0.3, 8.222)  
 
  0.3  

EllipticF(7.396, 0.1)  
 
  7.58123216114307  
 
The Complete Elliptic Integral of the First Kind can be found by putting the first argument to pi/2 or by using EllipticK  and the second argument. 

#$+ KELLIPTICK				operator

 The EllipticK  operator returns the Elliptic value K. 

syntax: 
EllipticK (<integer>) 

 
examples: 
 
EllipticK(0.2)  
 
  1.65962359861053    

EllipticK(4.3)  
 
  0.808442364282734 - 1.05562492399206*i   

EllipticK(0.000481)  
 
  1.57098526617635     
 
The EllipticK  function is the Complete Elliptic Integral of the First Kind. 

#$+ KELLIPTICKPRIME				operator

 The EllipticK'  operator returns the Elliptic value K(m). 

syntax: 
EllipticKprime (<integer>) 

 
examples: 
 
EllipticKprime(0.2)  
 
  2.25720532682085  

EllipticKprime(4.3)  
 
  1.05562492399206  

EllipticKprime(0.000481)  
 
  5.206621921966    
 
The EllipticKprime  function is the Complete Elliptic Integral of the First Kind of (1-m). 

#$+ KELLIPTICE				operator

 The EllipticE  operator used with two arguments returns the Elliptic Integral of the Second Kind.  
syntax: 

EllipticE (<expression>,<integer>) 

 
examples: 
 
EllipticE(1.2,0.22)  
 
  1.15094019180949  

EllipticE(0,4.35)  
 
  0                 

EllipticE(9,0.00719)  
 
  8.98312465929145   
 
The Complete Elliptic Integral of the Second Kind can be obtained by using just the second argument, or by using pi/2 as the first argument. 

The EllipticE  operator used with one argument returns the Elliptic value E.  
syntax: 

EllipticE (<integer>) 

 
examples: 
 
EllipticE(0.22)  
 
  1.48046637439519   

EllipticE(pi/2, 0.22)  
 
  1.48046637439519   

#$+ KELLIPTICTHETA				operator

 The EllipticTheta  operator returns one of the four Theta functions. It cannot except any number other than 1,2,3 or 4 as its first argument. 

syntax: 
EllipticTheta (<integer>,<expression>,<integer>) 

 
examples: 
 
EllipticTheta(1, 1.4, 0.72)  
 
  0.91634775373   

EllipticTheta(2, 3.9, 6.1 )  
 
  -48.0202736969 + 20.9881034377 i  

EllipticTheta(3, 0.67, 0.2)  
 
  1.0083077448    

EllipticTheta(4, 8, 0.75)  
 
  0.894963369304  

EllipticTheta(5, 1, 0.1)  
 
  ***** In EllipticTheta(a,u,m); a = 1,2,3 or 4.    
 
Theta functions are important because every one of the Jacobian Elliptic functions can be expressed as the ratio of two theta functions. 

#$+ KJACOBIZETA				operator

 The JacobiZeta  operator returns the Jacobian function Zeta. 

syntax: 
JacobiZeta (<expression>,<integer>) 

 
examples: 
 
JacobiZeta(3.2, 0.8)  
 
  - 0.254536403439  

JacobiZeta(0.2, 1.6)  
 
  0.171766095970451 - 0.0717028569800147*i   
 
The Jacobian function Zeta is related to the Jacobian function Theta. But it is significantly different from Riemann's Zeta Function Zeta . 

#$+Jacobi's Elliptic Functions and Elliptic Integrals

	JacobiSN operator
	JacobiCN operator
	JacobiDN operator
	JacobiCD operator
	JacobiSD operator
	JacobiND operator
	JacobiDC operator
	JacobiNC operator
	JacobiSC operator
	JacobiNS operator
	JacobiDS operator
	JacobiCS operator
	JacobiAMPLITUDE operator
	AGM_FUNCTION operator
	LANDENTRANS operator
	EllipticF operator
	EllipticK operator
	EllipticKprime operator
	EllipticE operator
	EllipticTHETA operator
	JacobiZETA operator

#$+ KPOCHHAMMER				operator

The Pochhammer  operator implements the Pochhammer notation (shifted factorial). 

syntax: 
Pochhammer (<expression>,<expression>) 

 
examples: 
 
pochhammer(17,4);  
 
  116280  

 
pochhammer(1/2,z);  
 
    factorial(2*z) 
  -------------------- 
    2*z 
  (2   *factorial(z)) 
 
A number of complex rules for Pochhammer  are inactive, because they cause a huge system load in algebraic mode. If one wants to use more rules for the simplification of Pochhammer's notation, one can do: 

let special!*pochhammer!*rules; 

#$+ KGAMMA				operator

 The Gamma  operator returns the Gamma function. 

syntax: 
Gamma (<expression>) 

 
examples: 
 
gamma(10);  
 
  362880     

gamma(1/2);  
 
  sqrt(pi) 

#$+ KBETA				operator

 The Beta  operator returns the Beta function defined by 

Beta (z,w) := defint(t**(z-1)* (1 - t)**(w-1),t,0,1) . 

syntax: 
Beta (<expression>,<expression>) 

 
examples: 
 
Beta(2,2);  
 
  1 / 6  

Beta(x,y);  
 
  gamma(x)*gamma(y) / gamma(x + y) 
 
The operator Beta  is simplified towards the GAMMA  operator. 

#$+ KPSI				operator

The Psi  operator returns the Psi (or DiGamma) function. 

Psi(x) := df(Gamma(z),z)/ Gamma (z) 

syntax: 
Gamma (<expression>) 

 
examples: 
 
Psi(3);  
 
  (2*log(2) + psi(1/2) + psi(1) + 3)/2  

on rounded;  
 
- Psi(1);  
 
  0.577215664902 
 
Euler's constant can be found as - Psi(1). 

#$+ KPOLYGAMMA				operator

 The Polygamma  operator returns the Polygamma function. 

Polygamma(n,x) := df(Psi(z),z,n); 

syntax: 
Polygamma (<integer>,<expression>) 

 
examples: 
 
 Polygamma(1,2);  
 
     2 
  (pi   - 6) / 6 

on rounded;  
 
Polygamma(1,2.35);  
 
  0.52849689109 
 
The Polygamma function is used for simplification of the ZETA  function for some arguments. 

#$+Gamma and Related Functions

	POCHHAMMER operator
	GAMMA operator
	BETA operator
	PSI operator
	POLYGAMMA operator

#$+ KDILOG EXTENDED				operator

The package specfn  supplies an extended support for the dilog  operator which implements the dilogarithm function . 

dilog(x) := - defint(log(t)/(t - 1),t,1,x); 

syntax: 
Dilog (<order>,<expression>) 

 
examples: 
 
defint(log(t)/(t - 1),t,1,x);  
 
  - dilog (x)  

dilog 2;  
 
      2 
  - pi  /12  

 
on rounded;  
 
Dilog 20;  
 
  - 5.92783972438 
 
The operator Dilog  is sometimes called Spence's Integral for n = 2. 

#$+ KLAMBERT_W FUNCTION				operator

 Lambert's W function is the inverse of the function w * e^w. It is used in the solve  package for equations containing exponentials and logarithms. 

syntax: 
Lambert_W (<z>) 

 
examples: 
 
Lambert_W(-1/e);  
 
  -1  

solve(w + log(w),w);  
 
  w=lambert_w(1) 

on rounded;  
 
Lambert_W(-0.05);  
 
  - 0.0527059835515 
 
The current implementation will compute the principal branch in rounded mode only. 

#$+Miscellaneous Functions

	DILOG extended operator
	Lambert_W function operator

#$+ KCHEBYSHEVT				operator

 The ChebyshevT  operator computes the nth Chebyshev T Polynomial (of the first kind). 

syntax: 
ChebyshevT (<integer>,<expression>) 

 
examples: 
 
ChebyshevT(3,xx);  
 
          2 
  xx*(4*xx   - 3)  

 
ChebyshevT(3,4);  
 
  244 
 
Chebyshev's T polynomials are computed using the recurrence relation: 

ChebyshevT(n,x) := 2x*ChebyshevT(n-1,x) - ChebyshevT(n-2,x) with 

ChebyshevT(0,x) := 0 and ChebyshevT(1,x) := x 

#$+ KCHEBYSHEVU				operator

 The ChebyshevU  operator returns the nth Chebyshev U Polynomial (of the second kind). 

syntax: 
ChebyshevU (<integer>,<expression>) 

 
examples: 
 
ChebyshevU(3,xx);  
 
          2 
  4*x*(2*x   - 1)  

 
ChebyshevU(3,4);  
 
  496 
 
Chebyshev's U polynomials are computed using the recurrence relation: 

ChebyshevU(n,x) := 2x*ChebyshevU(n-1,x) - ChebyshevU(n-2,x) with 

ChebyshevU(0,x) := 0 and ChebyshevU(1,x) := 2x 

#$+ KHERMITEP				operator

 The HermiteP  operator returns the nth Hermite Polynomial. 

syntax: 
HermiteP (<integer>,<expression>) 

 
examples: 
 
HermiteP(3,xx);  
 
            2 
  4*xx*(2*xx   - 3)  

HermiteP(3,4);  
 
  464 
 
Hermite polynomials are computed using the recurrence relation:  

HermiteP(n,x) := 2x*HermiteP(n-1,x) - 2*(n-1)*HermiteP(n-2,x) with 

HermiteP(0,x) := 1 and HermiteP(1,x) := 2x 

#$+ KLAGUERREP				operator

 The LaguerreP  operator computes the nth Laguerre Polynomial. The two argument call of LaguerreP is a (common) abbreviation of LaguerreP(n,0,x). 

syntax: 
LaguerreP (<integer>,<expression>) or 

LaguerreP (<integer>,<expression>,<expression>) 

 
examples: 
 
LaguerreP(3,xx);  
 
       3        2 
  (- xx   + 9*xx   - 18*xx + 6)/6 

 
LaguerreP(2,3,4);  
 
  -2 
 
Laguerre polynomials are computed using the recurrence relation: 

LaguerreP(n,a,x) := (2n+a-1-x)/n*LaguerreP(n-1,a,x) - 			(n+a-1) * LaguerreP(n-2,a,x) with 

LaguerreP(0,a,x) := 1 and LaguerreP(2,a,x) := -x+1+a 

#$+ KLEGENDREP				operator

 The binary LegendreP  operator computes the nth Legendre Polynomial which is a special case of the nth Jacobi Polynomial with 

LegendreP(n,x) := JacobiP(n,0,0,x) 

The ternary form returns the associated Legendre Polynomial (see below). 

syntax: 
LegendreP (<integer>,<expression>) or 

LegendreP (<integer>,<expression>,<expression>) 

 
examples: 
 
LegendreP(3,xx);  
 
          2 
  xx*(5*xx   - 3) 
  ---------------- 
         2 

 
LegendreP(3,2,xx);  
 
              2 
  15*xx*( - xx   + 1) 
 
The ternary form of the operator LegendreP  is the associated Legendre Polynomial defined as  

P(n,m,x) = (-1)**m * (1-x**2)**(m/2) * df(LegendreP(n,x),x,m) 

#$+ KJACOBIP				operator

 The JacobiP  operator computes the nth Jacobi Polynomial. 

syntax: 
JacobiP (<integer>,<expression>,<expression>,  <expression>) 

 
examples: 
 
JacobiP(3,4,5,xx);  
 
          3         2 
  7*(65*xx   - 13*xx   - 13*xx + 1) 
  ---------------------------------- 
                  8 

 
JacobiP(3,4,5,6);  
 
  94465/8 

#$+ KGEGENBAUERP				operator

The GegenbauerP  operator computes Gegenbauer's (ultraspherical) polynomials. 

syntax: 
GegenbauerP (<integer>,<expression>,<expression>) 

 
examples: 
 
GegenbauerP(3,2,xx);  
 
            2 
  4*xx*(8*xx   - 3) 

 
GegenbauerP(3,2,4);  
 
  2000 

#$+ KSOLIDHARMONICY				operator

The SolidHarmonicY  operator computes Solid harmonic (Laplace) polynomials. 

syntax: 
SolidHarmonicY (<integer>,<integer>, <expression>,<expression>,<expression>,<expression>) 

 
examples: 

SolidHarmonicY(3,-2,x,y,z,r2);  
 
                           2    2 
  sqrt(105)*z*(-2*i*x*y + x  - y ) 
  --------------------------------- 
         4*sqrt(pi)*sqrt(2) 

#$+ KSPHERICALHARMONICY				operator

The SphericalHarmonicY  operator computes Spherical harmonic (Laplace) polynomials. These are special cases of the solid harmonic polynomials, SolidHarmonicY . 

syntax: 
SphericalHarmonicY (<integer>,<integer>, <expression>,<expression>) 

 
examples: 
 
SphericalHarmonicY(3,2,theta,phi);  

                                 2          2                               2 
  sqrt(105)*cos(theta)*sin(theta) *(cos(phi) +2*cos(phi)*sin(phi)*i-sin(phi) ) 
  ----------------------------------------------------------------------------- 
                               4*sqrt(pi)*sqrt(2) 

#$+Orthogonal Polynomials

	ChebyshevT operator
	ChebyshevU operator
	HermiteP operator
	LaguerreP operator
	LegendreP operator
	JacobiP operator
	GegenbauerP operator
	SolidHarmonicY operator
	SphericalHarmonicY operator

#$+ KSI				operator

The Si  operator returns the Sine Integral function. 

syntax: 
Si (<expression>) 

 
examples: 
 
limit(Si(x),x,infinity);  
 
  pi / 2  

on rounded;  
 
Si(0.35);  
 
  0.347626790989 
 
The numeric values for the operator Si  are computed via the power series representation, which limits the argument range. 

#$+ KSHI				operator

The Shi  operator returns the hyperbolic Sine Integral function. 

syntax: 
Shi (<expression>) 

 
examples: 
 
df(shi(x),x);  
 
  sinh(x) / x  

on rounded;  
 
Shi(0.35);  
 
  0.352390716351 
 
The numeric values for the operator Shi  are computed via the power series representation, which limits the argument range. 

#$+ KS_I				operator

The s_i  operator returns the Sine Integral function si. 

syntax: 
s_i (<expression>) 

 
examples: 
 
s_i(xx);  
 
  (2*Si(xx) - pi) / 2  

df(s_i(x),x);  
 
  sin(x) / x 
 
The operator name s_i  is simplified towards SI . Since REDUCE is not case sensitive by default the name ``si'' can't be used. 

#$+ KCI				operator

The Ci  operator returns the Cosine Integral function. 

syntax: 
Ci (<expression>) 

 
examples: 
 
defint(cos(t)/t,t,x,infinity);  
 
  - ci (x)  

on rounded;  
 
Ci(0.35);  
 
  - 0.50307556932 
 
The numeric values for the operator Ci  are computed via the power series representation, which limits the argument range. 

#$+ KCHI				operator

The Chi  operator returns the Hyperbolic Cosine Integral function. 

syntax: 
Chi (<expression>) 

 
examples: 
 
defint((cosh(t)-1)/t,t,0,x);  
 
  - log(x) + psi(1) + chi(x) 

on rounded;  
 
Chi(0.35);  
 
  - 0.44182471827 
 
The numeric values for the operator Chi  are computed via the power series representation, which limits the argument range. 

#$+ KERF EXTENDED				operator

The special function package supplies an extended support for the erf  operator which implements the error function  

defint(e**(-x**2),x,0,infinity) * 2/sqrt(pi) 

. 

syntax: 
erf (<expression>) 

 
examples: 
 
erf(-x);  
 
  - erf(x) 

on rounded;  
 
erf(0.35);  
 
  0.379382053562 
 
The numeric values for the operator erf  are computed via the power series representation, which limits the argument range. 

#$+ KERFC				operator

The erfc  operator returns the complementary Error function 

1 - defint(e**(-x**2),x,0,infinity) * 2/sqrt(pi) 

. 

syntax: 
erfc (<expression>) 

 
examples: 
 
erfc(xx);  
 
  - erf(xx) + 1 
 
The operator erfc  is simplified towards the erf  operator. 

#$+ KEI				operator

The Ei  operator returns the Exponential Integral function. 

syntax: 
Ei (<expression>) 

 
examples: 
 
df(ei(x),x);  
 
   x 
  e 
  --- 
  x 

on rounded;  
 
Ei(0.35);  
 
  - 0.0894340019184 
 
The numeric values for the operator Ei  are computed via the power series representation, which limits the argument range. 

#$+ KFRESNEL_C				operator

 The Fresnel_C  operator represents Fresnel's Cosine function. 

syntax: 
Fresnel_C (<expression>) 

 
examples: 
 
int(cos(t^2*pi/2),t,0,x);  
 
  fresnel_c(x)  

on rounded;  
 
fresnel_c(2.1);  
 
  0.581564135061 
 
The operator Fresnel_C  has a limited numeric evaluation of large values of its argument. 

#$+ KFRESNEL_S				operator

 The Fresnel_S  operator represents Fresnel's Sine Integral function. 

syntax: 
Fresnel_S (<expression>) 

 
examples: 
 
int(sin(t^2*pi/2),t,0,x);  
 
  fresnel_s(x)  

on rounded;  
 
fresnel_s(2.1);  
 
  0.374273359378 
 
The operator Fresnel_S  has a limited numeric evaluation of large values of its argument. 

#$+Integral Functions

	Si operator
	Shi operator
	s_i operator
	Ci operator
	Chi operator
	ERF extended operator
	erfc operator
	Ei operator
	Fresnel_C operator
	Fresnel_S operator

#$+ KBINOMIAL				operator

 The Binomial  operator returns the Binomial coefficient if both parameter are integer and expressions involving the Gamma function otherwise. 

syntax: 
Binomial (<integer>,<integer>) 

 
examples: 
 
Binomial(49,6);  
 
  13983816  

 
Binomial(n,3);  
 
   gamma(n + 1) 
  --------------- 
  6*gamma(n - 2) 
 
The operator Binomial  evaluates the Binomial coefficients from the explicit form and therefore it is not the best algorithm if you want to compute many binomial coefficients with big indices in which case a recursive algorithm is preferable. 

#$+ KSTIRLING1				operator

 The Stirling1  operator returns the Stirling Numbers S(n,m) of the first kind, i.e. the number of permutations of n symbols which have exactly m cycles (divided by (-1)**(n-m)). 

syntax: 
Stirling1 (<integer>,<integer>) 

 
examples: 
 
Stirling1 (17,4);  
 
  -87077748875904  

Stirling1 (n,n-1);  
 
  -gamma(n+1) 
  ------------- 
  2*gamma(n-1) 
 
The operator Stirling1  evaluates the Stirling numbers of the first kind by rulesets for special cases or by a computing the closed form, which is a series involving the operators BINOMIAL  and STIRLING2 . 

#$+ KSTIRLING2				operator

 The Stirling1  operator returns the Stirling Numbers S(n,m) of the second kind, i.e. the number of ways of partitioning a set of n elements into m non-empty subsets. 

syntax: 
Stirling2 (<integer>,<integer>) 

 
examples: 
 
Stirling2 (17,4);  
 
  694337290  

Stirling2 (n,n-1);  
 
   gamma(n+1) 
  ------------- 
  2*gamma(n-1) 
 
The operator Stirling2  evaluates the Stirling numbers of the second kind by rulesets for special cases or by a computing the closed form. 

#$+Combinatorial Operators

	BINOMIAL operator
	STIRLING1 operator
	STIRLING2 operator

#$+ KTHREEJSYMBOL				operator

 The ThreejSymbol  operator implements the 3j symbol. 

syntax: 
ThreejSymbol (<list of j1,m1>,<list of j2,m2>, <list of j3,m3>) 

 
examples: 

ThreejSymbol({j+1,m},{j+1,-m},{1,0});  

        j 
  ( - 1)  *(abs(j - m + 1) - abs(j + m + 1)) 
  ------------------------------------------- 
             3       2                    m 
   2*sqrt(2*j   + 9*j   + 13*j + 6)*( - 1) 

#$+ KCLEBSCH_GORDAN				operator

 The Clebsch_Gordan  operator implements the Clebsch_Gordan coefficients. This is closely related to the Threejsymbol . 

syntax: 
Clebsch_Gordan (<list of j1,m1>,<list of j2,m2>, <list of j3,m3>) 

 
examples: 
 
 Clebsch_Gordan({2,0},{2,0},{2,0});  

     -2 
  --------- 
  sqrt(14) 

#$+ KSIXJSYMBOL				operator

 The SixjSymbol  operator implements the 6j symbol.  
syntax: 

SixjSymbol (<list of j1,j2,j3>,<list of l1,l2,l3>) 

 
examples: 

SixjSymbol({7,6,3},{2,4,6});  
 
       1 
  ------------- 
  14*sqrt(858) 
 
The operator SixjSymbol  uses the ineq  package in order to find minima and maxima for the summation index. 

#$+3j and  6j symbols

	ThreejSymbol operator
	Clebsch_Gordan operator
	SixjSymbol operator

#$+ KHYPERGEOMETRIC				operator

The Hypergeometric  operator provides simplifications for the generalized hypergeometric functions. The Hypergeometric  operator is included in the package specfn2. 

syntax: 
hypergeometric (<list of parameters>,<list of parameters>,  <argument>) 

 
examples: 
 
load specfn2; 
 
hypergeometric ({1/2,1},{3/2},-x^2);  

  atan(x) 
  -------- 
     x 

hypergeometric ({},{},z);  
 
   z 
  e 
 
The special case where the length of the first list is equal to 2 and the length of the second list is equal to 1 is often called ``the hypergeometric function'' (notated as 2F1(a1,a2,b;x)). 

#$+ KMEIJERG				operator

 The MeijerG  operator provides simplifications for Meijer's G function. The simplifications are performed towards polynomials, elementary or special functions or (generalized) hypergeometric  functions. 

The MeijerG  operator is included in the package specfn2. 

syntax: 
MeijerG (<list of parameters>,<list of parameters>,  <argument>) 

The first element of the lists has to be the list containing the first group (mostly called ``m'' and ``n'') of parameters. This passes the four parameters of a Meijer's G function implicitly via the length of the lists. 

examples: 
 
load specfn2; 
 
MeijerG({{},1},{{0}},x);  
 
  heaviside(-x+1) 

MeijerG({{}},{{1+1/4},1-1/4},(x^2)/4) * sqrt pi; 

 
                  2 
  sqrt(2)*sin(x)*x 
  ------------------ 
      4*sqrt(x) 
 
Many well-known functions can be written as G functions, e.g. exponentials, logarithms, trigonometric functions, Bessel functions and hypergeometric functions. The formulae can be found e.g. in 

A.P.Prudnikov, Yu.A.Brychkov, O.I.Marichev: Integrals and Series, Volume 3: More special functions, Gordon and Breach Science Publishers (1990). 

#$+ KHEAVISIDE				operator

The Heaviside  operator returns the Heaviside function. 

Heaviside(~w) => if (w < 0) then 0 else 1 

when numberp w; 

syntax: 
Heaviside (<argument>) 

This operator is often included in the result of the simplification of a generalized hypergeometric  function or a MeijerG  function. 

No simplification is done for this function. 

#$+ KERFI				operator

The erfi  operator returns the error function of an imaginary argument. 

erfi(~x) => 2/sqrt(pi) * defint(e**(t**2),t,0,x); 

syntax: 
erfi (<argument>) 

This operator is sometimes included in the result of the simplification of a generalized hypergeometric  function or a MeijerG  function. 

No simplification is done for this function. 

#$+Miscellaneous

	HYPERGEOMETRIC operator
	MeijerG operator
	Heaviside operator
	erfi operator

#$+Special Functions

	Special Function Package introduction
	Constants concept
	Bernoulli Euler Zeta
	Bessel Functions
	Airy Functions
	Jacobi's Elliptic Functions and Elliptic Integrals
	Gamma and Related Functions
	Miscellaneous Functions
	Orthogonal Polynomials
	Integral Functions
	Combinatorial Operators
	3j and  6j symbols
	Miscellaneous

#$+ KTAYLOR				introduction

 This short note describes a package of REDUCE procedures that allow Taylor expansion in one or more variables and efficient manipulation of the resulting Taylor series. Capabilities include basic operations (addition, subtraction, multiplication and division) and also application of certain algebraic and transcendental functions. To a certain extent, Laurent expansion can be performed as well. 

#$+ KTAYLOR				operator

  The taylor  operator is used for expanding an expression into a  Taylor series. 

syntax: 
taylor (<expression>  , <var>,   <expression>, <number> 

{, <var>,   <expression>, <number>}*)  

<expression> can be any valid REDUCE algebraic expression.  <var> must be a kernel , and is the expansion  variable. The <expression> following it denotes the point  about which the expansion is to take place. <number> must be a  non-negative integer and denotes the maximum expansion order. If  more than one triple is specified taylor  will expand its  first argument independently with respect to all the variables.  Note that once the expansion has been done it is not possible to  calculate higher orders. 

Instead of a kernel , <var> may also be a list of  kernels. In this case expansion will take place in a way so that  the sum/ of the degrees of the kernels does not exceed the  maximum expansion order. If the expansion point evaluates to the  special identifier infinity , taylor  tries to expand in  a series in 1/<var>. 

The expansion is performed variable per variable, i.e. in the  example above by first expanding  exp(x^2+y^2)  with respect to  x  and then expanding every coefficient with respect to y . 

examples: 
 
    taylor(e^(x^2+y^2),x,0,2,y,0,2);  

       2    2    2  2      2  2 
  1 + Y  + X  + Y *X  + O(X ,Y )    

    taylor(e^(x^2+y^2),{x,y},0,2);  

       2    2       2  2 
  1 + Y  + X  + O({X ,Y }) 
 
The following example shows the case of a non-analytical function. 
 
    taylor(x*y/(x+y),x,0,2,y,0,2);  

  ***** Not a unit in argument to QUOTTAYLOR  

Note that it is not generally possible to apply the standard  reduce operators to a Taylor kernel. For example, part ,  coeff , or coeffn  cannot be used. Instead, the  expression at hand has to be converted to standard form first  using the taylortostandard  operator. 

Differentiation of a Taylor expression is possible. If you  differentiate with respect to one of the Taylor variables the  order will decrease by one. 

Substitution is a bit restricted: Taylor variables can only be  replaced by other kernels. There is one exception to this rule:  you can always substitute a Taylor variable by an expression that  evaluates to a constant. Note that REDUCE will not always be able  to determine that an expression is constant: an example is  sin(acos(4)). 

Only simple taylor kernels can be integrated. More complicated  expressions that contain Taylor kernels as parts of themselves are  automatically converted into a standard representation by means of  the taylortostandard  operator. In this case a suitable  warning is printed. 

#$+ KTAYLORAUTOCOMBINE				switch

  If you set taylorautocombine  to on , REDUCE  automatically combines Taylor expressions during the simplification  process. This is equivalent to applying taylorcombine  to  every expression that contains Taylor kernels. Default is  on . 

#$+ KTAYLORAUTOEXPAND				switch

  taylorautoexpand  makes Taylor expressions ``contagious'' in  the sense that taylorcombine  tries to Taylor expand all  non-Taylor subexpressions and to combine the result with the rest.  Default is off . 

#$+ KTAYLORCOMBINE				operator

  This operator tries to combine all Taylor kernels found in its  argument into one. Operations currently possible are:  

	Addition, subtraction, multiplication, and division.  
	Roots, exponentials, and logarithms.  
	Trigonometric and hyperbolic functions and their inverses.  

examples: 
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    taylorcombine log hugo;  
 
         3 
  X + O(X ) 

    taylorcombine(hugo + x);  
 
           1  2      3 
  (1 + X + -*X  + O(X )) + X 
           2 

    on taylorautoexpand;  
 
    taylorcombine(hugo + x);  
 
            1  2      3 
  1 + 2*X + -*X  + O(X )   
            2 
 
Application of unary operators like log  and atan   will nearly always succeed. For binary operations their arguments  have to be Taylor kernels with the same template. This means that  the expansion variable and the expansion point must match.  Expansion order is not so important, different order usually means  that one of them is truncated before doing the operation. 

If taylorkeeporiginal  is set to on  and if all  Taylor kernels in its argument have their original expressions  kept taylorcombine  will also combine these and store the  result as the original expression of the resulting Taylor kernel.  There is also the switch taylorautoexpand . 

There are a few restrictions to avoid mathematically undefined  expressions: it is not possible to take the logarithm of a Taylor  kernel which has no terms (i.e. is zero), or to divide by such a  beast. There are some provisions made to detect singularities  during expansion: poles that arise because the denominator has  zeros at the expansion point are detected and properly treated,  i.e. the Taylor kernel will start with a negative power. (This  is accomplished by expanding numerator and denominator separately  and combining the results.) Essential singularities of the known  functions (see above) are handled correctly.  

#$+ KTAYLORKEEPORIGINAL				switch

  taylorkeeporiginal , if set to on , forces the  taylor  and all Taylor kernel manipulation operators to  keep the original expression, i.e. the expression that was Taylor  expanded. All operations performed on the Taylor kernels are also  applied to this expression which can be recovered using the operator  taylororiginal . Default is off . 

#$+ KTAYLORORIGINAL				operator

  Recovers the original expression (the one that was expanded) from  the Taylor kernel that is given as its argument. 

syntax: 
taylororiginal (<expression>) or  taylororiginal  <simple_expression>  

 
examples: 
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    taylororiginal hugo;  
 
  ***** Taylor kernel doesn't have an original part in TAYLORORIGINAL 

    on taylorkeeporiginal;  
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    taylororiginal hugo;  
 
   X 
  E    
 
An error is signalled if the argument is not a Taylor kernel or if  the original expression was not kept, i.e. if  taylorkeeporiginal  was set off  during expansion.  

#$+ KTAYLORPRINTORDER				switch

  taylorprintorder , if set to on , causes the remainder  to be printed in big-O notation. Otherwise, three dots are printed.  Default is on . 

#$+ KTAYLORPRINTTERMS				variable

  Only a certain number of (non-zero) coefficients are printed. If  there are more, an expression of the form n terms  is printed  to indicate how many non-zero terms have been suppressed. The  number of terms printed is given by the value of the shared  algebraic variable taylorprintterms . Allowed values are  integers and the special identifier all . The latter setting  specifies that all terms are to be printed. The default setting is  5. 

examples: 
 
    taylor(e^(x^2+y^2),x,0,4,y,0,4);  

       2   1  4    2    2  2                              5  5 
  1 + Y  + -*Y  + X  + Y *X  +             (4 terms) + O(X ,Y ) 
           2 

    taylorprintterms := all;  
 
  TAYLORPRINTTERMS := ALL  

    taylor(e^(x^2+y^2),x,0,4,y,0,4);  

       2   1  4    2    2  2   1  4  2   1  4   1  2  4 
  1 + Y  + -*Y  + X  + Y *X  + -*Y *X  + -*X  + -*Y *X 
           2                   2         2      2 
     1  4  4      5  5 
   + -*Y *X  + O(X ,Y ) 
     4 

#$+ KTAYLORREVERT				operator

  taylorrevert  allows reversion of a Taylor series of a  function f, i.e., to compute the first terms of the expansion of the  inverse of f from the expansion of f. 

syntax: 
taylorrevert (<expression>,   <var>, <var>)  

The first argument must evaluate to a Taylor kernel with the second  argument being one of its expansion variables. 

examples: 
 
    taylor(u - u**2,u,0,5);  
 
       2      6 
  U - U  + O(U )  

    taylorrevert (ws,u,x);  
 
       2      3      4       5      6 
  X + X  + 2*X  + 5*X  + 14*X  + O(X )   

#$+ KTAYLORSERIESP				operator

  This operator may be used to determine if its argument is a Taylor  kernel. 

syntax: 
taylorseriesp (<expression>) or taylorseriesp   <simple_expression>  

 
examples: 
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    if taylorseriesp hugo then OK; 
 
  OK  

    if taylorseriesp(hugo + y) then OK else NO;  

  NO   
 
Note that this operator is subject to the same restrictions as,  e.g., ordp  or numberp , i.e. it may only be used in  boolean expressions in if  or let  statements.  

#$+ KTAYLORTEMPLATE				operator

  The template of a Taylor kernel, i.e. the list of all variables  with respect to which expansion took place together with expansion  point and order can be extracted using 

syntax: 
taylortemplate (<expression>) or  taylortemplate  <simple_expression>  

This returns a list of lists with the three elements  (VAR,VAR0,ORDER). An error is signalled if the argument is not a  Taylor kernel. 

examples: 
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    taylortemplate hugo;  
 
  {{X,0,2}}   

#$+ KTAYLORTOSTANDARD				operator

  This operator converts all Taylor kernels in its argument into  standard form and resimplifies the result. 

syntax: 
taylortostandard (<expression>) or  taylortostandard  <simple_expression> 

 
examples: 
 
    hugo := taylor(exp(x),x,0,2);  
 
                  1  2      3 
  HUGO := 1 + X + -*X  + O(X ) 
                  2 

    taylortostandard hugo;  
 
   2 
  X  + 2*X + 2 
  ------------   
       2 

#$+Taylor series

	TAYLOR introduction
	taylor operator
	taylorautocombine switch
	taylorautoexpand switch
	taylorcombine operator
	taylorkeeporiginal switch
	taylororiginal operator
	taylorprintorder switch
	taylorprintterms variable
	taylorrevert operator
	taylorseriesp operator
	taylortemplate operator
	taylortostandard operator

#$+ KGNUPLOT AND REDUCE				introduction

The GNUPLOT system provides easy to use graphics output for curves or surfaces which are defined by formulas and/or data sets. GNUPLOT supports a great variety of output devices such as X-windows, VGA screen, postscript, picTeX. The REDUCE GNUPLOT package lets one use the GNUPLOT graphical output directly from inside REDUCE, either for the interactive display of curves/surfaces or for the production of pictures on paper. 

Note that this package may not be supported on all system platforms. 

For a detailed description you should read the GNUPLOT system documentation, available together with the GNUPLOT installation material from several servers by anonymous FTP. 

The REDUCE developers thank the GNUPLOT people for their permission to distribute GNUPLOT together with REDUCE. 

#$+ KAXES NAMES

 Inside REDUCE the choice of variable names for a graph is completely free. For referring to the GNUPLOT axes the names X and Y for 2 dimensions, X,Y and Z for 3 dimensions are used in the usual schoolbook sense independent from the variables of the REDUCE expression. 

examples: 

#$+ KPOINTSET				type

A curve can be give as set of precomputed points (a polygon) in 2 or 3 dimensions. Such a point set is a list  of points, where each point is a list  2 (or 3) numbers. These numbers are interpreted as (x,y)  (or x,y,z ) coordinates. All points of one set must have the same dimension. 

examples: 
Also a surface in 3d can be given by precomputed points, but only on a logically orthogonal mesh: the surface is defined by a list of curves (in 3d) which must have a uniform length. GNUPLOT then will draw an orthogonal mesh by first drawing the given lines, and second connecting the 1st point of the 1st curve with the 1st point of the 2nd curve, that one with the 1st point of the 3rd curve and so on for all curves and for all indexes. 

#$+ KPLOT				command

The command plot  is the main entry for drawing a picture from inside REDUCE. 

syntax: 
plot (<spec>,<spec>,...) 

where <spec> is a <function>, a <range> or an <option>. 

<function>: 

- an expression depending on one unknown (e.g. sin(x)  or two unknowns (e.g. sin(x+y) , 

- an equation with a function on its right-hand side and a single name on its left-hand side (e.g. z=sin(x+y)  where the name on the left-hand side specifies the dependent variable. 

- a list of functions: if in 2 dimensions the picture should have more than one curve the expressions can be given as list (e.g. {sin(x),cos(x)} ). 

- an equation with zero left or right hand side describing  an implicit curve in two dimensions (e.g. x**3+x*y**3-9x=0 ). 

- a point set: the graph can be given as point set in 2 dimensions or a pointset  or pointset list in 3 dimensions. 

<range>: 

Each dependent and independent variable can be limited to an interval by an equation where the left-hand side specifies the variable and the right-hand side defines the interval , e.g. x=( -3 .. 5) . 

If omitted the independent variables range from -10 to 10 and the dependent variable is limited only by the precision of the IEEE floating point arithmetic. 

<option>: 

An option can be an equation equating a variable and a value (in general a string), or a keyword(GNUPLOT switch). These have to be included in the gnuplot command arguments directly. Strings have to be enclosed in string quotes (see string ). Available options are: 

title : assign a heading (default: empty) 

xlabel : set label for the x axis 

ylabel : set label for the y axis 

zlabel : set label for the z axis 

terminal : select an output device 

size : rescale the picture 

view : set a viewpoint 

(no) contour : 3d: add contour lines 

(no) surface : 3d: draw surface (default: yes) 

(no) hidden3d : 3d: remove hidden lines (default: no) 

examples: 
 
plot(cos x); 
 
plot(s=sin phi,phi=(-3 .. 3)); 
 
plot(sin phi,cos phi,phi=(-3 .. 3)); 
 
plot (cos sqrt(x**2 + y**2),x=(-3 .. 3),y=(-3 .. 3),hidden3d); 
 
plot {{0,0},{0,1},{1,1},{0,0},{1,0},{0,1},{0.5,1.5},{1,1},{1,0}}; 

 
on rounded; 
 
w:=for j:=1:200 collect {1/j*sin j,1/j*cos j,j/200}$ 
 
plot w;  
Additional control of the plot  operation: plotrefine , plot_xmesh , plot_ymesh , trplot , plotkeep , show_grid . 

#$+ KPLOTRESET				command

 The command plotreset  closes the current GNUPLOT windows. The next call to plot  will create a new one. plotreset  can also be used to reset the system status after technical problems. 

syntax: 
plotreset ; 

#$+ KTITLE				variable

plot option: Assign a title to the GNUPLOT graph. 

syntax: 
title = <string> 

 
examples: 
 
title="annual revenue in 1993" 

#$+ KXLABEL				variable

plot option: Assign a name to to the x axis (see axes names ). 

syntax: 
xlabel = <string> 

 
examples: 
 
xlabel="month" 

#$+ KYLABEL				variable

plot option: Assign a name to to the x axis (see axes names ). 

syntax: 
ylabel = <string> 

 
examples: 
 
ylabel="million forint" 

#$+ KZLABEL				variable

plot option: Assign a name to to the z axis (see axes names ). 

syntax: 
zlabel = <string> 

 
examples: 
 
zlabel="local weight" 

#$+ KTERMINAL				variable

plot option: Select a different output device. The possible values here depend highly on the facilities installed for your GNUPLOT software. 

syntax: 
terminal = <string> 

 
examples: 
 
terminal="x11" 

#$+ KSIZE				variable

plot option: Rescale the graph (not the window!) in x and y direction. Default is 1.0 (no rescaling). 

syntax: 
size = "<sx>,<sy>" 

where <sx>,<sy> are floating point number not too far from 1.0.  
examples: 
 
size="0.7,1" 

#$+ KVIEW				variable

plot option: Set a new viewpoint by turning the object around the x and then around the z axis (see axes names ). 

syntax: 
view = "<sx>,<sz>" 

where <sx>,<sz> are floating point number representing angles in degrees.  
examples: 
 
view="30,130" 

#$+ KCONTOUR				switch

plot option: If contour  is member of the options for a 3d plot  contour lines are projected to the z=0 plane (see axes names ). The absence of contour lines can be selected explicitly by including nocontour . Default is nocontour . 

#$+ KSURFACE				switch

plot option: If surface  is member of the options for a 3d plot  the surface is drawn. The absence of the surface plotting can be selected by including nosurface , e.g. if only the contour  should be visualized. Default is surface . 

#$+ KHIDDEN3D				switch

plot option: If hidden3d  is member of the options for a 3d plot  hidden lines are removed from the picture. Otherwise a surface is drawn as transparent object. Default is nohidden3d . Selecting hidden3d  increases the computing time substantially. 

#$+ KPLOTKEEP				switch

Normally all intermediate data sets are deleted after terminating a plot session. If the switch plotkeep  is set on , the data sets are kept for eventual post processing independent of REDUCE. 

#$+ KPLOTREFINE				switch

In general plot  tries to generate smooth pictures by evaluating the functions at interior points until the distances are fine enough. This can require a lot of computing time if the single function evaluation is expensive. The refinement is controlled by the switch plotrefine  which is on  by default. When you turn it off  the functions will be evaluated only at the basic points (see plot_xmesh , plot_ymesh ). 

#$+ KPLOT_XMESH				variable

The integer value of the global variable plot_xmesh  defines the number of initial function evaluations in x direction (see axes names ) for plot . For 2d graphs additional points will be used as long as plotrefine  is on . For 3d graphs this number defines also the number of mesh lines orthogonal to the x axis. 

#$+ KPLOT_YMESH				variable

The integer value of the global variable plot_ymesh  defines for 3d plot  calls the number of function evaluations in y direction (see axes names ) and the number of mesh lines orthogonal to the y axis. 

#$+ KSHOW_GRID				switch

The grid for localizing an implicitly defined curve in plot  consists of triangles. These are computed initially equally distributed over the x-y plane controlled by plot_xmesh . The grid is refined adaptively in several levels. The final grid can be visualized by setting on the switch show_grid . 

#$+ KTRPLOT				switch

In general the interaction between REDUCE and GNUPLOT is performed as silently as possible. However, sometimes it might be useful to see the GNUPLOT commands generated by REDUCE, e.g. for a postprocessing of generated data sets independent of REDUCE. When the switch trplot  is set on all GNUPLOT commands will be printed to the standard output additionally. 

#$+Gnuplot package

	GNUPLOT and REDUCE introduction
	Axes names concept
	Pointset type
	PLOT command
	PLOTRESET command
	title variable
	xlabel variable
	ylabel variable
	zlabel variable
	terminal variable
	size variable
	view variable
	contour switch
	surface switch
	hidden3d switch
	PLOTKEEP switch
	PLOTREFINE switch
	plot_xmesh variable
	plot_ymesh variable
	SHOW_GRID switch
	TRPLOT switch

#$+ KLINEAR ALGEBRA PACKAGE				introduction

This section briefly describes what's available in the Linear Algebra package. 

Note on examples: In the examples throughout this document, the matrix A will be  
     [1  2  3] 
     [4  5  6] 
     [7  8  9]. 

The functions can be divided into four categories: 

Basic matrix handling  

add_columns , 

add_rows ,  

add_to_columns ,  

add_to_rows ,  

augment_columns ,  

char_poly ,  

column_dim ,  

copy_into ,  

diagonal ,  

extend ,  

find_companion ,  

get_columns ,  

get_rows ,  

hermitian_tp ,  

matrix_augment ,  

matrix_stack ,  

minor ,  

mult_columns ,  

mult_rows , 

pivot ,  

remove_columns ,  

remove_rows ,  

row_dim ,  

rows_pivot ,  

stack_rows ,  

sub_matrix ,  

swap_columns ,  

swap_entries ,  

swap_rows . 

Constructors -- functions that create matrices  

band_matrix ,  

block_matrix ,  

char_matrix ,  

coeff_matrix ,  

companion ,  

hessian ,  

hilbert ,  

jacobian ,  

jordan_block ,  

make_identity ,  

random_matrix ,  

toeplitz ,  

vandermonde . 

High level algorithms  

char_poly ,  

cholesky ,  

gram_schmidt ,  

lu_decom ,  

pseudo_inverse ,  

simplex ,  

svd . 

Normal Forms 

There is a separate package, NORMFORM, for computing the following matrix normal forms in REDUCE: 

smithex , 

smithex_int , 

frobenius , 

ratjordan , 

jordansymbolic , 

jordan . 

Predicates 

matrixp ,  

squarep ,  

symmetricp . 

#$+ KFAST_LA				switch

By turning the fast_la  switch on, the speed of the following functions will be increased: 

add_columns ,  

add_rows ,  

augment_columns ,  

column_dim ,  

copy_into ,  

make_identity ,  

matrix_augment ,  

matrix_stack ,  

minor ,  

mult_columns ,  

mult_rows ,  

pivot ,  

remove_columns ,  

remove_rows ,  

rows_pivot ,  

squarep ,  

stack_rows ,  

sub_matrix ,  

swap_columns ,  

swap_entries ,  

swap_rows ,  

symmetricp .  

The increase in speed will be negligible unless you are making a significant number (i.e. thousands) of calls. When using this switch, error checking is minimized. This means that illegal input may give strange error messages. Beware. 

#$+ KADD_COLUMNS				operator

 Add columns, add rows:  
syntax: 

add_columns (<matrix>,<c1>,<c2>,<expr>) 

<matrix> :- a matrix . 

<c1>,<c2> :- positive integers. 

<expr> :- a scalar expression. 

The Operator add_columns  replaces column <{c2>} of <matrix> by <expr> * column(<matrix>,<c1>) + column(<matrix>,<c2>). 

add_rows performs the equivalent task on the rows of <matrix>. 

examples: 

add_columns(A,1,2,x);  
 
  [1   x + 2   3] 
  [             ] 
  [4  4*x + 5  6] 
  [             ] 
  [7  7*x + 8  9] 

 
add_rows(A,2,3,5);  
 
  [1   2   3 ] 
  [          ] 
  [4   5   6 ] 
  [          ] 
  [27  33  39] 
 
Related functions: add_to_columns , add_to_rows , mult_columns , mult_rows . 

#$+ KADD_ROWS				operator

  see: add_columns . 

#$+ KADD_TO_COLUMNS				operator

 Add to columns, add to rows: 

syntax: 
add_to_columns (<matrix>,<column‑list>,<expr>) 

<matrix> :- a matrix. 

<column‑list> :- a positive integer or a list of positive  integers. 

<expr> :- a scalar expression. 

add_to_columns adds <expr> to each column specified in <column‑list> of <matrix>. 

add_to_rows performs the equivalent task on the rows of <matrix>. 

examples: 

add_to_columns(A,{1,2},10);  
 
  [11  12  3] 
  [         ] 
  [14  15  6] 
  [         ] 
  [17  18  9] 

 
add_to_rows(A,2,-x)  

  [   1         2         3    ] 
  [                            ] 
  [ - x + 4   - x + 5   - x + 6] 
  [                            ] 
  [   7         8         9    ] 
 
Related functions: add_columns , add_rows , mult_rows , mult_columns . 

#$+ KADD_TO_ROWS				operator

  see: add_to_columns . 

#$+ KAUGMENT_COLUMNS				operator

 Augment columns, stack rows: 

syntax: 
augment_columns (<matrix>,<column‑list>) 

<matrix> :- a matrix. 

<column‑list> :- either a positive integer or a list of positive  integers. 

augment_columns gets hold of the columns of <matrix> specified in column_list  and sticks them together. 

stack_rows performs the same task on rows of <matrix>. 

examples: 

augment_columns(A,{1,2})  

  [1  2] 
  [    ] 
  [4  5] 
  [    ] 
  [7  8] 

 
stack_rows(A,{1,3})  
 
  [1  2  3] 
  [       ] 
  [7  8  9] 
 
Related functions: get_columns , get_rows , sub_matrix . 

#$+ KBAND_MATRIX				operator

 
syntax: 
band_matrix (<expr‑list>,<square‑size>) 

<expr‑list> :- either a single scalar expression or a list of  an odd number of scalar expressions. 

<square‑size> :- a positive integer. 

band_matrix creates a square matrix of dimension <square‑size>. The diagonal consists of the middle expression of the <expr‑list>. The expressions to the left of this fill the required number of sub_diagonals and the expressions to the right the super_diagonals. 

examples: 

band_matrix({x,y,z},6)  
 
  [y  z  0  0  0  0] 
  [                ] 
  [x  y  z  0  0  0] 
  [                ] 
  [0  x  y  z  0  0] 
  [                ] 
  [0  0  x  y  z  0] 
  [                ] 
  [0  0  0  x  y  z] 
  [                ] 
  [0  0  0  0  x  y] 
 
Related functions: diagonal . 

#$+ KBLOCK_MATRIX				operator

 
syntax: 
block_matrix (<r>,<c>,<matrix‑list>) 

<r>,<c> :- positive integers. 

<matrix‑list> :- a list of matrices. 

block_matrix creates a matrix that consists of <r> by <c> matrices filled from the <matrix‑list> row wise. 

examples: 
 
B := make_identity(2);  
 
       [1  0] 
  b := [    ] 
       [0  1] 

 
C := mat((5),(5));  
 
       [5] 
  c := [ ] 
       [5] 

 
D := mat((22,33),(44,55));  
 
       [22  33] 
  d := [      ] 
       [44  55] 

 
block_matrix(2,3,{B,C,D,D,C,B});  

  [1   0   5  22  33] 
  [                 ] 
  [0   1   5  44  55] 
  [                 ] 
  [22  33  5  1   0 ] 
  [                 ] 
  [44  55  5  0   1 ] 

#$+ KCHAR_MATRIX				operator

 
syntax: 
char_matrix (<matrix>,<lambda>) 

<matrix> :- a square matrix. <lambda> :- a symbol or algebraic expression. 

<char‑matrix> creates the characteristic matrix C of <matrix>. 

This is C = <lambda> * Id - A. Id is the identity matrix. 

examples: 

char_matrix(A,x);  
 
  [x - 1   -2     -3  ] 
  [                   ] 
  [ -4    x - 5   -6  ] 
  [                   ] 
  [ -7     -8    x - 9] 
 
Related functions: char_poly . 

#$+ KCHAR_POLY				operator

 
syntax: 
char_poly (<matrix>,<lambda>) 

<matrix> :- a square matrix. 

<lambda> :- a symbol or algebraic expression. 

char_poly finds the characteristic polynomial of <matrix>. This is the determinant of <lambda> * Id - A. Id is the identity matrix. 

examples: 
 
char_poly(A,x);  
 
   3     2 
  x -15*x -18*x 
 
Related functions: char_matrix . 

#$+ KCHOLESKY				operator

 
syntax: 
cholesky (<matrix>) 

<matrix> :- a positive definite matrix containing numeric entries. 

cholesky computes the cholesky decomposition of <matrix>. 

It returns {L,U} where L is a lower matrix, U is an upper matrix, A = LU, and U = L^T. 

examples: 
 
F := mat((1,1,0),(1,3,1),(0,1,1));  

       [1  1  0] 
       [       ] 
  f := [1  3  1] 
       [       ] 
       [0  1  1] 

 
on rounded;  
 
cholesky(F);  
 
  { 
   [1        0               0       ] 
   [                                 ] 
   [1  1.41421356237         0       ] 
   [                                 ] 
   [0  0.707106781187  0.707106781187] 
   , 
   [1        1              0       ] 
   [                                ] 
   [0  1.41421356237  0.707106781187] 
   [                                ] 
   [0        0        0.707106781187] 
  } 
 
Related functions: lu_decom . 

#$+ KCOEFF_MATRIX				operator

 
syntax: 
coeff_matrix ({<lineq‑list>}) 

(If you are feeling lazy then the braces can be omitted.) 

<lineq‑list> :- linear equations. Can be of the form equation = number or just equation. 

coeff_matrix creates the coefficient matrix C of the linear equations. 

It returns {C,X,B} such that CX = B. 

examples: 

coeff_matrix({x+y+4*z=10,y+x-z=20,x+y+4});  

  { 
   [4   1  1] 
   [        ] 
   [-1  1  1] 
   [        ] 
   [0   1  1] 
   , 
   [z] 
   [ ] 
   [y] 
   [ ] 
   [x] 
   , 
   [10] 
   [  ] 
   [20] 
   [  ] 
   [-4] 
  } 

#$+ KCOLUMN_DIM				operator

 Column dimension, row dimension: 

syntax: 
column_dim (<matrix>) 

<matrix> :- a matrix. 

column_dim finds the column dimension of <matrix>. 

row_dim finds the row dimension of <matrix>. 

examples: 

column_dim(A);  
 
  3  

row_dim(A);  
 
  3  

#$+ KCOMPANION				operator

 
syntax: 
companion (<poly>,<x>) 

<poly> :- a monic univariate polynomial in <x>. 

<x> :- the variable. 

companion creates the companion matrix C of <poly>. 

This is the square matrix of dimension n, where n is the degree of <poly> w.r.t. <x>. 

The entries of C are: 

C(i,n) = -coeffn(<poly>,<x>,i-1) for i = 1  ... n, C(i,i-1) = 1 for i = 2 ... n and  the rest are 0. 

examples: 

companion(x^4+17*x^3-9*x^2+11,x);  

  [0  0  0  -11] 
  [            ] 
  [1  0  0   0 ] 
  [            ] 
  [0  1  0   9 ] 
  [            ] 
  [0  0  1  -17] 
 
Related functions: find_companion . 

#$+ KCOPY_INTO				operator

 
syntax: 
copy_into (<A>,<B>,<r>,<c>) 

<A>,<B> :- matrices. 

<r>,<c> :- positive integers. 

copy_into copies matrix <matrix> into <B> with <matrix>(1,1) at <B>(<r>,<c>). 

examples: 

G := mat((0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0));  

       [0  0  0  0  0] 
       [             ] 
       [0  0  0  0  0] 
       [             ] 
  g := [0  0  0  0  0] 
       [             ] 
       [0  0  0  0  0] 
       [             ] 
       [0  0  0  0  0] 

 
copy_into(A,G,1,2);  
 
  [0  1  2  3  0] 
  [             ] 
  [0  4  5  6  0] 
  [             ] 
  [0  7  8  9  0] 
  [             ] 
  [0  0  0  0  0] 
  [             ] 
  [0  0  0  0  0] 
 
Related functions: augment_columns , extend , matrix_augment , matrix_stack , stack_rows , sub_matrix . 

#$+ KDIAGONAL				operator

 
syntax: 
diagonal ({<mat‑list>}) 

(If you are feeling lazy then the braces can be omitted.) 

<mat‑list> :- each can be either a scalar expression or a square matrix . 

diagonal creates a matrix that contains the input on the diagonal. 

examples: 

H := mat((66,77),(88,99));  
 
       [66  77] 
  h := [      ] 
       [88  99] 

 
diagonal({A,x,H});  
 
  [1  2  3  0  0   0 ] 
  [                  ] 
  [4  5  6  0  0   0 ] 
  [                  ] 
  [7  8  9  0  0   0 ] 
  [                  ] 
  [0  0  0  x  0   0 ] 
  [                  ] 
  [0  0  0  0  66  77] 
  [                  ] 
  [0  0  0  0  88  99] 
 
Related functions: jordan_block . 

#$+ KEXTEND				operator

 
syntax: 
extend (<matrix>,<r>,<c>,<expr>) 

<matrix> :- a matrix . 

<r>,<c> :- positive integers. 

<expr> :- algebraic expression or symbol. 

extend returns a copy of <matrix> that has been extended by <r> rows and <c> columns. The new entries are made equal to <expr>. 

examples: 

extend(A,1,2,x);  
 
  [1  2  3  x  x] 
  [             ] 
  [4  5  6  x  x] 
  [             ] 
  [7  8  9  x  x] 
  [             ] 
  [x  x  x  x  x] 
 
Related functions: copy_into , matrix_augment , matrix_stack , remove_columns , remove_rows . 

#$+ KFIND_COMPANION				operator

 
syntax: 
find_companion (<matrix>,<x>) 

<matrix> :- a matrix . 

<x> :- the variable. 

Given a companion matrix, find_companion  finds the polynomial from which it was made. 

examples: 

C := companion(x^4+17*x^3-9*x^2+11,x);  

       [0  0  0  -11] 
       [            ] 
       [1  0  0   0 ] 
  c := [            ] 
       [0  1  0   9 ] 
       [            ] 
       [0  0  1  -17] 

 
find_companion(C,x);  
 
   4     3    2 
  x +17*x -9*x +11 
 
Related functions: companion . 

#$+ KGET_COLUMNS				operator

 Get columns, get rows: 

syntax: 
get_columns (<matrix>,<column‑list>) 

<matrix> :- a matrix . 

<c> :- either a positive integer or a list of positive  integers. 

get_columns removes the columns of <matrix> specified in <column‑list> and returns them as a list of column matrices. 

get_rows performs the same task on the rows of <matrix>. 

examples: 

get_columns(A,{1,3});  
 
  { 
   [1] 
   [ ] 
   [4] 
   [ ] 
   [7] 
   , 
   [3] 
   [ ] 
   [6] 
   [ ] 
   [9] 
  } 

 
get_rows(A,2);  
 
  { 
   [4  5  6] 
  } 
 
Related functions: augment_columns , stack_rows , sub_matrix . 

#$+ KGET_ROWS				operator

 see: get_columns . 

#$+ KGRAM_SCHMIDT				operator

 
syntax: 
gram_schmidt ({<vec‑list>}) 

(If you are feeling lazy then the braces can be omitted.) 

<vec‑list> :- linearly independent vectors. Each vector must be written as a list, eg:{1,0,0}. 

gram_schmidt performs the gram_schmidt orthonormalization on the input vectors. 

It returns a list of orthogonal normalized vectors. 

examples: 

gram_schmidt({{1,0,0},{1,1,0},{1,1,1}});  

  {{1,0,0},{0,1,0},{0,0,1}}  

 
gram_schmidt({{1,2},{3,4}});  

        1         2        2*sqrt(5)   -sqrt(5) 
  {{ ------- , ------- },{ --------- , -------- }} 
     sqrt(5)   sqrt(5)         5          5 

#$+ KHERMITIAN_TP				operator

 
syntax: 
 hermitian_tp (<matrix>) 

<matrix> :- a matrix . 

hermitian_tp computes the hermitian transpose of <matrix>. 

This is a matrix  in which the (i,j)'th entry is the conjugate of the (j,i)'th entry of <matrix>. 

examples: 

J := mat((i+1,i+2,i+3),(4,5,2),(1,i,0));  

       [i + 1  i + 2  i + 3] 
       [                   ] 
  j := [  4      5      2  ] 
       [                   ] 
       [  1      i      0  ] 

 
hermitian_tp(j);  
 
  [ - i + 1  4   1  ] 
  [                 ] 
  [ - i + 2  5   - i] 
  [                 ] 
  [ - i + 3  2   0  ] 
 
Related functions: tp . 

#$+ KHESSIAN				operator

 
syntax: 
hessian (<expr>,<variable‑list>) 

<expr> :- a scalar expression. 

<variable‑list> :- either a single variable or a list of  variables. 

hessian computes the hessian matrix of <expr> w.r.t. the variables in <variable‑list>. 

This is an n by n matrix where n is the number of variables and the (i,j)'th entry is df (<expr>,<variable‑list>(i), <variable‑list>(j)). 

examples: 

hessian(x*y*z+x^2,{w,x,y,z});  
 
  [0  0  0  0] 
  [          ] 
  [0  2  z  y] 
  [          ] 
  [0  z  0  x] 
  [          ] 
  [0  y  x  0] 
 
Related functions: df . 

#$+ KHILBERT				operator

 
syntax: 
hilbert (<square‑size>,<expr>) 

<square‑size> :- a positive integer. 

<expr> :- an algebraic expression. 

hilbert computes the square hilbert matrix of dimension <square‑size>. 

This is the symmetric matrix in which the (i,j)'th entry is 1/(i+j-<expr>). 

examples: 

hilbert(3,y+x);  
 
  [    - 1          - 1          - 1    ] 
  [-----------  -----------  -----------] 
  [ x + y - 2    x + y - 3    x + y - 4 ] 
  [                                     ] 
  [    - 1          - 1          - 1    ] 
  [-----------  -----------  -----------] 
  [ x + y - 3    x + y - 4    x + y - 5 ] 
  [                                     ] 
  [    - 1          - 1          - 1    ] 
  [-----------  -----------  -----------] 
  [ x + y - 4    x + y - 5    x + y - 6 ] 

#$+ KJACOBIAN				operator

 
syntax: 
jacobian (<expr‑list>,<variable‑list>) 

<expr‑list> :- either a single algebraic expression or a list  of algebraic expressions. 

<variable‑list> :- either a single variable or a list of  variables. 

jacobian computes the jacobian matrix of <expr‑list> w.r.t. <variable‑list>. 

This is a matrix whose (i,j)'th entry is df (<expr‑list> (i),<variable‑list>(j)). 

The matrix is n by m where n is the number of variables and m the number of expressions. 

examples: 

jacobian({x^4,x*y^2,x*y*z^3},{w,x,y,z});  

  [      3                 ] 
  [0  4*x     0       0    ] 
  [                        ] 
  [     2                  ] 
  [0   y    2*x*y     0    ] 
  [                        ] 
  [      3     3          2] 
  [0  y*z   x*z    3*x*y*z ] 
 
Related functions: hessian , df . 

#$+ KJORDAN_BLOCK				operator

 
syntax: 
jordan_block (<expr>,<square‑size>) 

<expr> :- an algebraic expression or symbol. 

<square‑size> :- a positive integer. 

jordan_block computes the square jordan block matrix J of dimension <square‑size>. 

The entries of J are: 

J(i,i) = <expr> for i=1  ... n, J(i,i+1) = 1 for i=1  ... n-1, and all other entries are 0. 

examples: 

jordan‑block(x,5);  
 
  [x  1  0  0  0] 
  [             ] 
  [0  x  1  0  0] 
  [             ] 
  [0  0  x  1  0] 
  [             ] 
  [0  0  0  x  1] 
  [             ] 
  [0  0  0  0  x] 
 
Related functions: diagonal , companion . 

#$+ KLU_DECOM				operator

 
syntax: 
lu_decom (<matrix>) 

<matrix> :- a matrix  containing either numeric entries  or imaginary entries with numeric coefficients. 

lu_decom performs LU decomposition on <matrix>, ie: it returns {L,U} where L is a lower diagonal matrix , U an upper diagonal matrix  and A = LU. 

Caution: 

The algorithm used can swap the rows of <matrix> during the calculation. This means that LU does not equal <matrix> but a row equivalent of it. Due to this, lu_decom  returns {L,U,vec}. The call convert(meta{matrix ,vec)} will return the matrix that has been decomposed, i.e: LU = convert(<matrix>,vec). 

examples: 

K := mat((1,3,5),(-4,3,7),(8,6,4));  

       [1   3  5] 
       [        ] 
  k := [-4  3  7] 
       [        ] 
       [8   6  4] 

 
on rounded; 
 
lu :=  lu_decom(K);  
 
  lu := { 
         [8    0      0  ] 
         [               ] 
         [-4  6.0     0  ] 
         [               ] 
         [1   2.25  1.125] 
         , 
         [1  0.75  0.5] 
         [            ] 
         [0   1    1.5] 
         [            ] 
         [0   0     1 ] 
         , 
         [3 2 3]} 

 
first lu * second lu;  
 
  [8   6.0  4.0] 
  [            ] 
  [-4  3.0  7.0] 
  [            ] 
  [1   3.0  5.0] 

 
convert(K,third lu);  
 
  P := mat((i+1,i+2,i+3),(4,5,2),(1,i,0)); 	 
       [i + 1  i + 2  i + 3] 
       [                   ] 
  p := [  4      5      2  ] 
       [                   ] 
       [  1      i      0  ] 

lu :=  lu_decom(P);  
 
  lu := { 
         [  1        0                      0                ] 
         [                                                   ] 
         [  4     - 4*i + 5                 0                ] 
         [                                                   ] 
         [i + 1      3       0.414634146341*i + 2.26829268293] 
         , 
         [1  i                 0                ] 
         [                                      ] 
         [0  1  0.19512195122*i + 0.243902439024] 
         [                                      ] 
         [0  0                 1                ] 
         , 
         [3 2 3]} 

 
first lu * second lu;  
 
  [  1      i       0   ] 
  [                     ] 
  [  4      5      2.0  ] 
  [                     ] 
  [i + 1  i + 2  i + 3.0] 

 
convert(P,third lu);  
 
  [  1      i      0  ] 
  [                   ] 
  [  4      5      2  ] 
  [                   ] 
  [i + 1  i + 2  i + 3] 

Related functions: cholesky . 

#$+ KMAKE_IDENTITY				operator

 
syntax: 
make_identity (<square‑size>) 

<square‑size> :- a positive integer. 

make_identity creates the identity matrix of dimension <square‑size>. 

examples: 

make_identity(4);  
 
  [1  0  0  0] 
  [          ] 
  [0  1  0  0] 
  [          ] 
  [0  0  1  0] 
  [          ] 
  [0  0  0  1] 
 
Related functions: diagonal . 

#$+ KMATRIX_AUGMENT				operator

 Matrix augment, matrix stack: 

syntax: 
matrix_augment {<matrix‑list>} 

(If you are feeling lazy then the braces can be omitted.) 

<matrix‑list> :- matrices. 

matrix_augment sticks the matrices in <matrix‑list> together horizontally. 

matrix_stack sticks the matrices in <matrix‑list> together vertically. 

examples: 

matrix_augment({A,A});  
 
  [1  2  3  1  2  3] 
  [                ] 
  [4  5  6  4  5  6] 
  [                ] 
  [7  8  9  7  8  9] 

 
matrix_stack(A,A);  
 
  [1  2  3] 
  [       ] 
  [4  5  6] 
  [       ] 
  [7  8  9] 
  [       ] 
  [1  2  3] 
  [       ] 
  [4  5  6] 
  [       ] 
  [7  8  9] 
 
Related functions: augment_columns , stack_rows , sub_matrix . 

#$+ KMATRIXP				operator

 
syntax: 
matrixp (<test‑input>) 

<test‑input> :- anything you like. 

matrixp is a boolean function that returns t if the input is a matrix and nil otherwise. 

examples: 

matrixp A;  
 
  t  

matrixp(doodlesackbanana); 
 
  nil  
 
Related functions: squarep , symmetricp . 

#$+ KMATRIX_STACK				operator

 see: matrix_augment . 

#$+ KMINOR				operator

 
syntax: 
minor (<matrix>,<r>,<c>) 

<matrix> :- a matrix . <r>,<c> :- positive integers. 

minor computes the (<r>,<c>)'th minor of <matrix>. This is created by removing the <r>'th row and the <c>'th column from <matrix>. 

examples: 

minor(A,1,3);  
 
  [4  5] 
  [    ] 
  [7  8] 
 
Related functions: remove_columns , remove_rows . 

#$+ KMULT_COLUMNS				operator

 Mult columns, mult rows: 

syntax: 
mult_columns (<matrix>,<column‑list>,<expr>) 

<matrix> :- a matrix . 

<column‑list> :- a positive integer or a list of positive  integers. 

<expr> :- an algebraic expression. 

mult_columns returns a copy of <matrix> in which the columns specified in <column‑list> have been multiplied by <expr>. 

mult_rows performs the same task on the rows of <matrix>. 

examples: 

mult_columns(A,{1,3},x);  
 
  [ x   2  3*x] 
  [           ] 
  [4*x  5  6*x] 
  [           ] 
  [7*x  8  9*x] 

 
mult_rows(A,2,10);  
 
  [1   2   3 ] 
  [          ] 
  [40  50  60] 
  [          ] 
  [7   8   9 ] 
 
Related functions: add_to_columns , add_to_rows . 

#$+ KMULT_ROWS				operator

 see: mult_columns . 

#$+ KPIVOT				operator

 
syntax: 
pivot (<matrix>,<r>,<c>) 

<matrix> :- a matrix. 

<r>,<c> :- positive integers such that <matrix>(<r>,  <c>) neq 0. 

pivot pivots <matrix> about it's (<r>,<c>)'th entry.  

To do this, multiples of the <r>'th row are added to every other row in the matrix. 

This means that the <c>'th column will be 0 except for the (<r>,<c>)'th entry. 

examples: 

pivot(A,2,3);  
 
  [      - 1    ] 
  [-1  ------  0] 
  [      2      ] 
  [             ] 
  [4     5     6] 
  [             ] 
  [      1      ] 
  [1    ---    0] 
  [      2      ] 
 
Related functions: rows_pivot . 

#$+ KPSEUDO_INVERSE				operator

 
syntax: 
pseudo_inverse (<matrix>) 

<matrix> :- a matrix . 

pseudo_inverse , also known as the Moore-Penrose inverse, computes the pseudo inverse of <matrix>. 

Given the singular value decomposition of <matrix>, i.e: A = U*P*V^T, then the pseudo inverse A^-1 is defined by A^-1 = V^T*P^-1*U. 

Thus <matrix> * pseudo_inverse(A) = Id. (Id is the identity matrix). 

examples: 

R := mat((1,2,3,4),(9,8,7,6));  
 
       [1  2  3  4] 
  r := [          ] 
       [9  8  7  6] 

 
on rounded;  
 
pseudo_inverse(R);  
 
  [ - 0.199999999996      0.100000000013   ] 
  [                                        ] 
  [ - 0.0499999999988    0.0500000000037   ] 
  [                                        ] 
  [ 0.0999999999982     - 5.57825497203e-12] 
  [                                        ] 
  [  0.249999999995      - 0.0500000000148 ] 
 
Related functions: svd . 

#$+ KRANDOM_MATRIX				operator

 
syntax: 
random_matrix (<r>,<c>,<limit>) 

<r>,<c>,<limit> :- positive integers. 

random_matrix creates an <r> by <c> matrix with random entries in the range -limit < entry < limit. 

Switches: 

imaginary :- if on then matrix entries are x+i*y where -limit < x,y  < <limit>. 

not_negative :- if on then 0 < entry < <limit>. In the imaginary  case we have 0 < x,y < <limit>. 

only_integer :- if on then each entry is an integer. In the imaginary 		 case x and y are integers. 

symmetric :- if on then the matrix is symmetric. 

upper_matrix :- if on then the matrix is upper triangular. 

lower_matrix :- if on then the matrix is lower triangular. 

examples: 

on rounded;  
 
random_matrix(3,3,10);  
 
  [ - 8.11911717343    - 5.71677292768   0.620580830035 ] 
  [                                                     ] 
  [ - 0.032596262422    7.1655452861     5.86742633837  ] 
  [                                                     ] 
  [ - 9.37155438255    - 7.55636708637   - 8.88618627557] 

 
on only_integer, not_negative, upper_matrix, imaginary;  
 
random_matrix(4,4,10);  
 
  [70*i + 15  28*i + 8   2*i + 79   27*i + 44] 
  [                                          ] 
  [    0      46*i + 95  9*i + 63   95*i + 50] 
  [                                          ] 
  [    0          0      31*i + 75  14*i + 65] 
  [                                          ] 
  [    0          0          0      5*i + 52 ] 

#$+ KREMOVE_COLUMNS				operator

 Remove columns, remove rows: 

syntax: 
remove_columns (<matrix>,<column‑list>) 

<matrix> :- a matrix . <column‑list> :- either a positive integer or a list of positive  integers. 

remove_columns removes the columns specified in <column‑list> from <matrix>. 

remove_rows performs the same task on the rows of <matrix>. 

examples: 

remove_columns(A,2);  
 
  [1  3] 
  [    ] 
  [4  6] 
  [    ] 
  [7  9] 

 
remove_rows(A,{1,3});  
 
  [4  5  6] 
 
Related functions: minor . 

#$+ KREMOVE_ROWS				operator

 see: remove_columns . 

#$+ KROW_DIM				operator

 see: column_dim . 

#$+ KROWS_PIVOT				operator

 
syntax: 
rows_pivot (<matrix>,<r>,<c>,{<row‑list>}) 

<matrix> :- a namerefmatrix. 

<r>,<c> :- positive integers such that <matrix>(<r>,  <c>) neq 0. 

<row‑list> :- positive integer or a list of positive integers. 

rows_pivot performs the same task as pivot  but applies the pivot only to the rows specified in <row‑list>. 

examples: 

N := mat((1,2,3),(4,5,6),(7,8,9),(1,2,3),(4,5,6));  

       [1  2  3] 
       [       ] 
       [4  5  6] 
       [       ] 
  n := [7  8  9] 
       [       ] 
       [1  2  3] 
       [       ] 
       [4  5  6] 

 
rows_pivot(N,2,3,{4,5});  
 
  [1     2     3] 
  [             ] 
  [4     5     6] 
  [             ] 
  [7     8     9] 
  [             ] 
  [      - 1    ] 
  [-1  ------  0] 
  [      2      ] 
  [             ] 
  [0     0     0] 
 
Related functions: pivot . 

#$+ KSIMPLEX				operator

 
syntax: 
simplex (<max/min>,<objective function>, {<linear inequalities>}) 

<max/min> :- either max or min (signifying maximize and 			 minimize). 

<objective function> :- the function you are maximizing or 			 minimizing. 

<linear inequalities> :- the constraint inequalities. Each one must  be of the form sum of variables (  <=,=,>=) number. 

simplex applies the revised simplex algorithm to find the optimal(either maximum or minimum) value of the <objective function> under the linear inequality constraints. 

It returns {optimal value,{ values of variables at this optimal}}. 

The algorithm implies that all the variables are non-negative. 

examples: 

 simplex(max,x+y,{x>=10,y>=20,x+y<=25});  

   ***** Error in simplex: Problem has no feasible solution 

 
simplex(max,10x+5y+5.5z,{5x+3z<=200,x+0.1y+0.5z<=12, 
0.1x+0.2y+0.3z<=9, 30x+10y+50z<=1500});  

  {525.0,{x=40.0,y=25.0,z=0}} 

#$+ KSQUAREP				operator

 
syntax: 
squarep (<matrix>) 

<matrix> :- a matrix . 

squarep is a predicate that returns t if the <matrix> is square and nil otherwise. 

examples: 

squarep(mat((1,3,5)));  
 
  nil  

squarep(A); 
t 
Related functions: matrixp , symmetricp . 

#$+ KSTACK_ROWS				operator

 see: augment_columns . 

#$+ KSUB_MATRIX				operator

 
syntax: 
sub_matrix (<matrix>,<row‑list>,<column‑list>) 

<matrix> :- a matrix. <row‑list>, <column‑list> :- either a positive integer or a  list of positive integers. 

namesub_matrix produces the matrix consisting of the intersection of the rows specified in <row‑list> and the columns specified in <column‑list>. 

examples: 

sub_matrix(A,{1,3},{2,3});  
 
  [2  3] 
  [    ] 
  [8  9] 
 
Related functions: augment_columns , stack_rows . 

#$+ KSVD				operator

Singular value decomposition: 

syntax: 
svd (<matrix>) 

<matrix> :- a matrix  containing only numeric entries. 

svd computes the singular value decomposition of <matrix>. 

It returns 

{U,P,V} 

where A = U*P*V^T 

and P = diag(sigma(1) ... sigma(n)). 

sigma(i) for i= 1 ... n are the singular values of <matrix>. 

n is the column dimension of <matrix>. 

The singular values of <matrix> are the non-negative square roots of the eigenvalues of A^T*A. 

U and V are such that U*U^T = V*V^T = V^T*V = Id. Id is the identity matrix. 

examples: 

Q := mat((1,3),(-4,3));  
 
       [1   3] 
  q := [     ] 
       [-4  3] 

 
on rounded;  
 
svd(Q);  
 
  { 
   [ 0.289784137735    0.957092029805] 
   [                                 ] 
   [ - 0.957092029805  0.289784137735] 
   , 
   [5.1491628629       0      ] 
   [                          ] 
   [     0        2.9130948854] 
   , 
   [ - 0.687215403194   0.726453707825  ] 
   [                                    ] 
   [ - 0.726453707825   - 0.687215403194] 
  } 

#$+ KSWAP_COLUMNS				operator

 Swap columns, swap rows: 

syntax: 
swap_columns (<matrix>,<c1>,<c2>) 

<matrix> :- a matrix . 

<c1>,<c1> :- positive integers.  

swap_columns swaps column <c1> of <matrix> with column <c2>. 

swap_rows performs the same task on two rows of <matrix>. 

examples: 

swap_columns(A,2,3);  
 
  [1  3  2] 
  [       ] 
  [4  6  5] 
  [       ] 
  [7  9  8] 

 
swap_rows(A,1,3);  
 
  [7  8  9] 
  [       ] 
  [4  5  6] 
  [       ] 
  [1  2  3] 
 
Related functions: swap_entries . 

#$+ KSWAP_ENTRIES				operator

 
syntax: 
swap_entries (<matrix>,{<r1>,<c1>},{<r2>, <c2>}) 

<matrix> :- a matrix . 

<r1>,<c1>,<r2>,<c2> :- positive integers. 

swap_entries swaps <matrix>(<r1>,<c1>) with <matrix>(<r2>,<c2>). 

examples: 

swap_entries(A,{1,1},{3,3});  
 
  [9  2  3] 
  [       ] 
  [4  5  6] 
  [       ] 
  [7  8  1] 
 
Related functions: swap_columns , swap_rows . 

#$+ KSWAP_ROWS				operator

 see: swap_columns . 

#$+ KSYMMETRICP				operator

 
syntax: 
symmetricp (<matrix>) 

<matrix> :- a matrix . 

symmetricp is a predicate that returns t if the matrix is symmetric and nil otherwise. 

examples: 

symmetricp(make_identity(11));  
 
  t  

symmetricp(A);  
 
  nil 
 
Related functions: matrixp , squarep . 

#$+ KTOEPLITZ				operator

 
syntax: 
toeplitz (<expr‑list>) 

(If you are feeling lazy then the braces can be omitted.) 

<expr‑list> :- list of algebraic expressions. 

toeplitz creates the toeplitz matrix from the <expr‑list>. 

This is a square symmetric matrix in which the first expression is placed on the diagonal and the i'th expression is placed on the (i-1)'th sub and super diagonals. 

It has dimension n where n is the number of expressions. 

examples: 

toeplitz({w,x,y,z});  
 
  [w  x  y  z] 
  [          ] 
  [x  w  x  y] 
  [          ] 
  [y  x  w  x] 
  [          ] 
  [z  y  x  w] 

#$+ KVANDERMONDE				operator

 
syntax: 
vandermonde ({<expr‑list>}) 

(If you are feeling lazy then the braces can be omitted.) 

<expr‑list> :- list of algebraic expressions. 

vandermonde creates the vandermonde matrix from the <expr‑list>. 

This is the square matrix in which the (i,j)'th entry is <expr‑list>(i)^(j-1). 

It has dimension n where n is the number of expressions. 

examples: 
              
vandermonde({x,2*y,3*z});  

  [          2 ] 
  [1   x    x  ] 
  [            ] 
  [           2] 
  [1  2*y  4*y ] 
  [            ] 
  [           2] 
  [1  3*z  9*z ] 

#$+Linear Algebra package

	Linear Algebra package introduction
	fast_la switch
	add_columns operator
	add_rows operator
	add_to_columns operator
	add_to_rows operator
	augment_columns operator
	band_matrix operator
	block_matrix operator
	char_matrix operator
	char_poly operator
	cholesky operator
	coeff_matrix operator
	column_dim operator
	companion operator
	copy_into operator
	diagonal operator
	extend operator
	find_companion operator
	get_columns operator
	get_rows operator
	gram_schmidt operator
	hermitian_tp operator
	hessian operator
	hilbert operator
	jacobian operator
	jordan_block operator
	lu_decom operator
	make_identity operator
	matrix_augment operator
	matrixp operator
	matrix_stack operator
	minor operator
	mult_columns operator
	mult_rows operator
	pivot operator
	pseudo_inverse operator
	random_matrix operator
	remove_columns operator
	remove_rows operator
	row_dim operator
	rows_pivot operator
	simplex operator
	squarep operator
	stack_rows operator
	sub_matrix operator
	svd operator
	swap_columns operator
	swap_entries operator
	swap_rows operator
	symmetricp operator
	toeplitz operator
	vandermonde operator

#$+ KSMITHEX				operator

 The operator smithex  computes the Smith normal form S of a matrix  A (say). It returns {S,P,P^-1} where P*S*P^-1 = A. 

syntax: 
smithex (<matrix>,<variable>) 

<matrix> :- a rectangular matrix  of univariate polynomials in  <variable>. <variable> :- the variable. 

 
examples: 
 
 a := mat((x,x+1),(0,3*x^2));  
 
        [x  x + 1] 
        [        ] 
   a := [      2 ] 
        [0  3*x  ] 

 
 smithex(a,x);  
 
     [1  0 ]    [1    0]    [x   x + 1] 
  {  [     ],   [      ],   [         ]  } 
     [    3]    [   2  ]    [         ] 
     [0  x ]    [3*x  1]    [-3    -3 ] 

#$+ KSMITHEX‑INT				operator

 The operator smithex_int  performs the same task as smithex  but on matrices containing only integer entries. Namely, smithex_int  returns {S,P,P^-1} where S is the smith normal form of the input matrix  (A say), and P*S*P^-1 = A. 

syntax: 
smithex_int (<matrix>) 

<matrix> :- a rectangular matrix  of integer entries. 

 
examples: 
 
 a := mat((9,-36,30),(-36,192,-180),(30,-180,180));  

       [ 9   -36    30 ] 
       [               ] 
  a := [-36  192   -180] 
       [               ] 
       [30   -180  180 ] 

 
 smithex_int(a);  
 
    [3  0   0 ]    [-17  -5   -4 ]    [1   -24  30 ] 
    [         ]    [             ]    [            ] 
  { [0  12  0 ],   [64   19   15 ],   [-1  25   -30] } 
    [         ]    [             ]    [            ]  
    [0  0   60]    [-50  -15  -12]    [0   -1    1 ]  

#$+ KFROBENIUS				operator

 The operator frobenius  computes the frobenius  normal form F of a matrix  (A say). It returns {F,P,P^-1} where P*F*P^-1 = A. 

syntax: 
frobenius (<matrix>) 

<matrix> :- a square matrix . 

Field Extensions: 

By default, calculations are performed in the rational numbers. To extend this field the arnum  package can be used. The package must first be loaded by load_package arnum;. The field can now be extended by using the defpoly command. For example, defpoly sqrt2**2-2; will extend the field to include the square root of 2 (now defined by sqrt2). 

Modular Arithmetic: 

Frobenius can also be calculated in a modular base. To do this first type on modular;. Then setmod p; (where p is a prime) will set the modular base of calculation to p. By further typing on balanced_mod the answer will appear using a symmetric modular representation. See ratjordan  for an example. 

examples: 
 
 a := mat((x,x^2),(3,5*x));  
 
       [    2 ] 
       [x  x  ] 
  a := [      ] 
       [3  5*x] 

 frobenius(a); 
 
     [         2]    [1  x]    [       - x ] 
  {  [0   - 2*x ],   [    ],   [1     -----]  } 
     [          ]    [0  3]    [        3  ] 
     [1    6*x  ]              [           ] 
                               [        1  ] 
                               [0      --- ] 
                               [        3  ] 

 load‑package arnum; 
 
 defpoly sqrt2**2-2; 
 
 a := mat((sqrt2,5),(7*sqrt2,sqrt2)); 

       [ sqrt2     5  ] 
  a := [              ] 
       [7*sqrt2  sqrt2] 

 
 frobenius(a);  
 
    [0  35*sqrt2 - 2]    [1   sqrt2 ]    [           1  ] 
  { [               ],   [          ],   [1       - --- ]  } 
    [1    2*sqrt2   ]    [1  7*sqrt2]    [           7  ] 
                                         [              ] 
                                         [     1        ] 
                                         [0   ----*sqrt2] 
                                         [     14       ] 

#$+ KRATJORDAN				operator

 The operator ratjordan  computes the rational Jordan normal form R of a matrix  (A say). It returns {R,P,P^-1} where P*R*P^-1 = A. 

syntax: 
ratjordan (<matrix>) 

<matrix> :- a square matrix . 

Field Extensions: 

By default, calculations are performed in the rational numbers. To extend this field the arnum  package can be used. The package must first be loaded by load_package arnum;. The field can now be extended by using the defpoly command. For example, defpoly sqrt2**2-2; will extend the field to include the square root of 2 (now defined by sqrt2). See frobenius  for an example. 

Modular Arithmetic: 

ratjordan can also be calculated in a modular base. To do this first type on modular;. Then setmod p; (where p is a prime) will set the modular base of calculation to p. By further typing on balanced_mod the answer will appear using a symmetric modular representation. 

examples: 
 
 a := mat((5,4*x),(2,x^2)); 
 
       [5  4*x] 
       [      ] 
  a := [    2 ] 
       [2  x  ] 

 
 ratjordan(a);  
 
    [0  x*( - 5*x + 8)]   [1  5]    [        -5 ]   
  { [                 ],  [    ],   [1     -----] } 
    [        2        ]   [0  2]    [        2  ] 
    [1      x  + 5    ]             [           ] 
                                    [        1  ] 
                                    [0     -----] 
                                    [        2  ] 

 on modular;  
 
 setmod 23;  
 
 a := mat((12,34),(56,78));  
 
       [12  11] 
  a := [      ] 
       [10  9 ] 

 
 ratjordan(a);  
 
    [15  0]   [16  8]   [1  21] 
  { [     ],  [     ],  [     ]  } 
    [0   6]   [19  4]   [1  4 ] 

 
 on balanced‑mod; 
 
 ratjordan(a); 
 
    [- 8  0]   [ - 7  8]   [1  - 2] 
  { [      ],  [       ],  [      ]  } 
    [ 0   6]   [ - 4  4]   [1   4 ] 

#$+ KJORDANSYMBOLIC				operator

 The operator jordansymbolic  computes the Jordan normal form J of a matrix  (A say). It returns {J,L,P,P^-1} where P*J*P^-1 = A. L = {ll,mm} where mm is a name and ll is a list of irreducible factors of p(mm). 

syntax: 
jordansymbolic (<matrix>) 

<matrix> :- a square matrix . 

Field Extensions: 

By default, calculations are performed in the rational numbers. To extend this field the arnum  package can be used. The package must first be loaded by load_package arnum;. The field can now be extended by using the defpoly command. For example, defpoly sqrt2**2-2; will extend the field to include the square root of 2 (now defined by sqrt2). See frobenius  for an example. 

Modular Arithmetic: 

jordansymbolic can also be calculated in a modular base. To do this first type on modular;. Then setmod p; (where p is a prime) will set the modular base of calculation to p. By further typing on balanced_mod the answer will appear using a symmetric modular representation. See ratjordan  for an example. 

examples: 

 a := mat((1,y),(2,5*y));  
 
       [1   y ] 
  a := [      ] 
       [2  5*y] 

 
 jordansymbolic(a);  
 
  { 
   [lambda11     0    ] 
   [                  ] 
   [   0      lambda12] 
   , 
           2 
   lambda  - 5*lambda*y - lambda + 3*y,lambda, 
   [lambda11 - 5*y  lambda12 - 5*y] 
   [                              ] 
   [      2               2       ] 
   , 
   [ 2*lambda11 - 5*y - 1    5*lambda11*y - lambda11 - y + 1 ] 
   [----------------------  ---------------------------------] 
   [       2                              2                  ] 
   [   25*y  - 2*y + 1             2*(25*y  - 2*y + 1)       ] 
   [                                                         ] 
   [ 2*lambda12 - 5*y - 1    5*lambda12*y - lambda12 - y + 1 ] 
   [----------------------  ---------------------------------] 
   [       2                              2                  ] 
   [   25*y  - 2*y + 1             2*(25*y  - 2*y + 1)       ] 
   } 

#$+ KJORDAN				operator

 The operator jordan  computes the Jordan normal form J of a matrix  (A say). It returns {J,P,P^-1} where P*J*P^-1 = A. 

syntax: 
jordan (<matrix>) 

<matrix> :- a square matrix . 

Field Extensions: By default, calculations are performed in the rational numbers. To extend this field the arnum  package can be used. The package must first be loaded by load_package arnum;. The field can now be extended by using the defpoly command. For example, defpoly sqrt2**2-2; will extend the field to include the square root of 2 (now defined by sqrt2). See frobenius  for an example. 

Modular Arithmetic: Jordan  can also be calculated in a modular base. To do this first type on modular;. Then setmod p; (where p is a prime) will set the modular base of calculation to p. By further typing on balanced_mod the answer will appear using a symmetric modular representation. See ratjordan  for an example. 

examples: 

 a := mat((1,x),(0,x));  
 
       [1  x] 
  a := [    ] 
       [0  x] 

 
 jordan(a); 
 
  { 
   [1  0] 
   [    ] 
   [0  x] 
   , 
   [   1           x       ] 
   [-------  --------------] 
   [ x - 1     2           ] 
   [          x  - 2*x + 1 ] 
   [                       ] 
   [               1       ] 
   [   0        -------    ] 
   [             x - 1     ] 
   , 
   [x - 1   - x ] 
   [            ] 
   [  0    x - 1] 
   } 

#$+Matrix Normal Forms

	Smithex operator
	Smithex‑int operator
	Frobenius operator
	Ratjordan operator
	Jordansymbolic operator
	Jordan operator

#$+ KMISCELLANEOUS PACKAGES				introduction

 REDUCE includes a large number of packages that have been contributed by users from various fields. Some of these, together with their relevant commands, switches and so on (e.g., the NUMERIC package), have been described elsewhere. This section describes those packages for which no separate help material exists. Each has its own switches, commands, and operators, and some redefine special characters to aid in their notation. However, the brief descriptions given here do not include all such information. Readers are referred to the general package documentation in this case, which can be found, along with the source code, under the subdirectories doc  and src  in the reduce  directory. The load_package  command is used to load the files you wish into your system. There will be a short delay while the package is loaded. A package cannot be unloaded. Once it is in your system, it stays there until you end the session. Each package also has a test file, which you will find under its name in the $reduce/xmpl  directory. 

Finally, it should be mentioned that such user-contributed packages are unsupported; any questions or problems should be directed to their authors. 

#$+ KALGINT				package

Author: James H. Davenport 

The algint  package provides indefinite integration of square roots. This package, which is an extension of the basic integration package distributed with REDUCE, will analytically integrate a wide range of expressions involving square roots. The algint  switch provides for the use of the facilities given by the package, and is automatically turned on when the package is loaded. If you want to return to the standard integration algorithms, turn algint  off. An error message is given if you try to turn the algint  switch on when its package is not loaded. 

#$+ KAPPLYSYM				package

Author: Thomas Wolf 

This package provides programs APPLYSYM, QUASILINPDE and DETRAFO for computing with infinitesimal symmetries of differential equations. 

#$+ KARNUM				package

Author: Eberhard Schruefer 

This package provides facilities for handling algebraic numbers as polynomial coefficients in REDUCE calculations. It includes facilities for introducing indeterminates to represent algebraic numbers, for calculating splitting fields, and for factoring and finding greatest common divisors in such domains. 

#$+ KASSIST				package

Author: Hubert Caprasse 

ASSIST contains a large number of additional general purpose functions that allow a user to better adapt REDUCE to various calculational strategies and to make the programming task more straightforward and more efficient. 

#$+ KAVECTOR				package

Author: David Harper 

This package provides REDUCE with the ability to perform vector algebra using the same notation as scalar algebra. The basic algebraic operations are supported, as are differentiation and integration of vectors with respect to scalar variables, cross product and dot product, component manipulation and application of scalar functions (e.g. cosine) to a vector to yield a vector result. 

#$+ KBOOLEAN				package

Author: Herbert Melenk 

This package supports the computation with boolean expressions in the propositional calculus. The data objects are composed from algebraic expressions connected by the infix boolean operators and, or,  implies, equiv, and the unary prefix operator not.  Boolean allows you to simplify expressions built from these operators, and to test properties like equivalence, subset property etc. 

#$+ KCALI				package

Author: Hans-Gert Gr"abe 

This package contains algorithms for computations in commutative algebra closely related to the Groebner algorithm for ideals and modules. Its heart is a new implementation of the Groebner algorithm that also allows for the computation of syzygies. This implementation is also applicable to submodules of free modules with generators represented as rows of a matrix. 

#$+ KCAMAL				package

Author: John P. Fitch 

This packages implements in REDUCE the Fourier transform procedures of the CAMAL package for celestial mechanics. 

#$+ KCHANGEVR				package

 Author: G. Ucoluk 

This package provides facilities for changing the independent variables in a differential equation. It is basically the application of the chain rule. 

#$+ KCOMPACT				package

Author: Anthony C. Hearn 

COMPACT is a package of functions for the reduction of a polynomial in the presence of side relations. COMPACT applies the side relations to the polynomial so that an equivalent expression results with as few terms as possible. For example, the evaluation of 

     compact(s*(1-sin x^2)+c*(1-cos x^2)+sin x^2+cos x^2, 
             {cos x^2+sin x^2=1}); 
 
yields the result  
 
              2           2 
        SIN(X) *C + COS(X) *S + 1 

The first argument to the operator compact  is the expression and the second is a list of side relations that can be equations or simple expressions (implicitly equated to zero). The kernels in the side relations may also be free variables with the same meaning as in rules, e.g.  
     sin_cos_identity :=  {cos ~w^2+sin ~w^2=1}$ 
     compact(u,in_cos_identity); 

Also the full rule syntax with the replacement operator is allowed here.  

#$+ KCONTFR				package

Author: Herbert Melenk 

This package provides for the simultaneous approximation of a real number by a continued fraction and a rational number with optional user controlled precision (an upper bound for the denominator). 

To use this package, the misc  package should be loaded. One can then use the operator continued_fraction  to approximate the real number by a continued fraction. This operator has one or two arguments, the number to be converted and an optional precision. The result is a list of two elements: the first is the rational value of the approximation and the second the list of terms of the continued fraction that represent the same value according to the definition t0 +1/(t1 + 1/(t2 + ...)). The second optional parameter size  is an upper bound on the absolute value of the result denominator. If omitted, the approximation is performed up to the current system precision. 

examples: 
 
continued‑fraction pi;  
 
    1146408 
  {---------,{3,7,15,1,292,1,1,1,2,1}} 
    364913 

 
continued‑fraction(pi,100);  
 
    22 
  {----,{3,7}} 
    7 

#$+ KCRACK				package

Authors: Andreas Brand, Thomas Wolf 

CRACK is a package for solving overdetermined systems of partial or ordinary differential equations (PDEs, ODEs). Examples of programs which make use of CRACK for investigating ODEs (finding symmetries, first integrals, an equivalent Lagrangian or a ``differential factorization'') are included. 

#$+ KCVIT				package

Authors: V.Ilyin, A.Kryukov, A.Rodionov, A.Taranov 

This package provides an alternative method for computing traces of Dirac gamma matrices, based on an algorithm by Cvitanovich that treats gamma matrices as 3-j symbols. 

#$+ KDEFINT				package

Authors: Kerry Gaskell, Stanley M. Kameny, Winfried Neun 

This package finds the definite integral of an expression in a stated interval. It uses several techniques, including an innovative approach based on the Meijer G-function, and contour integration. 

#$+ KDESIR				package

Authors: C. Dicrescenzo, F. Richard-Jung, E. Tournier 

This package enables the basis of formal solutions to be computed for an ordinary homogeneous differential equation with polynomial coefficients over Q of any order, in the neighborhood of zero (regular or irregular singular point, or ordinary point). 

#$+ KDFPART				package

Author: Herbert Melenk 

This package supports computations with total and partial derivatives of formal function objects. Such computations can be useful in the context of differential equations or power series expansions. 

#$+ KDUMMY				package

Author: Alain Dresse 

This package allows a user to find the canonical form of expressions involving dummy variables. In that way, the simplification of polynomial expressions can be fully done. The indeterminates are general operator objects endowed with as few properties as possible. In that way the package may be used in a large spectrum of applications. 

#$+ KEXCALC				package

Author: Eberhard Schruefer 

The excalc  package is designed for easy use by all who are familiar with the calculus of Modern Differential Geometry. The program is currently able to handle scalar-valued exterior forms, vectors and operations between them, as well as non-scalar valued forms (indexed forms). It is thus an ideal tool for studying differential equations, doing calculations in general relativity and field theories, or doing simple things such as calculating the Laplacian of a tensor field for an arbitrary given frame. 

#$+ KFPS				package

Authors: Wolfram Koepf, Winfried Neun 

This package can expand a specific class of functions into their corresponding Laurent-Puiseux series. 

#$+ KFIDE				package

 Author: Richard Liska 

This package performs automation of the process of numerically solving partial differential equations systems (PDES) by means of computer algebra. For PDES solving, the finite difference method is applied. The computer algebra system REDUCE and the numerical programming language FORTRAN are used in the presented methodology. The main aim of this methodology is to speed up the process of preparing numerical programs for solving PDES. This process is quite often, especially for complicated systems, a tedious and time consuming task. 

#$+ KGENTRAN				package

Author: Barbara L. Gates 

This package is an automatic code GENerator and TRANslator. It constructs complete numerical programs based on sets of algorithmic specifications and symbolic expressions. Formatted FORTRAN, RATFOR or C code can be generated through a series of interactive commands or under the control of a template processing routine. Large expressions can be automatically segmented into subexpressions of manageable size, and a special file-handling mechanism maintains stacks of open I/O channels to allow output to be sent to any number of files simultaneously and to facilitate recursive invocation of the whole code generation process. 

#$+ KIDEALS				package

Author: Herbert Melenk 

This package implements the basic arithmetic for polynomial ideals by exploiting the Groebner bases package of REDUCE. In order to save computing time all intermediate Groebner bases are stored internally such that time consuming repetitions are inhibited. 

#$+ KINEQ				package

Author: Herbert Melenk 

This package supports the operator ineq_solve  that tries to solves single inequalities and sets of coupled inequalities. 

#$+ KINVBASE				package

 Authors: A.Yu. Zharkov and Yu.A. Blinkov 

Involutive bases are a new tool for solving problems in connection with multivariate polynomials, such as solving systems of polynomial equations and analyzing polynomial ideals. An involutive basis of polynomial ideal is nothing but a special form of a redundant Groebner basis. The construction of involutive bases reduces the problem of solving polynomial systems to simple linear algebra. 

#$+ KLAPLACE				package

Authors: C. Kazasov, M. Spiridonova, V. Tomov 

This package can calculate ordinary and inverse Laplace transforms of expressions. Documentation is in plain text. 

#$+ KLIE				package

 Authors: Carsten and Franziska Sch"obel 

Lie is a package of functions for the classification of real n-dimensional Lie algebras. It consists of two modules: liendmc1  and lie1234 . With the help of the functions in the liendmcl  module, real n-dimensional Lie algebras L with a derived algebra L^(1) of dimension 1 can be classified. 

#$+ KMODSR				package

Author: Herbert Melenk 

This package supports solve (M_SOLVE) and roots (M_ROOTS) operators for modular polynomials and modular polynomial systems. The moduli need not be primes. M_SOLVE requires a modulus to be set. M_ROOTS takes the modulus as a second argument. For example: 

on modular; setmod 8; 
m_solve(2x=4);            ->  {{X=2},{X=6}} 
m_solve({x^2-y^3=3}); 
    ->  {{X=0,Y=5}, {X=2,Y=1}, {X=4,Y=5}, {X=6,Y=1}} 
m_solve({x=2,x^2-y^3=3}); ->  {{X=2,Y=1}} 
off modular; 
m_roots(x^2-1,8);         ->  {1,3,5,7} 
m_roots(x^3-x,7);         ->  {0,1,6} 

#$+ KNCPOLY				package

Authors: Herbert Melenk, Joachim Apel 

This package allows the user to set up automatically a consistent environment for computing in an algebra where the non--commutativity is defined by Lie-bracket commutators. The package uses the REDUCE noncom  mechanism for elementary polynomial arithmetic; the commutator rules are automatically computed from the Lie brackets. 

#$+ KORTHOVEC				package

Author: James W. Eastwood 

orthovec is a collection of REDUCE procedures and operations which provide a simple-to-use environment for the manipulation of scalars and vectors. Operations include addition, subtraction, dot and cross products, division, modulus, div, grad, curl, laplacian, differentiation, integration, and Taylor expansion. 

#$+ KPHYSOP				package

 Author: Mathias Warns 

This package has been designed to meet the requirements of theoretical physicists looking for a computer algebra tool to perform complicated calculations in quantum theory with expressions containing operators. These operations consist mainly of the calculation of commutators between operator expressions and in the evaluations of operator matrix elements in some abstract space. 

#$+ KPM				package

Author: Kevin McIsaac 

PM is a general pattern matcher similar in style to those found in systems such as SMP and Mathematica, and is based on the pattern matcher described in Kevin McIsaac, ``Pattern Matching Algebraic Identities'', SIGSAM Bulletin, 19 (1985), 4-13. 

#$+ KRANDPOLY				package

Author: Francis J. Wright 

This package is based on a port of the Maple random polynomial generator together with some support facilities for the generation of random numbers and anonymous procedures. 

#$+ KREACTEQN				package

Author: Herbert Melenk 

This package allows a user to transform chemical reaction systems into ordinary differential equation systems (ODE) corresponding to the laws of pure mass action. 

#$+ KRESET				package

 Author: John Fitch 

This package defines a command command RESETREDUCE that works through the history of previous commands, and clears any values which have been assigned, plus any rules, arrays and the like. It also sets the various switches to their initial values. It is not complete, but does work for most things that cause a gradual loss of space. It would be relatively easy to make it interactive, so allowing for selective resetting. 

#$+ KRESIDUE				package

 Author: Wolfram Koepf 

This package supports the calculation of residues of arbitrary expressions. 

#$+ KRLFI				package

Author: Richard Liska 

This package adds LaTeX syntax to REDUCE. Text generated by REDUCE in this mode can be directly used in LaTeX source documents. Various mathematical constructions are supported by the interface including subscripts, superscripts, font changing, Greek letters, divide-bars, integral and sum signs, derivatives, and so on. 

#$+ KSCOPE				package

Author: J.A. van Hulzen 

SCOPE is a package for the production of an optimized form of a set of expressions. It applies an heuristic search for common (sub)expressions to almost any set of proper REDUCE assignment statements. The output is obtained as a sequence of assignment statements. gentran  is used to facilitate expression output. 

#$+ KSETS				package

 Author: Francis J. Wright 

The SETS package provides algebraic-mode support for set operations on lists regarded as sets (or representing explicit sets) and on implicit sets represented by identifiers. 

#$+ KSPDE				package

Author: Fritz Schwartz 

The package spde  provides a set of functions which may be used to determine the symmetry group of Lie- or point-symmetries of a given system of partial differential equations. In many cases the determining system is solved completely automatically. In other cases the user has to provide additional input information for the solution algorithm to terminate. 

#$+ KSYMMETRY				package

 Author: Karin Gatermann 

This package computes symmetry-adapted bases and block diagonal forms of matrices which have the symmetry of a group. The package is the implementation of the theory of linear representations for small finite groups such as the dihedral groups. 

#$+ KTPS				package

Authors: Alan Barnes, Julian Padget 

This package implements formal Laurent series expansions in one variable using the domain mechanism of REDUCE. This means that power series objects can be added, multiplied, differentiated etc., like other first class objects in the system. A lazy evaluation scheme is used and thus terms of the series are not evaluated until they are required for printing or for use in calculating terms in other power series. The series are extendible giving the user the impression that the full infinite series is being manipulated. The errors that can sometimes occur using series that are truncated at some fixed depth (for example when a term in the required series depends on terms of an intermediate series beyond the truncation depth) are thus avoided. 

#$+ KTRI				package

Author: Werner Antweiler 

This package provides facilities written in REDUCE-Lisp for typesetting REDUCE formulas using TeX. The TeX-REDUCE-Interface incorporates three levels of TeX output: without line breaking, with line breaking, and with line breaking plus indentation. 

#$+ KTRIGSIMP				package

Author: Wolfram Koepf 

TRIGSIMP is a useful tool for all kinds of trigonometric and hyperbolic simplification and factorization. There are three procedures included in TRIGSIMP: trigsimp , trigfactorize  and triggcd . The first is for finding simplifications of trigonometric or hyperbolic expressions with many options, the second for factorizing them and the third for finding the greatest common divisor of two trigonometric or hyperbolic polynomials. 

#$+ KXCOLOR				package

Author: A. Kryukov 

This package calculates the color factor in non-abelian gauge field theories using an algorithm due to Cvitanovich. 

#$+ KXIDEAL				package

Author: David Hartley 

xideal constructs Groebner bases for solving the left ideal membership problem: Groebner left ideal bases or GLIBs. For graded ideals, where each form is homogeneous in degree, the distinction between left and right ideals vanishes. Furthermore, if the generating forms are all homogeneous, then the Groebner bases for the non-graded and graded ideals are identical. In this case, xideal  is able to save time by truncating the Groebner basis at some maximum degree if desired. 

#$+ KWU				package

Author: Russell Bradford 

This is a simple implementation of the Wu algorithm implemented in REDUCE working directly from ``A Zero Structure Theorem for Polynomial-Equations-Solving,'' Wu Wen-tsun, Institute of Systems Science, Academia Sinica, Beijing. 

#$+ KZEILBERG				package

Authors: Gregor St"olting and Wolfram Koepf 

This package is a careful implementation of the Gosper and Zeilberger algorithms for indefinite and definite summation of hypergeometric terms, respectively. Extensions of these algorithms are also included that are valid for ratios of products of powers, factorials, gamma function terms, binomial coefficients, and shifted factorials that are rational-linear in their arguments. 

#$+ KZTRANS				package

 Authors: Wolfram Koepf, Lisa Temme 

This package is an implementation of the Z-transform of a sequence. This is the discrete analogue of the Laplace Transform. 

#$+Miscellaneous Packages

	Miscellaneous Packages introduction
	ALGINT package
	APPLYSYM package
	ARNUM package
	ASSIST package
	AVECTOR package
	BOOLEAN package
	CALI package
	CAMAL package
	CHANGEVR package
	COMPACT package
	CONTFR package
	CRACK package
	CVIT package
	DEFINT package
	DESIR package
	DFPART package
	DUMMY package
	EXCALC package
	FPS package
	FIDE package
	GENTRAN package
	IDEALS package
	INEQ package
	INVBASE package
	LAPLACE package
	LIE package
	MODSR package
	NCPOLY package
	ORTHOVEC package
	PHYSOP package
	PM package
	RANDPOLY package
	REACTEQN package
	RESET package
	RESIDUE package
	RLFI package
	SCOPE package
	SETS package
	SPDE package
	SYMMETRY package
	TPS package
	TRI package
	TRIGSIMP package
	XCOLOR package
	XIDEAL package
	WU package
	ZEILBERG package
	ZTRANS package

#$+ KED				command

 The ed  command invokes a simple line editor for REDUCE input statements. 

syntax: 
ed <integer> or ed  

ed called with no argument edits the last input statement. If <integer> is greater than or equal to the current line number, an error message is printed. Reenter a proper ed  command or return to the top level with a semicolon. 

The editor formats REDUCE's version of the desired input statement, dividing it into lines at semicolons and dollar signs. The statement is printed at the beginning of the edit session. The editor works on one line at a time, and has a pointer (shown by ^ ) to the current character of that line. When the session begins, the pointer is at the left hand side of the first line. The editing prompt is > . 

The following commands are available. They may be entered in either upper or lower case. All commands are activated by the carriage return, which also prints out the current line after changes. Several commands can be placed on a single line, except that commands terminated by an ESC  must be the last command before the carriage return. 

	b Move pointer to beginning of current line. 

	d<digit> Delete current character and next (digit-1) characters. An error message is printed if anything other than a single digit follows d. If there are fewer than <digit> characters left on the line, all but the final dollar sign or semicolon is removed. To delete a line completely, use the k command. 

	e End the current session, causing the edited expression to be reparsed by REDUCE. 

	f<char> Find the next occurrence of the character <char> to the right of the pointer on the current line and move the pointer to it. If the character is not found, an error message is printed and the pointer remains in its original position. Other lines are not searched. The f command is not case-sensitive. 

	i<string>ESC  Insert <string> in front of pointer. The ESC  key is your delimiter for the input string. No other command may follow this one on the same line. 

	k Kill rest of the current line, including the semicolon or dollar sign terminator. If there are characters remaining on the current line, and it is the last line of the input statement, a semicolon is added to the line as a terminator for REDUCE. If the current line is now empty, one of the following actions is performed: If there is a following line, it becomes the current line and the pointer is placed at its first character. If the current line was the final line of the statement, and there is a previous line, the previous line becomes the current line. If the current line was the only line of the statement, and it is empty, a single semicolon is inserted for REDUCE to parse. 

	l Finish editing this line and move to the last previous line. An error message is printed if there is no previous line. 

	n Finish editing this line and move to the next line. An error message is printed if there is no next line. 

	p Print out all the lines of the statement. Then a dotted line is printed, and the current line is reprinted, with the pointer under it. 

	q Quit the editing session without saving the changes. If a semicolon is entered after q, a new line prompt is given, otherwise REDUCE prompts you for another command. Whatever you type in to the prompt appearing after the q is entered is stored as the input for the line number in which you called the edit. Thus if you enter a semicolon, neither input  ed  will find anything under the current number. 

	r<char> Replace the character at the pointer by <char>. 

	s<string>ESC  Search for the first occurrence of <string> to the right of the pointer on the current line and move the pointer to its first character. The ESC  key is your delimiter for the input string. The s function does not search other lines of the statement. If the string is not found, an error message is printed and the pointer remains in its original position. The s command is not case-sensitive. No other command may follow this one on the same line. 

	x <or space> Move the pointer one character to the right. If the pointer is already at the end of the line, an error message is printed. 

	- <(minus)> Move the pointer one character to the left. If the pointer is already at the beginning of the line, an error message is printed. 

	? Display the Help menu, showing the commands and their actions. 

examples: 
(Line numbers are shown in the following examples)  
 
2: >>x**2 + y;  
 
X^{2} + Y  
 
3: >>ed 2;  
 
  X**2 + Y;  
 
  ^  
 
For help, type '?'  
 
?-                  (Enter three spaces and {Return})  
 
  X**2 + Y;  
 
     ^  
 
?- r5  
 
  X**5 + Y;  
 
     ^  
 
?- fY  
 
  X**5 + Y;  
 
	 ^  
 
?- iabc (Terminate with {ESC} and {Return})  
 
  X**5 + abcY;  
 
	    ^  
 
?- ----  
 
  X**5 + abcY;  
 
	^  
 
?- fbd2  
 
  X**5 + aY;  
 
	  ^  
 
?- b  
 
  X**5 + aY;  
 
  ^  
 
?- e  
 
AY + X^{5}  
 
4: >>procedure dumb(a);  
 
>>write a;  
 
DUMB  
 
5: >>dumb(17);  
 
17  
 
6: >>ed 4;  
 
  PROCEDURE DUMB (A);  
 
  ^  
 
WRITE A;  
 
?- fArBn  
 
  WRITE A;  
 
  ^  
 
?- ibegin scalar a; a := b + 10; (Type a space, {ESC}, and {Return})  
 
  begin scalar a; a := b + 10; WRITE A;  
 
?- f;i end {ESC}, {Return}  
 
  begin scalar b; b := a + 10; WRITE A end;  
 
					  ^  
 
?- p  
 
 PROCEDURE DUMB (B);  
 
 begin scalar b; b := a + 10; WRITE A end;  
 
 -  -  -  -  -  -  -  -  -  -  
 
  begin scalar b; b := a + 10; WRITE A end;  
 
					  ^  
 
?- e  
 
DUMB  
 
7: >>dumb(17);  
 
27  
 
8: >>  

Note that REDUCE reparsed the procedure dumb  and updated the definition. 

Since REDUCE divides the expression to be edited into lines at semicolons or dollar sign terminators, some lines may occupy more than one line of screen space. If the pointer is directly beneath the last line of text, it refers to the top line of text. If there is a blank line between the last line of text and the pointer, it refers to the second line of text, and likewise for cases of greater than two lines of text. In other words, the entire REDUCE statement up to the next terminator is printed, even if it runs to several lines, then the pointer line is printed. 

You can insert new statements which contain semicolons of their own into the current line. They are run into the current line where you placed them until you edit the statement again. REDUCE will understand the set of statements if the syntax is correct. 

If you leave out needed closing brackets when you exit the editor, a message is printed allowing you to redo the edit (you can edit the previous line number and return to where you were). If you leave out a closing double-quotation mark, an error message is printed, and the editing must be redone from the original version; the edited version has been destroyed. Most syntax errors which you inadvertently leave in an edited statement are caught as usual by the REDUCE parser, and you will be able to re-edit the statement. 

When the editor processes a previous statement for your editing, escape characters are removed. Most special characters that you may use in identifiers are printed in legal fashion, prefixed by the exclamation point. Be sure to treat the special character and its escape as a pair in your editing. The characters ( ) # ; ' `  are different. Since they have special meaning in Lisp, they are double-escaped in the editor. It is unwise to use these characters inside identifiers anyway, due to the probability of confusion. 

If you see a Lisp error message during editing, the edit has been aborted. Enter a semicolon and you will see a new line prompt. 

Since the editor has no dependence on any window system, it can be used if you are running REDUCE without windows. 

#$+ KEDITDEF				command

The interactive editor ed  may be used to edit a user-defined procedure that has not been compiled.  
syntax: 

editdef (identifier ) 

where identifier  is the name of the procedure. When editdef  is invoked, the procedure definition will be displayed in editing mode, and may then be edited and redefined on exiting from the editor using standard ed  commands. 

#$+Outmoded Operations

	ED command
	EDITDEF command

#$+Top

	Concepts
	Variables
	Syntax
	Arithmetic Operations
	Boolean Operators
	General Commands
	Algebraic Operators
	Declarations
	Input and Output
	Elementary Functions
	General Switches
	Matrix Operations
	Groebner package
	High Energy Physics
	Numeric Package
	Roots Package
	Special Functions
	Taylor series
	Gnuplot package
	Linear Algebra package
	Matrix Normal Forms
	Miscellaneous Packages
	Outmoded Operations