opened
matthewwardrop
username_0
Hi all,

Not sure if this is intended behaviour, but running the following differs in output between Sympy 1.0 and Sympy master:

```
import sympy

e = sympy.S("x+y")
e.subs({'y': '2*x-1'}).free_symbols
```

On 1.0, it outputs: `{x}`.

On master, it outputs `{2*x-1, x}`, treating the string as an atomic entity (rather than interpreting it).

I like the former behaviour in general, and am wondering if this is a regression.
`subs` method of expressions no longer interprets strings
issue
created
bjodah
username_1
Don't know if that is intended or not, let's see when that happened: using find_regr.py:
```
#!/usr/bin/env python3
from sympy import S, Symbol; assert S("x+y").subs({'y': '2*x-1'}).free_symbols == {Symbol("x")}
```
and running:
```
$ git bisect start master sympy-1.0
$ git bisect run find_regr.py
...
72e29984132bfe920ac5d1d2ab260ea44282e136 is the first bad commit
commit 72e29984132bfe920ac5d1d2ab260ea44282e136
Author: chaitanya sai alaparthi <achaitanyasai@gmail.com>
Date:   Wed Feb 3 17:09:58 2016 +0530

    Simplification of simple finite sets

:040000 040000 e0d30cfc04784409849eeaeab8445c04b2530559 362f6472b681c787b28380353df8238647d5aee0 M	sympy
bisect run success
```
72e2998 is part of #10638 so pinging @smichr to see what he thinks.
comment
created
matthewwardrop
username_0
Thanks @username_1
comment
created
asmeurer
username_2
Automatic string sympfication should not be relied on, and it could be removed from any function at any point. With that said, it definitely shouldn't be creating a Symbol from a string.
comment
created
matthewwardrop
username_0
@username_2 That's a pity. String substitution is extremely convenient, but understood. Thanks for looking into it!
comment
created
asmeurer
username_2
You can always convert a string into an expression with `sympify` (`S`) first.
comment
created
matthewwardrop
username_0
I know... but particularly for interactive work on the command line, I find it handy to remove as much boilerplate and nested braces/brackets/parentheses as possible. In this instance, I suppose you could reduce it to three extra characters `S(...)`, so it's not terrible. For my edification, though, can you describe some circumstances where you would not want automatic Sympification? Is it a performance concern? Or in the interests of reducing boilerplate code sympy package-side?
comment
created
asmeurer
username_2
For interactive work, you should use things like `init_session()` or `var` to define symbols, and only work with expressions. It's much less typing if you never type a quote character. 

[This page](https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input) lists some reasons why using strings is an antipattern.
comment
created
matthewwardrop
username_0
Okay. Thanks for explaining!
comment
created
oscarbenjamin
username_3
On master now I get:
```julia
In [5]: import sympy 
   ...:  
   ...: e = sympy.S("x+y") 
   ...: e.subs({'y': '2*x-1'}).free_symbols                                                                                                                   
Out[5]: {x}
```
So it seems like this is now fixed...
comment
closed
asmeurer
username_2
issue
created
asmeurer
username_2
I think this was fixed by https://github.com/sympy/sympy/pull/15371
comment
created
matthewwardrop
username_0
Fantastic. Thanks for following this up. Will close the issue now.
comment