factor(deep=True) is supposed to do this. However, for whatever
reason, it isn't applying to the subexpression.
You can do it manually using the bottom_up function, however (and also
as ric noted, you need to set x as positive). That is a more efficient
way than calling use() several times.
>>> x = symbols('x', positive=True)
>>> expr = 16*x**3/(-x**2 + sqrt(8*x**2 + (x**2 - 2)**2) + 2)**2 -
>>> 2*2**(S(4)/5)*x*(-x**2 + sqrt(8*x**2 + (x**2 - 2)**2) + 2)**(S(3)/5) + 10*x
>>> bottom_up(expr, factor)
x*(x**2 + 2)
Aaron Meurer
On Tue, Dec 18, 2018 at 10:04 AM [email protected] <[email protected]> wrote:
>
> The problem is to force sympy simplyfing sqrt(x**4+4*x**2+4).
>
> positive=True and factor at the good level work. The problem is that in my
> knowledge in sympy there is no built-in "apply a function f at all levels",
> so I used a loop over the levels from a high-enough on (5). I'd like to know
> if there are more elegant ways to proceed...
>
> >>> x=Symbol("x",positive=True)
> >>> expr = 16*x**3/(-x**2 + sqrt(8*x**2 + (x**2 - 2)**2) + 2)**2 -
> >>> 2*2**(S(4)/5
> ... )*x*(-x**2 + sqrt(8*x**2 + (x**2 - 2)**2) + 2)**(S(3)/5) + 10*x
> >>> e=expr
> >>> for i in range(5,-1,-1): e=use(e,factor,i)
> >>> e
> x*(x**2 + 2)
>
> ric
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/930faa65-da6f-fe8f-db17-ab433bbd4632%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BfyoLxHJkJ58ymuMpKS7UbJmogMywHo%3DUaN4S%2BNNtfmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.