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

Code before:
        if not match:
            return False

        # We need: a3*y'' + b3*y' + c3*y = 0
        # For Bessel with symbolic exponent: y'' + 0*y' + (x^k)*y = 0
        a3 = match[2]  # coefficient of y''
        b3 = match[1]  # coefficient of y'
        c3 = match[0]  # coefficient of y

        # Check if b3 = 0 (no first derivative term)
        if b3 != 0:
            return False

        # Normalize: divide by coefficient of y''
        if a3 == 0:
            return False

        if a3 != 1 and a3 != S.One:
            if not a3.is_constant():
                return False
            c3 = c3 / a3

        # Check if c3 is of the form A*x^k where k has free symbols
        # This indicates symbolic exponent
        A_sym = Wild('A_sym', exclude=[x])
        k_sym = Wild('k_sym', exclude=[x])

        pattern_match = c3.match(A_sym * x**k_sym)
        if not pattern_match:
            pattern_match = c3.match(x**k_sym)
            if pattern_match:
                pattern_match[A_sym] = S.One

        # Store the matched values
        if not pattern_match or k_sym not in pattern_match:
            return False

        # Check if k is symbolic (has free symbols)
        k_val = pattern_match[k_sym]

        # Exclude k=0 and k=1 cases (handled by other solvers)
        # k=0: constant coefficient ODEs
        # k=1: Airy equation (handled by 2nd_linear_airy)
        if k_val.is_number and k_val in [0, 1]:
            return False

        # Store the matched values
        self.match_dict = {
            'A': pattern_match[A_sym],
            'k': k_val,
        }

Review comment (suggestion):
As far as I can tell the solutions are valid for `k = 0` and `k = 1` and at least for most real values of `k` I have checked with the notable exception being `k = -2` which is not checked here.

The fact that other solvers can handle this is not a reason for not returning a valid answer here. It just means that the other solvers should be preferred by the solver ordering.

Code after:
        if not match:
            return False

        # We need: a3*y'' + b3*y' + c3*y = 0
        # For Bessel with symbolic exponent: y'' + 0*y' + (x^k)*y = 0
        a3 = match[2]  # coefficient of y''
        b3 = match[1]  # coefficient of y'
        c3 = match[0]  # coefficient of y
        rhs = match[-1]  # right-hand side

        # Check if b3 = 0 (no first derivative term) or a3 = 0  (no second derivative term)
        # or rhs != 0 (non-homogeneous)
        if b3 != 0 or a3 == 0 or rhs != 0:
            return False

        # Normalize: divide by coefficient of y''
        c3 = c3 / a3

        # Check if c3 is of the form A*x^k where k has free symbols
        A_sym = Wild('A_sym', exclude=[x])
        k_sym = Wild('k_sym', exclude=[x])

        pattern_match = c3.match(A_sym * x**k_sym)

        if not pattern_match or k_sym not in pattern_match:
            return False

        k_val = pattern_match[k_sym]
        A_val = pattern_match[A_sym]

        if k_val == -2:
            # Special case: k = -2 is an Euler equation, better handled by other solvers.
            return False

        # Store the matched values
        self.match_dict = {
            'A': A_val,
            'k': k_val,
        }

        return True

    def _get_general_solution(self, *, simplify_flag: bool = True):
        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']

        # For y'' + A*x^k*y = 0