1
$\begingroup$

I start with the following input:

f[n_] = Sum[(1+x)^j, {j,1,n}];
g[n_] := Sum[(1+x)^j, {j,1,n}]

When I try to evaluate the code above I get:

f[2]

$$ \dfrac{(1+x)(-1+(1+x)^2)}{x} $$

g[2]

$$ 1+x+(1+x)^2 $$

Why is this the case?

$\endgroup$
  • 1
    $\begingroup$ This is because in the definition with Set the expression is evaluated first. Mathematica can symbolically manipulate Sums even when n does not have a value. To see this, you can evaluate the expression Sum[(1 + x)^j, {j, 1, n}] when n does not have a value, and see that it evaluates to the same thing as you can see in f//Definition. $\endgroup$ – Jacob Akkerboom Nov 15 '14 at 11:28
  • 1
    $\begingroup$ Also compare f[2]//Expand and g[2]//Expand. Lastly I think the question looks quite alright :). $\endgroup$ – Jacob Akkerboom Nov 15 '14 at 11:39
  • $\begingroup$ Yeap, I got it. Thank you $\endgroup$ – Nikita Luparev Nov 15 '14 at 12:00
  • 1
    $\begingroup$ Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basic rules of the site. Your question may be put on-hold because it seems to be off-topic and a duplicate. Please don't be discouraged by that cleaning-up policy. Your questions are and will be most welcomed. Learn about good questions here. $\endgroup$ – rhermans Nov 15 '14 at 12:28

Browse other questions tagged or ask your own question.