Safe driving distance Suppose you are driving in a highway and you suspect the car ahead of you might come to a sudden stop, perhaps after
hitting some very heavy vehicle improperly parked in the middle of the driving lane.  You should then try to keep a
safe distance which is defined by how much time you need to come to a complete stop before hitting the car ahead of you
in the event of such an accident.
Assuming that your current speed is $v$ (measured in  $m/s$,  that is,  meters  per second) and that
the force of your braking system is $b$ (in $m/s^2$),  you will need  at least $t:=v/b$ seconds to stop, and exactly this much time in case your
reflexes are good enough allowing you to  step on the brake the very moment the accident happens.
During that time you will
travel for
  $$
  vt - {1\over 2}bt^2 = {v^2\over 2b}
  $$
  measured in meters,
  so voilà the minimum safe distance.
This much is pretty trivial, so here is a somewhat more complicated scenario: you now have reasons to believe that the
car ahead of you will never come to a sudden stop (in fact Physical laws prevent this from happening), but you still
suspect that something might frighten its driver, causing him or her to fully step on the brake$^{(*)}$, quickly coming to a
complete stop.  
A sudden stop ruled out, the safe distance will now certainly decrease by a bit, and it will also depend on the the other car's
current speed $v'$ and braking force $b'$.  The question is then:

How to compute the new safe driving distance in terms of the
  parameters $v$, $b$, $v'$ and $b'$ (again assuming a quick braking
  reflex)?

${(*)}$ Drivers of stick-shift cars sometimes mistake the brake for the clutch and do precisely that!
 A: If both vehicles start decelerating at the same time, and are then at a distance $\ S\ $ apart, then after time $\ t\ $ they will be separated by a distance
$$
D(t)=\cases{S+(v'-v)t-\frac{(b'-b)t^2}{2}& if $0\le t\le\min(\frac{v}{b},\frac{v'}{b'})\ $,\\
S+\frac{v'^2}{2b'}-vt+\frac{bt^2}{2}& if $\ \frac{v'}{b'}<t\le\frac{v}{b}\ $.}
$$
The vehicles do not collide if $\ D(t)\ $ remains non-negative for $\ 0\le t\le\frac{v}{b}\ $, where I assume that if the vehicles just touch at the instant when the trailing vehicle stops, or, if $\ b'>b\ $, they just touch for an instant after which they then separate, then that doesn't count as a collision.
If $\ b'<b\ $ and $\ v\le v'\ $, then $\ D'(t) =(v'-v)+(b-b')t>0\ $ and $\ D(t)\ge S\ $ for $\ 0\le t\le \frac{v}{b}\ $, so the minimum safe distance in this case is $0$.
If $\ b'<b\ $, $\ v > v'\ $, but $\ \frac{v}{b}\le\frac{v'}{b'}\ $, then $\ D'(t) =(v'-v)+(b-b')t\ $, and the minimum value of $\ D(t)\ $ over the interval $\ 0\le t\le \frac{v}{b}\ $ is $\ S-\frac{(v-v')^2}{2(b-b')}\ $, occurring at $\ t=\frac{v-v'}{b-b'}\ $, so the minimum safe distance in this case is $\ \frac{(v-v')^2}{2(b-b')}\ $.
If $\ b'<b\ $, $\ v > v'\ $, but $\ \frac{v}{b}>\frac{v'}{b'}\ $, then $\ D'(t) =(v'-v)+(b-b')t\ $ for $\ 0\le t\le\frac{v'}{b'} \ $ and $\ D'(t)=bt-v\ $ for $\ \frac{v'}{b'}<t\le\frac{v}{b}\ $. Since $\ D'(t)<0\ $ over the interval $\ 0\le t\le \frac{v}{b}\ $, the minimum value of $\ D(t)\ $ over that interval is $\ S-\left(\frac{v^2}{2b}-\frac{v'^2}{2b'}\right)\ $, occurring at $\ t=\frac{v}{b}\ $, so the minimum safe distance in this case is $\ \frac{v^2}{2b}-\frac{v'^2}{2b'}\ $.
If $\ b'\ge b\ $ and $\ v>v'\ $, then again $\ D'(t)<0\ $ over the interval $\ 0\le t\le \frac{v}{b}\ $, and the minimum safe distance is $\ \frac{v^2}{2b}-\frac{v'^2}{2b'}\ $.
If $\ b'\ge b\ $, $\ v\le v'\ $ and $\ \frac{v}{b}\le\frac{v'}{b'}\ $, then the minimum of $\ D(t)\ $ is $\ S\ $, occurring at $\ t=0\ $, so the minimum safe distance in this case is $0$.
If $\ b'\ge b\ $, $\ v\le v'\ $ and $\ \frac{v}{b}>\frac{v'}{b'}\ $, then the minimum of $\ D(t)\ $ is $\ S-\left(\frac{v^2}{2b}-\frac{v'^2}{2b'}\right)\ $, occurring at $\ t=\frac{v}{b}\ $, so the minimum safe distance in this case is $\ \frac{v^2}{2b}-\frac{v'^2}{2b'}\ $.
Putting this all together, we have the minimum safe distance being
$$
\cases{0& if $\ v\le v'\ $ and either $\ b'<b\ $ or$\ \frac{v}{b}\le\frac{v'}{b'}\ $,\\
\frac{(v-v')^2}{2(b-b')}&if $\ b'<b\ $, $\ v > v'\ $, and $\ \frac{v}{b}\le\frac{v'}{b'}\ $,\\
 \frac{v^2}{2b}-\frac{v'^2}{2b'}& otherwise.}
$$
