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

Code before:
    order = [2]

    def _matches(self):
        eq = self.ode_problem.eq_high_order_free
        f = self.ode_problem.func
        x = self.ode_problem.sym
        order = self.ode_problem.order

        if order != 2:
            return False

        # Get linear coefficients
        match = self.ode_problem.get_linear_coefficients(eq, f, order)
        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
        # 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 or k_sym not in pattern_match:
            return False

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

        return True

    def _get_general_solution(self, *, simplify_flag: bool = True):
        f = self.ode_problem.func.func

Review comment (suggestion):
There should be spaces like `rhs != 0`. Please see PEP 8.

Code after:
    order = [2]

    def _matches(self):
        eq = self.ode_problem.eq_high_order_free
        f = self.ode_problem.func
        x = self.ode_problem.sym
        order = self.ode_problem.order

        if order != 2:
            return False

        # Get linear coefficients
        match = self.ode_problem.get_linear_coefficients(eq, f, order)
        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,