3
$\begingroup$

I have a summation but I would like to put a condition like if j < q then assign 0, otherwise just perform the sum. But, I could not find how to explain this to mathematica.

Remove["Global`*"];
Needs["Developer`"];
$Assumptions = i ∈ Integers && j ∈ Integers && k ∈ Integers && q ∈ Integers;

a[j_, q_] := If[0 <= q <= j, 0];
a[j_, q_] := (2 q - 1 - j)! q!/((2 q - 1)! j! (q - j)!);

d[n_, q_] := I^n *Sum[(-1)^j*a[j, q]*a[n - j, q], {j, 0, n}];

FullSimplify[d[2 q, q]]

The output I should get is this ((q-1)! / (2q-1)!)^2 (which is easy to obtain by hand)

What mathematica gives me is very different.

$\endgroup$
  • $\begingroup$ Edit your post and add the code for the sum. $\endgroup$ – Edmund May 18 '17 at 21:59
  • $\begingroup$ try Clear[a];a[j_?NumericQ, q_?NumericQ]:=.. $\endgroup$ – george2079 May 18 '17 at 22:35
  • $\begingroup$ You may have a lingering definition of a. Evaluate ClearAll[a, d] then run your code. $\endgroup$ – Edmund May 18 '17 at 22:35
  • $\begingroup$ does q have a value? This will not work for symbolic q $\endgroup$ – george2079 May 18 '17 at 22:36
  • $\begingroup$ Thanks for the answers, I have tried to improve it a bit, but still I am not getting what I should. $\endgroup$ – NezPerce May 19 '17 at 2:14
1
$\begingroup$

The way you wrote your definitions the second definition of a[j_, q_] would overwrite the first. If you want to create cases of a function with special values you can use the Condition pattern (/;) in the LHS of the definition.

  a[j_, q_]/;0 <= q <= j := 0;
  a[j_, q_] := (2 q - 1 - j)! q!/((2 q - 1)! j! (q - j)!);

This should give the correct result.

$\endgroup$
  • $\begingroup$ I tried, it seems that the result is equal to what I need to get, but I do not understand why instead of a simple expression it gives the following, which is sort of meaningles (-1)^q \sum _{j=0}^{2 q} \frac{(-1)^j (j-1)! (q!)^2 (-j+2 q-1)!}{j! ((2 q-1)!)^2 (j-q)! (q-j)! (2 q-j)!} $\endgroup$ – NezPerce May 19 '17 at 16:33
  • $\begingroup$ @mment finally figured out, thanks $\endgroup$ – NezPerce May 21 '17 at 0:26

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.