Function with Variable Length Argument List

214 Views Asked by At

In programming languages, for instance, in the C language we may define a function with a variable length argument list as follows:

double sum(int n, ...) // Returns the sum of 'n' numbers

and for example call it as follows:

double result = sum(3,2.5,3.5,4.0); // Now 'result' holds the value 2.5+3.5+4.0=10

The problem is, How can we define in mathematics the equivalent of this notion?

For example we may try to define $sum$ as:

${sum}: \bigcup_{n\in\mathbb{N}}\{n\}\times \mathbb{R}^n\longrightarrow\mathbb{R}$

$\forall (m,\vec{x})\in \bigcup_{n\in\mathbb{N}}\{n\}\times\mathbb{R}^n, sum(m,\vec{x}):=\Sigma_{i=1}^m x_i$

And this seems to be a good mathematical definition of $sum$ as a variable length argument function.

So, is this the general way to look at variable length argument functions in mathematics?

If you want to make in mathematics a variable length argument function $f$ that will take variable length arguments from some non-empty set $X\neq \emptyset$ to some set $Y$ define the domain of $f$ to be $\bigcup_{n\in\mathbb{N}}\{n\}\times X^n$ And $f:\bigcup_{n\in\mathbb{N}}\{n\}\times X^n\longrightarrow Y$

?

1

There are 1 best solutions below

2
On

Sure, that works. Here is a different method: Given a set $X$ let $^{< \infty} Y$ be the set of all functions $s \colon n \to X$ with $n \in \mathbb N$. Now let $(f_n \mid n \in \mathbb N)$ be your sequence of $n$-ary function on $X$ with some common domain $Y$ (this isn't necessary -- we can take the union of all of the domains). Let $$ F \colon ^{< \infty}Y \to X, s \mapsto f_{\mathrm{dom}(s)} (s(0), \ldots, s(\mathrm{dom}(s)-1). $$

The key distinction to your solution is that $F$ is a $1$-ary function. It just so happends that you are allowed to plug in finite sequences into $F$ as an argument -- thus mimicking the behavior of a function with variable argument length.

Moreover, if the functions $f_n(.)$ commute, i.e. the order of its arguments doesn't matter, and you never want to enter an argument into to different places in $f_n$, you can consider the set $^{< \omega}[Y]$ of all finite subsets of $Y$ and consider $$ G \colon ^{< \infty}[Y] \to X, x \mapsto f_{|x|}(x_0, \ldots, x_{|x|-1}) $$ for any enumeration $x = \{ x_0, \ldots, x_{|x|-1}\}$ of $x$.