Characterizing Polynomial Time Computability of Rational and Real Functions