2
$\begingroup$

DigitQ behaviour appears consistent

"" is treated as 0 by DigitQ`

DigitQ[""] 
FromDigits[""]

True

0

" " is not

DigitQ[" "] 
FromDigits[" "]

False

enter image description here FromDigits[" "]

Now for LetterQ

LetterQ[""]
LetterQ[" "]

True

False

But

FullForm@FromLetterNumber[0]

" " (*a single space *)

This is to me implies that " " is a letter in contradiction with LetterQ[" "].

Furthermore from DigitQ if we infer that "" is 0 then FullForm@FromLetterNumber[0] should return "" not " ".

What do you think?

$\endgroup$
4
  • $\begingroup$ Possibly related mathematica.stackexchange.com/q/293233/60568 $\endgroup$ Jan 7 at 5:26
  • $\begingroup$ You can't really say this is a bug since it is clearly mentioned in the documentation (last bullet points under Details for FromLetterNumber and LetterNumber). It's probably implemented like this just due to convenience so that you can seamlessly convert a piece of text between its string and numeric representetation. $\endgroup$
    – Domen
    Jan 7 at 8:31
  • $\begingroup$ Perhaps the inconsistency in definitions could be considered a bug? $\endgroup$ Jan 7 at 8:36
  • 3
    $\begingroup$ The documentation for FromLetterNumber states FromLetterNumber[0] gives " ". I think it's mentioned specifically because it's an exception; and I think the exception is included by the developers because they thought it would be useful. $\endgroup$
    – Goofy
    Jan 7 at 16:59

1 Answer 1

8
$\begingroup$

"" is treated as 0 by DigitQ

No, that's not what's happening. DigitQ isn't so much asserting anything as it is following rules of logic. Are there any characters in "" that are not digits? No. Then DigitQ returns True. It's similar to this:

AllTrue[{}, EvenQ]
(* True *)

The same analysis applies to LetterQ.

The reason FromDigits[""] evaluates to 0 is because 0 is the additive identity. It's just standard practice that an empty sum/product will be the additive/multiplicative identity.

As for

This is to me implies that " " is a letter in contradiction with LetterQ[" "].

There is no reason to assume that FromLetterNumber and LetterQ are operating under the same rules and assumptions. The use of 0 and " " in the LetterNumber/FromLetterNumber situation is a useful convenience, not a logical assertion.

$\endgroup$
1
  • $\begingroup$ Thank you for your explanation. Personally, given the overall elegance of Mathematica that Letter would imply consistency between FromLetterNumber and LetterQ. $\endgroup$ Jan 8 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.