# Conditional summation in mathematica

How to write following conditional sum?

$$F(\theta1,\theta2)=\sum_{m1,m2} a^*_{m1}a_{m2} A_{m2,m1}(\theta1) \exp[i(m1-m2)\theta2]$$, where $$A_{m2,m1}(\theta1)$$ is a conditional function, such that

$$A_{m2,m1}(\theta1)=\sqrt{\frac{\Gamma(m2+k)\Gamma(m2-k+1)}{\Gamma(m1+k)\Gamma(m1-k+1)}}\frac{1}{\Gamma(m2-m1+1)} {}_2 F_1\left(\begin{matrix}k-m1& &k+m2& \\&m2-m1+1& \end{matrix};f(\theta1)^2\right)$$ for $$m2\ge m1$$

and

$$A_{m1,m2}(\theta1)=(-1)^{(m2-m1)}A_{m2,m1}(\theta1)$$ for $$m2.

• Look up Sum[] and Piecewise[]. Commented Dec 18, 2021 at 8:06
• Your expression does not depend on $\theta_2$: is there a mistake in the formula for $F(\theta_1,\theta_2)$? Commented Dec 18, 2021 at 8:49
• C is a protected symbol that you cannot use as a variable name. Better to use lowercase letters for variables. Commented Dec 18, 2021 at 8:49
• it is correted now.
– Mike
Commented Dec 18, 2021 at 9:03
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Commented Dec 18, 2021 at 10:31

You can define a multiple dispatch for the function A:

A[{m2_, m1_} /; m2 >= m1, θ1_] = b[{m2, m1}, θ1];
A[{m2_, m1_} /; m2 < m1, θ1_] = c[{m2, m1}, θ1];


With the given hypergeometric functions:

A[{m2_, m1_} /; m2 >= m1, θ1_] =
Hypergeometric2F1[k - m1, k + m2, m2 - m1 + 1, f[θ1]];
A[{m2_, m1_} /; m2 < m1, θ1_] =
(-1)^(m2 - m1) Hypergeometric2F1[k - m2, k + m1, m1 - m2 + 1, f[θ1]];


and then sum them up to a given maximum $$m$$:

F[θ1_, θ2_] = With[{M = 3},
Sum[Conjugate[a[m1]] a[m2] A[{m2, m1}, θ1] Exp[I (m1 - m2) θ2], {m1, -M, M}, {m2, -M, M}]]

• Can you please elaborate it more? For $m2>=m1$ the conditional function is $A_ {m2,m1}(\theta1)=2F^1(k-m1,k+m2,m2-m1+1,f(\theta1))$, with k is a fixed integer (k>=1/2) and $2F^1()$ is a Hypergeometric function. For $m2<m1$, $A(\theta1)=(-1)^ {(m2-m1) }2F^1(k-m2,k+m1,m1-m2+1,f(\theta1))$.
– Mike
Commented Dec 19, 2021 at 7:29