如何藉助 AI 學習數學與計算機科學,避免自我欺騙
How to learn maths and CS with AI without fooling yourself
作者建議以教科書或講義作為學習主線,讓 AI 提供五道由易到難的練習,並協助找出解題中的第一個錯誤。計算機科學可用隨機測試對照暴力解法,數學則可代入小整數核對公式;文中的 Kadane 演算法例子展示了測試如何找出錯誤版本把空子陣列計入的問題。
If you're using AI to learn a hard maths or CS topic, I'd stop asking it for tutorials. A generated tutorial reads smoothly and you come away feeling you've understood it, but you haven't done anything yet, and doing it is the part that makes it stick.
What has worked better for me and for the people I teach is keeping a proper textbook or set of lecture notes as the spine. Somebody who knows the subject has already decided the order things come in and which examples matter. The AI then gets two narrower jobs.
Job one: problems, and finding your first mistake
Once you've read a section, ask for five exercises on it that go from routine to hard, without the answers, and do them on paper. Then paste your attempt and ask where the first mistake is. Don't ask it to grade the whole thing, because it'll tend to tell you a mostly-right answer is fine.
Also, if an explanation it gives you feels more complicated than the topic, ask for one worked example with real numbers before any general statement. That is usually the bit that's missing.
Job two: check whatever can be checked by running something
For computer science this part is fairly easy, because you can write the slowest version you're sure is correct next to your own solution and compare the two on lots of small random inputs. You can see it on the maximum subarray problem (Kadane's algorithm next to a common wrong version of it, with a brute force over every subarray as the referee):
import random
def kadane(a):
best = cur = a[0]
for x in a[1:]:
cur = max(x, cur + x)
best = max(best, cur)
return best
def kadane_wrong(a): # starts from 0, a version you'll see often
best = cur = 0
for x in a:
cur = max(0, cur + x)
best = max(best, cur)
return best
def brute(a):
return max(sum(a[i:j]) for i in range(len(a)) for j in range(i + 1, len(a) + 1))
for f in (kadane, kadane_wrong):
random.seed(1)
for _ in range(1000):
a = [random.randint(-5, 5) for _ in range(random.randint(1, 6))]
if f(a) != brute(a):
print(f.__name__, "fails on", a, f(a), brute(a))
break
else:
print(f.__name__, "passes 1000 tests")
Running it prints:
kadane passes 1000 tests
kadane_wrong fails on [-5, -5, -5] 0 -5
The wrong version returns 0 for a list where every number is negative, because it lets the empty subarray count (and that has a sum of 0). I think you and the AI could both read straight past that in the code, whereas the random test finds it almost immediately and even hands you a three-element input that shows the bug.
For maths the equivalent is plugging small numbers in, so if you've derived a formula you'd try it at n = 1, 2 and 3 and compare it with a direct count. Suppose you've worked out that the number of pairs you can choose from n people is n(n+1)2 . At n = 2 that gives 3, although two people obviously make only one pair. The right formula is (n2)=n(n−1)2 , which gives 0, 1, 3, 6 for n = 1 to 4. A check like this usually takes about a minute, and in my experience it catches the AI's mistakes just as often as your own.
What this looks like week to week
In practice I'd read a section of the book and do the AI's exercises on paper, then ask it where your first mistake is and test anything that can be run or counted. It's probably slower than reading generated notes, although by the end of each week you'll find you can actually do the problems yourself.
If you're studying computer science, the coding practice at https://academicquant.co.uk/coding?utm_source=devto&utm_medium=post&utm_campaign=devto-ai-learn-maths-cs works on the same principle (every problem has tests whose answers come from an independent brute-force version, in six languages), so you can check your own solution yourself without having to take anyone's word for it.
來源:DEV Community · dev.to