Complete to the Whole

A farmer wants to divide his 17 horses among his three sons. According to farmer the oldest son should get half of the horses,the middle son should get one third of the horses and the youngest son should get one ninth of the horses.
When their father died they were not able to divide the horses as the result was coming in fractions. As the sons were fighting on how to divide the horses a traveling mathematician came and heard their problem. He proposed a solution with which all the sons got their share in the property without harming any animal.

What was the advice given and how the group of horses were divided?