Level 1 Guarantees when you only know the mean
A model solves a request in a random time T >= 0. All you know is E[T] = mean. You may restart: give up on an attempt when it hits its timeout and start a fresh, independent attempt. The request succeeds if some attempt finishes within its timeout (an attempt with timeout t succeeds iff its T <= t). Restarting costs nothing.
Return exact fractions.Fraction values. Inputs are ints or Fractions.
markov_tail_bound(mean, a): the best upper bound onP(T > a)that holds for every nonnegativeTwith that mean:min(1, mean / a), or1whena <= 0.worst_case_example(mean, a, eps): show the bound is essentially tight. Return a distribution as a dict{value: probability}with exactly two values,0anda + eps, with mean exactlymeanandP(T > a) = mean / (a + eps). You may assume0 < mean <= aandeps > 0.restart_guarantee(mean, timeouts): the success probability guaranteed by applying the Markov bound to each independent attempt, when you run one attempt per timeout intimeouts. (For unequal timeouts no single distribution need hit every bound at once, so this is a valid lower bound on the true worst case rather than exactly equal to it.)best_equal_split(mean, budget): split a total timebudgetintom >= 1equal timeoutsbudget / m. Return(m, guarantee)for themwith the largest guarantee, taking the smallestmon ties. When nothing positive can be guaranteed, return(1, 0).
markov_tail_bound(1, 5) # 1/5
restart_guarantee(1, [5, 5]) # 24/25
best_equal_split(1, 10) # (4, 609/625): four tries of 2.5 minutes beat two of 5
Be ready to explain roughly where the best m lies as a function of budget / mean, and why unequal timeouts can't raise this guarantee.
Show hint
For the explanation: maximise (budget / (m · mean))^m over real m, and compare a product of per-attempt bounds with fixed sum of timeouts using AM-GM.