code: def is_algebraic(p):
      """Return True if p is comprised of only Rationals or square roots
      of Rationals and algebraic operations.
  
      Examples
      ========
  
      >>> from sympy.functions.elementary.miscellaneous import sqrt
      >>> from sympy.simplify.sqrtdenest import is_algebraic
      >>> from sympy import cos
      >>> is_algebraic(sqrt(2)*(3/(sqrt(7) + sqrt(5)*sqrt(2))))
      True
      >>> is_algebraic(sqrt(2)*(3/(sqrt(7) + sqrt(5)*cos(2))))
      False
      """
  
      if p.is_Rational:
          return True
      elif p.is_Atom:
          return False
      elif is_sqrt(p) or p.is_Pow and p.exp.is_Integer:
          return is_algebraic(p.base)
      elif p.is_Add or p.is_Mul:
          return all(is_algebraic(x) for x in p.args)
      else:
          return False
  
imports: from sympy.core import Add, Expr, Mul, S, sympify
  from sympy.core.function import _mexpand, count_ops, expand_mul
  from sympy.core.sorting import default_sort_key
  from sympy.core.symbol import Dummy
  from sympy.functions import root, sign, sqrt
  from sympy.polys import Poly, PolynomialError
label_desc: Use image node_id 3 for calling a global function with example usage: is_algebraic(p) and returns: True, False, is_algebraic, all, False