Writing code with ChatGPT is too time-saving

A few months ago, we talked about Tao Terence using ChatGPT to assist in solving math problems. At that time, he felt that although the test results were not satisfactory, he did not hold a completely negative attitude towards ChatGPT. He feels that large language models like ChatGPT can be used in mathematics to do some semi-finished semantic search work, that is, to use it to generate some hints.

picture

Terence Tao also believes that, "I predict that if used properly, by 2026, AI will become a trusted co-author in mathematical research and many other fields."

Today, Tao Terence shared a new experience: using ChatGPT to write Python code to calculate the mathematical problems of non-decreasing sequence of Phi, he thinks it is also very valuable.

The premise a while ago was still "the future", and now he has expressed his opinion on ChatGPT's mathematics. It can be seen that he is still not giving up, and he is still trying to use AI large models to improve his work efficiency.

picture

在这次体验中,他使用的 Prompt 是「I would like to write a program in some standard programming language (e.g., Python or C++) that, when given a natural number n, calculates the length M (n) of the longest subsequence of {1,…,n} on which the Euler totient function varphi is non-decreasing. For instance, if n = 6, we would have M (n)=5, because varphi is non-decreasing on {1,2,3,4,5} or {1,2,3,4,6} but not {1,2,3,4,5,6}. How would one program this? Ideally I’d like a program that can run reasonably quickly for medium values of n (say as large as 100), suggesting perhaps a dynamic programming method, but initially a brute force approach that only works for small n might be good enough for me.」

picture

In the results of the conversation, ChatGPT first explained, giving the following Python code:

import math

def phi(n):
    """Compute the Euler totient function for n."""
    result = n
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            while n % i == 0:
                n //= i
            result -= result // i
    if n > 1:
        result -= result // n
    return result

def is_non_decreasing(seq):
    """Check if a sequence is non-decreasing."""
    for i in range(1, len(seq)):
        if seq[i] < seq[i-1]:
            return False
    return True

def longest_non_decreasing_phi_subsequence(n):
    """Find the length of the longest subsequence of {1,...,n} on which phi is non-decreasing."""
    phi_values = [phi(i) for i in range(1, n+1)]
    max_length = 0
    for i in range(n):
        for j in range(i, n):
            if is_non_decreasing(phi_values[i:j+1]):
                max_length = max(max_length, j-i+1)
    return max_length

n = 6
print(longest_non_decreasing_phi_subsequence(n))  # Output: 5

In Tao Terence's view, the generated results have very interesting points, for example, it can generate a very smart program to calculate the totient function. However, there are calculation deviations in some places.

After using it, Tao Terence thought the result was good enough, "I was able to use the code originally generated by GPT as a starting point to manually generate the code I wanted, which probably saved me about half an hour of work." In addition, he also said that in the future In a similar calculation, he may turn to GPT again to provide the initial code.

In the interaction with readers, we can find that everyone is very welcome to ChatGPT to help write code. Some people said that I don't know much about codes, but with ChatGPT, it is not a problem to write programs from scratch.

picture

The first generative AI killer app, so scary?

At this time, someone asked: If you don't know how to code, how do you know whether the code generated by ChatGPT is correct?

Tao Terence said that I don't often write code in Python, so I didn't grasp some basic syntax (such as for loops), and there are some subtleties between pass by reference and pass by value, which confuses me. Almost every time, including when I end up initializing a 2D array incorrectly, I have to debug by manually checking for dynamic updates. So, having almost correct code, and already having the correct syntax helps me a lot, otherwise I would have to search through almost every line of code to figure out how to express it exactly.

Rather than writing mathematical proofs (which is more of my domain expertise), I agree with you that not quite correct arguments provided by GPT would be particularly helpful to me. AI-generated content isn't as good as writing it myself from scratch.

picture

Using a large model to get unfamiliar professional knowledge, it seems that this is how people will use ChatGPT to improve productivity in the future?

In addition, some people are more concerned about the source of these generated codes? Are there copyright issues? But it seems really difficult to trace the source.

picture

In your work, do you use ChatGPT to generate code for assistance?

Guess you like

Origin blog.csdn.net/qq_34160248/article/details/132652544