How to express a conditional in a summation I have a question about notation: What's the proper mathematical notation to write (sum from i=1 to X)(sum from j=1 to X) 1 if gcd(i,j)==2, 0 otherwise?
 A: For that Knuth uses Iverson's convention: $[\gcd(i, j) = 2]$ is 1 if the condition is true, 0 if false.
A: There is the Kronecker delta $\delta_{i,j}=0$ if $i\neq j$ 1 otherwise.
For you $\sum_{i=1}^X \sum_{j=1}^X \delta_{\gcd(i,j),2}$.
I hope it helps.
A: I might just write
$$
\sum_{\begin{smallmatrix} 1\le i\le X \\  1\le j\le X \\  \gcd(i,j)=2 \end{smallmatrix}} 1.
$$
If you need to write it as an iterated sum, you could write
$$
\sum_{1\le i\le X} \sum_{\begin{smallmatrix} 1\le j \le X \\  \gcd(i,j)=2 \end{smallmatrix}} 1.
$$
But it won't do to write
$$
\sum_{\begin{smallmatrix} 1\le i \le X \\  \gcd(i,j)=2 \end{smallmatrix}} \sum_{1\le j \le X } 1
$$
because there's not yet anything called $j$.  For example, suppose one has
$$
\sum_{i=1}^4 \sum_{j=1}^3 (i^2+j).
$$
This is
$$
\underbrace{\Big((1^2+1)+(1^2+2)+(1^2+3)\Big)}_{i=1} + \underbrace{\Big((2^2+1)+(2^2+2)+(2^2+3)\Big)}_{i=2} + \underbrace{\Big((3^2+1)+(3^2+2)+(3^2+3)\Big)}_{i=3}
$$
Within the term in which $i=2$, we find one term in which $j=2$ and two other terms. But we cannot include or exclude in its entirety the term labeled with the $\underbrace{\text{underbrace}}$ as $i=2$ on the grounds of its relationship with some other variable called $j$.
A: $$\sum_{1\le i\le X,\gcd(i,j)=2}\sum_{1\le j\le X}1$$ will do. Also, you could look up the Iverson bracket notation. 
EDIT: Sorry, make that $$\sum_{1\le i\le X}\sum_{1\le j\le X,\gcd(i,j)=2}1$$ (Thanks, Michael)
A: You could do something like this, for instance:
$$
f(X)=\sum_{1\leq i,j\leq X, (i,j)=2}^X1=1+2\sum_{1\leq i<j\leq X, (i,j)=2}^X1
$$
$$
=1+2\sum_{2\leq 2i<2j\leq X, (i,j)=1}^X1
$$
$$
=1+2\sum_{j=1}^{\lfloor X/2\rfloor}\sum_{1\leq i<j, (i,j)=1}1
$$
$$
=1+2\sum_{j=2}^{\lfloor X/2\rfloor}\phi(j)
$$
where $\phi(j)$ is Euler's totient function which counts the number of $i$ between $1$ and $j$ such that $(i,j)=1$.
This way you can get an asymptotic estimate:
$$
f(X)=\frac{3X^2}{4\pi^2}+O(X\log X).
$$
