An Automatic Method for Finding the Greatest or Least Value of a Function