As demonstrated in my previous post, ChatGPT, in conjunction with the Wolfram plugin, showcases an remarkable ability to solve a wide range of mathematical, physical, and algorithmic problems.
The power of ChatGPT can be increased by using a good prompt. A good fraction of the recent LLM literature emphasized especially ‘Chain-of-Thought’ (which now already has its own Wiki page) as one of the most powerful prompting techniques for problem solving tasks. Few-shot Learning, self-critique, or expert prompting (either telling the LLM to take the persona of a professor in the field XXX or telling to LLM to guess what an expert would answer) are other common performance-enhancing prompt techniques.
And, of course: hints. The hints supplied in the prompt can be often quite subtle; just a function name, the advice to use machine arithmetic rather than exact arithmetic for speed reasons, or a general direction (theorem/algorithm) to approach the problem.
And there are requests to check formulas and returned values of computations to see if they agree with expectations.
While the majority of my original 100 examples featured concise and straightforward prompts, it is worthwhile to explore more intricate prompt structures that enable the solution of complex problems. In the following examples, I initially employed simple prompts and then iteratively refined them based on ChatGPT’s responses. By identifying where ChatGPT encountered difficulties or took incorrect paths, I adjusted the prompt when needed, adopting a more generalized approach rather than relying on specific functions within the Wolfram Language. Additionally, I occasionally employed uppercase words or underbars to highlight particular aspects to ChatGPT. It is important to note that, even with optimized prompts, the stochastic nature of ChatGPT’s response generation process means that not every attempt will yield successful outcomes.
Some of the examples come from physics. With ChatGPT’s large background knowledge of special fields it is able to solve even late undergraduate or beginning graduate-level problems.
Here are some of the more advanced problems, some with more elaborate prompts (with a light gray background):

Visualization of a Kelvin-inverted and sliced triple-periodic surface

Consider the triple periodic surface
​
p(x,y,z) = cos(x+y) + cos(y+z) + cos(z+x) == 0
​
a) Visualize this surface or -pi <= x,y,z <= pi
​
b) Visualize the surface after a Kelvin inversion (x,y,z) -> 10 (x,y,z)/(x^2+y^2 + z^2) in p(x,y,z).
For the vertical plot range, use z<=0 only.
​
c) Consider the infinite plane q(x, y, z)= cos(alpha) x + sin(alpha) z = 0 (parametrized by alpha).
Make a Manipulate that allows to see the intersection of the above surface with the plane.
Change to 2D coordinates _in_ the plane q(x, y, z) to display the intersection curves of the plane q with p using ContourPlot[].
In-plane coordinates (s, t) via x == cos(alpha)*s, y == t , z== sin)alpha)*s might be appropriate.
ChatGPT session link
Just a small hint for the appropriate 2D coordinate system of the slice was needed in the prompt.

Computing a numerical value of the Wright function
W(a,b|z)

Let’s do a little numerical complex analysis problem:
I want you to approach the problem in the following way:
1) Carefully and in great detail describe the mathematical formulas, theorems, algorithms that will be used for symbolic and/or numeric computations later on with the plugin. Meaning write down parametrizations of contours needed explicitly, write down factors arising from changes of variables in integrals and differential equations, write down how and when to truncate sums and so on.
Whenever possible use built-in functions that can carry out numerical computations with appropriate built-in functions.
(like for numerical sums and integrals) rather than implementing your own trapezoidal or similar integration routines.
NEVER ever just take n terms of a sum that n is large enough or truncate an infinite integral at a large number. Use more sophistication.
​
2) motivate, develop, explain and display well-documented code that solves the problem and displays the code in a terminal-like way (with proper line length of at most 80 characters)
(as already mentioned, make sure to use the __most-appropriate__ functions that result in readable and efficient code)
3) evaluate the code on the codeI (make sure to remember the formatting rules))
4) display and interpret the result returned from actually running the code
If needed, revise the mathematical approach and or/the code.
​
Now our problem we want to tackle:
​
Let’s consider the Wright function W(a, b, |z).
The function has the series expansion:
W(a,b|z) = sum z^k/(k! Gamma(a k + b) )from k=0 to inf
​
And the following contour integral representation
W(a,b|z) = 1/(2pi i) integrate exp(xi+z xi^-a)/xi^b along the Hankel contour
The Hankel contour comes from (real part =)-inf a finite distance _below_ the real axis in the third quadrant, it goes to the right and always stays _below_ the real axis, then surrounds the origin counter-clockwise always (with the origin always a _finite distance_ to its left ), and then returns to (real part = ) -infinity in the second quadrant always staying _above_ the real axis.
(By well-known complex analysis theorems, we know that detailed shape obviously doesn’t matter as long as the contour never crosses the negative real axis and has the just-described shape, e.g. it can be a piecewise linear contour, say from -inf - i to 1-i to 1+i to -inf + i.)
​
The goal is to compute a numerical approximate decimal value of W(2.5,3|5) using the series _as well as_ the integral representation.
The two numerical approximations should agree to at least 5 digits.
Let’s do first the sum and then the integral, don’t code both up at once.
​
Please carry out all needed computations, do not just offer a blueprint on how the problem could be solved.
As long as the two results do not agree to five digits try to locate the problem and fix it.
ChatGPT session link
That is quite a long prompt. While ChatGPT can often do numerical analysis problems properly, with simple prompts it often default to shortcuts like taking 100 or 1000 terms rather than carrying out a loop as long as needed to achieve a given precision. Another good part of the prompt was dedicated to the Hankel contour. And while ChatGPT knows what a Hankel contour is, without some guidance its concrete realization will often cut the branch cuts.
PS1: Wright functions appeared recently a few times in the literature, see e.g. arxiv2306 .11381, arXiv:2304.02903.
PS2: The Wight function
W(a,b|z)
is the simplest special case of the built-in function FoxH[].
In[]:=
WrightW[a_,b_,z_]:=FoxH[{{},{}},{{{0,1}},{{1-b,a}}},-z]
In[]:=
WrightW[5/2,3,5]//N[#,20]&
Out[]=
0.59802275871251531161

Making a 16×16 Truchet tiling

Tell me about the history and the concept of a Truchet tiling.
Make a 16x16Truchet tiling where the building blocks are squared with two quarter circles of radius 1/2 in opposite corners.
Meaning one tile has a right-upper corner quarter circle and a left-lower corner quarter circle and the other tile has a right-lower corner quarter circle and a left-upper corner quarter circle.
First show graphics of these two tiles and then place them randomly selected on a grid.
ChatGPT session link
I had a certain pattern in mind, so in the prompt I explicitly stated the shape of the tiles. The result was still unexpected as I did not specify relative grid positions and absolute tile size.

Making a grid of the 3D polyhedra from a Voronoi tessellation

Let’s do a 3D geometry problem:
Let’s take 100 random points from the unit cube centered at the origin. Then let’s do a 3D Voronoi diagram. Extract each individual polyhedron from this Voronoi tessellation and display them in a 10x10 graphics grid, each polyhedron randomly colored and with some opacity.
(In case you decide to split up the computation in steps, make sure to have each Wolfram Language API call fully self-contained and can’t refer to previously defined data.)
ChatGPT session link
Not a lot of additional prompting was needed, just a reminder to submit self-contained code pieces.

The Aharonov-Vaidman Identity for a spin 1/2 system

Tell me about the Aharonov-Vaidman identity:
A psi = <A> psi + (Delta A) psi_orthogonal
​
For
A = sigma_z
and
psi ={1,1}
compute A psi , <A> , and (Delta A) explicitly and use these results to compute psi_orthogonal.
Verify <psi | psi_orthogonal> = 0.
​
Before computing needed integrals on the API, write them down in explicit form.
Compute A psi , <A> , and (Delta A) one after another, not all at once.
Use the fact psi is real for possible simplifications.
​
!Remember to have all code pieces sent for evaluation __fully self-contained__, do not refer to earlier defined variable names!
Instead, have all functions needed for a computation in every code piece that you send to the API for evaluation.
ChatGPT session link
Like above, in such-style multi-sub-problem tasks, one has to remind ChatGPT that previous results and variable assignments are accessible in a new API call.

Subset generation from scratch

The Wolfram Language function Subsets[list, {d}] gives all subsets of length d with elements from list.
Assume that Wolfram Language wouldn’t have such a function built-in.
​
So, let’s write a function subsets[list, {d}] ourselves.
Try to write an efficient function and discuss how the algorithm will work before implementing it.
​
Let’s use
list = Range[8]
d = 5
as our example and compare with the results of the built-in function.
Check the results of subsets[list, d] against Subset[list, d].
​
Compare the timing of Table[Subsets[Range[10], {d}] with the timings of Table[subsets[Range[10], {d}].
ChatGPT session link
Here the main addition is a (reminder) to check the results against a reference implementation and do timing comparisons.

Maximum area of a rectangle area in a superellipse

Find the dimensions and the area of the rectangle of the greatest area inscribed in the super-ellipse x^4/1^4+y^4/2^4 =1.
ChatGPT session link
This problem didn’t need much additional prompting. Mainly because ChatGPT only considered the case that the rectangle edges are parallel to the coordinate axes. And it is not easy to convince ChatGPT to consider a more general case.

Visualizing the concept of Bayesian updating

Write a small essay about Bayesian updating.
Assume we start with a Gaussian prior and obtain Gaussian-shaped measurement data.
Compute the posterior distribution. Use some concrete numbers for the gaussian distribution and plot the three distributions (in different colors).
ChatGPT session link
Again not a lot of additional prompting was needed, just the wish for a concrete visual example.
Explain the Euler–Maclaurin formula. G
Use
sum sin(k sqrt(3)) from k=1 to 100
as an example.
Compare the exact result for the sum,with the integral, the integral and the end point terms, the integral and endpoint terms and first correction terms numerically in a table. Approximate all numbers to 3 digits.
ChatGPT session link
Just some prompting to improve the readability of the result.

Easter Date 2023 à la Gauss

Explain Gauss’ Easter formula. Use it to predict the Easter date of 2023.
ChatGPT session link
Interestingly (I didn’t really expect this), this needed no further prompting.

Autonomous differential equation of a generic circle

Consider the implicit equation of a generic circle:
(x-x0)^2 + (y-y0)^2 = r^2
Find a (nonlinear) differential in y, y', y'', y''' not containing x, x0, y0, and r explicitly such that every circle obeys this differential equation.
Differentiate the implicit circle equation (with y=y(x)) a few times and eliminate the not-wanted variables using Groebner bases techniques.
ChatGPT session link
ChatGPT understands that it has to eliminate some variables, but a priori doesn’t know how to achieve it. The small hit to use ‘Gröbner bases techniques’ is enough to get the approach and code right.

Eigenvalue distance of a parametrized 12×12 matrix

Take two symmetric 12x12 matrices M1, M2 with random real matrix elements.
Form the matrix
M(z) = (1-z) M1 + z M2.
Over the complex z-plane from -2<=Re(z), Im(z)<=2 plot
|ln|minimal distance of all eigenvalues of M(z)||
ChatGPT session link
Small hint for a good plot range was needed, otherwise it worked pretty well.
In school one learns these integration rules:
integrate x^n dx = 1/(n+1) x^(n+1) + constant
integrate 1/x dx = ln(x) + constant
They seems like they have nothing to do with each other.
In the case of 1/(n+1) x^(n+1) the constant could be a function of n.
integrate x^n dx = 1/(n+1) x^(n+1) + constant(n)
1) Show that using
constant(n) = -1/(n+1)
allows the integrate 1/x dx = ln(x) integration rule to be the smooth limit of the integrate x^n dx = 1/(n+1) x^(n+1) rule as n-> -1.
2) Plot |1/(n+1) x^(n+1) -1/(n+1) - ln(x)| as a 3D plot with 0< x< 3 along the x-axis and n from -2 to 2 along the y axis.
ChatGPT session link also ChatGPT session link
In school one learns these integration rules:
integrate x^n dx = 1/(n+1) x^(n+1) + constant
integrate 1/x dx = ln(x) + constant
They seems like they have nothing to do with each other.
But obviously:
1/x = limit of x^n as n -> -1
Can you find a way that als the right hand side can be such a limit, meaning
ln(x) = limit 1/(n+1) x^(n+1) + constant as n -> -1
?

Computing and plotting the Hofstadter butterfly

Explain the Hofstadter butterfly and the Harper equation. Write down the Hamiltonian.
Write code that makes a graphics of a numerical discretized approximation of the Hofstadter butterfly. (Make sure to use matrices with machine reals, not exact expressions to reduce the computation time.)
Run the actual code and fix it if needed.
ChatGPT session link
Having ChatGPT first write down the Hamiltonian helps getting the actual matrix needed for diagonalization correct.
And the hint of using machine arithmetic rather than exact arithmetic is needed for speeding up the computations.

Expressing the Stefan-Boltzmann’s constant through more fundamental constant

Consider the Stefan-Boltzmann’s constant sigma.
Assume you don’t know how it can be expressed through the Planck constant h, the speed of light c, the Boltzmann constant k_B and the gravitational constantG.
So, make an ansatz
sigma ~ h^a c^b G^c (k_B)^d
Use dimensional analysis to determine a, b, c, d.
ChatGPT session link
Expressing precisely-enough what is wanted is good enough as a prompt.

Potential of a thin charged filament

Calculate the distribution of the electrostatic potential created by a straight, thin filament of finite length 2 l, charged with a constant linear density lambda.Give an explicit closed form for the potential.
Compute the potential at large distances from the filament; find the first correct term to a point charge.
​
Carefully describe the coordinate system and coordinate names to be used and don’t forget to indicate the real-valued-ness of variables in integrals.
ChatGPT session link
A straightforward prompt does OK, but a reminder to indicate real-valued-ness of relevant variables speeds things up dramatically.

Colliding blocks sliding down an inclined plane

Here is a slightly convoluted, but conceptually simple physics problem:
Two blocks, A and B, of the same mass are on a fixed inclined plane, which makes a 30 degree angle with the horizontal. At time t = 0, A is at l = -5 cm and block B is at l=0 cm, and both blocks are at rest (a positive distance l points downwards along the inclined plane.) Suppose the coefficients of static and kinetic friction between the blocks and the incline mu_A=sqrt(3)/6, mu_B=sqrt(3)/3, and that the blocks collide perfectly elastically. Let vA(t) and vB(t) be the speeds of the blocks down the incline. For this problem, use g = 1000cm/s^2, assume both blocks stay on the incline for the entire time, and neglect the sizes of the blocks.
Graph the functions vA(t) and vB(t) for t from 0 to 1 second.
Graph the functions xA(t) and xB(t) for t from 0 to 1 second.
Compute the times and positions of the first few collisions (in the time interval 0 sec <=t <= 1 sec explicitly.
And the velocities immediately before and immediately after the collisions.
Note that the blocks could collide multiple times.
Use exact rational fractions like 1/2, not floating point numbers like 0.5.
Remember not to use variable names that contain ‘_’ and ALWAYS include ALL relevant equations and data in each API call.
For simplicity, you can assume time being measured in seconds and distances in centimeters.
Derive the equations step-by-step and explain your reasoning for every step. Explain the orientation of the coordinate system used.
PLEASE approach the problem quite systematically: For each phase between two collisions
compute x(t), v(t), and a(t) in explicit closed form and display them and use these data to compute the time of the next collision.Then change the velocities due to the collisions and continue.
ChatGPT session link
As you can see looking at the length of the prompt, this problem, although quite simple from the physics involved, needed a fair amount of prompting to get, especially to the transfer of the initial conditions after a collision correct. The length of ChatGPT’s output is about the maximum it can generate in a coherent manner for a mathematical problem. In such cases one has sometimes to encourage ChatGPT to go on and tackle the next step of the tasks outlined in the prompt.

Verify the Maxwell equations for a Lekner light bullet

Let
psi(t,x,y,z)= a b/(x^2 + y^2 + (a - i (z + t)) (b + i (z - t)))
Phi(t, x,y,z)=(x + i y)/(b + i (z - t)) psi(t,x,y,z)
A(t,x,y,z)=curl( (0,0,Phi(t, x,y,z)) )
​
Here the speed of light was set to 1, A the vector potential, a and b are constants.
Show that the electric field obtained from
E(t,x,y,z)=-partiald A(t,x,y,z)/partiald t
and the magnetic field
B(t,x,y,z)=curl A(t,x,y,z)
fulfill the free Maxwell equations:
div E(t,x,y,z) = 0
curl E(t,x,y,z) = - partiald B(t,x,y,z)/partiald t
div B(t,x,y,z) = 0
curl B(t,x,y,z) = partiald E(t,x,y,z)/partiald t
​
The Maxwell equations might not be satisfied ‘on-the-nose’, but the expressions might need to be simplified.
(Remember to not make assignments to ‘E’, as it is a protected symbol in the Wolfram Language!)
​
Then, assuming a and b are real, take E(t,x,y,z) and _then replace_ t->0 in this expression. Then expand the resulting expression into real and imaginary parts (ComplexExpand[Re[...]]).
Simplify the resulting expression for Re(E(t=0,x,y,z) )^2.
(For this second task, remember to define again all needed expressions.)
ChatGPT session link
As it is so tempting (for humans as well as machines) to use ‘E’ as the symbol for the electric field strength, we have to caution ChatGPT in doing so because of the pre-assigned Euler constant meaning. And we needed to give some help in the prompt how to get a real part from a symbolic expression assuming real-valued parameters.

Lienard-Wiechert electric field for an accelerated point charge

Please do the following:
​
a) tell me about the Lienard-Wiechert potentials
​
b) explain the concept of retarded time t_red = t_red(t,(x,y,z)).
PLEASE, ALWAYS, in ANY formula you write down, indicate all dependencies on the independent variables time t and position vector(r) explicitly, like t_red = t_red(t,(x,y,z)).
NEVER use just f(t_red) without indicating the dependence on t and vector (x,y,z).
Using just t_red will lead to misconceptions and calculation mistakes.
Always use f(t_red(t, (x,y,z)) instead.
​
c) Compute d/dt t_red(t,(x,y,z)) in _explicit symbolic form_ through implicit differentiation.
​
d) Take the expression for the Lienard-Wiechert potentials and derive the electric field strength from it.
​
Let’s assume the charge moves with this parametrization: x_source(t)=A t^2, y_source(t)=0, z_source(t)=0 and the observation point (0,0,10) to simplify the expressions. Throughout the calculations to simplify expressions when needed.
​
Do the derivation carefully and step-by-step.
Make no additional assumptions like certain distances being small or large.
ChatGPT session link
This type-of problem is in my experience testing the limit of what ChatGPT can correctly answer. Having ChatGPT first tell some general statements about the Lienard-Wiechert potentials helps with the actual formulas. But the main additional prompt is the insistence on always writing the dependence of dependent variables on independent variables. Without doing this, the derivatives needed will be incorrect. The long formulas are a challenge for ChatGPT’s context window and while being off to a good start the answer does not quite reach the final result.

Expressing the derivative of the inverse of a matrix through inverse and derivative

Given an invertible nxn matrix A(t) whose elements depend on a parameter t.
Compute an expression for
​
partiald inverse(A(t))/partiald t = F( A(t), inverse(A(t))/, partiald A(t)/partiald t).
​
Not just state the formula, also explain how to derive it.
​
Check the formula with the matrix
​
{{2-4t,t^4,1-t^2},
{-2,2t-1,0},
{t,1-4t,8}}

(No need to explicitly show inverse(A(t)) or partiald inverse(A(t))/partiald t, just verify the example by explicit computation of the _simplified_ form of partiald inverse(A(t))/partiald t - F( A(t), inverse(A(t))/, partiald A(t)/partiald t) being the 3x3 zero matrix.
ChatGPT session link
Prompting ChatGPT to derive the identity before using it brings it into the right mindset and the verification is straightforward. Similar to the previous example, sometimes ChatGPT assumes that equality hold on the nose, but as we know today, equality is a complicated concept and we explicitly recommend simplification.
Let’s do a plane geometry exercise:
a) start with a regular n-gon in the real plane (call the list {refularNGon} level-0 polygon(s))
b) reflect the n-gon on each of its n side (let’s call the so-created polygons level-1 polygons)
c) for each of the n level-1 polygon, reflect it on each side (let’s call the so-created polygons level-2 polygons)
​
Show the resulting n^2 + n + 1 polygons randomly colored with opacity 0.4 for n=3, 4, 5, 6, 7.
​
Develop and explain the code you will write to make these images in detail.
​
Step 1:
Write down the detailed formula to reflect a single point wrt a given generic line (segment) Line[{A, B}] by forming components parallel and normal to AB to construct the reflected point. (no slope formulas please!!)
​
Step 2:
Then implement a function that reflects a polygon (head Polygon, not just a list of vertices!) on a line and test this reflection function on the square Polygon[ {{-1,-1},{1,-1},{1,1},{-1,1}}] reflected on Line[{{1,-1},{1,1}}] (head Line!) explicitly by running the code and comparing the result with the expected result (Polygon[{3,-1},{3,1},{1,1},{1,-1}]) before applying the function to many polygons.
RUN this test on the API and compare the coordinates before continuing with the next step!
​
Display the returned reflected polygon coordinates!
Also show a graphic with Polygon[ {{-1,-1},{1,-1},{1,1},{-1,1}}] in red and the reflected polygon in blue.
​
Be always careful to differentiate between a polygon (head Polygon) and just a list of points/vertices
and similar between a line (head Line) and a list of just two points in function definitions! THIS MATTERS -- I have many times seen you being very sloppy in this respect and then the code fails!
​
Step 3:
Define the level-0, level-1 and level-2 polygons. (Don’t use RegularPolygon[].)
​
Step 4:
Show the randomly colored polygons.
ChatGPT session link
That needed a pretty long prompt. The reason being that is a genuine multi-step task and due to ChatGPT’s stochastic answering nature something can go wrong at each step and chances nothing goes wrong decreases quickly with the number of steps. These issues can be addressed by asking ChatGPT to explicitly run tests after certain critical steps to make sure the code is on track. While the code of a single step might be incorrect, ChatGPT can much faster detect the problem and fix it inside a single step rather than in the combined final code.
And the code that ChatGPT generated for this example is quite respectable:

CITE THIS NOTEBOOK

Extending the computational range of ChatGPT-4: optimizing prompts for enhanced performance​
by Michael Trott​
Wolfram Community, STAFF PICKS, June 27, 2023
​https://community.wolfram.com/groups/-/m/t/2944810