def _ternary_search_domain(f, domain):
    """Trinary search: minimize f(x) over a domain (sequence).

    Works assuming f is quasiconvex and domain is ascending sorted.

    BUGGY, DO NOT USE

    >>> arr = np.concatenate([np.arange(10, 2, -1), np.arange(2, 20)])
    >>> t1 = _ternary_search_domain(lambda t: arr[t], range(len(arr)))
    >>> t2 = np.argmin(arr)

    >>> assert t1 == t2
    >>> assert arr[t1] == arr[t2]
    """
    left = 0
    right = len(domain) - 1
    changed = True
    while changed and left != right:
        changed = False
        left_third = (2 * left + right) // 3
        right_third = (left + 2 * right) // 3
        if f(domain[left_third]) < f(domain[right_third]):
            right = right_third - 1
            changed = True
        else:
            left = left_third + 1
            changed = True
    return domain[(left + right) // 2]
