2
$\begingroup$
In[1]:= Table[Product[If[j == k, 1, (n x - j)/(k - j)], {j, 0, n}] /. n -> 3, {k, 0, 3}]

Out[1]= {1/6 (1 - 3 x) (2 - 3 x) (3 - 3 x), ( 3 (1 - 3 x) (2 - 3 x) (3 - 3 x) x)/(2 - 6 x), 3/2 x (-1 + 3 x),  1/2 x (-2 + 3 x) (-1 + 3 x)}

In[2]:= Table[Product[If[j == k, 1, (3 x - j)/(k - j)], {j, 0, 3}], {k, 0, 3}]

Out[2]= {1/6 (1 - 3 x) (2 - 3 x) (3 - 3 x), 3/2 (2 - 3 x) (3 - 3 x) x, 3/2 (3 - 3 x) x (-1 + 3 x), 1/2 x (-2 + 3 x) (-1 + 3 x)}

In[3]:= FullSimplify[% - %%]

Out[3]= {0, 0, -(3/2) x (2 + 9 (-1 + x) x), 0}

As far as I can tell, these should give the same result ... so what's going on here?

$\endgroup$

1 Answer 1

3
$\begingroup$

Try this:

Table[Inactivate@Product[If[j == k, 1, (n x - j)/(k - j)], {j, 0, n}] /. n -> 3, {k, 0, 3}] // Activate

Table[Product[If[j == k, 1, (3 x - j)/(k - j)], {j, 0, 3}], {k, 0, 3}]

Check that the outputs are the same:

% === %%
(*True*)

Note the differences in the use of your replacement rule for $n$:

enter image description here

enter image description here

$\endgroup$
1
  • $\begingroup$ Interesting .. but why should the original input give a different answer? $\endgroup$
    – gmvh
    Aug 16, 2022 at 18:23

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.