# Why does a function need a fixed number of arguments?

I was thinking about how common commutative and associative operations can be thought of as acting on several numbers even though we do it in many separate binary steps, such as $$a+b+c+d$$ being expressible as $$a+(b+(c+d))$$ and we call the value that any of these expressions have as their 'Sum' but can we define a function/operation or mapping that takes $$n$$ number inputs for any $$n$$ and returns their sum? The issue is, we could give it $$3$$ inputs, or two inputs and for each there would be a different tuple, (or real number), so the function would have a non-constant number of arguments, is this possible to define?

As in general for a function $$f(x_1,x_2....x_n$$) for a different $$n$$ it must be a different function denoted by $$f$$.

• Perhaps more a consequence of history than objective mathematical necessity, variadic functions are primarily a matter of computer science rather than standard mathematical practice. But if I define functions $f_n$ of domain $A^n$ and codomain $B$ and take these functions' union, I get a function of domain $\bigcup_nA^n$, which is often but by no means always an inconvenient concept.
– J.G.
Sep 5, 2022 at 12:16
• What is it you mean by an union of functions, exactly? For instance, if $x \in A^n \subset A^m$, and $f_n(x) \neq f_m(x)$, how is the union defined at $x$? Sep 5, 2022 at 12:30
• @J.G. So they exist, but it's not particularly common practice to do so? Sep 5, 2022 at 12:32
• If you're into databases, the SQL programming language has the concept of aggregate/aggregating functions that behave rather like what you describe. Sep 5, 2022 at 13:14
• @DouglasFinamore If we identify a function $f$ with the set of ordered pairs of the form $(x,\,f(x))$, and functions have no common domain values (except maybe ones on which they're equal), the union of these sets is also identifiable with a function.
– J.G.
Sep 5, 2022 at 13:54

Strictly speaking a function can be regarded as a quadruple of

• A label or name, like $$\sin$$.

• A domain $$D$$.

• A codomain $$C$$.

• A mapping that for each element of $$D$$ tells how to "compute" its image in $$C$$.

Functions with variable number of arguments can be convenient, there are several ways to approach them.

## I. Use different functions with the same label

(Ab)using notation, you could have functions with the same name indexed by their number of arguments like:

$$\gcd\nolimits_n:\Bbb Z^n\to\Bbb Z$$ defined recursively as

$$\gcd\nolimits_n(x_1,\dots,x_n)=\begin{cases} x_1, &\text{ if } n=1\\ \gcd(x_1, x_2), &\text{ if } n=2\\ \gcd(\gcd_\nolimits{n-1}(x_1,\dots, x_{n-1}), x_n), &\text{ if } n>2\\ \end{cases}$$ and then, as a matter of convenience / lazyness, drop the index and just write $$\gcd(a,b,c,d)$$ etc. where it's unabgiguously clear that you mean the specimen $$\gcd_4$$.

## II. Use a domain that contains all possible $$n$$-tuples

You can use a domain that contais all possible tuples of values: $$D^\cup=\bigcup_{n\in\Bbb N} D = D\cup D^2\cup D^3\cup\cdots$$

The $$\gcd$$-example from above would be $$\gcd:\Bbb Z^\cup\to\Bbb Z$$. Notice however, that we didn't yet define the function law, and doing it recursively gets much more convoluted than with approach I. To write it down, we'd need to define a function that "forgets" the last component of a $$n$$-dimensional vector etc., and all that notations is just cluttering up things and making things more convoluted than needed.

## III. Use already existing notation

As you are referrung to sums: Functions with variable number of arguments are already in wide-spread use, and using them is usually not a deep dive in the rabbithole of nitpicking, it's just a notation that's been taken for granted. For example, the sum notation $$\sum$$ is a very generic device. It's supposed to be meaningful over any domain that knows of summation, different notations of specifying the indices are understood, etc. like

$$\sum_{n\in\Bbb N}\frac1{n^2}=\sum_{n=1}^\infty\frac1{n^2}$$

and it can even cope with zero arguments: The empty sum is defined to be $$0$$.

## On Notation

The previous sections make it very clear that variable-argument functions is more a matter of notation, that help to improve reader's experience by not going into 200% nitpick mode. To that end, the notation for arguments that are vectors is already bit sloppy but still consistent. Take for example again $$\gcd:\Bbb Z^2\to\Bbb Z$$ This can be seen as

• A function that takes two arguments from $$\Bbb Z$$.

• A function that takes one vector-argument from $$\Bbb Z^2$$.

In the first case, the notation is $$\gcd(a,b)$$ with $$a,b\in\Bbb Z$$. In the second case, it is $$\gcd(v)=\gcd((a,b))$$ with $$v=(a,b)\in\Bbb Z^2$$.

• For gcd, in particular, the natural generalization is in fact to define it as a function from $\mathcal P(\mathbb Z)$ (i.e. the set of sets of integers) to $\mathbb N$, with $\gcd(\emptyset)=\gcd(\{0\})=0$ and $\gcd(S)$ for all other $S\subseteq\mathbb Z$ is the largest $n\in\mathbb N$ such that every number $x\in S$ can be written as $x = nk$ for some integer $k$. Showing that $\gcd(S)$ is indeed well defined for all $S\subseteq\mathbb Z$ and that $\gcd(\{a,b,c,…\})=\gcd(a,\gcd(b,\gcd(c,…)))$ for finite sets is left as an exercise. :) Sep 5, 2022 at 21:30

The way functions are defined is as a relation between two sets. A function $$f: A \to B$$ can be thought as a subset $$G = (x, f(x))$$ of the cartesian product $$A \times B = \{ (a,b); a \in A, b \in B\}$$ satisfying the property that for each $$x \in A$$ there's is only one $$f(x) \in B$$ such that $$(x, f(x)) \in G$$. Heuristically, this is basically defining what a function is by means of its graph. Of course, what we usually do in a daily basis is to think of $$f$$ not as an subset, but as a rule $$x \mapsto f(x)$$ relating to each object of $$A$$ an object in $$B$$

In this sense, you could say that, technically, every function $$f$$ has only one argument, which is the element in $$A$$. When you write something like $$f(x_1, \cdots, x_n)$$ and say $$f$$ is a function of $$n$$ arguments you are simply considering a function whose domain $$A$$ is written as product $$A = A_1 \times A_2 \times \cdots \times A_n$$. In this case, each $$n$$-tuple $$(x_1, \cdots, x_n)$$ is a single element $$x$$ of $$A$$, so in the end $$f(x_1, \cdots, x_n)$$ is simply $$f(x)$$.

By adding or removing arguments I'm changing the product $$A$$, so I end up with different functions, strictly speaking, because I'm varying the domain.

What you can do is consider a huge set with all possible arguments, and fill most of them with constants. Let's think of real numbers, for example. You let the domain be $$\mathbb{R}^\mathbb{N} = \mathbb{R} \times \mathbb{R} \times \mathbb{R} \times \cdots = \{(x_1, x_2, \cdots, x_n, \cdots); x_i \in \mathbb{R}\},$$ which is basically the set of all sequences $$\{a_n\}_{n \in \mathbb{N}}$$. Let $$f:\mathbb{R}^\mathbb{N} \to B$$ be a function. If you make the convention that every $$m$$-tuple $$(x_1, \cdots, x_m)$$ corresponds to the sequence $$(x_1, \cdots, x_m, 0, 0, 0, \cdots)$$, then it makes sense to write things like $$f(x_1, x_2)$$ or $$f(x_1, x_2, x_3, x_4,x_5)$$, and you can think of this as a fucntion where the number of arguments is varying. But in the end there is only one argument, which is a sequence in $$\mathbb{R}^\mathbb{N}$$.

This would work in a general infinite product $$A_1 \times A_2 \times \cdots$$ as well, but then you would have to choose elements $$a_n \in A_n$$ to play the role of $$0$$.

• This works OK for $a + b + c + d,$ not so well (I think) for $a \cdot b \cdot c \cdot d.$ Sep 5, 2022 at 14:30
• For multiplication of an arbitray number of elements to make sense you would have to "fill" the sequences with $1$'s. But in any case, my intention was to show a way in which a function already defined in a large countable cartesian product can be seem as function of a any finite number of elements. As for the answer to OP actual question, "why do we need a fixed number of arguments", I believe it would be that, formally, functions have actually only one argument. Sep 5, 2022 at 18:35
• Right, the main point is one argument. You make that quite clear in the answer. Sep 5, 2022 at 18:41

You can actually simulate a function with an arbitrary finite number of arguments: if the domain of your variables is $$X$$, then your function's domain could be $$\coprod_{n\in \mathbb N}X^n$$.