ODE, SageMath, and General AI - An Example From
High School Teaching
wanmin liu
wanminliu@gmail.com
21st June 2024
Abstract
In this teaching notes, we solve an ordinary differential equation
using mathematical logic. Additionally, we present a solution obtained
through the mathematical software SageMath. We also test the ODE on
various General AI systems, finding that they are unable to solve this
particular ODE directly. This example highlights the rigor and beauty
of mathematics, demonstrates the power of SageMath, and reveals the
current limitations of general artificial intelligence in solving complex
mathematical problems.
1 th e od e pro bl em a nd s ol ut io ns .
We assume that the reader has basic knowledge of calculus in the level of
high school, for example, as in the syllabus [1] for Mathematics 3c and
Mathematics 5 from Swedish National Agency for Education.
The following ordinary differential equation problem is raised in a teaching
in Mathematics 5.
The ODE Problem. Solve the ordinary differential equation
y
′′
(x) 8y
(x) + 16y(x) = xe
4x
(1.1)
with the conditions y
(0) = 1 and y
(1) = e
4
.
Solution. The equation
(1.1)
is a second order inhomogeneous linear ODE.
Step 1. Solutions of corresponding homogeneous equation. We solve
y
′′
(x) 8y
(x) + 16y(x) = 0. (1.2)
Its characteristic equation is given by
r
2
8r + 16 = 0. (1.3)
The solution of
(1.3)
is given by
r
= 4 with multiplicity 2. By the standard
theory of ODE (see for example [2] or [3, Ch. 19]), the solution of
(1.2)
is
given by
y
c
(x) = e
4x
(Ax + B), (1.4)
This note is based on my teaching at Kärrtorps Gymnasium in the spring of 2024. The
author thanks Mr. Herman Katea for sharing the question.
1
where A and B are constants.
Step 2. Find a particular solution of inhomogeneous equation
(1.1)
. We
observe that the right side of
(1.1)
is a solution for the homogeneous equation
(1.2)
. This feature of the right side of
(1.1)
is what makes the equation
intriguing, presenting challenges specifically for AI solvers.
A guess of a particular solution of the form
y
p
(x) = k
1
x
2
e
4x
+ k
2
xe
4x
+ k
3
e
4x
(1.5)
will not work, because
k
2
xe
4x
and
k
3
e
4x
are already solutions of homogeneous
equation, and one can check that y
p
(x) = k
1
x
2
e
4x
is not a solution of (1.1).
We must use new idea. The method is to let the solution be of the form
y(x) = e
4x
g(x), (1.6)
and we can convert the original ODE to a new ODE of the function g(x).
By the chain rule and (1.6), we have
y
(x) =e
4x
4g(x) + g
(x)
, (1.7)
y
′′
(x) =e
4x
16g(x) + 8g
(x) + g
′′
(x)
. (1.8)
Putting (1.8) and (1.7) into left side of (1.1), we obtain
y
′′
(x) 8y
(x) + 16y(x)
= e
4x
16g(x) + 8g
(x) + g
′′
(x) 32g(x) 8g
(x) + 16g(x)
= e
4x
g
′′
(x).
Thus, from the original ODE
(1.1)
, we derive a new ODE of function
g
(
x
):
g
′′
(x) = x. (1.9)
The general solution of (1.9) is given by
g(x) =
x
3
6
+ c
1
x + c
2
.
Therefore a particular solution of the inhomogeneous ODE
(1.1)
is given by
(taking c
1
= c
2
= 0 and using (1.6))
y
p
(x) = e
4x
x
3
6
,
and the general solution of the (1.1) is of the form
y(x) = y
c
(x) + y
p
(x) = e
4x
x
3
6
+ Ax + B
!
, (1.10)
where A and B are some constants.
Step 3. Find the constants A and B. From (1.10), we get
y
(x) = e
4x
4
x
3
6
+ 4Ax + 4B +
x
2
2
+ A
!
. (1.11)
So
y
(0) =
(4B + A)
,
y
(1) =
e
4
4
6
+ 4A + 4B +
1
2
+ A
. By comparing with
the conditions
y
(0) = 1 and
y
(1) =
e
4
, we obtain that 4
B
+
A
= 1, and
4
6
+ 4
A
+ 4
B
+
1
2
+
A
= 1. It follows that
4
6
+ 4
A
+
1
2
= 0 and
A
=
7
24
,
B
=
31
96
.
2
So the solution of the (1.1) with the given conditions is
y(x) = e
4x
x
3
6
7x
24
+
31
96
!
. (1.12)
Remark 1.1. One can also use the Laplace transform ( [3, Ch. 20]) to solve the
(1.1). The transformation (1.6) is simple from Laplace transform point-view.
2 sag em at h: an a pp li cat io n
SageMath [4] is a free open-source mathematics software system. The homepage
is
https://www.sagemath.org/
. One can install it or use it online. For
simplicity, we use the cloud version Sage on CoCalc.
Step 1. Visit
https://cocalc.com/features/sage
and sign up for a free
CoCalc account.
Step 2. After signing in, create a project
https://cocalc.com/projects
.
We call the project ODE-2024. Then we can create a SageMath Worksheet.
Step 3. In the SageMath Worksheet, we write the following code.
x = var(’x’)
y = function(’y’)(x)
de = diff(y,x,2) - 8*diff(y,x) + 16*y == x*exp(4*x)
desolve(de, y)
The first line of the code defines the variable
x
. The second line defines
y
as
a function of
x
. The third line defines the ODE, which is
(1.1)
. The forth line
solves the ODE by using the built-in function
desolve()
. More information
of solving ordinary differential equations can be found at [5].
Step 4. We can run the code now by clicking button Run. It gives the
solution of the general form, which is precisely (1.10):
1/6*x^3*e^(4*x) + (_K2*x + _K1)*e^(4*x)
3
So the SageMath solves the ODE and finds the general solution.
3 ge ne ra l art if ic ia l in te ll ig en ce .
The ODE serves as a good example to demonstrate that General AI cannot
solve certain mathematical problems or, at the very least, have significant
limitations. We have tested several General AI systems, including ChatGPT
and Copilot.
3.1 Two tests on ChatGPT 3.5, incorrect solutions
We tested this ODE on ChatGPT version 3.5 on May 16, 2024, with the prompt
that
Solve the ODE y’’(x)-8*y’(x)+16*y(x)=x*exp^{4x}, where y is a
funtion of variable x.
The response to the prompt is available at [6]. We also attach ChatGPT’s
response on the last page. It is a useful exercise to verify that ChatGPT’s
result is incorrect, as stated on the last page:
ChatGPT can make mistakes. Check important info.
One reason is that General AI is based on large language models and
statistics, rather than on mathematical logic.
There are two type of errors.
The first error is the assumption of the form of particular solution
y
p
(
x
) =
Ax
2
e
4x
+ Bxe
4x
+ Ce
4x
, as explained in (1.5).
The second error occurs in the computation of
y
p
(
x
). Specifically, it
omits the term related to
C
in the expression of
y
p
(
x
). Consequently, the
computations of both y
p
(x) and y
p
′′
(x) are completely incorrect.
We do not understand the mechanism why ChatGPT makes the second
error. If it did not make this mistake, it would have the opportunity to
recognize that there is no solution to this calculation. This would lead it back
to the first error, allowing it to discover that the initial assumption is incorrect.
Additionally, it could test more hypotheses to find the correct solution.
Another version of ChatGPT 3.5’s response to the same prompt on June 5,
2024, is available at [7]. It is also incorrect for similar reasons. The first error
is the assumption form of particular solution. The second error occurs in the
computation of y
p
′′
(x).
4
3.2 A test on ChatGPT 3.5 with improved prompt, correct solutions
We improved the prompt as follows in the ChatGPT 3.5, and tested it on June
5, 2024.
Solve the ODE y’’(x)-8*y’(x)+16*y(x)=x*exp^{4x}, where y is a
function of variable x. Find a particular solution of the form
y(x)=K*(x^3)*exp^{4x}.
It generates the correct solutions. The full response is available at [8]. The
improved prompt provides the exact information needed for the correct guess
form for the particular solution of the ODE, which can be derived through
human mathematical logic as shown in
(1.6)
. We do not know if the current
general AI can solve this ODE directly without this additional information.
4 co nc lu si on .
This ODE example highlights the rigor and beauty of mathematics, demon-
strates the power of SageMath, and reveals the current limitations of general
artificial intelligence in solving complex mathematical problems. The quality
of ChatGPT responses is entirely dependent on the prompts that provided.
re fe re nc es
[1] ‘Mathematics Syllabus in the Swedish upper secondary school’. https:
//www.skolverket.se/download/18.4fc05a3f164131a74181063/
1535372298267/Mathematics-swedish-school.pdf.
[2] Attila Szabo, Niclas Larson, Daniel Dufåker, and Roger Fermsjö,
Matematik Origo 5. Sanoma Utbildning, 3 ed.
[3] Robert Adams and Christopher Essex, Calculus - a complete course.
Pearson, 10 ed.
[4] ‘SageMath Mathematical Software System - Sage’.
https://www.sagemath.org/.
[5] The Sage Development Team, ‘Solving ordinary differential equations -
Symbolic Calculus’.
https://doc.sagemath.org/html/en/reference/calculus/sage/
calculus/desolvers.html#sage.calculus.desolvers.desolve.
[6] ‘ChatGPT 3.5 gives the incorrect solutions of an ODE on 20240516’.
https:
//chatgpt.com/share/dfe5d47f-2f40-49ab-b9ee-958ddff1073b.
[7] ‘ChatGPT 3.5 gives the incorrect solutions of an ODE on 20240605’.
https:
//chatgpt.com/share/4ea556d0-07f4-4fa2-9146-a5679ee4dfb5.
[8]
‘ChatGPT 3.5 gives the correct solutions of an ODE on 20240605’.
https:
//chatgpt.com/share/89355d26-017f-4008-997d-32c56a8fbd8c.
5
Solve the ODE y''(x)-8*y'(x)+16*y(x)=x*exp^{4x}, where y is a function of variable x.
To solve the given ordinary differential equation (ODE), we'll first find the complementary solution,
then the particular solution.
The characteristic equation corresponding to the homogeneous part of the ODE is:
Solving this quadratic equation, we get a repeated root . Therefore, the complementary
solution is:
Now, for the particular solution, we can use the method of undetermined coefficients. We assume the
particular solution has the form .
Differentiating twice and substituting into the original ODE, we find the values of , , and
that satisfy the equation.
Let's proceed with finding , , and :
Substituting these into the original ODE:
Grouping like terms:
Simplify and equate coefficients:
Comparing coefficients:
So, we have , and and are arbitrary constants.
Thus, the particular solution is:
Now, the general solution is the sum of the complementary and particular solutions:
This is the general solution to the given ODE.
r
2
8r + 16 = 0.
r = 4
y (x) =
c
(c +
1
c x)e .
2
4x
y (x) =
p
Ax e +
2 4x
Bxe +
4x
Ce
4x
y (x)
p
A B C
A B C
y (x) =
p
Ax e +
2 4x
Bxe +
4x
Ce
4x
y (x) =
p
(2Ax + B)e +
4x
4Ax e +
2 4x
Be
4x
y (x) =
p
′′
(2A + 8Ax + 4B)e +
4x
8Axe
4x
(2A + 8Ax + 4B)e +
4x
8Axe
4x
8((2Ax + B)e +
4x
4Ax e +
2 4x
Be ) +
4x
16(Ax e +
2 4x
Bxe +
4x
Ce ) =
4x
xe
4x
(2A + 8Ax + 4B 8B)e +
4x
(8Ax 8Ax)e +
4x
(16Ax
2
32Ax +
2
16Bx)e +
4x
(16C)e =
4x
xe
4x
(−4B)e +
4x
(16Bx)e +
4x
(16C)e =
4x
xe
4x
−4B = 0 B = 0
16B = 1 B =
16
1
16C = 0 C = 0
B =
16
1
A C
y (x) =
p
xe .
16
1
4x
y(x) = y (x) +
c
y (x) =
p
(c +
1
c x)e +
2
4x
xe .
16
1
4x
Message ChatGPT
ChatGPT can make mistakes. Check important info.
ChatGPT 3.5
?
16/05/2024, 10:19
ChatGPT
https://chatgpt.com/c/50e94f89-1e8f-4ec4-be4e-99db7ced0f42
1/1
6