But a disease need not be eradicated completely to ease the pressure on public-health budgets. For all but mild afflictions vaccinating large portions of a population is cheaper than letting an illness linger. That is because an endemic disease imposes a cost on society, directly in treating the sick, and indirectly through lost productivity.

The reason is that if the vaccination rate exceeds a certain critical level (higher for more infectious diseases) everyone, including the unvaccinated, enjoys what epidemiologists call herd immunity. In such a situation, a scourge is stopped in its tracks because an infected individual is much more likely to bump into a vaccinated fellow citizen than an unprotected one. He therefore recovers, gaining natural immunity, or dies, effectively removing himself from the equation, without having passed the disease on.

However, as people become more mobile, achieving herd immunity in any given country gets trickier. For example, young children are routinely vaccinated for chickenpox in America, but not in Britain. Of the 5.5m Britons to travel across the pond each year, many will be susceptible to the disease and some will be infected. This will change the equation for America's health department, which should compensate by increasing the vaccination rate so that it exceeds the critical level for a population encompassing both protected Americans and unprotected visitors.

Petra Klepac, from Princeton University, and her colleagues wanted to know more precisely how such intermingling affects the economic benefits of vaccination. She presented her findings to the meeting of the American Mathematical Society and the Mathematical Association of America, held earlier this month in Boston.

Dr Klepac began with a well-established epidemiological tool called the susceptible-infected-removed (SIR) model. It is used to predict the increase in infections based on the average number of people a single sick individual infects, known as the disease's basic reproduction number, and the proportion of the population susceptible to it. A population's susceptibility in turn depends on how many vulnerable children are born and how many already susceptible citizens either die or become infected.

Next, the researchers assumed that that vaccination costs rise exponentially with vaccination rate, since once the initial queues of eager participants outside surgeries subside it becomes progressively more difficult for the health authorities to track down the remaining unvaccinated folk. The total social cost of infection, by contrast, was estimated to increase in direct proportion to the number of infections.

Combining this with the SIR model allowed Dr Klepac to calculate the vaccination rate for which the total cost to society—a mix of vaccination costs and infection costs—is lowest. This confirmed that striving for herd immunity makes economic sense for an isolated country. (To her surprise, though, she discovered that the optimal vaccination rate depends mostly on the relative costs of vaccination and infection, and not at all on the disease's basic reproduction number, as had been assumed.)

Finally, travellers were thrown in. Dr Klepac found that a small flow of unprotected immigrants can reduce the optimal vaccination rate for the host country markedly, especially for diseases whose infection costs are not too onerous. This happens because a trickle of such immigration is enough to scotch the host population's herd immunity. At the same time, the compensatory vaccinations needed to reinstate it are extremely pricey since they need to be administered to some of the few remaining unprotected individuals. As a consequence, the economic balance shifts towards tolerating a number of infections. Where immigration is considerable and infections costly, though, the added burden of the additional infection would outweigh the cost of ramping up the vaccination rate.

Another upshot is that the two intermingling neighbours are often best off pooling their resources. Often, it seems, the optimal vaccination-infection trade-off for each country separately, which takes into consideration the other's own optimal strategy, is not the best solution for the two of them taken together. In such a Nash equilibrium, named after John Forbes Nash, the mathematician who first probed it, acting in concert can often yield a superior outcome for both parties.

Most strikingly, when one country lacks the means to achieve herd immunity at home it might actually benefit by spending a small protion of its healthcare budget to help out a neighbour that is on the brink of success rather than pursuing a domestic vaccination that would fall short of the target. That would minimise the number of infected visitors, saving money in the long run. The idea may be counterintuitive, but makes perfect mathematical sense. Good luck selling it to national health authorities, though.