# Function application

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Function_application
> Markdown URL: https://mediated.wiki/source/Function_application.md
> Source: https://en.wikipedia.org/wiki/Function_application
> Source revision: 1357119651
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Evaluation of a function on its argument

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Function application" – news · newspapers · books · scholar · JSTOR (February 2024) (Learn how and when to remove this message)

In [mathematics](/source/Mathematics), **function application** (or **evaluation**) is the act of taking a [function](/source/Function_(mathematics)) and an input from its [domain](/source/Domain_of_a_function) to obtain the corresponding value from its [range](/source/Range_of_a_function). In this sense, function application can be thought of as the opposite of function [abstraction](/source/Abstraction_(mathematics)).[1]

It is central to [programming languages](/source/Programming_language) derived from [lambda calculus](/source/Lambda_calculus), such as [LISP](/source/LISP) and [Scheme](/source/Scheme_(programming_language)), and also in [functional languages](/source/Functional_language). It has a role in the study of the [denotational semantics](/source/Denotational_semantics) of computer programs, because it is a [continuous function](/source/Scott_continuity) on [complete partial orders](/source/Complete_partial_order). Function application is also a continuous function in [homotopy theory](/source/Homotopy_theory), and, indeed underpins the entire theory: it allows a homotopy deformation to be viewed as a continuous path in the space of functions. Likewise, valid mutations (refactorings) of computer programs can be seen as those that are "continuous" in the [Scott topology](/source/Scott_topology).

The most general setting for function application is in [category theory](/source/Category_theory), where it is [right adjoint](/source/Right_adjoint) to [currying](/source/Currying) in [closed monoidal categories](/source/Closed_monoidal_category). A special case of this are the [Cartesian closed categories](/source/Cartesian_closed_categories), whose [internal language](/source/Internal_language) is [simply typed lambda calculus](/source/Simply_typed_lambda_calculus).

## Representation

Function application is usually depicted by juxtaposing the variable representing the function with its argument encompassed in [parentheses](/source/Parentheses). For example, the following expression represents the application of the function *ƒ* to its argument *x*.

- f ( x ) {\displaystyle f(x)}

In some instances, a different notation is used where the parentheses aren't required, and function application can be expressed just by [juxtaposition](/source/Juxtaposition). For example, the following expression can be considered the same as the previous one:

- f x {\displaystyle f\;x}

The latter notation is especially useful in combination with the [currying](/source/Currying) isomorphism. Given a function f : ( X × Y ) → Z {\displaystyle f:(X\times Y)\to Z} , its application is represented as f ( x , y ) {\displaystyle f(x,y)} by the former notation and f ( x , y ) {\displaystyle f\;(x,y)} (or f ⟨ x , y ⟩ {\displaystyle f\;\langle x,y\rangle } with the argument ⟨ x , y ⟩ ∈ X × Y {\displaystyle \langle x,y\rangle \in X\times Y} written with the less common angle brackets) by the latter. However, functions in curried form f : X → ( Y → Z ) {\displaystyle f:X\to (Y\to Z)} can be represented by juxtaposing their arguments: f x y {\displaystyle f\;x\;y} , rather than f ( x ) ( y ) {\displaystyle f(x)(y)} . This relies on function application being [left-associative](/source/Left-associative).

When mathematical notation is represented in a digital document, the invisible zero-width [Unicode](/source/Unicode) characters U+2061 FUNCTION APPLICATION and U+2062 INVISIBLE TIMES can be used to distinguish concatenation meaning function application from concatenation meaning multiplication.

## As an operator

Function application can be defined as an [operator](/source/Operator_(mathematics)), called [apply](/source/Apply) or $ {\displaystyle \$} , by the following definition:

- f $ ⁡ x = f ( x ) {\displaystyle f\mathop {\,\$\,} x=f(x)}

The operator may also be denoted by a [backtick](/source/Backtick) (`).

If the operator is understood to be of [low precedence](/source/Order_of_operations) and [right-associative](/source/Right-associative), the application operator can be used to cut down on the number of parentheses needed in an expression. For example;

- f ( g ( h ( j ( x ) ) ) ) {\displaystyle f(g(h(j(x))))}

can be rewritten as:

- f $ ⁡ g $ ⁡ h $ ⁡ j $ ⁡ x {\displaystyle f\mathop {\,\$\,} g\mathop {\,\$\,} h\mathop {\,\$\,} j\mathop {\,\$\,} x}

This can be equivalently expressed using [function composition](/source/Function_composition) as:

- ( f ∘ g ∘ h ∘ j ) ( x ) {\displaystyle (f\circ g\circ h\circ j)(x)}

or even:

- ( f ∘ g ∘ h ∘ j ∘ x ) ( ) {\displaystyle (f\circ g\circ h\circ j\circ x)()}

if one considers x {\displaystyle x} to be a [constant function](/source/Constant_function) returning x {\displaystyle x} .

## Set theory

In [axiomatic set theory](/source/Axiomatic_set_theory), especially [Zermelo–Fraenkel set theory](/source/Zermelo%E2%80%93Fraenkel_set_theory), a function f : D ↦ R {\displaystyle f:D\mapsto R} is often defined as a [relation](/source/Relation_(mathematics)) ( f ⊆ D × R {\displaystyle f\subseteq D\times R} ) having the property that, for any x ∈ D {\displaystyle x\in D} [there is a unique](/source/There_is_a_unique) y ∈ R {\displaystyle y\in R} such that ( x , y ) ∈ f {\displaystyle (x,y)\in f} .

One is usually not content to write " ( x , y ) ∈ f {\displaystyle (x,y)\in f} " to specify that y {\displaystyle y} , and usually wishes for the more common function notation " f ( x ) = y {\displaystyle f(x)=y} " . Function application, or more specifically, the notation " f ( x ) {\displaystyle f(x)} ", is not present in the usual signature of set theory, but may be added to the theory as a binary [function symbol](/source/Function_symbol) ∙ ( ∙ ) {\displaystyle \bullet (\bullet )} if desired without any loss of expressiveness by defining:[2]

X ( Y ) = { z if X is a function, and ( Y , z ) ∈ X ∅ otherwise {\displaystyle X(Y)=\left\{{\begin{array}{lll}z&{\text{if }}X{\text{ is a function, and }}(Y,z)\in X\\\varnothing &{\text{otherwise}}\\\end{array}}\right.}

Or, more formally:[3][4]

X ( Y ) = z ⟺ ( ∃ D , R ( X ∈ R D ∧ ( ( Y , z ) ∈ X ) ) ) ∨ ( ∀ D , R ( X ∉ R D ∨ ( Y , z ) ∉ X ) ∧ z = ∅ ) , {\displaystyle X(Y)=z\iff (\exists D,R(X\in R^{D}\land ((Y,z)\in X)))\lor (\forall D,R(X\notin R^{D}\lor (Y,z)\notin X)\land z=\varnothing ),}

where R D {\displaystyle R^{D}} denotes [set exponentiation](/source/Set_exponentiation): the set of all functions from D {\displaystyle D} to R {\displaystyle R} .

In prose: X ( Y ) = z {\displaystyle X(Y)=z} if there exists a domain D {\displaystyle D} and range R {\displaystyle R} such that X {\displaystyle X} is a function from D {\displaystyle D} to R {\displaystyle R} and ( Y , z ) ∈ X {\displaystyle (Y,z)\in X} ; or (the negation of former) and z = ∅ . {\displaystyle z=\varnothing .} The choice of using the [empty set](/source/Empty_set) ∅ {\displaystyle \varnothing } when X ( Y ) {\displaystyle X(Y)} is undefined is arbitrary to ensure that the notation defined for the entire [domain of discourse](/source/Domain_of_discourse).[5]

If Ψ ( X , Y , z ) {\displaystyle \Psi (X,Y,z)} denotes the formula on the right side of the [biconditional](/source/Biconditional) above, for any two sets, X , Y {\displaystyle X,Y} the formula Ψ {\displaystyle \Psi } associates a unique object z {\displaystyle z} : ∀ X , Y ∃ ! z Ψ ( X , Y , z ) {\displaystyle \forall X,Y\,\exists !z\,\Psi (X,Y,z)} . Therefore the language of set theory can use an [extension by definition](/source/Extension_by_definition) to include the function application operation ∙ ( ∙ ) {\displaystyle \bullet (\bullet )} [conservatively](/source/Conservative_extension).

## Programming

In computer programming, function application often refers to calling or executing a procedure, rather than a true mathematical function (see [functions in computer programing](/source/Function_(computer_programming))), with similar rules for its behavior.

Function application corresponds to [beta reduction](/source/Beta_reduction) in [lambda calculus](/source/Lambda_calculus).

### Apply function

Related to the apply operator, the function **apply** applies a function to a variable *list* of arguments. *[Eval](/source/Eval)* and apply are the two interdependent components of the *eval-apply cycle* in Lisp, described in [SICP](/source/Structure_and_Interpretation_of_Computer_Programs).[6] This is suported in languages with [variadic functions](/source/Variadic_function), because this is the only way to call a function with an indeterminate (at compile time) number of arguments.

#### Common Lisp and Scheme

In [Common Lisp](/source/Common_Lisp) **apply** is a function that applies a function to a list of arguments (note here that "+" is a variadic function that takes any number of arguments):

(apply #'+ (list 1 2))

Similarly in Scheme:

(apply + (list 1 2))

#### C++

In [C++](/source/C%2B%2B), Bind [7] is used either via the std namespace or via the boost namespace.

#### C# and Java

In [C#](/source/C_Sharp_(programming_language)) and [Java](/source/Java_(programming_language)), variadic arguments are simply collected in an array. Caller can explicitly pass in an array in place of the variadic arguments. This can only be done for a variadic parameter. It is not possible to apply an array of arguments to non-variadic parameter without using [reflection](/source/Reflection_(computer_science)). An ambiguous case arises should the caller want to pass an array itself as one of the arguments rather than using the array as a *list* of arguments. In this case, the caller should cast the array to Object to prevent the compiler from using the *apply* interpretation.

variadicFunc(arrayOfArgs);

With version 8 lambda expressions were introduced. Functions are implemented as objects with a functional interface, an interface with only one non-static method. The standard interface

Function<T,R>

consist of the method (plus some static utility functions):

R apply(T para)

#### Go

In [Go](/source/Go_(programming_language)), typed variadic arguments are simply collected in a slice. The caller can explicitly pass in a slice in place of the variadic arguments, by appending a ... to the slice argument. This can only be done for a variadic parameter. The caller can not apply an array of arguments to non-variadic parameters, without using reflection..

s := []string{"foo", "bar"}
variadicFunc(s...)

#### JavaScript

In [JavaScript](/source/JavaScript), function objects have an apply method, the first argument is the value of the this keyword inside the function; the second is the list of arguments:

func.apply(null, args);

[ES6](/source/ECMAScript#6th_Edition_–_ECMAScript_2015) adds the spread operator func(...args)[8] which may be used instead of apply.

#### Lua

In [Lua](/source/Lua_(programming_language)), apply can be written this way:

function apply(f,...)
  return f(...)
end

#### Perl

In [Perl](/source/Perl), arrays, hashes and expressions are automatically "flattened" into a single list when evaluated in a list context, such as in the argument list of a function

# Equivalent subroutine calls:
@args = (@some_args, @more_args);
func(@args);

func(@some_args, @more_args);

#### PHP

In [PHP](/source/PHP), apply is called call_user_func_array:

call_user_func_array('func_name', $args);

#### Python and Ruby

In [Python](/source/Python_(programming_language)) and [Ruby](/source/Ruby_(programming_language)), the same asterisk notation used in defining [variadic functions](/source/Variadic_function) is used for calling a function on a sequence and array respectively:

func(*args)

Python originally had an apply function, but this was [deprecated](/source/Deprecated) in favour of the asterisk in 2.3 and removed in 3.0.[9]

#### R

In [R](/source/R_(programming_language)), do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it:

f(x1, x2)
# can also be performed via
do.call(what = f, args = list(x1, x2))

#### Smalltalk

In [Smalltalk](/source/Smalltalk), block (function) objects have a valueWithArguments: method which takes an array of arguments:

aBlock valueWithArguments: args

#### Tcl

Since [Tcl](/source/Tcl_(programming_language)) 8.5,[10] a function can be applied to arguments with the apply command

apply func ?arg1 arg2 ...?

where the function is a two element list {args body} or a three element list {args body namespace}.

## Universal property

Consider a [function](/source/Function_(mathematics)) g : ( X × Y ) → Z {\displaystyle g:(X\times Y)\to Z} , that is, g ∈ [ ( X × Y ) → Z ] {\displaystyle g\in [(X\times Y)\to Z]} where the bracket notation [ A → B ] {\displaystyle [A\to B]} denotes the [space of functions](/source/Space_of_functions) from *A* to *B*. By means of [currying](/source/Currying), there is a unique function curry ( g ) : X → [ Y → Z ] {\displaystyle {\mbox{curry}}(g):X\to [Y\to Z]} . Then **Apply** provides the [universal morphism](/source/Universal_morphism)

- Apply : ( [ Y → Z ] × Y ) → Z {\displaystyle {\mbox{Apply}}:([Y\to Z]\times Y)\to Z} ,

so that

- Apply ( f , y ) = f ( y ) {\displaystyle {\mbox{Apply}}(f,y)=f(y)}

or, equivalently one has the [commuting diagram](/source/Commuting_diagram)

- Apply ∘ ( curry ( g ) × id Y ) = g {\displaystyle {\mbox{Apply}}\circ \left({\mbox{curry}}(g)\times {\mbox{id}}_{Y}\right)=g}

More precisely, curry and apply are [adjoint functors](/source/Adjoint_functors).

The notation [ A → B ] {\displaystyle [A\to B]} for the space of functions from *A* to *B* occurs more commonly in computer science. In [category theory](/source/Category_theory), however, [ A → B ] {\displaystyle [A\to B]} is known as the [exponential object](/source/Exponential_object), and is written as B A {\displaystyle B^{A}} . There are other common notational differences as well; for example *Apply* is often called *Eval*,[11] even though in computer science, these are not the same thing, with [eval](/source/Eval) distinguished from *Apply*, as being the evaluation of the quoted string form of a function with its arguments, rather than the application of a function to some arguments.

Also, in category theory, *curry* is commonly denoted by λ {\displaystyle \lambda } , so that λ g {\displaystyle \lambda g} is written for *curry*(*g*). This notation is in conflict with the use of λ {\displaystyle \lambda } in [lambda calculus](/source/Lambda_calculus), where lambda is used to denote bound variables. With all of these notational changes accounted for, the adjointness of *Apply* and *curry* is then expressed in the commuting diagram

Universal property of the exponential object

The articles on [exponential object](/source/Exponential_object) and [Cartesian closed category](/source/Cartesian_closed_category) provide a more precise discussion of the category-theoretic formulation of this idea. Thus the use of lambda here is not accidental; the [internal language](/source/Internal_language) of Cartesian closed categories is [simply typed lambda calculus](/source/Simply_typed_lambda_calculus). The most general possible setting for *Apply* are the [closed monoidal categories](/source/Closed_monoidal_category), of which the cartesian closed categories are an example. In [homological algebra](/source/Homological_algebra), the adjointness of curry and apply is known as [tensor-hom adjunction](/source/Tensor-hom_adjunction).

## Topological properties

In [order theory](/source/Order_theory), in the category of [complete partial orders](/source/Complete_partial_order) endowed with the [Scott topology](/source/Scott_topology), both *curry* and *apply* are [continuous functions](/source/Continuous_function) (that is, they are [Scott continuous](/source/Scott_continuous)).[12] This property helps establish the foundational validity of the study of the [denotational semantics](/source/Denotational_semantics) of computer programs.

In [algebraic geometry](/source/Algebraic_geometry) and [homotopy theory](/source/Homotopy_theory), *curry* and *apply* are both continuous functions when the space Y X {\displaystyle Y^{X}} of continuous functions from X {\displaystyle X} to Y {\displaystyle Y} is given the [compact open topology](/source/Compact_open_topology), and X {\displaystyle X} is [locally compact Hausdorff](/source/Locally_compact_Hausdorff). This result is very important, in that it underpins homotopy theory, allowing homotopic deformations to be understood as continuous paths in the space of functions.

## Other instances

The [Curry–Howard correspondence](/source/Curry%E2%80%93Howard_correspondence) relates function application to the logical rule of [modus ponens](/source/Modus_ponens).

## See also

Look up ***[apply](https://en.wiktionary.org/wiki/apply)*** in Wiktionary, the free dictionary.

- [Evaluation strategy](/source/Evaluation_strategy)

- [Execution (computing)](/source/Execution_(computing))

- [Function composition](/source/Function_composition)

- [Polish notation](/source/Polish_notation)

## References

1. **[^](#cite_ref-1)** Alama, Jesse; Korbmacher, Johannes (2023), ["The Lambda Calculus"](https://plato.stanford.edu/archives/win2023/entries/lambda-calculus/), in Zalta, Edward N.; Nodelman, Uri (eds.), *The Stanford Encyclopedia of Philosophy* (Winter 2023 ed.), Metaphysics Research Lab, Stanford University, retrieved 2024-02-29

1. **[^](#cite_ref-2)** [Mendelson, Elliott](/source/Elliott_Mendelson) (2015). [*Introduction to Mathematical Logic*](https://www.routledge.com/Introduction-to-Mathematical-Logic/Mendelson/p/book/9781032919140) (6th ed.). [CRC Press](/source/CRC_Press). pp. 102–103, 231, 235, 245–246. [ISBN](/source/ISBN_(identifier)) [978-1-4822-3778-8](https://en.wikipedia.org/wiki/Special:BookSources/978-1-4822-3778-8).

1. **[^](#cite_ref-3)** [Suppes, Patrick](/source/Patrick_Suppes) (1972). [*Axiomatic set theory*](https://archive.org/details/axiomaticsettheo00supp_0/). Internet Archive. New York, Dover Publications. p. 87. [ISBN](/source/ISBN_(identifier)) [978-0-486-61630-8](https://en.wikipedia.org/wiki/Special:BookSources/978-0-486-61630-8).

1. **[^](#cite_ref-4)** Lévy, Azriel (1979). [*Basic set theory*](https://archive.org/details/basicsettheory00levy_0/mode/2up). Berlin; New York: Springer-Verlag. p. 27. [ISBN](/source/ISBN_(identifier)) [978-0-387-08417-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-387-08417-6).

1. **[^](#cite_ref-5)** Lévy, Azriel (1979). [*Basic set theory*](https://archive.org/details/basicsettheory00levy_0/mode/2up). Berlin; New York: Springer-Verlag. p. 15. [ISBN](/source/ISBN_(identifier)) [978-0-387-08417-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-387-08417-6).

1. **[^](#cite_ref-6)** Harold Abelson, Gerald Jay Sussman, Julie Sussman, *Structure and Interpretation of Computer Programs*, (1996) MIT Press, [ISBN](/source/ISBN_(identifier)) [0-262-01153-0](https://en.wikipedia.org/wiki/Special:BookSources/0-262-01153-0). *See [Section 4.1, The Metacircular Evaluator](http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html)*

1. **[^](#cite_ref-7)** ["Boost: Bind.HPP documentation - 1.49.0"](http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html#with_functions).

1. **[^](#cite_ref-8)** ["Spread syntax - JavaScript | MDN"](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator). Retrieved 2017-04-20.

1. **[^](#cite_ref-9)** ["Non-essential built-in functions"](https://docs.python.org/release/2.3.5/lib/non-essential-built-in-funcs.html). *Python Library Reference*. 8 February 2005. Retrieved 19 May 2013.

1. **[^](#cite_ref-10)** ["apply"](https://tmml.sourceforge.net/doc/tcl/apply.html). *Tcl documentation*. 2006. Retrieved 23 June 2014.

1. **[^](#cite_ref-11)** [Saunders Mac Lane](/source/Saunders_Mac_Lane), *Category Theory*

1. **[^](#cite_ref-12)** H.P. Barendregt, *The Lambda Calculus*, (1984) North-Holland [ISBN](/source/ISBN_(identifier)) [0-444-87508-5](https://en.wikipedia.org/wiki/Special:BookSources/0-444-87508-5)

---
Adapted from the Wikipedia article [Function application](https://en.wikipedia.org/wiki/Function_application) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Function_application?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
