On Thu, Apr 1, 2021 at 1:25 PM Aaron Meurer <asmeu...@gmail.com> wrote: > > powsimp() would normally be the function to do this. > > However, it currently can't work if a is defined as real because > sqrt() splits apart automatically > > >>> var('a', real=True) > a > >>> sqrt((4*a**2 + 1)*(1/(4*a**6 - 15*a**4 + 12*a**2 + 4))) > sqrt(4*a**2 + 1)*sqrt(1/(4*a**6 - 15*a**4 + 12*a**2 + 4)) > > I think we should remove this automatic evaluation from sqrt(). If we > did, then simply calling powsimp() on your expression would do what > you want.
I believe this is the corresponding issue for this https://github.com/sympy/sympy/issues/7376 Aaron Meurer > > Aaron Meurer > > On Thu, Apr 1, 2021 at 8:43 AM 'B A' via sympy <sympy@googlegroups.com> wrote: > > > > What is described above has worked well for me. But there is a further > > simplification step that I need help with. > > > > I have some long expressions containing terms contain terms which look like > > this example: > > sqrt(4*a**2 + 1)*sqrt(1/(4*a**6 - 15*a**4 + 12*a**2 + 4)) > > How can I instruct sympy to combine such square roots and factor the > > arguments? In this example that would lead to: > > > > sqrt(factor((4*a**2 + 1)/(4*a**6 - 15*a**4 + 12*a**2 + 4))) > > = > > 1/Abs(a**2 - 2) > > > > On Wednesday, March 31, 2021 at 9:03:08 AM UTC+2 B A wrote: > >> > >> Dear Chris, > >> > >> On 31.03.21 05:48, Chris Smith wrote: > >> > Oscar posted code at issue https://github.com/sympy/sympy/issues/19164 > >> > for a interva-based Newton solver. > >> > >> Thank you, that's very useful. I didn't know about interval arithmetic. > >> > >> I just implemented the following, which works very well and helps to > >> increase my confidence that problems will be caught: > >> > >> d_abs={} > >> d_problems={} > >> > >> def MyAbs(x): > >> # check if this argument is already in dictionary > >> if x in d_abs: > >> return d_abs[x] > >> # see if there are any roots nearby > >> soln_list = nsolve_interval(x, 0.563, 0.583) > >> # nearby roots provide a warning message and get saved > >> if len(soln_list) > 0: > >> print('WARNING: ambiguous case found, argument of Abs() is', x) > >> d_problems[x]=soln_list > >> # Check sign, determine correct output > >> x1 = x.evalf(subs={a:0.573}) > >> if x1 < 0.0: > >> out = -x > >> else: > >> out = x > >> # save into dictionary and return > >> d_abs[x] = out > >> return out > >> > >> 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/44ef5b14-ea0a-45ca-a978-3b09f1cf82ddn%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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6KTAJS6pBXtXbxM_g3vOx9%2B7FW2ve5TPrdTzWWCwvCcRg%40mail.gmail.com.