{'fraction_non_alphanumeric': 0.035103785103785104, 'fraction_numerical': 0.005738705738705739, 'mean_word_length': 4.041859033548784, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Note on Walking Versus Waiting

This mathematical recreation extends the analysis of a recent paper, asking when a traveller at a bus stop and not knowing the time of the next bus is best advised to wait or to start walking toward the destination. A detailed analysis and solution is provided for a very general class of probability distributions of bus arrival time, and the solution characterised in terms of a function analogous to the hazard rate in reliability theory. The note also considers the question of intermediate stops. It is found that the optimal strategy is not always the laziest, even when headways are not excessively long. For the common special case where one knows the (uniform) headway but not the exact timetable, it is shown that one should wait if the headway is less than the walking time (less bus travel time), and walk if the headway is more than twice this much. In between it may be better to wait or to walk, depending on one's confidence in being able to catch up to a passing bus.

To what extent is a traveller (called Justin, say) better off to wait for a bus rather than just start walking-particularly when the bus headway is of a similar order of magnitude to the walking time and Justin does not know the precise arrival time of the bus? The recent analysis by Chen et al [1] goes some way toward answering this question; however, there are additional valuable insights that can be gained from their approach.
In essence this is a decision-theoretic problem, where the aim is to compare various strategies for getting to one's destination. Following Chen et al [1], it is supposed that the comparison hinges solely on the expectation of overall travel time, and there is no additional penalty attached to walking. We may list some of the available strategies as follows: • Strategy A: Wait indefinitely until a bus arrives.
• Strategy B: Begin walking immediately and do not wait for a bus.
• Strategy C: Wait for a predetermined time interval T W , and if no bus has arrived in this time then walk.
(Naturally, strategies A and B can themselves be thought of as the extreme limiting cases of strategy C as T W → ∞ and T W → 0 respectively. However, we distinguish them for the sake of discussion.) Following the nomenclature of [1], let d denote the journey distance, v w Justin's average walking speed and v b the average speed of a bus. The overall travel time is a random variable and will be denoted T t .
As indicated in [1], if the decision is purely between strategies A and B, the problem has an easy, one might say trivial, solution: if the expected arrival time for the bus is T minutes in the future, Justin should wait if T ≤ d/v w − d/v b and walk otherwise. The more interesting questions are (a) could there exist values T W for which strategy C is superior to either A or B; and (b) does the presence of intermediate stops affect the conclusion? The purpose of this note is to show, by direct analysis for (almost) arbitrary arrival probabilities, that the answer to (a) is indeed no in most practical cases, but that the answer to (b) is not quite as clear-cut as the authors in [1] argue.

The Case of No Intermediate Stops
The following expression is provided in [1] for Justin's expected travel time under strategy C, where p(t) is the density function for the probability a bus arrives t minutes from now: In [1], this expression is used to determine the waiting time T W such that E[T t ] is equal to the time d/v w required under strategy B. However, it is also of interest to optimise (1) directly. The derivative of (1) with respect to T W is The first term in parentheses is the complementary c.d.f. of the arrival time for the bus; that is, the probability that the bus has not arrived by time T W . Denote this function by R(t): Also for brevity, define T δ as the difference between the travel time on foot and the travel time by bus: Then the derivative (2) may be expressed as Zeros of (5) occur at points where In reliability theory where one is concerned with failure-time distributions, the function λ(t) = p(t)/R(t) is known as the hazard rate: the density for the probability of failure given a component has not failed up to time t [2]. But λ(t) also has a natural interpretation for arrival times, where it may be termed the appearance rate for the distribution p(t).
By definition λ(t) is nonnegative, but depending on the underlying distribution it may behave in a variety of ways: it may increase, decrease, attain local maxima or minima, or be constant. More precisely, for any T ∈ R + ∪ {∞} any nonnegative real measurable function on (0, T ) can be the appearance rate for a possible arrival time distribution p(t); if T is finite then take p(t) = R(t) = 0 for t ≥ T . An increasing λ(t) is characteristic of many waiting scenarios; it represents the case where the conditional probability increases with time spent waiting. By contrast, a constant λ(t) characterises the exponential arrival time distribution, where time spent waiting does not affect the conditional likelihood of a bus arriving.
Equation (6) indicates that E[T t ] as a function of T W is stationary at any point where the appearance rate λ(T W ) equals the reciprocal of T δ . To determine whether this is a minimum or a maximum, one calculates the second derivative (assuming for simplicity that p(t) is dfferentiable) and inspects the sign of this quantity. Since p(t) and T δ are both positive (and p(T W ) is nonzero by (6)) this is equivalent to the sign of Accordingly, any stationary point of E[T t ] is a minimum when it coincides with a falling appearance rate, and a maximum when it coincides with a rising appearance rate. It is thus established that, when faced with a typical probability distribution for bus arrivals having a rising appearance rate, the optimal strategy reduces to a choice between strategies A and B, and hence to a straightforward comparision of expected arrival time with T δ as indicated above.
For example, if it is known that buses run punctually every T minutes but one does not know the actual arrival times, the uncertainty in arrival time can be modelled as a uniform probability density p(t) between 0 and T , with mean T /2. The corresponding appearance rate is an increasing function of t. One may then distinguish three cases: 1. If T < T δ , the expected travel time E[T t ] has no stationary points, and is in fact a decreasing function of wait time. In this case strategy A is optimal: one should wait for the next bus.
2. If T δ < T < 2T δ , the expected travel time has one stationary point at T * W = T − T δ , which is a maximum. The expected travel time increases with waiting time up to T * W and then decreases. But since the mean bus arrival time is T /2 < T δ , the waiting strategy A is still preferable to an initial decision to walk.
3. If T > 2T δ , then expected travel time again reaches a maximum at T * W = T − T δ . But now, it is better to follow strategy B and not wait for a bus at all.
Perhaps the most interesting situation here is the marginal case where T = 2T δ : the interval between buses is twice the difference between walking time and bus travel time. In this case it is equally good (or bad) to wait as to walk, but having decided to wait, one should not give up and walk, as this will result in a worse outcome (averaged over all eventualities).
Not all practically realisable probability distributions have rising appearance rates for all t. Consider, for example, the situation where Justin has arrived at the bus stop one minute after the (known) scheduled arrival time for the bus, but knows that buses sometimes run up to five minutes late. Under reasonable assumptions this leads to a falling λ(t) for the first four minutes, and if p(0) is sufficiently large and the service relatively infrequent, this will result in an optimal time T * W for which Justin should remain at the bus stop and then start walking. However, if the next bus can be counted on to arrive in a time comparable to T δ , it will still be advantageous to keep waiting for the next bus, and the lazy mathematician still wins.
One may also contemplate the special case where λ(t) ≡ λ is constant, and bus arrivals are a Poisson process. The mean time between arrivals is T = 1/λ; if this is greater than T δ then it is better to walk, and if less then it is better to wait, as is intuitively clear. More interesting is the case where T happens to just equal T δ : then, the derivative (5) vanishes and the expected travel time is equal to the walking time d/v w , regardless of the time spent waiting. What this means is, no matter how long Justin decides in advance to wait, over a large number of journeys he can expect to spend no more or less time than if he had decided to walk at the outset. Nonetheless, Poisson arrivals are generally an unrealistic assumption except in some cases of very frequent service, where it is generally better to catch the bus in any event.

Intermediate Stops
In [1] it is argued that the conclusion is unchanged when Justin has the additional option of walking to an intermediate stop and catching the bus there. If, for example, one re-evaluates the decision between strategies A and B at a distance d 1 from the start of the journey, then the walking time is (d − d 1 )/v w and the bus travel time is (d − d 1 )/v b . However, the expected waiting time for the bus (assuming it does not pass by en route) is now reduced by T 1 = d 1 /v w − d 1 /v b , the time that passes while walking less the additional time taken by the bus to reach the next stop. The terms involving d 1 cancel, and one is left with a decision identical to the original one. Under these circumstances, one would "rather save energy" and act as though the intermediate stop did not exist, since the outcome is the same. This conclusion is also intuitively evident.
The authors argue that the same reasoning applies to walk-and-wait strategies analogous to strategy C, at least when the wait time T W at the next stop is chosen to make the expected travel time equal to the walking time. However, there appears to be a circularity involved here-if the expected travel time is fixed as d/v w a priori, then naturally it will be observed to be the same whether or not Justin walks to another stop. Again, some more insight into the problem is gained by seeking stationary points of E[T t ] with respect to the free variables.
Suppose strategy C is modified so that one walks a distance d 1 to another stop, then waits for a maximum time T W . One may now distinguish two cases, depending on whether or not a bus passes by en route. Denote this event by M ('miss the bus') and its non-occurrence byM ; the relevant probabilities are If no bus passes by en route, then the expected travel time is similar to (1), but with a time offset: (Note that within the integral, τ is the time at which the caught bus reaches the starting point, rather than Justin's current position, since p(τ ) is the p.d.f. of bus arrivals at a fixed point on the route. This is a subtle point and easily overlooked. In terms of τ , Justin's overall travel time if he catches the bus is τ plus the time taken by the bus to cover the entire journey, regardless of where Justin is when he catches it.) The overall expected travel time is where E[T t |M ] and E[T t |M ] are given by (12) and (11) respectively. Again, one can differentiate to find optimal values of wait time T W at the more distant stop. (This is made easier by noting that E[T t |M ] does not vary with T W .) One finds that and where is the difference between travel time on foot and by bus starting from the more distant stop. These are exactly equivalent to (5) and (7), with T W +T 1 in place of T W and T δ1 in place of T δ . Accordingly, the analysis of the previous section is essentially unchanged, as is the conclusion: that in most waiting scenarios the optimal value of T W is either zero or arbitrarily large. But now there is an additional variable in the problem, because Justin will generally have a number of stops to choose from between the starting point and the destination. For the sake of simplicity, suppose the stop spacing is small enough that d 1 can be regarded as a continuous variable. Then we can try and optimise with respect to d 1 , obtaining after a little work where q = 1/v w − 1/v b is a constant. The above discussion suggests directing attention to the cases T W = 0 and T W → ∞. If T W = 0, then (17) vanishes unless P C > 0; that is, when there is a nonzero chance of catching a bus while walking to the next stop. Assuming then that P C > 0 and T W = 0, (17) is found to be zero when p(T 1 ) = 0 and negative when p(T 1 ) > 0. (Recall that T 1 is proportional to d 1 .) The result is intuitively evident: as long as there is a chance of catching a bus on the way (however small), walking a distance d 1 to an intermediate stop always reduces the expected travel time E[T t ] relative to strategy B, where one does not attempt to catch a bus. The actual reduction can be quantified by integrating (17) with respect to d 1 . Due to the factor (d − d 1 ) in (17), the marginal reduction in travel time is greatest at the start of the journey, all other things being equal. Now consider the case T W → ∞. One may presume that there is a limit to the time one must wait for a bus, so that p(T 1 + T W ) becomes zero for T W sufficiently large. It is also fair to assume that P C < 1. Then it follows that for T W sufficiently large, (17) is zero when p(T 1 ) = 0, but is positive when p(T 1 ) > 0. It follows that walking to an intermediate stop only to wait indefinitely at that stop yields a worse expected outcome than waiting at the starting point, consistent with common sense. Again, (17) can be used to judge how much one is worse off due to the chance of missing the bus on the way.
The more interesting case to consider, of course, is a direct comparison between strategy A (waiting indefinitely at the starting point) and a strategy of walking but trying to catch a bus on the way. From above, the best possible strategy of the latter variety is the case T W = 0 and d 1 = d: a little manipulation of (13) yields the result Under strategy A, of course, the expected travel time is just the bus travel time, plus the expected arrival time for the bus: The difference in expected travel time is then If this quantity is positive, it represents the expected time saving if one walks instead of waiting. (It will be seen that all terms are in fact nonnegative apart from the last one, T δ ; which, however, is relatively large.) For example, let p(t) be the uniform distribution based on a bus headway T . The mean arrival time is T /2 and hence E A [ and this improves on As T /T δ increases from 1 to 2, the minimum probability P C decreases from 1 to zero; recall that when T /T δ > 2 strategy A is worse than strategy B, which is equivalent to the above strategy with and the condition for this to improve on E A [T t ] reduces to P C > 1, a contradiction. Accordingly, strategy A is still the best choice for uniform arrival probabilities with headway T < T δ .

Conclusion
Closer analysis of the model and results in [1] for a traveller at a bus stop confirms that the lazy mathematician does indeed win in many cases. The exact criteria for when it is better to walk can be formulated in terms of an appearance rate function, and if one disregards the existence of intermediate stops, an arrival probability with a rising appearance rate is sufficient to make waiting the best strategy. It has also been shown, however, that allowing for the possibility of catching the bus at an intermediate stop can restore the walking strategy to optimality. In the end, the decision whether to walk or wait is not always clear-cut, and relies on one's expectations of being able to catch a bus on the run, as well as of a bus turning up in the first place.
In the particular case where one knows the (uniform) headway but not the exact timetable, it has been clearly established that one should wait if the headway is less than the walking time (less bus travel time), and should walk if the headway is more than twice this much. This leaves a substantial window where it may be better to wait or to walk, depending on one's confidence in being able to catch up to a passing bus.