Up | Prev | PrevTail | Tail |
Operators in REDUCE are specified by name and type. There are two types, infix and
prefix. Operators can be purely abstract, just symbols with no properties; they can have
values assigned (using :=
or simple let
declarations) for specific arguments; they
can have properties declared for some collection of arguments (using more
general let
declarations); or they can be fully defined (usually by a procedure
declaration).
Infix operators have a definite precedence with respect to one another, and normally occur between their arguments. For example:
a + b - c
(spaces optional)
x<y and y=z
(spaces required where shown)
Spaces can be freely inserted between operators and variables or operators and operators.
They are required only where operator names are spelled out with letters (such as the
and
in the example) and must be unambiguously separated from another such or
from a variable (like y
). Wherever one space can be used, so can any larger
number.
Prefix operators occur to the left of their arguments, which are written as a list enclosed in parentheses and separated by commas, as with normal mathematical functions, e.g.,
cos(u) df(x^2,x) q(v+w)
Unmatched parentheses, incorrect groupings of infix operators and the like, naturally lead to syntax errors. The parentheses can be omitted (replaced by a space following the operator name) if the operator is unary and the argument is a single symbol or begins with a prefix operator name:
cos y
means cos(y)
cos (-y)
– parentheses necessary
log cos y
means log(cos(y))
log cos (a+b)
means log(cos(a+b))
but
cos a*b
means (cos a)*b
cos -y
is erroneous (treated as a variable
“ cos
” minus the variabley
)
A unary prefix operator has a precedence higher than any infix operator, including unary
infix operators. In other words, REDUCE will always interpret cos y + 3
as
(cos y) + 3
rather than as cos(y + 3)
.
Infix operators may also be used in a prefix format on input, e.g., +(a,b,c)
. On output,
however, such expressions will always be printed in infix form (i.e., a + b + c
for this
example).
A number of prefix operators are built into the system with predefined properties. Users may also add new operators and define their rules for simplification. The built in operators are described in another section.
The following infix operators are built into the system. They are all defined internally as procedures.
\(\langle \)infix operator\(\rangle \) | \(\longrightarrow \) | where \(\ \mid \ \):= \(\ \mid \ \)or \(\ \mid \ \)and \(\ \mid \ \)member \(\ \mid \ \)memq \(\ \mid \ \) |
= \(\ \mid \ \)neq \(\ \mid \ \)eq \(\ \mid \ \)>= \(\ \mid \ \)> \(\ \mid \ \)<= \(\ \mid \ \)< \(\ \mid \ \) |
||
+ \(\ \mid \ \)- \(\ \mid \ \)* \(\ \mid \ \)/ \(\ \mid \ \)^ \(\ \mid \ \)** \(\ \mid \ \). |
These operators may be further divided into the following subclasses:
\(\langle \)assignment operator\(\rangle \) | \(\longrightarrow \) | := |
\(\langle \)logical operator\(\rangle \) | \(\longrightarrow \) | or \(\ \mid \ \)and \(\ \mid \ \)member \(\ \mid \ \)memq |
\(\langle \)relational operator\(\rangle \) | \(\longrightarrow \) | = \(\ \mid \ \)neq \(\ \mid \ \)eq \(\ \mid \ \)>= \(\ \mid \ \)> \(\ \mid \ \)<= \(\ \mid \ \)< |
\(\langle \)substitution operator\(\rangle \) | \(\longrightarrow \) | where |
\(\langle \)arithmetic operator\(\rangle \) | \(\longrightarrow \) | + \(\ \mid \ \)- \(\ \mid \ \)* \(\ \mid \ \)/ \(\ \mid \ \)^ \(\ \mid \ \)** |
\(\langle \)construction operator\(\rangle \) | \(\longrightarrow \) | . |
memq
and eq
are not used in the algebraic mode of REDUCE. They are explained in the
section on symbolic mode. where
is described in the section on substitutions.
In previous versions of REDUCE, not
was also defined as an infix operator.
In the present version it is a regular prefix operator, and interchangeable with
null
.
For compatibility with the intermediate language used by REDUCE, each special character infix operator has an alternative alphanumeric identifier associated with it. These identifiers may be used interchangeably with the corresponding special character names on input. This correspondence is as follows:
:=
setq
(the assignment operator) =
equal
>=
geq
>
greaterp
<=
leq
<
lessp
+
plus
-
difference
(if unary, minus
)*
times
/
quotient
(if unary, recip
)^ or **
expt
(raising to a power) .
cons
Note: neq
is used to mean not equal. There is no special symbol provided for
it.
The above operators are binary, except not
which is unary and +
and *
which
are nary (i.e., taking an arbitrary number of arguments). In addition, -
and /
may be used as unary operators, e.g., /2
means the same as 1/2
. Any other
operator is parsed as a binary operator using a left association rule. Thus a/b/c
is
interpreted as (a/b)/c
. There are two exceptions to this rule: :=
and .
are right
associative. Example: a:=b:=c
is interpreted as a:=(b:=c)
. Unlike ALGOL
and PASCAL, ^
is left associative. In other words, a^b^c
is interpreted as
(a^b)^c
.
The operators <
, <=
, >
, >=
can only be used for making comparisons between numbers.
No meaning is currently assigned to this kind of comparison between general
expressions.
Parentheses may be used to specify the order of combination. If parentheses are omitted
then this order is by the ordering of the precedence list defined by the right-hand side of
the \(\langle \)infix operator\(\rangle \) table at the beginning of this section, from lowest to highest. In
other words, where
has the lowest precedence, and .
(the dot operator) the
highest.
Up | Prev | PrevTail | Front |