<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _find_log_index(f):
 """Look up the index of the frequency f in the frequency table. Return the nearest index. """

    global _last_asked, _log_cache
    (begin, end) = (0, 128)

    # Most calls are sequential, this keeps track of the last value asked for so
    # that we need to search much, much less.
    if _last_asked is not None:
        (lastn, lastval) = _last_asked
        if f >= lastval:
            if f <= _log_cache[lastn]:
                _last_asked = (lastn, f)
                return lastn
            elif f <= _log_cache[lastn + 1]:
                _last_asked = (lastn + 1, f)
                return lastn + 1
            begin = lastn

    # Do some range checking
    if f > _log_cache[127] or f <= 0:
        return 128

    # Binary search related algorithm to find the index
    while begin != end:
        n = (begin + end) // 2
        c = _log_cache[n]
        cp = _log_cache[n - 1] if n != 0 else 0
        if cp < f <= c:
            _last_asked = (n, f)
            return n
        if f < c:
            end = n
        else:
            begin = n
    _last_asked = (begin, f)
    return begin