d = (average speed) (time)
time = d / (average speed)
So if your average speed is 40 (mph), your total time is d/40.
You have already travelled half the distance at speed 20 (mph), so that took time (d/2)/20 = d/40. Your time left to complete the trip is your total time minus the time spent so far: d/40 - d/40 = 0. In this time you have to travel the remaining distance d/2, so you have travel at a speed (d/2)/0 = infinity, which means it is impossible to actually do.
Suppose the total trip is a distance d.
So if your average speed is 40 (mph), your total time is d/40.
You have already travelled half the distance at speed 20 (mph), so that took time (d/2)/20 = d/40. Your time left to complete the trip is your total time minus the time spent so far: d/40 - d/40 = 0. In this time you have to travel the remaining distance d/2, so you have travel at a speed (d/2)/0 = infinity, which means it is impossible to actually do.