Page Numbers: Yes X: 527 Y: -.4 First Page: 25 Not-on-first-page Margins: Top: 1.1" Bottom: 1" Binding: 5 Odd Heading: Not-on-first-page y576qj(635) 3. ARITHMETIC AND MATHEMATICAL FUNCTIONSy763qc(0,14848)\5f1 9f0 1f1 3f0 2f1 11f0 2f1 Even Heading: Not-on-first-pagey756qj(0,17815) IDL REFERENCE MANUALy763qc\5f1 9f0 1f1 3. Arithmetic and Mathematical Functionsy666e12c(635)\f9b Interlisp provides a large repertoire of arithmetic and mathematical functions. All of these are available to the IDL user, and many of them have been generalized to handle missing values and extended to expect scalars, so that they will operate elementwise on arbitrary IDL arrays. In addition, IDL defines some commonly used numeric constants and includes a set of arithmetic functions particularly suited to statistical applications.e36j\115f1 3f0 154f1 3f0 23f1 3f0 3.1 Arithmetic operatorse18j(0,65535)(1,635) There are three sets of basic arithmetic operators in Lisp, those that operate on integers and produce integer values (with names like IPLUS, IMINUS, ITIMES), those that operate on floating point numbers and produce floating values (FPLUS, FMINUS, FTIMES, etc.), and those that operate on mixed integer and floating arguments and produce values whose type depends on their argument types (PLUS, MINUS, TIMES, etc.). In IDL, only the mixed arithmetic operators have been extended and may be used freely on IDL arrays. Though the integer and floating operators exist in the system, they will generate errors if applied to missing data items or multi-element arrays, and their use is discouraged. The CLISP operators +,*,/, have been bound to the mixed operators PLUS, TIMES, QUOTIENT, DIFFERENCE, and MINUS, so that complicated expressions may be written in abbreviated form. QUOTIENT has been modified so that if its divisor is zero, the result will be NIL.e12j\135f1 5f0 2f1 6f0 2f1 6f0 77f1 5f0 2f1 6f0 2f1 6f0 135f1 4f0 2f1 5f0 2f1 5f0 13f1 3f0 83f1 3f0 192f1 5f0 17g1G40f1 4f0 2f1 5f0 2f1 8f0 2f1 10f0 6f1 5f0 71f1 8f0 70f1 3f0 The simple Lisp functions ABS, MAX, MIN and REMAINDER have also been extended. As well as being extended, MAX and MIN have both been modified so that they ignore NIL arguments. Thus, (MAX 1 NIL 2) is 1, not NIL.e12j\26f1 3f0 2f1 3f0 2f1 3f0 5f1 9f0 54f1 3f0 5f1 3f0 45f1 3f0 19f1 5f0g1f1G6f0g1f1G3f0 3g1G7f1 3f0 The mixed arithmetic predicates have been modified in IDL so that they provide a reasonable result when applied to a missing data item. These functions have not been extended, however, since they return the truth values T and NIL, which cannot both be stored into an array. The predicates from Lisp are GREATERP, LESSP, EQP, and MINUSP. For convenience, the function PLUSP also exists in IDL and is T for any argument greater than zero. As mentioned in section 1.4, the missing data value compares EQP to NIL. As a somewhat arbitrary choice, necessitated by the binary nature of truth, it compares as if it is zero for the GREATERP and LESSP predicates, and is neither MINUSP nor PLUSP.e12j\54f1 3f0 164f1 1f0 5f1 3f0 75f1 8f0 2f1 5f0 2f1 3f0 6f1 6f0 33f1 5f0 16f1 3f0 8f1 1f0 99f1 3f0 4f1 3f0 116f1 8f0 5f1 5f0 28f1 6f0 5f1 5f0 scalarp[s] is T if s is a scalar, NIL otherwise.e12j\14f1 1f0 4b1B14f1 3f0 3.2 Constantse18j The following variables are initialized to some common mathematical constants. If changed by the user, their values are lost and must be reset.e12j E is set to the base of the natural logarithms. PI is set to p. l4233e4j\61f4 1f0 3.3 Mathematical and trigonometric functionse18j The following scalar functions have been extended: SQRT (which returns NIL for negative arguments), LOG (which also returns NIL for negative arguments), ANTILOG, EXPT (with associated CLISP operator ^), and GCD. These are fully described in Section 13 of the Interlisp Reference Manual (Teitelman, 1978). e12j\52f1 4f0 16f1 3f0 26f1 3f0 21f1 3f0 26f1 7f0 2f1 4f0 18f1 5f0 18f1 3f0 Interlisp's trigonometric functions (SIN, COS, TAN, ARCSIN, ARCCOS, and ARCTAN) have been extended to expect scalars. All these functions have an optional flag argument which if T indicates that all angle sizes are to be interpreted in radians. If the flag is NIL or omitted, arguments and values will be in degrees. Again, see Section 13 of the Interlisp Reference Manual. e12j\37f1 3f0 2f1 3f0 2f1 3f0 2f1 6f0 2f1 6f0 6f1 6f0 101f1 1f0 82f1 3f0 3.4 Distribution functionse18jk36(1,65535) IDL provides several functions for evaluating the probability of values drawn from certain common statistical distributions.e12j(1,635)\f1 3f0 fprob[f;dfnum;dfden] where dfnum and dfden are the degrees of freedom for the numerator and denominator, respectively, of the F-value f, returns the probability of such an F-value.l4233d2999e6j\27b5B5b5B84i1I7b1B37i1I nprob[z] where z is a normal deviate, returns the probability of such a normal deviate.l4233d2999e6j\15b1B tprob[x;df] where df is the degrees of freedom for t-value x, returns the probability of such a t-value.l4233d2999e6j\18b2B31i1I7b1B36i1I At a future date, binomial and x2 distribution functions may be added.e12j\31f4 1f1o4 1f0o0 3.5 RAND and RANDNe18j Uniformly distributed random numbers can be obtained from the Interlisp RAND function, and random normal deviates from the function RANDN. Both are extended to expect scalars.e12j\72f1 4f0 56f1 5f0 rand[lower;upper] returns a single pseudo-random number between lower and upper inclusive.l4233d2999e6j\64b5B5b5B randn[mean;stdev] returns a single floating number, randomly sampled from the normal distribution with mean mean (default 0) and standard deviation stdev (default 1).l4233d2999e6j\108b4B36b5B The Lisp function RANDSET may be used to initialize the random-number generator that both these functions depend on. e12j\18f1 7f0 At a future date, generators for random deviates from other distributions may be added.e12j 3.6 ROUNDe18j The function ROUND rounds a number to a specified tolerance.e12j\13f1 5f0 round[val;interval] for scalar val and interval, returns the nearest integral multiple of interval to val. interval defaults to one, i.e., rounding to the nearest integer.l4233d2999e8j\31b3B5b8B43b8B4b3B3b8B Thus, (ROUND INCOMES 1000) will round a vector of dollar incomes to the nearest $1000. Note that rounding is to the nearest multiple, as opposed to truncation, so (ROUND 1.4 0.5) is 1.5, not 1.e12j\6f1 20f0 59f1 1f0 31i7I40f1 15f0 4g3G ROUND is useful for converting a continuous measure into a GROUP classifier.e12j\f1 5f0 54f1 5f0 3.7 SAMEe18j The Lisp comparison functions (EQP, etc.) return either T or NIL. Occasionally, it is useful to have a predicate function return an arithmetic value, so that the results of such a comparison can be assembled into an array. SAME provides this alternative to EQP.e12j\31f1 3f0 22f1 1f0 4f1 3f0 161f1 4f0 30f1 3f0 same[a;b] for scalar a and b, returns one if a and b are EQP, else zero.l4233d2999e8j\21b1B5b1B17b1B5b1B5f1 3f0 This is useful when applied to arrays rather than individual scalars, as the result can be manipulated to derive array properties. For example, reducing the result with TIMES or LOGAND will indicate whether two separate arrays have identical elements or which of their rows or columns are the same. Thus, (RTIMES (SAME X Y)) is one if X and Y are the same; (RTIMES (KEEP (SAME X Y) 2)) is a vector indicating which columns are the same.e12j\170f1 5f0 4f1 6f0 122f1 19f0 11f1 1f0 5f1 1f0 14f1 29f0 51f6 3.8 TRANSLATEe18j TRANSLATE provides a table-driven translation facility that is particularly useful for recoding.e12j\f1 9f0 translate[s;table;default] where s is a scalar to be translated, table is a translation matrix, and default is an (optional) default value to be used if there is no translation for s in table. TRANSLATE provides three types of translation, depending on the number of columns in table:l4233d2999e8j\33b1B31b5B30b7B74b1B4b5B3f1 9f0 76b5B One column: If table is an [N,1]-matrix, TRANSLATE returns the smallest row index r of table such that table@'(r 1) is s.l4233e8j\16b5B21f1 9f0 32i1I4b5B11b5B3i1I7b1B Two columns: If table is an [N,2]-matrix, TRANSLATE returns table@'(r 2) for the smallest r such that table@'(r 1) is s. That is, it returns the second element of the row whose first element matches s.l4233e8j\17b5B21f1 9f0 9b5B3i1I21i1I11b5B3i1I7b1B81b1B Three columns: If table is an [N,3]-matrix, TRANSLATE returns table@'(r 3) for the smallest r such that table@'(r 1) < s < table@'(r 2). That is, it returns the third element of the first row such that s is in the interval defined by its first two elements. NIL receives special treatment:l4233e8j\19b5B21f1 9f0 9b5B3i1I21i1I11b5B3i1I4f3 1f0 1b1B1f3 1f0 1b5B3i1I71b1B56f1 3f0 NIL NIL X translates a NIL s to X NIL Y X Y not NIL, translates any s < Y to X Y NIL X Y not NIL, translates any s > Y to X l5503e8j(0,6432)(1,7616)(2,8992)\f1 3f0t1 1f1t0 3f0t2 1f1t0 1f0t3 1t0 13f1 3f0 1b1B4f1 1f0 1f1 3f0 2f1 1f0 1f1 1f0 1f1 1f0 5f1 3f0 17b2f3B1f0 1f1 1f0 4f1 1f0b1B1f1 1f0 1f1 3f0 1f1 1f0 1f1 1f0 5f1 3f0 17b2f3B1f0 1f1 1f0 4f1 1f0b1B In all cases, if no match for s is found in the translation table, default is returned if it was given, otherwise s.l4233e8j(0,65535)(1,635)(2,65535)\30b1B36b7B40b1B TRANSLATE is extended on all its arguments. Thus, one can translate an entire array, obtain a vector of one scalar translated according to several different translation tables, or both at once (producing a multi-dimensional array). For example, TRANSLATE is commonly used for recoding a variable, represented as a vector or column of a matrix. Because of extension, the output will be an image of s (the variable) with each value mapped into an index (one-column table), a scalar corresponding to the old value (two-column table), or a scalar corresponding to the interval in which the old value lies (three-column table). The latter case is particularly useful for categorizing continuous variables. e12j\f1 9f0 238f1 9f0 144b1B65b5B55b5B87b5B