Set your learning free with ChatGPT
Yeah it rhymes, but it also demonstrates an important truth: education will change.
We can imagine a precocious student, bored with the stultifyingly rigid curriculum that her teacher drones on about, going home to sit in front of her computer, and pounding ChatGPT with inquiries. I just want to learn cool shit she thinks to herself. Help me scale the learning curve at a rate commensurate with my ability.
We can further imagine that our precocious student has been teaching herself Python (or, really, any other Turing complete programming language), and, in a flash of insight, she realized that she can use ChatGPT to combine both Python and math, and so rapidly scale the knowledge curves of both subjects.
And, she can do this without the imprimatur of her teacher or any other pedagogical authority. Our precocious student, in other words, can be freed by generative AI.
What would this look like? How do you combine Python and math in ChatGPT to quickly learn about both? Well this morning I played around with several prompts to get an idea of what this looks like. Following are my prompts and ChatGPT’s output, along with some commentary from me. You can imagine a precocious student doing this for math or history or French or any other subject for which an LLM is useful1.
Now that we’ve set the scene, let’s take a look at what this looks like.
Prompt:
Write a Python script which calculates the least common multiple for two numbers. Have the user enter the two numbers, separated by a comma. The numbers should be real integers greater than zero.
Output:
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
num1, num2 = map(int, input("Enter two numbers, separated by a comma: ").split(','))
print("The LCM of", num1, "and", num2, "is", lcm(num1, num2))
But out intrepid student notes that it is possible to violate her instructions:
So she modifies her prompt by providing the following feedback:
Write a check into the script to ensure that the user enters integers that are real numbers greater than zero. If the user fails to enter real number integers greater than zero, return an error message: “Input must be real number integers greater than zero.”
ChatGPT modifies the script accordingly:
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
while True:
try:
num1, num2 = map(int, input("Enter two numbers, separated by a comma: ").split(','))
if num1 <= 0 or num2 <= 0:
raise ValueError
break
except ValueError:
print("Input must be real number integers greater than zero.")
print("The LCM of", num1, "and", num2, "is", lcm(num1, num2))
Now our output looks like this:
But she starts to look at the script, and some parts don’t make sense. She instructs her tutor: Explain how map(int, input( works
.
ChatGPT returns the following explanation:
The map(int, input().split(',')) function takes user input as a string and converts it into a list of integers.
Here's how it works:
The input() function takes user input as a string.
The split(',') method splits the input string into a list of strings, separated by a comma.
The map(int, ...) function applies the int function to each element in the list of strings, converting each string into an integer.
The result of map(int, ...) is an iterable object, which can be converted into a list using the list function, or unpacked directly into variables as in this case.
We can start to see something very powerful occurring here. Our student is synthesizing information about both least common multiples and Python. And she’s doing this iteratively, and probably fairly rapidly. And she’s doing it free from the oversight of pedagogical authority.
She continues in her quest:
Write a python script that will calculate the volume of a uniform polyhedron of the type specified by the user. The user can specify one of the following types: pentagon, hexagon, octogon, dodecagon. After the user has inputted the polyhedron type, request information about its size, in cm. Then calculate its volume in cubic cm.
ChatGPT works its magic:
import math
def polyhedron_volume(sides, size):
if sides == 5:
return (3/2) * math.sqrt(5 * (5 + 2 * math.sqrt(5))) * (size ** 3) / 12
elif sides == 6:
return (3/2) * (3 ** (3/2)) * (size ** 3) / 4
elif sides == 8:
return (2 ** (3/2)) * (size ** 3) / 3
elif sides == 12:
return (15 + 7 * math.sqrt(5)) * (size ** 3) / 4
else:
return 0
polyhedron = input("Enter polyhedron type (pentagon, hexagon, octogon, dodecagon): ")
size = float(input("Enter polyhedron size in cm: "))
if polyhedron == 'pentagon':
sides = 5
elif polyhedron == 'hexagon':
sides = 6
elif polyhedron == 'octogon':
sides = 8
elif polyhedron == 'dodecagon':
sides = 12
else:
sides = 0
volume = polyhedron_volume(sides, size)
if volume > 0:
print("The volume of the", polyhedron, "is", volume, "cubic cm.")
else:
print("Invalid polyhedron type.")
She runs the script, and gets the following result:
I’ll quit pretending to be a young student at this point. Surely you can understand that we can continue in this vein indefinitely. Here I told ChatGPT to write a script which makes use of calculus:
import numpy as np
def f(x):
return np.sin(x)
a, b = 0, np.pi
n = 1000
dx = (b - a) / n
integral = 0.0
for i in range(n):
integral += f(a + i * dx) * dx
print("The approximate value of the integral of sin(x) from", a, "to", b, "is", integral)
I ran the script:
ChatGPT helpfully provides an explanation of what this script does:
In this script, we define the function f(x) = sin(x), and then use the rectangle rule method to approximate the definite integral of f(x) from a to b by dividing the interval into n subintervals and summing up the areas of rectangles with height equal to the value of f(x) at the midpoint of each subinterval and width equal to the width of the subinterval (dx). The result is printed as the approximate value of the definite integral.
I wanted to make sure that I remembered what I had learned about calculus in high school. I had an intuition that the “rectangle rule method” was related to infinitesimals, so I asked ChatGPT about the relationship. Here’s its response:
The rectangle rule is a numerical method for approximating definite integrals that is based on the idea of infinitesimals. In calculus, a definite integral is defined as the limit of the sum of infinitesimal rectangles as the number of rectangles approaches infinity. The rectangle rule approximates this sum by using a finite number of rectangles and computing their total area.
In the rectangle rule, the interval of integration is divided into n subintervals, and a rectangle is constructed over each subinterval with height equal to the value of the function at the midpoint of the subinterval and width equal to the width of the subinterval. The total area of these rectangles is used as an estimate of the definite integral of the function.
As n approaches infinity, the width of each subinterval approaches zero and the rectangle rule approaches the actual definite integral. In this sense, the rectangle rule is a discrete approximation of the continuous concept of infinitesimals in calculus.
OK, well this is all rather simple and prosaic thus far. What if I wanted ChatGPT to write a script for a more sophisticated use of calculus? My prompt:
OK let's try something more advanced in calculus. What python script can you write that demonstrates a more complex calculus topic than definite integral approximation?
It came up with the following script:
import numpy as np
def f(x):
return (x[0] - 2)**2 + (x[1] - 1)**2
def grad_f(x):
return np.array([2 * (x[0] - 2), 2 * (x[1] - 1)])
x = np.array([10.0, 10.0])
alpha = 0.01
tolerance = 1e-6
while np.linalg.norm(grad_f(x)) > tolerance:
x = x - alpha * grad_f(x)
print("The minimum of f(x) is at", x)
And it provides this handy explanation of what’s going on:
In this script, we define a function f(x) = (x[0] - 2)**2 + (x[1] - 1)**2 and its gradient grad_f(x) = [2 * (x[0] - 2), 2 * (x[1] - 1)]. The goal is to find the minimum of f(x) using gradient descent.
The script starts with an initial guess for x and a step size alpha. The gradient of f(x) at the current value of x is calculated using the grad_f(x) function, and the value of x is updated according to the formula x = x - alpha * grad_f(x). This process is repeated until the norm of the gradient is less than a specified tolerance. The final value of x is printed as the estimated minimum of f(x).
This script demonstrates the use of gradient descent, a optimization algorithm in calculus which is widely used in machine learning and data science. It involves finding the minimum of a differentiable function by iteratively updating the current estimate of the minimum in the direction of the negative gradient.
So where does all of this leave us? What can we conclude from my brief experiment of using ChatGPT has an all-knowing tutor? (And when I say ‘brief’: I mean that. All of the scripts and prompts you see above, plus about a dozen others that I did not include in this post, took me about 20 minutes to generate this morning as I was sucking down coffee.)
I think this has pretty profound implications for education, especially for the education of our smartest and most inquisitive students. I think that they will be able to scale knowledge curves at a much quicker rate than they could previously, especially if they’re not in some sort of gifted or advanced program.
I also expect a lot of noise from the usual quarters about this. The credentialed and pedrigreed will be averse to the notion that a student can learn independently. The political left will cavil about equity, access, and inclusion. Teachers’ unions will complain about yet more authority being taken from them. Some parents, I am sure, will find fault in little Johnny or Suzy quickly learning more math than they.
And yet, the directional arrows of progress are evident. This technology only becomes more powerful and capable over time, and those students who avail themselves of it will rapdily advance relative to those who ignore it. Come to think of it, this is the same pattern we can expect to see with white collar knowledge workers: those who figure out how to use ChatGPT as a complement to their own work will quickly scale past their Luddite co-workers. Generative AI is going to make our near term future much weirder than we expect, and those who climb aboard will be best-positioned to take advantage of the weirdness.
Yes, issues about ChatGPT’s hallucinations obtain, at least for the time being. We are assuming here—and it may be a big assumption—that a student precocious enough to avail herself of this tool also is savvy enough to understand ChatGPT’s tendency toward hallucination, and that she can figure out a way to fact check its output.
I will be running all the scripts in this post via VS Code as it’s pretty easy to run small scripts in that environment.