1
$\begingroup$

The code

testseq = {0, 0, 4, -3, 2, 5, 11};
testfunction1[x_] := FromDigits[Reverse[testseq], x];
Print[testfunction1[x]];
testfunction2[x_] := Dot[testseq, Power[x, Range[Length[testseq]] - 1]];
Print[testfunction2[x]];

gives me

(4 - 3x)x^2 + x^4(2 + 5x + 11x^2)

4x^2 - 3x^3 + 2x^4 + 5x^5 + 11x^6

The first result is surprising, the second as expected. Why do I get the first result?

$\endgroup$
  • 3
    $\begingroup$ FromDigits[] is in fact a documented way for producing polynomials that are in Horner form. $\endgroup$ – J. M. will be back soon Aug 1 '17 at 7:47
  • $\begingroup$ Thank you, J.M. that seems a potentially very useful feature. May I ask where is it documented ? Also wouldn't Horner's form according to mathworld be (((((11x+5)x+2)x-3)x+4)x^3 ? $\endgroup$ – Simon Aug 1 '17 at 8:05
  • 1
    $\begingroup$ Programming hint: Save yourself some typing. f[x] gives the same result as Print[f[x]];. See this answer for further useful info. $\endgroup$ – m_goldberg Aug 1 '17 at 12:58
  • $\begingroup$ Thank you m_goldberg, that is a useful hint and an interesting read. I have got into the habit of using ; as a delimiter because it seems to be necessary within a Module. $\endgroup$ – Simon Aug 1 '17 at 15:21
1
$\begingroup$

You need Apart or Expand

list = {0, 0, 4, -3, 2, 5, 11};

FromDigits[Reverse[list], x] // Apart

4 x^2 - 3 x^3 + 2 x^4 + 5 x^5 + 11 x^6

Why?

Probably because FromDigits Simplify's automatically (the factored form is considererd to be the simpler one)

$\endgroup$
  • $\begingroup$ Thank you eldo. However, when I apply Simplify to 4 x^2 - 3 x^3 + 2 x^4 + 5 x^5 + 11 x^6 it just takes out the factor of x^2. $\endgroup$ – Simon Aug 1 '17 at 10:54
  • $\begingroup$ Yes, the behaviour of Simplify is complex, but you can control it to a certain degree (see Doc and many QAs here) $\endgroup$ – eldo Aug 1 '17 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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