# Are “sum” and “product” defined when there is only one number?

I solved a math problem on an online judge site recently. The question specified that the answer should be for an input number N, the smallest non-negative number Q so that the product of the digits of Q exactly equal N.

The answer for inputs 1 through 9 are 1 through 9, respectively. However, this offends my sense that a "product" must have two or more "factors". To me, the answers for 1 through 9 should be 11 through 19 -- it takes two factors to produce a product.

I'll note that this sense does not extend to sum, I'd have no issue saying that the sum of the digits in the number 3 is 3, which I'll readily admit isn't being self consistent.

It is mathematically rigorous to say that "the sum/product of a set of numbers" is defined for when there is just one number, and that the answer is that number?

-
In functional programming terms, sums and products are defined as folds, where it’s natural to begin with an identity element—the product of just $n$ is really $1 \times n$. – Jon Purdy Sep 16 '12 at 23:45
Amazing, didn't know that product and sum could also be interpretated as an unary operator. – Voyska Sep 17 '12 at 9:06

You would probably agree that $$\sum\limits_{n=1}^Nx_n=x_N+\sum\limits_{n=1}^{N-1}x_n\quad\text{and}\quad \prod\limits_{n=1}^Nx_n=x_N\cdot\prod\limits_{n=1}^{N-1}x_n.$$ Try $N=2$ in these formulas and identify $$\sum\limits_{n=1}^{1}x_n\quad\text{and}\quad\prod\limits_{n=1}^{1}x_n.$$ By the same argument, any sum of zero terms is $0$ and any product of zero terms is $1$.

-
"You would probably agree...": yes for many values of $N$, but not for all. I wouldn't agree for $N=0$. The real question is how small one wants to let $N$ be in order to agree. Personally $N=1$ is fine with me, but one does not have to accept thus just because one accepts the equation for $N>2$. In other words, the above is just a plausibility argument. – Marc van Leeuwen Jan 14 '14 at 7:41
@MarcvanLeeuwen Thanks for letting me know your personal restrictions. – Did Jan 14 '14 at 9:51

We can define multiplication $a\cdot b$ as an $a$ long sum of $b$'s. Think of objects alligned in a rectangle, the way you're taught in elementary school. What then would the product $1\cdot5$ mean? It would be the total sum of one $5$. For multiplication, the same argument can be made with $5^1$. But it gets better.

What is the sum of no numbers? That's easy to calculate, $0\cdot b= 0$. But how do you make sense of that? Imagine having a box full of numbers, and a display on the lid of the box what the sum of those numbers are. Then take them out, one by one, and see how the display changes. The intuitive consequence is that when you remove the last number from the box, the display should read "0".

What then, of the product of 0 numbers? Imagine a calculator with a number pad, a clear-button, an enter-button and a one-line display. It has one number stored, and you can type in another number. As long as you're not typing, the stored number is shown on the display. When you press the "enter"-button, the calculator multiplies the typed number wiht the stored number, stores the result, and displays it. When you press "clear", you would intuitively have a product of no numbers stored, and the only number to store that makes the calculator work is 1. So the empty product is 1. You see it in math as for instance $5^0$, and $0!$.

-
kind of lost you with the calculator but all the rest makes sense, thanks! – Bogatyr Sep 16 '12 at 20:34
@Bogatyr Actually, the calculator example I think I stole from the wikipedia article on empty product. It might have more understandable phrasing there. – Arthur Sep 16 '12 at 21:34
@Bogatyr I see from your profile, you're a programmer. Here's a nice analogy. How would you implement: $\sum_{i} x_i$? One way is using a loop and an accumulator variable sum, then doing sum += something at every iteration. The key question is how do you initialize sum? Zero! Because it's the null sum. Similarly, if you're implementing a loop for $\prod_{i} x_i$, you'll keep an accumulator result and do result *= something and initialize it to $1$ (not $0$). Hopefully this will help your understand the calculator example! – user2468 Sep 16 '12 at 21:49
@JenniferDylan yes that makes sense :), thanks. – Bogatyr Sep 17 '12 at 4:13

A function should be defined for as many inputs as it can consistently be defined for. Defining product(x) => x is perfectly consistent with all the rules of multiplication, so defining it thus can only improve the expressiveness of mathematical statements.

-
I don't quite agree on "A function should be defined for as many inputs as it can consistently be defined for". You could extend any function $\mathbb{N}\to\mathbb{Q}$ to, say, the quarternions in some way, but where there isn't one canonical way to do it would be more confusing than helpful. – leftaroundabout Sep 17 '12 at 7:34

Actually when you define the sum and the product, you initially define it for exactly two numbers. Not more, not less. Then you notice that addition and multiplication are associative, so it doesn't matter if you first add $a$ and $b$, and then add $c$ to the result, or of you first add $b$ and $c$, and then add that to $a$. Therefore you can easily extend that definition to three or more summands, by using a recursion: $a_1+\ldots+a_n = (a_1+\ldots+a_{n-1})+a_n$. This way, you have defined the sum for any number of at least two summands.

But then, the restriction seems quite arbitrary, so can we extend the definition to just one summand? Well, we can, because the obvious condition is that the recursion rule still holds, that is $(\text{the sum of$a_1$})+a_2 = a_1 + a_2$, which of course for given $a_1$ has to hold for all values of $a_2$. There's exactly one solution to this equation, namely $(\text{the sum of$a_1$})=a_1$.

We can go even further and ask if we can define the sum of no numbers. And indeed, we can: Our recursion now reads $(\text{the sum of no numbers})+a_1 = a_1$, which of course immediately implies $(\text{the sum of no numbers})=0$.

The same construction can be done with the product of course, and we again get $(\text{the product of$a_1$})=a_1$, and then $(\text{the product of no numbers})=1$.

Another way to make sense of sums of no or just one number, imagine a set of disjunct finite sets (that is, each set has only finitely many elements, and no two sets have the same elements), and then ask how many elements there are totally (mathematically: how many elements the union of those sets has). Of course, since the sets are disjunct, the total number of elements is the sum of the numbers of elements in the sets. But what if there is only one set? Well, in that case, the total number of elements is just the number of elements in that set! Thus the sum of just one number is that number. And finally, what if there are no sets at all? Well, if there are no sets, there are no elements, therefore the sum of no numbers is $0$.

To do the same argument for multiplication, ask how many different sets there are which have exactly one element from each of the sets, and nothing else. You'll find that this is just the product of the sizes of the sets (e.g. if you have the sets $\{a,b\}$ and $\{1,2,3\}$ you'll get the 6 sets $\{a,1\}$, $\{a,2\}$, $\{a,3\}$, $\{b,1\}$, $\{b,2\}$ and $\{b,3\}$). But what if you have only one set? Well, then of course you'll get one set for each element of that set, so the number of sets you get is the number of elements in the set, that is, the product of one number it the number itself. And if you start with no set to begin with? Well, the only set which has no element from another set is the empty set. That's exactly one set, and thus the product of no numbers is $1$.

-
interesting, thanks! – Bogatyr Sep 18 '12 at 19:28