import math


def GrieFunc(vardim, x, bound):
    """
    Griewangk function
    wiki: https://en.wikipedia.org/wiki/Griewank_function
    """
    s1 = 0.
    s2 = 1.
    for i in range(1, vardim + 1):
        s1 = s1 + x[i - 1] ** 2
        s2 = s2 * math.cos(x[i - 1] / math.sqrt(i))
    y = (1. / 4000.) * s1 - s2 + 1
    y = 1. / (1. + y)
    return y