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$
4
  • 3
    $\begingroup$ FromDigits[] is in fact a documented way for producing polynomials that are in Horner form. $\endgroup$ Commented Aug 1, 2017 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$ Commented Aug 1, 2017 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$ Commented Aug 1, 2017 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$ Commented Aug 1, 2017 at 15:21

1 Answer 1

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$
2
  • $\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$ Commented Aug 1, 2017 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$ Commented Aug 1, 2017 at 11:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.