If you are solving univariate expressions you don't need to pass the symbol:
>>> solve(S('x**2 -1'))
[-1, 1]
On Saturday, February 15, 2020 at 3:47:01 AM UTC-6, ludi wrote:
>
> On Saturday, 15 February 2020 00:55:20 UTC+1, Aaron Meurer wrote:
>>
>> ...
>> The best recommendation is in general
On Saturday, 15 February 2020 00:55:20 UTC+1, Aaron Meurer wrote:
>
> ...
> The best recommendation is in general to avoid sympify, unless you are
> processing arbitrary strings
>
Thanks for the reply, but as I am processing user-input I think there is no
way around sympify.
--
You
sympify() works independently of what you already have defined. So for
instance,
x = 1
print(sympify('x')) # prints x
This produce Symbol('x'), not 1. If you want it to use what you
already have defined, you can pass locals() as the second argument to
sympify()
x = 1
print(sympify('x',
Thanks a lot
I read about locals and individual dictionaries, but I didn't realize that
it would affect "already defined" Symbols.
It is a little bit confusing that 'a' and 'a' can be not the same thing.
But now everything works as expected, thanks again.
--
You received this message because
Hi,
sympify('a') will return a symbol with no assumptions, which is different
from a as defined. You can amend this by passing a dictionary with intended
translations:
>>> from sympy import sympify, Symbol
>>> a = Symbol('a', real=True)
>>> sympify('a') == a
False
>>> sympify('a', {'a': a}) == a