Who did the math, the slug?
There’s no major math involved. Proportional control is achieved through trial and error (much like a child would learn to control his or her arms through practice) to use the light-sensitive spots to locomote the body towards the direction of increasing light intensity gradient.
If math, as in digital logic, was involved in natural systems, your arms would have the accuracy, speed and repeatability of a CNC robot. You obviously don’t, however.