Top
IDENTIFIER _ _ _ _ _ _ _ _ _ _ _ _ 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.
KERNEL _ _ _ _ _ _ _ _ _ _ _ _ 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.
STRING _ _ _ _ _ _ _ _ _ _ _ _ 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.
write "this is a string"; this is a string write a, " ", b, " ",c,"!"; A B C!
Concepts
ASSUMPTIONS _ _ _ _ _ _ _ _ _ _ _ _ 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.
solve({a*x-b*y+x,y-c},{x,y}); b*c {{x=-----,y=c}} a + 1 assumptions; {a + 1}
CARD\_NO _ _ _ _ _ _ _ _ _ _ _ _ variable
card_nosets the total number of cards allowed in a Fortran output statement when fort is on. Default is 20.
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.
E _ _ _ _ _ _ _ _ _ _ _ _ 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.
emay 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.
EVAL\_MODE _ _ _ _ _ _ _ _ _ _ _ _ variable
The system variable eval_mode contains the current mode, either algebraic or symbolic.
EVAL_MODE; ALGEBRAIC
Some commands do not behave the same way in algebraic and symbolic modes.
FORT\_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.
fort_width := 30; FORT_WIDTH := 30 on fort; df(sin(x**3*y),x); ANS=3.*COS(X . **3*Y)*X**2* . Y
fort_widthincludes the usually blank characters at the be ginning of the card. As you may notice above, it is conservative and makes the lines even shorter than it was told.
HIGH\_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.
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
I _ _ _ _ _ _ _ _ _ _ _ _ constant
REDUCE knows i is the square root of -1, and that i^2 = -1.
(a + b*i)*(c + d*i); A*C + A*D*I + B*C*I - B*D i**2; -1
icannot 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.
INFINITY _ _ _ _ _ _ _ _ _ _ _ _ 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.
LOW\_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.
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
NIL _ _ _ _ _ _ _ _ _ _ _ _ constant
nilrepresents 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.
PI _ _ _ _ _ _ _ _ _ _ _ _ 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.
pimay 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.
REQUIREMENTS _ _ _ _ _ _ _ _ _ _ _ _ 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.
solve({x-a,x-y,y-1},{x,y}); {} requirements; {a - 1}
ROOT\_MULTIPLICITIES _ _ _ _ _ _ _ _ _ _ _ _ variable
The root_multiplicities variable is set to the list of the multiplicities of the roots of an equation by the solve operator.
solvereturns its solutions in a list. The multipliciti es of each solution are put in the corresponding locations of the list root_multiplicities.
T _ _ _ _ _ _ _ _ _ _ _ _ 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
; _ _ _ SEMICOLON _ _ _ _ _ _ _ _ _ _ _ _ command
The semicolon is a statement delimiter, indicating results are to be printed when used in interactive mode.
(x+1)**2; 2 X + 2*X + 1 df(x**2 + 1,x); 2*X
Entering a Return without a semicolon or dollar sign resu lts 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.
$ _ _ _ DOLLAR _ _ _ _ _ _ _ _ _ _ _ _ command
The dollar sign is a statement delimiter, indicating results are not to be printed when used in interactive mode.
(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.
% _ _ _ PERCENT _ _ _ _ _ _ _ _ _ _ _ _ command
The percent sign is used to precede comments; everything from a percent to the end of the line is ignored.
df(x**3 + y,x);% This is a comment key{Return} 2 3*X int(3*x**2,x) %This is a comment; key{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.
. _ _ _ 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.
<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.
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
:= _ _ _ ASSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
The := is the assignment operator, assigning the value on the right-han d side to the identifier or other valid expression on the left-hand side.
<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.
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 seco nd 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.
= _ _ _ EQUALSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
The = operator is a prefix or infix equality comparison operator.
<expression> can be any REDUCE scalar expression.
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 condition al statement, such as if...then...else or repeat...until. In other places the equal sign establishes an algebraic object of type equation.
=> _ _ _ REPLACE _ _ _ _ _ _ _ _ _ _ _ _ operator
The => operator is a binary operator used in rule lists to denote replacements.
operator f; let f(x) => x^2; f(x); 2 x
+ _ _ _ PLUSSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
The + operator is a prefix or infix n-ary addition operator.
or +(<expression> {,<expression>}+)
<expression> may be any valid REDUCE expression.
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 equations.
- _ _ _ MINUSSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
The - operator is a prefix or infix binary subtraction operator, as wel l as the unary minus operator.
<expression> may be any valid REDUCE expression.
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 equations.
* _ _ _ ASTERISK _ _ _ _ _ _ _ _ _ _ _ _ operator
The * operator is a prefix or infix n-ary multiplication operator.
or *(<expression> {,<expression>}+)
<expression> may be any valid REDUCE expression.
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 w hen 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 equations can also be multiplied by scalars: the result is as if each element was multiplied by the scalar.
/ _ _ _ SLASH _ _ _ _ _ _ _ _ _ _ _ _ operator
The / operator is a prefix or infix binary division operator or prefix unary reciprocal operator.
or /(<expression>,<expression>)
<expression> may be any valid REDUCE expression.
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.
** _ _ _ POWER _ _ _ _ _ _ _ _ _ _ _ _ operator
The ** operator is a prefix or infix binary exponentiation operator.
<expression> may be any valid REDUCE expression.
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 pow ers with the exponentiation operator (negative powers require the matrix to be invertible). Scalar expressions and equations may be raised to fractional and floating-point powers.
^ _ _ _ CARET _ _ _ _ _ _ _ _ _ _ _ _ operator
The ^ operator is a prefix or infix binary exponentiation operator. It is equivalent to power or **.
<expression> may be any valid REDUCE expression.
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 equations may be raised to fractional and floating-point powers.
>= _ _ _ GEQSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
>= is an infix binary comparison operator, which returns true if its first argument is greater than or equal to its second argument.
<expression> must evaluate to an integer or floating-point number.
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 b etween 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.
> _ _ _ GREATER _ _ _ _ _ _ _ _ _ _ _ _ operator
The > is an infix binary comparison operator that returns true if its first argument is strictly greater than its second.
<expression> must evaluate to a number, e.g., integer, rational or floating point number.
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 b etween 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.
<= _ _ _ LEQSIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
<= is an infix binary comparison operator that returns true if its first argument is less than or equal to its second argument.
<expression> must evaluate to a number, e.g., integer, rational or floating point number.
a := 10; A := 10 if a <= 10 then true; true
The binary comparison operators can only be used for comparisons b etween 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.
< _ _ _ LESS _ _ _ _ _ _ _ _ _ _ _ _ operator
< is an infix binary logical comparison operator that returns true if its first argument is strictly less than its second argument.
<expression> must evaluate to a number, e.g., integer, rational or floating point number.
f := -3; F := -3 if f < -3 then write "yes" else write "no"; no
The binary comparison operators can only be used for comparisons b etween 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.
~ _ _ _ TILDE _ _ _ _ _ _ _ _ _ _ _ _ operator
The ~ is used as a unary prefix operator in the left-hand sides of rules to mark free variables. A double tilde marks an optional free variable.
<< _ _ _ GROUP _ _ _ _ _ _ _ _ _ _ _ _ command
The <<...>> command is a group statement, used to group statements together where REDUCE expects a single statement.
<statement> may be any valid REDUCE statement or expression.
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.
AND _ _ _ _ _ _ _ _ _ _ _ _ operator
The and binary logical operator returns true if both of its arguments are true.
<logical\_expression> must evaluate to true or nil.
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 exami nes 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.
andis left associative: x and y and z is equivalent to (x and y) and z.
BEGIN _ _ _ _ _ _ _ _ _ _ _ _ command
begin is used to start a block statement, which is closed with end.
<statement> is any valid REDUCE statement.
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.
BLOCK _ _ _ _ _ _ _ _ _ _ _ _ command
A block is a sequence of statements enclosed by commands begin and end.
For more details see begin.
COMMENT _ _ _ _ _ _ _ _ _ _ _ _ command
Beginning with the word comment, all text until the next statement terminator (; or $) is ignored.
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.
CONS _ _ _ _ _ _ _ _ _ _ _ _ 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.
<item> can be any REDUCE scalar expression, including a list; <list> must be a list.
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 val id if c is a list; b need not be a list. The list produced is {a,b,c}.
END _ _ _ _ _ _ _ _ _ _ _ _ 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.
EQUATION _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
FIRST _ _ _ _ _ _ _ _ _ _ _ _ operator
The first operator returns the first element of a list.
first(<list>) or first <list>
<list> must be a non-empty list to avoid an error message.
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
FOR _ _ _ _ _ _ _ _ _ _ _ _ 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 o r 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.
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.
FOREACH _ _ _ _ _ _ _ _ _ _ _ _ command
foreachis 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.
where <action> ::= do | product | sum | collect | join
foreach x in {q,r,s} sum x**2; 2 2 2 Q + R + S
GEQ _ _ _ _ _ _ _ _ _ _ _ _ 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 >=.
geq(<expression>,<expression>) or <expression> geq <expression>
<expression> can be any valid REDUCE expression that evaluates to a number.
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.
GOTO _ _ _ _ _ _ _ _ _ _ _ _ command
Inside a begin...end block, goto, or preferably, go to, transfers flow of control to a labeled statement.
go to<labeled_statement> or goto <labeled_statement >
<labeled_statement> is of the form <label> :<statement >
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 tocan 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.
GREATERP _ _ _ _ _ _ _ _ _ _ _ _ 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 >.
greaterp(<expression>,<expression>) or <expression> greaterp <expression>
<expression> can be any valid REDUCE expression that evaluates to a number.
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.
IF _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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 statemen t 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)
if<condition> then if <condition> the n <action> else <action>
which is equivalent to
if<condition> then (if <condition> then <action> else <action>);
_ _ _ (2)
if<condition> then <action> else if <condition> then <action> else <action>
which is equivalent to
if<condition> then <action> else
(if <condition> then <action> else <action>).
LIST _ _ _ _ _ _ _ _ _ _ _ _ operator
The list operator constructs a list from its arguments.
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.
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 wher e 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.
OR _ _ _ _ _ _ _ _ _ _ _ _ operator
The or binary logical operator returns true if either one or both of its arguments is true.
<logical expression> or <logical expression>
<logical expression> must evaluate to true or nil.
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.
PROCEDURE _ _ _ _ _ _ _ _ _ _ _ _ command
The procedure command allows you to define a mathematical operation as a function with arguments.
_ _ _ <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 d efault 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 activiti es in it.
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 va lue 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 blocks. 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 bef ore 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.
REPEAT _ _ _ _ _ _ _ _ _ _ _ _ command
The repeat command causes repeated execution of a statemen t until
the given condition is found to be true. The statement is always executed at least once.
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.
<<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
repeatmust 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.
REST _ _ _ _ _ _ _ _ _ _ _ _ operator
The rest operator returns a list containing all but the first element of the list it is given.
rest(<list>) or rest <list>
<list> must be a non-empty list, but need not have more than one element.
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; {}
RETURN _ _ _ _ _ _ _ _ _ _ _ _ command
The return command causes a value to be returned from inside a begin...end block.
<statements> can be any valid REDUCE statements. The value of <expression> is returned.
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 req uested, 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 blocks. 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-outermos t block, rather than all the way to the outside.
REVERSE _ _ _ _ _ _ _ _ _ _ _ _ operator
The reverse operator returns a list that is the reverse of the list it is given.
reverse(<list>) or reverse <list>
<list> must be a list.
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}
reverseand 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.
RULE _ _ _ _ _ _ _ _ _ _ _ _ type
A rule is an instruction to replace an algebraic expression or a part of an expression by another one.
<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 variables 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.
Rulesand 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.
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)
FREE 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 rules, 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 variables may occur.
OPTIONAL 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 variables 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
Optional free variables are allowed only in the left-h and sides of rules.
SECOND _ _ _ _ _ _ _ _ _ _ _ _ operator
The second operator returns the second element of a list.
second(<list>) or second <list>
<list> must be a list with at least two elements, to avoid an error message.
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
SET _ _ _ _ _ _ _ _ _ _ _ _ operator
The set operator is used for assignments when you want both sides of the assignment statement to be evaluated.
set(<restricted\_expression>,<expression>)
<expression> can be any REDUCE expression; <restricted\_expression> must be an identifier or an expression that evaluates to an identifier.
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.
SETQ _ _ _ _ _ _ _ _ _ _ _ _ operator
The setq operator is an infix or prefix binary assignment operator. It is identical to :=.
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.
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.
THIRD _ _ _ _ _ _ _ _ _ _ _ _ operator
The third operator returns the third item of a list.
third(<list>) or third <list>
<list> must be a list containing at least three items to avoid an error message.
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
WHEN _ _ _ _ _ _ _ _ _ _ _ _ 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
ARITHMETIC\_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.
ABS _ _ _ _ _ _ _ _ _ _ _ _ operator
The abs operator returns the absolute value of its argument.
<expression> can be any REDUCE scalar expression.
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 a n 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.
ADJPREC _ _ _ _ _ _ _ _ _ _ _ _ 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.
on rounded; 1.23456789012345; 1.23456789012 on adjprec; 1.23456789012345; *** precision increased to 15
ARG _ _ _ _ _ _ _ _ _ _ _ _ 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.
arg(3+4i) ARG(3 + 4*I) on rounded, complex; ws; 0.927295218002 arg a; ARG(A)
CEILING _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
ceiling 3.4; 4 fix 3.4; 3 ceiling(-5.2); -5 fix(-5.2); -5 ceiling a; CEILING(A)
CHOOSE _ _ _ _ _ _ _ _ _ _ _ _ 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
choose(2,3); 3 choose(3,2); CHOOSE(3,2) choose(a,b); CHOOSE(A,B)
DEG2DMS _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
deg2dms 60; DEG2DMS(60) on rounded; ws; {60,0,0} deg2dms 42.4; {42,23,60.0} deg2dms a; DEG2DMS(A)
DEG2RAD _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
deg2rad 60; DEG2RAD(60) on rounded; ws; 1.0471975512 deg2rad a; DEG2RAD(A)
DIFFERENCE _ _ _ _ _ _ _ _ _ _ _ _ operator
The difference operator may be used as either an infix or prefix binary subtraction operator. It is identical to - as a binary operator.
<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.
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.
DILOG _ _ _ _ _ _ _ _ _ _ _ _ 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)
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
DMS2DEG _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
dms2deg {42,3,7}; DMS2DEG({42,3,7}) on rounded; ws; 42.0519444444 dms2deg a; DMS2DEG(A)
DMS2RAD _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
dms2rad {42,3,7}; DMS2RAD({42,3,7}) on rounded; ws; 0.733944887421 dms2rad a; DMS2RAD(A)
FACTORIAL _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
factorial 4; 24 factorial 30 ; 265252859812191058636308480000000
FIX _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
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)
FIXP _ _ _ _ _ _ _ _ _ _ _ _ operator
The fixp logical operator returns true if its argument is an integer.
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.
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.
FLOOR _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
floor 3.4; 3 fix 3.4; 3 floor(-5.2); -6 fix(-5.2); -5 floor a; FLOOR(A)
EXPT _ _ _ _ _ _ _ _ _ _ _ _ operator
The expt operator is both an infix and prefix binary exponentiation operator. It is identical to ^ or **.
expt(<expression>,<expression>) or <expression> expt <expression>
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.
exptis 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.
GCD _ _ _ _ _ _ _ _ _ _ _ _ operator
The gcd operator returns the greatest common divisor of two polynomials.
gcd(<expression>,<expression>)
<expression> must be a polynomial (or integer), otherwise an error occurs.
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 mean s 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.
LN _ _ _ _ _ _ _ _ _ _ _ _ operator
<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.
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, use rs are advised to use log whenever possible.
LOG _ _ _ _ _ _ _ _ _ _ _ _ operator
The log operator returns the natural logarithm of its argument.
log(<expression>) or log <expression>
<expression> can be any valid scalar REDUCE expression.
log(x); LOG(X) log 4; LOG(4) log(e); 1 on rounded; log 4; 1.38629436112
logreturns 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.
LOGB _ _ _ _ _ _ _ _ _ _ _ _ operator
<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 .
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
MAX _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator max is an n-ary prefix operator, which returns the largest value in its arguments.
max(<expression>{,<expression>}*)
<expression> must evaluate to a number. max of an empty list returns 0.
max(4,6,10,-1); 10 <<a := 23;b := 2*a;c := 4**2;max(a,b,c)>>; 46 max(-5,-10,-a); -5
MIN _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator min is an n-ary prefix operator, which returns the smallest value in its arguments.
min(<expression>{,<expression>}*)
<expression> must evaluate to a number. min of an empty list returns 0.
min(-3,0,17,2); -3 <<a := 23;b := 2*a;c := 4**2;min(a,b,c)>>; 16 min(5,10,a); 5
MINUS _ _ _ _ _ _ _ _ _ _ _ _ operator
The minus operator is a unary minus, returning the negative of its argument. It is equivalent to the unary -.
minus(<expression>)
<expression> may be any scalar REDUCE expression.
minus(a); - A minus(-1); 1 minus((x+1)**4); 4 3 2 - (X + 4*X + 6*X + 4*X + 1)
NEXTPRIME _ _ _ _ _ _ _ _ _ _ _ _ operator
If the argument of nextprime is an integer, the least prime greater than that argument is returned. Otherwise, a type error results.
nextprime 5001; 5003 nextprime(10^30); 1000000000000000000000000000057 nextprime a; ***** A invalid as integer
NOCONVERT _ _ _ _ _ _ _ _ _ _ _ _ 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.
on rounded; 1.0000000000001; 1 on noconvert; 1.0000000000001; 1.0
NORM _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
norm (-2); NORM(-2) on rounded; ws; 2.0 norm(3+4i); NORM(4*I+3) on complex; ws; 5.0
PERM _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
perm(1,1); 1 perm(3,5); 60 perm(-3,5); PERM(-3,5) perm(a,b); PERM(A,B)
PLUS _ _ _ _ _ _ _ _ _ _ _ _ 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.
plus(<expression>,<expression>{,<expression>} *) or
<expression> plus <expression> {plus <expressio n>}*
<expression> can be any valid REDUCE expression, including matrix expressions of the same dimensions.
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
QUOTIENT _ _ _ _ _ _ _ _ _ _ _ _ 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 reciprocal operator. It is identical to / and slash.
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.
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.
RAD2DEG _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
rad2deg 1; RAD2DEG(1) on rounded; ws; 57.2957795131 rad2deg a; RAD2DEG(A)
RAD2DMS _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
rad2dms 1; RAD2DMS(1) on rounded; ws; {57,17,44.8062470964} rad2dms a; RAD2DMS(A)
RECIP _ _ _ _ _ _ _ _ _ _ _ _ operator
recip is the alphabetical name for the division operator / or slash used as a unary operator. The use of / is preferred.
recip a; 1 - A recip 2; 1 -- 2
REMAINDER _ _ _ _ _ _ _ _ _ _ _ _ operator
The remainder operator returns the remainder after its first argument is divided by its second argument.
<expression> can be any valid REDUCE polynomial, and is not limited to numeric values.
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.
ROUND _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
round 3.4; 3 round 3.5; 4 round a; ROUND(A)
SETMOD _ _ _ _ _ _ _ _ _ _ _ _ command
The setmod command sets the modulus value for subsequent modular arithmetic.
setmod<integer>
<integer> must be positive, and greater than 1. It need not be a prime number.
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
setmodreturns 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 th e operation is equivalent to dividing by 0. However, dividing by a factor of a non-prime modulus does not produce an error message.
SIGN _ _ _ _ _ _ _ _ _ _ _ _ operator
signtries 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.
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.
SQRT _ _ _ _ _ _ _ _ _ _ _ _ operator
The sqrt operator returns the square root of its argument.
sqrt(<expression>)
<expression> can be any REDUCE scalar expression.
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
sqrtchecks its argument for squared factors and removes t hem.
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.
TIMES _ _ _ _ _ _ _ _ _ _ _ _ operator
The times operator is an infix or prefix n-ary multiplication operator. It is identical to *.
<expression> times <expression> {times <express ion>}*
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.
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
BOOLEAN 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).
EQUAL _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator equal is an infix binary comparison operator. It is identical with =. It returns true if its two arguments are equal.
Equality is given between floating point numbers and integers that have the same value.
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.
EVENP _ _ _ _ _ _ _ _ _ _ _ _ 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.
<integer> must evaluate to an integer.
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.
FALSE
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.
FREEOF _ _ _ _ _ _ _ _ _ _ _ _ operator
The freeof logical operator returns true if its first argument does not contain its second argument anywhere in its structure.
freeof(<expression>,<kernel>) or <expression> freeof <kernel>
<expression> can be any valid scalar REDUCE expression, <kernel> mus t be a kernel expression (see kernel).
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.
LEQ _ _ _ _ _ _ _ _ _ _ _ _ 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 it s second argument. As an infix operator it is identical with <=.
leq(<expression>,<expression>) or <expression> leq <expression>
<expression> can be any valid REDUCE expression that evaluates to a number.
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.
LESSP _ _ _ _ _ _ _ _ _ _ _ _ operator
The lessp operator is a binary infix or prefix logical operator. It returns true if its first argument is strictly less than its s econd argument. As an infix operator it is identical with <.
lessp(<expression>,<expression>) or <expression> lessp <expression>
<expression> can be any valid REDUCE expression that evaluates to a number.
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.
MEMBER _ _ _ _ _ _ _ _ _ _ _ _ operator
memberis an infix binary comparison operator that evaluates to true if <expression> is equal to a member of the list <list>.
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.
NEQ _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator neq is an infix binary comparison operator. It returns true if its two arguments are not equal.
An inequality is satisfied between floating point numbers and integers that have the same value.
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.
NOT _ _ _ _ _ _ _ _ _ _ _ _ operator
The not operator returns true if its argument evaluates to nil, and nil if its argument is true .
not(<logical expression>)
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.
NUMBERP _ _ _ _ _ _ _ _ _ _ _ _ operator
The numberp operator returns true if its argument is a number, and nil otherwise.
numberp(<expression>) or numberp <expression>
<expression> can be any REDUCE scalar expression.
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, suc h as
if...then...else and while...do.
ORDP _ _ _ _ _ _ _ _ _ _ _ _ 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.
ordp(<expression1>,<expression2>)
<expression1> and <expression2> can be any valid REDUCE scalar expression.
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, suc h as
if...then...else and while...do.
PRIMEP _ _ _ _ _ _ _ _ _ _ _ _ operator
If <expression> evaluates to a integer, primep returns true
if <expression> is a prime number (i.e., a number other than 0 and plus or minus 1 which is only exactly divisible by itself or a unit) and nil otherwise. If <expression> does not have an integer value, a type error occurs.
if primep 3 then write "yes" else write "no"; YES if primep a then 1; ***** A invalid as integer
TRUE
Any value of the boolean part of a logical expression which is neither nil nor 0 is considered as true. Mos t builtin test and compare functions return t for true and nil for false.
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
BYE _ _ _ _ _ _ _ _ _ _ _ _ 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.
CONT _ _ _ _ _ _ _ _ _ _ _ _ command
The command cont returns control to an interactive file after a pause command that has been answered with n.
Suppose you are in the middle of an interactive file.
factorize(x**2 + 17*x + 60); {{X + 12,1},{X + 5,1}} pause; Cont? (Y or N) n saveas results; factor1 := first results; FACTOR1 := {X + 12,1} factor2 := second results; FACTOR2 := {X + 5,1} cont;
the file resumes
A pause allows you to enter your own REDUCE commands, ch ange switch values, inquire about results, or other such activities. When you wish to resume operation of the interactive file, use cont.
DISPLAY _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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.
LOAD\_PACKAGE _ _ _ _ _ _ _ _ _ _ _ _ command
The load_package command is used to load REDUCE packages, such as gentran that are not automatically loaded by the system.
load_package "<package\_name>"
A package is only loaded once; subsequent calls of load_package for the same package name are ignored.
PAUSE _ _ _ _ _ _ _ _ _ _ _ _ command
The pause command, given in an interactive file, stops operation and asks if you want to continue or not.
An interactive file is running, and at some point you see the question
Cont? (Y or N)
If you type
ykey{Return}
the file continues to run until the next pause or the end.
If you type
nkey{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.
pausedoes 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.
QUIT _ _ _ _ _ _ _ _ _ _ _ _ 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.
RECLAIM _ _ _ _ _ _ _ _ _ _ _ _ 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.
REDERR _ _ _ _ _ _ _ _ _ _ _ _ command
The rederr command allows you to print an error message from inside a procedure or a block statement. The calculation is gracefully terminated.
rederr<message>
<message> is an error message, usually inside double quotation marks (a string).
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.
RETRY _ _ _ _ _ _ _ _ _ _ _ _ command
The retry command allows you to retry the latest statement that resulte d in an error message.
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
retryremembers only the most recent statement that result ed in an error message. It allows you to stop and fix something obvious, then continue on your way without retyping the original command.
SAVEAS _ _ _ _ _ _ _ _ _ _ _ _ command
The saveas command saves the current workspace under the name of its argument.
saveas<identifier>
<identifier> can be any valid REDUCE identifier.
(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)}
saveasworks 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.
SHOWTIME _ _ _ _ _ _ _ _ _ _ _ _ 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.
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 wal l 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.
WRITE _ _ _ _ _ _ _ _ _ _ _ _ command
The write command explicitly writes its arguments to the output device (terminal or file).
write<item>{,<item>}*
<item> can be an expression, an assignment or a string enclosed in double quotation marks (").
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
APPEND _ _ _ _ _ _ _ _ _ _ _ _ operator
The append operator constructs a new list from the elements of its two arguments (which must be lists).
<list> must be a list, though it may be the empty list ({}). Any arguments beyond the first two are ignored.
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.
ARBINT _ _ _ _ _ _ _ _ _ _ _ _ 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.
solve(log(sin(x+3)),x); {X=2*ARBINT(1)*PI - ASIN(1) - 3, X=2*ARBINT(1)*PI + ASIN(1) + PI - 3}
ARBCOMPLEX _ _ _ _ _ _ _ _ _ _ _ _ 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.
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)}
ARGLENGTH _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator arglength returns the number of arguments of the top-level operator in its argument.
<expression> can be any valid REDUCE algebraic expression.
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 numb er 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.
COEFF _ _ _ _ _ _ _ _ _ _ _ _ operator
The coeff operator returns the coefficients of the powers of the specified variable in the given expression, in a list.
<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 r esults are returned in a list.
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.
COEFFN _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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.
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.
CONJ _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
conj(1+i); 1-I conj(a+i*b); REPART(A) - REPART(B)*I - IMPART(A)*I - IMPART(B)
CONTINUED_FRACTION _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
continued_fraction pi; 1146408 {-------,{3,7,15,1,292,1,1,1,2,1}} 364913 continued_fraction(pi,100); 22 {--,{3,7}} 7
DECOMPOSE _ _ _ _ _ _ _ _ _ _ _ _ operator
The decompose operator takes a multivariate polynomial as argument, and returns an expression and a list of equations from which the original polynomial can be found by composition.
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.
DEG _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator deg returns the highest degree of its variable argument found in its expression argument.
<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.
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
DEN _ _ _ _ _ _ _ _ _ _ _ _ operator
The den operator returns the denominator of its argument.
<expression> is ordinarily a rational expression, but may be any valid scalar REDUCE expression.
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
denreturns 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.
DF _ _ _ _ _ _ _ _ _ _ _ _ operator
The df operator finds partial derivatives with respect to one or more variables.
<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.
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 different iation 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.
EXPAND\_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.
EXPREAD _ _ _ _ _ _ _ _ _ _ _ _ operator
expreadreads one well-formed expression from the current input buffer and returns its value.
expread(); a+b; A + B
FACTORIZE _ _ _ _ _ _ _ _ _ _ _ _ operator
The factorize operator factors a given expression into a list of {factor,power} pairs.
factorize(<expression>)
<expression> should be a polynomial, otherwise an error will result.
fff := factorize(x^3 - y^3); 2 2 {{X + X*Y + Y ,1},{X - Y,1}} fac1 := first fff; 2 2 FAC1 := {{X + X*Y + Y ,1} factorize(x^15 - 1); 8 7 6 5 4 {{ X - X + X - X + X - X + 1,1}, 4 3 2 {X + X + X + X + 1,1}, 2 {X + X + 1,1}, {X - 1,1}} lastone := part(ws,length ws); LASTONE := {X - 1,1} setmod 2; 1 on modular; factorize(x^15 - 1); 4 3 2 {{X + X + X + X + 1,1}, 4 3 {X + X + 1,1}, 4 {X + X + 1,1}, 2 { X + X + 1,1}, {X + 1,1}}
The factorize command returns the factor,power pairs as a list. You can therefore use the usual list access methods ( first, second, third, rest, length and part) to extract these pairs.
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.
HYPOT _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
hypot(3,4); HYPOT(3,4) on rounded; ws; 5.0 hypot(a,b); HYPOT(A,B)
IMPART _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
impart(1+i); 1 impart(a+i*b); REPART(B) + IMPART(A)
INT _ _ _ _ _ _ _ _ _ _ _ _ operator
The int operator performs analytic integration on a variety of functions.
<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.
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 defaul t 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. Ev aluation 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.
INTERPOL _ _ _ _ _ _ _ _ _ _ _ _ operator
interpolgenerates an interpolation polynomial.
interpol(<values>,<variable>,<points>)
<values> and <points> are lists 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.
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 guarantee s a stable result even with rounded numbers and an ill-conditioned problem.
LCOF _ _ _ _ _ _ _ _ _ _ _ _ operator
The lcof operator returns the leading coefficient of a given expression with respect to a given variable.
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.
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 ret urns the expression.
LENGTH _ _ _ _ _ _ _ _ _ _ _ _ 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.
length(<expr>) or length <expr>
<expr> can be a list structure, an array, a matrix, or a scalar expression .
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. A n 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.
LHS _ _ _ _ _ _ _ _ _ _ _ _ operator
The lhs operator returns the left-hand side of an equation, such as those returned in a list by solve.
lhs(<equation>) or lhs <equation>
<equation> must be an equation of the form
left-hand side=right-hand side.
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
LIMIT _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
limit(x*cot(x),x,0); 0 limit((2x+5)/(3x-2),x,infinity); 2 -- 3
LPOWER _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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
LTERM _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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
MAINVAR _ _ _ _ _ _ _ _ _ _ _ _ operator
The mainvar operator returns the main variable (in the system's internal representation) of its argument.
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.
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.
MAP _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
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.
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.
MKID _ _ _ _ _ _ _ _ _ _ _ _ command
The mkid command constructs an identifier, given a stem and an identifi er or an integer.
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.
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 pro cedures. 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.
NPRIMITIVE _ _ _ _ _ _ _ _ _ _ _ _ operator
This operator returns the numerically-primitive part of any scalar expression. In other words, any overall integer factors in the expression are removed.
nprimitive((2x+2y)^2); 2 2 X + 2*X*Y + Y nprimitive(3*a*b*c); 3*A*B*C
NUM _ _ _ _ _ _ _ _ _ _ _ _ operator
The num operator returns the numerator of its argument.
num(<expression>) or num <simple\_expression>
<expression> can be any valid REDUCE scalar expression.
num(100/6); 50 num(a/5 + b/6); 6*A + 5*B num(sin(x)); SIN(X)
numreturns the numerator of the expression after it has b een 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.
ODESOLVE _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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.
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)}
ONE\_OF _ _ _ _ _ _ _ _ _ _ _ _ type
The operator one_of is used to represent an indefinite choice of one element from a finite set of objects.
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.
PART _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator part permits the extraction of various parts or operators of expressions and lists.
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).
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.
partworks 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.
partcan 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.
PF _ _ _ _ _ _ _ _ _ _ _ _ operator
pftransforms <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.
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 t he terms. Alternatively, one can use the operations on lists to extract any desired term.
PROD _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator prod returns the indefinite or definite product of a given expression.
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.
prod(k/(k-2),k); k*( - k + 1)
REDUCT _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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 ret urns 0.
REPART _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
repart(1+i); 1 repart(a+i*b); REPART(A) - IMPART(B)
RESULTANT _ _ _ _ _ _ _ _ _ _ _ _ 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.
resultant(<expression>,<expression>,<kernel>)
<expression> must be a polynomial containing <kernel> ; <kernel> must be a kernel.
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 f rom 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, an d a and b are free of x.
Error messages are given if resultant is given a non-polynomial expression, or a non-kernel variable.
RHS _ _ _ _ _ _ _ _ _ _ _ _ operator
The rhs operator returns the right-hand side of an equation, such as those returned in a list by solve.
rhs(<equation>) or rhs <equation>
<equation> must be an equation of the form left-hand side = right-hand side.
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.
ROOT\_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.
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.
SELECT _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
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.
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
SHOWRULES _ _ _ _ _ _ _ _ _ _ _ _ operator
showrulesreturns in rule-list form any operator rules associated with its argument.
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.
SOLVE _ _ _ _ _ _ _ _ _ _ _ _ operator
The solve operator solves a single algebraic equation or a system of simultaneous equations.
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 kernels follows, also in curly braces.
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 equations 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 o f 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.
_ _ _ allbranchswitch
_ _ _ arbvars switch
_ _ _ assumptions variable
_ _ _ fullroots switch
_ _ _ requirements variable
_ _ _ roots operator
_ _ _ root_of operator
_ _ _ trigform switch
_ _ _ varopt switch
SORT _ _ _ _ _ _ _ _ _ _ _ _ operator
The sort operator sorts the elements of a list according to an arbitrary comparison operator.
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>.
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 }
STRUCTR _ _ _ _ _ _ _ _ _ _ _ _ operator
The structr operator breaks its argument expression into named subexpressions.
<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.
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.
SUB _ _ _ _ _ _ _ _ _ _ _ _ operator
The sub operator substitutes a new expression for a kernel in an expression.
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.
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 th e sub operator.
SUM _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator sum returns the indefinite or definite summation of a given expression.
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.
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)
WS _ _ _ _ _ _ _ _ _ _ _ _ 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.
wsor ws(<number>)
<number> must be an integer between 1 and the current REDUCE prompt number .
(In the following examples, unlike most others, the nu mbered prompt is shown.)
1: df(sin y,y); COS(Y) 2: ws^2; 2 COS(Y) 3: df(ws 1,y); -SIN(Y)
wsand ws(<number>) can be used anywher e 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
ALGEBRAIC _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
ANTISYMMETRIC _ _ _ _ _ _ _ _ _ _ _ _ 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.
<identifier> is an identifier that has been declared as an operator.
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).
ARRAY _ _ _ _ _ _ _ _ _ _ _ _ declaration
The array declaration declares a list of identifiers to be of type array, and sets all their entries to 0.
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>}*.
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 bl ock 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 assignment 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.
CLEAR _ _ _ _ _ _ _ _ _ _ _ _ command
The clear command is used to remove assignments or remove substitution rules from any expression.
<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).
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 tak ing 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 exa mple under forall.
CLEARRULES _ _ _ _ _ _ _ _ _ _ _ _ command
The operator clearrules is used to remove previously defined rule lists from the system. <list> can be an exp licit rule list, or evaluate to a rule list.
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)
DEFINE _ _ _ _ _ _ _ _ _ _ _ _ command
The command define allows you to supply a new name for an identifier or replace it by any valid REDUCE expression.
<identifier> is any valid REDUCE identifier, <substitution> can be a number, an identifier, an operator, a reserved word, or an expression.
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 prece dence 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.
DEPEND _ _ _ _ _ _ _ _ _ _ _ _ declaration
dependdeclares that its first argument depends on the rest of its arguments.
<kernel> must be a legal variable name or a prefix operator (see kernel).
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.
EVEN _ _ _ _ _ _ _ _ _ _ _ _ declaration
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.
even f; f(-a) F(A) f(-a,-b) F(A,-B)
FACTOR _ _ _ _ _ _ _ _ _ _ _ _ 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.
factor<kernel> {,<kernel>}*
<kernel> must be a kernel or a list of kernels.
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 intere st 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.
Note that factor does not affect the order of its arguments. You should also use order if this is important.
FORALL _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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 for all...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 su bstitutions. 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 defin e 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 let sin(x)=0; has exactly that effect, and the usual definition for sin(x) has been lost for the remainder of the REDUCE session.
INFIX _ _ _ _ _ _ _ _ _ _ _ _ declaration
infixdeclares identifiers to be infix operators.
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.
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.
INTEGER _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
KORDER _ _ _ _ _ _ _ _ _ _ _ _ declaration
The korder declaration changes the internal canonical ordering of kernels.
korder<kernel>{,<kernel>}*
<kernel> must be a REDUCE kernel or a list of kernels.
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.
LET _ _ _ _ _ _ _ _ _ _ _ _ command
The let command defines general or specific substitution rules.
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.
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 .
let<list>{,<list>}+
<list> can be an explicit rule list, or evaluate to a rule list.
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 r ule 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.
letsubstitutions 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:
for all<vars> let<operator>(<vars>)=<block>
is an alternative to the
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);
awould 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.
LINEAR _ _ _ _ _ _ _ _ _ _ _ _ declaration
An operator can be declared linear in its first argument over powers of its second argument by the declaration linear.
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.
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.
LINELENGTH _ _ _ _ _ _ _ _ _ _ _ _ declaration
The linelength declaration sets the length of the output line. Default is 80.
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.
linelengthreturns the previous linelength. If you want the current linelength value, but not change it, say linelength nil.
LISP _ _ _ _ _ _ _ _ _ _ _ _ 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.
lisp; NIL car '(a b c d e); A algebraic; c := (lisp car '(first second))**2; 2 C := FIRST
LISTARGP _ _ _ _ _ _ _ _ _ _ _ _ declaration
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.
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 on e argument, no such distribution occurs, so listargp has no effect.
NODEPEND _ _ _ _ _ _ _ _ _ _ _ _ declaration
The nodepend declaration removes the dependency declared with depend.
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.
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 declar ed by depend.
MATCH _ _ _ _ _ _ _ _ _ _ _ _ command
The match command is similar to the let command, except that it matches only explicit powers in substitution.
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.
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 m atched 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 ex ecuted 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.
NONCOM _ _ _ _ _ _ _ _ _ _ _ _ declaration
noncomdeclares that already-declared operators are noncommutative under multiplication.
noncom<operator>{,<operator>}*
<operator> must have been declared an operator, or a warning message is given.
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.
NONZERO _ _ _ _ _ _ _ _ _ _ _ _ declaration
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.
odd f; f(0) 0 nonzero f; f(0) F(0)
ODD _ _ _ _ _ _ _ _ _ _ _ _ declaration
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.
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.
OFF _ _ _ _ _ _ _ _ _ _ _ _ command
The off command is used to turn switches off.
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.
ON _ _ _ _ _ _ _ _ _ _ _ _ command
The on command is used to turn switches on.
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.
OPERATOR _ _ _ _ _ _ _ _ _ _ _ _ declaration
Use the operator declaration to declare your own operators.
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.
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 noncommutative. 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 procedures, 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.
ORDER _ _ _ _ _ _ _ _ _ _ _ _ declaration
The order declaration changes the order of precedence of kernels for display purposes only.
order<identifier>{,<identifier>}*
<kernel> must be a valid kernel or operator name complete with argument or a list of such objects.
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
orderaffects 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 variable s 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.
PRECEDENCE _ _ _ _ _ _ _ _ _ _ _ _ declaration
The precedence declaration attaches a precedence to an infix operator.
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.
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 t he 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.
PRECISION _ _ _ _ _ _ _ _ _ _ _ _ declaration
The precision declaration sets the number of decimal places used when rounded is on. Default is system dependent, and normal ly about 12.
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.
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 pl aces 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.
PRINT\_PRECISION _ _ _ _ _ _ _ _ _ _ _ _ declaration
In rounded mode, numbers are normally printed to the spec ified precision. If the user wishes to print such numbers with less precision, the printing precision can be set by the declaration print_precision.
on rounded; 1/3; 0.333333333333 print_precision 5; 1/3 0.33333
REAL _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
REMFAC _ _ _ _ _ _ _ _ _ _ _ _ declaration
The remfac declaration removes the special factoring treatment of its arguments that was declared with factor.
remfac<kernel>{,<kernel>}+
<kernel> must be a kernel or operator name that was declared as special with the factor declaration.
SCALAR _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
SCIENTIFIC\_NOTATION _ _ _ _ _ _ _ _ _ _ _ _ declaration
<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.
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
SHARE _ _ _ _ _ _ _ _ _ _ _ _ declaration
The share declaration allows access to its arguments by both algebraic and symbolic modes.
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 matri x stored as lists of the individual elements. Access in symbolic mode is by the operators first, second, third and rest.
SYMBOLIC _ _ _ _ _ _ _ _ _ _ _ _ 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.
symbolic; NIL cdr '(a b c); (B C) algebraic; x + symbolic car '(y z); X + Y
SYMMETRIC _ _ _ _ _ _ _ _ _ _ _ _ declaration
When an operator is declared symmetric, its arguments are reordered to conform to the internal ordering of the system.
symmetric<identifier>{,<identifier>}*
<identifier> is an identifier that has been declared an operator.
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.
TR _ _ _ _ _ _ _ _ _ _ _ _ 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.
<name> is the name of a REDUCE system procedure or one of your own procedures.
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.
UNTR _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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.
VARNAME _ _ _ _ _ _ _ _ _ _ _ _ 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.
varname<identifier>
<identifier> can be any combination of one or more alphanumeric characters. Try to avoid REDUCE reserved words.
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
expwas turned off so that structr could show the structure. If exp had been on, the expression would have been expanded into a polynomial.
WEIGHT _ _ _ _ _ _ _ _ _ _ _ _ command
The weight command is used to attach weights to kernels for asymptotic constraints.
weight<kernel> =<number>
<kernel> must be a REDUCE kernel, <number> must be a positive integer, not 0.
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.
WHERE _ _ _ _ _ _ _ _ _ _ _ _ operator
The where operator provides an infix notation for one-time substitutions for kernels in expressions.
<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.
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.
wheregives 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.
WHILE _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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
WTLEVEL _ _ _ _ _ _ _ _ _ _ _ _ command
In conjunction with weight, wtlevel is used to implement asymptotic constraints. Its default value is 2.
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.
(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
wtlevelis 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
IN _ _ _ _ _ _ _ _ _ _ _ _ command
The in command takes a list of file names and inputs each file into the system.
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.
INPUT _ _ _ _ _ _ _ _ _ _ _ _ command
The input command returns the input expression to the REDUCE numbered prompt that is its argument.
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.
OUT _ _ _ _ _ _ _ _ _ _ _ _ command
The out command directs output to the filename that is its argument, until another out changes the output file, or shut closes it.
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 fo rm 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.
SHUT _ _ _ _ _ _ _ _ _ _ _ _ command
The shut command closes output files.
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
ACOS _ _ _ _ _ _ _ _ _ _ _ _ operator
The acos operator returns the arccosine of its argument.
<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.
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.
ACOSH _ _ _ _ _ _ _ _ _ _ _ _ operator
acoshrepresents 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.
<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.
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.
ACOT _ _ _ _ _ _ _ _ _ _ _ _ operator
acotrepresents 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.
<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.
ACOTH _ _ _ _ _ _ _ _ _ _ _ _ operator
acothrepresents 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.
<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.
ACSC _ _ _ _ _ _ _ _ _ _ _ _ operator
The acsc operator returns the arccosecant of its argument.
<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.
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 round ed is on and the argument has an absolute numeric value less than or equal to 1.
ACSCH _ _ _ _ _ _ _ _ _ _ _ _ operator
The acsch operator returns the hyperbolic arccosecant of its argument.
<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.
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 round ed is on and the argument has an absolute numeric value less than or equal to 1.
ASEC _ _ _ _ _ _ _ _ _ _ _ _ operator
The asec operator returns the arccosecant of its argument.
<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.
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 round ed is on and the argument has an absolute numeric value greater or equal to 1.
ASECH _ _ _ _ _ _ _ _ _ _ _ _ operator
asechrepresents 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.
<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.
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.
ASIN _ _ _ _ _ _ _ _ _ _ _ _ operator
The asin operator returns the arcsine of its argument.
<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.
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.
ASINH _ _ _ _ _ _ _ _ _ _ _ _ operator
The asinh operator returns the hyperbolic arcsine of its argument. The derivative of asinh and some simple transformations are known to the system.
<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.
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.
ATAN _ _ _ _ _ _ _ _ _ _ _ _ operator
The atan operator returns the arctangent of its argument.
<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.
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.
ATANH _ _ _ _ _ _ _ _ _ _ _ _ operator
The atanh operator returns the hyperbolic arctangent of its argument. The derivative of asinh and some simple transformations are known to the system.
<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.
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 switc h 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);
ATAN2 _ _ _ _ _ _ _ _ _ _ _ _ operator
<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.
atan2(3,2); ATAN2(3,2); on rounded; atan2(3,2); 0.982793723247 atan2(a,b); ATAN2(A,B); atan2(1,0); 1.57079632679
atan2returns a numeric value only if rounded is on. Then atan2 is calculated to the current degree of floating point precision.
COS _ _ _ _ _ _ _ _ _ _ _ _ operator
The cos operator returns the cosine of its argument.
<expression> is any valid scalar REDUCE expression, <simple\_expression> is a single identifier or begins with a prefix operator name.
cos abc; COS(ABC) cos(pi); -1 cos 4; COS(4) on rounded; cos(4); - 0.653643620864 cos log 5; - 0.0386319699339
cosreturns a numeric value only if rounded is on. Then the cosine is calculated to the current degree of floating point precision.
COSH _ _ _ _ _ _ _ _ _ _ _ _ operator
The cosh operator returns the hyperbolic cosine of its argument. The derivative of cosh and some simple transformations are known to the system.
<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.
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.
COT _ _ _ _ _ _ _ _ _ _ _ _ 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.
<expression> may be any scalar REDUCE expression. <simple\_expression > must be a single identifier or begin with a prefix operator name.
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 foun d by turning on the switch rounded.
COTH _ _ _ _ _ _ _ _ _ _ _ _ operator
The coth operator returns the hyperbolic cotangent of its argument. The derivative of coth and some simple transformations are known to the system.
<expression> may be any scalar REDUCE expression. <simple\_expression > must be a single identifier or begin with a prefix operator name.
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.
CSC _ _ _ _ _ _ _ _ _ _ _ _ operator
The csc operator returns the cosecant of its argument. The derivative of csc and some simple transformations are known to the system.
<expression> may be any scalar REDUCE expression. <simple\_expression > must be a single identifier or begin with a prefix operator name.
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.
CSCH _ _ _ _ _ _ _ _ _ _ _ _ operator
The cosh operator returns the hyperbolic cosecant of its argument. The derivative of csch and some simple transformations are known to the system.
<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.
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.
ERF _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
EXP _ _ _ _ _ _ _ _ _ _ _ _ operator
The exp operator returns e raised to the power of its argument .
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.
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.
SEC _ _ _ _ _ _ _ _ _ _ _ _ operator
The sec operator returns the secant of its argument.
<expression> is any valid scalar REDUCE expression, <simple\_expression> is a single identifier or begins with a prefix operator name.
sec abc; SEC(ABC) sec(pi); -1 sec 4; SEC(4) on rounded; sec(4); - 1.52988565647 sec log 5; - 25.8852966005
secreturns a numeric value only if rounded is on. Then the secant is calculated to the current degree of floating point precision.
SECH _ _ _ _ _ _ _ _ _ _ _ _ operator
The sech operator returns the hyperbolic secant of its argument.
<expression> is any valid scalar REDUCE expression, <simple\_expression> is a single identifier or begins with a prefix operator name.
sech abc; SECH(ABC) sech(0); 1 sech 4; SECH(4) on rounded; sech(4); 0.0366189934737 sech log 5; 0.384615384615
sechreturns a numeric value only if rounded is on. Then the expression is calculated to the current degree of floating point precision.
SIN _ _ _ _ _ _ _ _ _ _ _ _ operator
The sin operator returns the sine of its argument.
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.
sin aa; SIN(AA) sin(pi/2); 1 on rounded; sin 3; 0.14112000806 sin(pi/2); 1.0
sinreturns 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.
SINH _ _ _ _ _ _ _ _ _ _ _ _ operator
The sinh operator returns the hyperbolic sine of its argument. The derivative of sinh and some simple transformations are known to the system.
<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.
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.
TAN _ _ _ _ _ _ _ _ _ _ _ _ operator
The tan operator returns the tangent of its argument.
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.
tan a; TAN(A) tan(pi/5); PI TAN(--) 5 on rounded; tan(pi/5); 0.726542528005
tanreturns 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.
TANH _ _ _ _ _ _ _ _ _ _ _ _ operator
The tanh operator returns the hyperbolic tangent of its argument. The derivative of tanh and some simple transformations are known to the system.
<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.
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
SWITCHES _ _ _ _ _ _ _ _ _ _ _ _ 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.
ALGINT _ _ _ _ _ _ _ _ _ _ _ _ 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.
ALLBRANCH _ _ _ _ _ _ _ _ _ _ _ _ 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.
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 giv en 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.
ALLFAC _ _ _ _ _ _ _ _ _ _ _ _ switch
The allfac switch, when on, causes REDUCE to factor out automatically common products in the output of expressions. Default is on.
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.
ARBVARS _ _ _ _ _ _ _ _ _ _ _ _ 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 i n terms of some of the input variables. Default is on.
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 th at the equations given to solve imply no relation among the input variables.
BALANCED\_MOD _ _ _ _ _ _ _ _ _ _ _ _ switch
modularnumbers are normally produced in the range [0,. ..<n>), where <n> is the current modulus. With balanced_mod on, the range [-<n>/2,<n>/2], or more precisely [-floor((<n>-1)/2), ceiling((<n>-1)/2)], is used instead.
setmod 7; 1 on modular; 4; 4 on balanced_mod; 4; -3
BFSPACE _ _ _ _ _ _ _ _ _ _ _ _ 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.
on rounded; 1.2345678; 1.2345678 on bfspace; 1.2345678; 1.234 5678
bfspaceis normally off.
COMBINEEXPT _ _ _ _ _ _ _ _ _ _ _ _ switch
REDUCE is in general poor at surd simplification. However, when the switch combineexpt is on, the system attempts to combine exponentials whenever possible.
3^(1/2)*3^(1/3)*3^(1/6); 1/3 1/6 SQRT(3)*3 *3 on combineexpt; ws; 1
COMBINELOGS _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
COMP _ _ _ _ _ _ _ _ _ _ _ _ switch
When comp is on, any succeeding function definitions are compiled into a faster-running form. Default is off.
The following procedure finds Fibonacci numbers recurs ively. 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.
COMPLEX _ _ _ _ _ _ _ _ _ _ _ _ switch
When the complex switch is on, full complex arithmetic is used in simplification, function evaluation, and factorization. Default is off.
factorize(a**2 + b**2); 2 2 {{A + B ,1}} on complex; factorize(a**2 + b**2); {{A + I*B,1},{A - I*B,1}} (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.
CREF _ _ _ _ _ _ _ _ _ _ _ _ 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.
CRAMER _ _ _ _ _ _ _ _ _ _ _ _ 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.
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 u se. 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.
DEFN _ _ _ _ _ _ _ _ _ _ _ _ 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.
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 (c osh) 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;
DEMO _ _ _ _ _ _ _ _ _ _ _ _ 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.
DFPRINT _ _ _ _ _ _ _ _ _ _ _ _ switch
When dfprint is on, expressions in the differentiation operator df are printed in a more ``natural'' notation, with th e differentiation variables appearing as subscripts. In addition, if the switch noarg is on (the default), the arguments of the differentiated operator are suppressed.
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
DIV _ _ _ _ _ _ _ _ _ _ _ _ switch
When div is on, the system divides any simple factors found in the denominator of an expression into the numerator. Default is off.
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.
ECHO _ _ _ _ _ _ _ _ _ _ _ _ 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.
ERRCONT _ _ _ _ _ _ _ _ _ _ _ _ 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;
errcontoff, int on: Message is printed, and you are asked if you wish to continue. (This is the default behavior);
errconton, int off: Message is printed, and file continues to execute without pause;
Both on: Message is printed, and file continues to execute without pause.
EVALLHSEQP _ _ _ _ _ _ _ _ _ _ _ _ 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.
EXP _ _ _ _ _ _ _ _ _ _ _ _ switch
When the exp switch is on, powers and products of expressions are expanded. Default is on.
(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.
EXPANDLOGS _ _ _ _ _ _ _ _ _ _ _ _ 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 of f by default.
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.
EZGCD _ _ _ _ _ _ _ _ _ _ _ _ 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.
FACTOR _ _ _ _ _ _ _ _ _ _ _ _ switch
When the factor switch is on, input expressions and results are automatically factored.
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.
FAILHARD _ _ _ _ _ _ _ _ _ _ _ _ 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.
FORT _ _ _ _ _ _ _ _ _ _ _ _ switch
When fort is on, output is given Fortran-compatible syntax. Default is off.
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 th e fort switch. It produces Fortran (or C or Ratfor) code from REDUCE procedures or structured specifications, including facilities for producing double precision output.
FORTUPPER _ _ _ _ _ _ _ _ _ _ _ _ switch
When fortupper is on, any Fortran-style output appears in upper case. Default is off.
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)
FULLPREC _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
FULLROOTS _ _ _ _ _ _ _ _ _ _ _ _ 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.
GC _ _ _ _ _ _ _ _ _ _ _ _ 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. REDU CE does garbage collection when needed even if you have turned the notices off.
GCD _ _ _ _ _ _ _ _ _ _ _ _ switch
When gcd is on, common factors in numerators and denominators of expressions are canceled. Default is off.
(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 comm on 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.
HORNER _ _ _ _ _ _ _ _ _ _ _ _ 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.
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)))
IFACTOR _ _ _ _ _ _ _ _ _ _ _ _ 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.
factorize(4*x**2 + 28*x + 48); {{4,1},{X + 4,1},{X + 3,1}} factorize(22587); {{3,1},{7529,1}} on ifactor; factorize(4*x**2 + 28*x + 48); {{2,2},{X + 4,1},{X + 3,1}} factorize(22587); {{3,1},{7529,1}}
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 th e factor switch is on.
INT _ _ _ _ _ _ _ _ _ _ _ _ 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.
INTSTR _ _ _ _ _ _ _ _ _ _ _ _ switch
If intstr (for ``internal structure'') is on, arguments of an operator are printed in a more structured form.
operator f; f(2x+2y); F(2*X + 2*Y) on intstr; ws; F(2*(X + Y))
LCM _ _ _ _ _ _ _ _ _ _ _ _ switch
The lcm switch instructs REDUCE to compute the least common multiple of denominators whenever rational expressions occur. Default is on.
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 a re 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.
LESSSPACE _ _ _ _ _ _ _ _ _ _ _ _ switch
You can turn on the switch lessspace if you want fewer blank lines in your output.
LIMITEDFACTORS _ _ _ _ _ _ _ _ _ _ _ _ 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.
a := (y-x)^2*(y^3+2x*y+5)*(y^2-3x*y+7)$ factorize a; 2 {- 3*X*Y + Y + 7,1} 3 {2*X*Y + Y + 5,1}, {X - Y,2}} on limitedfactors; factorize a; 2 2 4 3 5 3 2 {- 6*X *Y - 3*X*Y + 2*X*Y - X*Y + Y + 7*Y + 5*Y + 35,1}, {X - Y,2}}
LIST _ _ _ _ _ _ _ _ _ _ _ _ switch
The list switch causes REDUCE to print each term in any sum on separate lines.
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)
LISTARGS _ _ _ _ _ _ _ _ _ _ _ _ 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.
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 operato r by using the declaration listargp. In addition, if an operator has more than one argument, no such distribution occurs, so listargs has no effect.
MCD _ _ _ _ _ _ _ _ _ _ _ _ switch
When mcd is on, sums and differences of rational expressions are put on a common denominator. Default is on.
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 nu mbers 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.
MODULAR _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
MSG _ _ _ _ _ _ _ _ _ _ _ _ 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.
MULTIPLICITIES _ _ _ _ _ _ _ _ _ _ _ _ switch
When solve is applied to a set of equations with multiple r oots, 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.
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;
NAT _ _ _ _ _ _ _ _ _ _ _ _ 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.
(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.
NERO _ _ _ _ _ _ _ _ _ _ _ _ switch
When nero is on, zero assignments (such as matrix elements) are not printed.
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
nerois often used when dealing with large sparse matrices, to avoid being overloaded with zero assignments.
NOARG _ _ _ _ _ _ _ _ _ _ _ _ switch
When dfprint is on, expressions in the differentiation oper ator df are printed in a more ``natural'' notation, with th e differentiation variables appearing as subscripts. When noarg is on (the default), the arguments of the differentiated operator are also suppressed.
operator f; df(f x,x); DF(F(X),X); on dfprint; ws; F X off noarg; ws; F(X) X
NOLNR _ _ _ _ _ _ _ _ _ _ _ _ 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.
NOSPLIT _ _ _ _ _ _ _ _ _ _ _ _ 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.
NUMVAL _ _ _ _ _ _ _ _ _ _ _ _ switch
With rounded on, elementary functions with numerical argume nts will return a numerical answer where appropriate. If you wish to inhibit this evaluation, numval should be turned off. It is normally on.
on rounded; cos 3.4; - 0.966798192579 off numval; cos 3.4; COS(3.4)
OUTPUT _ _ _ _ _ _ _ _ _ _ _ _ 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.
OVERVIEW _ _ _ _ _ _ _ _ _ _ _ _ switch
When overview is on, the amount of detail reported by the factorizer switches trfac and trallfac is reduced.
PERIOD _ _ _ _ _ _ _ _ _ _ _ _ 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.
PRECISE _ _ _ _ _ _ _ _ _ _ _ _ switch
When the precise switch is on, simplification of roots of even powers returns absolute values, a more precise answer mathematically. Default is on.
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 s urds 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.
PRET _ _ _ _ _ _ _ _ _ _ _ _ switch
When pret is on, input is printed in standard REDUCE format and then evaluated.
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 (whi ch 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.
PRI _ _ _ _ _ _ _ _ _ _ _ _ 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.
RAISE _ _ _ _ _ _ _ _ _ _ _ _ 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.
RAT _ _ _ _ _ _ _ _ _ _ _ _ switch
When the rat switch is on, and kernels have been selected to display with the factor declaration, the denominator is printed with ea ch term rather than one common denominator at the end of an expression.
(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.
RATARG _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
RATIONAL _ _ _ _ _ _ _ _ _ _ _ _ switch
When rational is on, polynomial expressions with rational coefficients are produced.
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.
RATIONALIZE _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
RATPRI _ _ _ _ _ _ _ _ _ _ _ _ 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.
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)
REVPRI _ _ _ _ _ _ _ _ _ _ _ _ switch
When the revpri switch is on, terms are printed in reverse order from the normal printing order.
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 a scending rather than descending order.
RLISP88 _ _ _ _ _ _ _ _ _ _ _ _ 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.
ROUNDALL _ _ _ _ _ _ _ _ _ _ _ _ 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.
on rounded; 1/2; 0.5 off roundall;
ROUNDBF _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.)
ROUNDED _ _ _ _ _ _ _ _ _ _ _ _ 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).
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.
SAVESTRUCTR _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
SOLVESINGULAR _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
TIME _ _ _ _ _ _ _ _ _ _ _ _ switch
When time is on, the system time used in executing each REDUCE statement is printed after the answer is printed.
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 beginnin g 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.
TRALLFAC _ _ _ _ _ _ _ _ _ _ _ _ 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 se nt to the factorizer automatically and trace information is generated. The out command saves the results of the factoring, but no t the trace.
TRFAC _ _ _ _ _ _ _ _ _ _ _ _ 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 no t the trace. The trallfac switch gives trace information to a greater level of detail.
TRIGFORM _ _ _ _ _ _ _ _ _ _ _ _ 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.
TRINT _ _ _ _ _ _ _ _ _ _ _ _ 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.
TRNONLNR _ _ _ _ _ _ _ _ _ _ _ _ switch
When trnonlnr is on, a narrative tracing various steps in the process for solving non-linear equations is produced.
trnonlnrcan 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.
VAROPT _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
COFACTOR _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
DET _ _ _ _ _ _ _ _ _ _ _ _ operator
The det operator returns the determinant of its (square matrix) argument.
<expression> must evaluate to a square matrix.
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. Howev er, given a variable name that has not been declared of type matrix, or a non-square matrix, det returns an error message.
MAT _ _ _ _ _ _ _ _ _ _ _ _ operator
The mat operator is used to represent a two-dimensional matrix.
mat((<expr>{,<expr>}*) {(<expr>{,<expr >}*)}*)
<expr> may be any valid REDUCE scalar expression.
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.
MATEIGEN _ _ _ _ _ _ _ _ _ _ _ _ operator
The mateigen operator calculates the eigenvalue equation and the corresponding eigenvectors of a matrix.
mateigen(<matrix-id>,<tag-id>)
<matrix-id> must be a declared matrix of values, and <tag-id> must b e a legal REDUCE identifier.
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.
MATRIX _ _ _ _ _ _ _ _ _ _ _ _ declaration
Identifiers are declared to be of type matrix.
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.
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 c annot 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.
NULLSPACE _ _ _ _ _ _ _ _ _ _ _ _ operator
<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.
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 lengt h 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.
RANK _ _ _ _ _ _ _ _ _ _ _ _ operator
rankcalculates the rank of its matrix argument.
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.
TP _ _ _ _ _ _ _ _ _ _ _ _ operator
The tp operator returns the transpose of its matrix argument.
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.
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 ident ifier on the left-hand side is redimensioned to the correct size for the transpose.
TRACE _ _ _ _ _ _ _ _ _ _ _ _ operator
The trace operator finds the trace of its matrix argument.
trace(<expression>) or trace <simple\_expression>
<expression> or <simple\_expression> must evaluate to a square matrix.
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
GROEBNER 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.
IDEAL 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 kernels 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>,...} .
TERM 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.
TORDER _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator torder sets the actual variable sequence and term order.
1. simple term order:
torder(<vl>, <m>)
where <vl> is a list of variables ( kernels) and <m> is the name of a simple term order mode lex term order, gradlex term order, revgradlex term order or another implemented parameter less mode.
2. stepped term order:
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
torder(<vl>, weighted, <n>,<n>,...);
where the <n> are positive integers, see weighted term order.
4. matrix term order
torder(<vl>, matrix, <m>);
where <m> is a matrix with integer elements, see torder_compile.
5. compiled term order
torder(<vl>, co);
where <co> is the name of a routine generated by torder_compile.
tordersets 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.
TORDER_COMPILE _ _ _ _ _ _ _ _ _ _ _ _ operator
A matrix can be converted into a compilable LISP program for faster execution by using
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.
LEX 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.
GRADLEX 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.
REVGRADLEX 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.
GRADLEXGRADLEX 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.
GRADLEXREVGRADLEX TERM ORDER
Similar to gradlexgradlex term order, but using revgradlex term order for the second group.
LEXGRADLEX TERM ORDER
Similar to gradlexgradlex term order, but using lex term order for the first group.
LEXREVGRADLEX TERM ORDER
Similar to gradlexgradlex term order, but using lex term order for the first group revgradlex term order for the second group.
WEIGHTED 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.
GRADED 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.
MATRIX 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
GVARS _ _ _ _ _ _ _ _ _ _ _ _ operator
gvars({<exp>,<exp>,... })
where <exp> are expressions or equations.
gvarsextracts from the expressions the kernels which can play the role of variables for a groebner or groebnerf calculation.
GROEBNER _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
groebner({x**2+y**2-1,x-y}) {X - Y,2*Y**2 -1}
_ _ _ groebnerfoperator
_ _ _ 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
GROEBNER\_WALK _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator groebner_walk computes a lex basis from a given graded (or weighted) one.
groebner_walk(<g>)
where <g> is a graded basis (or weighted basis with a weight vector with one repeated element) of the polynomial ideal. Groebner_walk computes a sequence of monomial bases, each time lifting the full system to a complete basis. Groebner_walk should be called only in cases, where a normal kex computation would take too much computer time.
The operator torder has to be called before in order to define the variable sequence and the term order mode of <g>.
The variable gvarslast is not set.
Do not call groebner_walk with on groebopt.
Groebner_walkincludes some overhead (such as e. g. computation with division). On the other hand, sometimes groebner_walk is faster than a direct lex computation.
GROEBOPT _ _ _ _ _ _ _ _ _ _ _ _ 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.
guarantees that a will be placed in front of x and y.
GVARSLAST _ _ _ _ _ _ _ _ _ _ _ _ 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.
GROEBPREREDUCE _ _ _ _ _ _ _ _ _ _ _ _ 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.
GROEBFULLREDUCTION _ _ _ _ _ _ _ _ _ _ _ _ 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.
GLTBASIS _ _ _ _ _ _ _ _ _ _ _ _ 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.
GLTB _ _ _ _ _ _ _ _ _ _ _ _ variable
See gltbasis
GLTERMS _ _ _ _ _ _ _ _ _ _ _ _ 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.
GROEBSTAT _ _ _ _ _ _ _ _ _ _ _ _ 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.
TRGROEB _ _ _ _ _ _ _ _ _ _ _ _ switch
if trgroeb is on, intermediate H polynomials are printed during a groebner or groebnerf calculation.
TRGROEBS _ _ _ _ _ _ _ _ _ _ _ _ switch
if trgroebs is on, intermediate H and S polynomials are printed during a groebner or groebnerf calculation.
GZERODIM? _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
GDIMENSION _ _ _ _ _ _ _ _ _ _ _ _ operator
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
GINDEPENDENT\_SETS _ _ _ _ _ _ _ _ _ _ _ _ operator
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_setscomputes 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.
DD_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:
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.
GLEXCONVERT _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
GREDUCE _ _ _ _ _ _ _ _ _ _ _ _ operator
greduce(exp, {exp1, exp2, ... , expm})
where exp is an expression, and {exp1, exp2, ... , expm} is a list of expressions or equations.
greduceis functionally equivalent with a call to groebner and then a call to preduce.
PREDUCE _ _ _ _ _ _ _ _ _ _ _ _ operator
preduce(<p>, {<exp>, ... })
where <p> is an expression, and {<exp>, ... } is a list of expressions or equations.
Preducecomputes 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.
IDEALQUOTIENT _ _ _ _ _ _ _ _ _ _ _ _ operator
idealquotient({<exp>, ...}, <d>)
where {<exp>,...} is a list of expressions or equations, <d> is a single expression or equation.
Idealquotientcomputes 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.
HILBERTPOLYNOMIAL _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
SATURATION _ _ _ _ _ _ _ _ _ _ _ _ operator
saturation({<exp>, ...}, <p>)
where {<exp>,...} is a list of expressions or equations, <p> is a single polynomial.
Saturationcomputes the quotient of the polynomial <p> and a power (with unknown but finite exponent) of the ideal built from {<exp>, ...}. The result is the computed quotient. Saturation calls idealquotient several times until the result does not change any more.
Basic Groebner operators
GROEBNERF _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
groebnerftries 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.
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}}
_ _ _ groebresmaxvariable
_ _ _ 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
GROEBMONFAC _ _ _ _ _ _ _ _ _ _ _ _ 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 lowe red 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.
GROEBRESMAX _ _ _ _ _ _ _ _ _ _ _ _ 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.
GROEBRESTRICTION _ _ _ _ _ _ _ _ _ _ _ _ variable
During groebnerf calculations irrelevant branches can be excluded by setting the variable groebrestriction. The following restrictions are implemented:
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
GROEBPROT _ _ _ _ _ _ _ _ _ _ _ _ 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.
GROEBPROTFILE _ _ _ _ _ _ _ _ _ _ _ _ variable
See groebprot switch.
GROEBNERT _ _ _ _ _ _ _ _ _ _ _ _ operator
groebnert({<v>=<exp>,...})
where <v> are kernels (simple or indexed variables), <exp> are polynomials.
groebnertis 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>
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}
PREDUCET _ _ _ _ _ _ _ _ _ _ _ _ operator
preduce(<p>,{<v>=<exp>...})
where <p> is an expression, <v> are kernels (simple or indexed variables), exp are polynomials.
preducetcomputes the remainder of <p> modulo {<exp>,...} similar to preduce, but the result is an equation which expresses the remainder as combination of the polynomials.
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
MODULE
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.
GMODULE _ _ _ _ _ _ _ _ _ _ _ _ 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
GSORT _ _ _ _ _ _ _ _ _ _ _ _ operator
where <p> is a polynomial or a list of polynomials.
The polynomials are reordered and sorted corresponding to the current term order.
torder lex; gsort(x**2+2x*y+y**2,{y,x}); y**2+2y*x+x**2
GSPLIT _ _ _ _ _ _ _ _ _ _ _ _ operator
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.
torder lex; gsplit(x**2+2x*y+y**2,{y,x}); {y**2,2y*x+x**2}
GSPOLY _ _ _ _ _ _ _ _ _ _ _ _ operator
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
Groebner package
HEPHYS _ _ _ _ _ _ _ _ _ _ _ _ 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.
. _ _ _ HE-DOT _ _ _ _ _ _ _ _ _ _ _ _ operator
The . operator is used to denote the scalar product of two Lorentz four-vectors.
<vector> . <vector>
<vector> must be an identifier declared to be of type vector to h ave the scalar product definition. When applied to arguments that are not vectors, the cons operator is used, whose symbol is also ``dot.''
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.
EPS _ _ _ _ _ _ _ _ _ _ _ _ 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.
eps(<vector-expr>,<vector-expr>,<vector-expr>, <vector-expr>)
<vector-expr> must be a valid vector expression, and may be an index.
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 o dd 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.
G _ _ _ _ _ _ _ _ _ _ _ _ operator
g is an n-ary operator used to denote a product of gamma matrices contracted with Lorentz four-vectors, in high-energy physics.
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.
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 de note 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 trace s, 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>.
INDEX _ _ _ _ _ _ _ _ _ _ _ _ declaration
The declaration index flags a four-vector as an index for subsequent high-energy physics calculations.
index<vector-id>{,<vector-id>}*
<vector-id> must have been declared of type vector.
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.
MASS _ _ _ _ _ _ _ _ _ _ _ _ command
The mass command associates a scalar variable as a mass with the corresponding vector variable, in high-energy physics calculations.
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.
vector bb,cc; mass cc=m; mshell cc; cc.cc; 2 M
Once a mass has been attached to a vector with a mass dec laration, the mshell declaration puts the associated particle ``on t he mass shell.'' Subsequent scalar (.) products of the vector with itself will be replaced by the square of the mass expression.
MSHELL _ _ _ _ _ _ _ _ _ _ _ _ command
The mshell command puts particles on the mass shell in high-energy physics calculations.
mshell<vector-var>{,<vector-var>}*
<vector-var> must have had a mass attached to it by a mass declaration.
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.
NOSPUR _ _ _ _ _ _ _ _ _ _ _ _ declaration
The nospur declaration prevents the trace calculation over the given line identifiers in high-energy physics calculations.
nospur<line-id>{,<line-id>}*
<line-id> is a scalar identifier that will be used as a line identifier.
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.
REMIND _ _ _ _ _ _ _ _ _ _ _ _ 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.
remind<identifier>{,<identifier>}*
<identifier> must have been declared to be of type index.
SPUR _ _ _ _ _ _ _ _ _ _ _ _ declaration
The spur declaration removes the special exemption from trace calculations that was declared by nospur, in high-energy physics calculations.
spur<line-id>{,<line-id>}*
<line-id> must be a line-identifier that has previously been declared nospur.
VECDIM _ _ _ _ _ _ _ _ _ _ _ _ command
The command vecdim changes the vector dimension from 4 to an arbitrary integer or symbol. Used in high-energy physics calculations.
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.
VECTOR _ _ _ _ _ _ _ _ _ _ _ _ declaration
The vector declaration declares that its arguments are of type vect or.
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 componen t of the vector V1.
Identifiers that are declared by the index and mass declaratio ns 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 expressionsYou have tried to use A i n some way other than gamma5 in a high-energy physics expression.
Gamma5 not allowed unless vecdim is 4You have used gamma_5 in a high-en ergy 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 operatorA line symbol is missing in a gamma mat rix 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
NUMERIC 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.
INTERVAL _ _ _ _ _ _ _ _ _ _ _ _ type
Intervals are generally coded as lower bound and upper bound connected by the operator .., usually associated to a variable in an equation.
where <var> is a kernel and <low>, <high> are numbers or expression which evaluate to numbers with <low><=<high >.
means that the variable x is taken in the range from 2 .5 up to 3.5.
NUMERIC ACCURACY
The keyword parameters accuracy=a and iterations=i, where aand 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.
TRNUMERIC _ _ _ _ _ _ _ _ _ _ _ _ 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.
NUM_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.
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_mintries 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 equations, where the variables are equated to the coordinates of the result point.
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}}
NUM_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.
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_solvetries 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.
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 ]
NUM_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).
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.
num_int(sin x,x=(0 .. 3.1415926)); 2.0000010334
NUM_ODESOLVE _ _ _ _ _ _ _ _ _ _ _ _ operator
The Runge-Kutta method of order 3 finds an approximate graph for the solution of real ODE initial value problem.
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.
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.
BOUNDS _ _ _ _ _ _ _ _ _ _ _ _ operator
Upper and lower bounds of a real valued function over an interval or a rectangular multivariate domain are comp uted 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.
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 intervals.
boundscomputes upper and lower bounds for the expression in the given area. An interval is returned.
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
CHEBYSHEV 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 an d 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.
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.
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
NUM_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.
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.
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
ROOTS 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.
MKPOLY _ _ _ _ _ _ _ _ _ _ _ _ operator
Given a roots list as returned by roots, the operator mkpoly constructs a polynomial which has these numbers as roots.
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.
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.
NEARESTROOT _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator nearestroot finds one root of a polynomial with an iteration using a given starting point.
where <p> is a univariate polynomial and <pt> is a number.
nearestroot(x^2+2,2); {x=1.41421*i}
The minimal accuracy of the result values is controlled by rootacc.
REALROOTS _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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.
ROOTACC _ _ _ _ _ _ _ _ _ _ _ _ operator
The operator rootacc allows you to set the accuracy up to which the roots package computes its results.
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.
ROOTS _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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.
ROOT\_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.
roots(<p>)
where <p> is a univariate polynomial.
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}
ROOTSCOMPLEX _ _ _ _ _ _ _ _ _ _ _ _ variable
When the operator roots is called the complex roots are collected in the global variable rootscomplex as list.
ROOTSREAL _ _ _ _ _ _ _ _ _ _ _ _ variable
When the operator roots is called the real roots are collected in the global variable rootreal as list.
Roots Package
SPECIAL 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.
showrulesBesseli;
.
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;
CONSTANTS
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 recipro cal powers)
on rounded; Euler_Gamma; 0.577215664902 Khinchin; 2.68545200107 Catalan 0.915965594177 Golden_Ratio 1.61803398875
BERNOULLI _ _ _ _ _ _ _ _ _ _ _ _ operator
The bernoulli operator returns the nth Bernoulli number.
bernoulli 20; - 174611 / 330 bernoulli 17; 0
All Bernoulli numbers with odd indices except for 1 are zero.
BERNOULLIP _ _ _ _ _ _ _ _ _ _ _ _ operator
The BernoulliP operator returns the nth Bernoulli Polynomial evaluated at x.
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 Bernoull i number.
EULER _ _ _ _ _ _ _ _ _ _ _ _ operator
The EULER operator returns the nth Euler number.
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).
EULERP _ _ _ _ _ _ _ _ _ _ _ _ operator
The EulerP operator returns the nth Euler Polynomial.
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.
ZETA _ _ _ _ _ _ _ _ _ _ _ _ operator
The Zeta operator returns Riemann's Zeta function,
Zeta (z) := sum(1/(k**z),k,1,infinity)
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
BESSELJ _ _ _ _ _ _ _ _ _ _ _ _ operator
The BesselJ operator returns the Bessel function of the first kind.
BesselJ(1/2,pi); 0 on rounded; BesselJ(0,1); 0.765197686558
BESSELY _ _ _ _ _ _ _ _ _ _ _ _ operator
The BesselY operator returns the Bessel function of the second kind.
BesselY(<order>,<argument>)
BesselY (1/2,pi); - sqrt(2) / pi on rounded; BesselY (1,3); 0.324674424792
The operator BesselY is also called Weber's function.
HANKEL1 _ _ _ _ _ _ _ _ _ _ _ _ operator
The Hankel1 operator returns the Hankel function of the first kind.
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 th e third kind. There is currently no numeric evaluation of Hankel functions.
HANKEL2 _ _ _ _ _ _ _ _ _ _ _ _ operator
The Hankel2 operator returns the Hankel function of the second kind.
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 th e third kind. There is currently no numeric evaluation of Hankel functions.
BESSELI _ _ _ _ _ _ _ _ _ _ _ _ operator
The BesselI operator returns the modified Bessel function I.
on rounded; Besseli (1,1); 0.565159103992
The knowledge about the operator BesselI is currently fai rly limited.
BESSELK _ _ _ _ _ _ _ _ _ _ _ _ operator
The BesselK operator returns the modified Bessel function K.
df(besselk(0,x),x); - besselk(1,x)
There is currently no numeric support for the operator BesselK .
STRUVEH _ _ _ _ _ _ _ _ _ _ _ _ operator
The StruveH operator returns Struve's H function.
struveh(-3/2,x); - besselj(3/2,x) / i
STRUVEL _ _ _ _ _ _ _ _ _ _ _ _ operator
The StruveL operator returns the modified Struve L function .
struvel(-3/2,x); besseli(3/2,x)
KUMMERM _ _ _ _ _ _ _ _ _ _ _ _ operator
The KummerM operator returns Kummer's M function.
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 functio ns. For reference see the hypergeometric operator.
KUMMERU _ _ _ _ _ _ _ _ _ _ _ _ operator
The KummerU operator returns Kummer's U function.
df(kummeru(1,1,x),x) - kummeru(2,2,x)
Kummer's U function is one of the Confluent Hypergeometric functio ns. For reference see the hypergeometric operator.
WHITTAKERW _ _ _ _ _ _ _ _ _ _ _ _ operator
The WhittakerW operator returns Whittaker's W function.
WhittakerW(2,2,2); 1 4*sqrt(2)*kummeru(-,5,2) 2 ------------------------- e
Whittaker's W function is one of the Confluent Hypergeometric func tions. For reference see the hypergeometric operator.
Bessel Functions
AIRY_AI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Airy_Ai operator returns the Airy Ai function for a given argument.
on complex; on rounded; Airy_Ai(0); 0.355028053888 Airy_Ai(3.45 + 17.97i); - 5.5561528511e+9 - 8.80397899932e+9*i
AIRY_BI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Airy_Bi operator returns the Airy Bi function for a given argument.
Airy_Bi(0); 0.614926627446 Airy_Bi(3.45 + 17.97i); 8.80397899932e+9 - 5.5561528511e+9*i
AIRY_AIPRIME _ _ _ _ _ _ _ _ _ _ _ _ operator
The Airy_Aiprime operator returns the Airy Aiprime function for a given argument.
Airy_Aiprime(0); - 0.258819403793 Airy_Aiprime(3.45+17.97i); - 3.83386421824e+19 + 2.16608828136e+19*i
AIRY_BIPRIME _ _ _ _ _ _ _ _ _ _ _ _ operator
The Airy_Biprime operator returns the Airy Biprime function for a given argument.
Airy_Biprime(0); Airy_Biprime(3.45 + 17.97i); 3.84251916792e+19 - 2.18006297399e+19*i
Airy Functions
JACOBISN _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobisn operator returns the Jacobi Elliptic function sn.
Jacobisn(0.672, 0.36) 0.609519691792 Jacobisn(1,0.9) 0.770085724907881
JACOBICN _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobicn operator returns the Jacobi Elliptic function cn.
Jacobicn(7.2, 0.6) 0.837288298482018 Jacobicn(0.11, 19) 0.994403862690043 - 1.6219006985556e-16*i
JACOBIDN _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobidn operator returns the Jacobi Elliptic function dn.
Jacobidn(15, 0.683) 0.640574162024592 Jacobidn(0,0) 1
JACOBICD _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobicd operator returns the Jacobi Elliptic function cd.
Jacobicd(1, 0.34) 0.657683337805273 Jacobicd(0.8,0.8) 0.925587311582301
JACOBISD _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobisd operator returns the Jacobi Elliptic function sd.
Jacobisd(12, 0.4) 0.357189729437272 Jacobisd(0.35,1) - 1.17713873203043
JACOBIND _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobind operator returns the Jacobi Elliptic function nd.
Jacobind(0.2, 17) 1.46553203037507 + 0.0000000000334032759313703*i Jacobind(30, 0.001) 1.00048958438
JACOBIDC _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobidc operator returns the Jacobi Elliptic function dc.
Jacobidc(0.003,1) 1 Jacobidc(2, 0.75) 6.43472885111
JACOBINC _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobinc operator returns the Jacobi Elliptic function nc.
Jacobinc(1,0) 1.85081571768093 Jacobinc(56, 0.4387) 39.304842663512
JACOBISC _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobisc operator returns the Jacobi Elliptic function sc.
Jacobisc(9, 0.88) - 1.16417697982095 Jacobisc(0.34, 7) 0.305851938390775 - 9.8768100944891e-12*i
JACOBINS _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobins operator returns the Jacobi Elliptic function ns.
Jacobins(3, 0.9) 1.00945801599785 Jacobins(0.887, 15) 0.683578280513975 - 0.85023411082469*i
JACOBIDS _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobisn operator returns the Jacobi Elliptic function ds.
Jacobids(98,0.223) - 1.061253961477 Jacobids(0.36,0.6) 2.76693172243692
JACOBICS _ _ _ _ _ _ _ _ _ _ _ _ operator
The Jacobics operator returns the Jacobi Elliptic function cs.
Jacobics(0, 0.767) infinity Jacobics(1.43, 0) 0.141734127352112
JACOBIAMPLITUDE _ _ _ _ _ _ _ _ _ _ _ _ operator
The JacobiAmplitude operator returns the amplitude of u.
JacobiAmplitude(<expression>,<integer>)
JacobiAmplitude(7.239, 0.427) 0.0520978301448978 JacobiAmplitude(0,0.1) 0
Amplitude u = asin(Jacobisn(u,m))
AGM_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.
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).
LANDENTRANS _ _ _ _ _ _ _ _ _ _ _ _ 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.
landentrans(<expression>,<integer>)
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.
ELLIPTICF _ _ _ _ _ _ _ _ _ _ _ _ operator
The EllipticF operator returns the Elliptic Integral of the First Kind.
EllitpicF(<expression>,<integer>)
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.
ELLIPTICK _ _ _ _ _ _ _ _ _ _ _ _ operator
The EllipticK operator returns the Elliptic value K.
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.
ELLIPTICKPRIME _ _ _ _ _ _ _ _ _ _ _ _ operator
The EllipticK' operator returns the Elliptic value K(m).
EllipticKprime(0.2) 2.25720532682085 EllipticKprime(4.3) 1.05562492399206 EllipticKprime(0.000481) 5.206621921966
The EllipticKprime function is the Complete Elliptic Inte gral of the First Kind of (1-m).
ELLIPTICE _ _ _ _ _ _ _ _ _ _ _ _ operator
The EllipticE operator used with two arguments returns the Elliptic Integral of the Second Kind.
EllipticE(<expression>,<integer>)
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.
EllipticE(<integer>)
EllipticE(0.22) 1.48046637439519 EllipticE(pi/2, 0.22) 1.48046637439519
ELLIPTICTHETA _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
JACOBIZETA _ _ _ _ _ _ _ _ _ _ _ _ operator
The JacobiZeta operator returns the Jacobian function Zeta.
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 The ta. But it is significantly different from Riemann's Zeta Function Zeta.
Jacobi's Elliptic Functions and Elliptic Integrals
POCHHAMMER _ _ _ _ _ _ _ _ _ _ _ _ operator
The Pochhammer operator implements the Pochhammer notation (shifted factorial).
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, be cause 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;
GAMMA _ _ _ _ _ _ _ _ _ _ _ _ operator
The Gamma operator returns the Gamma function.
gamma(10); 362880 gamma(1/2); sqrt(pi)
BETA _ _ _ _ _ _ _ _ _ _ _ _ operator
The Beta operator returns the Beta function defined by
Beta (z,w) := defint(t**(z-1)* (1 - t)**(w-1),t,0,1) .
Beta(2,2); 1 / 6 Beta(x,y); gamma(x)*gamma(y) / gamma(x + y)
The operator Beta is simplified towards the GAMMA operator.
PSI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Psi operator returns the Psi (or DiGamma) function.
Psi(x) := df(Gamma(z),z)/ Gamma (z)
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).
POLYGAMMA _ _ _ _ _ _ _ _ _ _ _ _ operator
The Polygamma operator returns the Polygamma function.
Polygamma(n,x) := df(Psi(z),z,n);
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
DILOG EXTENDED _ _ _ _ _ _ _ _ _ _ _ _ operator
The package specfn supplies an extended support for the dilog operator which implements the dilogarithm fu nction.
dilog(x) := - defint(log(t)/(t - 1),t,1,x);
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.
LAMBERT\_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.
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
CHEBYSHEVT _ _ _ _ _ _ _ _ _ _ _ _ operator
The ChebyshevT operator computes the nth Chebyshev T Polynomial (of the first kind).
ChebyshevT(3,xx); 2 xx*(4*xx - 3) ChebyshevT(3,4); 244
Chebyshev's T polynomials are computed using the recurrence relati on:
ChebyshevT(n,x) := 2x*ChebyshevT(n-1,x) - ChebyshevT(n-2,x) with
ChebyshevT(0,x) := 0 and ChebyshevT(1,x) := x
CHEBYSHEVU _ _ _ _ _ _ _ _ _ _ _ _ operator
The ChebyshevU operator returns the nth Chebyshev U Polynomial (of the second kind).
ChebyshevU(3,xx); 2 4*x*(2*x - 1) ChebyshevU(3,4); 496
Chebyshev's U polynomials are computed using the recurrence relati on:
ChebyshevU(n,x) := 2x*ChebyshevU(n-1,x) - ChebyshevU(n-2,x) with
ChebyshevU(0,x) := 0 and ChebyshevU(1,x) := 2x
HERMITEP _ _ _ _ _ _ _ _ _ _ _ _ operator
The HermiteP operator returns the nth Hermite Polynomial.
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
LAGUERREP _ _ _ _ _ _ _ _ _ _ _ _ operator
The LaguerreP operator computes the nth Laguerre Polynomial. The two argument call of LaguerreP is a (common) abbreviation of LaguerreP(n,0,x).
LaguerreP(<integer>,<expression>,<expression>)
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
LEGENDREP _ _ _ _ _ _ _ _ _ _ _ _ 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).
LegendreP(<integer>,<expression>,<expression>)
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 associa ted Legendre Polynomial defined as
P(n,m,x) = (-1)**m * (1-x**2)**(m/2) * df(LegendreP(n,x),x,m)
JACOBIP _ _ _ _ _ _ _ _ _ _ _ _ operator
The JacobiP operator computes the nth Jacobi Polynomial.
JacobiP(3,4,5,xx); 3 2 7*(65*xx - 13*xx - 13*xx + 1) ---------------------------------- 8 JacobiP(3,4,5,6); 94465/8
GEGENBAUERP _ _ _ _ _ _ _ _ _ _ _ _ operator
The GegenbauerP operator computes Gegenbauer's (ultraspherical) polynomials.
GegenbauerP(3,2,xx); 2 4*xx*(8*xx - 3) GegenbauerP(3,2,4); 2000
SOLIDHARMONICY _ _ _ _ _ _ _ _ _ _ _ _ operator
The SolidHarmonicY operator computes Solid harmonic (Laplace) polynomials.
SolidHarmonicY(3,-2,x,y,z,r2); 2 2 sqrt(105)*z*(-2*i*x*y + x - y ) --------------------------------- 4*sqrt(pi)*sqrt(2)
SPHERICALHARMONICY _ _ _ _ _ _ _ _ _ _ _ _ operator
The SphericalHarmonicY operator computes Spherical harmonic (Laplace) polynomials. These are special cases of the solid harmonic polynomials, SolidHarmonicY.
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
SI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Si operator returns the Sine Integral function.
limit(Si(x),x,infinity); pi / 2 on rounded; Si(0.35); 0.347626790989
The numeric values for the operator Si are computed via t he power series representation, which limits the argument range.
SHI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Shi operator returns the hyperbolic Sine Integral function.
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.
S_I _ _ _ _ _ _ _ _ _ _ _ _ operator
The s_i operator returns the Sine Integral function si.
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.
CI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Ci operator returns the Cosine Integral function.
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 t he power series representation, which limits the argument range.
CHI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Chi operator returns the Hyperbolic Cosine Integral function.
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.
ERF 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)
.
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.
ERFC _ _ _ _ _ _ _ _ _ _ _ _ operator
The erfc operator returns the complementary Error function
1 - defint(e**(-x**2),x,0,infinity) * 2/sqrt(pi)
.
erfc(xx); - erf(xx) + 1
The operator erfc is simplified towards the erf operator.
EI _ _ _ _ _ _ _ _ _ _ _ _ operator
The Ei operator returns the Exponential Integral function.
df(ei(x),x); x e --- x on rounded; Ei(0.35); - 0.0894340019184
The numeric values for the operator Ei are computed via t he power series representation, which limits the argument range.
FRESNEL_C _ _ _ _ _ _ _ _ _ _ _ _ operator
The Fresnel_C operator represents Fresnel's Cosine function.
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 o f large values of its argument.
FRESNEL_S _ _ _ _ _ _ _ _ _ _ _ _ operator
The Fresnel_S operator represents Fresnel's Sine Integral function.
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 o f large values of its argument.
Integral Functions
BINOMIAL _ _ _ _ _ _ _ _ _ _ _ _ operator
The Binomial operator returns the Binomial coefficient if both parameter are integer and expressions involving the Gamma function otherwise.
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.
STIRLING1 _ _ _ _ _ _ _ _ _ _ _ _ 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)).
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.
STIRLING2 _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
THREEJSYMBOL _ _ _ _ _ _ _ _ _ _ _ _ operator
The ThreejSymbol operator implements the 3j symbol.
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)
CLEBSCH_GORDAN _ _ _ _ _ _ _ _ _ _ _ _ operator
The Clebsch_Gordan operator implements the Clebsch_Gordan coefficients. This is closely related to the Threejsymbol.
Clebsch_Gordan({2,0},{2,0},{2,0}); -2 --------- sqrt(14)
SIXJSYMBOL _ _ _ _ _ _ _ _ _ _ _ _ operator
The SixjSymbol operator implements the 6j symbol.
SixjSymbol(<list of j1,j2,j3>,<list of l1,l2,l3>)
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
HYPERGEOMETRIC _ _ _ _ _ _ _ _ _ _ _ _ operator
The Hypergeometric operator provides simplifications for the generalized hypergeometric functions. The Hypergeometric operator is included in the package specfn2.
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)).
MEIJERG _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
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).
HEAVISIDE _ _ _ _ _ _ _ _ _ _ _ _ operator
The Heaviside operator returns the Heaviside function.
Heaviside(~w) => if (w <0) then 0 else 1
when numberp w;
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.
ERFI _ _ _ _ _ _ _ _ _ _ _ _ operator
The erfi operator returns the error function of an imaginary argument.
erfi(~x) => 2/sqrt(pi) * defint(e**(t**2),t,0,x);
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
Special Functions
TAYLOR _ _ _ _ _ _ _ _ _ _ _ _ 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.
TAYLOR _ _ _ _ _ _ _ _ _ _ _ _ operator
The taylor operator is used for expanding an expression into a Taylor series.
{,<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.
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.
TAYLORAUTOCOMBINE _ _ _ _ _ _ _ _ _ _ _ _ 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.
TAYLORAUTOEXPAND _ _ _ _ _ _ _ _ _ _ _ _ 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.
TAYLORCOMBINE _ _ _ _ _ _ _ _ _ _ _ _ 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.
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.
TAYLORKEEPORIGINAL _ _ _ _ _ _ _ _ _ _ _ _ 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.
TAYLORORIGINAL _ _ _ _ _ _ _ _ _ _ _ _ operator
Recovers the original expression (the one that was expanded) from the Taylor kernel that is given as its argument.
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 expansi on.
TAYLORPRINTORDER _ _ _ _ _ _ _ _ _ _ _ _ switch
taylorprintorder, if set to on, causes the remainder to be printed in big-O notation. Otherwise, three dots are printed. Default is on.
TAYLORPRINTTERMS _ _ _ _ _ _ _ _ _ _ _ _ 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.
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
TAYLORREVERT _ _ _ _ _ _ _ _ _ _ _ _ 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.
The first argument must evaluate to a Taylor kernel with the second argument being one of its expansion variables.
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 )
TAYLORSERIESP _ _ _ _ _ _ _ _ _ _ _ _ operator
This operator may be used to determine if its argument is a Taylor kernel.
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.
TAYLORTEMPLATE _ _ _ _ _ _ _ _ _ _ _ _ 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
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.
hugo := taylor(exp(x),x,0,2); 1 2 3 HUGO := 1 + X + -*X + O(X ) 2 taylortemplate hugo; {{X,0,2}}
TAYLORTOSTANDARD _ _ _ _ _ _ _ _ _ _ _ _ operator
This operator converts all Taylor kernels in its argument into standard form and resimplifies the result.
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
GNUPLOT 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.
AXES 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.
POINTSET _ _ _ _ _ _ _ _ _ _ _ _ type
A curve can be give as a 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.
Also a surface in 3d can be given by precomputed point s, 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.
PLOT _ _ _ _ _ _ _ _ _ _ _ _ command
The command plot is the main entry for drawing a picture from inside REDUCE.
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)
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.
PLOTRESET _ _ _ _ _ _ _ _ _ _ _ _ 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.
TITLE _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Assign a title to the GNUPLOT graph.
title="annual revenue in 1993"
XLABEL _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Assign a name to to the x axis (see axes names).
xlabel="month"
YLABEL _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Assign a name to to the x axis (see axes names).
ylabel="million forint"
ZLABEL _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Assign a name to to the z axis (see axes names).
zlabel="local weight"
TERMINAL _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Select a different output device. The possible values here depend highly on the facilities installed for your GNUPLOT software.
terminal="x11"
SIZE _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Rescale the graph (not the window!) in x and y direction. Default is 1.0 (no rescaling).
where <sx>,<sy> are floating point number not too far from 1.0.
size="0.7,1"
VIEW _ _ _ _ _ _ _ _ _ _ _ _ variable
plotoption: Set a new viewpoint by turning the object around the x and then around the z axis (see axes names).
where <sx>,<sz> are floating point number representing angles in degrees.
view="30,130"
CONTOUR _ _ _ _ _ _ _ _ _ _ _ _ switch
plotoption: 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.
SURFACE _ _ _ _ _ _ _ _ _ _ _ _ switch
plotoption: 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 .
HIDDEN3D _ _ _ _ _ _ _ _ _ _ _ _ switch
plotoption: 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.
PLOTKEEP _ _ _ _ _ _ _ _ _ _ _ _ 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.
PLOTREFINE _ _ _ _ _ _ _ _ _ _ _ _ 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).
PLOT_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.
PLOT_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.
SHOW_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.
TRPLOT _ _ _ _ _ _ _ _ _ _ _ _ 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
LINEAR 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
Constructors -- functions that create matrices
High level algorithms
svd.
Normal Forms
There is a separate package, NORMFORM, for computing the following matrix normal forms in REDUCE:
Predicates
FAST_LA _ _ _ _ _ _ _ _ _ _ _ _ switch
By turning the fast_la switch on, the speed of the following functions will be increased:
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.
ADD_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Add columns, add rows:
add_columns(<matrix>,<c1>,<c2>,<expr>)
<matrix> :- a matrix.
<c1>,<c2> :- positive integers.
<expr> :- a scalar expression.
The Operator add_columns replaces column <\meta{c2>} of <matrix> by <expr> * column(<matrix>,<c1>) + column(<matrix>,<c2>).
add_rowsperforms the equivalent task on the rows of <matrix>.
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.
ADD_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: add_columns.
ADD_TO_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Add to columns, add to rows:
<matrix> :- a matrix.
<column\_list> :- a positive integer or a list of positive integers.
<expr> :- a scalar expression.
add_to_columnsadds <expr> to each column specified in <column\_list> of <matrix>.
add_to_rowsperforms the equivalent task on the rows of <matrix>.
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.
ADD_TO_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: add_to_columns.
AUGMENT_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Augment columns, stack rows:
<matrix> :- a matrix.
<column\_list> :- either a positive integer or a list of positive integers.
augment_columnsgets hold of the columns of <matrix> specified in column_list and sticks them together.
stack_rowsperforms the same task on rows of <matrix>.
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.
BAND_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
<expr\_list> :- either a single scalar expression or a list of an odd number of scalar expressions.
<square\_size> :- a positive integer.
band_matrixcreates 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.
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.
BLOCK_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
<r>,<c> :- positive integers.
<matrix\_list> :- a list of matrices.
block_matrixcreates a matrix that consists of <r> by <c> matrices filled from the <matrix\_list> row wise.
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 ]
CHAR_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
<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.
char_matrix(A,x); [x - 1 -2 -3 ] [ ] [ -4 x - 5 -6 ] [ ] [ -7 -8 x - 9]
Related functions: char_poly.
CHAR_POLY _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a square matrix.
<lambda> :- a symbol or algebraic expression.
char_polyfinds the characteristic polynomial of <matrix>. This is the determinant of <lambda> * Id - A. Id is the identity matrix.
char_poly(A,x); 3 2 x -15*x -18*x
Related functions: char_matrix.
CHOLESKY _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a positive definite matrix containing numeric entries.
choleskycomputes 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.
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.
COEFF_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
(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_matrixcreates the coefficient matrix C of the linear equations.
It returns {C,X,B} such that CX = B.
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] }
COLUMN_DIM _ _ _ _ _ _ _ _ _ _ _ _ operator
Column dimension, row dimension:
<matrix> :- a matrix.
column_dimfinds the column dimension of <matrix>.
row_dimfinds the row dimension of <matrix>.
column_dim(A); 3 row_dim(A); 3
COMPANION _ _ _ _ _ _ _ _ _ _ _ _ operator
<poly> :- a monic univariate polynomial in <x>.
<x> :- the variable.
companioncreates 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.
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.
COPY_INTO _ _ _ _ _ _ _ _ _ _ _ _ operator
<A>,<B> :- matrices.
<r>,<c> :- positive integers.
copy_intocopies matrix <matrix> into <B> with <matrix>(1,1) at <B>(<r>,<c>).
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.
DIAGONAL _ _ _ _ _ _ _ _ _ _ _ _ operator
(If you are feeling lazy then the braces can be omitted.)
<mat\_list> :- each can be either a scalar expression or a square matrix.
diagonalcreates a matrix that contains the input on the diagonal.
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.
EXTEND _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
<r>,<c> :- positive integers.
<expr> :- algebraic expression or symbol.
extendreturns a copy of <matrix> that has been extended by <r> rows and <c> columns. The new entries are made equal to <expr>.
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.
FIND_COMPANION _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
<x> :- the variable.
Given a companion matrix, find_companion finds the polynomial from which it was made.
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.
GET_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Get columns, get rows:
<matrix> :- a matrix.
<c> :- either a positive integer or a list of positive integers.
get_columnsremoves the columns of <matrix> specified in <column\_list> and returns them as a list of column matrices.
get_rowsperforms the same task on the rows of <matrix>.
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.
GET_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: get_columns.
GRAM_SCHMIDT _ _ _ _ _ _ _ _ _ _ _ _ operator
(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_schmidtperforms the gram_schmidt orthonormalization on the input vectors.
It returns a list of orthogonal normalized vectors.
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
HERMITIAN_TP _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
hermitian_tpcomputes 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>.
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.
HESSIAN _ _ _ _ _ _ _ _ _ _ _ _ operator
<expr> :- a scalar expression.
<variable\_list> :- either a single variable or a list of variables.
hessiancomputes 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)).
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.
HILBERT _ _ _ _ _ _ _ _ _ _ _ _ operator
<square\_size> :- a positive integer.
<expr> :- an algebraic expression.
hilbertcomputes 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>).
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 ]
JACOBIAN _ _ _ _ _ _ _ _ _ _ _ _ operator
<expr\_list> :- either a single algebraic expression or a list of algebraic expressions.
<variable\_list> :- either a single variable or a list of variables.
jacobiancomputes 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.
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.
JORDAN_BLOCK _ _ _ _ _ _ _ _ _ _ _ _ operator
<expr> :- an algebraic expression or symbol.
<square\_size> :- a positive integer.
jordan_blockcomputes 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.
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.
LU_DECOM _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix containing either numeric entries or imaginary entries with numeric coefficients.
lu_decomperforms 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).
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.
MAKE_IDENTITY _ _ _ _ _ _ _ _ _ _ _ _ operator
<square\_size> :- a positive integer.
make_identitycreates the identity matrix of dimension <square\_size>.
make_identity(4); [1 0 0 0] [ ] [0 1 0 0] [ ] [0 0 1 0] [ ] [0 0 0 1]
Related functions: diagonal.
MATRIX_AUGMENT _ _ _ _ _ _ _ _ _ _ _ _ operator
Matrix augment, matrix stack:
(If you are feeling lazy then the braces can be omitted.)
<matrix\_list> :- matrices.
matrix_augmentsticks the matrices in <matrix\_list> together horizontally.
matrix_stacksticks the matrices in <matrix\_list> together vertically.
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.
MATRIXP _ _ _ _ _ _ _ _ _ _ _ _ operator
<test\_input> :- anything you like.
matrixpis a boolean function that returns t if the input is a matrix and nil otherwise.
matrixp A; t matrixp(doodlesackbanana); nil
Related functions: squarep, symmetricp.
MATRIX_STACK _ _ _ _ _ _ _ _ _ _ _ _ operator
see: matrix_augment.
MINOR _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix. <r>,<c> :- positive integers.
minorcomputes the (<r>,<c>)'th minor of <matrix>. This is created by removing the <r>'th row and the <c>'th column from <matrix>.
minor(A,1,3); [4 5] [ ] [7 8]
Related functions: remove_columns, remove_rows.
MULT_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Mult columns, mult rows:
<matrix> :- a matrix.
<column\_list> :- a positive integer or a list of positive integers.
<expr> :- an algebraic expression.
mult_columnsreturns a copy of <matrix> in which the columns specified in <column\_list> have been multiplied by <expr>.
mult_rowsperforms the same task on the rows of <matrix>.
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.
MULT_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: mult_columns.
PIVOT _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
<r>,<c> :- positive integers such that <matrix>(<r>, <c>) neq 0.
pivotpivots <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.
pivot(A,2,3); [ - 1 ] [-1 ------ 0] [ 2 ] [ ] [4 5 6] [ ] [ 1 ] [1 --- 0] [ 2 ]
Related functions: rows_pivot.
PSEUDO_INVERSE _ _ _ _ _ _ _ _ _ _ _ _ operator
<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).
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.
RANDOM_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
<r>,<c>,<limit> :- positive integers.
random_matrixcreates 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 imagina ry 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.
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 ]
REMOVE_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Remove columns, remove rows:
<matrix> :- a matrix. <column\_list> :- either a positive integer or a list of positive integers.
remove_columnsremoves the columns specified in <column\_list> from <matrix>.
remove_rowsperforms the same task on the rows of <matrix>.
remove_columns(A,2); [1 3] [ ] [4 6] [ ] [7 9] remove_rows(A,{1,3}); [4 5 6]
Related functions: minor.
REMOVE_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: remove_columns.
ROW_DIM _ _ _ _ _ _ _ _ _ _ _ _ operator
see: column_dim.
ROWS_PIVOT _ _ _ _ _ _ _ _ _ _ _ _ operator
<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_pivotperforms the same task as pivot but applies the pivot only to the rows specified in <row\_list>.
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.
SIMPLEX _ _ _ _ _ _ _ _ _ _ _ _ operator
<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.
simplexapplies 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.
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}}
SQUAREP _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
squarepis a predicate that returns t if the <matrix> is square and nil otherwise.
squarep(mat((1,3,5))); nil squarep(A); t
Related functions: matrixp, symmetricp.
STACK_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: augment_columns.
SUB_MATRIX _ _ _ _ _ _ _ _ _ _ _ _ operator
<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>.
sub_matrix(A,{1,3},{2,3}); [2 3] [ ] [8 9]
Related functions: augment_columns, stack_rows.
SVD _ _ _ _ _ _ _ _ _ _ _ _ operator
Singular value decomposition:
<matrix> :- a matrix containing only numeric entries.
svdcomputes 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.
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] }
SWAP_COLUMNS _ _ _ _ _ _ _ _ _ _ _ _ operator
Swap columns, swap rows:
<matrix> :- a matrix.
<c1>,<c1> :- positive integers.
swap_columnsswaps column <c1> of <matrix> with column <c2>.
swap_rowsperforms the same task on two rows of <matrix>.
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.
SWAP_ENTRIES _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
<r1>,<c1>,<r2>,<c2> :- positive integers.
swap_entriesswaps <matrix>(<r1>,<c1>) with <matrix>(<r2>,<c2>).
swap_entries(A,{1,1},{3,3}); [9 2 3] [ ] [4 5 6] [ ] [7 8 1]
Related functions: swap_columns, swap_rows.
SWAP_ROWS _ _ _ _ _ _ _ _ _ _ _ _ operator
see: swap_columns.
SYMMETRICP _ _ _ _ _ _ _ _ _ _ _ _ operator
<matrix> :- a matrix.
symmetricpis a predicate that returns t if the matrix is symmetric and nil otherwise.
symmetricp(make_identity(11)); t symmetricp(A); nil
Related functions: matrixp, squarep.
TOEPLITZ _ _ _ _ _ _ _ _ _ _ _ _ operator
(If you are feeling lazy then the braces can be omitted.)
<expr\_list> :- list of algebraic expressions.
toeplitzcreates 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.
toeplitz({w,x,y,z}); [w x y z] [ ] [x w x y] [ ] [y x w x] [ ] [z y x w]
VANDERMONDE _ _ _ _ _ _ _ _ _ _ _ _ operator
(If you are feeling lazy then the braces can be omitted.)
<expr\_list> :- list of algebraic expressions.
vandermondecreates 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.
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
SMITHEX _ _ _ _ _ _ _ _ _ _ _ _ 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.
<matrix> :- a rectangular matrix of univariate polynomials in <variable>. <variable> :- the variable.
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 ]
SMITHEX\_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.
<matrix> :- a rectangular matrix of integer entries.
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 ]
FROBENIUS _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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:
Frobeniuscan 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.
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 ]
RATJORDAN _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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:
ratjordancan 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.
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 ]
JORDANSYMBOLIC _ _ _ _ _ _ _ _ _ _ _ _ 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).
<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:
jordansymboliccan 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.
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) ] }
JORDAN _ _ _ _ _ _ _ _ _ _ _ _ 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.
<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.
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
MISCELLANEOUS 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.
ALGINT _ _ _ _ _ _ _ _ _ _ _ _ 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.
APPLYSYM _ _ _ _ _ _ _ _ _ _ _ _ package
Author: Thomas Wolf
This package provides programs APPLYSYM, QUASILINPDE and DETRAFO for computing with infinitesimal symmetries of differential equations.
ARNUM _ _ _ _ _ _ _ _ _ _ _ _ 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.
ASSIST _ _ _ _ _ _ _ _ _ _ _ _ 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.
AVECTOR _ _ _ _ _ _ _ _ _ _ _ _ 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.
BOOLEAN _ _ _ _ _ _ _ _ _ _ _ _ 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.
CALI _ _ _ _ _ _ _ _ _ _ _ _ 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.
CAMAL _ _ _ _ _ _ _ _ _ _ _ _ package
Author: John P. Fitch
This package implements in REDUCE the Fourier transform procedures of the CAMAL package for celestial mechanics.
CHANGEVR _ _ _ _ _ _ _ _ _ _ _ _ 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.
COMPACT _ _ _ _ _ _ _ _ _ _ _ _ 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.
CRACK _ _ _ _ _ _ _ _ _ _ _ _ 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.
CVIT _ _ _ _ _ _ _ _ _ _ _ _ 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.
DEFINT _ _ _ _ _ _ _ _ _ _ _ _ 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.
DESIR _ _ _ _ _ _ _ _ _ _ _ _ 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).
DFPART _ _ _ _ _ _ _ _ _ _ _ _ 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.
DUMMY _ _ _ _ _ _ _ _ _ _ _ _ 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.
EXCALC _ _ _ _ _ _ _ _ _ _ _ _ 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.
FPS _ _ _ _ _ _ _ _ _ _ _ _ package
Authors: Wolfram Koepf, Winfried Neun
This package can expand a specific class of functions into their corresponding Laurent-Puiseux series.
FIDE _ _ _ _ _ _ _ _ _ _ _ _ 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.
GENTRAN _ _ _ _ _ _ _ _ _ _ _ _ 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.
IDEALS _ _ _ _ _ _ _ _ _ _ _ _ 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.
INEQ _ _ _ _ _ _ _ _ _ _ _ _ package
Author: Herbert Melenk
This package supports the operator ineq_solve that attempts to solve single inequalities and sets of coupled inequalities.
INVBASE _ _ _ _ _ _ _ _ _ _ _ _ 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 a polynomial ideal is nothing more than a special form of a redundant Groebner basis. The construction of involutive bases reduces the problem of solving polynomial systems to simple linear algebra.
LAPLACE _ _ _ _ _ _ _ _ _ _ _ _ package
Authors: C. Kazasov, M. Spiridonova, V. Tomov
This package can calculate ordinary and inverse Laplace transforms of expressions.
LIE _ _ _ _ _ _ _ _ _ _ _ _ package
Authors: Carsten and Franziska Sch"obel
Lieis 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.
MODSR _ _ _ _ _ _ _ _ _ _ _ _ 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}
NCPOLY _ _ _ _ _ _ _ _ _ _ _ _ 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.
ORTHOVEC _ _ _ _ _ _ _ _ _ _ _ _ package
Author: James W. Eastwood
orthovecis 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.
PHYSOP _ _ _ _ _ _ _ _ _ _ _ _ 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.
PM _ _ _ _ _ _ _ _ _ _ _ _ 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.
RANDPOLY _ _ _ _ _ _ _ _ _ _ _ _ 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.
REACTEQN _ _ _ _ _ _ _ _ _ _ _ _ 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.
RESET _ _ _ _ _ _ _ _ _ _ _ _ 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.
RESIDUE _ _ _ _ _ _ _ _ _ _ _ _ package
Author: Wolfram Koepf
This package supports the calculation of residues of arbitrary expressions.
RLFI _ _ _ _ _ _ _ _ _ _ _ _ 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.
SCOPE _ _ _ _ _ _ _ _ _ _ _ _ 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.
SETS _ _ _ _ _ _ _ _ _ _ _ _ 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.
SPDE _ _ _ _ _ _ _ _ _ _ _ _ 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.
SYMMETRY _ _ _ _ _ _ _ _ _ _ _ _ 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.
TPS _ _ _ _ _ _ _ _ _ _ _ _ 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.
TRI _ _ _ _ _ _ _ _ _ _ _ _ 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.
TRIGSIMP _ _ _ _ _ _ _ _ _ _ _ _ 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.
XCOLOR _ _ _ _ _ _ _ _ _ _ _ _ package
Author: A. Kryukov
This package calculates the color factor in non-abelian gauge field theories using an algorithm due to Cvitanovich.
XIDEAL _ _ _ _ _ _ _ _ _ _ _ _ package
Author: David Hartley
xidealconstructs 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.
WU _ _ _ _ _ _ _ _ _ _ _ _ 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.
ZEILBERG _ _ _ _ _ _ _ _ _ _ _ _ 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.
ZTRANS _ _ _ _ _ _ _ _ _ _ _ _ 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
ED _ _ _ _ _ _ _ _ _ _ _ _ command
The ed command invokes a simple line editor for REDUCE input statements.
edcalled 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.
(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 key{Return}) X**2 + Y; ^ ?- r5 X**5 + Y; ^ ?- fY X**5 + Y; ^ ?- iabc (Terminate with key{ESC} and key{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, key{ESC}, and key{Return}) begin scalar a; a := b + 10; WRITE A; ?- f;i end key{ESC}, key{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.
EDITDEF _ _ _ _ _ _ _ _ _ _ _ _ command
The interactive editor ed may be used to edit a user-defined procedure that has not been compiled.
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