| Up | Next | Tail |
REDUCE includes a number of functions that are analogs of those found in most numerical systems. With numerical arguments, such functions return the expected result. However, they may also be called with non-numerical arguments. In such cases, except where noted, the system attempts to simplify the expression as far as it can. In such cases, a residual expression involving the original operator usually remains. These operators are as follows:
ABS returns the absolute value of its single argument, if that argument has a numerical value. A non-numerical argument is returned as an absolute value, with an overall numerical coefficient taken outside the absolute value operator. For example:
This operator returns the ceiling (i.e., the least integer greater than the given argument) if its single argument has a numerical value. A non-numerical argument is returned as an expression in the original operator. For example:
This returns the complex conjugate of an expression, if that argument has a numerical value. By default the complex conjugate of a non-numerical argument is returned as an expression in the operators REPART and IMPART. For example:
If rules have been previously defined for the complex conjugate(s) of one or more non-numerical terms appearing in the argument, these rules are applied and the expansion in terms of the operators REPART and IMPART is suppressed.
For example:
Note that in defining the rule conj z => z!*, the rule conj z!* => z is (in effect) automatically defined and should not be entered by the user. The main use of rules for CONJ is to associate two identifiers as complex conjugates as in the examples above. In addition rules of the form let conj(z)=>z, conj(w)=>-w may be used. They imply that z is real-valued and w is purely imaginary, although the effect of the first rule can also be obtained by declaring z to be realvalued.
Rules of the form let conj z => «some-expression» may be used, but are not recommended. More useful results will usually be obtained by defining the equivalent rule let z => conj(«some-expression»). Rules of the form let conj z => «some-expression» are particularly problematic if «some-expression» involves z itself as they may be inconsistent, for example let conj z => z+1. Even where they are consistent, better results may usually achieved by defining alternative rules. For example, given:
so that the real part of z is a and the imaginary part of w is b, more useful results will be obtained by defining the mathematically equivalent rules:
Note also that the standard elementary functions and their inverses (where appropriate) are automatically defined to be SELFCONJUGATE so that conj(f(z)) => f(conj(z)).
If the single argument of FACTORIAL evaluates to a non-negative integer, its factorial is returned. Otherwise an expression involving FACTORIAL is returned. For example:
This operator returns the fixed value (i.e., the integer part of the given argument) if its single argument has a numerical value. A non-numerical argument is returned as an expression in the original operator. For example:
This operator returns the floor (i.e., the greatest integer less than the given argument) if its single argument has a numerical value. A non-numerical argument is returned as an expression in the original operator. For example:
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. For example:
For the inverse trigometric and hyperbolic functions with non-numeric arguments the output is usually more compact when the FACTOR is on.
MAX and MIN can take an arbitrary number of expressions as their arguments. If all arguments evaluate to numerical values, the maximum or minimum of the argument list is returned. If any argument is non-numeric, an appropriately reduced expression is returned. For example:
MAX or MIN of an empty list returns 0.
NEXTPRIME returns the next prime greater than its integer argument, using a probabilistic algorithm. A type error occurs if the value of the argument is not an integer. For example:
whereas nextprime(a) gives a type error.
random(n) returns a random number r in the range 0 ≤ r < n. A type error occurs if the value of the argument is not a positive integer in algebraic mode, or positive number in symbolic mode. For example:
whereas random(a) gives a type error.
random_new_seed(n) reseeds the random number generator to a sequence determined by the integer argument n. It can be used to ensure that a repeatable pseudo-random sequence will be delivered regardless of any previous use of RANDOM, or can be called early in a run with an argument derived from something variable (such as the time of day) to arrange that different runs of a REDUCE program will use different random sequences. When a fresh copy of REDUCE is first created it is as if random_new_seed(1) has been obeyed.
A type error occurs if the value of the argument is not a positive integer.
This returns a two-element list of the real and imaginary parts 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. This is more efficient than calling REPART and IMPART separately particularly if its argument is complicated. For example:
For the inverse trigometric and hyperbolic functions with non-numeric arguments the output is usually more compact when the FACTOR is on.
This 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. For example:
For the inverse trigometric and hyperbolic functions with non-numeric arguments the output is usually more compact when the FACTOR is on.
This operator returns the rounded value (i.e, the nearest integer) of its single argument if that argument has a numerical value. A non-numeric argument is returned as an expression in the original operator. For example:
SIGN tries to evaluate the sign of its argument. If this is possible SIGN returns one of 1, 0 or -1. Otherwise, the result is the original form or a simplified variant. For example:
Note that even powers of formal expressions are assumed to be positive only as long as the switch COMPLEX is off.
| Up | Next | Front |