# if statement in mathematica

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.

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

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;