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