THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
 Built-in Mathematica Symbol Tutorials »| See Also »| More About »

# Function (&)

 Function[body]or body& is a pure function. The formal parameters are # (or #1), #2, etc. Function[x, body]is a pure function with a single formal parameter x. Function[{x1, x2, ...}, body]is a pure function with a list of formal parameters.
• When Function[body] or body& is applied to a set of arguments, # (or #1) is replaced by the first argument, #2 by the second, and so on. #0 is replaced by the function itself.
• If there are more arguments supplied than #i in the function, the remaining arguments are ignored.  »
• ## stands for the sequence of all arguments supplied.  »
• ##n stands for arguments from number n on.  »
• Function[x, body] can be input as xbody, where the character is entered as Esc fn Esc or \[Function].
• Function is analogous to in LISP or formal logic.
• Function has attribute HoldAll. The function body is evaluated only after the formal parameters have been replaced by arguments.
• The named formal parameters xi in Function[{x1, ...}, body] are treated as local, and are renamed xi\$ when necessary to avoid confusion with actual arguments supplied to the function.  »
• Function constructs can be nested in any way. Each is treated as a scoping construct, with named inner variables being renamed if necessary.  »
• Function[params, body, {attr1, attr2, ...}] represents a pure function that is to be treated as having attributes attri for the purpose of evaluation.  »
Pure function with one parameter:
Pure function with two parameters:
Set to be a pure function:
Use the pure function:
Pure function with one parameter:
 Out[1]=
 Out[2]=
 Out[3]=

Pure function with two parameters:
 Out[1]=
 Out[2]=

Set to be a pure function:
 Out[1]=
Use the pure function:
 Out[2]=
 Scope   (12)
Map a pure function over a list:
Select with a pure function:
Use a pure function as a predicate:
Create an array from a pure function:
Sort by comparing the second part of each element:
Specify a custom comparison function in FixedPoint:
Specify a custom color function:
Provide a custom distance function:
Derivative of a pure function:
Derivative of Tan:
Solutions of differential equations may be expressed as pure functions:
Difference equations may return pure functions:
## stands for all arguments:
##n stands for argument n on:
Create a pure function with attribute Listable:
#0 stands for the whole pure function:
A recursive definition for factorial using #0:
 Applications   (3)
Turn a function that takes several arguments into one that takes a list of arguments:
A function that returns a function that multiplies its argument by n:
Preserve arguments in unevaluated form:
#1 uses only the first argument supplied; the rest are ignored:
Not using any arguments results in a constant pure function:
Replacements can be done inside pure functions:
Formal parameters are renamed whenever there is a possibility of confusion:
The names of the parameters do not matter:
However, reusing a name introduces a new scope:
Nested functions take their arguments one at a time:
f[#]& is the same as simply f in the univariate case:
In general f[##]& is the same as f:
Turn a formula involving a variable into a pure function:
Use a formula in Table:
Use the corresponding pure function in an equivalent Array expression:
Special-purpose function constructs include InterpolatingFunction:
& binds more loosely than ->, so it usually needs parentheses in rules:
& binds more loosely than ?, so it usually needs parentheses in pattern tests:
Function does not evaluate its body until the function is applied:
Supplying fewer than the required number of arguments generates an error:
Define the recursion operator of recursion theory [more info]:
Use it to define the factorial function:
Newton's formula for finding a zero of a function:
New in 1 | Last modified in 7
 Site Index Choose Language