Recently, ChatGpt has gained a lot of attention and there are mixed reviews about it. Some people think highly of its capabilities, while others are more critical. Regardless, it has been an interesting  topic on assistant programming.

I'm going to give two examples to illustrate what's interesting and what's lacking.

First, I want ChatGpt to write a Maple code for the enumeration of all prime numbers up to 100. Then it writes:

primes:= proc(n)
   local i, j, primes;
   primes:= [2];
   for i from 3 to n do
      for j from 2 to i-1 do
         if i mod j = 0 then break;
      end do;
      if j = i then primes:= [op(primes), i]; end if;
   end do;
   return primes;
end proc;

primes(100);

I copy and paste this code, maple shows an error: Error, reserved word `do` unexpected

I report the error to it:

this code cannot run since "Error, reserved word `do` unexpected"

Then it gives: I apologize for the error in the previous code. Here is a corrected version of the code that can be run in Maple:

primes:= proc(n)
   local i, j, primesList;
   primesList:= [2];
   for i from 3 to n do
      for j from 2 to i-1 do
         if i mod j = 0 then 
            break;
         end if;
      end do;
      if j = i then 
         primesList:= [op(primesList), i]; 
      end if;
   end do;
   return primesList;
end proc;

primes(100);

Ok, It's tediously written code, but at least it's correct. 

Furthermore, I ask:

Is there a more concise approach that utilizes maple's built-in functions.

It tells me:

Yes, there is a more concise approach that utilizes Maple's built-in functions. Here's an example:

primes := [seq(i, i=2..100)]; primes := [op(select(isprime, primes))];

The seq function generates a list of numbers from 2 to 100. The select function filters out all non-prime numbers using the isprime function, which tests the primality of a number. The result is stored in the primes array.

Ok, this answer meets my expectations.

 

Another example is the generation of all 6th order non-isomorphic graphs, which pops up as:

# Load the GraphTheory package
with(GraphTheory):

# Generate a list of all non-isomorphic graphs with 6 vertices
graphs := NonIsomorphicGraphs(6):

# Print the list of non-isomorphic graphs
print(graphs);

But NonIsomorphicGraphs(6) as we know is the number  of non-isomorphic graphs but  not graphs  themselves.

 

So I say:

in the above codes, NonIsomorphicGraphs need the options output = graphs, outputform = graph

ChatGpt gives :

Here is a revised version of the code that takes into account the options output = graphs and outputform = graph:

 

# Load the GraphTheory package
with(GraphTheory):

# Generate a list of all non-isomorphic graphs with 6 vertices
graphsList := NonIsomorphicGraphs(6, output = graphs, outputform = graph):

# Print the number of non-isomorphic graphs
print("Number of non-isomorphic graphs: ", nops(graphsList));

# Print each non-isomorphic graph in the list
for i in 1 to nops(graphsList) do
  print("Graph ", i, ": ", graphsList[i]);
end do

It still has syntax errors. I made some artificial adjustments.

# Load the GraphTheory package
with(GraphTheory):

# Generate a list of all non-isomorphic graphs with 6 vertices
graphsList := [NonIsomorphicGraphs(6, output = graphs, outputform = graph)]:

# Print the number of non-isomorphic graphs
print("Number of non-isomorphic graphs: ", nops(graphsList));

# Print each non-isomorphic graph in the list
for i from 1 to nops(graphsList) do
  print("Graph ", i, ": ", graphsList[i]);
end do;

I pulled a wry face when  it builds a lot of codes  that do not exist in Maple.. Here's a little tidbit of my conversation with it.

This software still needs more work. I'm not sure how far it can go, but maybe programming becomes easier. Maybe more interesting examples will be found.


Please Wait...