Traversing the Python Landscape for Mathematical Applets

By Lew Ludwig

A Thought Experiment

He said, “Imagine you have a container with a curvy top that is filled with Kool-Aid. Now imagine the Kool-Aid leveling out due to gravity. That level is the average value of the function.” I said, “That’s pretty good. Have you looked for a GIF so students can visualize this? I’m sure one has to exist.”

These are the types of conversations we have at the dinner table now, ever since my son, Bjorn, accepted a long-term substitute teaching position at his former high school, teaching three sections of AP AB, one of AP BC, and one class called the `Fundamentals of Calculus.’ After graduating with bachelor's degrees in math and computer science, he decided to take a gap year before pursuing a graduate degree in computer science. He spent the fall in New Zealand on a 30,000-acre sheep station. Now, he is teaching calculus six times a day - a win-win for him and the school.

But what about this average value gif?

The next day, Bjron texted me this:

 
 

To which I responded:

In his senior year, Bjorn worked with GPT 2.0 for a creative computing project. This was before ChatGPT 3.5 was released in November 2022. He is a self-described “capable coder,” but even he was surprised at the little effort it took to have ChatGPT 4.0 create a working, error-free visual.

Teach me! Teach me!

The real question was, could he teach me how to do this? Someone who has not compiled any computer code since the early aughts. I was reticent to install a compiler on my computer and learn the ins and outs of new technology. Moreover, how easy would it be for me to explain this process to others? Luckily, Bjorn found a clever and freely available workaround - Google Colab - a free cloud service that allows you to write and execute Pythion code through your browser, with no setup required.

I will now share how you too can attempt to create cool visuals using ChatGPT, even if you have no programming experience. To be clear, this is an attempt; not a definitive guide. Consider this a “how to try” manual rather than a “how to” manual. While many attempts are successful, due to the predictive nature of GPT, sometimes things might not work as expected.

The process:

1.Create a prompt for ChatGPT using the RTRO method:

a.Role (Act as)

b. Task (Create a)

c. Requirement (Be sure to)

d. Output (Turn into)

In this video, see how the initial prompt is entered into ChatGPT, and its response. Not only does it produce the desired code, but also alerts you of the libraries you will need for Google Colab.

 
 

2. Cut and paste the code into Google Colab

a.Be sure to put the library calls in a separate code box and run first.

b. Run the main code to see what you get

 
 

3. Not happy or want something else? Adjust your prompt.

 
 
 
 

That's all there is to it!

You'll soon discover that ChatGPT might not always generate exactly what you're seeking. However, because it recalls your previous prompts, you can continue to have a "conversation" with it to fine-tune your results. As Bjorn frequently advises, "Simply tell it what you want."

Here is an aspirational example. It took me about 10 minutes to create with seven revised prompts.

 
 

Some important caveats are in order here.

Caveat 1: Results may vary

As the advertising community reminds us, “results may vary.” This can be frustrating at times. As scientists, we want results that are replicable. This is not always the case with the current AI models. But don’t forget, this is the dumbest AI will ever be.

Caveat 2: You get what you pay for.

For my demonstration, I'm utilizing ChatGPT 4.0, the premium version. At the time of this writing, the premium version significantly outperforms the free 3.5 version in robustness. The free version struggled to consistently produce executable code more than half of the time. Although the latest version of Google Gemini was more adept at generating functional code than 3.5, it didn't match the capabilities of ChatGPT 4.0. Furthermore, 4.0 excelled in making refinements following prompts.

Caveat 3: There are better ways to compile.

While Google Colab offers someone like me, who isn't a coder, the ability to run Python code, it's no replacement for a Python IDE (Integrated Development Environment). As mentioned in Wikipedia, “Integrated development environments (IDE) are designed to maximize programmer productivity by providing closely integrated components with similar user interfaces.” In his testing, Bjorn found that some Python code produced by ChatGPT didn't compile correctly on Google Colab, yet functioned flawlessly in his local IDE. Therefore, if you possess some coding experience, you might prefer using your favored IDE compiler.

In a world increasingly driven by technology and innovation, the ability to demystify the process of creating code is more valuable than ever. I hope this piece helps showcases the power of modern AI and the potential within each of us to harness it. Whether you're a seasoned coder or someone who hasn't touched code since the dawn of the internet age, ChatGPT can help level that playing field. By following the journey outlined, you too can create visuals or solve problems with code, making the once daunting world of programming accessible and engaging. Let this be your invitation to explore and experiment with ChatGPT. Embrace the possibilities it presents, and remember, the journey of a thousand lines of code begins with a single prompt!


Lew Ludwig is a professor of mathematics and the Director of the Center for Learning and Teaching at Denison University. An active member of the MAA, he recently served on the project team for the MAA Instructional Practices Guide and was the creator and senior editor of the MAA’s former Teaching Tidbits blog.