Doctest cleanup

This PR fixes Issue 1947 and the bug mentioned in https://groups.google.com/forum/?fromgroups=#!topic/sympy/8dC1XJAIvQg