This is the first part of post series that serve as a concise guide to harnessing the possibilities of the Wolfram plugin for mathematics, physics and Wolfram Language coding, with a special focus on effective problem-solving prompting techniques, exemplified with 100+ plugin-using ChatGPT chat sessions.
Check out other parts of this guide here:
Guide 1: https://community.wolfram.com/groups/-/m/t/3070428
Guide 2: https://community.wolfram.com/groups/-/m/t/3075538
Guide 3: https://community.wolfram.com/groups/-/m/t/3077476
Guide 5: https://community.wolfram.com/groups/-/m/t/3078038
Guide 1: https://community.wolfram.com/groups/-/m/t/3070428
Guide 2: https://community.wolfram.com/groups/-/m/t/3075538
Guide 3: https://community.wolfram.com/groups/-/m/t/3077476
Guide 5: https://community.wolfram.com/groups/-/m/t/3078038
Contents
Contents
The Importance of Prompt Engineering Remarkable Results from Good Prompting Other Prompt Components Seeding Creativity JailbreakingThe Wolfram Plugin Summary The APIs of the Wolfram Plugin The Manifest (Plugin-Level Prompt) The ChatGPT-Wolfram Plugin-User Interactions ChatGPT Results with and without Plugin Common Wolfram Language Coding Mistakes Made by ChatGPTPlugin Usage Examples ChatGPT with and without Plugin Usage Modes Some Prompt Examples Solving Simple Problems Problem Solving Using the Wolfram Knowledgebase Write, Test (and Potentially Fix) Code
Cell coloring conventions
Cell coloring conventions
The Importance of Prompt Engineering
The Importance of Prompt Engineering
The Wolfram Plugin
The Wolfram Plugin
Summary
Summary
LLMs that can make use of tools allow for a much wider range of applications compared to ‘pure’ LLMs.
The Wolfram plugin allows you to:
• solve (nontrivial) symbolic and numeric computational problems
• retrieve curated and real-time data from hundreds of domains (mathematical, scientific, socio-economic, geo, …)
• carry out a wide range of function and data visualizations
• write post-beginner-level Wolfram code
• solve (nontrivial) symbolic and numeric computational problems
• retrieve curated and real-time data from hundreds of domains (mathematical, scientific, socio-economic, geo, …)
• carry out a wide range of function and data visualizations
• write post-beginner-level Wolfram code
• ChatGPT is pretty good at writing Wolfram Language code for a wide variety of problems.
Official announcement: https://www.wolfram.com/wolfram-plugin-chatgpt
The APIs of the Wolfram Plugin
The APIs of the Wolfram Plugin
◼
Wolfram|Alpha
◼
returns fully text-ified results of Wolfram|Alpha together with image links
◼
Wolfram Language (cloud)
◼
returns JSON of Wolfram Language output (result, messages, suggestions for changes) and image links
◼
Forthcoming: Wolfram Language Documentation
The Manifest (Plugin-Level Prompt)
The Manifest (Plugin-Level Prompt)
The ChatGPT-Wolfram Plugin-User Interactions
The ChatGPT-Wolfram Plugin-User Interactions
‘Typical’ interactions during a ChatGPT session with the Wolfram plugin:
Out[]=
ChatGPT Results with and without Plugin
ChatGPT Results with and without Plugin
Common Wolfram Language Coding Mistakes Made by ChatGPT
Common Wolfram Language Coding Mistakes Made by ChatGPT
Plugin Usage Examples
Plugin Usage Examples
This section will show a variety of math/physics problems solved with the Wolfram plugin.
Most problems will be ‘one-offs’, meaning they are not part of a large set of obviously similar ones.
So, the majority of prompts will not contain examples, but only instructions how to solve the problem.
More ‘run-of-the-mill’ problems are better approached with giving sample problems in the prompt.
Most problems will be ‘one-offs’, meaning they are not part of a large set of obviously similar ones.
So, the majority of prompts will not contain examples, but only instructions how to solve the problem.
More ‘run-of-the-mill’ problems are better approached with giving sample problems in the prompt.
ChatGPT with and without Plugin
ChatGPT with and without Plugin
Usage Modes
Usage Modes
Some Prompt Examples
Some Prompt Examples
Procedural instructions:
In the following every time I input a task/query/problem, I want you
1) develop and display well-documented Wolfram Language code that solves the problem and displays the code in a terminal-like way (with proper line length)
2) evaluate the code on the Wolfram Language API (make sure to remember the formatting rules for this API)
3) display the result returned from the Wolfram Language API
1) develop and display well-documented Wolfram Language code that solves the problem and displays the code in a terminal-like way (with proper line length)
2) evaluate the code on the Wolfram Language API (make sure to remember the formatting rules for this API)
3) display the result returned from the Wolfram Language API
Procedural + strategy instructions:
In the following every time I input a task, I want you ALWAYS
1) develop and display well-documented Wolfram Language code that solves the problem
(or part of it) and display it in a terminal-like way with proper line length
2) _then_ evaluate the code on the Wolfram Language API (remember the formatting rules for this API)
(NEVER send ANY code to the API that you didn’t show me before)
3) if needed go back and write better code
4) display the final result returned from the Wolfram Language API for the (potentially corrected) code
For complex problems do not write code for all steps together, rather do each step separately and check after each step if the data have the expected shape/form.
1) develop and display well-documented Wolfram Language code that solves the problem
(or part of it) and display it in a terminal-like way with proper line length
2) _then_ evaluate the code on the Wolfram Language API (remember the formatting rules for this API)
(NEVER send ANY code to the API that you didn’t show me before)
3) if needed go back and write better code
4) display the final result returned from the Wolfram Language API for the (potentially corrected) code
For complex problems do not write code for all steps together, rather do each step separately and check after each step if the data have the expected shape/form.
CDP (Comment-Describing Program) CoT versus SDP (Self-Describing Program) CoT
Remember that it is possible to include in the prompt:
• ChatGPT should test the code on examples and if needed fix the code.
• ChatGPT should revisit the code if done to make it more efficient.
• Take on a certain expert role.
• ChatGPT should test the code on examples and if needed fix the code.
• ChatGPT should revisit the code if done to make it more efficient.
• Take on a certain expert role.
Some examples of code-writing–related points that one could include in the prompt:
• “Please write the code with proper indentation for readability.”
• “Include comments in the code to explain each section or operation.”
• “Provide a brief explanation of how the code works.”
• “Explain the code in detail, including a step-by-step breakdown of each operation.”
• “Execute the code and display the output.”
• “Review the code for potential errors or inefficiencies.”
• “Check the code and, if necessary, fix any issues that were present in the code provided earlier.”
• “Generate test cases automatically to validate the code’s functionality.”
• “Restrict the use of certain functions to specific argument types or patterns.”
• “Follow a specific naming convention for variable names in the code.”
• “Make sure that no errors are generated when you run the code.”
• “Please write the code with proper indentation for readability.”
• “Include comments in the code to explain each section or operation.”
• “Provide a brief explanation of how the code works.”
• “Explain the code in detail, including a step-by-step breakdown of each operation.”
• “Execute the code and display the output.”
• “Review the code for potential errors or inefficiencies.”
• “Check the code and, if necessary, fix any issues that were present in the code provided earlier.”
• “Generate test cases automatically to validate the code’s functionality.”
• “Restrict the use of certain functions to specific argument types or patterns.”
• “Follow a specific naming convention for variable names in the code.”
• “Make sure that no errors are generated when you run the code.”
Use the plugin for verification and let GPT iterate to find a solution
Use the plugin for verification and let GPT iterate to find a solution
User prompt:
Can you construct a univariate real function f(x) for me with the following properties:
1) limit f(x) as x -> -inf is 3
2) limit f(x) as x -> inf is 0
3) f(x) vanishes exponentially fast as x-> infinity
Please discuss in detail how to construct such a function and how to ensure each of the properties.
Once you have constructed the function, please check all properties 1) to 3) one after another using Wolfram Language
Compute f(-10) and f(10) numerically to 4 digits. Print these approximate values.
If the checks don’t succeed, go back and fix the construction.
Finally plot the function over the range -10 to 10.
(Don’t forget to define the function __every time__ you call the API to compute one of the properties or plot the function.)
Can you construct a univariate real function f(x) for me with the following properties:
1) limit f(x) as x -> -inf is 3
2) limit f(x) as x -> inf is 0
3) f(x) vanishes exponentially fast as x-> infinity
Please discuss in detail how to construct such a function and how to ensure each of the properties.
Once you have constructed the function, please check all properties 1) to 3) one after another using Wolfram Language
Compute f(-10) and f(10) numerically to 4 digits. Print these approximate values.
If the checks don’t succeed, go back and fix the construction.
Finally plot the function over the range -10 to 10.
(Don’t forget to define the function __every time__ you call the API to compute one of the properties or plot the function.)
First attempt:
Second attempt:
f(x)=3exp(-x)exp(x)=3
Second attempt:
f(x)=3/(1+exp(x))
The curse and blessing of non-deterministic output
The curse and blessing of non-deterministic output
Solving Simple Problems
Solving Simple Problems
For ‘simple’ (operationally defined) problems, no special prompting techniques are needed.
Make log-log-plots
Make log-log-plots
User prompt:
Make a loglogplot of log(lcm(1,3,5,...,2n+1)) and log(lcm(2,4,6,...,2n)) for n=1,2,3, ...,100
Make a loglogplot of log(lcm(1,3,5,...,2n+1)) and log(lcm(2,4,6,...,2n)) for n=1,2,3, ...,100
Visualize de Moivre-Laplace theorem
Visualize de Moivre-Laplace theorem
Which (k2)base has all digits?
Which has all digits?
()
k
2
base
Rolling three dice
Rolling three dice
Phase portrait of damped harmonic oscillator
Phase portrait of damped harmonic oscillator
User prompt:
Consider a simple classical 1D harmonic oscillator.
For simplicity we will use mass = 1 and spring constant = 1.
Now we will add a non-conventional damping term: -x(t)/(1+x(t)^2/100) x’(t) meaning the damping is a nonlinear function of x(t).
Make a high-res phase portrait of such an oscillator for x(0)=2, x’(0)=-4 for 0<t<2000.
Consider a simple classical 1D harmonic oscillator.
For simplicity we will use mass = 1 and spring constant = 1.
Now we will add a non-conventional damping term: -x(t)/(1+x(t)^2/100) x’(t) meaning the damping is a nonlinear function of x(t).
Make a high-res phase portrait of such an oscillator for x(0)=2, x’(0)=-4 for 0<t<2000.
Problem Solving
Problem Solving
Telling ChatGPT in detail what results are desired and in which order frequently improves the result quality substantially.
Taking Tylenol
Taking Tylenol
User prompt:
Let’s do some math:
simple:
James takes 2 Tylenol tablets that are 375 mg each, every 6 hours. How many mg does he take in 24 hours?
medium:
James takes 2 Tylenol tablets that are 375 mg each, every 5 hours. How many mg does he take on average in 24 hours?
difficult 1:
James takes 2 Tylenol tablets that are 375 mg each, exactly every 5 hours. How many mg does he take at least and at most in 24 hours?
difficult 2:
James takes 2 Tylenol tablets that are 375 mg each every 6 hours +- 5 min. How many mg does he take at least and at most in 24 hours?
Assume the act of taking the tables is instantaneous.
Also assume the times are measured in an inertial frame with both James and the tablets at rest.
Carefully explain your reasoning. If needed, supply explicit time tables for taking the medicine.
Let’s do some math:
simple:
James takes 2 Tylenol tablets that are 375 mg each, every 6 hours. How many mg does he take in 24 hours?
medium:
James takes 2 Tylenol tablets that are 375 mg each, every 5 hours. How many mg does he take on average in 24 hours?
difficult 1:
James takes 2 Tylenol tablets that are 375 mg each, exactly every 5 hours. How many mg does he take at least and at most in 24 hours?
difficult 2:
James takes 2 Tylenol tablets that are 375 mg each every 6 hours +- 5 min. How many mg does he take at least and at most in 24 hours?
Assume the act of taking the tables is instantaneous.
Also assume the times are measured in an inertial frame with both James and the tablets at rest.
Carefully explain your reasoning. If needed, supply explicit time tables for taking the medicine.
User prompt:
Let’s do a small, but very enlightening wrt understanding the origins of chaos, numerical complex analysis experiment.
Consider the classical pendulum equation
y’’(t)=sin(y(t))
As a warmup, let’s plot some y(t) for initial conditions y(0)=y_0, y’(0)=0 for a few y_0 from 0 to 2.
Now let’s take a deep breadth and remember how change of variables worked for ODEs.
Let’s change
y(t) ==> Y(tau)
t = tau exp(i phi)
Derive the ODE for Y(tau), keeping phi as a parameter. Be very careful here and explain each step in the change of variable procedure.
In other words, I want to solve the pendulum equation along a ray (starting at the origin) in the complex plane.
Now that we have an ODE for Y(tau), let’s solve the IVP for Y’(0)=0 and Y(0)=1 for 0<=tau <=8 pi.
For phi from 0 to pi in steps of pi/8, then plot the Re( Y(tau)) and Im(Y(tau)).
Let’s do a small, but very enlightening wrt understanding the origins of chaos, numerical complex analysis experiment.
Consider the classical pendulum equation
y’’(t)=sin(y(t))
As a warmup, let’s plot some y(t) for initial conditions y(0)=y_0, y’(0)=0 for a few y_0 from 0 to 2.
Now let’s take a deep breadth and remember how change of variables worked for ODEs.
Let’s change
y(t) ==> Y(tau)
t = tau exp(i phi)
Derive the ODE for Y(tau), keeping phi as a parameter. Be very careful here and explain each step in the change of variable procedure.
In other words, I want to solve the pendulum equation along a ray (starting at the origin) in the complex plane.
Now that we have an ODE for Y(tau), let’s solve the IVP for Y’(0)=0 and Y(0)=1 for 0<=tau <=8 pi.
For phi from 0 to pi in steps of pi/8, then plot the Re( Y(tau)) and Im(Y(tau)).
Write, Test (and Potentially Fix) Code
Write, Test (and Potentially Fix) Code
Telling ChatGPT to test and potentially fix code is one of the most powerful techniques to get correct, working code.
Roots of Littlewood polynomials
Roots of Littlewood polynomials
User prompt:
Make me a nicely-colored image of the roots of all Littlewood polynomial up to degree six. Color the roots according to the degree of the polynomial.
Explain (and show) each function (not built-in functions) used in the code you will use to solve this problem.
While developing the code, after you developed a function, text it on a maximal degree of 3 to see if the function works as expected. If not, correct the function.
Make me a nicely-colored image of the roots of all Littlewood polynomial up to degree six. Color the roots according to the degree of the polynomial.
Explain (and show) each function (not built-in functions) used in the code you will use to solve this problem.
While developing the code, after you developed a function, text it on a maximal degree of 3 to see if the function works as expected. If not, correct the function.
Area and perimeter of random polygons
Area and perimeter of random polygons
User prompt:
Define a function that does the following:
Take n points in the unit square. Find the shortest tour through these n points. Finally form a polygon of the points in the order of the shortest tour.
Then return three things: an image of the polygon, the area of the polygon and the perimeter of the polygon.
Check for n=10 that the function returns an image and two numbers.
If this is not the case, try to make changes to the code to obtain the wanted results.
Define a function that does the following:
Take n points in the unit square. Find the shortest tour through these n points. Finally form a polygon of the points in the order of the shortest tour.
Then return three things: an image of the polygon, the area of the polygon and the perimeter of the polygon.
Check for n=10 that the function returns an image and two numbers.
If this is not the case, try to make changes to the code to obtain the wanted results.
Lévy searches
Lévy searches
User prompt:
I have read that Levy-type searches are the most efficient ones and that animals perform such searches.
Can you tell me about it?
Even better, could you design a computational experiment (in 2D) that statistically shows that Levy-type searches are optimal.
Please develop the code step-by-step.
Motivate, explain, EXPLICITLY SHOW, and test the code you develop.
Describe every step of the computation.
Make sure to not allow flights larger than the search area.
You can assume a finite overall search area; maybe use periodic boundary conditions for simplicity.
Yes, please implement the needed code and test it on a toy example. I will run a larger, longer-running experiment myself.
I have read that Levy-type searches are the most efficient ones and that animals perform such searches.
Can you tell me about it?
Even better, could you design a computational experiment (in 2D) that statistically shows that Levy-type searches are optimal.
Please develop the code step-by-step.
Motivate, explain, EXPLICITLY SHOW, and test the code you develop.
Describe every step of the computation.
Make sure to not allow flights larger than the search area.
You can assume a finite overall search area; maybe use periodic boundary conditions for simplicity.
Yes, please implement the needed code and test it on a toy example. I will run a larger, longer-running experiment myself.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Guide 4: The Wolfram Plugin for ChatGPT
by Michael Trott
Wolfram Community, STAFF PICKS, December 5, 2023
https://community.wolfram.com/groups/-/m/t/3077667
by Michael Trott
Wolfram Community, STAFF PICKS, December 5, 2023
https://community.wolfram.com/groups/-/m/t/3077667