Use _sympify instead of sympify in replace()
Use _sympify instead of sympify in replace()

This fixes some major performance issues when calling replace with non-SymPy
types such as functions or classes. This was seen in particular, in diff
(issue #15416), but likely other places are affected as well. The problem is
that sympify() as a final attempt converts the input to a string and tries to
parse it. This of course fails, but it takes a lot of time, especially since
diff can be called many times recursively. String parsing is skipped entirely
with _sympify().

The downside to this of course is that string inputs to replace() will no
longer work. However, string inputs to library functions have always been
considered an antipattern (see
https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input)
and unsupported behavior that could be removed at any time.

We might want to consider making sympify() more conservative in what sorts of
things it tries to parse as strings. Obviously a function will never parse
(the string form of a function is '<function blah at 0x11d729488>'), and
classes wouldn't unless they are doing something strange with metaclasses.
IMHO the string parsing fallback behavior of sympify shouldn't be there in the
first place, but removing it would likely be too much of a backward
incompatible change to make at this point.

More generally though, we should prefer _sympify in library code, *especially*
any code that accepts non-SymPy types such as functions.

kaushik94/sympy,kaushik94/sympy,kaushik94/sympy