optimization of incomplete gamma and beta function