def _sqrt_symbolic_denest(a, b, r):
 (a, b, r) = map(sympify, (a, b, r))
 rval = _sqrt_match(r)
 if (not rval):
  return None
 (ra, rb, rr) = rval
 if rb:
  y = Dummy('y', positive=True)
  try:
   newa = Poly(a.subs(sqrt(rr), (((y ** 2) - ra) / rb)), y)
  except PolynomialError:
   return None
  if (newa.degree() == 2):
   (ca, cb, cc) = newa.all_coeffs()
   cb += b
   if _mexpand(((cb ** 2) - ((4 * ca) * cc))).equals(0):
    z = sqrt((ca * ((sqrt(r) + (cb / (2 * ca))) ** 2)))
    if z.is_number:
     z = _mexpand(Mul._from_args(z.as_content_primitive()))
    return z

def _sqrt_symbolic_denest ( a , b , r ) : ( a , b , r ) = map ( sympify , ( a , b , r ) ) rval = _sqrt_match ( r ) if ( not rval ) : return None ( ra , rb , rr ) = rval if rb : y = Dummy ( 'y' , positive = True ) try : newa = Poly ( a . subs ( sqrt ( rr ) , ( ( ( y ** 2 ) - ra ) / rb ) ) , y ) except PolynomialError : return None if ( newa . degree ( ) == 2 ) : ( ca , cb , cc ) = newa . all_coeffs ( ) cb += b if _mexpand ( ( ( cb ** 2 ) - ( ( 4 * ca ) * cc ) ) ) . equals ( 0 ) : z = sqrt ( ( ca * ( ( sqrt ( r ) + ( cb / ( 2 * ca ) ) ) ** 2 ) ) ) if z . is_number : z = _mexpand ( Mul . _from_args ( z . as_content_primitive ( ) ) ) return z
given an expression .