def _get_examples_ode_sol_factorable(): """ some hints are marked as xfail for examples because they missed additional algebraic solution which could be found by Factorable hint. Fact_01 raise exception for nth_linear_constant_coeff_undetermined_coefficients""" return { 'hint': "factorable", 'func': f(x), 'examples': { 'fact_01': { 'eq': f(x) + f(x) * f(x).diff(x), 'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)], 'XFAIL': [ 'separable', '1st_exact', '1st_linear', 'Bernoulli', '1st_homogeneous_coeff_best', '1st_homogeneous_coeff_subs_indep_div_dep', '1st_homogeneous_coeff_subs_dep_div_indep', 'lie_group', 'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients', 'nth_linear_constant_coeff_variation_of_parameters', 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters', 'nth_linear_constant_coeff_undetermined_coefficients' ] }, 'fact_02': { 'eq': f(x) * (f(x).diff(x) + f(x) * x + 2), 'sol': [ Eq(f(x), (C1 - sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x / 2)) * exp(-x**2 / 2)), Eq(f(x), 0) ], 'XFAIL': ['Bernoulli', '1st_linear', 'lie_group'] }, 'fact_03': { 'eq': (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + x * f(x)), 'sol': [ Eq(f(x), C1 * airyai(-x) + C2 * airybi(-x)), Eq(f(x), C1 * exp(-x**3 / 3)) ] }, 'fact_04': { 'eq': (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + f(x)), 'sol': [ Eq(f(x), C1 * exp(-x**3 / 3)), Eq(f(x), C1 * sin(x) + C2 * cos(x)) ] }, 'fact_05': { 'eq': (f(x).diff(x)**2 - 1) * (f(x).diff(x)**2 - 4), 'sol': [ Eq(f(x), C1 - x), Eq(f(x), C1 + x), Eq(f(x), C1 + 2 * x), Eq(f(x), C1 - 2 * x) ] }, 'fact_06': { 'eq': (f(x).diff(x, 2) - exp(f(x))) * f(x).diff(x), 'sol': [Eq(f(x), C1)] }, 'fact_07': { 'eq': (f(x).diff(x)**2 - 1) * (f(x) * f(x).diff(x) - 1), 'sol': [ Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2 * x)), Eq(f(x), sqrt(C1 + 2 * x)), Eq(f(x), C1 + x) ] }, 'fact_08': { 'eq': Derivative(f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1, 'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x)] }, 'fact_09': { 'eq': f(x)**2 * Derivative(f(x), x)**6 - 2 * f(x)**2 * Derivative(f(x), x)**4 + f(x)**2 * Derivative(f(x), x)**2 - 2 * f(x) * Derivative(f(x), x)**5 + 4 * f(x) * Derivative(f(x), x)**3 - 2 * f(x) * Derivative(f(x), x) + Derivative(f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1, 'sol': [ Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2 * x)), Eq(f(x), sqrt(C1 + 2 * x)), Eq(f(x), C1 + x) ] }, 'fact_10': { 'eq': x**4 * f(x)**2 + 2 * x**4 * f(x) * Derivative(f(x), (x, 2)) + x**4 * Derivative(f(x), (x, 2))**2 + 2 * x**3 * f(x) * Derivative(f(x), x) + 2 * x**3 * Derivative(f(x), x) * Derivative(f(x), (x, 2)) - 7 * x**2 * f(x)**2 - 7 * x**2 * f(x) * Derivative(f(x), (x, 2)) + x**2 * Derivative(f(x), x)**2 - 7 * x * f(x) * Derivative(f(x), x) + 12 * f(x)**2, 'sol': [ Eq(f(x), C1 * besselj(2, x) + C2 * bessely(2, x)), Eq(f(x), C1 * besselj(sqrt(3), x) + C2 * bessely(sqrt(3), x)) ] }, 'fact_11': { 'eq': (f(x).diff(x, 2) - exp(f(x))) * (f(x).diff(x, 2) + exp(f(x))), 'sol': [], #currently dsolve doesn't return any solution for this example 'XFAIL': ['factorable'] }, } }
def test_factorable(): eq = f(x) + f(x) * f(x).diff(x) sols = [Eq(f(x), C1 - x), Eq(f(x), 0)] assert set(sols) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sols) == 2 * [(True, 0)] eq = f(x) * (f(x).diff(x) + f(x) * x + 2) sols = [ Eq(f(x), (C1 - sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x / 2)) * exp(-x**2 / 2)), Eq(f(x), 0) ] assert set(sols) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sols) == 2 * [(True, 0)] eq = (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + x * f(x)) sols = [ Eq(f(x), C1 * airyai(-x) + C2 * airybi(-x)), Eq(f(x), C1 * exp(-x**3 / 3)) ] assert set(sols) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sols[1]) == (True, 0) eq = (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + f(x)) sols = [Eq(f(x), C1 * exp(-x**3 / 3)), Eq(f(x), C1 * sin(x) + C2 * cos(x))] assert set(sols) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sols) == 2 * [(True, 0)] eq = (f(x).diff(x)**2 - 1) * (f(x).diff(x)**2 - 4) sols = [ Eq(f(x), C1 - x), Eq(f(x), C1 + x), Eq(f(x), C1 + 2 * x), Eq(f(x), C1 - 2 * x) ] assert set(sols) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sols) == 4 * [(True, 0)] eq = (f(x).diff(x, 2) - exp(f(x))) * f(x).diff(x) sol = Eq(f(x), C1) assert sol == dsolve(eq, f(x), hint='factorable') assert checkodesol(eq, sol) == (True, 0) eq = (f(x).diff(x)**2 - 1) * (f(x) * f(x).diff(x) - 1) sol = [ Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2 * x)), Eq(f(x), sqrt(C1 + 2 * x)), Eq(f(x), C1 + x) ] assert set(sol) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sol) == 4 * [(True, 0)] eq = Derivative(f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1 sol = [Eq(f(x), C1 - x), Eq(f(x), C1 + x)] assert set(sol) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sol) == 2 * [(True, 0)] eq = f(x)**2 * Derivative(f(x), x)**6 - 2 * f(x)**2 * Derivative( f(x), x)**4 + f(x)**2 * Derivative(f(x), x)**2 - 2 * f(x) * Derivative( f(x), x)**5 + 4 * f(x) * Derivative( f(x), x)**3 - 2 * f(x) * Derivative(f(x), x) + Derivative( f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1 sol = [ Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2 * x)), Eq(f(x), sqrt(C1 + 2 * x)), Eq(f(x), C1 + x) ] assert set(sol) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sol) == 4 * [(True, 0)] eq = (f(x).diff(x, 2) - exp(f(x))) * (f(x).diff(x, 2) + exp(f(x))) raises(NotImplementedError, lambda: dsolve(eq, hint='factorable')) eq = x**4 * f(x)**2 + 2 * x**4 * f(x) * Derivative( f(x), (x, 2) ) + x**4 * Derivative(f(x), (x, 2))**2 + 2 * x**3 * f(x) * Derivative( f(x), x) + 2 * x**3 * Derivative(f(x), x) * Derivative( f(x), (x, 2)) - 7 * x**2 * f(x)**2 - 7 * x**2 * f(x) * Derivative( f(x), (x, 2)) + x**2 * Derivative(f(x), x)**2 - 7 * x * f( x) * Derivative(f(x), x) + 12 * f(x)**2 sol = [ Eq(f(x), C1 * besselj(2, x) + C2 * bessely(2, x)), Eq(f(x), C1 * besselj(sqrt(3), x) + C2 * bessely(sqrt(3), x)) ] assert set(sol) == set(dsolve(eq, f(x), hint='factorable')) assert checkodesol(eq, sol) == 2 * [(True, 0)]
def _get_examples_ode_sol_factorable(): """ some hints are marked as xfail for examples because they missed additional algebraic solution which could be found by Factorable hint. Fact_01 raise exception for nth_linear_constant_coeff_undetermined_coefficients""" y = Dummy('y') return { 'hint': "factorable", 'func': f(x), 'examples':{ 'fact_01': { 'eq': f(x) + f(x)*f(x).diff(x), 'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)], 'XFAIL': ['separable', '1st_exact', '1st_linear', 'Bernoulli', '1st_homogeneous_coeff_best', '1st_homogeneous_coeff_subs_indep_div_dep', '1st_homogeneous_coeff_subs_dep_div_indep', 'lie_group', 'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients', 'nth_linear_constant_coeff_variation_of_parameters', 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters', 'nth_linear_constant_coeff_undetermined_coefficients'] }, 'fact_02': { 'eq': f(x)*(f(x).diff(x)+f(x)*x+2), 'sol': [Eq(f(x), (C1 - sqrt(2)*sqrt(pi)*erfi(sqrt(2)*x/2))*exp(-x**2/2)), Eq(f(x), 0)], 'XFAIL': ['Bernoulli', '1st_linear', 'lie_group'] }, 'fact_03': { 'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + x*f(x)), 'sol': [Eq(f(x), C1*airyai(-x) + C2*airybi(-x)),Eq(f(x), C1*exp(-x**3/3))] }, 'fact_04': { 'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + f(x)), 'sol': [Eq(f(x), C1*exp(-x**3/3)), Eq(f(x), C1*sin(x) + C2*cos(x))] }, 'fact_05': { 'eq': (f(x).diff(x)**2-1)*(f(x).diff(x)**2-4), 'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x), Eq(f(x), C1 + 2*x), Eq(f(x), C1 - 2*x)] }, 'fact_06': { 'eq': (f(x).diff(x, 2)-exp(f(x)))*f(x).diff(x), 'sol': [Eq(f(x), C1)] }, 'fact_07': { 'eq': (f(x).diff(x)**2-1)*(f(x)*f(x).diff(x)-1), 'sol': [Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)),Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)] }, 'fact_08': { 'eq': Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1, 'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x)] }, 'fact_09': { 'eq': f(x)**2*Derivative(f(x), x)**6 - 2*f(x)**2*Derivative(f(x), x)**4 + f(x)**2*Derivative(f(x), x)**2 - 2*f(x)*Derivative(f(x), x)**5 + 4*f(x)*Derivative(f(x), x)**3 - 2*f(x)*Derivative(f(x), x) + Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1, 'sol': [Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)), Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)] }, 'fact_10': { 'eq': x**4*f(x)**2 + 2*x**4*f(x)*Derivative(f(x), (x, 2)) + x**4*Derivative(f(x), (x, 2))**2 + 2*x**3*f(x)*Derivative(f(x), x) + 2*x**3*Derivative(f(x), x)*Derivative(f(x), (x, 2)) - 7*x**2*f(x)**2 - 7*x**2*f(x)*Derivative(f(x), (x, 2)) + x**2*Derivative(f(x), x)**2 - 7*x*f(x)*Derivative(f(x), x) + 12*f(x)**2, 'sol': [Eq(f(x), C1*besselj(2, x) + C2*bessely(2, x)), Eq(f(x), C1*besselj(sqrt(3), x) + C2*bessely(sqrt(3), x))] }, 'fact_11': { 'eq': (f(x).diff(x, 2)-exp(f(x)))*(f(x).diff(x, 2)+exp(f(x))), 'sol': [], #currently dsolve doesn't return any solution for this example 'XFAIL': ['factorable'] }, #Below examples were added for the issue: https://github.com/sympy/sympy/issues/15889 'fact_12': { 'eq': exp(f(x).diff(x))-f(x)**2, 'sol': [Eq(NonElementaryIntegral(1/log(y**2), (y, f(x))), C1 + x)], 'XFAIL': ['lie_group'] #It shows not implemented error for lie_group. }, 'fact_13': { 'eq': f(x).diff(x)**2 - f(x)**3, 'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))], 'XFAIL': ['lie_group'] #It shows not implemented error for lie_group. }, 'fact_14': { 'eq': f(x).diff(x)**2 - f(x), 'sol': [Eq(f(x), C1**2/4 - C1*x/2 + x**2/4)] }, 'fact_15': { 'eq': f(x).diff(x)**2 - f(x)**2, 'sol': [Eq(f(x), C1*exp(x)), Eq(f(x), C1*exp(-x))] }, 'fact_16': { 'eq': f(x).diff(x)**2 - f(x)**3, 'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))] }, } }