Mathematics of Least Squares