# Wrong answer from DSolve when solving a differential equation

Bug introduced in 12.0.0, fixed in 12.1.1.

I was trying to solve the following differential equation: $$\frac{dy}{dx}=x^2+y^2-1 \quad \text{and} \quad y(0)=1$$

and I used the code below:

DSolve[{y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y[x], x]


The output from Mathematica 12 is

{{y[x] -> 1/(1 - x)}}


However, it is obviously wrong because if $$y(x)=\dfrac{1}{1-x}$$, then $$y'(x)=\dfrac{1}{(1-x)^2} \neq \left(\dfrac{1}{1-x}\right)^2+x^2-1$$

I cannot figure out why.

• Looks like a bug to me (in V12.0). Also fails on the ode: DSolve[{y'[x] == y[x]^2 + x^2 - 1}, y, x] May 2, 2019 at 12:35
• Can't reproduce in v9.0.1 and v11.2. Which version are you in? May 2, 2019 at 12:36
• @xzczd 12.0.0.0 May 2, 2019 at 12:37
• Please report it to Wolfram: support.wolfram.com May 2, 2019 at 12:58
• @Superfrankie: Interestingly, wolframalpha.com/input/…
– Moo
May 2, 2019 at 13:09

As noted by other users, this is a bug in DSolve in Version 12.0.

The problem appears to be related to a change in Series between Version 11.3 and Version 12.0, which is under investigation.

A partial workaround for the problem is to set an assumption on the independent variable as shown below to obtain the correct solution.

In[1]:= DSolve[{y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y[x], x,
Assumptions -> x > 0] // InputForm

Out[1]//InputForm=
{{y[x] -> (I*2^(I/2)*x*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] + (1 - I)*2^(1/2 + I/2)*x*Gamma[1/4 + I/4]*
Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] +
I*x*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*ParabolicCylinderD[-1/2 + I/2,
(1 + I)*x] + (1 + I)*Sqrt[2]*x*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[-1/2 + I/2, (1 + I)*x] - (1 - I)*2^(I/2)*Gamma[1/4 - I/4]*
Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[1/2 - I/2, (-1 + I)*x] +
2^(3/2 + I/2)*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[1/2 - I/2, (-1 + I)*x] - (1 + I)*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*
Gamma[3/4 - I/4]*ParabolicCylinderD[1/2 + I/2, (1 + I)*x] -
2*Sqrt[2]*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[1/2 + I/2, (1 + I)*x])/
(2^(I/2)*Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] - (1 + I)*2^(1/2 + I/2)*Gamma[1/4 + I/4]*
Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*ParabolicCylinderD[-1/2 - I/2, (-1 + I)*x] -
Gamma[1/4 - I/4]*Gamma[1/4 + I/4]*Gamma[3/4 - I/4]*ParabolicCylinderD[-1/2 + I/2,
(1 + I)*x] - (1 - I)*Sqrt[2]*Gamma[1/4 - I/4]*Gamma[3/4 - I/4]*Gamma[3/4 + I/4]*
ParabolicCylinderD[-1/2 + I/2, (1 + I)*x])}}


I apologize for the confusion caused by this issue.

• Unfortunately, this does not work under the assumption $x<0$ though the solution is valid (at least, for small negative values of $x$). May 2, 2019 at 19:22
• @user64494 It's because the series is being expanded about (positive) Infinity. The assumption x < 0 would contradict that and cause Series to fail. May 2, 2019 at 21:01
• Are there other known consequences of this Series bug? May 13, 2019 at 12:18

Here's a workaround for this particular case, based on the method shown in Riccati Equation:

Block[{DSolveDSolveFirstOrderODEDumpRiccati},
DSolveDSolveFirstOrderODEDumpRiccati[y_[x_], q0_, q1_, q2_, c_] :=
Module[{R, S, u},
S = q2*q0;
R = q1 + D[q2, x]/q2;
{{y[x] -> -u'[x]/(q2*u[x]) /.
First@DSolve[u''[x] - R*u'[x] + S*u[x] == 0, u, x] /. {C[2] ->
C[1] c, C[1] -> c}}}
];
sol = DSolve[ivp = {y'[x] == y[x]^2 + x^2 - 1, y[0] == 1}, y, x]
]


ivp /. sol // FullSimplify
(*  {{True, True}}  *)


This seems to be fixed in 12.1.1, DSolve and DSolveValue give the same result as in the workarounds posted: