def sympy_obj_from_dist(dist, _recursive=False):
  """ Attempts to return the object class instance for sympy distribution.
  :example:
  >>> import sympy
  >>> import sympy.stats
  >>> import probayes as pb
  >>> x = sympy.Symbol('x')
  >>> p_x = sympy.stats.Normal(x, mean=0, std=1.)
  >>> p_x_obj = pb.sympy_obj_from_dist(p_x)
  >>> print(p_x_obj.pdf)
  0.5*sqrt(2)*exp(-0.5*x**2)/sqrt(pi)
  """
  obj = dist
  if hasattr(obj, '_cdf'):
    return obj
  if not hasattr(obj, 'args'):
    if not _recursive:
      raise ValueError('Unsupported distribution: {}'.format(dist))
    return None
  objs = [sympy_obj_from_dist(arg, True) for arg in obj.args]
  if any(objs):
    for obj in objs:
      if obj:
        return obj
  if not _recursive:
    raise ValueError('Unsupported distribution: {}'.format(dist))
  return None