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