Function
✖
Function
Details

- 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 onward. »
- When applied to an association, #name is equivalent to #["name"], and picks out elements in the association.
- In the form #name, the characters in name can be any combination of alphanumeric characters not beginning with digits.
- The character is entered as
|->
,
fn
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. »
- In Function[params, body, attrs], attrs can be a single attribute or a list of attributes. »
- Function[Null,body,attrs] represents a function in which the parameters in body are given using # etc.
Examples
open allclose allBasic Examples (4)Summary of the most common use cases
Pure function with one parameter:

https://wolfram.com/xid/0giru6-qjx


https://wolfram.com/xid/0giru6-1r2z5z


https://wolfram.com/xid/0giru6-w15

Pure function with two parameters:

https://wolfram.com/xid/0giru6-me0


https://wolfram.com/xid/0giru6-tfy


https://wolfram.com/xid/0giru6-jgl


https://wolfram.com/xid/0giru6-tf4

Pick out named arguments from an association:

https://wolfram.com/xid/0giru6-7a7mft

Scope (15)Survey of the scope of standard use cases
Use a Pure Function as an Argument (5)
Map a pure function over a list:

https://wolfram.com/xid/0giru6-gz5


https://wolfram.com/xid/0giru6-gp4

Use a pure function as a predicate:

https://wolfram.com/xid/0giru6-39ky4o

Create an array from a pure function:

https://wolfram.com/xid/0giru6-i2y

Sort by comparing the second part of each element:

https://wolfram.com/xid/0giru6-op6

Use a Pure Function as an Option Value (3)
Specify a custom comparison function in FixedPoint:

https://wolfram.com/xid/0giru6-q3avny

Specify a custom color function:

https://wolfram.com/xid/0giru6-ue070a

Provide a custom distance function:

https://wolfram.com/xid/0giru6-01mgpk

Return a Pure Function as a Result (4)
Derivative of a pure function:

https://wolfram.com/xid/0giru6-2dhmwi

Derivative of Tan:

https://wolfram.com/xid/0giru6-m60x96

Solutions of differential equations may be expressed as pure functions:

https://wolfram.com/xid/0giru6-35roy2

Difference equations may return pure functions:

https://wolfram.com/xid/0giru6-lkwyp

Function and Associations (3)
#name is effectively a short form of #["name"]:

https://wolfram.com/xid/0giru6-0p0fac


https://wolfram.com/xid/0giru6-vf026h

#name always refers to the association in the first argument:

https://wolfram.com/xid/0giru6-t3jukc

Extract from an association slot other than the first:

https://wolfram.com/xid/0giru6-n7ddh1

Generalizations & Extensions (4)Generalized and extended use cases

https://wolfram.com/xid/0giru6-o9g


https://wolfram.com/xid/0giru6-i2g

## n stands for arguments n and onward:

https://wolfram.com/xid/0giru6-kzo


https://wolfram.com/xid/0giru6-p9w

Create a pure function with attribute Listable:

https://wolfram.com/xid/0giru6-ex0


https://wolfram.com/xid/0giru6-ga9

#0 stands for the whole pure function:

https://wolfram.com/xid/0giru6-u0l

A recursive definition for factorial using #0:

https://wolfram.com/xid/0giru6-kc5


https://wolfram.com/xid/0giru6-xtk

Applications (3)Sample problems that can be solved with this function
Turn a function that takes several arguments into one that takes a list of arguments:

https://wolfram.com/xid/0giru6-x2chbs


https://wolfram.com/xid/0giru6-9acbtj

A function that returns a function that multiplies its argument by n:

https://wolfram.com/xid/0giru6-ugrutv

https://wolfram.com/xid/0giru6-wnpy54


https://wolfram.com/xid/0giru6-byyt9o

Preserve arguments in unevaluated form:

https://wolfram.com/xid/0giru6-qddppy

Properties & Relations (11)Properties of the function, and connections to other functions
#1 uses only the first argument supplied; the rest are ignored:

https://wolfram.com/xid/0giru6-gs6

Not using any arguments results in a constant pure function:

https://wolfram.com/xid/0giru6-yt8evc

Replacements can be done inside pure functions:

https://wolfram.com/xid/0giru6-uy9


https://wolfram.com/xid/0giru6-ifi

Formal parameters are renamed whenever there is a possibility of confusion:

https://wolfram.com/xid/0giru6-xv1


https://wolfram.com/xid/0giru6-cwe


https://wolfram.com/xid/0giru6-f08

The names of the parameters do not matter:

https://wolfram.com/xid/0giru6-85r7je


https://wolfram.com/xid/0giru6-7u67s7

However, reusing a name introduces a new scope:

https://wolfram.com/xid/0giru6-6tquu1

Nested functions take their arguments one at a time:

https://wolfram.com/xid/0giru6-ot0rjv


https://wolfram.com/xid/0giru6-rdr2xq

f[#]& is the same as simply f in the univariate case:

https://wolfram.com/xid/0giru6-8wmja8

In general, f[##]& is the same as f:

https://wolfram.com/xid/0giru6-zg08f

Turn a formula involving a variable into a pure function:

https://wolfram.com/xid/0giru6-zb8x32

https://wolfram.com/xid/0giru6-odp1sh

Use a formula in Table:

https://wolfram.com/xid/0giru6-1gwqyh

Use the corresponding pure function in an equivalent Array expression:

https://wolfram.com/xid/0giru6-q6fwcf

Special-purpose function constructs include InterpolatingFunction:

https://wolfram.com/xid/0giru6-o7mzko


https://wolfram.com/xid/0giru6-doonux


https://wolfram.com/xid/0giru6-ldg35v


https://wolfram.com/xid/0giru6-209v16


https://wolfram.com/xid/0giru6-3ofmzq


https://wolfram.com/xid/0giru6-5211ob


https://wolfram.com/xid/0giru6-ehmjqt


https://wolfram.com/xid/0giru6-eboqmm

Possible Issues (4)Common pitfalls and unexpected behavior
& binds more loosely than ->, so it usually needs parentheses in rules:

https://wolfram.com/xid/0giru6-wyh


https://wolfram.com/xid/0giru6-bnl

& binds more loosely than ?, so it usually needs parentheses in pattern tests:

https://wolfram.com/xid/0giru6-zimxdz

Function does not evaluate its body until the function is applied:

https://wolfram.com/xid/0giru6-n40


https://wolfram.com/xid/0giru6-c1v

Supplying fewer than the required number of arguments generates an error:

https://wolfram.com/xid/0giru6-h25jpv


Neat Examples (2)Surprising or curious use cases
Define the recursion operator of recursion theory [more info]:

https://wolfram.com/xid/0giru6-68coz4

Use it to define the factorial function:

https://wolfram.com/xid/0giru6-b6q45v

Newton's formula for finding a zero of a function:

https://wolfram.com/xid/0giru6-qcgb47

https://wolfram.com/xid/0giru6-f3qcdb

Wolfram Research (1988), Function, Wolfram Language function, https://reference.wolfram.com/language/ref/Function.html (updated 2020).
Text
Wolfram Research (1988), Function, Wolfram Language function, https://reference.wolfram.com/language/ref/Function.html (updated 2020).
Wolfram Research (1988), Function, Wolfram Language function, https://reference.wolfram.com/language/ref/Function.html (updated 2020).
CMS
Wolfram Language. 1988. "Function." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Function.html.
Wolfram Language. 1988. "Function." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Function.html.
APA
Wolfram Language. (1988). Function. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Function.html
Wolfram Language. (1988). Function. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Function.html
BibTeX
@misc{reference.wolfram_2025_function, author="Wolfram Research", title="{Function}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Function.html}", note=[Accessed: 30-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_function, organization={Wolfram Research}, title={Function}, year={2020}, url={https://reference.wolfram.com/language/ref/Function.html}, note=[Accessed: 30-March-2025
]}