expressions: Implement the STRUNC function.
[pspp] / doc / expressions.texi
1 @c Use @func when refering to a function.
2 @c Use @deftypefn for their definitions 
3 @macro func{NAME}
4 @code{/NAME/}
5 @end macro
6
7 @node Expressions
8 @chapter Mathematical Expressions
9 @cindex expressions, mathematical
10 @cindex mathematical expressions
11
12 Expressions share a common syntax each place they appear in @pspp{}
13 commands.  Expressions are made up of @dfn{operands}, which can be
14 numbers, strings, or variable names, separated by @dfn{operators}.
15 There are five types of operators: grouping, arithmetic, logical,
16 relational, and functions.
17
18 Every operator takes one or more operands as input and yields exactly
19 one result as output.  Depending on the operator, operands accept
20 strings or numbers as operands.  With few exceptions, operands may be
21 full-fledged expressions in themselves.
22
23 @menu
24 * Boolean Values::                 Boolean values
25 * Missing Values in Expressions::  Using missing values in expressions
26 * Grouping Operators::             parentheses
27 * Arithmetic Operators::           add sub mul div pow
28 * Logical Operators::              AND NOT OR
29 * Relational Operators::           EQ GE GT LE LT NE
30 * Functions::                      More-sophisticated operators
31 * Order of Operations::            Operator precedence
32 @end menu
33
34 @node Boolean Values
35 @section Boolean Values
36 @cindex Boolean
37 @cindex values, Boolean
38
39 Some @pspp{} operators and expressions work with Boolean values, which
40 represent true/false conditions.  Booleans have only three possible
41 values: 0 (false), 1 (true), and system-missing (unknown).
42 System-missing is neither true nor false and indicates that the true
43 value is unknown.
44
45 Boolean-typed operands or function arguments must take on one of these
46 three values.  Other values are considered false, but provoke a warning
47 when the expression is evaluated.
48
49 Strings and Booleans are not compatible, and neither may be used in
50 place of the other.
51
52 @node Missing Values in Expressions
53 @section Missing Values in Expressions
54
55 Most numeric operators yield system-missing when given any
56 system-missing operand.  A string operator given any system-missing
57 operand typically results in the empty string.  Exceptions are listed
58 under particular operator descriptions.
59
60 String user-missing values are not treated specially in expressions.
61
62 User-missing values for numeric variables are always transformed into
63 the system-missing value, except inside the arguments to the
64 @code{VALUE} and @code{SYSMIS} functions.
65
66 The missing-value functions can be used to precisely control how missing
67 values are treated in expressions.  @xref{Missing Value Functions}, for
68 more details.
69
70 @node Grouping Operators
71 @section Grouping Operators
72 @cindex parentheses
73 @cindex @samp{(  )}
74 @cindex grouping operators
75 @cindex operators, grouping
76
77 Parentheses (@samp{()}) are the grouping operators.  Surround an
78 expression with parentheses to force early evaluation.
79
80 Parentheses also surround the arguments to functions, but in that
81 situation they act as punctuators, not as operators.
82
83 @node Arithmetic Operators
84 @section Arithmetic Operators
85 @cindex operators, arithmetic
86 @cindex arithmetic operators
87
88 The arithmetic operators take numeric operands and produce numeric
89 results.
90
91 @table @code
92 @cindex @samp{+}
93 @cindex addition
94 @item @var{a} + @var{b}
95 Yields the sum of @var{a} and @var{b}.
96
97 @cindex @samp{-}
98 @cindex subtraction
99 @item @var{a} - @var{b}
100 Subtracts @var{b} from @var{a} and yields the difference.
101
102 @cindex @samp{*}
103 @cindex multiplication
104 @item @var{a} * @var{b}
105 Yields the product of @var{a} and @var{b}.  If either @var{a} or
106 @var{b} is 0, then the result is 0, even if the other operand is
107 missing.
108
109 @cindex @samp{/}
110 @cindex division
111 @item @var{a} / @var{b}
112 Divides @var{a} by @var{b} and yields the quotient.  If @var{a} is 0,
113 then the result is 0, even if @var{b} is missing.  If @var{b} is zero,
114 the result is system-missing.
115
116 @cindex @samp{**}
117 @cindex exponentiation
118 @item @var{a} ** @var{b}
119 Yields the result of raising @var{a} to the power @var{b}.  If
120 @var{a} is negative and @var{b} is not an integer, the result is
121 system-missing.  The result of @code{0**0} is system-missing as well.
122
123 @cindex @samp{-}
124 @cindex negation
125 @item - @var{a}
126 Reverses the sign of @var{a}.  
127 @end table
128
129 @node Logical Operators
130 @section Logical Operators
131 @cindex logical operators
132 @cindex operators, logical
133
134 @cindex true
135 @cindex false
136 @cindex Boolean
137 @cindex values, system-missing
138 @cindex system-missing
139 The logical operators take logical operands and produce logical
140 results, meaning ``true or false.''  Logical operators are
141 not true Boolean operators because they may also result in a
142 system-missing value.  @xref{Boolean Values}, for more information.
143
144 @table @code
145 @cindex @code{AND}
146 @cindex @samp{&}
147 @cindex intersection, logical
148 @cindex logical intersection
149 @item @var{a} AND @var{b}
150 @itemx @var{a} & @var{b}
151 True if both @var{a} and @var{b} are true, false otherwise.  If one
152 operand is false, the result is false even if the other is missing.  If
153 both operands are missing, the result is missing.
154
155 @cindex @code{OR}
156 @cindex @samp{|}
157 @cindex union, logical
158 @cindex logical union
159 @item @var{a} OR @var{b}
160 @itemx @var{a} | @var{b}
161 True if at least one of @var{a} and @var{b} is true.  If one operand is
162 true, the result is true even if the other operand is missing.  If both
163 operands are missing, the result is missing.
164
165 @cindex @code{NOT}
166 @cindex @samp{~}
167 @cindex inversion, logical
168 @cindex logical inversion
169 @item NOT @var{a}
170 @itemx ~ @var{a}
171 True if @var{a} is false.  If the operand is missing, then the result
172 is missing.
173 @end table
174
175 @node Relational Operators
176 @section Relational Operators
177
178 The relational operators take numeric or string operands and produce Boolean
179 results.
180
181 Strings cannot be compared to numbers.  When strings of different
182 lengths are compared, the shorter string is right-padded with spaces
183 to match the length of the longer string.
184
185 The results of string comparisons, other than tests for equality or
186 inequality, depend on the character set in use.  String comparisons
187 are case-sensitive.
188
189 @table @code
190 @cindex equality, testing
191 @cindex testing for equality
192 @cindex @code{EQ}
193 @cindex @samp{=}
194 @item @var{a} EQ @var{b}
195 @itemx @var{a} = @var{b}
196 True if @var{a} is equal to @var{b}.
197
198 @cindex less than or equal to
199 @cindex @code{LE}
200 @cindex @code{<=}
201 @item @var{a} LE @var{b}
202 @itemx @var{a} <= @var{b}
203 True if @var{a} is less than or equal to @var{b}.
204
205 @cindex less than
206 @cindex @code{LT}
207 @cindex @code{<}
208 @item @var{a} LT @var{b}
209 @itemx @var{a} < @var{b}
210 True if @var{a} is less than @var{b}.
211
212 @cindex greater than or equal to
213 @cindex @code{GE}
214 @cindex @code{>=}
215 @item @var{a} GE @var{b}
216 @itemx @var{a} >= @var{b}
217 True if @var{a} is greater than or equal to @var{b}.
218
219 @cindex greater than
220 @cindex @code{GT}
221 @cindex @samp{>}
222 @item @var{a} GT @var{b}
223 @itemx @var{a} > @var{b}
224 True if @var{a} is greater than @var{b}.
225
226 @cindex inequality, testing
227 @cindex testing for inequality
228 @cindex @code{NE}
229 @cindex @code{~=}
230 @cindex @code{<>}
231 @item @var{a} NE @var{b}
232 @itemx @var{a} ~= @var{b}
233 @itemx @var{a} <> @var{b}
234 True if @var{a} is not equal to @var{b}.
235 @end table
236
237 @node Functions
238 @section Functions
239 @cindex functions
240
241 @cindex mathematics
242 @cindex operators
243 @cindex parentheses
244 @cindex @code{(}
245 @cindex @code{)}
246 @cindex names, of functions
247 @pspp{} functions provide mathematical abilities above and beyond
248 those possible using simple operators.  Functions have a common
249 syntax: each is composed of a function name followed by a left
250 parenthesis, one or more arguments, and a right parenthesis.
251
252 Function names are not reserved.  Their names are specially treated
253 only when followed by a left parenthesis, so that @samp{EXP(10)}
254 refers to the constant value @math{e} raised to the 10th power, but
255 @samp{EXP} by itself refers to the value of a variable called @code{EXP}.
256
257 The sections below describe each function in detail.
258
259 @menu
260 * Mathematics::                 EXP LG10 LN LNGAMMA SQRT
261 * Miscellaneous Mathematics::   ABS MOD MOD10 RND TRUNC
262 * Trigonometry::                ACOS ARCOS ARSIN ARTAN ASIN ATAN COS SIN TAN
263 * Missing Value Functions::     MISSING NMISS NVALID SYSMIS VALUE
264 * Set Membership::              ANY RANGE
265 * Statistical Functions::       CFVAR MAX MEAN MEDIAN MIN SD SUM VARIANCE
266 * String Functions::            CONCAT INDEX LENGTH LOWER LPAD LTRIM NUMBER 
267                                 REPLACE RINDEX RPAD RTRIM STRING STRUNC SUBSTR
268                                 UPCASE
269 * Time and Date::               CTIME.xxx DATE.xxx TIME.xxx XDATE.xxx
270                                 DATEDIFF DATESUM
271 * Miscellaneous Functions::     LAG YRMODA VALUELABEL
272 * Statistical Distribution Functions::  PDF CDF SIG IDF RV NPDF NCDF
273 @end menu
274
275 @node Mathematics
276 @subsection Mathematical Functions
277 @cindex mathematics, advanced
278
279 Advanced mathematical functions take numeric arguments and produce
280 numeric results.
281
282 @deftypefn {Function} {} EXP (@var{exponent})
283 Returns @math{e} (approximately 2.71828) raised to power @var{exponent}.
284 @end deftypefn
285
286 @cindex logarithms
287 @deftypefn {Function} {} LG10 (@var{number})
288 Takes the base-10 logarithm of @var{number}.  If @var{number} is
289 not positive, the result is system-missing.
290 @end deftypefn
291
292 @deftypefn {Function} {} LN (@var{number})
293 Takes the base-@math{e} logarithm of @var{number}.  If @var{number} is
294 not positive, the result is system-missing.
295 @end deftypefn
296
297 @deftypefn {Function} {} LNGAMMA (@var{number})
298 Yields the base-@math{e} logarithm of the complete gamma of @var{number}.
299 If @var{number} is a negative integer, the result is system-missing.
300 @end deftypefn
301
302 @cindex square roots
303 @deftypefn {Function} {} SQRT (@var{number})
304 Takes the square root of @var{number}.  If @var{number} is negative,
305 the result is system-missing.
306 @end deftypefn
307
308 @node Miscellaneous Mathematics
309 @subsection Miscellaneous Mathematical Functions
310 @cindex mathematics, miscellaneous
311
312 Miscellaneous mathematical functions take numeric arguments and produce
313 numeric results.
314
315 @cindex absolute value
316 @deftypefn {Function} {} ABS (@var{number})
317 Results in the absolute value of @var{number}.
318 @end deftypefn
319
320 @cindex modulus
321 @deftypefn {Function} {} MOD (@var{numerator}, @var{denominator})
322 Returns the remainder (modulus) of @var{numerator} divided by
323 @var{denominator}.  If @var{numerator} is 0, then the result is 0,
324 even if @var{denominator} is missing.  If @var{denominator} is 0, the
325 result is system-missing.
326 @end deftypefn
327
328 @cindex modulus, by 10
329 @deftypefn {Function} {} MOD10 (@var{number})
330 Returns the remainder when @var{number} is divided by 10.  If
331 @var{number} is negative, MOD10(@var{number}) is negative or zero.
332 @end deftypefn
333
334 @cindex rounding
335 @deftypefn {Function} {} RND (@var{number} [, @var{mult}[, @var{fuzzbits}]])
336 Rounds @var{number} and rounds it to a multiple of @var{mult} (by
337 default 1).  Halves are rounded away from zero, as are values that
338 fall short of halves by less than @var{fuzzbits} of errors in the
339 least-significant bits of @var{number}.  If @var{fuzzbits} is not
340 specified then the default is taken from SET FUZZBITS (@pxref{SET
341 FUZZBITS}), which is 6 unless overridden.
342 @end deftypefn
343
344 @cindex truncation
345 @deftypefn {Function} {} TRUNC (@var{number})
346 Discards the fractional part of @var{number}; that is, rounds
347 @var{number} towards zero.
348 @end deftypefn
349
350 @node Trigonometry
351 @subsection Trigonometric Functions
352 @cindex trigonometry
353
354 Trigonometric functions take numeric arguments and produce numeric
355 results.
356
357 @cindex arccosine
358 @cindex inverse cosine
359 @deftypefn {Function} {} ARCOS (@var{number})
360 @deftypefnx {Function} {} ACOS (@var{number})
361 Takes the arccosine, in radians, of @var{number}.  Results in
362 system-missing if @var{number} is not between -1 and 1 inclusive.
363 This function is a @pspp{} extension.
364 @end deftypefn
365
366 @cindex arcsine
367 @cindex inverse sine
368 @deftypefn {Function} {} ARSIN (@var{number})
369 @deftypefnx {Function} {} ASIN (@var{number})
370 Takes the arcsine, in radians, of @var{number}.  Results in
371 system-missing if @var{number} is not between -1 and 1 inclusive.
372 @end deftypefn
373
374 @cindex arctangent
375 @cindex inverse tangent
376 @deftypefn {Function} {} ARTAN (@var{number})
377 @deftypefnx {Function} {} ATAN (@var{number})
378 Takes the arctangent, in radians, of @var{number}.
379 @end deftypefn
380
381 @cindex cosine
382 @deftypefn {Function} {} COS (@var{angle})
383 Takes the cosine of @var{angle} which should be in radians.
384 @end deftypefn
385
386 @cindex sine
387 @deftypefn {Function} {} SIN (@var{angle})
388 Takes the sine of @var{angle} which should be in radians.
389 @end deftypefn
390
391 @cindex tangent
392 @deftypefn {Function} {} TAN (@var{angle})
393 Takes the tangent of @var{angle} which should be in radians.
394 Results in system-missing at values
395 of @var{angle} that are too close to odd multiples of @math{\pi/2}.
396 Portability: none.
397 @end deftypefn
398
399 @node Missing Value Functions
400 @subsection Missing-Value Functions
401 @cindex missing values
402 @cindex values, missing
403 @cindex functions, missing-value
404
405 Missing-value functions take various numeric arguments and yield
406 various types of results.  Except where otherwise stated below, the
407 normal rules of evaluation apply within expression arguments to these
408 functions.  In particular, user-missing values for numeric variables
409 are converted to system-missing values.
410
411 @deftypefn {Function} {} MISSING (@var{expr})
412 Returns 1 if @var{expr} has the system-missing value, 0 otherwise.
413 @end deftypefn
414
415 @deftypefn {Function} {} NMISS (@var{expr} [, @var{expr}]@dots{})
416 Each argument must be a numeric expression.  Returns the number of
417 system-missing values in the list, which may include variable ranges
418 using the @code{@var{var1} TO @var{var2}} syntax.
419 @end deftypefn
420
421 @deftypefn {Function} {} NVALID (@var{expr} [, @var{expr}]@dots{})
422 Each argument must be a numeric expression.  Returns the number of
423 values in the list that are not system-missing.  The list may include
424 variable ranges using the @code{@var{var1} TO @var{var2}} syntax.
425 @end deftypefn
426
427 @deftypefn {Function} {} SYSMIS (@var{expr})
428 When @var{expr} is simply the name of a numeric variable, returns 1 if
429 the variable has the system-missing value, 0 if it is user-missing or
430 not missing.  If given @var{expr} takes another form, results in 1 if
431 the value is system-missing, 0 otherwise.
432 @end deftypefn
433
434 @deftypefn {Function} {} VALUE (@var{variable})
435 Prevents the user-missing values of @var{variable} from being
436 transformed into system-missing values, and always results in the
437 actual value of @var{variable}, whether it is valid, user-missing, or
438 system-missing.
439 @end deftypefn
440
441 @node Set Membership
442 @subsection Set-Membership Functions
443 @cindex set membership
444 @cindex membership, of set
445
446 Set membership functions determine whether a value is a member of a set.
447 They take a set of numeric arguments or a set of string arguments, and
448 produce Boolean results.
449
450 String comparisons are performed according to the rules given in
451 @ref{Relational Operators}.
452
453 @deftypefn {Function} {} ANY (@var{value}, @var{set} [, @var{set}]@dots{})
454 Results in true if @var{value} is equal to any of the @var{set}
455 values.  Otherwise, results in false.  If @var{value} is
456 system-missing, returns system-missing.  System-missing values in
457 @var{set} do not cause @func{ANY} to return system-missing.
458 @end deftypefn
459
460 @deftypefn {Function} {} RANGE (@var{value}, @var{low}, @var{high} [, @var{low}, @var{high}]@dots{})
461 Results in true if @var{value} is in any of the intervals bounded by
462 @var{low} and @var{high} inclusive.  Otherwise, results in false.
463 Each @var{low} must be less than or equal to its corresponding
464 @var{high} value.  @var{low} and @var{high} must be given in pairs.
465 If @var{value} is system-missing, returns system-missing.
466 System-missing values in @var{set} do not cause @func{RANGE} to return
467 system-missing.
468 @end deftypefn
469
470 @node Statistical Functions
471 @subsection Statistical Functions
472 @cindex functions, statistical
473 @cindex statistics
474
475 Statistical functions compute descriptive statistics on a list of
476 values.  Some statistics can be computed on numeric or string values;
477 other can only be computed on numeric values.  Their results have the
478 same type as their arguments.  The current case's weighting factor
479 (@pxref{WEIGHT}) has no effect on statistical functions.
480
481 These functions' argument lists may include entire ranges of variables
482 using the @code{@var{var1} TO @var{var2}} syntax.
483
484 @cindex arguments, minimum valid
485 @cindex minimum valid number of arguments
486 Unlike most functions, statistical functions can return non-missing
487 values even when some of their arguments are missing.  Most
488 statistical functions, by default, require only 1 non-missing value to
489 have a non-missing return, but @func{CFVAR}, @func{SD}, and @func {VARIANCE} require 2.
490 These defaults can be increased (but not decreased) by appending a dot
491 and the minimum number of valid arguments to the function name.  For
492 example, @subcmd{MEAN.3(X, Y, Z)} would only return non-missing if all
493 of @samp{X}, @samp{Y}, and @samp{Z} were valid.
494
495 @cindex coefficient of variation
496 @cindex variation, coefficient of
497 @deftypefn {Function} {} CFVAR (@var{number}, @var{number}[, @dots{}])
498 Results in the coefficient of variation of the values of @var{number}.
499 (The coefficient of variation is the standard deviation divided by the
500 mean.)
501 @end deftypefn
502
503 @cindex maximum
504 @deftypefn {Function} {} MAX (@var{value}, @var{value}[, @dots{}])
505 Results in the value of the greatest @var{value}.  The @var{value}s may
506 be numeric or string.
507 @end deftypefn
508
509 @cindex mean
510 @deftypefn {Function} {} MEAN (@var{number}, @var{number}[, @dots{}])
511 Results in the mean of the values of @var{number}.
512 @end deftypefn
513
514 @cindex median
515 @deftypefn {Function} {} MEDIAN (@var{number}, @var{number}[, @dots{}])
516 Results in the median of the values of @var{number}.  Given an even
517 number of nonmissing arguments, yields the mean of the two middle
518 values.
519 @end deftypefn
520
521 @cindex minimum
522 @deftypefn {Function} {} MIN (@var{number}, @var{number}[, @dots{}])
523 Results in the value of the least @var{value}.  The @var{value}s may
524 be numeric or string.
525 @end deftypefn
526
527 @cindex standard deviation
528 @cindex deviation, standard
529 @deftypefn {Function} {} SD (@var{number}, @var{number}[, @dots{}])
530 Results in the standard deviation of the values of @var{number}.
531 @end deftypefn
532
533 @cindex sum
534 @deftypefn {Function} {} SUM (@var{number}, @var{number}[, @dots{}])
535 Results in the sum of the values of @var{number}.
536 @end deftypefn
537
538 @cindex variance
539 @deftypefn {Function} {} VARIANCE (@var{number}, @var{number}[, @dots{}])
540 Results in the variance of the values of @var{number}.
541 @end deftypefn
542
543 @node String Functions
544 @subsection String Functions
545 @cindex functions, string
546 @cindex string functions
547
548 String functions take various arguments and return various results.
549
550 @cindex concatenation
551 @cindex strings, concatenation of
552 @deftypefn {Function} {} CONCAT (@var{string}, @var{string}[, @dots{}])
553 Returns a string consisting of each @var{string} in sequence.
554 @code{CONCAT("abc", "def", "ghi")} has a value of @code{"abcdefghi"}.
555 The resultant string is truncated to a maximum of 255 characters.
556 @end deftypefn
557
558 @cindex searching strings
559 @deftypefn {Function} {} INDEX (@var{haystack}, @var{needle})
560 Returns a positive integer indicating the position of the first
561 occurrence of @var{needle} in @var{haystack}.  Returns 0 if @var{haystack}
562 does not contain @var{needle}.  Returns system-missing if @var{needle}
563 is an empty string.
564 @end deftypefn
565
566 @deftypefn {Function} {} INDEX (@var{haystack}, @var{needles}, @var{needle_len})
567 Divides @var{needles} into one or more needles, each with length
568 @var{needle_len}.
569 Searches @var{haystack} for the first occurrence of each needle, and
570 returns the smallest value.  Returns 0 if @var{haystack} does not
571 contain any part in @var{needle}.  It is an error if @var{needle_len}
572 does not evenly divide the length of @var{needles}.  Returns
573 system-missing if @var{needles} is an empty string.
574 @end deftypefn
575
576 @cindex strings, finding length of
577 @deftypefn {Function} {} LENGTH (@var{string})
578 Returns the number of characters in @var{string}.
579 @end deftypefn
580
581 @cindex strings, case of
582 @deftypefn {Function} {} LOWER (@var{string})
583 Returns a string identical to @var{string} except that all uppercase
584 letters are changed to lowercase letters.  The definitions of
585 ``uppercase'' and ``lowercase'' are system-dependent.
586 @end deftypefn
587
588 @cindex strings, padding
589 @deftypefn {Function} {} LPAD (@var{string}, @var{length})
590 If @var{string} is at least @var{length} characters in length, returns
591 @var{string} unchanged.  Otherwise, returns @var{string} padded with
592 spaces on the left side to length @var{length}.  Returns an empty string
593 if @var{length} is system-missing, negative, or greater than 255.
594 @end deftypefn
595
596 @deftypefn {Function} {} LPAD (@var{string}, @var{length}, @var{padding})
597 If @var{string} is at least @var{length} characters in length, returns
598 @var{string} unchanged.  Otherwise, returns @var{string} padded with
599 @var{padding} on the left side to length @var{length}.  Returns an empty
600 string if @var{length} is system-missing, negative, or greater than 255, or
601 if @var{padding} does not contain exactly one character.
602 @end deftypefn
603
604 @cindex strings, trimming
605 @cindex white space, trimming
606 @deftypefn {Function} {} LTRIM (@var{string})
607 Returns @var{string}, after removing leading spaces.  Other white space,
608 such as tabs, carriage returns, line feeds, and vertical tabs, is not
609 removed.
610 @end deftypefn
611
612 @deftypefn {Function} {} LTRIM (@var{string}, @var{padding})
613 Returns @var{string}, after removing leading @var{padding} characters.
614 If @var{padding} does not contain exactly one character, returns an
615 empty string.
616 @end deftypefn
617
618 @cindex numbers, converting from strings
619 @cindex strings, converting to numbers
620 @deftypefn {Function} {} NUMBER (@var{string}, @var{format})
621 Returns the number produced when @var{string} is interpreted according
622 to format specifier @var{format}.  If the format width @var{w} is less
623 than the length of @var{string}, then only the first @var{w}
624 characters in @var{string} are used, e.g.@: @code{NUMBER("123", F3.0)}
625 and @code{NUMBER("1234", F3.0)} both have value 123.  If @var{w} is
626 greater than @var{string}'s length, then it is treated as if it were
627 right-padded with spaces.  If @var{string} is not in the correct
628 format for @var{format}, system-missing is returned.
629 @end deftypefn
630
631 @cindex strings, replacing substrings
632 @cindex replacing substrings
633 @deftypefn {Function} {} REPLACE (@var{haystack}, @var{needle}, @var{replacement}[, @var{n}])
634 Returns string @var{haystack} with instances of @var{needle} replaced
635 by @var{replacement}.  If nonnegative integer @var{n} is specified, it
636 limits the maximum number of replacements; otherwise, all instances of
637 @var{needle} are replaced.
638 @end deftypefn
639
640 @cindex strings, searching backwards
641 @deftypefn {Function} {} RINDEX (@var{haystack}, @var{needle})
642 Returns a positive integer indicating the position of the last
643 occurrence of @var{needle} in @var{haystack}.  Returns 0 if
644 @var{haystack} does not contain @var{needle}.  Returns system-missing if
645 @var{needle} is an empty string.
646 @end deftypefn
647
648 @deftypefn {Function} {} RINDEX (@var{haystack}, @var{needle}, @var{needle_len})
649 Divides @var{needle} into parts, each with length @var{needle_len}.
650 Searches @var{haystack} for the last occurrence of each part, and
651 returns the largest value.  Returns 0 if @var{haystack} does not contain
652 any part in @var{needle}.  It is an error if @var{needle_len} does not
653 evenly divide the length of @var{needle}.  Returns system-missing
654 if @var{needle} is an empty string or if needle_len is less than 1.
655 @end deftypefn
656
657 @cindex padding strings
658 @cindex strings, padding
659 @deftypefn {Function} {} RPAD (@var{string}, @var{length})
660 If @var{string} is at least @var{length} characters in length, returns
661 @var{string} unchanged.  Otherwise, returns @var{string} padded with
662 spaces on the right to length @var{length}.  Returns an empty string if
663 @var{length} is system-missing, negative, or greater than 255.
664 @end deftypefn
665
666 @deftypefn {Function} {} RPAD (@var{string}, @var{length}, @var{padding})
667 If @var{string} is at least @var{length} characters in length, returns
668 @var{string} unchanged.  Otherwise, returns @var{string} padded with
669 @var{padding} on the right to length @var{length}.  Returns an empty
670 string if @var{length} is system-missing, negative, or greater than 255,
671 or if @var{padding} does not contain exactly one character.
672 @end deftypefn
673
674 @cindex strings, trimming
675 @cindex white space, trimming
676 @deftypefn {Function} {} RTRIM (@var{string})
677 Returns @var{string}, after removing trailing spaces.  Other types of
678 white space are not removed.
679 @end deftypefn
680
681 @deftypefn {Function} {} RTRIM (@var{string}, @var{padding})
682 Returns @var{string}, after removing trailing @var{padding} characters.
683 If @var{padding} does not contain exactly one character, returns an
684 empty string.
685 @end deftypefn
686
687 @cindex strings, converting from numbers
688 @cindex numbers, converting to strings
689 @deftypefn {Function} {} STRING (@var{number}, @var{format})
690 Returns a string corresponding to @var{number} in the format given by
691 format specifier @var{format}.  For example, @code{STRING(123.56, F5.1)}
692 has the value @code{"123.6"}.
693 @end deftypefn
694
695 @cindex strings, trimming
696 @cindex strings, truncating
697 @cindex white space, trimming
698 @deftypefn {Function} {} STRUNC (@var{string}, @var{n})
699 Returns @var{string}, first trimming it to at most @var{n} bytes, then
700 removing trailing spaces.  Returns an empty string if @var{n} is
701 missing or negative.
702 @end deftypefn
703
704 @cindex substrings
705 @cindex strings, taking substrings of
706 @deftypefn {Function} {} SUBSTR (@var{string}, @var{start})
707 Returns a string consisting of the value of @var{string} from position
708 @var{start} onward.  Returns an empty string if @var{start} is system-missing,
709 less than 1, or greater than the length of @var{string}.
710 @end deftypefn
711
712 @deftypefn {Function} {} SUBSTR (@var{string}, @var{start}, @var{count})
713 Returns a string consisting of the first @var{count} characters from
714 @var{string} beginning at position @var{start}.  Returns an empty string
715 if @var{start} or @var{count} is system-missing, if @var{start} is less
716 than 1 or greater than the number of characters in @var{string}, or if
717 @var{count} is less than 1.  Returns a string shorter than @var{count}
718 characters if @var{start} + @var{count} - 1 is greater than the number
719 of characters in @var{string}.  Examples: @code{SUBSTR("abcdefg", 3, 2)}
720 has value @code{"cd"}; @code{SUBSTR("nonsense", 4, 10)} has the value
721 @code{"sense"}.
722 @end deftypefn
723
724 @cindex case conversion
725 @cindex strings, case of
726 @deftypefn {Function} {} UPCASE (@var{string})
727 Returns @var{string}, changing lowercase letters to uppercase letters.
728 @end deftypefn
729
730 @node Time and Date
731 @subsection Time & Date Functions
732 @cindex functions, time & date
733 @cindex times
734 @cindex dates
735
736 @cindex dates, valid
737 For compatibility, @pspp{} considers dates before 15 Oct 1582 invalid.
738 Most time and date functions will not accept earlier dates.
739
740 @menu
741 * Time and Date Concepts::      How times & dates are defined and represented
742 * Time Construction::           TIME.@{DAYS HMS@}
743 * Time Extraction::             CTIME.@{DAYS HOURS MINUTES SECONDS@}
744 * Date Construction::           DATE.@{DMY MDY MOYR QYR WKYR YRDAY@}
745 * Date Extraction::             XDATE.@{DATE HOUR JDAY MDAY MINUTE MONTH
746                                        QUARTER SECOND TDAY TIME WEEK
747                                        WKDAY YEAR@}
748 * Time and Date Arithmetic::    DATEDIFF DATESUM
749 @end menu
750
751 @node Time and Date Concepts
752 @subsubsection How times & dates are defined and represented
753
754 @cindex time, concepts
755 @cindex time, intervals
756 Times and dates are handled by @pspp{} as single numbers.  A
757 @dfn{time} is an interval.  @pspp{} measures times in seconds.
758 Thus, the following intervals correspond with the numeric values given:
759                 
760 @example
761           10 minutes                        600
762           1 hour                          3,600
763           1 day, 3 hours, 10 seconds     97,210
764           40 days                     3,456,000
765 @end example
766
767 @cindex dates, concepts
768 @cindex time, instants of
769 A @dfn{date}, on the other hand, is a particular instant in the past
770 or the future.  @pspp{} represents a date as a number of seconds since
771 midnight preceding 14 Oct 1582.  Because midnight preceding the dates
772 given below correspond with the numeric @pspp{} dates given:
773
774 @example
775               15 Oct 1582                86,400
776                4 Jul 1776         6,113,318,400
777                1 Jan 1900        10,010,390,400
778                1 Oct 1978        12,495,427,200
779               24 Aug 1995        13,028,601,600
780 @end example
781
782 @node Time Construction
783 @subsubsection Functions that Produce Times
784 @cindex times, constructing
785 @cindex constructing times
786
787 These functions take numeric arguments and return numeric values that
788 represent times.
789
790 @cindex days
791 @cindex time, in days
792 @deftypefn {Function} {} TIME.DAYS (@var{ndays})
793 Returns a time corresponding to @var{ndays} days.
794 @end deftypefn
795
796 @cindex hours-minutes-seconds
797 @cindex time, in hours-minutes-seconds
798 @deftypefn {Function} {} TIME.HMS (@var{nhours}, @var{nmins}, @var{nsecs})
799 Returns a time corresponding to @var{nhours} hours, @var{nmins}
800 minutes, and @var{nsecs} seconds.  The arguments may not have mixed
801 signs: if any of them are positive, then none may be negative, and
802 vice versa.  
803 @end deftypefn
804
805 @node Time Extraction
806 @subsubsection Functions that Examine Times
807 @cindex extraction, of time
808 @cindex time examination
809 @cindex examination, of times
810 @cindex time, lengths of
811
812 These functions take numeric arguments in @pspp{} time format and
813 give numeric results.
814
815 @cindex days
816 @cindex time, in days
817 @deftypefn {Function} {} CTIME.DAYS (@var{time})
818 Results in the number of days and fractional days in @var{time}.
819 @end deftypefn
820
821 @cindex hours
822 @cindex time, in hours
823 @deftypefn {Function} {} CTIME.HOURS (@var{time})
824 Results in the number of hours and fractional hours in @var{time}.
825 @end deftypefn
826
827 @cindex minutes
828 @cindex time, in minutes
829 @deftypefn {Function} {} CTIME.MINUTES (@var{time})
830 Results in the number of minutes and fractional minutes in @var{time}.
831 @end deftypefn
832
833 @cindex seconds
834 @cindex time, in seconds
835 @deftypefn {Function} {} CTIME.SECONDS (@var{time})
836 Results in the number of seconds and fractional seconds in @var{time}.
837 (@code{CTIME.SECONDS} does nothing; @code{CTIME.SECONDS(@var{x})} is
838 equivalent to @code{@var{x}}.)
839 @end deftypefn
840
841 @node Date Construction
842 @subsubsection Functions that Produce Dates
843 @cindex dates, constructing
844 @cindex constructing dates
845
846 @cindex arguments, of date construction functions
847 These functions take numeric arguments and give numeric results that
848 represent dates.  Arguments taken by these functions are:
849
850 @table @var
851 @item day
852 Refers to a day of the month between 1 and 31.  Day 0 is also accepted
853 and refers to the final day of the previous month.  Days 29, 30, and
854 31 are accepted even in months that have fewer days and refer to a day
855 near the beginning of the following month.
856
857 @item month
858 Refers to a month of the year between 1 and 12.  Months 0 and 13 are
859 also accepted and refer to the last month of the preceding year and
860 the first month of the following year, respectively.
861
862 @item quarter
863 Refers to a quarter of the year between 1 and 4.  The quarters of the
864 year begin on the first day of months 1, 4, 7, and 10.
865
866 @item week
867 Refers to a week of the year between 1 and 53.
868
869 @item yday
870 Refers to a day of the year between 1 and 366.
871
872 @item year
873 Refers to a year, 1582 or greater.  Years between 0 and 99 are treated
874 according to the epoch set on SET EPOCH, by default beginning 69 years
875 before the current date (@pxref{SET EPOCH}).
876 @end table
877
878 @cindex arguments, invalid
879 If these functions' arguments are out-of-range, they are correctly
880 normalized before conversion to date format.  Non-integers are rounded
881 toward zero.
882
883 @cindex day-month-year
884 @cindex dates, day-month-year
885 @deftypefn {Function} {} DATE.DMY (@var{day}, @var{month}, @var{year})
886 @deftypefnx {Function} {} DATE.MDY (@var{month}, @var{day}, @var{year})
887 Results in a date value corresponding to the midnight before day
888 @var{day} of month @var{month} of year @var{year}.
889 @end deftypefn
890
891 @cindex month-year
892 @cindex dates, month-year
893 @deftypefn {Function} {} DATE.MOYR (@var{month}, @var{year})
894 Results in a date value corresponding to the midnight before the first
895 day of month @var{month} of year @var{year}.
896 @end deftypefn
897
898 @cindex quarter-year
899 @cindex dates, quarter-year
900 @deftypefn {Function} {} DATE.QYR (@var{quarter}, @var{year})
901 Results in a date value corresponding to the midnight before the first
902 day of quarter @var{quarter} of year @var{year}.
903 @end deftypefn
904
905 @cindex week-year
906 @cindex dates, week-year
907 @deftypefn {Function} {} DATE.WKYR (@var{week}, @var{year})
908 Results in a date value corresponding to the midnight before the first
909 day of week @var{week} of year @var{year}.
910 @end deftypefn
911
912 @cindex year-day
913 @cindex dates, year-day
914 @deftypefn {Function} {} DATE.YRDAY (@var{year}, @var{yday})
915 Results in a date value corresponding to the day
916 @var{yday} of year @var{year}.
917 @end deftypefn
918
919 @node Date Extraction
920 @subsubsection Functions that Examine Dates
921 @cindex extraction, of dates
922 @cindex date examination
923
924 @cindex arguments, of date extraction functions
925 These functions take numeric arguments in @pspp{} date or time
926 format and give numeric results.  These names are used for arguments:
927
928 @table @var
929 @item date
930 A numeric value in @pspp{} date format.
931
932 @item time
933 A numeric value in @pspp{} time format.
934
935 @item time-or-date
936 A numeric value in @pspp{} time or date format.
937 @end table
938
939 @cindex days
940 @cindex dates, in days
941 @cindex time, in days
942 @deftypefn {Function} {} XDATE.DATE (@var{time-or-date})
943 For a time, results in the time corresponding to the number of whole
944 days @var{date-or-time} includes.  For a date, results in the date
945 corresponding to the latest midnight at or before @var{date-or-time};
946 that is, gives the date that @var{date-or-time} is in.
947 @end deftypefn
948
949 @cindex hours
950 @cindex dates, in hours
951 @cindex time, in hours
952 @deftypefn {Function} {} XDATE.HOUR (@var{time-or-date})
953 For a time, results in the number of whole hours beyond the number of
954 whole days represented by @var{date-or-time}.  For a date, results in
955 the hour (as an integer between 0 and 23) corresponding to
956 @var{date-or-time}.  
957 @end deftypefn
958
959 @cindex day of the year
960 @cindex dates, day of the year
961 @deftypefn {Function} {} XDATE.JDAY (@var{date})
962 Results in the day of the year (as an integer between 1 and 366)
963 corresponding to @var{date}.
964 @end deftypefn
965
966 @cindex day of the month
967 @cindex dates, day of the month
968 @deftypefn {Function} {} XDATE.MDAY (@var{date})
969 Results in the day of the month (as an integer between 1 and 31)
970 corresponding to @var{date}.
971 @end deftypefn
972
973 @cindex minutes
974 @cindex dates, in minutes
975 @cindex time, in minutes
976 @deftypefn {Function} {} XDATE.MINUTE (@var{time-or-date})
977 Results in the number of minutes (as an integer between 0 and 59) after
978 the last hour in @var{time-or-date}. 
979 @end deftypefn
980
981 @cindex months
982 @cindex dates, in months
983 @deftypefn {Function} {} XDATE.MONTH (@var{date})
984 Results in the month of the year (as an integer between 1 and 12)
985 corresponding to @var{date}.
986 @end deftypefn
987
988 @cindex quarters
989 @cindex dates, in quarters
990 @deftypefn {Function} {} XDATE.QUARTER (@var{date})
991 Results in the quarter of the year (as an integer between 1 and 4)
992 corresponding to @var{date}.
993 @end deftypefn
994
995 @cindex seconds
996 @cindex dates, in seconds
997 @cindex time, in seconds
998 @deftypefn {Function} {} XDATE.SECOND (@var{time-or-date})
999 Results in the number of whole seconds after the last whole minute (as
1000 an integer between 0 and 59) in @var{time-or-date}.
1001 @end deftypefn
1002
1003 @cindex days
1004 @cindex times, in days
1005 @deftypefn {Function} {} XDATE.TDAY (@var{date})
1006 Results in the number of whole days from 14 Oct 1582 to @var{date}.
1007 @end deftypefn
1008
1009 @cindex time
1010 @cindex dates, time of day
1011 @deftypefn {Function} {} XDATE.TIME (@var{date})
1012 Results in the time of day at the instant corresponding to @var{date},
1013 as a time value.  This is the number of seconds since
1014 midnight on the day corresponding to @var{date}.
1015 @end deftypefn
1016
1017 @cindex week
1018 @cindex dates, in weeks
1019 @deftypefn {Function} {} XDATE.WEEK (@var{date})
1020 Results in the week of the year (as an integer between 1 and 53)
1021 corresponding to @var{date}.
1022 @end deftypefn
1023
1024 @cindex day of the week
1025 @cindex weekday
1026 @cindex dates, day of the week
1027 @cindex dates, in weekdays
1028 @deftypefn {Function} {} XDATE.WKDAY (@var{date})
1029 Results in the day of week (as an integer between 1 and 7) corresponding
1030 to @var{date}, where 1 represents Sunday.
1031 @end deftypefn
1032
1033 @cindex years
1034 @cindex dates, in years
1035 @deftypefn {Function} {} XDATE.YEAR (@var{date})
1036 Returns the year (as an integer 1582 or greater) corresponding to
1037 @var{date}.
1038 @end deftypefn
1039
1040 @node Time and Date Arithmetic
1041 @subsubsection Time and Date Arithmetic
1042
1043 @cindex time, mathematical properties of
1044 @cindex mathematics, applied to times & dates
1045 @cindex dates, mathematical properties of
1046 @noindent
1047 Ordinary arithmetic operations on dates and times often produce
1048 sensible results.  Adding a time to, or subtracting one from, a date
1049 produces a new date that much earlier or later.  The difference of two
1050 dates yields the time between those dates.  Adding two times produces
1051 the combined time.  Multiplying a time by a scalar produces a time
1052 that many times longer.  Since times and dates are just numbers, the
1053 ordinary addition and subtraction operators are employed for these
1054 purposes.
1055
1056 Adding two dates does not produce a useful result.
1057
1058 Dates and times may have very large values.  Thus,
1059 it is not a good idea to take powers of these values; also, the
1060 accuracy of some procedures may be affected.  If necessary, convert
1061 times or dates in seconds to some other unit, like days or years,
1062 before performing analysis.
1063
1064 @pspp{} supplies a few functions for date arithmetic:
1065
1066 @deftypefn {Function} {} DATEDIFF (@var{date2}, @var{date1}, @var{unit})
1067 Returns the span of time from @var{date1} to @var{date2} in terms of
1068 @var{unit}, which must be a quoted string, one of @samp{years},
1069 @samp{quarters}, @samp{months}, @samp{weeks}, @samp{days},
1070 @samp{hours}, @samp{minutes}, and @samp{seconds}.  The result is an
1071 integer, truncated toward zero.
1072
1073 One year is considered to span from a given date to the same month,
1074 day, and time of day the next year.  Thus, from Jan.@tie{}1 of one
1075 year to Jan.@tie{}1 the next year is considered to be a full year, but
1076 Feb.@tie{}29 of a leap year to the following Feb.@tie{}28 is not.
1077 Similarly, one month spans from a given day of the month to the same
1078 day of the following month.  Thus, there is never a full month from
1079 Jan.@tie{}31 of a given year to any day in the following February.
1080 @end deftypefn
1081
1082 @deftypefn {Function} {} DATESUM (@var{date}, @var{quantity}, @var{unit}[, @var{method}])
1083 Returns @var{date} advanced by the given @var{quantity} of the
1084 specified @var{unit}, which must be one of the strings @samp{years},
1085 @samp{quarters}, @samp{months}, @samp{weeks}, @samp{days},
1086 @samp{hours}, @samp{minutes}, and @samp{seconds}.
1087
1088 When @var{unit} is @samp{years}, @samp{quarters}, or @samp{months},
1089 only the integer part of @var{quantity} is considered.  Adding one of
1090 these units can cause the day of the month to exceed the number of
1091 days in the month.  In this case, the @var{method} comes into
1092 play: if it is omitted or specified as @samp{closest} (as a quoted
1093 string), then the resulting day is the last day of the month;
1094 otherwise, if it is specified as @samp{rollover}, then the extra days
1095 roll over into the following month.
1096
1097 When @var{unit} is @samp{weeks}, @samp{days}, @samp{hours},
1098 @samp{minutes}, or @samp{seconds}, the @var{quantity} is not rounded
1099 to an integer and @var{method}, if specified, is ignored.
1100 @end deftypefn
1101
1102 @node Miscellaneous Functions
1103 @subsection Miscellaneous Functions
1104 @cindex functions, miscellaneous
1105
1106 @cindex cross-case function
1107 @cindex function, cross-case
1108 @deftypefn {Function} {} LAG (@var{variable}[, @var{n}])
1109 @anchor{LAG}
1110
1111 @var{variable} must be a numeric or string variable name.  @code{LAG}
1112 yields the value of that variable for the case @var{n} before the
1113 current one.  Results in system-missing (for numeric variables) or
1114 blanks (for string variables) for the first @var{n} cases.
1115
1116 @code{LAG} obtains values from the cases that become the new active
1117 dataset
1118 after a procedure executes.  Thus, @code{LAG} will not return values
1119 from cases dropped by transformations such as @cmd{SELECT IF}, and
1120 transformations like @cmd{COMPUTE} that modify data will change the
1121 values returned by @code{LAG}.  These are both the case whether these
1122 transformations precede or follow the use of @code{LAG}.
1123
1124 If @code{LAG} is used before @cmd{TEMPORARY}, then the values it returns
1125 are those in cases just before @cmd{TEMPORARY}.  @code{LAG} may not be
1126 used after @cmd{TEMPORARY}.
1127
1128 If omitted, @var{ncases} defaults to 1.  Otherwise, @var{ncases} must
1129 be a small positive constant integer.  There is no explicit limit, but
1130 use of a large value will increase memory consumption.
1131 @end deftypefn
1132
1133 @cindex date, Julian
1134 @cindex Julian date
1135 @deftypefn {Function} {} YRMODA (@var{year}, @var{month}, @var{day})
1136 @var{year} is a year, either between 0 and 99 or at least 1582.
1137 Unlike other @pspp{} date functions, years between 0 and 99 always
1138 correspond to 1900 through 1999.  @var{month} is a month between 1 and
1139 13.  @var{day} is a day between 0 and 31.  A @var{day} of 0 refers to
1140 the last day of the previous month, and a @var{month} of 13 refers to
1141 the first month of the next year.  @var{year} must be in range.
1142 @var{year}, @var{month}, and @var{day} must all be integers.
1143
1144 @code{YRMODA} results in the number of days between 15 Oct 1582 and
1145 the date specified, plus one.  The date passed to @code{YRMODA} must be
1146 on or after 15 Oct 1582.  15 Oct 1582 has a value of 1.
1147 @end deftypefn
1148
1149 @cindex value label
1150 @deftypefn {Function} VALUELABEL (@var{variable})
1151 Returns a string matching the label associated with the current value
1152 of @var{variable}.  If the current value of @var{variable} has no
1153 associated label, then this function returns the empty string.
1154 @var{variable} may be a numeric or string variable.
1155 @end deftypefn
1156
1157 @node Statistical Distribution Functions
1158 @subsection Statistical Distribution Functions
1159
1160 @pspp{} can calculate several functions of standard statistical
1161 distributions.  These functions are named systematically based on the
1162 function and the distribution.  The table below describes the
1163 statistical distribution functions in general:
1164
1165 @table @asis
1166 @item PDF.@var{dist} (@var{x}[, @var{param}@dots{}])
1167 Probability density function for @var{dist}.  The domain of @var{x}
1168 depends on @var{dist}.  For continuous distributions, the result is
1169 the density of the probability function at @var{x}, and the range is
1170 nonnegative real numbers.  For discrete distributions, the result is
1171 the probability of @var{x}.
1172
1173 @item CDF.@var{dist} (@var{x}[, @var{param}@dots{}])
1174 Cumulative distribution function for @var{dist}, that is, the
1175 probability that a random variate drawn from the distribution is less
1176 than @var{x}.  The domain of @var{x} depends @var{dist}.  The result is
1177 a probability.
1178
1179 @item SIG.@var{dist} (@var{x}[, @var{param}@dots{})
1180 Tail probability function for @var{dist}, that is, the probability
1181 that a random variate drawn from the distribution is greater than
1182 @var{x}.  The domain of @var{x} depends @var{dist}.  The result is a
1183 probability.  Only a few distributions include an @func{SIG} function.
1184
1185 @item IDF.@var{dist} (@var{p}[, @var{param}@dots{}])
1186 Inverse distribution function for @var{dist}, the value of @var{x} for
1187 which the CDF would yield @var{p}.  The value of @var{p} is a
1188 probability.  The range depends on @var{dist} and is identical to the
1189 domain for the corresponding CDF.
1190
1191 @item RV.@var{dist} ([@var{param}@dots{}])
1192 Random variate function for @var{dist}.  The range depends on the
1193 distribution.
1194
1195 @item NPDF.@var{dist} (@var{x}[, @var{param}@dots{}])
1196 Noncentral probability density function.  The result is the density of
1197 the given noncentral distribution at @var{x}.  The domain of @var{x}
1198 depends on @var{dist}.  The range is nonnegative real numbers.  Only a
1199 few distributions include an @func{NPDF} function.
1200
1201 @item NCDF.@var{dist} (@var{x}[, @var{param}@dots{}])
1202 Noncentral cumulative distribution function for @var{dist}, that is,
1203 the probability that a random variate drawn from the given noncentral
1204 distribution is less than @var{x}.  The domain of @var{x} depends
1205 @var{dist}.  The result is a probability.  Only a few distributions
1206 include an NCDF function.
1207 @end table
1208
1209 The individual distributions are described individually below.
1210
1211 @menu
1212 * Continuous Distributions::    
1213 * Discrete Distributions::      
1214 @end menu
1215
1216 @node Continuous Distributions
1217 @subsubsection Continuous Distributions
1218
1219 The following continuous distributions are available:
1220
1221 @deftypefn {Function} {} PDF.BETA (@var{x})
1222 @deftypefnx {Function} {} CDF.BETA (@var{x}, @var{a}, @var{b})
1223 @deftypefnx {Function} {} IDF.BETA (@var{p}, @var{a}, @var{b})
1224 @deftypefnx {Function} {} RV.BETA (@var{a}, @var{b})
1225 @deftypefnx {Function} {} NPDF.BETA (@var{x}, @var{a}, @var{b}, @var{lambda})
1226 @deftypefnx {Function} {} NCDF.BETA (@var{x}, @var{a}, @var{b}, @var{lambda})
1227 Beta distribution with shape parameters @var{a} and @var{b}.  The
1228 noncentral distribution takes an additional parameter @var{lambda}.
1229 Constraints: @var{a} > 0, @var{b} > 0, @var{lambda} >= 0, 0 <= @var{x}
1230 <= 1, 0 <= @var{p} <= 1.
1231 @end deftypefn
1232
1233 @deftypefn {Function} {} PDF.BVNOR (@var{x0}, @var{x1}, @var{rho})
1234 @deftypefnx {Function} {} CDF.VBNOR (@var{x0}, @var{x1}, @var{rho})
1235 Bivariate normal distribution of two standard normal variables with
1236 correlation coefficient @var{rho}.  Two variates @var{x0} and @var{x1}
1237 must be provided.  Constraints: 0 <= @var{rho} <= 1, 0 <= @var{p} <= 1.
1238 @end deftypefn
1239
1240 @deftypefn {Function} {} PDF.CAUCHY (@var{x}, @var{a}, @var{b})
1241 @deftypefnx {Function} {} CDF.CAUCHY (@var{x}, @var{a}, @var{b})
1242 @deftypefnx {Function} {} IDF.CAUCHY (@var{p}, @var{a}, @var{b})
1243 @deftypefnx {Function} {} RV.CAUCHY (@var{a}, @var{b})
1244 Cauchy distribution with location parameter @var{a} and scale
1245 parameter @var{b}.  Constraints: @var{b} > 0, 0 < @var{p} < 1.
1246 @end deftypefn
1247
1248 @c @deftypefn {Function} {} PDF.CHISQ (@var{x}, @var{df})
1249 @deftypefn {Function} {} CDF.CHISQ (@var{x}, @var{df})
1250 @deftypefnx {Function} {} SIG.CHISQ (@var{x}, @var{df})
1251 @deftypefnx {Function} {} IDF.CHISQ (@var{p}, @var{df})
1252 @deftypefnx {Function} {} RV.CHISQ (@var{df})
1253 @c @deftypefnx {Function} {} NPDF.CHISQ (@var{x}, @var{df}, @var{lambda})
1254 @deftypefnx {Function} {} NCDF.CHISQ (@var{x}, @var{df}, @var{lambda})
1255 Chi-squared distribution with @var{df} degrees of freedom.  The
1256 noncentral distribution takes an additional parameter @var{lambda}.
1257 Constraints: @var{df} > 0, @var{lambda} > 0, @var{x} >= 0, 0 <=
1258 @var{p} < 1.
1259 @end deftypefn
1260
1261 @deftypefn {Function} {} PDF.EXP (@var{x}, @var{a})
1262 @deftypefnx {Function} {} CDF.EXP (@var{x}, @var{a})
1263 @deftypefnx {Function} {} IDF.EXP (@var{p}, @var{a})
1264 @deftypefnx {Function} {} RV.EXP (@var{a})
1265 Exponential distribution with scale parameter @var{a}.  The inverse of
1266 @var{a} represents the rate of decay.  Constraints: @var{a} > 0,
1267 @var{x} >= 0, 0 <= @var{p} < 1.
1268 @end deftypefn
1269
1270 @deftypefn {Function} {} PDF.XPOWER (@var{x}, @var{a}, @var{b})
1271 @deftypefnx {Function} {} RV.XPOWER (@var{a}, @var{b})
1272 Exponential power distribution with positive scale parameter @var{a}
1273 and nonnegative power parameter @var{b}.  Constraints: @var{a} > 0,
1274 @var{b} >= 0, @var{x} >= 0, 0 <= @var{p} <= 1.  This distribution is a
1275 @pspp{} extension.
1276 @end deftypefn
1277
1278 @deftypefn {Function} {} PDF.F (@var{x}, @var{df1}, @var{df2})
1279 @deftypefnx {Function} {} CDF.F (@var{x}, @var{df1}, @var{df2})
1280 @deftypefnx {Function} {} SIG.F (@var{x}, @var{df1}, @var{df2})
1281 @deftypefnx {Function} {} IDF.F (@var{p}, @var{df1}, @var{df2})
1282 @deftypefnx {Function} {} RV.F (@var{df1}, @var{df2})
1283 @c @deftypefnx {Function} {} NPDF.F (@var{x}, @var{df1}, @var{df2}, @var{lambda})
1284 @c @deftypefnx {Function} {} NCDF.F (@var{x}, @var{df1}, @var{df2}, @var{lambda})
1285 F-distribution of two chi-squared deviates with @var{df1} and
1286 @var{df2} degrees of freedom.  The noncentral distribution takes an
1287 additional parameter @var{lambda}.  Constraints: @var{df1} > 0,
1288 @var{df2} > 0, @var{lambda} >= 0, @var{x} >= 0, 0 <= @var{p} < 1.
1289 @end deftypefn
1290
1291 @deftypefn {Function} {} PDF.GAMMA (@var{x}, @var{a}, @var{b})
1292 @deftypefnx {Function} {} CDF.GAMMA (@var{x}, @var{a}, @var{b})
1293 @deftypefnx {Function} {} IDF.GAMMA (@var{p}, @var{a}, @var{b})
1294 @deftypefnx {Function} {} RV.GAMMA (@var{a}, @var{b})
1295 Gamma distribution with shape parameter @var{a} and scale parameter
1296 @var{b}.  Constraints: @var{a} > 0, @var{b} > 0, @var{x} >= 0, 0 <=
1297 @var{p} < 1.
1298 @end deftypefn
1299
1300 @c @deftypefn {Function} {} PDF.HALFNRM (@var{x}, @var{a}, @var{b})
1301 @c @deftypefnx {Function} {} CDF.HALFNRM (@var{x}, @var{a}, @var{b})
1302 @c @deftypefnx {Function} {} IDF.HALFNRM (@var{p}, @var{a}, @var{b})
1303 @c @deftypefnx {Function} {} RV.HALFNRM (@var{a}, @var{b})
1304 @c Half-normal distribution with location parameter @var{a} and shape
1305 @c parameter @var{b}.  Constraints: @var{b} > 0, 0 < @var{p} < 1.
1306 @c @end deftypefn
1307
1308 @c @deftypefn {Function} {} PDF.IGAUSS (@var{x}, @var{a}, @var{b})
1309 @c @deftypefnx {Function} {} CDF.IGAUSS (@var{x}, @var{a}, @var{b})
1310 @c @deftypefnx {Function} {} IDF.IGAUSS (@var{p}, @var{a}, @var{b})
1311 @c @deftypefnx {Function} {} RV.IGAUSS (@var{a}, @var{b})
1312 @c Inverse Gaussian distribution with parameters @var{a} and @var{b}.
1313 @c Constraints: @var{a} > 0, @var{b} > 0, @var{x} > 0, 0 <= @var{p} < 1.
1314 @c @end deftypefn
1315
1316 @deftypefn {Function} {} PDF.LANDAU (@var{x})
1317 @deftypefnx {Function} {} RV.LANDAU ()
1318 Landau distribution.
1319 @end deftypefn
1320
1321 @deftypefn {Function} {} PDF.LAPLACE (@var{x}, @var{a}, @var{b})
1322 @deftypefnx {Function} {} CDF.LAPLACE (@var{x}, @var{a}, @var{b})
1323 @deftypefnx {Function} {} IDF.LAPLACE (@var{p}, @var{a}, @var{b})
1324 @deftypefnx {Function} {} RV.LAPLACE (@var{a}, @var{b})
1325 Laplace distribution with location parameter @var{a} and scale
1326 parameter @var{b}.  Constraints: @var{b} > 0, 0 < @var{p} < 1.
1327 @end deftypefn
1328
1329 @deftypefn {Function} {} RV.LEVY (@var{c}, @var{alpha})
1330 Levy symmetric alpha-stable distribution with scale @var{c} and
1331 exponent @var{alpha}.  Constraints: 0 < @var{alpha} <= 2.
1332 @end deftypefn
1333
1334 @deftypefn {Function} {} RV.LVSKEW (@var{c}, @var{alpha}, @var{beta})
1335 Levy skew alpha-stable distribution with scale @var{c}, exponent
1336 @var{alpha}, and skewness parameter @var{beta}.  Constraints: 0 <
1337 @var{alpha} <= 2, -1 <= @var{beta} <= 1.
1338 @end deftypefn
1339
1340 @deftypefn {Function} {} PDF.LOGISTIC (@var{x}, @var{a}, @var{b})
1341 @deftypefnx {Function} {} CDF.LOGISTIC (@var{x}, @var{a}, @var{b})
1342 @deftypefnx {Function} {} IDF.LOGISTIC (@var{p}, @var{a}, @var{b})
1343 @deftypefnx {Function} {} RV.LOGISTIC (@var{a}, @var{b})
1344 Logistic distribution with location parameter @var{a} and scale
1345 parameter @var{b}.  Constraints: @var{b} > 0, 0 < @var{p} < 1.
1346 @end deftypefn
1347
1348 @deftypefn {Function} {} PDF.LNORMAL (@var{x}, @var{a}, @var{b})
1349 @deftypefnx {Function} {} CDF.LNORMAL (@var{x}, @var{a}, @var{b})
1350 @deftypefnx {Function} {} IDF.LNORMAL (@var{p}, @var{a}, @var{b})
1351 @deftypefnx {Function} {} RV.LNORMAL (@var{a}, @var{b})
1352 Lognormal distribution with parameters @var{a} and @var{b}.
1353 Constraints: @var{a} > 0, @var{b} > 0, @var{x} >= 0, 0 <= @var{p} < 1.
1354 @end deftypefn
1355
1356 @deftypefn {Function} {} PDF.NORMAL (@var{x}, @var{mu}, @var{sigma})
1357 @deftypefnx {Function} {} CDF.NORMAL (@var{x}, @var{mu}, @var{sigma})
1358 @deftypefnx {Function} {} IDF.NORMAL (@var{p}, @var{mu}, @var{sigma})
1359 @deftypefnx {Function} {} RV.NORMAL (@var{mu}, @var{sigma})
1360 Normal distribution with mean @var{mu} and standard deviation
1361 @var{sigma}.  Constraints: @var{b} > 0, 0 < @var{p} < 1.  Three
1362 additional functions are available as shorthand:
1363
1364 @deftypefn {Function} {} CDFNORM (@var{x})
1365 Equivalent to CDF.NORMAL(@var{x}, 0, 1).
1366 @end deftypefn
1367
1368 @deftypefn {Function} {} PROBIT (@var{p})
1369 Equivalent to IDF.NORMAL(@var{p}, 0, 1).
1370 @end deftypefn
1371
1372 @deftypefn {Function} {} NORMAL (@var{sigma})
1373 Equivalent to RV.NORMAL(0, @var{sigma}).
1374 @end deftypefn
1375 @end deftypefn
1376
1377 @deftypefn {Function} {} PDF.NTAIL (@var{x}, @var{a}, @var{sigma})
1378 @deftypefnx {Function} {} RV.NTAIL (@var{a}, @var{sigma})
1379 Normal tail distribution with lower limit @var{a} and standard
1380 deviation @var{sigma}.  This distribution is a @pspp{} extension.
1381 Constraints: @var{a} > 0, @var{x} > @var{a}, 0 < @var{p} < 1.
1382 @end deftypefn
1383
1384 @deftypefn {Function} {} PDF.PARETO (@var{x}, @var{a}, @var{b})
1385 @deftypefnx {Function} {} CDF.PARETO (@var{x}, @var{a}, @var{b})
1386 @deftypefnx {Function} {} IDF.PARETO (@var{p}, @var{a}, @var{b})
1387 @deftypefnx {Function} {} RV.PARETO (@var{a}, @var{b})
1388 Pareto distribution with threshold parameter @var{a} and shape
1389 parameter @var{b}.  Constraints: @var{a} > 0, @var{b} > 0, @var{x} >=
1390 @var{a}, 0 <= @var{p} < 1.
1391 @end deftypefn
1392
1393 @deftypefn {Function} {} PDF.RAYLEIGH (@var{x}, @var{sigma})
1394 @deftypefnx {Function} {} CDF.RAYLEIGH (@var{x}, @var{sigma})
1395 @deftypefnx {Function} {} IDF.RAYLEIGH (@var{p}, @var{sigma})
1396 @deftypefnx {Function} {} RV.RAYLEIGH (@var{sigma})
1397 Rayleigh distribution with scale parameter @var{sigma}.  This
1398 distribution is a @pspp{} extension.  Constraints: @var{sigma} > 0,
1399 @var{x} > 0.
1400 @end deftypefn
1401
1402 @deftypefn {Function} {} PDF.RTAIL (@var{x}, @var{a}, @var{sigma})
1403 @deftypefnx {Function} {} RV.RTAIL (@var{a}, @var{sigma})
1404 Rayleigh tail distribution with lower limit @var{a} and scale
1405 parameter @var{sigma}.  This distribution is a @pspp{} extension.
1406 Constraints: @var{a} > 0, @var{sigma} > 0, @var{x} > @var{a}.
1407 @end deftypefn
1408
1409 @c @deftypefn {Function} {} CDF.SMOD (@var{x}, @var{a}, @var{b})
1410 @c @deftypefnx {Function} {} IDF.SMOD (@var{p}, @var{a}, @var{b})
1411 @c Studentized maximum modulus distribution with parameters @var{a} and
1412 @c @var{b}.  Constraints: @var{a} > 0, @var{b} > 0, @var{x} > 0, 0 <=
1413 @c @var{p} < 1.
1414 @c @end deftypefn
1415
1416 @c @deftypefn {Function} {} CDF.SRANGE (@var{x}, @var{a}, @var{b})
1417 @c @deftypefnx {Function} {} IDF.SRANGE (@var{p}, @var{a}, @var{b})
1418 @c Studentized range distribution with parameters @var{a} and @var{b}.
1419 @c Constraints:  @var{a} >= 1, @var{b} >= 1, @var{x} > 0, 0 <= @var{p} <
1420 @c 1.
1421 @c @end deftypefn
1422
1423 @deftypefn {Function} {} PDF.T (@var{x}, @var{df})
1424 @deftypefnx {Function} {} CDF.T (@var{x}, @var{df})
1425 @deftypefnx {Function} {} IDF.T (@var{p}, @var{df})
1426 @deftypefnx {Function} {} RV.T (@var{df})
1427 @c @deftypefnx {Function} {} NPDF.T (@var{x}, @var{df}, @var{lambda})
1428 @c @deftypefnx {Function} {} NCDF.T (@var{x}, @var{df}, @var{lambda})
1429 T-distribution with @var{df} degrees of freedom.  The noncentral
1430 distribution takes an additional parameter @var{lambda}.  Constraints:
1431 @var{df} > 0, 0 < @var{p} < 1.
1432 @end deftypefn
1433
1434 @deftypefn {Function} {} PDF.T1G (@var{x}, @var{a}, @var{b})
1435 @deftypefnx {Function} {} CDF.T1G (@var{x}, @var{a}, @var{b})
1436 @deftypefnx {Function} {} IDF.T1G (@var{p}, @var{a}, @var{b})
1437 Type-1 Gumbel distribution with parameters @var{a} and @var{b}.  This
1438 distribution is a @pspp{} extension.  Constraints: 0 < @var{p} < 1.
1439 @end deftypefn
1440
1441 @deftypefn {Function} {} PDF.T2G (@var{x}, @var{a}, @var{b})
1442 @deftypefnx {Function} {} CDF.T2G (@var{x}, @var{a}, @var{b})
1443 @deftypefnx {Function} {} IDF.T2G (@var{p}, @var{a}, @var{b})
1444 Type-2 Gumbel distribution with parameters @var{a} and @var{b}.  This
1445 distribution is a @pspp{} extension.  Constraints: @var{x} > 0, 0 <
1446 @var{p} < 1.
1447 @end deftypefn
1448
1449 @deftypefn {Function} {} PDF.UNIFORM (@var{x}, @var{a}, @var{b})
1450 @deftypefnx {Function} {} CDF.UNIFORM (@var{x}, @var{a}, @var{b})
1451 @deftypefnx {Function} {} IDF.UNIFORM (@var{p}, @var{a}, @var{b})
1452 @deftypefnx {Function} {} RV.UNIFORM (@var{a}, @var{b})
1453 Uniform distribution with parameters @var{a} and @var{b}.
1454 Constraints: @var{a} <= @var{x} <= @var{b}, 0 <= @var{p} <= 1.  An
1455 additional function is available as shorthand:
1456
1457 @deftypefn {Function} {} UNIFORM (@var{b})
1458 Equivalent to RV.UNIFORM(0, @var{b}).
1459 @end deftypefn
1460 @end deftypefn
1461
1462 @deftypefn {Function} {} PDF.WEIBULL (@var{x}, @var{a}, @var{b})
1463 @deftypefnx {Function} {} CDF.WEIBULL (@var{x}, @var{a}, @var{b})
1464 @deftypefnx {Function} {} IDF.WEIBULL (@var{p}, @var{a}, @var{b})
1465 @deftypefnx {Function} {} RV.WEIBULL (@var{a}, @var{b})
1466 Weibull distribution with parameters @var{a} and @var{b}.
1467 Constraints: @var{a} > 0, @var{b} > 0, @var{x} >= 0, 0 <= @var{p} < 1.
1468 @end deftypefn
1469
1470 @node Discrete Distributions
1471 @subsubsection Discrete Distributions
1472
1473 The following discrete distributions are available:
1474
1475 @deftypefn {Function} {} PDF.BERNOULLI (@var{x})
1476 @deftypefnx {Function} {} CDF.BERNOULLI (@var{x}, @var{p})
1477 @deftypefnx {Function} {} RV.BERNOULLI (@var{p})
1478 Bernoulli distribution with probability of success @var{p}.
1479 Constraints: @var{x} = 0 or 1, 0 <= @var{p} <= 1.
1480 @end deftypefn
1481
1482 @deftypefn {Function} {} PDF.BINOM (@var{x}, @var{n}, @var{p})
1483 @deftypefnx {Function} {} CDF.BINOM (@var{x}, @var{n}, @var{p})
1484 @deftypefnx {Function} {} RV.BINOM (@var{n}, @var{p})
1485 Binomial distribution with @var{n} trials and probability of success
1486 @var{p}.  Constraints: integer @var{n} > 0, 0 <= @var{p} <= 1, integer
1487 @var{x} <= @var{n}.
1488 @end deftypefn
1489
1490 @deftypefn {Function} {} PDF.GEOM (@var{x}, @var{n}, @var{p})
1491 @deftypefnx {Function} {} CDF.GEOM (@var{x}, @var{n}, @var{p})
1492 @deftypefnx {Function} {} RV.GEOM (@var{n}, @var{p})
1493 Geometric distribution with probability of success @var{p}.
1494 Constraints: 0 <= @var{p} <= 1, integer @var{x} > 0.
1495 @end deftypefn
1496
1497 @deftypefn {Function} {} PDF.HYPER (@var{x}, @var{a}, @var{b}, @var{c})
1498 @deftypefnx {Function} {} CDF.HYPER (@var{x}, @var{a}, @var{b}, @var{c})
1499 @deftypefnx {Function} {} RV.HYPER (@var{a}, @var{b}, @var{c})
1500 Hypergeometric distribution when @var{b} objects out of @var{a} are
1501 drawn and @var{c} of the available objects are distinctive.
1502 Constraints: integer @var{a} > 0, integer @var{b} <= @var{a}, integer
1503 @var{c} <= @var{a}, integer @var{x} >= 0.
1504 @end deftypefn
1505
1506 @deftypefn {Function} {} PDF.LOG (@var{x}, @var{p})
1507 @deftypefnx {Function} {} RV.LOG (@var{p})
1508 Logarithmic distribution with probability parameter @var{p}.
1509 Constraints: 0 <= @var{p} < 1, @var{x} >= 1.
1510 @end deftypefn
1511
1512 @deftypefn {Function} {} PDF.NEGBIN (@var{x}, @var{n}, @var{p})
1513 @deftypefnx {Function} {} CDF.NEGBIN (@var{x}, @var{n}, @var{p})
1514 @deftypefnx {Function} {} RV.NEGBIN (@var{n}, @var{p})
1515 Negative binomial distribution with number of successes parameter
1516 @var{n} and probability of success parameter @var{p}.  Constraints:
1517 integer @var{n} >= 0, 0 < @var{p} <= 1, integer @var{x} >= 1.
1518 @end deftypefn
1519
1520 @deftypefn {Function} {} PDF.POISSON (@var{x}, @var{mu})
1521 @deftypefnx {Function} {} CDF.POISSON (@var{x}, @var{mu})
1522 @deftypefnx {Function} {} RV.POISSON (@var{mu})
1523 Poisson distribution with mean @var{mu}.  Constraints: @var{mu} > 0,
1524 integer @var{x} >= 0.
1525 @end deftypefn
1526
1527 @node Order of Operations
1528 @section Operator Precedence
1529 @cindex operator precedence
1530 @cindex precedence, operator
1531 @cindex order of operations
1532 @cindex operations, order of
1533
1534 The following table describes operator precedence.  Smaller-numbered
1535 levels in the table have higher precedence.  Within a level,
1536 operations are always performed from left to right.  The first
1537 occurrence of @samp{-} represents unary negation, the second binary
1538 subtraction.
1539
1540 @enumerate
1541 @item
1542 @code{(  )}
1543 @item
1544 @code{**}
1545 @item
1546 @code{-}
1547 @item
1548 @code{*  /}
1549 @item
1550 @code{+  -}
1551 @item
1552 @code{EQ  GE  GT  LE  LT  NE}
1553 @item
1554 @code{AND  NOT  OR}
1555 @end enumerate