It has long been said that there is an art to making the perfect cup of coffee.
But scientists at the University of Limerick have now established that maths plays a role too.
An analysis of what is being described as a "hideously complicated" set of variables has discovered that the size of a coffee grain is among the most important when it comes to brewing the ideal cup.
The study used a combination of maths and experiments, and was carried out by the Mathematics Applications Consortium for Science and Industry (MACSI) at University of Limerick.
It discovered that other factors come into play when making great coffee, including the shape of the filter, the flow rate of water and what type of machine or tool is used.
It is expected that the data, published in SIAM Journal on Applied Mathematics, will be of great interest to industrial manufacturers of filter coffee machines.
The next step will involve the researchers developing a complete theory of coffee brewing that might inform the design of such machines.
"There are about 2,000 chemicals in coffee, making it as complex as wine," said Dr William Lee, who now leads the industrial mathematics group at the University of Portsmouth.
"By using mathematical analysis, we can begin to tell the story of which elements and in what order lead to the best coffee - we are now one step closer to the perfect cup of coffee."
"One of the many challenges that have to be overcome to develop such a theory is to understand the effect the grind size has on the extraction of coffee."
"Our model shows that this can be understood in terms of the grind size controlling the balance between rapid extraction of coffee from the surface of grains and slow extraction from the interior of coffee grains."
"This not only explains qualitatively why grind size plays such an important role in determining the taste of coffee but also quantifies that relationship through formulas. These formulas could allow fine tuning the design of a coffee machine for a particular grind size."