6

I wanna be frank with you guys and say my mathematical education was a bit... bleh, so I'm teaching myself a lot of stuff lately, a question that has come up for me: "Is it possible to pass functions into other functions?"

Like say I have a function $g$ that takes $2$ parameters $f$ and $a$, where $f$ is a function, and $a$ is any natural or real number (doesn't really matter in this case), I'd then use both of those later in $g$'s definition... The function passed into $g$ would then slightly alter $g$'s behavior, making $g$ more general by letting me pass other functions into it whenever I'd need it.

Is this doable at all? And would there even be any use for this in mathematics?

Note that I'm aware of how Higher Order Functions work in programming, I just haven't gotten the faintest clue if or how they're used in maths

  • 2
    Composition of two functions is possible. – Torsten Hĕrculĕ Cärlemän Jul 17 '13 at 15:02
  • I would say that this idea was considered in mathematics long before the first digital computers were ever built... – Zhen Lin Jul 17 '13 at 15:11
  • @ZhenLin of course it was, functional programming is made on the basis of mathematics, I never stated otherwise – Electric Coffee Jul 17 '13 at 15:30
  • Two common examples are $\mathrm{Dom}(f)$ and $\mathrm{Img}(f)$ for the domain and image/range of a function $f$. Also, functions are usually "represented" as a set of pairs, so $f$ can simply be seen as a set, which you then can do usual set operations on, union, intersection, cardinality etc. – Pål GD Jul 17 '13 at 17:05
  • Ever heard of the Chain Rule when it comes to derivatives? – JB King Jul 17 '13 at 18:08
  • We had a teacher saying you've all seen composition of functions in the first grade! His example was $2 \longrightarrow^{+3} 5 \longrightarrow^{-2} 3$, which you have all simplified to $2 \longrightarrow^{+1} 3$ :) – Ali Jul 18 '13 at 06:55

5 Answers5

12

Yes, it's doable, and it's useful too.

Take for example the following 'indefinite integral function', which I'll denote by $I$. It takes three arguments:

  • A real number $a$
  • A real number $b$, with $a < b$
  • A real-valued function $f$ which is defined and bounded on the interval $a < x < b$

Then define $$I(a,b,f) = \int_a^b f(x)\, dx$$

This is as good a function as any, and takes a function as an argument.

You can even have functions which both take in functions as arguments and spit out functions afterwards. For example, there is a function on the class of differentiable real functions defined by $$\dfrac{d}{dx} : f \mapsto f'$$ It takes in a function $f$ and spits out its derivative.


For the nitpickers: some of the conditions given above aren't necessary, such as the stipulation that $a<b$ or even that $f$ be real-valued or whatever. But hopefully this is a simple example that illustrates the use of a function of the kind the OP wants.

5

Yes. Functions taking other functions as arguments are called higher-order functions. For example, g(f) might return a function 2*f(x) given a function f(x).

This has lots of uses in computer science and the rest of mathematics.

Charles
  • 32,122
4

Note that you can interpret normal functions $f: \mathbb{R}\to\mathbb{R}$ like this all the time. If

$$f(x)=x^2-3x$$

then

$$f(g(x))=g(x)^2-3g(x)$$

which we can reinterpret as

$$f(g)=g^2-3g$$

where $g$ is now a function, rather than a number. In the final line $f$ is a function that takes a function $g$ as input and produces a function $g^2-3g$ as output. So the same function can be considered as capable of operating on multiple types in a totally unambiguous way (they're not really the same because they have different domains and codomains, but this can be made precise). You'll see more of this if you get into functional programming.

  • Robert, I am not the OP, but this $f(g)$ business looks interesting. Is there somewhere I can learn more? – goblin GONE Jul 17 '13 at 15:09
  • @user18921 Other than general research into functional programming I'm not sure. I've just stumbled into/grown to realize the connection over time; I don't know the formal name for the concept. Hopefully someone who knows more can chime in. – Robert Mastragostino Jul 17 '13 at 15:20
2

This is very common. Examples of functions that map (or convert) functions into other functions are'"derivative" and "indefinite integral", which I will write as, respectively, $D$ and $\int$.

Both of these would take a function (such as $x^2$) and the variable of differentiation or integration (such as $x$) and return their derivative or indefinite integral with respect to that variable.

Then $D(x^2, x) = 2x$ and $\int(x^2, x) = x^3/3+c$ (where $c$ is an arbitrary constant).

Note that the variable is quite important. If it is not the same as the variable used by the function, you get results like $D(x^2, y) = 0$ and $\int(x^2, y) = y\ x^2+c$.

marty cohen
  • 107,799
1

You can define real function $f(x)$ on arbitrary set. The trick is that functions itself can be considered as set too.

For example you can get this famous physical formula for action of mechanical system:

$$\mathcal{S}[\mathbf{q}(t)] = \int_{t_1}^{t_2} L[\mathbf{q}(t),\dot{\mathbf{q}}(t),t]\, dt$$

or geometical formula for arc length:

$$l = \int_{a}^{b} \sqrt { 1 + [f'(x)]^2 }\, dx. $$

This is called functional. It studies by functional analysis and calculus of variation. Real interest and applications have a linear functionals that statisfies:

$$\Phi[\mathbf f+\mathbf g] = \Phi[\mathbf f] + \Phi[\mathbf g]$$

$$\Phi[c\ \mathbf f] = c\ \Phi[\mathbf f]$$

This of course not only application of idea of "function from function" in math. There is also a Lambda calculus and concept of recursion which is more related to computers.

igumnov
  • 809