3785: fix multiplicity handling and log of Rationals

https://code.google.com/p/sympy/issues/detail?id=3785