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