Its important to understand that ChatGPT does not really "understand" Math. As it says frequently, it is a just a "language model trained by OpenAI". If it is writing code for you, it is because the problem text resembles its training and not because it reflects an understanding.