Reaching population equilibrium

In "The Wright-Fisher model of genetic drift1", we introduced the Wright-Fisher model of genetic drift. Although the effects of genetic drift are inevitable, we should be able to quantify how many alleles for a given trait will remain in the next generation.

Intuitively, because Wright-Fisher demands that we randomly and independently select alleles for the next generation based off the allele frequency of the present generation, we would hope that on average this frequency would illustrate a stabilizing effect: that is, the expected frequency in the next generation should equal the allele frequency in the current generation. In this problem, we will see if the mathematics matches our intuition.

Assignment

In "The Wright-Fisher model of genetic drift2" we generalized the concept of a binomial random variable $$\textrm{Bin}(n, p)$$ as a "weighted coin flip". It is only natural to calculate the expected value of such a random variable.

For example, in the case of unweighted coin flips (i.e., $$p = \frac{1}{2}$$), our intuition would indicate that $$E(\textrm{Bin}(n, \frac{1}{2}))$$ is $$\frac{n}{2}$$. What should be the expected value of a binomial random variable?

Write a function expectedValue that takes a positive integer $$n \in \mathbb{N}$$ and a floating point number $$p \in \mathbb{R}$$ ($$0 \leq p \leq 1$$) representing a probability corresponding to an allele frequency. The function must return the expected value of $$\textrm{Bin}(n, p)$$. In terms of Wright-Fisher, it represents the expected allele frequency of the next generation.

Example

>>> expectedValue(17, 0.1)
1.7
>>> expectedValue(17, 0.2)
3.4
>>> expectedValue(17, 0.3)
5.1