第 219 期·中文精讀

唐納德·克努特:程式設計、演算法、難題與生命遊戲

Donald Knuth: Programming, Algorithms, Hard Problems & the Game of Life

電腦科學泰斗談《計算機程式設計藝術》的寫作、演算法之美、攻克難題的樂趣與生命遊戲。

官方音訊00:00 / --:--
中文精讀由 AI 基於原始訪談改寫,非官方翻譯,可能存在偏差或錯誤;表述以原音訊與官方文稿為準。說明

1957 年夏天,一個還沒念完大一的年輕人夜裡獨自坐在 IBM 650 的控制檯前,用十進位制數字一位一位撥進指令。他要讓這臺機器把開關上設好的數字分解成質因數。

那個年代幾乎沒人聽說過彙編器。他看的是隨機附帶的手冊,上面寫著 69 表示裝載,後面接上要裝入的地址。一條指令是十位十進位制數:兩位說明做什麼,四位說明對哪個地址做,剩下四位說明下一條指令去哪兒取。整臺機器的記憶體是兩千個字。

這個年輕人叫唐納德·克努特(Donald Knuth)。

他後來講過一句很實在的話:如果那本手冊寫得好,他大概不會走上電腦科學這條路。正因為寫得實在太差,他一邊讀一邊想,我一個新生都能寫得比這強,看來我在這上頭有點天賦。於是他跑到學校的計算中心打工,開始寫手冊。

前幾天,計算機歷史博物館的朋友道格·斯派瑟給他發了一個剛上傳到 YouTube 的連結:IBM 1956 年的進度報告。那年 IBM 把 650 捐給了斯坦福、MIT 和他所在的 Case Tech,影片裡能看到裝配線上第五百臺下線。片子還拍到一間教室,老師在黑板上寫著 69 8000,正在教學生怎麼給這臺十進位制機器寫程式。

克努特就在那樣的教室裡起步。

第一個程式除錯了一整夜,最後程式碼行數比預想的多出一大截

他的第一個程式是因數分解。輸入是控制檯上的撥盤,輸出打在穿孔卡片上。最初大概二十行,寫完開始除錯,行數就開始往上漲。

除錯的方式很原始。晚上沒人的時候,他坐在機器前,撥一個數,然後按單步執行,看機器做了什麼。有四組開關可以設一個地址,機器執行到那兒就停下來。他就這樣盯著它把這個數除以二,沒有餘數就說二是因子,有餘數就換三,一直試到開方為止。

第一個晚上他大概就跑通了 30 等於 2 乘 3 乘 5。之後麻煩陸續出現:有些數的因子多到一張卡片裝不下,而一張卡只有 80 列,每個因子要佔 10 列,他一開始根本沒考慮要輸出到第二張卡;如果輸入的是一個很大的質數,程式會在那兒空轉十分鐘,這臺機器慢得讓人分不清它是在計算還是卡在死迴圈裡。

第二個程式簡單得多,二進位制轉十進位制,幾乎沒出什麼岔子。第三個才是井字棋。

三個大腦,其中一個自己學會了不輸

井字棋那件事值得細說,因為裡面藏著一個十八九歲的年輕人對“學習”這件事最早的直覺。

棋盤是三乘三,每個格子有三種狀態:空、叉、圈。總共三的九次方,一萬九千六百八十三種局面。IBM 650 只有兩萬個十進位制數位的儲存,還得塞下程式本身、人機互動的邏輯、輸出邏輯。他做了一件事:利用對稱性。棋盤轉四次、翻一次,八種等價的擺法算一種,儲存需求一下降到八分之一。

每個見過的局面存一位數字。零表示壞棋,九表示好棋,初始值大概設成五六。贏了就把這個局面對自己調高,對對手調低。

他把程式分成三個大腦。第一個大腦完全隨機,輪到它就隨便找個空格打一子。第二個大腦是內建的固定策略,一套已知最優的走法。第三個大腦是真的在學。

然後他讓第一個大腦和第一個大腦對打。大約六百局之後,兩個什麼都不知道的隨機玩家,收斂到了一定和棋。

這個結果值得停一下。隨機對隨機,本來是亂打,最後變成了誰都不犯錯的穩健局面。原因在於他設計獎勵函式的方式:他懲罰的是錯誤,妙手反而沒有額外獎勵。這個學習系統學會的是不輸,不是想贏。他自己也點破了這一點,說如果換一個獎勵函式去獎勵漂亮的走法,學出來的東西會完全不一樣。

“它在學習怎麼不犯錯誤,它沒想贏,它只想別輸。”(唐納德·克努特)

他還提到兩件往事。查爾斯·巴貝奇一百多年前就在琢磨給那臺永遠沒造完的差分機編一個井字棋程式。而他自己上大學的動機之一,是小時候在芝加哥科學與工業博物館看過貝爾實驗室做的繼電器井字棋裝置,那時他就想著,我是不是也能寫一個。

凌晨的機器與停機時間寫出來的 TeX 手冊

那幾年他用機器只能靠夜裡。全世界都在睡覺,算力才輪得到他。高中時做校報,週一晚上整夜不睡,週二早上報紙出來。大一大二之間他基本不需要睡眠。

羅德尼·布魯克斯(Rodney Brooks)講過一件舊事。他在 MIT 的時候對克努特有點發怵,因為機器壞了,這位個子很高的教授就站在旁邊等,壓力全在修機器的人身上。克努特自己的版本更平淡:斯坦福 AI 實驗室的機器宕得厲害,因為那兒有一群天才程式設計師每天都在改作業系統,系統一天比一天好,也一天比一天容易崩。

TeX 的手冊,很大一部分就是在那臺機器宕機的間隙裡寫完的。

一張餐巾紙,一週寫完一本書

1967 年,克努特在牛津第一次見到約翰·康威(John Conway)。那場演講講的是紐結,康威拿一堆塑膠小棍在臺上現場拼出各種結,拼完再拆掉。他講的東西后來引出了成千上萬篇論文,而那些內容他在高中就想過,一直沒發表。

1972 年春天,兩人碰巧同一天到卡爾加里,一起吃了頓午飯。康威在餐巾紙上寫下了他關於“數”的那套公理,寫得滿滿一張。克努特看完覺得極其漂亮。

那年年末,他在挪威過學術休假。十二月的一個深夜,他忽然想到:康威這套數的理論,正好可以用來教學生怎麼做研究,怎麼體會發現的樂趣。他之前還讀過阿爾弗雷德·雷尼寫的一本對話體小書,兩個角色像蘇格拉底那樣互相追問數學。凌晨他把妻子吉爾叫醒,說我想寫一本書。

一月份,他在奧斯陸市中心租了一間旅館房間,除了寫這本書什麼都不幹。一個星期,白天黑夜連著寫。字流出來的速度幾乎比他思考還快。寫到第六天完成,第七天休息,然後他準備給秘書寫信交代怎麼打字,發現自己寫不出一個完整的句子了。

“靈感完全離開了我。就好像是在通靈。”(唐納德·克努特)

稿子寄給康威,康威回信說,唐,你有一條公理寫錯了。他用的是“不大於”,而應該是“小於等於”。在日常語言裡這兩個說法差不多,在邏輯公理系統裡,選錯一個會讓後面每一步證明都變難。那年夏天他又抽出一週,跑到挪威山裡重寫了一遍。

書最後叫《超現實數》(Surreal Numbers)。一本講數學的書,寫成了兩個人的對話,寫的過程本身就是書裡講的那個過程:從兩條公理出發,一步步發現,作者犯的每個錯,書裡的角色也犯一遍。

這兩個人後來的交往也很有意思。克努特在蒙特利爾做七場關於穩定匹配的系列講座,康威在第六場和第七場之間到了,兩人在派對上碰面,克努特講了自己在做什麼,康威當場想了一會兒,推出了一套漂亮的理論:所有穩定匹配構成的集合是一個分配格,還給出了求兩個穩定配對的下確界和上確界的方法。第二天的講座就用上了。

穩定婚姻這個詞,克努特用了六十年。他和吉爾結婚也正好六十年。他們認識的方式是他先跟吉爾的室友約會,然後跑去問吉爾該怎麼追。他發現聽她出主意比追她室友有意思得多。一個藝術家,一個極客,一起做設計專案,每年寫聖誕卡都要互相妥協各自對美的理解。

他說了一句話,婚禮上大概沒人敢講:在遇到她之前,他其實並不喜歡接吻這件事。

費曼問了一個沒人問過的問題

在加州理工,他和費曼會互相去聽對方的講座。費曼要是坐在第一排,他會走神,會漏掉幾句話。

他印象最深的是費曼在巴西的那段經歷。費曼說那兒的物理教育全錯了,學生只是在學怎麼透過考試,沒在學物理。別人不信,他說你把書翻到任何一頁,我告訴你這一頁錯在哪兒。那本教材的作者就坐在臺下,還是位很好的老師。

克努特從中提煉出的東西,比故事本身更重要:教育機構很容易滑向發證書,把給知識這件事放到了一邊。他自己講過一個鮑勃·弗洛伊德喜歡的漫畫:兩個人站在一臺大機器前面,一個說這機器一秒鐘能幹一百萬人一百年的活,另一個問,那你怎麼知道它算得對。

他和費曼之間還有一段純粹智力上的交鋒,關於他名字掛在上面的那個記號:克努特箭號。

加法重複若干次變成乘法,乘法重複若干次變成冪,冪重複若干次就是雙箭號。二的二次的二次,二的二次方是四,二的四次方是十六。三箭號、四箭號可以一直疊上去,數字會迅速膨脹到人腦無法把握的程度。他用這個來舉例說明什麼叫“大到無法理解”。

費曼聽完說,那我們別隻用整數,考慮考慮複數。x 雙箭號 2.5 可以插值,那 x 雙箭號 i 呢?他斷言不存在能做這件事的解析函式。克努特當時沒弄明白他憑什麼這麼斷定。然後費曼接著問:那箭號的個數能不能是複數?

這就是費曼式的提問方式。克努特講這段的時候語氣很平靜,但你能聽出來他記住這個提問已經幾十年了。

他還解釋過自己為什麼從物理轉到數學。物理考試他能拿 A+,但他完全不知道老師是怎麼想出那些題的。數學不一樣,他知道題目為什麼這麼出,還能自己編題。他擅長代數,不擅長几何。物理學家用波思考,他也能用波思考,但那感覺像一條狗用後腿走路。能走,但不像它的本能。

他相信電腦科學很大程度上是被那些大腦恰好能和某類概念共振的人推動的。量子計算就屬於需要另一種大腦的東西,它正好卡在物理和電腦科學的交叉口上。

KMP 演算法:三個不同的人摸到了同一頭大象

字串匹配這個問題,今天每個用搜尋引擎的人都受益於它。你有一大段文字,想知道“Knuth”這個詞出現在哪兒,或者某個比 Knuth 更沒意思的詞出現在哪兒。

樸素做法是:從頭掃,先找 K,找到 M,再找 O,一路下去,但遇到“Morris”這個詞,讀到第五個字母發現是 E 而不是 I,只能退回下一個位置重來。加州大學伯克利分校的吉姆·莫里斯(Jim Morris)注意到一個巧妙之處:剛才那幾個字母已經讀過了,而且它們不可能是 M,沒必要重讀。

如果模式詞像“abracadabra”這樣,開頭、中間、結尾都有重複的花紋,事情就變得很微妙。

莫里斯把這個想法寫進了伯克利 Unix 的系統軟體裡,但他沒寫解釋。幾個月後有人翻到這段程式碼,看看覺得不對勁,刪掉了。演算法做出來了,沒人看得懂,就等於沒做。

沃恩·普拉特(Vaughn Pratt)一兩年後獨立發現了同樣的東西,當時他研究的其實是迴文問題,跟文字搜尋八竿子打不著。克努特自己則是從另一個方向過來的,而且路徑相當繞。

那會兒史蒂夫·庫克在伯克利當教授,克努特說伯克利計算機系最大的失誤就是沒給他終身教職,後來庫克去了多倫多。庫克證明過一個關於棧自動機的定理:這種機器只能看棧頂,只能後進先出地存取,沒有別的記憶,比圖靈機弱得多;但如果它能識別某個語言,那麼一個普通計算機一定能在 n log n 的時間內識別同一個語言。

這個定理聽起來純粹是理論上的漂亮話。克努特拿它試了一個自己知道棧自動機能做、但想不出快辦法的問題。他自認是個不錯的程式設計師,可就是想不出來。於是他把庫克的構造一步步寫在黑板上,填滿一整塊,然後盯著那堆東西找規律。最後他看明白了。

“我之所以能寫出那個高效程式,完全是因為手裡有那個純粹抽象的定理。”(唐納德·克努特)

他寫過一篇小文章,標題叫《自動機理論可以是有用的》。在那之前他讀過大量自動機理論的論文,但它們從沒改善過他日常程式設計的水平,那些東西只是發表在期刊上、看起來有趣的內容。這一次不一樣:他想不出怎麼寫程式,手上有一個自動機理論的定理,然後他就會寫了。他說這是他人生中的一個轉折點。

他把這份筆記給普拉特看,普拉特說這跟我做的東西很像。三個人各自獨立發現了同一件事,每個人摸到的是大象的不同部位,拼起來就完整了。論文的署名按字母順序排,所以叫 KMP,其實應該叫 MPK。

他這輩子解過的最難的題:把大爆炸放慢

問到他遇到過最難的問題,他沒怎麼猶豫,答案很明確:巨組元的誕生(the birth of the giant component)。

先講背景。有 N 個點,彼此完全平等,沒有距離,沒有幾何。取出 π 的十進位制數字,兩位一組:31、41、59、26,拿第一組和第二組連一條邊,拿第三組和第四組連一條邊。或者乾脆擲骰子,每次隨機挑兩個端點連起來。π 在這裡沒有任何特殊性,只是沒人知道它的規律,拿來當隨機源用。

邊一條一條加上去。埃爾德什和雷尼研究過這個過程,叫隨機圖的演化。

神奇的地方在這兒:當邊數是 0.49N 的時候,比如一百萬個點、四十九萬條邊,圖幾乎全是一棵一棵孤立的樹,連一個環都沒有。而邊數變成 0.51N,五十一萬條邊,就會出現一個比其它所有連通塊大得多的塊。這就是巨組元。

幾乎就是相變。但它是個雙重相變,兩件事同時發生,這才是真正引人注目的地方。

伯克利的迪克·卡普有一批學生在模擬這個過程,每過一陣子給圖拍一張快照。然後傳出一個小道訊息:幾乎每一次觀察,都只有一個連通塊裡帶環。他們做了上百萬次實驗,只有三四次看到有一個以上的塊帶環。

斯坦福這邊聽到這個訊息,克努特他們的反應是:如果這是真的,那一定還有更多東西是真的,有一整套理論等著被發現。仔細一看,訊息不完全對,但幾乎對。確實存在兩個或三個帶環的塊同時存在的時刻,但那個時間視窗極短,快門速度不夠就拍不到。

於是問題變成:怎麼把這場大爆炸放慢,看清楚中間發生了什麼。

他定義了一個叫“複雜度”的量:邊數減去頂點數。一棵樹有十個點九個邊,複雜度是負一。一個單環連通塊,環上掛著一堆樹,邊數等於點數,複雜度是零。多一個環就多一條邊,複雜度是一,那叫雙環。複雜度加一就是環的個數。

演化過程是這樣的:先出現一個環;下一步,按那個小道訊息,應該變成雙環;但實際上有相當的機率,大約二十四分之五,分裂成兩個各自帶環的塊。再下一步,可能變成三個,也可能是一個雙環加一個單環,也可能是三個單環。

他把前五次躍遷的機率全算了出來。算到凌晨三點,數字出來了,分母是 23023。他盯著這個數看:1001 等於 7 乘 11 乘 13,這是他人生第一個程式教會他的事。23023 等於 7 乘 11 乘 13 乘 23。

一個隨便的分數不會這樣分解。分母裡出現這些小質數,說明背後有個理由。他當即換個角度,取對數,公式果然簡化了。

第二天,比爾·蓋茨來斯坦福,學校想說服他給新計算機系大樓捐錢。他們安排克努特去見蓋茨。他就把黑板上那張從一變到二、二十四分之五的演化圖講了一遍。當天結束時蓋茨跟發展辦公室的人說,那位克努特教授講巨組元的那段,我印象太深了。

克努特喜歡講這個故事,因為它說明理論電腦科學真的有用。

後來他和兩位合著者把整個問題做完了:那條小道訊息所說的“任何時刻都只有一個帶環的塊”,真實機率不是百分之百,大約是百分之八十七,而且能用 π 表示出來,形式像 12/π² 或者 8/π 那樣的東西。那是他這輩子證明過的最難的定理,花了很大力氣,也給隨機圖理論裡一大堆其它問題照了亮。

順帶說一句,這套東西和物理是通的:玻色愛因斯坦統計研究的正是分子如何在完全沒有幾何的情況下結合到一起。

為什麼 TeX 是開源的:收入是個閾值函式

TeX 釋出的時候,“開源”這個詞還不存在。他不要所有權。

因為他親眼見過所有權怎麼拖住一件事。五十年代末,IBM 的人做出了 Fortran,他們本可以規定只有 IBM 的機器能用這個語言,但他們沒有,他們說,誰能把 Fortran 翻譯到自己機器上,誰就可以做編譯器。反觀排版行業,每家廠商都有自己的頁面描述語言,使用者被綁死在某一家裝置上,一年後新機器出來,可印刷裝置的成本要攤二三十年。

他也不需要這筆錢。他有穩定的教職,書賣得夠多,孩子的教育費用不愁。

“收入是個閾值函式。不夠就是捱餓,過了那條線,你要麼開始想慈善,要麼開始想著怎麼把它帶走。”(唐納德·克努特)

他有一套自己的判斷標準:非平凡的軟體應該收費,平凡的軟體不該收費。他舉 Adobe Photoshop 的例子,說裡面有些真正諾貝爾獎級別的智慧財產權,那個撤銷功能可以在上千步複雜操作之後回到任意一箇中間狀態,背後一定有非常漂亮的演算法。專利的意義在於公開,讓人不能把它當商業秘密藏起來。

而他自己那臺筆記本跑 Ubuntu,不聯網,只用 U 盤在自己的 Mac 和它之間搬東西。原話是:我只把最重要的家當託付給 Linux。

你喜歡的字母、數字或符號是什麼

他翻到書的索引最後一頁,指著一個符號給採訪者看。那個符號來自蘇斯博士(Dr. Seuss)的《On Beyond Zebra》,書裡給這個符號起了名字。他說他小時候能把《Bartholomew Cubbins》背下來。蘇斯博士五十年代初還拍過一部電影,裡面有幾十架鋼琴同時演奏,整個佈景就是他繪本里那種奇想風格。

說到自己偏愛的符號,是 π。

理由很實用:需要一個隨機例子的時候就用 π,因為它沒有已知的規律。他拿出一個叫 Masyu 的謎題來舉例。盤面上有黑石和白石,像圍棋,要求畫一條閉合路徑,穿過白子時直行,經過黑子時必須直角轉彎。這個謎題好玩的地方在於不需要數字,純視覺,但比數獨更上癮。

他想把它寫進《計算機程式設計藝術》當例題,還寫了習題教人怎麼設計漂亮的 Masyu 題。於是他給自己出了個難題:拿 π 這個希臘字母的畫素圖,在每個該有石子的位置放一顆石子,然後給其中一些染成黑色、一些留白,要求整個謎題有唯一解。

結果真的存在唯一一種染色方式。

“π 是我用來舉例子時能證明自己沒有抄現成東西的來源。”(唐納德·克努特)

把美國地圖做成優雅標號,有人順手把 π 嵌了進去

他最近在寫優雅圖(graceful graph)。規則是:給每個頂點一個編號,每條邊連線的兩個頂點編號之差,恰好構成從 1 到邊數的一個排列,每條邊佔一個差值,一個不重複。

他拿了一張完全不對稱的真實地圖來試:美國四十九個州,加上哥倫比亞特區,阿拉斯加和夏威夷不算,因為得能開車過去。加州和俄勒岡、內華達、亞利桑那相鄰,每條相鄰關係是一條邊。問題是,能不能給每個州一個編號,讓所有邊對應的差值不重不漏?

他原本想搞個競賽,因為他自己只做到把所有邊的差值控制在一到一百一十七之間,中間還有空缺,實際上應該是一到一百零五左右。他的朋友湯姆·羅基茨一個下午就做出了完美解,競賽還沒開始就結束了。

更妙的是兩天後羅基茨回來說,他不僅找到了優雅標號,還讓華盛頓州的編號是 31、愛達荷州是 41,沿著美國北邊那條邊界,編號正好是 π 的數字。

克努特講這件事的時候是很高興的。他喜歡用 π,而 π 總會在最難的問題中間某個地方冒出來。

讀程式碼能認人:風格是技術能力,標點符號算不得什麼

他說自己讀程式的時候,能看出作者換人了。

他舉的例子是一個卡內基梅隆團隊寫的編譯器。讀到某一段,那個人明顯不知道怎麼高效地在暫存器之間搬東西,本來一條指令能做完的事要三條。這就是很明顯的風格切換。然後又有一些靈光一現的地方,一條指令幹了兩件事,因為那個人足夠了解機器,知道怎麼一步達成兩個目標。

“我能靠技術水準認出作者,但認不出節奏意義上的風格。”(唐納德·克努特)

那他自己的程式碼有什麼可辨認的特徵?他說現在都是文學化程式設計,英文和 C 混在一起。如果只看 C 那部分,別人大概會注意到他用大量全域性變數,別人不這麼用;他更傾向於內聯展開而不是函式呼叫;他用的是 C 的一個子集。

文學化程式設計是他自己認為最重要的產出

他說,TeX 專案帶來的最重要的東西是:他意識到程式是給人讀的,不只是給計算機讀的,而排版能極大地增強這件事。

他推薦了一本書,《Physically Based Rendering》,作者是 Matt Pharr 等人,拿過奧斯卡獎。電影裡所有的圖形特效都是演算法做出來的,而整本書就是一個文學化程式,不只告訴你陰影怎麼算、動畫和紋理需要的影象怎麼匯入,程式碼還能直接跑。

他把這看成教學程式設計的一種延伸:把程式當成一個故事來講。

“它作為程式能跑,同時人也能讀,尤其是一週之後或者一年之後的我自己。”(唐納德·克努特)

這是他自己設的驗收標準。一週後、一個月後、一年後,你自己還能不能輕鬆看懂。

什麼是優美的程式

他之前被問過這個問題,迴避了。這次他說了為什麼迴避:答案有幾十個,取決於你此刻在找什麼。

一個層面上,能跑就美。另一個層面上,容易看懂就美。文學化程式設計的形態也美。還有,它讓你笑出來,也是美。

他提到幽默這件事。有人問過他程式碼註釋裡該不該有幽默,他的答案是該。他給出一條很講究的標準:理想的情況是,讀者知道這兒大概有個笑話,只是還沒看懂,於是有了動力去想。

《計算機程式設計藝術》第一卷的初稿,主要審稿人是鮑勃·弗洛伊德。出版社把稿子拿給他看,他還專門問,這個笑話留不留。出版社甚至組織了焦點小組,問大家對一本講計算機程式設計的書裡有幽默怎麼看。他堅持了自己的原則,而且書裡還留著一些至今沒人解出來的笑話。

第二卷裡有一個密文。要解開它,得先破一個比現在人類已知方法能破的還要大的 RSA 金鑰。他說,如果計算機一直變快,也許一百年後會有人解出來,然後笑一下。

過早最佳化是萬惡之源,這話是在什麼語境下說的

他先澄清了“最佳化”這個詞在當時的意思。那會兒他是編譯器作者,最佳化指的是讓翻譯出來的程式碼在機器上跑得更快,就是給編譯器設最佳化等級那件事。他當時翻未刪節詞典,看到 optimizer 這個詞的解釋是“以樂觀的態度看待”。

他那句話針對的是另一種現象:寫程式的人會以為,自己寫得最費勁的那幾頁,計算機執行起來也最費勁。十頁程式碼,其中一頁折騰了一個星期,於是潛意識裡覺得機器讀到那一頁也會慢下來,會“看不懂,得小心點”。這當然很荒唐。

他做過一次測試。分析一個 Fortran 編譯器,發現它超過百分之八十的時間花在讀註釋卡上。而寫編譯器的人整天操心的是怎麼把帶多層括號的複雜表示式翻譯好,那部分連百分之一都不到。如果早知道八成時間在讀註釋卡,十分鐘就能讓編譯器快一倍以上。

這種認識只能來自程式寫完之後的實測,來自 profiling。

但他強調這句話還有另一層意思:有時候一種最佳化確實提升了執行速度,代價是程式下個星期就改不動了,因為你把資料結構換了,適應性沒了。所以電腦科學裡有一條重要原則叫延遲繫結,能晚決定的就別早決定。他說現在已經有人量化地研究過,延遲決策在製造業、在各種領域都有它的最優性。

而這句話之所以被這麼多人記住,是因為程式設計師心裡確實有一種對最佳化的偏愛。一份最佳化得極好的程式碼有它的優雅,那是另一種美。

Copilot、自動化,以及“讓人開心”和“正確”之間的選擇

採訪者給他講了 GitHub Copilot:寫幾行註釋,說明這段程式碼要幹什麼,它就把函式補全。用的是 OpenAI 的 Codex。採訪者說,這裡面有文學化程式設計的影子。

克努特聽完先追問了一句:那你怎麼知道它做得好不好?

然後他講了一個六十年代加州理工的同事。那個人課講得極好,聽完一小時你覺得全是激動人心的東西,再過一小時你回想,他到底說了什麼?那個人真的相信,計算機算得對不對不重要,重要的是它讓你開心。你老闆付了錢,你有了工作,能養活老婆孩子,這就行了。

“他相信快樂比真相更重要。他不相信有真相,不過他是個哲學家。”(唐納德·克努特)

他說這種思路正在擴散。越來越多的事情被“看起來能跑就行”接管。當有利益衝突的時候,兩邊都不明白決定是怎麼做出來的。現在大家還知道這是壞事,可五年十年之後,一層一層疊上去,就徹底脫鉤了。

反面他也認:自動化程度越高,人越能去做人最擅長的事。也許程式設計師該專注於程式設計裡那一小塊需要天才、需要人類心智的魔法,剩下的雜亂部分交給機器生成。

但他劃了線。他說自己永遠不會推薦學生去那種地方工作。他要的是理解。正確和快樂都排在它後面。如果這些工具帶來的是更好的醫療診斷,是幫某個科學實驗找到方向,是攻克疾病,那真是妙極了。可如果它影響到人的生命,那就得非常小心。現在看著像玩鬧,寫個小 JavaScript 幫網站做點事。一年、兩年、五年過去,你忘了底下的東西,你在上面繼續蓋,最後就是自主武器系統。

他也不迴避最終結局,這一點他看得很開:宇宙終有熱寂,他只是想把那件事往後推一推。而如果真到那一天,最好還有某種意識存在,能欣賞它。最好是人類的意識。

那費米悖論呢?為什麼收不到外星訊號?也許是他們也發明了這個東西。

他為什麼還抱有樂觀

他沒有直接回答樂觀還是悲觀,而是讓人看這個房間:鉛筆、書、桌子、麥克風、衣服、食物,每一樣都是某個人一件一件發明的。幾百萬人、幾十億件東西,我們繼承下來的這一整套文明。

這麼多東西,每一樣都可能出問題,每一樣都可能帶來負面效應,而它居然大體上運轉著。這非常不可思議,而這正是他樂觀的來源,人工智慧也不例外。

“我們開著車過橋,用著各種根本不知道怎麼運作的技術。幾百萬聰明人各負責其中一小塊,它大體上不出錯,出錯的時候我們能發現,然後改進,雖然常常改得不太理想。”(唐納德·克努特)

但緊接著他補了一句,語氣很輕:他能想到的改進辦法,都要求人是理性的。而他對人是否理性這件事,信心正在流失。

採訪者接話說,人也許不理性,但人很聰明,而且以自己的方式很美。多數人有對彼此好的意願,只要有機會,愛最終會贏。

彭羅斯、意識,以及“超出知識範圍”

羅傑·彭羅斯主張,人發現數學觀念的方式不止是計算,圖靈機做不到人腦能做的全部事情,他寫過一本關於意識的書。克努特的女兒的孩子和彭羅斯的孩子在牛津一起玩過。

克努特說,他可以回答是或不是,但他沒有理由。他反覆強調自己在這上頭沒有專門知識。這是個無法回答的問題,這話的意思只是他現在看不清,還談不上永遠看不清。

他打了個比方,有多少天使能在針尖上跳舞。他說,這樣的事我們可以推測,但他不希望別人說,克努特說過這個,所以他很聰明,所以那一定是對的。他真正想說的是:現在還沒到能問清楚的時候。

採訪者說他個人相信,人類心智的運作終有一天在科學可及的範圍內。克努特說,這完全可能,我並不否認,只是你現在問我,我沒法給出判斷。他還接了句玩笑:也說不定宇宙是某個 AI 造出來的,智慧設計什麼的,全是一個 AI 乾的。

他也提到約翰·麥卡錫對這類主張完全不以為然。還提到二十年前在美國藝術與科學院的一次研討會,開場就說,關於意識寫過的一切都是胡扯。他不太同意這個說法,但也沒打算站在哪一邊。

真正讓他覺得有意思的是那些實驗:神經學家指出,人在意識到自己做出決定之前,訊號已經送到手臂上了。還有萊斯·瓦利安特給出的一個大腦架構,以及克里斯托斯·帕帕季米特里烏一年前在《美國科學院院刊》上和另外兩人發表的模型,這個模型能產生與意識實驗相當吻合的結果,而且有一套機器語言,可以在上面寫程式碼、檢驗假設。

他自己最認可的解釋是這樣的:大腦內部是一場持續的適者生存競爭。他現在說話,所有可能想說的東西都在裡面,像一場投票,某一句話贏了,它影響下一句。聽起來像有一個清晰的敘事在發生,像他本人在掌控,可底下可能是一堆想法在激烈競爭,最後機器編出一個連貫的故事給你,讓你相信。

他把這比作文學化程式設計。你不知道底下在跑什麼程式,但你拿到了一個好故事。

生命遊戲:他不覺得自己在玩弄生命,但他會猶豫要不要關機

他說生命遊戲是絕妙的東西,展示了在創造者什麼都不懂的情況下,事物怎麼自己演化起來。

但對他而言,生命遊戲最重要的意義在別處:它把自由意志這件事說清楚了。它顯然是徹底決定論的。可他說,任何有過孩子的人,都很難不相信自由意志。

康威說過,當他玩到某局特別有意思的時候,會猶豫把計算機關掉是不是不道德。

從簡單的初始條件、簡單的規則出發,你完全知道系統在怎麼運作,它是決定論的。可只要你允許自己忘掉一部分細節,退後一步去看那些湧現出來的更大的結構,它們看起來就像活的。

採訪者接了一句:如果宇宙是有限的,那我們其實都活在生命遊戲裡,只是更快一點。

至於能不能用分析演算法的方法分析生命遊戲,克努特說可以,他在第四卷第六分冊裡有十幾個習題就是幹這個的。他還提到比爾·戈斯珀的演算法讓 Golly 跑得快了成千上萬倍。

把最討厭的事放在最前面

他的時間安排原則是:每天先做待辦清單上他最討厭的那件事。週末回頭看,會很愉快,因為討厭的事都幹完了。

他媽媽教過他另一條,跟搞機器人的人說的“規劃”不太一樣:看見有什麼需要做,就去做。別先排個一二三,看見了就撿起來。

這兩條怎麼並存?他的說法是,任何時刻手上都有一組任務,那麼一個好的啟發式是,先做那個你最不想做、而且再拖也不會做得更好的。有些事確實先做別的會更好,有些則相反,拖久了會把當初的思路忘掉,反而更難。

他剛寫完書裡一個很難的部分,現在在做比較有意思的部分。但寫書的時候,他希望讀者覺得他全程都很快樂,語氣是向上的,可以有幽默,可以說這個很酷。他得把過程的痛苦藏起來。通往那種興奮的路是痛苦的。

疫情期間他的效率掉了一半。原因是溝通全靠寫字,而寫字慢。他不願意發出一句寫得不好的話,所以要反覆讀、反覆改。還有圖書館關門之類的事。

給年輕人的建議:人生是二分查詢

他的建議跟以前一樣:不要因為某個東西流行就去做,要做你個人覺得被召喚去做的事,而不是別人期待你做的事。

怎麼知道自己被召喚了?試試看,成了或者沒成,你都會更瞭解自己。人生就是一次二分查詢。試一件事,發現自己在這上面有底子,或者發現只要再努把力就能做到。試另一件事,發現自己完全沒有直覺,看起來跟自己不搭。

他也承認自己有個反向的毛病:看見所有人都在往一個方向走,他會想,競爭有點激烈。

多數時候他只是玩自己覺得有意思的東西,後來才明白,他學到的最重要的一件事是怎麼對幾乎任何事都產生興趣,怎麼不無聊。

“聽見小孩說這個好無聊,我會很難過。一個人如果不得不承認自己沒能力從一件事裡找到有意思的地方,他應該為此不安。”(唐納德·克努特)

他說這是一種技能,一種還沒學會怎麼享受生活的表現,非得有人來娛樂自己才行。

他提到在新冠疫情最嚴重的時候,很多天他見不到任何一個人,但他照樣能找到別的辦法,那段時間他過得相當愉快。那天他提前幾分鐘到了福斯特城,在附近走了走,在幾個街區外的家得寶苗圃看見一些很美的花。

“生活充滿這樣奇妙的東西。有時候我就坐在那兒盯著樹看。”(唐納德·克努特)

生命的意義

他先拿 42 擋了一下,然後說了實話。

他信上帝存在,雖然他說自己完全不知道這句話是什麼意思。他相信有某種超出人類能力的東西存在,也許是某種 AI,不管是什麼。他相信自己可以去摸索怎麼和那個存在想要他做的事共振。

他說自己不敢說接近過,但他在努力。他做的選擇不帶策略性,他只是試著想象自己在遵循某個人(那個存在)的意願,哪怕他聰明不到能弄明白那是什麼。

那個存在大概聰明到能給他線索,也能讓從一個線索走到下一個線索的整段路程變得有趣。

他最近讀肯·福萊特的《來自聖彼得堡的人》,講一戰前的那段。書裡丘吉爾看到德國把黃金儲備全砸進了軍備,英國一旦被打就完了,所以想讓俄國從另一側夾擊,因為德國沒有足夠的兵力兩線作戰。而俄國有個無政府主義者認為,戰爭是領袖發動的,死的卻是普通人,所以他要去刺殺來訪的俄國親王,讓沙皇不籤這個同盟,這樣成千上萬本來不會死的俄國人就能活下來。

他讀完的感受是:如果他被放在一個要為他人生命負責的位置上,大多數情況下,他對自己的任何一個決定都不會有信心。這些問題對人類來說太難了,對他更是。

採訪者補了一句:對自己沒把握,同時又必須做出決定並承擔它,這兩件事合在一起其實是件好事。

克努特沒有反駁。他說他對人有信心,偉大的領導者會出現,幫助建設一個更好的世界,這就是民主的希望。採訪者說,希望我們能用手上的演算法增強他們的能力。

節目最後,他留給聽眾的是一句他自己說過很多次的話:

“科學是我們理解得足夠透徹、可以講給計算機聽的東西。藝術是我們做的其它一切。”(唐納德·克努特)

這句話可以當作整場對話的註腳。他這一輩子在做的,就是把儘可能多的東西講清楚到能讓機器執行,剩下的那些講不清的,就留給藝術、留給幽默、留給凌晨三點因為一個分母裡的小質數而突然看清的一整套理論。

  • 手上有一個具體問題卡住的時候,去翻純理論的文獻。克努特寫不出字串匹配的高效程式,最後是庫克一個關於棧自動機的抽象定理給了他那把鑰匙。理論和實踐的距離,往往比你以為的近。
  • 設計任何反饋機制之前,先想清楚你要的是哪一種結果。學習系統的獎勵函式決定了它學會什麼:只懲罰錯誤,它學會不輸;獎勵妙手,它學會冒險。克努特的井字棋收斂成了必和,他自己說得很明白。
  • 做一個東西給別人用之前,先問一句“你怎麼知道它是對的”。Copilot 這類工具最好用在你能獨立驗證結果的地方,別用在驗證成本高於重寫成本的地方。
  • 最佳化之前先測量。寫程式碼時覺得最難的那幾頁,往往不是機器花時間最多的地方。Fortran 編譯器八成時間在讀註釋卡,這個事實只有跑起來才知道。
  • 給自己的程式碼寫給人看的部分。檢驗標準很簡單:一年後你還能不能輕鬆讀懂。做不到,就重寫。
  • 每天先做清單上最不想做的那件事。拖不會讓它變簡單,只會讓你忘掉當初的思路。
  • 把“不無聊”當成一項要練的技能。覺得一件事沒意思,多半是自己還沒找到看它的角度。
  • 試錯是二分查詢。不要因為某個方向流行就走進去,也不要因為競爭激烈就繞開。想清楚自己有沒有那個直覺,然後動手試一次,答案會比任何規劃都清楚。
文稿來自公開 Kaggle 資料集(rajneesh231/lex-fridman-podcast-transcript),為早期自動轉錄存檔,可能存在識別錯誤。
The following is a conversation with Donald Knuth, his second time on this podcast. Don is a legendary computer scientist, Turing Award winner, father of algorithm analysis, author of The Art of Computer Programming, creator of tech that led to late tech, and one of the kindest and most fascinating human beings I've ever got a chance to talk to. I wrote him a letter a long time ago, he responded, and the rest, as they say, is history. We've interacted many times since then, and every time has been joyful and inspiring. To support this podcast, please check out our sponsors in the description. This is the Lex Friedman Podcast, and here is my conversation with Donald Knuth. Don Knuth, your first large scale program, you wrote it in IBM 650 Assembler in the summer of 1957. I wrote it in decimal machine language. I didn't know about Assembler until a year later. But the year, 1957, and the program is tic tac toe. Yeah, I might have learned about Assembler later that summer, I probably did. In 1957, hardly anybody had heard of Assemblers. You looked at the user manuals, and how would you write a program for this machine? It would say 69, which meant load the distributor, and then you would give the address of the number you wanted to load into the distributor. Yesterday, my friend Doug Spicer at the Computer History Museum sent me a link to something that just went on YouTube. It was IBM's progress report from 1956, which is very contemporary with 1957. In 1956, IBM had donated to Stanford University an IBM 650, one of the first ones, when they showed a picture of the assembly line for IBM 650s, and they said, this is number 500 or something coming off the assembly line. I had never seen so many IBM 650s I did in this movie that's on YouTube now. It showed the picture from Stanford. They said, look, we donated one of these to Stanford, one to MIT, and they mentioned one other college. In December of 1956, they donated to my university, Case Tech. Anyway, they showed a picture then of a class session where a guy was teaching programming, and on the blackboard, it said 69, 8,000. He was teaching them how to write code for this IBM 650, which was in decimal numbers. The instructions were 10 decimal digits. You had two digits that said what to do, four digits to say what to do it to, and four more digits to say where to get your next instruction. And there's a manual that describes what each of the numbers mean. If the manual had been well written, I probably never would have gone into computer science, but it was so badly written, I figured that I must have a talent for it because I'm only a freshman and I could write a better manual. That's what you did. And so I started working at the computer center and wrote some manuals then. But this was the way we did it. And my first program then was June of 1957. The Tic Tac Toe? No, that was the second program. The first, the third program. The first program was factoring a number. So you dial a number on the switches. I mean, you sat at this big mainframe and you turn the dials, set a number, and then it would punch out the factors of that number on cards. So that's the input, is the number? The input was, yeah, the input was a number, a tentative number. And the output was its factors. And I wrote that program. I still have a copy of it somewhere. How many lines of code? Do you remember? Well, yeah, it started out as about 20, but then I kept having to debug it. And I discovered debugging, of course, when I wrote my first program. What does debugging look like on a program with just all numbers? Well, you sit there and you, I don't remember how I got it into the machine, but I think there was a way to punch it on cards. So each instruction would be one card. Or maybe I could get seven instructions on a card, eight instructions. I don't know. But anyway, so I'm sitting there at the console of the machine. I mean, I'm doing this at night when nobody else is around. Of course. And so you have one set of switches where you dial the number I'm inputting, but there's another switch that says, okay, now execute one instruction and show me what you did. Or there was another four switches that say, stop if you get to that instruction. So I can say, now go until you get there again and watch. So I could watch, it would take that number and it would divide it by two. And if there's no remainder, then okay, two is a factor. So then I work on it. But if not divisible by two, divide by three. Keep trying until you know you're at the end. And you would find a bug if you were just surprised that something weird happened? Well, certainly. I mean, first of all, I might have tried to divide by one instead of two. You go off by one error, as people make all the time. Yes. But maybe I go to the wrong instruction. Maybe I left something in a register that I shouldn't have done. But the first bugs were pretty... Probably on the first night, I was able to get the factors of 30 as equal to two, three, and five. Okay. Sorry to interrupt. So you're sitting there late at night. Yeah. So it feels like you spent many years late at night working on a computer. Oh, yeah. So what's that like? So most of the world is sleeping. And you have to be there at night because that's when you get access to the computer. Between my freshman and sophomore year, I didn't need sleep. I used to do all nighters. When I was in high school, I used to do the whole student newspaper every Monday night. I would just stay up all night and it would be done on Tuesday morning. I didn't get ulcers and stuff like that until later. I don't know if you know Rodney Brooks. Rod Brooks, of course. Yeah. He told me a story that he really looked up to you. He was actually afraid of you. Well, vice versa, I must say. But he tells a story when you were working on tech that they screwed up something with a machine. I think this might have been MIT. I don't know. And you were waiting for them to fix the machine so you can get back to work late at night. That happened all the time. He was really intimidated. He's like, Dr. Knuth is not happy with this. That's interesting. But no, the machine at Stanford AI Lab was down an awful lot because they had many talented programmers changing the operating system every day. So the operating system was getting better every day, but it was also crashing. So I wrote almost the entire manual for tech during downtime of that machine. But that's another story. Well, he was saying it's a hardware problem. They tried to fix it and they reinserted something and smoke was everywhere. Oh, wow. Well, that didn't happen as often as the operating system. It's a funny story because he was saying there's this tall Don Knuth that I look up to and there was pressure to fix the computer. It's funny. The kind of things we remember that stick in our memory. Well, okay. Yeah. Well, I could tell you a bunch of Rod Brooks stories too, but let's go back to the 650. So I'm debugging my first program and I had more bugs in it than a number of lines of code. I mean, the number of lines of code kept growing. And let me explain. So I had to punch the answers on cards. So suppose I'm factoring the number 30, then I got to put two somewhere on the card. I got to put a three somewhere on the card. I got to put a five somewhere on the card. And here's my first program. I probably screwed up and it fell off the edge of the card or something like that. But I didn't realize that there are some tentative numbers that have more than eight factors. And the card has only 80 columns. And so I need 10 columns for every factor. So my first program didn't take account for the fact that I would have to punch more than one card. My first program just lined stuff up in memory and then punched the card. So by the time I finished, I had to deal with lots of things. Also, if you put a large prime number in there, my program might have sat there for 10 minutes. The 650 was pretty slow. And so it would sit there spinning its wheels and you wouldn't know if it was in a loop or whatever. You said 10 digit? 10 digits. Yeah. So I think the largest is sort of 999999997 or something like that. That would take me a while for that first one. Anyway, that was my first program. Well, what was your goal with that program? Was there something you were hoping to find a large prime maybe or the opposite? No, my goal was to see the lights flashing and understand how this magical machine would be able to do something that took so long by hand. So what was your second program? My second program was a converted number from binary to decimal or something like that. It was much simpler. It didn't have that many bugs in it. My third program was tic tac toe. Yeah. And it had some machines. So the tic tac toe program is interesting on many levels, but one of them is that it had some you can call machine learning in it. Yeah, that's right. I don't know how long it's going to be before the name of our field has changed from computer science to machine learning. But anyway, it was my first experience with machine learning. Okay. So here we had... Yeah. How does the program... Well, first of all, what is the problem you were solving? What is tic tac toe? What are we talking about? And then how was it designed? Right. So you've got a three by three grid and each can be in three states. It can be empty or it can have an X or an O. Yeah. All right. So three to the ninth is a... Well, how big is it? I should know. But it's 81 times three. So anyway, eight is like two to the third. And so that would be like two to the sixth. But that would be 64. Then you have to... Anyway, I love how you're doing the calculation. So it's a lot of... Anyway, the three comes from the fact that it's either empty, an X or an O. Right. And the 650 was a machine that had only two thousand ten digit words. You go from zero zero zero zero to one nine nine nine and that's it. And each word you have a ten digit number. So that's not many bits. I mean, I got to have... In order to have a memory of every position I've seen, I need three to the ninth bits. Okay. But it was a decimal machine too. It didn't have bits. But it did have strange instruction where if you had a ten digit number, but all the digits were either eight or nine, you'd be eight, nine, nine, eight or something like that. You could make a test whether it was eight or nine. That was one of the strange things IBM engineers put into the machine. I have no idea why. Well, hardly ever used. But anyway, I needed one digit for every position I'd seen. Zero meant it was a bad position. Nine meant it was good position. And I think I started out at five or six. But if you win a game, then you increase the value of that position for you, but you decrease it for your opponent. But I had that much total memory for every possible position was one digit. And I had a total of 20,000 digits, which had to also include my program and all the logic and everything, including how to ask the user what the moves are and things like this. So I think I had to work it out. Every position in tic tac toe is equivalent to roughly eight others because you can rotate the board, which gives you a factor of four, and you can also flip it over. And that's another factor too. So I might have needed only three to the ninth over eight positions plus a little bit. But anyway, that was a part of the program to squeeze it into this tiny... So you tried to find an efficient representation that took account for that kind of rotation. I had to, otherwise I couldn't do the learning. But I had three parts to my tic tac toe program. And I called it brain one, brain two, and brain three. So brain one just played at random. It's your turn. Okay. You got to put an X somewhere. It has to go in an empty space, but that's it. Okay. Choose one and play it. Brain two had a canned routine. And I think it also... Maybe it assumed you were the first player, or maybe it allowed you to be first. I think you're allowed to be either first or second, but had a canned built in strategy known to be optimum for tic tac toe. Before I forget, by the way, I learned many years later that Charles Babbage had thought about programming tic tac toe for his dream machine that he was never able to finish. Wow. So that was the program he thought about. More than 100 years ago. He did that. Okay. And I had, however, been influenced by a demonstration at the Museum of Science and Industry in Chicago. It's like Boston Science Museum. I think Bell Labs had prepared a special exhibit about telephones and relay technology, and they had a tic tac toe playing machine as part of that exhibit. So that had been one of my... Something I'd seen before I was a freshman in college and inspired me to see if I could write a program for it. Okay. So anyway, I had brain one, random, knowing nothing. Brain two, knowing everything. Then brain three was the learning one. And I could play brain one against brain one, brain one against brain two, and so on. And so you could also play against the user, against the live users. So I started going, the learning thing, and I said, okay, take two random people just playing tic tac toe knowing nothing. And after about... I forget the number now, but it converged after about 600 games to a safe draw. The way my program learned was actually, it learned how not to make mistakes. It didn't try to do anything for winning, it just tried to say not losing. So that was probably because of the way I designed the learning thing. I could have had a different reinforcement function that would reward brilliant play. And if I took a novice against a skilled player, it was able to learn how to play a good game. And that was really my... But after I finished that, I felt I understood programming. Yeah. Did a curiosity and interest in learning systems persist for you? So why did you want brain three to learn? Yeah. I think naturally, we're talking about Rod Brooks. He was teaching all kinds of very small devices to learn stuff. If a leaf drops off of a tree, he was saying something, well, it learns if there's wind or not. But I mean, he pushed that a little bit too far. But he said he could probably train some little mini bugs to scour out dishes if he had enough financial support. I don't know. Can I ask you about that? He also mentioned that during those years, there was discussion inspired by Turing about computation, of what is computation. Yeah. I never thought about any stuff like that. That was way too philosophical. I was a freshman It simulates the cellular automata, like Game of Life? Yeah, you got to check it out. Can I ask you about John Conway? Yes. In fact, I'm just reading now the issue of mathematical intelligence that came in last week. It's a whole issue devoted to remembrance of him. Did you know him? I slept overnight in his house several times. Yeah. He recently passed away. Yeah, he died a year ago, May, I think it was, of COVID. What are some memories of him, of his work, that stand out for you? On a technical level, did any of his work inspire you? On a personal level, did he himself inspire you in some way? Absolutely, all of those things. But let's see, when did I first meet him? I guess I first met him at Oxford in 1967 when I was... Okay, that's a long time ago. Yeah, you were minus 20 years old or something, I don't know, 1967. But there was a conference where I think I was speaking about something known as the Knuth Bendix algorithm now, but he gave a famous talk about knots. And I didn't know at the time, but anyway, that talk had now... The source of thousands and thousands of papers since then. And he was reported on something that he had done in high school almost 10 years earlier before this conference, but he never published it. And he climaxed his talk by building some knots. You have these little plastic things that you can stick together. It's something like Lego, but easier. And so he made a whole bunch of knots in front of the audience and so on and then disassembled it. So it was a dramatic lecture before he had learned how to give even more dramatic lectures later. Were you at that lecture? And I was there, yeah, because I was at the same conference. For some reason, I happened to be in Calgary the same day that he was visiting Calgary. And it was the spring of 72, I'm pretty sure. And we had lunch together and he wrote down during the lunch on a napkin all of the facts about what he called numbers. And he covered the napkin with the theorems about his idea of numbers. And I thought it was incredibly beautiful. And later in 1972, my sabbatical year began and I went to Norway. And in December of that year, in the middle of the night, the thought came to me, you know, Conway's theory about numbers would be a great thing to teach students how to invent research and what the joys are of research. And I had also read a book in dialogue by Alfred Renyi, kind of a Socratic thing where the two characters were talking to each other about mathematics. And so at the end, in the morning, I woke up my wife and said, Jill, I think I want to write a book about Conway's theory. And, you know, I'm supposed to be writing the Art of Computer Program and doing all this other stuff, but I really want to write this other book. And so we made this plan. But I said, I thought I could write it in a week. And we made the plan then. So in January, I rented a room in a hotel in downtown Oslo. We were in sabbatical in Norway. And I rented the hotel in downtown Oslo and did nothing else except write up Conway's theory. And I changed the name to Surreal Numbers. And so this book is now published as Surreal Numbers. And, you know, we figured out, we'd always wonder what would be like to have a fair enough hotel room. So we figured out that she would visit me twice during the week. Things like this, you know, we would try to sneak in. This hotel was run by a mission organization. These ladies were probably very strict, but anyway. So, and it's a wild week in every way. But the thing is, I had lost that. I had lost that napkin in which he wrote the theory, but I looked for it, but I couldn't find it. So I tried to recreate from memory what he had told me at that lunch in Calgary. And as I wrote the book, I was going through exactly what I, what the characters in the book were supposed to be doing. So I start with the two axioms that start out the whole thing and everything is defined, flows from that, but you have to discover why. And every mistake that I make as I'm trying to discover it, my characters make too. And so it's a long, long story. But I worked through this week and it was one of the most intense weeks of my life and I described it in other places. But anyway, after six days, I finished it and on the seventh day I rested and I sent to my secretary to type it. It was flowing as I was writing it faster than I could think almost. But after I finished and tried to write a letter to my secretary telling her how to type it, I couldn't write anymore. You gave it everything. The muse had left me completely. Can you explain how that week could have happened? Like why? That seems like such a magical week of productivity. I have no idea. But anyway, there was some... It was almost as if I was channeling. So the book was typed, they sent it to Conway and he said, well, Don, you got the one axiom wrong. Is there a difference between less than or equal and not greater than? The opposite of being greater than and less than or equal. But anyway, technically it can make a difference when you're developing a logical theory. And the way I had chosen was harder to do than John's original. And we visited him at his house in Cambridge in April. We took a boat actually from Norway over to across the channel and so on and stayed with him for some days. And we talked about all kinds of things he had. He had puzzles that I'd never heard of before. He had a great way to solve the game of solitaire. Many of the common interests that he'd never written them up. But anyway, then in the summertime, I took another week off and went to a Conway place in the mountains of Norway and rewrote the book using the correct axiom. So that was the most intensive connection with Conway. After that... It started with a napkin. It started with a napkin. But we would run into each other. The next really... And I was giving lectures in Montreal. I was giving a series of seven lectures about the topic called Stable Marriages. And he arrived in Montreal between my sixth and seventh lecture. And we met at a party. And I started telling him about the topic I was doing. And he sat and thought about it. He came up with a beautiful theory to show that the... I mean, in technical terms, it's that the set of all stable marriages forms a lattice. And there was a simple way to find the greatest lower bound of two stable pairings and least upper bound of two stable marriage. And so I could use it in my lecture the next day. And he came up with this theorem during the party. And it's a distributive lattice. It added greatly to the theory of stable matching. So you mentioned your wife, Jill. You mentioned stable marriage. Can you tell the story of how you two met? So we celebrated 60 years of wedded bliss last month. And we met because I was dating her roommate. This was my sophomore year, her freshman year. I was dating her roommate. And I wanted her advice on strategy or something like this. And anyway, I found I enjoyed her advice better than her. I enjoyed her roommate. You guys were majoring the same thing? No, no, no. Because I read something about working on a computer in grad school on a difficult computer science topic. So she's an artist and I'm a geek. What was she doing with a computer science book? Was it the manual that she was reading? What was she reading? I wrote the manual that she had to take a class in computer science. So you're the tutor? No, no. There were terrible times trying to learn certain concepts, but I learned art from her. And so we worked together occasionally in design projects. But every year we write a Christmas card and we each have to compromise our own notions of beauty. When did you fall in love with her? That day that I asked her about her roommate. I don't mind telling these things, depending on how far you go. I promise not to go too far. Let me tell you this. I never really enjoyed kissing until I found how she did it. Wow. And 60 years. Is there a secret you can say in terms of stable marriages, of how you stayed together so long? The topic stable marriage, by the way, is a technical term. Yes. It's a joke, Don. But two different people will have to learn how to compromise and work together and you're going to have ups and downs and crises and so on. And so as long as you don't set your expectation on having 24 hours of bliss, then there's a lot of hope for stability. But if you decide that there's going to be no frustration, then... So you're going to have to compromise on your notions of beauty when you write Christmas cards. That's it. You mentioned that Richard Feynman was someone you looked up to. Yeah. Probably you've met him in Caltech. Well, we knew each other, yeah, at Caltech, for sure, yeah. You are one of the seminal personalities of computer science. He's one for physics. Is there specific things you picked up from him by way of inspiration? So we used to go to each other's lectures. But if I saw him sitting in the front row, it would throw me for a loop, actually. I would miss a few sentences. What unique story do I have? I often refer to his time in Brazil where he essentially said they were teaching all the physics students the wrong way. They were just learning how to pass exams and not learning any physics. And he said, if you want me to prove it, here, I'll turn any page of this textbook and I'll tell you what's wrong with this page. And he did so. And the textbook had been written by his host, and he was a great teacher. And he had previously asked his host if he was supposed to tell the truth. But anyway, it epitomizes the way education goes wrong in all kinds of fields and has to periodically be brought back from a process of giving credentials to a process of giving knowledge. That's probably a story that continues to this day in a bunch of places where it's too easy for educational institutions to fall into credentialism versus inspirationalism. I don't know if those are words, but sort of understanding versus just giving a little plaque. It's very much like what we were talking about. If you want to be able to believe the answer, a computer is doing that. One of the things Bob Floyd showed me in the 60s, there was a... He loved this cartoon. There were two guys standing in front of... In those days, a computer was a big thing. And the first guy says to the other guy, he said, this machine can do in one second what it would take a million people to do in a hundred years. And the other guy says, oh, so how do you know it's right? That's a good line. Is there some interesting distinction between physics and math to you? Have you looked at physics much? Speaking of Richard Feynman, the difference between the physics community, the physics way of thinking, the physics intuition versus the theoretical computer science, the mathematical sciences, do you see that as a gap? Are they strongly overlapping? It's quite different, in my opinion. I started as a physics major and I switched into math. And probably the reason was that I could get A plus on the physics exam, but I never had any idea why I would have been able to come up with the problems that were on those exams. But in math, I knew why the teacher set those problems and I thought of other problems that I could set, too. And I believe it's quite a different mentality. It has to do with your philosophy of geekdom? No, it's... I mean, some of my computer scientist friends are really good at physics and others are really good at physics and others are not. And I'm really good at algebra, but not at geometry. Talk about different parts of mathematics. So there are different kinds of physics, but physicists think of things in terms of waves. And I can think of things in terms of waves, but it's like a dog walking on hind legs if I'm thinking about it. So you basically like to see the world in discrete ways and then physics is more continuous. Yeah. I'm not sure if Turing would have been a great physicist. I think he was a pretty good chemist, but I don't know. But anyway, I see things... I believe that computer science is largely driven by people who have brains who are good at resonating with certain kinds of concepts. And like quantum computers, it takes a different kind of brain. Yeah, that's interesting. Yeah. Well, quantum computers is almost like at the intersection in terms of brain between computer science and physics because it involves both at least at this time. But there is like the physicists I've known, they have incredibly powerful intuition. And I mean, statistical mechanics. So I study statistical mechanics and I mean, random processes are related to algorithms in a lot of ways. But there's lots of different flavors of physics as there are different flavors of mathematics as well. But the thing is that I don't see... Well, actually, when they talk to physicists, they use a completely different language than when they're writing expository papers. And so I didn't understand quantum mechanics at all from reading about it in Scientific American. But when I read how they describe it to each other, talking about eigenvalues and various mathematical terms that made sense, then it made sense to me. But Hawking said that every formula you put in a book, you lose half of your readers. And so he didn't put any formulas in the book. So I couldn't understand his book at all. You could say you understood it, but I really didn't. Well, Feynman also spoke in this way. So Feynman, I think, prided himself on really strong intuition. But at the same time, he was hiding all the really good, the deep computation he was doing. So there was one thing that I was never able to... I wish I'd had more time to work out with him. But I guess I could describe it for you. There's something that got my name attached to it called Knuth arrow notation. But it's a notation for very large numbers. And so I find out that somebody invented it in the 1830s. It's fairly easy to understand anyway. So you start with x plus x plus x plus x n times, and you can call that xn. So xn is multiplication. Then you take x times x times x times x n times. That gives you exponentiation, x to the nth power. So that's one arrow. So xn with no arrows is multiplication. Arrow n is x to the nth power. Yeah. So just to clarify for the... So x times x times x n times is obviously xn. x plus x plus x n times. Oh, yeah. Okay. And then multiplication is x to the n. And then here the arrow is when you're doing the same kind of repetitive operation for the exponential. So I put in one arrow, and I get x to the nth power. Now I put in two arrows. And that takes x to the x to the x to the x n times power. So in other words, if it's two double arrow three, that would be two to the two to the two. So that would be two to the fourth power. That'd be 16. Okay. So that's the double arrow. And now you can do a triple arrow, of course, and so on. And I had this paper called, well, essentially big numbers. You try to impress your friend, but by saying a number they've never thought of before. And I gave a special name for it and designed a font for it that has script k and so on. But it really is 10, I think, like 10 quadruple arrow three or something like that. And I claim that that number is so mind boggling that you can't comprehend how large it is. But anyway, I talked to Feynman about this, and he said, oh, let's just use double arrow. But instead of taking integers, let's consider complex numbers. I mean, okay, x arrow arrow two, that means x to the x. But what about x double arrow 2.5? Well, that's not too hard to figure out. That's interpolate between those. But what about x double arrow i or 1 plus i or some complex number? And so he claimed that there was no analytic function that would do the job. But I didn't know how he could claim that that wasn't true. And his next question was, did then have a complex number of arrows? Yeah. Okay. Wow. Okay. Okay. So that's Feynman. That's Feynman. Yeah. Can you describe what the Knuth Morris Pratt algorithm does? And how did you come to develop it? One of the many things that you're known for and has your name attached to it. Yeah. All right. So it should be actually Morris Pratt Knuth. But we decided to use alphabetical order when we published the paper. The problem is something that everybody knows now if they're using a search engine. You have a large collection of text, and you want to know if the word Knuth appears anywhere in the text, let's say, or some other word that's less interesting than Knuth. But anyway. That's the most interesting word. Like Morris or something. Like Morris, right. So anyway, we have a large piece of text, and it's all one long, one dimensional thing. First letter, second letter, et cetera, et cetera, et cetera. And so you'd like to be able to do this quickly. And the obvious way is let's say we're looking for Morris. Okay. So we would go through and wait till we get to letter M. Then we look at the next word, and sure enough, it's an O, and then an R. But then, too bad, the next letter is E. So we missed out on Morris. And so we go back and start looking for another. So that's the obvious way to do it. All right. And Jim Morris noticed there was a more clever way to do it. The obvious way would have started... Let's say we found that letter M had character position 1000. So it would have started next at character position 1001. But he said, no, look, we already read the O and the R, and we know that they aren't Ms. So we can start... We don't have to read those over again. And this gets pretty tricky when the word isn't Morris, but it's more like abracadabra, where you have patterns that are occurring. Like repeating patterns at the beginning, at the middle, at the end. Right. So he worked it out, and he put it into the system software at Berkeley, I think it was, where he was writing some... Berkeley Unix, I think, was some routine that was supposed to find occurrences of patterns in text. But he didn't explain it. And so he found out that several months later, somebody had looked at it, didn't look right, and so they ripped it out. So he had this algorithm, but it didn't make it through because it wasn't understood. Nobody knew about this particularly. Von Pratt also had independently discovered it a year or two later. I forget why. I think Von was studying some technical problem about palindromes or something like that. He wasn't really... Von wasn't working on text searching, but he was working on an abstract problem that was related. Well, at that time, Steve Cook was professor at Berkeley, and it was the greatest mistake that Berkeley CS department made was not to give him tenure. So Steve went to Toronto. But I knew Steve while he was at Berkeley, and he had come up with a very peculiar theorem about a technical concept called a stack automaton. And a stack automaton is a machine that can't do everything a Turing machine can do, but it can only look at something at the top of a stack, or it can put more things on the stack, or it can take things off of the stack. It can't remember a long string of symbols, but it can remember them in reverse order. So if you tell a stack automaton A, B, C, D, E, it can tell you afterwards E, D, C, B, A. It doesn't have any other memory except this one thing that it can see. And Steve Cook proved this amazing thing that says if a stack automaton can recognize a language where the strings of the language are length n in any amount of time whatsoever, so the stack automaton might use a zillion steps, a regular computer can recognize that same language in time n log n. So Steve had a way of transforming a computation that goes on and on and on and on using different data structures into something that you can do on a regular computer fast. The stack automaton goes slow, but somehow the fact that it can do it at all means that there has to be a fast way. So I thought this was a pretty cool theorem. And so I tried it out on a problem where I knew a stack automaton could do it, but I couldn't figure out a fast way to do it on a regular computer. I thought it was a pretty good programmer, but by golly, I couldn't think of any way to recognize this language efficiently. So I went through Steve Cook's construction. I filled my blackboard with everything that stack automaton did. I wrote down, and then I tried to see patterns in that. And how did he convert that into a computer program on a regular machine? And finally, I psyched it out. What was the thing I was missing so that I could say, oh yeah, this is what I should do in my program. And now I have an efficient program. And so I would never have thought about that if I hadn't had his theorem, which was a purely abstract thing. So you used this theorem to try to intuit how to use the stack automaton for the string matching problem. Yeah. So the problem I had started with was not the string matching problem, but then I realized that the string matching problem was another thing which could be done by a stack automaton. And so when I looked at what that told me, then I had a nice algorithm for this string matching problem. And it told me exactly what I should remember as I'm going through the string. And I worked it out, and I wrote this little paper called Automata Theory Can Be Useful. And the reason was that it was first, I mean, I had been reading all kinds of papers about automata theory, but it never improved my programming for everyday problems. It was something that you published in journals, and it was interesting stuff. But here was a case where I couldn't figure out how to write the program. I had a theorem from automata theory. Then I knew how to write the program. So this was, for me, a change in life. I started to say, maybe I should learn more about automata theory. And I showed this note to Vaughn Pratt, and he said, that's similar to something I was working on. And Jim Morris was at Berkeley, too, at the time. Anyway, he's had an illustrious career, but I haven't kept track of Jim. But Vaughn is my colleague at Stanford and my student later. But this was before Vaughn was still a graduate student and hadn't come to Stanford yet. So we found out that we'd all been working on the same thing. So it was our algorithm. We each discovered it independently, but each of us had discovered a different part of the elephant, a different aspect of it. And so we could put our things together with my job to write the paper. How did the elephant spring to life? Spring to life was because I had drafted this paper, automata theory. Oh. It can be useful, which was seen by Vaughn and then by Jim. And then we combined, because maybe they had also been thinking of writing something up about it. About specifically the string match problem in a period. Let me ask a ridiculous question. Last time we talked, you told me what the most beautiful algorithm is, actually, for strongly connected graphs. What is the hardest problem, puzzle, idea in computer science for you personally that you had to work through? Just something that was just the hardest thing that I've ever been involved with. I don't know how to answer questions like that, but in this case, it's pretty clear because it's called the birth of the giant component. So now let me explain that because this actually gets into physics too. And it gets into something called Bose Einstein statistics. But anyway, it's got some interesting stories and it's connected with Berkeley again. So start with the idea of a random graph. Now, here we just say we have N points that are totally unconnected and there's no geometry involved. There's no saying some points are further apart than others. All points are exactly alike. And let's say we have 100 points and we number them from 0 to 99. Now let's take pi, the digits of pi, so two at a time. So we had 31, 41, 59, 26. We can look, go through pi. And so we take the first two, 31, 41, and let's put a connection between 0.31 and 0.41. That's an edge in the graph. Then we take 59, 26 and make another edge. And the graph gets bigger, gets more and more connected as we add these things one at a time. So we started out with N points and we add M edges. Each edge is completely, we forgot about edges we had before. We might get an edge twice. We might get an edge from a point to itself even. Maybe pi is going to have a run of four digits in there. But anyway, we're evolving a graph at random. And a magical thing happens when the number of edges is like 0.49 N, so maybe N is a million and I have 490,000 edges. Then almost all the time, it consists of isolated trees, not even any loops. It's a very small number of edges so far. A little less than half N. N, right. A little less than half N. But if I had 0.51 edges, so a little more than half N. So a million points, 510,000 edges. Now it probably has one component that's much bigger than the others. And we call that the giant component. So can you clarify? First of all, is there a name for this kind of random, super cool pi random graph? Well, I call it the pi graph. No, no, the pi graph is actually, my pi graph is based on binary representation of pi, not the decimal representation of pi. But anyway, let's suppose I was rolling dice instead. So it doesn't have to be pi? The point is, every step, choose totally at random one of those endpoints, choose totally at random another one of those endpoints, make that an edge. That's the process. So there's nothing magical about pi? No, no, I was sort of saying pi is sort of random that nobody knows the pattern in. Exactly, got it. But I could have just as well drawn straws or something. This was a concept invented by Erdos and Renyi, and they call it the evolution of random graphs. And if you start out with a large number N, and you repeat this process, all of a sudden a big bang happens at one half N. There'll be two points together, then maybe we'll have three. And then maybe branch out a little bit. But they'll all be separate until we get to one half N. And we pass one half N, and all of a sudden there's substance to it. There's a big clump of stuff that's all joined together. So it's almost like a phase transition of some kind. It's exactly. It's a phase transition, but it's a double phase transition. It turns out that there's actually two things going on at once at this phase transition, which is very remarkable about it. So a lot of the most important algorithms are based on random processes. And so I want to understand random processes now. So there are data structures that sort of grow this way. Okay, so Dick Karp, one of the leading experts on randomized algorithms, had his students looking at this at Berkeley. And we heard a rumor that the students had found something interesting happening. The students are generating this, or simulating this random evolution of graphs. And they're taking snapshots every so often to take a look at what the graph is. And the rumor was that every time they looked, there was only one component that had loops in it, almost always. They do a million experiments, and only three or four times did they ever happen to see a loop at this point. I mean, no, more than one component with a loop. So they watch it until the graph gets completely full. So it starts out totally empty and gets more and more edges all the time. And so, okay, certainly a loop comes along once. But now all the loops stay somehow joined to that one. There never were two guys with loops in these experiments. So anyway, almost always, certainly not always, but with very high probability this seemed to be true. So we heard about this rumor at Stanford, and we said, if that's true, then a lot more must also be true. So there's a whole theory out there waiting to be discovered that we haven't ever thought about. So let's take a look at it. And so we looked closer and we found out, no, actually, it's not true. But in fact, it's almost true. Namely, there's a very short interval of time when it's true. And if you don't happen to look at it during that short interval of time, then you miss it. So in other words, there'll be a period where there are two or three components that have loops, but they join together pretty soon. Okay. So if you don't have a real fast shutter speed, you're going to miss that instant. So separate loops don't exist for long. That's it. Yeah. I started looking at this to make it quantitative. And the basic problem was to slow down the Big Bang so that I could watch it happening. I think I can explain it actually in fairly elementary terms, even without writing a formula, like Hawking would do. And so let's watch the evolution. And at first, these edges are coming along and they're just making things without loops, which we call trees. So then all of a sudden, a loop first appears. So at that point, I have one component that has a loop. Now, I say that the complexity of a component is the number of edges minus the number of vertices. So if I have a loop, I have like a loop of length five, it has five edges and five vertices. Or I could put a tail on that and that would be another edge, another vertex. It's like a zero, one, two complexity kind of thing. So if the complexity is zero, we have one loop, I call it a cycle or I call it a cyclic component. So a cyclic component looks like a wheel to which you attach fibers or trees. They go branching, but there are no more loops. There's only one loop and everything else feeds into that loop. And that has complexity zero. But a tree itself has complexity minus one because it might have 10 vertices and nine edges to tie them together. So nine minus 10 is minus one. So complexity minus one is a tree. It's got to be connected. That's what I mean by a component. It's got to be connected. So if I have 10 things connected, I have to have nine edges. Can you clarify why when complexity can go above zero, I'm a little confused why. Right. So the complexity plus one is the number of loops. So if complexity is zero, I have one loop. If complexity is one, that means I have one more edge than I have vertices. So I might have like 11 edges and 10 vertices. So we call that a bicycle because it's got two loops in it. It's got to have two loops in it. Well, but why can't it be trees just going off of the loop? I would need more edges then. Oh, right. Right. Okay. I got it. So every time I get another loop, I get another excess of edges over vertices. I got you. Okay. So in other words, we start out and after I have one loop, I have one component that has a cycle in it. Now the next step, according to the rumor, would be that at the next step, I would have a bicycle in the evolution of almost all graphs. It would go from cycle to bicycle. But in fact, there's a certain probability it goes from cycle to two different cycles. And I worked out the probability was something like five out of 24. That's pretty high. Right. It was substantial. But still, soon they're going to merge together almost. Okay. That's so cool. But then it splits again after you have either two or one, one. The next step is you either have three or you have two, one or you have one, one, one. Okay. And so I worked out the probability for those transitions. And I worked it out up to the first five transitions. And I had these strange numbers, five 24s. And I stayed up all night and about 3 a.m. I had the numbers computed and I looked at them. The denominator was something like 23023. The probability was something over 23023. I don't know how you worked that out. But I had a formula that I could calculate the probability. And I could find the limiting probability as n goes to infinity. And it turned out to be this number. But the denominator was 230. And I looked at the denominator and I said, wait a minute. This number factors because 1001 is equal to 7 times 11 times 13. I had learned that in my first computer program. So 23023 is 7 times 11 times 13 times 23. That's not a random number. There has to be a reason why those small primes appear in the denominator. So all of a sudden that suggested another way of looking at the problem where small prime factors would occur. So that said, oh, yeah, let me take the logarithm of this formula. And sure enough, it's going to simplify. And it happened. So I and I wouldn't have noticed it except for this factorization. OK, so I go to bed and I say, oh, OK, this is this looks like I'm slowing down the Big Bang. I can figure out what's going on here. And the next day it turned out Bill Gates comes to Stanford to visit. They're trying to sell him on donating money for a new computer science building. And they gave me an appointment to talk to Bill and I wrote down on the blackboard this evolutionary diagram going from one to two, five twenty fourths in all this business. And I wrote it down. And anyway, at the end of the day, he was discussing people with the development office and he said, boy, I was really impressed with what Professor Knuth said about this giant component. And and so, you know, I love this story because it shows that theoretical computer science is really worthwhile. Does Bill have you ever talked to Bill Gates about it since then? Yeah, that's a cool that's a cool little moment in history. But anyway, he happened to visit on exactly the day after I had I had found this pattern and that allowed me to crack the problem so that I could develop the theory some more and understand what's happening in the big. But because I could I could now write down explicit formulas for stuff. And so it would work not only the first few steps, but also they'll study the whole process. And and I worked further and further and I with two authors, co authors, and we finally figured out that the probability that the rumor was true. In other words, look at the evolution of a random graph going from zero to complete and say, what's the probability that at every point in time, there was only one component with a cycle? We started with this rumor saying there's only one site, there's only one component with a cycle. And so the rumor was it's 100%. Rumor was that was 100%. It turned out the actual numbers is like 87%. I should remember the number but I don't but I don't have it with me. But but anyway, but but the but the number it turned out to be like 12 over pi squared or eight over pi. Anyway, it was a nice it related to pi. Yeah. And we could never have done that with it. But so that's the hardest problem I ever solved in my life was to prove that this probability is it was proven. The probability was proven. Yeah, I was able to prove this that this and this should shed light on a whole bunch of other things about random graphs. That was sort of the major thing we were after. That's super cool. What was the connection to physics that you mentioned? Well, Bose Einstein statistics is a study of how molecules bond together without geometry. You created the tech typesetting system and released it as open source. Just on that little aspect, why did you release it as open source? What is your vision for open source? Okay, well that the word open source didn't exist at that time. But we but I didn't want proprietary rights over it. Because I saw how proprietary rights were holding things back. In the late 50s, people at IBM developed the language called Fortran. They could have kept it proprietary. They could have said only IBM can use this language. Everybody else has to. But they didn't. They said anybody who can translate Fortran into the language of their machines is allowed to make Fortran compilers. On the other hand, in the typography industry, I had seen a lot of languages that were developed for composing pages. And each manufacturer had his own language for composing pages. And that was holding everything back because people were tied to a particular manufacturer. And then a new equipment is invented a year later. But printing machines, they have to expect to amortize the cost over 20, 30 years. So you didn't want that for tech? That for tech. I didn't need the income. I already had a good job. And my books were, people were buying enough books that it would bring me plenty of supplemental income for everything my kids needed for education and whatever. So there was no reason for me to try to maximize income any further. Income is sort of a threshold function. If you don't have enough, you're starving. But if you get over the threshold, then you start thinking about philanthropy or else you're trying to take it with you. But anyway, my income was over the threshold. So I didn't need to keep it. And so I specifically could see the advantage of making it open for everybody. Do you think most software should be open? So I think that people should charge for non trivial software, but not for trivial software. Yeah, you give an example of, I think, Adobe Photoshop versus GIMP on Linux as Photoshop has value. So it's definitely worth paying for all this stuff. I mean, well, they keep adding stuff that my wife and I don't care about, but they have built in a fantastic undo feature, for example, in Photoshop where you can go through a sequence of a thousand complicated steps on graphics and then it can take you back anywhere in that sequence with really beautiful algorithms. Oh, that's interesting. I didn't think about what algorithm. It must be some kind of efficient representation. Yeah, no. I mean, there's a lot of really subtle Nobel Prize class creation of intellectual property in there. And with patents, you get a limited time to, I mean, eventually the idea of patents is that you publish so that it's not a trade secret. That said, you've said that I currently use Ubuntu Linux on a standalone laptop. It has no internet connection. I occasionally carry flash memory drives between the machine and the Macs that I use for network surfing and graphics, but I trust my family jewels only to Linux. Why do you love Linux? The version of Linux that I use is stable. Actually, I'm going to have to upgrade one of these days, but... To a newer version of Ubuntu? Yeah, I'll stick with Ubuntu, but right now I'm running something that doesn't support a lot of the new software. The last stable, I don't remember the number, like 14. Anyway, it's quite... And I'm going to get a new computer. I'm getting new solid state memory instead of a hard disk. Yeah, the basics. Well, let me ask you, sticking on the topic of tech, when thinking about beautiful typography, what is your favorite letter, number, or symbol? I know, I know. Ridiculous question, but is there some... Let me show you here. Look at the last page. The very end of the index. What is that? There's a book by Dr. Seuss called On Beyond Zebra, and he gave a name to that. Did you say Dr. Seuss gave a name to that? Dr. Seuss, this is S, E, U, S, S, E. He wrote children's books in the 50s, 40s and 50s. Wait, you're talking about Cat in the Hat, Dr. Seuss? Cat in the Hat, yeah. That's it, yeah. I like how you had the spell there. On Beyond Zebra, did it get to Soviet Union? No, Dr. Seuss did not come to the Soviet Union, but since you... Oh, actually, I think it did actually a little bit when we were... That was a book, maybe Cat in the Hat or Green Eggs and Ham, I think was used to learn English. Oh, okay. So I think it made it in that way. Well, my... Okay, I didn't like those as much as Bartholomew Cubbins, but I used to know Bartholomew Cubbins by heart when I was young. So what the heck is this symbol we're looking at? There's so much going on. He has a name for it at the end of his book On Beyond Zebra. Who made it? He did. He did. So there's... It looks like a bunch of vines. Well, is that symbol exist in fact? By the way, he made a movie in the early 50s. I don't remember the name of the movie now. You can probably find it easily enough, but it features dozens and dozens of pianos all playing together at the same time. But all the scenery is sort of based on the kind of artwork that was in his books and the fantasy, you know, based of Seussland or something. And I saw the movie only once or twice, but it's quite... I'd like to see it again. That's really fascinating that you gave him... They gave him a shout out here. Okay. Is there some elegant basic symbol that you're attracted to? Something that gives you pleasure? Something you use a lot? Pi? Pi, of course. I try to use pi as often as I can when I need a random example because it doesn't have any known characters. So for instance, I don't have it here to show you, but do you know the game called Masyu? M A S Y U? after all. I was pretty much a machine. So it's almost like, yeah, I got you. It's a tinkering mindset, not a philosophical mindset. Yeah. It was just exciting to me to be able to control something, but not to say, am I solving a big problem or something like that? Or is this a step for humankind? No, no way. When did you first start thinking about computation in the big sense? Like the universal Turing machine? I had to take classes on computability when I was a senior. So we read this book by Martin Davis. Yeah, this is cool stuff. But I learned about it because I needed to pass the exams. But I didn't invent any of that boring stuff. But I had great fun playing with the machine. I wrote programs because it was fun to write programs and get this. I mean, it was like watching miracles happen. You mentioned in an interview that when reading a program, you can tell when the author of the program changed. How the heck can you do that? Like, what makes a distinct style for a programmer, do you think? You know, there's different Hemingway has a style of writing versus James Joyce or something. Yeah, those are pretty easy to imitate. But it's the same with music and whatever. During the pandemic, I spent a lot more time playing the piano. And I found something that I'd had when I was taking lessons before I was a teenager. And it was Yankee Doodle who played in the style of... You had Beethoven and you had Debussy and Chopin, and the last one was Gershwin. And I played over and over again. I thought it was so brilliant. But it was so easy. But also to appreciate how this author, Mario, somebody or other, had been able to reverse engineer the styles of those composers. But now, specifically to your question, I mean, there would be... It was pretty obvious in this program I was reading. It was a compiler and it had been written by a team at Carnegie Mellon. And I have no idea which program was responsible for it. But you would get to a part where the guy would just not know how to move things between registers very efficiently. And so everything that could be done in one instruction would take three or something like that. That would be a pretty obvious change in style. But there were also flashes of brilliance where you could do in one instruction. Normally, I used two because you knew enough about the way the machine worked that you could accomplish two goals in one step. So it was mostly the brilliance of the concept more than the semicolons or the use of short sentences versus long sentences or something like that. So you would see the idea in the code and you could see the different style of thinking expressed in the code. Right. It was stylistic. I mean, I could identify authors by their by the amount of technical aptitude they had, but not by the style in the sense of rhythm or something like that. So if you think about Mozart, Beethoven, Bach, if somebody looked at Don Knuth code, would they be able to tell that this is a distinct style of thinking going on here? What do you think? And what would be the defining characteristic of the style? Well, my code now is literate programming. So it's a combination of English and C mostly. But if you just looked at the C part of it, you would also probably notice that I use a lot of global variables that other people don't. And I expand things in line more than instead of calling. Anyway, I have different subset of C that I use. Okay. But that's a little bit stylistic. But with literate programming, you alternate between English and C or whatever. And by the way, people listening to this should look up literate programming. It's very interesting concept that you proposed and developed over the years. Yeah. That's the most significant thing, I think, to come out of the tech project is that I realized that my programs were to be read by people and not just by computers and that typography could massively enhance that. And so, I mean, they're just wonderful. If they're going to look it up, they should also look up this book called Physically Based Rendering by Matt Farr and, gosh, anyway, it got an Academy Award. But all the graphic effects you see in movies are accomplished by algorithms. And the whole book is a literate program. It tells you not only how you do all the shading and bring images in that you need for animation and textures and so on, but you can run the code. And so, I find it an extension of how to teach programming is by telling a story as part of the program. So it works as a program, but it's also readable by humans. Yes. And especially by me a week later or a year later. That's a good test. If you yourself understand the code easily a week or a month or a year later. Yeah. So it's the greatest thing since sliced bread. Programming or literate programming? Literate programming. Okay. You heard it here first. Okay. You dodged this question in an interview I listened to. So let me ask you again here. What makes for a beautiful program? What makes for a beautiful program? Yeah. What are the characteristics you see? Like you just said, literate programming. What are the characteristics you see in a program that make you sit back and say, that's pretty good? Well, the reason I didn't answer is because there are dozens and dozens of answers to that because you can define beauty, the same personal defined beauty, different way from hour to hour. I mean, it depends on what you're looking for. At one level, it's beautiful just if it works at all. At another level, it's beautiful if it can be understood easily. It's beautiful if it's literate programming. It's beautiful. It makes you laugh. I mean. Yeah. So I'm with you. I think beauty, if it's readable. Readable, yeah. Is if you understand what's going on and also understand the elegance of thought behind it. And then also, as you said, wit and humor. I was always, I remember having this conversation, I had this conversation on Stack Overflow, whether humor is good in comments. And I think it is. Whether humor is good in comments. Like when you add comments in code, I always thought a little bit of humor is good. It shows personality. It shows character, shows wit and fun and all those kinds of things of the personality of the programmer. Yeah. Okay. So a couple of days ago, I received a wonderful present from my former editor at Aspen Wesley. He's downsizing his house and he found that somebody at the company had found all of their internal files about the art of computer programming from the 1960s and they gave it to him before throwing it in the garbage. And then so he said, oh yeah, he planned to keep it for posterity, but now he realized that posterity is a bit too much for him to handle, so he sent it to me. And so I just received this big stack of letters, some of which I had written to them, but many of which they had written to No. It's a great recreation. I mean, Sudoku is easier to understand, but Masyu is more addictive. You have black and white stones, like on a go board, and you have to draw a path that goes straight through a white stone and makes a right angle turn at the black stone. And it turns out to be a really nice puzzle because it doesn't involve numbers. It's visual, but it's really pleasant to play with. So I wanted to use it as an example in art of computer programming, and I have exercises on how to design cool Masyu puzzles. You can find on Wikipedia certainly as an example, M A S Y U. And so I decided I would take pi, the actual image of it, and it had pixels, and I would put a stone wherever it belongs in the Greek letter pi. But the problem was, find a way to make some of the stones white, some of the stones black, so that there's a unique solution to the Masyu puzzle. That was a good test case for my algorithm on how to design Masyu puzzles because I insisted in advance that the stones had to be placed in exactly the positions that make the letter pi, make a Greek letter pi. And it turned out there was a unique way to do that. And so pi is a source of examples where I can prove that I'm starting with something that isn't canned. And most recently, I was writing about something called graceful graphs. Graceful graphs is the following. You have a graph that has M edges to it, and you attach numbers to every vertex in the following way. So every time you have an edge between vertices, you take the difference between those numbers, and that difference has got to be... I'll tell you what edge it is. So one edge, two numbers will be one apart. There'll be another edge where the numbers are two apart. And so it's a great computer problem. Can you find a graceful way to label a graph? So I started with a graph that I use for an organic graph, not a mathematically symmetric graph or anything. And I take 49 states of the United States, the edges go from one state to the next state. So for example, California be next to Oregon, Nevada, Arizona. And I include District of Columbia, so I have 49. I can't get Alaska and Hawaii in there because they don't touch. You have to be able to drive from one to the other. So is there a graceful labeling of the United States? Each state gets a number, and then if California is number 30 and Oregon is number 11, that edge is going to be number 19, the difference between those, okay? So is there a way to do this for all the states? And so I was thinking of having a contest for people to get it as graceful as they could. But my friend, Tom Rokicki, actually solved the problem by proving that, I mean, I was able to get it down within seven or something like that. He was able to get a perfect solution. The actual solution or to prove that a solution exists? Well, more precisely, I had figured out a way to put labels on so that all the edges were labeled somewhere between 1 and 117, but there were some gaps in there because I should really have gone from 1 to 105 or whatever the number is. So I gave myself a lot of slack. He did it without any slack whatsoever, a perfect graceful labeling. And so I called out the contest because the problem's already solved and too easy in a sense because Tom was able to do it in an afternoon. Sorry, he gave the algorithm or for this particular... For the United States. For the United States. This problem is incredibly hard. I mean... For the general algorithm. But it was very lucky that it worked for the United States, I think. The theory is still very incomplete. But anyway, then Tom came back a couple of days later and he had been able to not only find a graceful labeling, but the label of Washington was 31, and the label of Idaho was 41, following the digits of pi. Going across the top edge of the United States, he has the digits of pi perfectly. Did he do it on purpose? He was able to still get a graceful labeling with that extra thing. What? Wow. Wow. And it's a miracle, okay? But I like to use pi in my book, you see. All roads lead to pi. Somehow often hidden in the middle of the most difficult problems. Can I ask you about productivity? Productivity. Yeah, you said that, quote, my scheduling principle is to do the thing I hate most on my to do list. By week's end, I'm very happy. Can you explain this process to a productive life? Oh, I see. Well, but all the time I'm working on what I don't want to do, but still, I'm glad to have all those unpleasant tasks finished. Yes. Is that something you would advise to others? Well, yeah, I don't know how to say it. During the pandemic, I feel my productivity actually went down by half because I have to communicate by writing, which is slow. I don't like to send out a bad sentence. So I go through and reread what I've written and edit and fix it. So everything takes a lot longer when I'm communicating by text messages instead of just together with somebody in a room. And it's also slower because the libraries are closed and stuff. But there's another thing about scheduling that I learned from my mother that I should probably tell you, and that is it's different from what people in the robotics field do, which is called planning. So she had this principle that was, see something that needs to be done and do it. Instead of saying, I'm going to do this first and do this first, just pick this up. But at any one moment, there's a set of tasks that you can do. And you're saying a good heuristic is to do the one you want to do least. Right. The one I haven't got any good reason, that I'll never be able to do it any better than I am now. There are some things that I know, if I do something else first, then I'll be able to do that one better. Yeah. But there are some that are going to be harder because I've forgotten some of the groundwork that went into it or something like that. So I just finished a pretty tough part of the book. And so now I'm doing the parts that are more fun. But the other thing is, as I'm writing the book, of course, I want the reader to think that I'm happy all the time I'm writing the book. It's upbeat. I can have humor. I can say this is cool. And this, I have to disguise the fact that it was painful in any way to come up with these. The road to that excitement is painful. Yeah. It's laden with pain. Okay. You've given some advice to people before, but can you... You give me too much credit. But anyway, this is my turn to say things that I believe. But I want to preface it by saying I also believe that other people do these things much better than I do. So I can only tell you my side of it. Right. So can I ask you to give advice to young people today, to high school students, to college students, whether they're geeks or the other kind, about how to live a life that they can be proud of, how to have a successful career, how to have a successful life? It's always the same as I've said before, I guess, not to do something because it's trendy, but something that you personally feel that you were called to do rather than somebody else expects you to do. How do you know you're called to do something? If you try it and it works or it doesn't work. I mean, you learn about yourself. Life is a binary search. You try something and you find out, oh yeah, I have a background that helped me with this. Or maybe I could do this if I worked a little bit harder. But you try something else and you say, well, I have really no intuition for this and it looks like it doesn't have my name on it. Was there advice along the way that you got about what you should and shouldn't work on? Or do you just try to listen to yourself? Yeah, I probably overreact another way. When I see everybody else going some way, I probably say, hmm, not too much competition. But mostly I played with things that were interesting to me and then later on I found, oh, actually the most important thing I learned was how to be interested in almost anything. I mean, not to be bored. It makes me very sad when I see kids talking to each other and they say, that was boring. And to me, a person should feel upset if he had to admit that he wasn't able to find something interesting. It's a skill they think, I haven't learned how to enjoy life. I have to have somebody entertain me instead of... Right. That's really interesting. It is a skill. David Foster Wallace, I really like the thing he says about this, which is the key to life is to be unborable. And I do really like you saying that it's a skill because I think that's a really good advice, which is if you find something boring, that's not... I don't believe it's because it's boring. It's because you haven't developed a skill. I haven't learned how to... How to find the beauty in that, how to find the fun in it. That's a really good point. Sometimes it's more difficult than others to do this. I mean, during the COVID, lots of days when I never saw another human being, but I still find other ways to... It still was a pretty fun time. Yeah. I came a few minutes early today and I walked around Foster City. I didn't know what was going on in Foster City. I saw some beautiful flowers at the nursery at Home Depot a few blocks away. Yeah. Life is amazing. It's full of amazing things like this. Yeah. Sometimes I'll sit there and just stare at a tree. Nature is beautiful. Let me ask you the big ridiculous question. I don't think I asked you last time. So I have to ask this time in case you have a good answer. What is the meaning of life? Our existence here on earth, the whole thing. No, no, you can't. I will not allow you to try to escape answering this question. You have to answer definitively because surely, surely, Don Knuth, there must be an answer. What is the answer? Is it 42? Yes. Well, I don't think it's a numerical. That's the SDS. That was in Zen and... All right. So anyway, it's only for me, but I personally think of my belief that God exists, although I have no idea what that means. But I believe that there is something beyond human capabilities. It might be some AI, but whatever it is. But whatever. But I do believe that there is something that goes beyond the realm of human understanding, but that I can try to learn more about how to resonate with whatever that being would like me to do. So you think you can have occasional glimpses of that being? I strive for that. Not that I ever think I'm going to get close to it, but it's not for me. It's saying, what should I do that that being wants me to do? I'm trying to ask, does that being want me to be talking to Lex Friedman right now? And I said, yes. Okay. Thank you. Well, thank you. What I'm trying to say is, of all the strategies I could choose or something, I try to do it not strategically, but I try to imagine that I'm following somebody's wishes. Even though you're not smart enough to know what they are. Yeah. It's that funny little dance. Well, I mean, this AI or whatever, probably is smart enough to help to give me clues. And to make the whole journey from clue to clue a fun one. Yeah. As so many people have said, it's the journey, not the destination. And people live through crises, help each other. Things come up, history repeats itself. You try to say, in the world today, is there any government that's working? I read history. I know that things were... They were a lot worse in many ways. There's a lot of bad things all the time. And I read about... I look at things and people had good ideas and they were working on great projects. And then I know that it didn't succeed, though, in the end. But the new insight I've gotten actually in that way was... I was reading... What book was I reading recently? It was by Ken Follett and it was called The Man from St. Petersburg. But it was talking about the prequel to World War I. And Winston Churchill, according to this book, sees that Germany has been spending all its gold reserves building up a huge military. And there's no question that if Germany would attack England, that England would be wiped out. So he wants Russia to help to attack Germany from the other side, because Germany doesn't have enough of an army to be fighting two wars at one. Okay. Now, then there's an anarchist in Russia who sees that wars are something that leaders start, but actually people get killed. And so he wants to stop any alliance between England and Russia, because that would mean that thousands and thousands of people of Russia would be killed that wouldn't be otherwise killed. All right. And so his life's goal is to assassinate a Russian prince who's visiting England, because that will mean the Tsar will not form the alliance. All right. So we have this question about what should the government do? Should it actually do something that will lead to... Is the war inevitable or is there a way to have peace? And it struck me that if I were in a position of responsibility for people's lives, in most cases, I wouldn't have any confidence that any of my decisions were good. That these questions are too hard, probably for any human being, but certainly for me. Well, I think coupling the not being sure that the decisions are right. So that's actually a really good thing, coupled with the fact that you do have to make a decision and carry the burden of that. And ultimately I have faith in human beings and the great leaders to arise and help build a better world. I mean, that's the hope of democracy. Yeah, Ben, let's hope that we can enhance their abilities with algorithms. Well put, Don. It's such a huge honor. You've been an inspiration to me and to millions for such a long time. Thank you for spending your really valuable time with me. Once again, it's a huge honor. I really enjoyed this conversation. Thanks for listening to this conversation with Donald Knuth. To support this podcast, please check out our sponsors in the description. And now let me leave you with some words from Don Knuth himself. Science is what we understand well enough to explain to a computer. Art is everything else we do. Thank you for listening and hope to see you next time. early guinea pigs who were telling them whether they should publish or not. You know, and one of the things was in the comments to volume one, the major reader was Bob Floyd, who is my great co worker in the 60s, died early, unfortunately. And he commented about the humor in it. So he ran it by me, you know, says, you know, keep this joke in or not, you know. They also sent it out to focus group. What do you think about humor in a book about computer programming? What's the conclusion? And I stated my philosophy. It said, you know, the ideal thing is that it's something where the reader knows that there's probably a joke here if you only understood it. And this is a motivation to understand, to think about it a little bit. But anyway, it's a very delicate humor. I mean, it's really each each century invents a different kind of humor, too. Different cultures have different different kinds of humor. Yeah. Like we talked about Russia a little bit offline. You know, there's dark humor and, you know, when a country goes through something difficult, that life and stuff like this. And, you know, and Jack Benny, I mean, you know, Steve Allen wrote this book about humor, and it was the most boring book, but he was one of my idols. But it's called The Funny Men or something like that. But yeah. Okay. So anyway, I think it's important to know that this is part of life, and it should be fun and not... And so, you know, I wrote this organ composition, which is based on the Bible, but I didn't refrain from putting little jokes in it also in the music. It's hidden in the music. It's there, yeah. A little humor is okay? Yeah. I mean, not egregious humor. So in this correspondence, you know, there were things I said, yeah, I really shouldn't have done that. But other ones I insisted on. And I've got jokes in there that nobody has figured out yet. In fact, in volume two, I've got a cryptogram, a message, enciphered. And in order to decipher it, you're going to have to break an RSA key, which is larger than people know how to break. And so, you know, if computers keep getting faster and faster, then, you know, it might be a hundred years, but somebody will figure out what this what this message is and they will laugh. I mean, I've got a joke in there. So that one you really have to work for. I don't know if you've heard about this. Let me explain it. Maybe you'll find it interesting. So OpenAI is a company that does AI work, and they have this language model. It's a neural network that can generate language pretty well. But they also have, on top of that, developed something called OpenAI Codex. And together with GitHub, they developed a system called OpenAI Copilot. Let me explain what it does. There's echoes of literate programming in it. So what you do is you start writing code and it completes the code for you. So, for example, you start, let's go to your factoring program. You start, you write in JavaScript and Python and any language that it trained on. You start, you write the first line and some comments, like what this code does, and it generates the function for you. And it does an incredibly good job. Like, it's not provably right, but it often does a really good job of completing the code for you. I see. But how do you know whether it did a good job or not? Yeah. You could see a lot of examples where it did a good job. And so it's not a thing that generates code for you. Yeah, exactly. It starts, it gives you, so it puts the human in the seat of fixing issues versus writing from scratch. Do you find that kind of idea at all interesting? Every year, we're going to be losing more and more control over what machines are doing. And people are saying, well, when I was a professor at Caltech in the 60s, we had this guy who talked a good game. He could give inspiring lectures and you'd think, well, thrilling things he was talking about. An hour later, you'd say, well, what did he say? Yeah. But he really felt that it didn't matter whether computers got the right answer or not, it just mattered whether it made you happy or not. In other words, if your boss paid for it, then you had a job, you could take care of your wife. Happiness is more important than truth. Exactly. He didn't believe in truth, but he was a philosopher. Yes, I like it. And somehow you see... We're going that way. So many more things are taken over by saying, well, this seems to work. When there is a competing interest involved, neither side understands why the decision is being made. We realize now that it's bad, but consider what happens 5 or 10 years down the line when things get even more further detached. Each thing is based on something from the previous year. Yeah. So you start to lose... The more you automate, the more you start to lose track of some deep human things. Exponentially. Exponentially. So that's the dark side. The positive side is the more you automate, the more you let humans do what humans do best. So maybe programming... Maybe humans should focus on a small part of programming that requires that genius, the magic of the human mind, and the mess you let the machine generate. That's the positive, but of course, it does come with the darkness of automation. What's better? Correctness? I'm never going to try to write a book about that. I'm never going to recommend to any of my students to work for them. Sure. So you're on the side of correctness, not beauty, not happiness. I'm on the side of understanding. Understanding. And I think these things are really marvelous if what they do is all of a sudden we have a better medical diagnosis or it'll help guide some scientific experiment or something like curing diseases or whatever. But when it affects people's lives in a serious way... If you're writing code, oh yeah, this is great. This will make a slaughter bot. I see. So you have to be very careful. Right now it seems like fun and games. It's useful to write a little JavaScript program that helps you with the website. But like you said, one year passes, two years passes, five years, and you forget. You start building on top of it, and then all of a sudden you have autonomous weapon systems. Well, we're all dead. It doesn't matter in that sense. Well, in the end, this whole thing ends anyway. There is a heat death of the universe predicted, but I'm trying to postpone that for a little bit. Well, it'd be nice that at the end, as we approach the heat death of the universe, there's still some kind of consciousness there to appreciate it. Hopefully human consciousness. I'll settle for 10 to the 10th year, some finite number. But things like this might be the reason we don't pick up any signals from extraterrestrials. They don't want anything to do with us. Oh, because they, because they, they, they invented it too. So you, you do have a little bit of worry on the existential threats of AI and automation. So like, like removing the human from the picture, et cetera. Yeah. Um, people have more, more potential to do harm now than by far than they did a hundred years ago. But are you optimistic about the humans are good at creating destructive things, but also humans are good at solving problems. Yeah. I mean, there's half empty and half full, you know, so I can go. So let me, let me put it this way because, because it's the only way I can be optimistic, but, but, but, but think of, um, of, uh, things that have changed because of civilization, you know, they don't occur just in nature. So just, uh, just imagine the room we're in, for example. Okay. Some, you know, we've got pencils, we've got books, we've got tables, we've got microphones, your clothing, food, all these things were added. Somebody invented them one by one and millions of things, uh, that we inherit. Okay. Um, and, uh, it's inconceivable that, that so many millions of billions of things, uh, wouldn't have problems and we get it all right. Um, and each one would have no negative effects and so on. So it, it's very amazing that as much works as does work. It's, it's, it's incredibly amazing. And actually that's the source of my optimism as well, including for artificial intelligence. So we, we drive over bridges. We, uh, we use all kinds of technology. We don't know how it works. And there's millions of brilliant people involved in building a small part of that and it doesn't go wrong and it works. And I mean that it, it works and it doesn't go, go wrong often enough for us to suffer. And we can identify things that aren't working and try to improve on them. In a suboptimal, often suboptimal way. Oh, absolutely. But it's, but the, but the, the kind of things that I know how to improve require human beings to be rational. And I, I'm losing my confidence that human beings are rational. Yeah. Yeah. Now here you go again with the worst case, uh, worst case analysis. Um, they may not be rational, but they're, um, they're, they're clever and, uh, beautiful in their own kind of way. I tend to think that most people, um, have the desire and the capacity to be good to each other and love will ultimately win out. Like if they're given the opportunity, that's where they lean. In the Art of Computer Programming, you wrote, the real problem is that programmers have spent far too much time worrying about efficiency in the wrong places. And at the wrong times, premature optimization is the root of all evil in parentheses, or at least most of it in programming. Can you, uh, explain this idea? Uh, what's the wrong time? What is the wrong place for optimization? So so first of all, the word optimization, I started out writing software, uh, and optimization was, I was a compiler writer. So optimization meant, uh, making the, uh, making a better translation so that it would run faster on a, on a machine. So an optimized program is just like, you know, you, you, you run a program and you set the optimization level, uh, for, uh, to the compiler. So that's one word for optimization. Um, and at that time I, I happened to be looking in an unabridged dictionary, uh, for some reason or other, and I came to the word optimizer. So what's the meaning of the word optimize? And it says to view with optimism. And you look in Webster's dictionary of English language in 19, early 1960s, that's what optimize meant. Okay. Um, now, so people started doing cost optimization, other kinds of things, uh, uh, you know, whole sub fields of, of, uh, algorithms and economics and whatever are based on what they call optimization now. But, uh, but to me optimization when I was saying that was saying, uh, changing a program to make it more, uh, tuned to the machine. And I found out that, uh, when a person writes a program, uh, he or she tends to think that the parts that were hardest to write are going to be hardest for the computer to execute. So maybe I have 10 pages of code, but I had to work a week writing this page. I mentally think that when the computer gets to that page, it's going to slow down. It's going to say, oh, I don't understand what I'm doing. I better, I better be more careful. Anyway, this is of course silly, but it's, it's, it's something that we, that we, that we don't know when we write a piece of code. We don't know what, what, whether the computer is actually going to be executing that code very much. So, so people had, had a very poor understanding of, of what the computer was actually doing. Uh, I made one test where, where we studied a Fortran compiler and it was spending more than 80% of its time reading the comments card. Um, but as a programmer, we were really concerned about how fast it could take a complicated expression that had lots of levels of parentheses and, and, and, and convert that into something. But that was just, you know, less than 1% of the, so if we optimize that, uh, we didn't know what we were doing, but, but, but if we knew that it was spending 80% of his time on the comments card, you know, in 10 minutes, we could, we could make the, the, the compiler run more than twice as fast. And you could only do that once you've completed the program and then you empirically study where. I had some kind of profiling that I knew what was important. Yeah. So you don't think this applies generally? I mean, there's something that rings true to this across all of them. I'm glad that it applied generally, but it was, it was only my good luck. I said it, but you know, but I did, but I said it in a limited context and I, and, and I'm glad if it makes people think about stuff because I, but it applies in another sense too, that is sometimes I will do optimization in a way that does help the actual running time, but makes the program impossible to change next week. Right. Because I've changed my data structure or something that, that made it less adaptable. So one of the great principles of computer science is, is, is laziness or whatever you call it, late binding. You know, don't hold off decisions when you can. And, and, and, you know, and we understand now quantitatively how valuable that is. What do you mean we understand? So you mean from a... People, people have written thesis about how you can, how late binding will, will improve the, I mean, you know, just in time manufacturing or whatever, you can make, you can defer a decision instead of doing your advanced planning and say, I'm going to allocate 30% to this and 50%. So in all kinds of domains, there's an optimality to laziness in many cases. Decision is not made in advance. So instead you, you, you design in order to be flexible to change with the, with the way the wind is blowing. Yeah. But so the reason that line resonated with a lot of people is because there's something about the programmer's mind that wants, that enjoys optimization. So it's a constant struggle to balance laziness and late binding with the desire to optimize. The elegance of a well optimized code is something that's compelling to programming. Yeah. It's another concept of beauty. Let me ask you a weird question. So Roger Penrose has talked about computation computers and he proposed that the way the human mind discovers mathematical ideas is something more than a computer. That, that a universal Turing machine cannot do everything that a human mind can do. Now this includes discovering mathematical ideas and it also includes, he's written a book about it, Consciousness. So I don't know if you know Roger, but my, my daughter's kids played with his kids in Oxford. Nice. So do you think there is such a limit to the computer? Do you think consciousness is more than a computation? Do you think the human mind, the way it thinks is more than a computation? I mean, I can say yes or no, but, but, but I don't, I have no reason. I mean. So you don't find it useful to have an intuition in one way or the other? Like when you think about algorithms, isn't it useful to think about the limits? Unanswerable question in my opinion is, is no better than anybody else. You think it's unanswerable. So you don't think eventually science. How many angels can dance on the head of a, I mean, I don't know. But angels. Anyway, there, there are lots of things that are beyond, that we can speculate about, but I don't want somebody to say, oh yeah, Knuth said this and so he's, he's, he's smart. And so, so he, so that must be, I mean, I say it's something that we'll never know. Oh, interesting. Okay. That's a strong statement. I don't, I personally think it's something we will know eventually. Like there's no reason to me why the, the workings of the human mind are not within the reach of science. That's absolutely possible. And I'm not denying it. Yeah. But right now you don't have a good intuition. I mean, that's also possible, you know, that an AI, you know, created the universe, you know, intelligent design has all been done by an AI. This is, I mean, all of these things are, but, but, but you're asking me to, to pronounce on it. And I don't have any expertise. I'm a teacher that passes on knowledge, but I don't, but I don't know the fact that I, that I vote yes or no on. Well, you do have expertise as a human, not as a, not as a teacher or a scholar of computer science. I mean, that's ultimately the realm of where the discussion of human thought. Yeah. Well, I know where. And consciousness is. I know where, where Penrose is coming from. He, I'm sure he has no, I mean, he might even thought he proved it, but. No, he doesn't. He doesn't prove it. He is following intuition. But, but I mean, you have to ask John McCarthy. John McCarthy, I think, were totally unimpressed by these statements. So you don't think, so even like the Turing paper on, on the Turing test that, you know, starts by asking, can machines think? Oh. You don't think these kind of, Turing doesn't like that question. Yeah. I don't consider it important, let's just put it that way. Because it's, it's in the category of things that it would be nice to know, but I think it's beyond knowledge. And so I don't, I'm more interested in knowing about the Riemann hypothesis or something. So when you say, it's an interesting statement, beyond knowledge. Yeah. I think what you mean is it's not sufficiently well, it's not even known well enough to be able to formalize it in order to ask a clear question. Yeah. And so that's why it's beyond knowledge, but that doesn't mean it's not eventually going to be formalized. Yeah. Yeah. Maybe consciousness will be understood some, someday. The last time I checked, it was still 200 years away. I mean, I haven't been specializing in this by any means, but I went to lectures about it 20 years ago when I was, there was a symposium at the American Academy in Cambridge. And it started out by saying, essentially, everything that's been written about consciousness is hogwash. I tend to disagree with that a little bit. So consciousness for the longest time still is in the realm of philosophy. So it's just conversations without any basis and understanding. Still, I think once you start creating artificial intelligence systems that interact with humans and they have personality, they have identity, you start flirting with the question of consciousness, not from a philosophical perspective, but from an engineering perspective. And then it starts becoming much more like, I feel like. Yeah. Don't misunderstand me. I certainly don't disagree with that at all. And even at these lectures that we had 20 years ago, there were neurologists pointing out that human beings had actually decided to do something before they were conscious of making that decision. I mean, they could tell that signals were being sent to their arms before they knew that things like this are true. And Les Valiant has an architecture for the brain. And more recently, Christos Papadimitriou in the Academy of Science Proceedings a year ago with two other people, but I know Christos very well. And he's got this model of this architecture by which you could create things that correlate well with experiments that are done on consciousness. And he actually has a machine language in which you can write code and test hypotheses. And so we might have a big breakthrough. My personal feeling is that consciousness is the best model I've heard of to explain the miracle of consciousness is that somehow inside of our brains, we're having a continual survival for the fittest competition. And I'm speaking to you, and I'm speaking to you, all the possible things I might be wanting to say are all in there and there's like a voting going on. Yeah, right. And one of them is winning and that's affecting the next sentence and so on. And there was this book, Machine Intelligence or something? On Intelligence? On Intelligence, yeah. Bill Atkinson was a total devotee of that book. Well, I like whether it's consciousness or something else, I like the storytelling part that it feels like for us humans, it feels like there's a concrete story. It's almost like literary programming. I don't know what the programming is going on on the inside, but I'm getting a nice story here about what happened. And it feels like I'm in control and I'm getting a nice clear story. But it's also possible there's a computation going on that's really messy. There's a bunch of different competing ideas. And in the end, it just kind of generates a story for you, a consistent story for you to believe. And that makes it all nice. Yeah. And so I prefer to talk about things that I have some expertise in than things which I'm only on the sideline. So there's a tricky thing. I don't know if you have any expertise in this. You might be a little bit on the sideline. It'd be interesting to ask though. What are your thoughts on Cellular Automata and the Game of Life? Have you ever played with those kind of little games? I think the Game of Life is wonderful and shows all kinds of stuff about how things can evolve without the creator understanding anything more than the power of learning in a way. But to me, the most important thing about the Game of Life is how it focused for me what it meant to have free will or not. Because the Game of Life is obviously totally deterministic. And I find it hard to believe that anybody who's ever had children cannot believe in free will. On the other hand, this makes it crystal clear. John Conway said he wondered whether it was immoral to shut the computer off after he got into a particularly interesting play of the Game of Life. Wow. Yeah. So to me, the reason I love the Game of Life is exactly as you said, a clear illustration that from simple initial conditions with simple rules, you know exactly how the system is operating, it's deterministic. And yet, if you allow yourself to lose that knowledge a little bit enough to see the bigger organisms that emerge, and then all of a sudden they seem conscious. They seem, not conscious, but living. If the universe is finite, we're all living in the Game of Life, just slowed down. I mean, it sped up a lot. But do you think technically some of the ideas that you used for analysis of algorithms can be used to analyze the Game of Life? Can we make sense of it? Or is it too weird? Yeah. I mean, I've got a dozen exercises in volume four, fascicle six, that actually work rather well for that purpose. Bill Gospers came up with the algorithm that allows Golly to run thousands and thousands of times faster. You know the website called Golly? G O L L Y?

本集資源與出處