code: def _real_to_rational(
      expr, tolerance=None, rational_conversion="base10"
  ):
      """
      Replace all reals in expr with rationals.
  
      Examples
      ========
  
      >>> from sympy.simplify.simplify import _real_to_rational
      >>> from sympy.abc import x
  
      >>> _real_to_rational(.76 + .1*x**.5)
      sqrt(x)/10 + 19/25
  
      If rational_conversion='base10', this uses the base-10 string. If
      rational_conversion='exact', the exact, base-2 representation is used.
  
      >>> _real_to_rational(0.333333333333333, rational_conversion='exact')
      6004799503160655/18014398509481984
      >>> _real_to_rational(0.333333333333333)
      1/3
  
      """
      expr = _sympify(expr)
      inf = Float("inf")
      p = expr
      reps = {}
      reduce_num = None
      if tolerance is not None and tolerance < 1:
          reduce_num = ceiling(1 / tolerance)
      for fl in p.atoms(Float):
          key = fl
          if reduce_num is not None:
              r = Rational(fl).limit_denominator(reduce_num)
          elif (
              tolerance is not None
              and tolerance >= 1
              and fl.is_Integer is False
          ):
              r = Rational(
                  tolerance * round(fl / tolerance)
              ).limit_denominator(int(tolerance))
          else:
              if rational_conversion == "exact":
                  r = Rational(fl)
                  reps[key] = r
                  continue
              elif rational_conversion != "base10":
                  raise ValueError(
                      "rational_conversion must be 'base10' or 'exact'"
                  )
  
              r = nsimplify(fl, rational=False)
              # e.g. log(3).n() -> log(3) instead of a Rational
              if fl and not r:
                  r = Rational(fl)
              elif not r.is_Rational:
                  if fl in (inf, -inf):
                      r = S.ComplexInfinity
                  elif fl < 0:
                      fl = -fl
                      d = Pow(10, int(mpmath.log(fl) / mpmath.log(10)))
                      r = -Rational(str(fl / d)) * d
                  elif fl > 0:
                      d = Pow(10, int(mpmath.log(fl) / mpmath.log(10)))
                      r = Rational(str(fl / d)) * d
                  else:
                      r = S.Zero
          reps[key] = r
      return p.subs(reps, simultaneous=True)
  
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 22 for calling a global function with example usage: _real_to_rational(expr, tolerance, rational_conversion) and returns: p