Subs behavior

61 views
Skip to first unread message

Paul Royik

unread,
Dec 9, 2014, 7:22:00 AM12/9/14
to sy...@googlegroups.com
from sympy import *
a = symbols('a',positive=True)
(1/(sec(a)**2-1)**(3/2)).subs(sec(a)**2-1,tan(a)**2)

last statement should output something close to 1/tan^3(a), or abs(tan(a))/tan^4(a)

But instead it outputs something unrelated: abs(tan(a))/tan^2(a)

Is this a bug or I'm missing something?

Chris Smith

unread,
Dec 9, 2014, 11:59:24 AM12/9/14
to sy...@googlegroups.com
gotcha: 3/2 -> 0. Use S(3)/2 instead or Rational(3, 2)

Paul Royik

unread,
Dec 9, 2014, 1:20:08 PM12/9/14
to sy...@googlegroups.com
This is just an example.
In my program this is done as
expr = (sec(a)**2-1)**3
expr = 1/sympy.sqrt(expr)

In general, I have more complicated expressions, so don't know when to substitute.

Aaron Meurer

unread,
Dec 9, 2014, 10:13:21 PM12/9/14
to sy...@googlegroups.com
This might be a bug.

Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/081c2561-cb00-4092-800a-c2fa10cf06b1%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Dec 11, 2014, 10:44:21 PM12/11/14
to sy...@googlegroups.com
Does this explain what you are seeing?

>>> var('a')
a
>>> expr = 1/sqrt((sec(a)**2-1)**3);expr
1/sqrt((sec(a)**2 - 1)**3)
>>> expr.subs(sec(a)**2 - 1, tan(a)**2)
1/sqrt(tan(a)**6)
>>> var('a', positive=True)
a
>>> (1/sqrt((sec(a)**2-1)**3)).subs(sec(a)**2 - 1, tan(a)**2)
Abs(tan(a))/tan(a)**4

Paul Royik

unread,
Dec 13, 2014, 5:16:18 AM12/13/14
to sy...@googlegroups.com
live.sympy.org gives Abs(tan(a))/tan(a)**2

Aaron Meurer

unread,
Dec 14, 2014, 4:59:49 AM12/14/14
to sy...@googlegroups.com
It looks like this works in master now (it gives
Abs(tan(x))/tan(x)**4). I bisected it to

commit 8b7642466e756f55bcbe7f6e8c108908f576e743
Author: zanzibar7 <tcr-p...@psu.edu>
Date: Sat Nov 1 19:28:56 2014 -0400

fixes Abs(x)**-3 bug

This was the pull request https://github.com/sympy/sympy/pull/8359.

Aaron Meurer

On Sat, Dec 13, 2014 at 4:16 AM, Paul Royik <distan...@gmail.com> wrote:
> live.sympy.org gives Abs(tan(a))/tan(a)**2
>
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/ded21455-a36a-40eb-952e-4f164a2d9372%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages