**Setup.** Suppose we are given a function $ $ f:\mathbb N\to\{\text{False},\text{True}\}$ $ such that $ $ f(n)=\text{True}\implies f(n+1)=\text{True}$ $ and such that $ f(n)=\text{True}$ for some $ n$ large enough.

**In natural language.** The function $ f$ imposes a condition on the natural numbers which is fulfilled once $ n$ is large enough.

**My question.** How can I, for any given $ f$ , find the smallest $ n$ such that $ f(n)=\text{True}$ ?

A first idea would be to start with $ n=1$ and to increment $ n$ by one until $ f(n)$ is True. However, this is fairly slow. So I designed a sort of “binary search” for this task. How can I translate this to Mathematica?

Here is the Code in Python:

`def bin_search(cond): n = 1 while not cond(n): n *= 2 lower_bound = n//2 upper_bound = n middle = (lower_bound + upper_bound)//2 while upper_bound - lower_bound > 1: if cond(middle): upper_bound = middle else: lower_bound = middle middle = (lower_bound + upper_bound)//2 return upper_bound `

For example, one such condition would be $ $ f(n)=[H_n\geq 10],$ $

where $ $ H_n=\sum_{i=1}^n \frac 1i$ $ is the $ n$ th harmonic number.