REDUCE is a general-purpose computer algebra system originally geared towards applications in physics.

The development of REDUCE was started in 1963 by Anthony C. Hearn; since then, many scientists from all over the world have contributed to its development. REDUCE was open-sourced in December 2008 and is available for free under a modified BSD license on SourceForge. Previously it had cost $695.

REDUCE is written entirely in its own Lisp dialect called Standard Lisp, expressed in an ALGOL-like syntax called RLISP that is also used as the basis for REDUCE's user-level language.

Implementations of REDUCE are available on most variants of Unix, Linux, Microsoft Windows, or Apple Macintosh systems by using an underlying Portable Standard Lisp (PSL) or Codemist Standard Lisp (CSL) implementation. CSL REDUCE offers a graphical user interface. REDUCE can also be built on other Lisps, such as Common Lisp.

Features arbitrary precision integer, rational, complex and floating-point arithmetic expressions and functions involving one or more variables algorithms for polynomials, rational and transcendental functions facilities for the solution of a variety of algebraic equations automatic and user-controlled simplification of expressions substitutions and pattern matching in a wide variety of forms symbolic differentiation, indefinite and definite integration solution of ordinary differential equations computations with a wide variety of special functions general matrix and non-commutative algebra plotting in 2 and 3 dimensions of graphs of functions arbitrary points, lines and curves Dirac matrix calculations of interest in high energy physics quantifier elimination and decision for interpreted first-order logic powerful intuitive user-level programming language.

Syntax The REDUCE language is a high-level structured programming language based on ALGOL 60 (but with Standard Lisp semantics), although it does not support all ALGOL 60 syntax. It is similar to Pascal, which evolved from ALGOL 60, and Modula, which evolved from Pascal.

REDUCE is a free-form language, meaning that spacing and line breaks are not significant, but consequently input statements must be separated from each other and all input must be terminated with either a semi-colon (;) or a dollar sign ($). The difference is that if the input results in a useful (non-nil) value then it will be output if the separator is a semi-colon (;) but hidden if it is a dollar sign ($). The assignment operator is colon-equal (:=), which in its simplest usage assigns to the variable on its left the value of the expression on its right. However, a REDUCE variable can have no value, in which case it is displayed as its name, in order to allow mathematical expressions involving indeterminates to be constructed and manipulated. The simplest way to use REDUCE is interactively: type input after the last input prompt, terminate it with semi-colon and press the Return or Enter key; REDUCE processes the input and displays the result. This is illustrated in the screenshot.

Identifiers and strings Programming languages use identifiers to name constructs such as variables and functions, and strings to store text. A REDUCE identifier must begin with a letter and can be followed by letters, digits and underscore characters (_). A REDUCE identifier can also include any character anywhere if it is input preceded by an exclamation mark (!). A REDUCE string is any sequence of characters delimited when input by double quote characters ("). A double quote can be included in a string by entering two double quotes; no other escape mechanism is implemented within strings. An identifier can be used instead of a string in most situations in REDUCE, such as to represent a file name.

REDUCE source code was originally written in all upper-case letters, as were all programming languages in the 1960s. (Hence, the name REDUCE is normally written in all upper-case.) However, modern REDUCE is case-insensitive (by default), which means that it ignores the case of letters, and it is normally written in lower-case. (The REDUCE source code has been converted to lower case.) The exceptions to this rule are that case is preserved within strings and when letters in identifiers are preceded by an exclamation mark (!). Hence, it is conventional to use snake-case (e.g. long_name) rather than camel-case (e.g. longName) for REDUCE identifiers, because camel-case gets lost without also using exclamation marks.

Hello World programs Below is a REDUCE "Hello, World!" program, which is almost as short as such a program could possibly be! "Hello, World!"; REDUCE displays the output Hello, World! Another REDUCE "Hello, World!" program, which is slightly longer than the version above, uses an identifier as follows !Hello!,! !World!!; CSL REDUCE displays the same output as shown above. (Other REDUCE GUIs may italicise this output on the grounds that it is an identifier rather than a string.)

Statements and expressions Because REDUCE inherits Lisp semantics, all programming constructs have values. Therefore, the only distinction between statements and expressions is that the value of an expression is used but the value of a statement is not. The terms statement and expression are interchangeable, although a few constructs always return the Lisp value nil and so are always used as statements.

There are two ways to group several statements or expressions into a single unit that is syntactically equivalent to a single statement or expression, which is necessary to facilitate structured programming. One is the begin...end construct inherited from ALGOL 60, which is called a block or compound statement. Its value is the value of the expression following the (optional) keyword return. The other uses the bracketing syntax <<...>>, which is called a group statement. Its value is the value of the last (unterminated) expression in it. Both are illustrated below in the procedural programming example below.

Structured programming REDUCE supports conditional and repetition statements, some of which are controlled by a boolean expression, which is any expression whose value can be either true or false, such as . (The REDUCE user-level language does not explicitly support constants representing true or false although, as in C and related languages, 0 has the boolean value false, whereas 1 and many other non-zero values have the boolean value true.)

Conditional statements: if ... then ... else The conditional statement has the form if boolean expression then statement which can optionally be followed by else statement For example, the following conditional statement ensures that the value of , assumed to be numerical, is positive. (It effectively implements the absolute value function.) if n < 0 then n := -n The following conditional statement, used as an expression, avoids an error that would be caused by dividing by 0. recip_x := if x = 0 then infinity else 1/x

Repetition statements: for ... The for statement is a flexible loop construct that executes statement repeatedly a number of times that must be known in advance. One version has the form for variable := initial step increment until final do statement where variable names a variable whose value can be used within statement, and initial, increment and final are numbers (preferably integers). The value of variable is initialized to initial and statement is executed, then the value of variable is repeatedly increased by increment and the statement executed again, provided the value of variable is not greater than final. The common special case "initial step 1 until final" can be abbreviated as "initial : final".

The following for statement computes the value of as the value of the variable fac. n := 5; fac := 1$ for r := 2 : n do fac := fac*r; fac;

Another version of the for statement iterates over a list, and the keyword do can be replaced by product, sum, collect or join, in which case the for statement becomes an expression and the controlled statement is treated as an expression. With product, the value is the product of the values of the controlled statement; with sum, the value is the sum of the values of the controlled statement; with collect, the value is the values of the controlled statement collected into a list; with join, the value is the values of the controlled statement, which must be lists, joined into one list.

The following for statement computes the value of much more succinctly and elegantly than the previous example. n := 5; for r := 2 : n product r;

Repetition statements: while ... do; repeat ... until The two loop statements while boolean expression do statementrepeat statement until boolean expression are closely related to the conditional statement and execute statement repeatedly a number of times that need not be known in advance. Their difference is that while repetition stops when boolean expression becomes false whereas repeat repetition stops when boolean expression becomes true. Also, repeat always executes statement at least once and it can be used to initialize boolean expression, whereas when using while boolean expression must be initialized before entering the loop.

The following while statement computes the value of as the value of the variable fac. Note that this code treats the assignment n := n - 1 as an expression and uses its value. n := 5; fac := n$ while n > 1 do fac := fac*(n := n - 1); fac;

Comments REDUCE has three comment conventions. It inherits the comment statement from ALGOL 60, which looks like this: comment This is a multi-line comment that ends at the next separator, so it cannot contain separators; Comment statements mostly appear in older code.

It inherits the %... comment from Standard Lisp, which looks like this: % This is a single-line comment that ends at the end of the line. % It can appear on a line after code and % can contain the separators ";" and "$". %... comments are analogous to C++ //... comments and are the most commonly used form of comment.

REDUCE also supports a C-style /*...*/ comment that looks like this: /* This is a multi-line comment that can appear anywhere a space could and can contain the separators ";" and "$". */

Programming paradigms REDUCE's user-level language supports several programming paradigms, as illustrated in the algebraic programming examples below.

Since it is based on Lisp, which is a functional programming language, REDUCE supports functional programming and all statements have values (although they are not always useful). REDUCE also supports procedural programming by ignoring statement values. Algebraic computation usually proceeds by transforming a mathematical expression into an equivalent but different form. This is called simplification, even though the result might be much longer. (The name REDUCE is a pun on this problem of intermediate expression swell!) In REDUCE, simplification occurs automatically when an expression is entered or computed, controlled by simplification rules and switches. In this way, REDUCE supports rule-based programming, which is the classic REDUCE programming paradigm. In early versions of REDUCE, rules and switches could only be set globally, but modern REDUCE also supports local setting of rules and switches, meaning that they control the simplification of only one expression. REDUCE programs often contain a mix of programming paradigms.

Algebraic programming examples The screenshot shows simple interactive use.

As a simple programming example, consider the problem of computing the th Taylor polynomial of the function about the point , which is given by the formula . Here, denotes the th derivative of evaluated at the point and denotes the factorial of . (However, note that REDUCE includes sophisticated facilities for power-series expansion.)