Hi David,

Thank you for your answer and suggestions. It was really helpful.

10 Şubat 2020 Pazartesi 02:12:34 UTC+3 tarihinde David Bailey yazdı:
>
> On 09/02/2020 18:52, Barış Bulut wrote:
>
> x,y = symbols('x,y')
>
> y = x**3
> y.subs(x,5)
> 125
>
> x = 5
> y.subs(x,x)
> x**3
> y.subs(x,10)
> x**3
> y.subs(x,3)
> x**3
>
> x = 3
> y.subs(x,125)
> x**125
> y.subs(x,10)
> x**10
>
>
> Hi Barış,
>
> It isn't a bug!
>
> Unfortunately as soon as you execute x=5 you destroy the symbol in x, 
> replacing it by 5 .
>
> That means that y.subs(x,10)  becomes
>
> (x**3).subs(5,3)
>
> No replacements are possible, so this return x**3
>
> Then you set x to 3 so that y.subs(x,125) becomes
>
> (x**3).subs(3,125) which yields
>
> x**125
>
> etc.
>
> The correct code would be 
>
> x=symbols('x')
>
> y=x**3
>
> y.subs(x,5)
>
> y.subs(x,10)
>
> etc.
>
> Notice that y never needed to be a variable, because you never used it - y 
> got overwritten just as x did.
>
> If you want to store an expression like x**3 in a python variable, I find 
> it useful to use a longer name that wouldn't normally be used in a 
> mathematical expression. If you set up a variable as a symbol, then it is 
> best not to assign to it later until perhaps you understand what is going 
> on.
>
> Cheers,
>
> David
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/8d61683f-6413-4c5f-a3dd-dd05237679fc%40googlegroups.com.

Reply via email to