import math


def wavy(ind, k=10.):
    """Wavy function defined as:
    $$ f(x) = 1 - \frac{1}{n} \sum_{i=1}^{n} \cos(kx_i)e^{-\frac{x_i^2}{2}}$$
    with a search domain of $-\pi < x_i < \pi, 1 \leq i \leq n$.
    """
    return 1. - sum(( math.cos(k * ind[i]) * math.exp(-(ind[i]*ind[i])/2.) for i in range(len(ind)))) / float(len(ind)),