Repository: sympy/sympy
File: sympy/solvers/ode/single.py (Python)

Code before:
        f = self.ode_problem.func.func
        x = self.ode_problem.sym
        (C1, C2) = self.ode_problem.get_numbered_constants(num=2)

        A = self.match_dict['A']
        k = self.match_dict['k']

        # Special case: k = -2 causes division by zero
        # The equation x^(-2)*y + y'' = 0 is an Euler equation
        # and should be handled differently
        if k == -2:
            # For x^(-2)*y + y'' = 0, characteristic equation is r^2 - r + A = 0
            discriminant = 1 - 4*A
            omega = sqrt(Abs(discriminant)) / 2
            return [Eq(f(x), sqrt(x)*(C1*sin(omega*log(x)) + C2*cos(omega*log(x))))]

        # For y'' + A*x^k*y = 0
        # The Bessel order and argument are:
        nu = 1 / (k + 2)

        z = (2 * sqrt(Abs(A)) / (k + 2)) * x**((k + 2)/2)

        # General solution
        solution = sqrt(x) * (C1 * besselj(nu, z) + C2 * bessely(nu, z))

        return [Eq(f(x), solution)]


class SecondLinearAiry(SingleODESolver):
    r"""
    Gives solution of the Airy differential equation

    .. math :: \frac{d^2y}{dx^2} + (a + b x) y(x) = 0

    in terms of Airy special functions airyai and airybi.

    Examples
    ========

    >>> from sympy import dsolve, Function
    >>> from sympy.abc import x
    >>> f = Function("f")
    >>> eq = f(x).diff(x, 2) - x*f(x)
    >>> dsolve(eq)
    Eq(f(x), C1*airyai(x) + C2*airybi(x))
    """
    hint = "2nd_linear_airy"
    has_integral = False

    def _matches(self):
        eq = self.ode_problem.eq_high_order_free

Review comment (suggestion):
This can be collapsed:
```python
        nu = 1 / (k + 2)
        z = (2 * sqrt(Abs(A)) / (k + 2)) * x**((k + 2)/2)
        return [Eq(f(x), sqrt(x) * (C1*besselj(nu, z) + C2*bessely(nu, z)))]
```

Code after:

        A = self.match_dict['A']
        k = self.match_dict['k']

        # For y'' + A*x^k*y = 0
        # The Bessel order and argument are:
        nu = 1 / (k + 2)

        z = (2 * sqrt(Abs(A)) / (k + 2)) * x**((k + 2)/2)

        # General solution
        return [Eq(f(x), sqrt(x) * (C1*besselj(nu, z) + C2*bessely(nu, z)))]


class SecondLinearAiry(SingleODESolver):
    r"""
    Gives solution of the Airy differential equation

    .. math :: \frac{d^2y}{dx^2} + (a + b x) y(x) = 0

    in terms of Airy special functions airyai and airybi.

    Examples
    ========

    >>> from sympy import dsolve, Function
    >>> from sympy.abc import x
    >>> f = Function("f")
    >>> eq = f(x).diff(x, 2) - x*f(x)
    >>> dsolve(eq)
    Eq(f(x), C1*airyai(x) + C2*airybi(x))
    """
    hint = "2nd_linear_airy"
    has_integral = False

    def _matches(self):
        eq = self.ode_problem.eq_high_order_free
        f = self.ode_problem.func
        order = self.ode_problem.order
        x = self.ode_problem.sym
        df = f.diff(x)
        a4 = Wild('a4', exclude=[x,f,df])
        b4 = Wild('b4', exclude=[x,f,df])
        match = self.ode_problem.get_linear_coefficients(eq, f, order)
        does_match = False
        if order == 2 and match and match[2] != 0:
            if match[1].is_zero:
                self.rn = cancel(match[0]/match[2]).match(a4+b4*x)
                if self.rn and self.rn[b4] != 0:
                    self.rn = {'b':self.rn[a4],'m':self.rn[b4]}
                    does_match = True