In the 18th century, the Church of Scotland had a problem – widows. Whenever a married minister died, his salary was transferred to his successor. If the dead man was married, his widow and children could find themselves without either income or home. The only option for some was the poorhouse – an unedifying spectacle for a church.

Two churchmen, Dr. Robert Wallace and Alexander Webster, decided something needed to be done. They wanted to create a fund that would provide ministers’ widows with a pension. But how to design it? Rather than turning to prayer, the two sought a solution in another of their great passions – mathematics.

As Yuval Noah Harari explains in his excellent Sapiens, the two churchmen exploited the emerging field of probability and, in particular, the Law of Big Numbers. This stated, in effect, that while “it might be difficult to predict with certainty a single event … it was possible to predict with great accuracy the average outcome of many similar events”. So, while it was impossible to say how many years an individual 60-year-old minister might live, one could say how much longer the average 60-year-old man would live. All that was needed was good data.

Here the two ministers were in luck. At the end of the 17th century, the great astronomer Sir Edmund Halley – better known today as a comet spotter – had studied records for births and deaths in the German city of Breslau. From these, he produced some of the world’s first life tables, which gave precise odds for the probability that a person of a certain age would die in a certain year.

The two preachers used this data to design their fund. As Dr. Harari explains, the fund proposed a range of pension plans: For example, any minister who paid in £2.12s.2d (or about £2.61) a year would guarantee an annual pension for his widow of £10 – more than enough to keep her out of the poorhouse.

The fund was an enormous success, not just because of the peace of mind it brought to ministers’ families but also because its careful design meant it was financially sound. Wallace and Webster had predicted that 20 years after its establishment, the fund would be worth £58,348. They were wrong: In fact it was worth, £58,347 – just £1 short of their forecast.

If only things were as straightforward today. The church fund existed at a time when – outside periods of disease and war – life expectancies changed little. That’s not the case now. In a typical wealthy country today, the life expectancy of a 65-year-old is rising by nearly two months every year.

Rising life expectancies are, of course, a good thing, but they do create problems for pension funds, most notably “longevity risk” – in other words, pension funds aren’t always taking sufficient account of just how much longer people are living. That’s due in part to the fact that they may be relying on outdated data that doesn’t improvements in life expectancy. According to a new OECD report, getting these estimates wrong can be costly: “Each additional year of life expectancy not provisioned for can be expected to add around 3-5% to current liabilities.”

Rising longevity is posing other problems for pensions, according to the OECD Pensions Outlook 2014, released today. In many countries, the rising share of retirees in the population will leave more people dependent on a shrinking share of workers. This imbalance will become much more evident as growing numbers of post-war baby-boomers reach retirement age.

There are other uncertainties, too, notably what Larry Summers (pdf) calls “secular stagnation” – a drawn-out period of economic sluggishness “characterized by low returns, low interest rates, and low growth”, says the Outlook. Meeting pension commitments against that backdrop could become quite a challenge.

How are governments responding? The Outlook reports that the pace of reforms has speeded up. Priorities have included raising the retirement age and linking benefits to expected rises in longevity as well as steps to strengthen the funding of private pensions. And to respond to rising public concern over private pension providers, there’s a growing focus on how the sector is regulated. Still, there’s no doubt that much more will need to be done if today’s future pensioners are to enjoy the peace of mind of those 18th century Scottish widows.