Nonlinear Least Squares Optimization Calculus