# Is the empty string an acceptable decimal representation of 0?

In a recent question for which the correct output for 1 is zero, an answer output ; i.e, nothing. Is this an acceptable base-10 representation for zero?

• Corollary: the infinite loop, printing nothing is a valid representation for 0.
– nimi
Feb 12, 2016 at 22:15
• @nimi Except programs need to terminate unless specified otherwise. Feb 14, 2016 at 13:37

# No, besides exceptions.

The challenge linked obviously requires the output to be a number for valid inputs.

The empty string is not a number. The fact that empty strings evaluate to 0 in some languages doesn't justify its use as the number 0. Otherwise I could argue that "a" is valid to represent 97 in outputs because it's the corresponding ASCII code.

The only case I can think of where outputting "" for 0 is OK is when your output is in unary.

• While I don't necessarily disagree with your conclusion, saying that the empty string is not a number is simply false. Bijective numerations do not have a zero symbol, and an empty string is the only way to represent the number zero. Feb 12, 2016 at 22:25
• That's why I said that there can be exceptions, if there are no more natural ways of writing 0. In standard base 10 that's definately not the case. Feb 12, 2016 at 22:28
• About the 97 part... link Feb 14, 2016 at 3:51
• @Sp3000 Due to that policy (which I agree with), I only halfway agree with this answer. a is a valid representation of 97, so 0x00 (the null byte) would be an acceptable representation of 0. A null byte is not the same as an empty string, so an empty string would not be acceptable (unary notwithstanding).
– user45941
Feb 15, 2016 at 0:41

# Yes

The mathematical definition of a base-10 representation is:

Where an...a1a0 is the base-10 representation. The value of the empty string is well-defined as the empty sum, 0.

The empty string can be considered a more consistent representation than 0, since it follows the convention that numbers have no leading zeroes.

• The empty string is not a legitimate representation of 0. The number with no digits is a legitimate representation of 0 (This is actually how 0 was historically written(i.e. not written)). The empty string is a string that contains the empty number but is not itself a number. You can't input the empty string into your formula since it is composed of delimiters that are not digits. Finally, everyone has agreed for hundreds of years now that 0 is a more convenient representation than the number with no digits. Feb 12, 2016 at 22:20
• I don't follow. How is the empty string different from the number with no digits? Feb 12, 2016 at 22:21
• It's different just as "[]" is different from []. The string that contains the empty list is not itself a list. Similarly, a string that contains a number with no digits is not itself a number. Feb 12, 2016 at 22:24
• Don't we allow programs that output the number 3.14 to output the string "3.14"? This doesn't seem different. Feb 12, 2016 at 22:27
• It doesn't matter that you manipulate a string as long as the output is formatted as a number, namely 3.14 and not "3.14". If you language prints 0 when you ask it to print the empty string then it's perfectly fine, since the final output is a number. But if it outputs "" when you ask to print "" then your output is not a number. Feb 12, 2016 at 22:30
• You said earlier that the number with no digits is a number. How is "" (without quotes) not a number, but "3.14" a number? Feb 12, 2016 at 22:35
• "" without quotes, as you say, is a number, namely the number with no digits, which has now been for hundreds of years written 0. But "" without quotes is not "", which is the empty string. Therefore an output of nothing (and not an output of "") would be valid as the number 0, but I guess wouldn't be valid overall because then it's debatable that you would have outputed anything. Feb 12, 2016 at 22:56
• I don't feel like people are on the same page with all of the "" "" "0" and "0". Which quotes are included in the output? For example, would System.out.print("") qualify, since there aren't any quotes in the output? Feb 12, 2016 at 23:10
• To add to PhiNotPi: what about returning the empty string from a function, which is considered output, too.
– nimi
Feb 12, 2016 at 23:46
• @nimi That doesn't apply here; we allow programs to print the string 3.14 for a number, because there's no way to print an integer. I don't think we allow functions to return the string 3.14 for the number 3.14. Feb 12, 2016 at 23:48
• @ThomasKwa: it does apply. Functions may output via return value. If the empty string is a valid representation for 0, then I'm allowed to return it from a function.
– nimi
Feb 12, 2016 at 23:58
• @PhiNotPi Yes, just like System.out.print("3.14"). Feb 13, 2016 at 1:46

## Yes.

In both the mathematical base conversion algorithm:

def frombase(array,base):
ret = 0
for digit in array:
ret = ret * base + digit
return ret


and in many languages interpretation (e.g., [int]""), the empty string evaluates to zero.

Thus, for a challenge requesting decimal output, an empty string is acceptable to output for zero.

• I would say that it should only count in languages where that is the case, personally. If your language does something different or throws an error, then it shouldn't be allowed. This would be in line with our general position on truthy/falsey: It needs to work as a conditional in the chosen language. Feb 12, 2016 at 18:06
• @Geobits I was going to suggest the same thing, until I realized that it would not determine the validity of this particular answer. Jelly has no way to cast to int. (That's a problem with the truthy/falsy definiton as well. What if the language doesn't have conditionals?) Feb 12, 2016 at 18:10
• I have mixed feelings. I'd like to say "no", but the empty string is the only way to output zero for unary output, which is allowed... Feb 12, 2016 at 19:07
• Here I see "" as an expression which evaluates to zero, which seems invalid for the same reason that any other expression is, like outputting "1-1", when a number was required. May 27, 2016 at 1:29