目錄

20200718 想法源起 20200719 我們在做什麼(一) 20200722 我們在做什麼(二) 20200725 竟然成為數學家(一) 20200729 竟然成為數學家(二) 20200801 竟然成為數學家(三) 20200805 不同職級(一) 20200808 不同職級(二) 20200812 趕客系列(一)為什麼讀大學? 20200815 趕客系列(二)不同大學學位跟工作的關係 20200819 趕客系列(三)大學的目的 20200822 趕客系列(四)大學為什麼要有主修 20200826 趕客系列(五)要挑選一個什麼樣的主修 20200829 沒有無緣無故的恨(一) 20200831 科普系列 - 數學與電影動畫製作(一) 20200902 沒有無緣無故的恨(二) 20200905 沒有無緣無故的恨(三) 20200907 科普系列 - 數學與電影動畫製作(二) 20200909 終身職位的評核 20200912 學術界吸引人的地方 20200914 科普系列 - 數學與電影動畫製作 (三) 20200916 學術界辛苦的地方(一) 20200919 學術界辛苦的地方(二) 20200921 科普系列 - 數學與電影動畫製作 (四) 20200923 大學的讀書成績有多重要 20200926 本科生研究機會 20200928 科普系列 - 數學與圖像修復(一) 20200930 用創新的方法去教育科學 20201003 參加研討會的重要 20201005 科普系列 - 數學與圖像修復(二) 20201007 教授與教學 20201010 研究是什麼(一) 20201012 科普系列 - 數學與圖像修復(三) 20201014 研究是什麼(二) 20201017 研究是什麼(三) 20201019 科普系列 - 數學與圖像修復(四) 20201021 如何閱讀研究論文 20201024 研究生應該修什麼課 20201026 科普系列 - 數學與圖像修復(五) 20201029 本科生的多主修多副修 20201102 科普系列 - 數學與數獨(一) 20201105 幾位教授(一) 20201109 科普系列 - 數學與數獨(二) 20201112 幾位教授(二) 20201116 科普系列 - 數學與數獨(三) 20201119 幾位教授(三) 20

與ChatGPT對話(二)

 


另外,因為自己在另外一個學期會教授一門用電腦編寫程式去計數的科目,所以也想知道這些聊天機械人是否能夠解答冷門科目上面的數學問題。上一個學期在教授這門科目時,因為容許同學們使用網上編寫程式工具,所以甚至在考試的時候,也容許同學們在網上搜尋答案。自己甚至乎跟同學們說,如果你們問Siri,他可以回答的話你也可以使用他的答案。所以在下一個學期在教這門科目時,我可能就真的要試一下不同的聊天機械人,看看他們是否能夠在我手上拿到一個好Grade。


首先是一條相對比較簡單的題目。


Tim:「python code to compute the distance between two vectors in 100 dimensions」

Sage:「Here's an example of how to compute the distance between two vectors in 100 dimensions using the numpy library:


import numpy as np


def euclidean_distance(v1, v2):

    return np.linalg.norm(v1 - v2)


v1 = np.random.rand(100)

v2 = np.random.rand(100)

distance = euclidean_distance(v1, v2)

print("The distance between the vectors is:", distance)

This code defines a function euclidean_distance that takes two vectors as input and returns the Euclidean distance between them. The input vectors v1 and v2 are generated using the random.rand function and are 100-dimensional. The function computes the Euclidean distance between the vectors as the magnitude of the difference between them. The result is displayed as "The distance between the vectors is:". 」


這條題目相對比較直接,所以可以見到他表現非常優秀。自己猜想他的答案可能比上一個學期某些同學還要好。 如果使用其他定義距離的方法呢?


Tim:「python code to determine the 1-norm distance between two vectors in 100 dimensions」

Sage:「Here's an example of how to compute the 1-norm distance (also known as the Manhattan distance) between two vectors in 100 dimensions using the numpy library:


import numpy as np


def manhattan_distance(v1, v2):

    return np.sum(np.abs(v1 - v2))


v1 = np.random.rand(100)

v2 = np.random.rand(100)

distance = manhattan_distance(v1, v2)

print("The Manhattan distance between the vectors is:", distance)

This code defines a function manhattan_distance that takes two vectors as input and returns the Manhattan distance between them. The input vectors v1 and v2 are generated using the random.rand function and are 100-dimensional. The function computes the Manhattan distance between the vectors as the sum of the absolute differences between the elements of the vectors. The result is displayed as "The Manhattan distance between the vectors is:". 」


也沒有錯,可以見到他其實是實質的使用定義去計算距離。他有沒有能力使用其他函數去幫助計算呢?


Tim:「can u use the function norm? 」

Sage:「Yes, you can use the norm function from the numpy library to compute the 1-norm distance between two vectors:


import numpy as np


v1 = np.random.rand(100)

v2 = np.random.rand(100)


distance = np.linalg.norm(v1 - v2, ord=1)

print("The 1-norm distance between the vectors is:", distance)

In this example, v1 and v2 are random 100-dimensional vectors, and the norm function is used to compute the 1-norm distance between them. The ord argument is set to 1 to specify that the 1-norm distance should be computed, and the result is displayed as "The 1-norm distance between the vectors is:". 」


在這條題目來說,他的表現真的非常優秀。可能是問題本身比較平凡,沒有太多的思考空間。 自己覺得這些問題直接在網上搜尋可能也可以找到這些答案。


既然如此,那就看一條比較困難的問題。在一個5×5的矩陣內,隨機選取20%的空格填上0,然後其他地方都填上1。 所以電腦第一步是需要知道其中5個空格是需要填上0。第二是需要知道選取這些空格的方式是需要隨機。看一看他是如何嘗試。


Tim:「python code to generate a five by five matrix with 20% entries in random given by 0 and all others 1」

Sage:「Here's an example in Python using the numpy library:


import numpy as np


matrix = np.ones((5, 5))

for i in range(5):

    for j in range(5):

        if np.random.rand() < 0.2:

            matrix[i][j] = 0


print("The 5x5 matrix with 20% entries as 0 and the rest as 1 is:\n", matrix)

This code generates a 5x5 matrix with all entries initialized as 1, and uses a nested loop to randomly change 20% of the entries to 0 using the numpy.random.rand function. The result is displayed as "The 5x5 matrix with 20% entries as 0 and the rest as 1 is:". 」


其實這個答案也不錯,你可以見到他選出20%的方式只是用了一個隨機數。當這個矩陣的大小趨向無限,這個方法就是對的。可是在這個5×5的矩陣情況,一般來說我們都不可以保證20%的空格是我們所希望的數值。為了要他解決這個問題,我在提問時多加了「exactly」這個提示,要求他所做的矩陣一定要只得5個空格是數字0。


Tim:「python code to generate a five by five matrix with exactly 20% entries in random given by 0 and all others 1」

Sage:「Here's an example in Python using the numpy library:


import numpy as np


matrix = np.ones((5, 5))

count = int(5 * 5 * 0.2)

for i in range(count):

    x = np.random.randint(5)

    y = np.random.randint(5)

    while matrix[x][y] == 0:

        x = np.random.randint(5)

        y = np.random.randint(5)

    matrix[x][y] = 0


print("The 5x5 matrix with exactly 20% entries as 0 and the rest as 1 is:\n", matrix)

This code generates a 5x5 matrix with all entries initialized as 1, and uses a loop to change exactly 20% of the entries to 0. The count variable keeps track of the number of entries that need to be changed to 0. The loop continues to run until count is equal to the number of entries that need to be changed. The np.random.randint function is used to generate random indices for the entries that will be changed to 0. The result is displayed as "The 5x5 matrix with exactly 20% entries as 0 and the rest as 1 is:". 」


結果非常好,只要問對問題,聊天機械人就可以給我們一個正確的答案。既然如此,就讓我多加一些數學的成份在問題裏面。


Tim:「python code to show two vectors are parallel」

Sage:「Here's an example in Python to show that two vectors are parallel:


def is_parallel(v1, v2):

    if v1 == v2 or v1 == [-x for x in v2]:

        return True

    else:

        return False


v1 = [1, 2]

v2 = [2, 4]


if is_parallel(v1, v2):

    print("The vectors are parallel")

else:

    print("The vectors are not parallel")

This code defines a function is_parallel that takes two vectors as input and returns True if they are parallel and False otherwise. Two vectors are parallel if they are equal or if one is equal to the negative of the other. In this example, v1 and v2 are defined as the 2D vectors [1, 2] and [2, 4], which are parallel. The function returns True and prints "The vectors are parallel".」


上面這條問題的數學題困難,只是想他證明一下兩支向量是否平行。他在程式裏面只是看一下兩支衡量是否相等或者其中一支另外一支成乘負一。這條題目,他的答案是錯了。所以如果題目有相當的數學成份,聊天機械人還是沒有能力把程式編出來。


ChatGPT 編寫程式的能力比起Sage 更加強大,這條平行向量的問題,他竟然做對了!


ChatGPT:「Two vectors are parallel if they are scalar multiples of each other. In other words, if one vector is a multiple of the other, they are parallel. We can use this fact to write a Python function that checks whether two vectors are parallel. Here's an example:


import numpy as np


def are_parallel(u, v, tol=1e-8):

    """

    Check whether two vectors u and v are parallel.

    """

    # Compute the norm of u and v

    norm_u = np.linalg.norm(u)

    norm_v = np.linalg.norm(v)

    

    # If either vector has zero norm, they are not parallel

    if norm_u == 0 or norm_v == 0:

        return False

    

    # Compute the ratio of the norm of u to the norm of v

    ratio = norm_u / norm_v

    

    # Check if u is a multiple of v, within a tolerance

    if np.allclose(u, ratio * v, atol=tol):

        return True

    else:

        return False

```


This function takes two vectors `u` and `v` as input, along with an optional tolerance `tol` (defaulting to 1e-8). It first computes the norms of the vectors using the `np.linalg.norm` function. If either vector has zero norm, they are not parallel, so the function returns `False`.


If both vectors have nonzero norm, the function computes the ratio of the norm of `u` to the norm of `v`. If `u` is a multiple of `v`, then `u` should be equal to some scalar multiple of `v`, which is given by multiplying `v` by the ratio. The function then checks whether `u` is close enough to the scaled version of `v` within the given tolerance using the `np.allclose` function. If they are close enough, the function returns `True`, indicating that the vectors are parallel. Otherwise, it returns `False`.」


有關於垂直的呢?


Tim:「python code to determine a unit vector that is orthogonal to (1,2,3,4) 」

Sage:「Unfortunately, a unit vector in 4-dimensional space cannot be orthogonal to a vector in 3-dimensional space. Orthogonality is only defined between two vectors in the same dimension. To determine a unit vector that is orthogonal to a 4-dimensional vector, you would need to input a 4-dimensional vector. 」


這條題目希望找一支在四維空間裏面長度是1的向量,而且他垂直於一支題目給予的向量。上面這條題目測試兩樣事情,第一是想知道他是否認識垂直,第二是如何從無限那麼多答案裏面給我其中一個。


Tim:「python code to determine a unit 4-dimensional vector that is orthogonal to (1,2,3,4) 」

Sage:「Here's an example code in Python to determine a unit 4-dimensional vector that is orthogonal to (1,2,3,4):


import numpy as np


def orthogonal_vector(vector):

    random_vector = np.random.rand(4)

    orthogonal_vector = np.cross(vector, random_vector)

    unit_vector = orthogonal_vector / np.linalg.norm(orthogonal_vector)

    return unit_vector


vector = np.array([1,2,3,4])

unit_vector = orthogonal_vector(vector)

print(unit_vector)

Note that this code uses numpy.cross to determine the cross product of two vectors. However, numpy.cross only works for arrays of 3 dimensions. To find the cross product of arrays with more than 3 dimensions, you need to use a different method. 」


這個答案是錯了。因為他使用了cross product。而這個東西只存在於三維空間。上面這個程式是有問題的。你既然知道四維空間沒有cross product,那為什麼要這樣做呢?


想一下他的答案,如果問題並不是設定在四維空間而是在三維空間,他的答案其實是對的。他是在三圍空間內隨機找一支向量,然後使用cross product, 所以orthogonal_vector 其實是儲存了一支垂直於題目所給予的向量,然後他下一步其實是把長度變成1。


Sage:「To find the cross product of two arrays of more than 3 dimensions, you can use the tensor product. The tensor product is a mathematical operation that takes two vectors and returns a matrix. The elements of the matrix are the products of the elements of the two vectors.


In general, the cross product of two vectors in n-dimensional space is not defined. However, there are specific cases when it's possible to find a vector that is orthogonal to a given vector in n-dimensional space. For example, in 4-dimensional space, it's possible to find two orthogonal vectors that are orthogonal to a given vector.


In conclusion, finding a unit vector that is orthogonal to a given vector in n-dimensional space is not straightforward and depends on the specific case. It's important to consider the properties of the vectors and the space they are defined in. 」


這個測試可以知道,他對cross product 是有一點認知,在他的數據庫內是有儲存着這個計算的特性。所以他嘗試使用這個技巧解決這個問題。可是要答對這個問題,需要的並不是在數據庫內的資料,同學們是需要運用垂直的定義小心嘗試,想辦法在這麼多可能性裏面找出一個符合規範的答案。這個就不是聊天機械人所能夠解決的了。


至於ChatGPT,他仍然是使用了cross-product。所以答案仍然是錯。


留言

  1. 你講嘅呢啲數學問題GPT-4都已經答得好好,就算仲有問題今日答唔好,聽日嘅gpt5、6、7應該都會解決到,教育真係唔知仲有咩價值

    回覆刪除
  2. 沒錯,我真的相信遲早它會給我正確的解答。因此,我們確實需要思考大學教育在未來的定位。

    回覆刪除

發佈留言