hermann on Sun, 12 Oct 2025 17:35:53 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

First non-trivial PARI/GP script from chatgpt session


I discussed with chatgpt on the number of faces of convex hull polyhedron of integer points x,y,z with n=4*k+1=x^2+y^2+z^2 and integer k>5. chatgpt told me that asymptotically all faces are triangles.

I objected and provided example for n=89*97 from
https://hermann-sw.github.io/lattice_sphere_cmp/

with setting n=pq. The console output stated that
 – 696 triangles (3‑gons)
 – 288 quadrilaterals (4‑gons)
 – 24 heptagons (7‑gons)
 – 14 dodecagons (12‑gons)
which chatgpt used from then on.

I mentioned that for n of the given form the number of vertices is 12*h(-4*n) and PARI/GP qfbclassno function can be used. chatgpt created this script for analysis:

\\ Function to compute vertex count from class number
vertex_count(n) = 12 * qfbclassno(-4 * n);

\\ Function to analyze face data
analyze_faces(n, face_counts) =
{
  V = vertex_count(n); \\ number of vertices
  F = 0; E2 = 0;

  print("Analyzing for n = ", n);
  print("Vertex count V = ", V);

  \\ face_counts should be a vector of [face_degree, count]
  for(i=1, #face_counts,
    local(k = face_counts[i][1], c = face_counts[i][2]);
    F += c;
    E2 += k * c;
  );

  E = E2 / 2;
  euler_check = V - E + F;

  avg_face_degree = E2 / F;
  avg_vertex_degree = 2 * E / V;

  print("Number of faces F = ", F);
  print("Number of edges E = ", E);
  print("Euler characteristic (should be 2): ", euler_check);
  print("Average face degree = ", avg_face_degree);
  print("Average vertex degree = ", avg_vertex_degree);
}

It told me also what the output should be, and how to execute.

And execution resulted in what was stated:

$ gp -q chatgpt_pari.gp
? \\ Define face data: vector of [number of sides, count]
? face_counts = [[3, 696], [4, 288], [7, 24], [12, 14]];
?
? \\ Call analysis
? analyze_faces(8633, face_counts);
Analyzing for n = 8633
Vertex count V = 768
Number of faces F = 1022
Number of edges E = 1788
Euler characteristic (should be 2): 2
Average face degree = 1788/511
Average vertex degree = 149/32
?


Until now I discussed linear time algorithms for different Boost graph related problems with several AIs and was not impressed. They did lie into my face, the algorithms the provided were not constant time. Always when I stated which line of code was not constant time, the AI came back and stated, "ah, you are right, an additional datastructure is needed ...".

Now chatgpt.com seems to be version 5, and the free mode without login allows for impressive discussion sessions. I wanted to mention this here only because of the noon-trivial GP script created from chatgpt.

Regards,

Hermann.