I have the following worksheet below.

enter image description here

(I took a screen shot because I didn't know how to type the code for the particular function). Circled in red are powers that shouldn't be there and yet they show up. They seems to be raising the part in parentheses to the particular $k$ value defined by $p[n,k]$. Can anyone tell me why this is the case?

Edit: Here is the copied and pasted code. Note that I actually corrected my formula by simply raising the parentheses expression to the $1/k$ power, but I'm still confused as to why it's being raised to the $k$ in the first place.

-Product[(n + i)^(Floor[k/i] - 1)*(p[n, 0] + 
          Sum[(Product[n + k + 1 - i, {i, 1, j}]/
                 Product[(n + i)^Floor[j/i], {i, 1, j}])*p[n, j], 
            {j, 1, k - 1}]), {i, 1, k}]

closed as off-topic by ybeltukov, Mr.Wizard Jan 17 '15 at 2:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – ybeltukov, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Please copy and paste the code from the Notebook; it will look like a mess but it should be usable anyway. I'll try to improve the formatting from there. $\endgroup$ – Mr.Wizard Jan 17 '15 at 0:03
  • $\begingroup$ Okay. Give me a minute. $\endgroup$ – Eleven-Eleven Jan 17 '15 at 0:03
  • $\begingroup$ The code you edited. Is this the fixed version? $\endgroup$ – Eleven-Eleven Jan 17 '15 at 0:17
  • 1
    $\begingroup$ You use index $i$ two times: one in the outer product and one in the inner product. The inner one shades the effect of the outer one. $\endgroup$ – ybeltukov Jan 17 '15 at 0:31
  • 1
    $\begingroup$ Oh, I think I understand. You do not want nested products. Just put the first product in parentheses! :-) $\endgroup$ – ybeltukov Jan 17 '15 at 0:34

Looking again at the image I realize you are using a strange construct:

p[n, 0] = p[n_, 0] := 1
p[n, 0] = p[n_, 1] := -1
p[n, k] = p[n_, k_] := (* body *)

I strongly suspect that this is not what you want. Instead I believe you are attempting to set up memoization, in which case I believe you need to change these to:

p[n_, 0] = 1;
p[n_, 1] = -1;
p[n_, k_] := p[n, k] = (*body*)

However this change does not affect the behavior that is the subject of your post. That behavior seems to be unrelated to the recursive use of p entirely:

With[{n = x, k = 3},
 -Product[(n + i)^(Floor[k/i] - 1)*(+ 
           Sum[(Product[n + k + 1 - i, {i, 1, j}]/
                 Product[(n + i)^Floor[j/i], {i, 1, j}]), 
             {j, 1, k - 1}]), {i, 1, k}]

$-(x+1)^2 \left(\frac{x+3}{x+1}+\frac{x+3}{(x+1)^2}\right)^3$

Do you believe this output is incorrect, and if so, why?

  • $\begingroup$ p[n,1]=-1, not 1. Also, I think I need to use Simplify to condense the polynomial. If it helps, I calculated all of these by hand and confirmed what I need so I know that P[n,2]=1, and p[n,3]=n-1. $\endgroup$ – Eleven-Eleven Jan 17 '15 at 0:23
  • $\begingroup$ The second parentheses should not be raised to the 3rd power. It shouldn't be raised to any power. $\endgroup$ – Eleven-Eleven Jan 17 '15 at 0:25
  • $\begingroup$ @Eleven Sorry, my mistake. I'll correct that, but I don't think it changes the second part of my answer. $\endgroup$ – Mr.Wizard Jan 17 '15 at 0:25
  • $\begingroup$ @Eleven Please consider the example where I removed the p[_, _] terms entirely; do you believe it is incorrect, and if so, how/why? $\endgroup$ – Mr.Wizard Jan 17 '15 at 0:26
  • $\begingroup$ I cut and paste it into a new notebook and ran it and it is not correct. that power still shows up $\endgroup$ – Eleven-Eleven Jan 17 '15 at 0:30

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