# How to write a covariance

Could somebody kindly explain how you can express something as a covariance?

A paper I am reading contains this term:

$$\sum_in_i(p_i-p)(b_a+\sum_t\sum_jr^t\frac {n_j} {n_i}b_c)$$

The author then says that the term "can be expressed using a covariance" as follows:

$$N\mathbb C[p_i,(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c)]$$

N is the sum of all n and $p$ is the average of all $p_i$.

It's a fascinating paper, but I've hit a block based on my neophyte maths. Please could somebody put me out of my misery and explain how such a covariance can be found?

Would love to hear an explanation so I'll be able to understand in the future!

Covariance of two random variables $X$ and $Y$ is defined as:
$$\mathbb C[X,Y] = E_{x,y}[XY] - E_x[X]E_y[Y]$$
where $E_x[X]$ represents the expected value of r.v $X$.
$E[p_i]=p$
\begin{align}N\mathbb C[p_i,(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c)] & =NE_i[p_i(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c)]\\ & -NE_i[p_i]E_i[b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c] \\ &= N\sum_i\Big(p_i(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c)\times\frac{n_i}{N}\Big)\\ &-N\times p\times \sum_i\Big(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c \Big)\times \frac{n_i}{N}\\ &= \sum_i n_ip_i(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c)-\sum_i n_ip(b_a+\sum_tr^t\sum_j\frac {n_j} {n_i} b_c) \end{align}