This seems like a bug, but without full steps to reproduce it, there's
not much we can do. If the srepr() output is the same, it should work
the same. If you are able to reproduce this consistently, that would
be helpful.  Typically this sort of thing is caused by a being
actually a different symbol with different assumptions, but based on
the srepr output, it should be the same. It seems like some odd
situation where something got messed up in the internal SymPy state,
and my guess is this will not be easy to reproduce (i.e., you won't
see it again).

Aaron Meurer

On Wed, Apr 7, 2021 at 3:28 AM 'Bruce Allen' via sympy
<sympy@googlegroups.com> wrote:
>
> I have a very basic sympy question, which has me stumped, and am hoping
> that someone here can set me straight. I have an expression for which
> subs() seems to have no effect:
>
>  >>> a=Symbol('a', real=True, positive=True)
>
>  >>> q=u[7]
>
>  >>> q
> -a*(45*a**18 - 120*a**16 + 240*a**12 - 504*a**8 + 1440*a**4 - 2700*a**2
> - 4645)/4050
>
>  >>> q.subs(a, Rational(1,2))
> -a*(45*a**18 - 120*a**16 + 240*a**12 - 504*a**8 + 1440*a**4 - 2700*a**2
> - 4645)/4050
>
>  >>> srepr(q)
> "Mul(Integer(-1), Rational(1, 4050), Symbol('a', real=True,
> positive=True), Add(Mul(Integer(45), Pow(Symbol('a', real=True,
> positive=True), Integer(18))), Mul(Integer(-1), Integer(120),
> Pow(Symbol('a', real=True, positive=True), Integer(16))),
> Mul(Integer(240), Pow(Symbol('a', real=True, positive=True),
> Integer(12))), Mul(Integer(-1), Integer(504), Pow(Symbol('a', real=True,
> positive=True), Integer(8))), Mul(Integer(1440), Pow(Symbol('a',
> real=True, positive=True), Integer(4))), Mul(Integer(-1), Integer(2700),
> Pow(Symbol('a', real=True, positive=True), Integer(2))), Integer(-4645)))"
>
> But if I just cut and paste the same expression into the variable, then
> subs() works as expected:
>
>  >>> q=-a*(45*a**18 - 120*a**16 + 240*a**12 - 504*a**8 + 1440*a**4 -
> 2700*a**2 - 4645)/4050
>
>  >>> q.subs(a, Rational(1,2))
> 1371514291/2123366400
>
> The internal representation is identical:
>
>  >>> srepr(q)
> "Mul(Integer(-1), Rational(1, 4050), Symbol('a', real=True,
> positive=True), Add(Mul(Integer(45), Pow(Symbol('a', real=True,
> positive=True), Integer(18))), Mul(Integer(-1), Integer(120),
> Pow(Symbol('a', real=True, positive=True), Integer(16))),
> Mul(Integer(240), Pow(Symbol('a', real=True, positive=True),
> Integer(12))), Mul(Integer(-1), Integer(504), Pow(Symbol('a', real=True,
> positive=True), Integer(8))), Mul(Integer(1440), Pow(Symbol('a',
> real=True, positive=True), Integer(4))), Mul(Integer(-1), Integer(2700),
> Pow(Symbol('a', real=True, positive=True), Integer(2))), Integer(-4645)))"
>
> Why does subs() work in one case, and not in the other?
>
> Cheers,
>         Bruce
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/4b8b8ea4-bd9f-d155-41f9-80fcbd2d5a38%40googlemail.com.

-- 
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 sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6K75%3D2YL2UZG45691gGWnES412n-um_JASTxpLo_LOiuA%40mail.gmail.com.

Reply via email to