3
$\begingroup$

I have tried FromDigits[{{1, 2, 3, 4},{2,3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}] and the result is as expected {1234,2341,3412,4123}. However for FromDigits[{{2,8},{8,2}}] the result is {28000000, 28}, and not the expected {28,82}. I wonder why this is the case?

$\endgroup$
2
  • 1
    $\begingroup$ Perhaps you can gain some insight by studying the result of {#, # /. x -> 10} &@FromDigits[{{2, 8}, {8, 2}}, x]. $\endgroup$ Commented Jun 6, 2020 at 3:23
  • $\begingroup$ Thanks for your suggestion. Let me see. $\endgroup$
    – Tapioka
    Commented Jun 6, 2020 at 3:31

1 Answer 1

6
$\begingroup$

The documentation mentions (in a bullet point in "Details")

FromDigits[{list,n},b] takes n to be an exponent [...]

I think what's happening here is that it's taking {8,2} to be a list of exponents. Indeed, it turns out that FromDigits[{{2,8},{n,m}},b] gives

{b^(-2 + n) (8 + 2 b), b^(-2 + m) (8 + 2 b)}

which is somewhat surprising!

I guess if your list has more than two elements, it can't match the pattern {listofdigits, listofexponents} (e.g. {{__Integer},{__Integer}}), which is probably checked first. It's a bit frustrating that it's length-dependent like that, though; I guess it's safer to use something like FromDigits /@ listoflistsofdigits.

$\endgroup$
2
  • 1
    $\begingroup$ Right, it's an edge case in the syntax specification, where on interpretation is used when another may have been expected. $\endgroup$ Commented Jun 6, 2020 at 20:10
  • 1
    $\begingroup$ @thorimur: Thank you very much, your method works! $\endgroup$
    – Tapioka
    Commented Jun 7, 2020 at 9:14

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.