Can functions be passed into functions and then called?

228 Views Asked by At

In computer science there are what are known as higher-order functions. This means pretty much nothing, really. It is a property of a programming language.

I want to know if they are valid in mathematics, and if so, what the notation is. It would be like the following function definition:

$$g(x,y,f) = 20 + f(x + 3y)$$

The function itself is not really important. I just obscured it enough so that it cannot be made into a function composition.

I know that integrals, limits, and derivatives are sort of like functions that take functions as arguments. What about functions that return arguments?

Like:

$$h(f) = 3 \cdot f$$

The above would return the f function but where the terms are multiplied by three. Of course this would be f itself, not its image.

What is the difference between a function and its image anyway? I imagine it would be like the difference between source code and return values, but I have never heard of math having "source code" so it seems bizarre to me.

3

There are 3 best solutions below

0
On

Yes, this is perfectly valid, and there's no particular notation for it (the notation you used is perfectly fine). In general, if $X$ and $Y$ are two sets then a function $g:X\to Y$ is a rule that assigns to each element of $X$ an element of $Y$ (more formally, "rule" here really means a set of ordered pairs $(x,y)$, where for each $x\in X$ there is a unique $y\in Y$ such that $(x,y)$ is in the set; we then say $y=g(x)$). The sets $X$ and $Y$ can be any sets at all, including sets of functions.

So, for instance, your example $g(x,y,f)=20+f(x+3y)$ could be considered as a function whose domain is the set $X$ of all ordered triples $(x,y,f)$, where $x,y\in\mathbb{R}$ and $f:\mathbb{R}\to\mathbb{R}$ is a function and whose range is $\mathbb{R}$. Given any triple $(x,y,f)$, $g$ gives you a real number, namely $20+f(x+3y)$.

0
On

Roughly speaking, in mathematics, higher-order functions come in two forms:

For example, the integral of a function $f : \mathbb R \to \mathbb R$ over all $\mathbb R$ is a functional

$$I (f) := \int_{-\infty}^{\infty} f (x) \, \mathrm d x$$

Another functional would be the energy of a square-integrable function $f : \mathbb R \to \mathbb R$

$$\mathcal E (f) := \int_{-\infty}^{\infty} |f (x)|^2 \, \mathrm d x$$

If I understand correctly, you are more interested in operators than in functionals. One can think of an electric circuit as an operator that transforms an input signal into an output signal. If this circuit has capacitors or inductors, then the operator will be a differential operator. For example, a simple RC circuit "embodies" the following differential operator

$$RC \frac{\mathrm d}{\mathrm d t} + 1$$

The gradient, divergence and curl are also differential operators. The indefinite integral is also an operator. The "source code" of an operator is its definition.

5
On

This probably might fit more in a comment, but still.

You wrote:

$$g(f)=3\cdot f$$ The above would return the f function but where the terms are multiplied by three.

And I want you to think a bit about it, because you have type mismatch here (using a programming jargon here as you have just revealed yourself being a programmer). You take a function, multiply it by a number and return it as a function.

As mathematics notation is meant to be understand by humans, which are constantly dealing with disgustingly ambiguous natural languages, chances are everyone is going to understand what you mean perfectly fine, but.

You cannot really multiply a number by a function (well, before you define such a thing). Assuming $f$ takes and returns a real number, which is notated as $$f:\mathbb R\to\mathbb R,$$ then the usage of $3f(x)$, for example, is correct, as the part $f(x)$ means "the result of evaluation of $f$ at $x$", which we know is a real number, so multiplication by $3$ works.

However, the use of $3f$ is problematic, because, for one, $f$ might as well return something different from a number, as noticed by @fleablood. But, and more importantly, in this expression you have $f$ unevaluated.

And, rigorously speaking, that is not at all defined in usual axiomatisations. Calling something a number usually implies it is an element of some set on which there is a multiplication defined. And there isn't any functions in those sets (again, usually). For example, there aren't any in $\mathbb R$. So there isn't any readily available multiplication to use.

Functions and numbers are (usually thought of as) different things, and have different structure.

Additionally, the use of the word "term" is also problematic in your quote. There isn't any reason to believe some function was defined via some formula, which in turn consists of terms. Polynomials consist of terms. Other types of formulae may not. Furthermore, functions may be defined by a plot, a chart, a table of values, or simply described in English. Find a term to multiply by three there!


The plain fix would be the use of function definition notation: $$g(f)=x\mapsto3f(x).$$ Notice the variable $x$ here is local and does not leave the scope of $\mapsto$. Better yet would, though, to specify the scope and domain, however you like. Maybe like $$g(f)=\mathbb R\ni x\mapsto3f(x)\in\mathbb R$$ or $$g(f)=x\mapsto_{_{\mathbb R\to\mathbb R}}3f(x).$$ Notice also, however, the difference between $\mapsto$ and $\to$. The former specifies which element maps to which another element, while the latter specifies which sets does the function relate.


P. S. Please do not use conflicting definitions (that's the second most irritating thing for me after sloppy use of function notation). Please notice you have $g$ defined twice and incompatibly in your original post.