code: def test_rewrite():
      assert besselj(n, z).rewrite(jn) == sqrt(2 * z / pi) * jn(
          n - S.Half, z
      )
      assert bessely(n, z).rewrite(yn) == sqrt(2 * z / pi) * yn(
          n - S.Half, z
      )
      assert besseli(n, z).rewrite(besselj) == exp(
          -I * n * pi / 2
      ) * besselj(n, polar_lift(I) * z)
      assert besselj(n, z).rewrite(besseli) == exp(
          I * n * pi / 2
      ) * besseli(n, polar_lift(-I) * z)
  
      nu = randcplx()
  
      assert tn(besselj(nu, z), besselj(nu, z).rewrite(besseli), z)
      assert tn(besselj(nu, z), besselj(nu, z).rewrite(bessely), z)
  
      assert tn(besseli(nu, z), besseli(nu, z).rewrite(besselj), z)
      assert tn(besseli(nu, z), besseli(nu, z).rewrite(bessely), z)
  
      assert tn(bessely(nu, z), bessely(nu, z).rewrite(besselj), z)
      assert tn(bessely(nu, z), bessely(nu, z).rewrite(besseli), z)
  
      assert tn(besselk(nu, z), besselk(nu, z).rewrite(besselj), z)
      assert tn(besselk(nu, z), besselk(nu, z).rewrite(besseli), z)
      assert tn(besselk(nu, z), besselk(nu, z).rewrite(bessely), z)
  
      # check that a rewrite was triggered, when the order is set to a generic
      # symbol 'nu'
      assert yn(nu, z) != yn(nu, z).rewrite(jn)
      assert hn1(nu, z) != hn1(nu, z).rewrite(jn)
      assert hn2(nu, z) != hn2(nu, z).rewrite(jn)
      assert jn(nu, z) != jn(nu, z).rewrite(yn)
      assert hn1(nu, z) != hn1(nu, z).rewrite(yn)
      assert hn2(nu, z) != hn2(nu, z).rewrite(yn)
  
      # rewriting spherical bessel functions (SBFs) w.r.t. besselj, bessely is
      # not allowed if a generic symbol 'nu' is used as the order of the SBFs
      # to avoid inconsistencies (the order of bessel[jy] is allowed to be
      # complex-valued, whereas SBFs are defined only for integer orders)
      order = nu
      for f in (besselj, bessely):
          assert hn1(order, z) == hn1(order, z).rewrite(f)
          assert hn2(order, z) == hn2(order, z).rewrite(f)
  
      assert (
          jn(order, z).rewrite(besselj)
          == sqrt(2)
          * sqrt(pi)
          * sqrt(1 / z)
          * besselj(order + S.Half, z)
          / 2
      )
      assert (
          jn(order, z).rewrite(bessely)
          == (-1) ** nu
          * sqrt(2)
          * sqrt(pi)
          * sqrt(1 / z)
          * bessely(-order - S.Half, z)
          / 2
      )
  
      # for integral orders rewriting SBFs w.r.t bessel[jy] is allowed
      N = Symbol("n", integer=True)
      ri = randint(-11, 10)
      for order in (ri, N):
          for f in (besselj, bessely):
              assert yn(order, z) != yn(order, z).rewrite(f)
              assert jn(order, z) != jn(order, z).rewrite(f)
              assert hn1(order, z) != hn1(order, z).rewrite(f)
              assert hn2(order, z) != hn2(order, z).rewrite(f)
  
      for func, refunc in product(
          (yn, jn, hn1, hn2), (jn, yn, besselj, bessely)
      ):
          assert tn(func(ri, z), func(ri, z).rewrite(refunc), z)
  
imports: from itertools import product
  from sympy.concrete.summations import Sum
  from sympy.core.function import diff, expand_func
  from sympy.core.numbers import I, Rational, oo, pi
  from sympy.core.singleton import S
  from sympy.core.symbol import Symbol, symbols
  from sympy.functions.elementary.complexes import conjugate, polar_lift
  from sympy.functions.elementary.exponential import exp, exp_polar, log
  from sympy.functions.elementary.hyperbolic import cosh, sinh
  from sympy.functions.elementary.miscellaneous import sqrt
  from sympy.functions.elementary.trigonometric import cos, sin
  from sympy.functions.special.bessel import besseli, besselj, besselk, bessely, hankel1, hankel2, hn1, hn2, jn, jn_zeros, yn
  from sympy.functions.special.gamma_functions import gamma, uppergamma
  from sympy.functions.special.hyper import hyper
  from sympy.integrals.integrals import Integral
  from sympy.series.order import O
  from sympy.series.series import series
  from sympy.functions.special.bessel import airyai, airybi, airyaiprime, airybiprime, marcumq
  from sympy.core.random import random_complex_number, verify_numerically, test_derivative_numerically, _randint
  from sympy.simplify import besselsimp
  from sympy.testing.pytest import raises, slow
  from sympy.abc import z, n, k, x
label_desc: Use image node_id 12 for calling a global function with example usage: test_rewrite() without return types