On Sunday, June 21, 2020 at 3:25:53 AM UTC-4, Aaron Meurer wrote: > > On Sat, Jun 20, 2020 at 8:27 PM Audrius-St <[email protected] > <javascript:>> wrote: > > > > Hello, > > > > A question regarding simplify() > > > > For example, simplify() followed by factor() successfully reduces the > rather long expression in (x, px, y, py) > > > > (24*px**3*x**4*sqrt(x**2 + y**2) - 72*px**3*x**2*y**2*sqrt(x**2 + y**2) > + 9*px**3*y**4*sqrt(x**2 + y**2) + > > 180*px**2*py*x**3*y*sqrt(x**2 + y**2) - 135*px**2*py*x*y**3*sqrt(x**2 + > y**2) - 36*px*py**2*x**4*sqrt(x**2 + y**2) + > > 243*px*py**2*x**2*y**2*sqrt(x**2 + y**2) - 36*px*py**2*y**4*sqrt(x**2 + > y**2) + 22*px*x**4 + 14*px*x**2*y**2 - 8*px*y**4 - > > 45*py**3*x**3*y*sqrt(x**2 + y**2) + 60*py**3*x*y**3*sqrt(x**2 + y**2) + > 30*py*x**3*y + 30*py*x*y**3)/(x**2 + y**2)**5 > > > > to the desired simpler form > > > > (24*px**3*x**4 - 72*px**3*x**2*y**2 + 9*px**3*y**4 + 180*px**2*py*x**3*y > - 135*px**2*py*x*y**3 - 36*px*py**2*x**4 + > > 243*px*py**2*x**2*y**2 - 36*px*py**2*y**4 + 22*px*x**2*sqrt(x**2 + y**2) > - 8*px*y**2*sqrt(x**2 + y**2) - 45*py**3*x**3*y + > > 60*py**3*x*y**3 + 30*py*x*y*sqrt(x**2 + y**2))/(x**2 + y**2)**(9/2) > > > > However, simplify() is, understandably, time consuming. > > Also, I would like to follow the the advice in introductory blurb in the > simplify() documentation regarding "robustness". > > > > My questions: > > > > 1. Is it possible to determine which algorithms simplify() chooses to > use? >
> The only way is to look at the source code, or run it through a debugger. > Understood. > > > > 2. I've reviewed the sympy documentation, but have not been able to > identify other simplification algorithms that would apply. > > This is probably due to my lack of familiarity with this aspect of > sympy. Any suggestions would be appreciated. > > I got your desired result with factor(expand(collect(expr, sqrt(x**2 + > y**2)), deep=False)). The collect() pulls the square roots into a > single square root term, and the expand(deep=False) expands the > top-level fraction so that the square root can combine with the > denominator. The factor() then puts it into a single fraction form. > Thank you for your explanations and code - a significant improvement in performance. > > 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 [email protected] <javascript:>. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/f8376c85-8e49-4570-9bd0-e1363bc87cc5o%40googlegroups.com. > > > On Sunday, June 21, 2020 at 3:25:53 AM UTC-4, Aaron Meurer wrote: > > On Sat, Jun 20, 2020 at 8:27 PM Audrius-St <[email protected] > <javascript:>> wrote: > > > > Hello, > > > > A question regarding simplify() > > > > For example, simplify() followed by factor() successfully reduces the > rather long expression in (x, px, y, py) > > > > (24*px**3*x**4*sqrt(x**2 + y**2) - 72*px**3*x**2*y**2*sqrt(x**2 + y**2) > + 9*px**3*y**4*sqrt(x**2 + y**2) + > > 180*px**2*py*x**3*y*sqrt(x**2 + y**2) - 135*px**2*py*x*y**3*sqrt(x**2 + > y**2) - 36*px*py**2*x**4*sqrt(x**2 + y**2) + > > 243*px*py**2*x**2*y**2*sqrt(x**2 + y**2) - 36*px*py**2*y**4*sqrt(x**2 + > y**2) + 22*px*x**4 + 14*px*x**2*y**2 - 8*px*y**4 - > > 45*py**3*x**3*y*sqrt(x**2 + y**2) + 60*py**3*x*y**3*sqrt(x**2 + y**2) + > 30*py*x**3*y + 30*py*x*y**3)/(x**2 + y**2)**5 > > > > to the desired simpler form > > > > (24*px**3*x**4 - 72*px**3*x**2*y**2 + 9*px**3*y**4 + 180*px**2*py*x**3*y > - 135*px**2*py*x*y**3 - 36*px*py**2*x**4 + > > 243*px*py**2*x**2*y**2 - 36*px*py**2*y**4 + 22*px*x**2*sqrt(x**2 + y**2) > - 8*px*y**2*sqrt(x**2 + y**2) - 45*py**3*x**3*y + > > 60*py**3*x*y**3 + 30*py*x*y*sqrt(x**2 + y**2))/(x**2 + y**2)**(9/2) > > > > However, simplify() is, understandably, time consuming. > > Also, I would like to follow the the advice in introductory blurb in the > simplify() documentation regarding "robustness". > > > > My questions: > > > > 1. Is it possible to determine which algorithms simplify() chooses to > use? > > The only way is to look at the source code, or run it through a debugger. > > > > > 2. I've reviewed the sympy documentation, but have not been able to > identify other simplification algorithms that would apply. > > This is probably due to my lack of familiarity with this aspect of > sympy. Any suggestions would be appreciated. > > I got your desired result with factor(expand(collect(expr, sqrt(x**2 + > y**2)), deep=False)). The collect() pulls the square roots into a > single square root term, and the expand(deep=False) expands the > top-level fraction so that the square root can combine with the > denominator. The factor() then puts it into a single fraction form. > > 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 [email protected] <javascript:>. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/f8376c85-8e49-4570-9bd0-e1363bc87cc5o%40googlegroups.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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/db9949ac-96fc-4102-a422-68aa8010add1o%40googlegroups.com.
