def golden_section_search(fn, a, b, tolerance=1e-5):
    """
    WIKIPEDIA IMPLEMENTATION
    golden section search
    to find the minimum of f on [a,b]
    f: a strictly unimodal function on [a,b]

    example:
    >>> f=lambda x:(x-2)**2
    >>> x=gss(f,1,5)
    >>> x
    2.000009644875678
    """
    c = b - GOLDEN*(b-a)
    d = a + GOLDEN*(b-a)
    while abs(c-d) > tolerance:
        fc, fd = fn(c), fn(d)
        if fc < fd:
            b = d
            d = c  #fd=fc;fc=f(c)
            c = b - GOLDEN*(b-a)
        else:
            a = c
            c = d  #fc=fd;fd=f(d)
            d = a + GOLDEN*(b-a)
    return (b+a)/2