code: def nsimplify(
      expr,
      constants=(),
      tolerance=None,
      full=False,
      rational=None,
      rational_conversion="base10",
  ):
      """
      Find a simple representation for a number or, if there are free symbols or
      if ``rational=True``, then replace Floats with their Rational equivalents. If
      no change is made and rational is not False then Floats will at least be
      converted to Rationals.
  
      Explanation
      ===========
  
      For numerical expressions, a simple formula that numerically matches the
      given numerical expression is sought (and the input should be possible
      to evalf to a precision of at least 30 digits).
  
      Optionally, a list of (rationally independent) constants to
      include in the formula may be given.
  
      A lower tolerance may be set to find less exact matches. If no tolerance
      is given then the least precise value will set the tolerance (e.g. Floats
      default to 15 digits of precision, so would be tolerance=10**-15).
  
      With ``full=True``, a more extensive search is performed
      (this is useful to find simpler numbers when the tolerance
      is set low).
  
      When converting to rational, if rational_conversion='base10' (the default), then
      convert floats to rationals using their base-10 (string) representation.
      When rational_conversion='exact' it uses the exact, base-2 representation.
  
      Examples
      ========
  
      >>> from sympy import nsimplify, sqrt, GoldenRatio, exp, I, pi
      >>> nsimplify(4/(1+sqrt(5)), [GoldenRatio])
      -2 + 2*GoldenRatio
      >>> nsimplify((1/(exp(3*pi*I/5)+1)))
      1/2 - I*sqrt(sqrt(5)/10 + 1/4)
      >>> nsimplify(I**I, [pi])
      exp(-pi/2)
      >>> nsimplify(pi, tolerance=0.01)
      22/7
  
      >>> nsimplify(0.333333333333333, rational=True, rational_conversion='exact')
      6004799503160655/18014398509481984
      >>> nsimplify(0.333333333333333, rational=True)
      1/3
  
      See Also
      ========
  
      sympy.core.function.nfloat
  
      """
      try:
          return sympify(as_int(expr))
      except (TypeError, ValueError):
          pass
      expr = sympify(expr).xreplace(
          {
              Float("inf"): S.Infinity,
              Float("-inf"): S.NegativeInfinity,
          }
      )
      if expr is S.Infinity or expr is S.NegativeInfinity:
          return expr
      if rational or expr.free_symbols:
          return _real_to_rational(expr, tolerance, rational_conversion)
  
      # SymPy's default tolerance for Rationals is 15; other numbers may have
      # lower tolerances set, so use them to pick the largest tolerance if None
      # was given
      if tolerance is None:
          tolerance = 10 ** -min(
              [15]
              + [
                  mpmath.libmp.libmpf.prec_to_dps(n._prec)
                  for n in expr.atoms(Float)
              ]
          )
      # XXX should prec be set independent of tolerance or should it be computed
      # from tolerance?
      prec = 30
      bprec = int(prec * 3.33)
  
      constants_dict = {}
      for constant in constants:
          constant = sympify(constant)
          v = constant.evalf(prec)
          if not v.is_Float:
              raise ValueError("constants must be real-valued")
          constants_dict[str(constant)] = v._to_mpmath(bprec)
  
      exprval = expr.evalf(prec, chop=True)
      re, im = exprval.as_real_imag()
  
      # safety check to make sure that this evaluated to a number
      if not (re.is_Number and im.is_Number):
          return expr
  
      def nsimplify_real(x):
          orig = mpmath.mp.dps
          xv = x._to_mpmath(bprec)
          try:
              # We'll be happy with low precision if a simple fraction
              if not (tolerance or full):
                  mpmath.mp.dps = 15
                  rat = mpmath.pslq([xv, 1])
                  if rat is not None:
                      return Rational(-int(rat[1]), int(rat[0]))
              mpmath.mp.dps = prec
              newexpr = mpmath.identify(
                  xv, constants=constants_dict, tol=tolerance, full=full
              )
              if not newexpr:
                  raise ValueError
              if full:
                  newexpr = newexpr[0]
              expr = sympify(newexpr)
              if x and not expr:  # don't let x become 0
                  raise ValueError
              if expr.is_finite is False and xv not in [
                  mpmath.inf,
                  mpmath.ninf,
              ]:
                  raise ValueError
              return expr
          finally:
              # even though there are returns above, this is executed
              # before leaving
              mpmath.mp.dps = orig
  
      try:
          if re:
              re = nsimplify_real(re)
          if im:
              im = nsimplify_real(im)
      except ValueError:
          if rational is None:
              return _real_to_rational(
                  expr, rational_conversion=rational_conversion
              )
          return expr
  
      rv = re + im * S.ImaginaryUnit
      # if there was a change or rational is explicitly not wanted
      # return the value, else return the Rational representation
      if rv != expr or rational is False:
          return rv
      return _real_to_rational(
          expr, rational_conversion=rational_conversion
      )
  
imports: from collections import defaultdict
  from sympy.concrete.products import Product
  from sympy.concrete.summations import Sum
  from sympy.core import Basic, S, Add, Mul, Pow, Symbol, sympify, expand_func, Function, Dummy, Expr, factor_terms, expand_power_exp, Eq
  from sympy.core.exprtools import factor_nc
  from sympy.core.parameters import global_parameters
  from sympy.core.function import expand_log, count_ops, _mexpand, nfloat, expand_mul, expand
  from sympy.core.numbers import Float, I, pi, Rational
  from sympy.core.relational import Relational
  from sympy.core.rules import Transform
  from sympy.core.sorting import ordered
  from sympy.core.sympify import _sympify
  from sympy.core.traversal import bottom_up, walk
  from sympy.functions import gamma, exp, sqrt, log, exp_polar, re
  from sympy.functions.combinatorial.factorials import CombinatorialFunction
  from sympy.functions.elementary.complexes import unpolarify, Abs, sign
  from sympy.functions.elementary.exponential import ExpBase
  from sympy.functions.elementary.hyperbolic import HyperbolicFunction
  from sympy.functions.elementary.integers import ceiling
  from sympy.functions.elementary.piecewise import Piecewise, piecewise_fold, piecewise_simplify
  from sympy.functions.elementary.trigonometric import TrigonometricFunction
  from sympy.functions.special.bessel import BesselBase, besselj, besseli, besselk, bessely, jn
  from sympy.functions.special.tensor_functions import KroneckerDelta
  from sympy.integrals.integrals import Integral
  from sympy.matrices.expressions import MatrixExpr, MatAdd, MatMul, MatPow, MatrixSymbol
  from sympy.polys import together, cancel, factor
  from sympy.polys.numberfields.minpoly import _is_sum_surds, _minimal_polynomial_sq
  from sympy.simplify.combsimp import combsimp
  from sympy.simplify.cse_opts import sub_pre, sub_post
  from sympy.simplify.hyperexpand import hyperexpand
  from sympy.simplify.powsimp import powsimp
  from sympy.simplify.radsimp import radsimp, fraction, collect_abs
  from sympy.simplify.sqrtdenest import sqrtdenest
  from sympy.simplify.trigsimp import trigsimp, exptrigsimp
  from sympy.utilities.decorator import deprecated
  from sympy.utilities.iterables import has_variety, sift, subsets, iterable
  from sympy.utilities.misc import as_int
  import mpmath
label_desc: Use image node_id 21 for calling a global function with example usage: nsimplify(expr, constants, tolerance, full, rational, rational_conversion) and returns: _real_to_rational, sympify, expr, _real_to_rational, expr, rv, expr, expr, _real_to_rational, Rational