You can do this by simply factoring the expression with keyword `deep`::

```
>>> var('a')
a 
>>> factor(sqrt(((4*a**2 + 1)/(4*a**6 - 15*a**4 + 12*a**2 + 4))), deep=True)
1/Abs(a**2 - 2) 
```
On Thursday, April 1, 2021 at 9:43:35 AM UTC-5 balle...@googlemail.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/d417c1a4-60eb-460b-ad5d-d78ad854bf2bn%40googlegroups.com.

Reply via email to