勇闖新世界︰《邏輯編程》

就讓我們從《人工智慧!!》一文中所講的『哲學爭論』︰

一九八零年希爾勒寫了一篇論文《心靈、大腦、與程式》Minds, Brains, and Programs,講到一個稱作『中文房間』Chinese room 的思想實驗︰

220px-Salachinesa2

一 位中文一竅不通,以英文為母語的人,關閉在一間只有一個開口的密閉房間中。房間裡有一本英文手冊以及伴隨著的電腦程式,還有充足的紙、筆、橡皮擦與檔案 櫃。門外的人從那個開口向房間內輸入中文之字詞,門裡的人便按照程式指令處理,再由那個開口輸出中文字詞。假使該程式已然通過中文的圖零測試,當然那人自 可以作剛才所說的這件事情。他只需簡單『用手』manually 來跑程式就好了。

希爾勒認為,儘管門裡的人很能夠以假亂真,讓門外的人以為他本就是華語使用者,然而他卻是壓根不懂中文的啊!假使門裡的人是『不可能』透過英文手冊來『理解』中文的話,那麼電腦也是不可能借著程式來獲得這個『理解力』的吧!!

有 批評者這麼說︰人們都認為人是擁有智慧的,然而人的智慧卻是來自於腦細胞的物理訊息轉換作用,單一個腦細胞並不能理解字詞的意義,難道不是大量的腦細胞造 就了人 類的認知與理解能力的嗎?這跟有眾多指令組成的整體程式又能有什麼實質的差異呢?所以為什麼電腦就不可能會有『理解力』的呢??

,展開『新世界』科技的探索。首先讀讀

年代 20世紀40年代 20世紀50年代 20世紀60年代 20世紀70年代 20世紀80年代 20世紀90年代
計算機 1945 計算機(ENIAC) 1957 FORTRAN語言
人工智慧研究 1953 博弈論
1956 達特矛斯會議
1977 知識工程宣言 1982 第五代電腦計劃開始 1991 人工神經網路
人工智慧語言 1960 LISP語言 1973 PROLOG語言
知識表達 1973 生產系統
1976 框架理論
專家系統 1965 DENDRAL 1975 MYCIN 1980 Xcon

,可以對於『人工智慧』的進程、主張以及批評,有個初步了解。知道此一語詞早在一九五五年,就由約翰‧麥卡錫  John McCarthy 所鑄造︰

Artificial intelligence (AI) is the intelligence exhibited by machines or software. It is also the name of the academic field of study which studies how to create computers and computer software that are capable of intelligent behavior. Major AI researchers and textbooks define this field as “the study and design of intelligent agents”,[1] in which an intelligent agent is a system that perceives its environment and takes actions that maximize its chances of success.[2] John McCarthy, who coined the term in 1955,[3] defines it as “the science and engineering of making intelligent machines”.[4]

,至今也已經有了一甲子了。這樣看來,也許人類尚未能理解如何創造科學怪人的奧秘。

英國著名小說家瑪莉‧雪萊 Mary Shelley 因一八八一年所創作的《弗蘭肯斯坦》 Frankenstein’s monster ── 科學怪人 ── 被譽為科幻小說之母。她曾經提到了伽伐尼的研究報告︰這份研究報告是夏季閱讀書目的一部分,這一書目引發了在瑞士的一次下雨天所進行的一場即席鬼故事大賽,繼而導致了小說《弗蘭肯斯坦》和其中的復活情節的誕生。

180px-Frankenstein.1831.inside-cover

那位 LISP 之父,約翰‧麥卡錫,也於二零一一年十月辭世。──

樹莓 λ 者 Lisps》︰

220px-Lisplogo_alien_256

“Lisp has jokingly been called “the most intelligent way to misuse a computer”. I think that description is a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.” — Edsger Dijkstra, CACM, 15:10

一九五四年美國艾倫‧紐厄爾 Allen Newell、克里夫‧蕭 Cliff Shaw 和赫伯特‧西蒙 Herbert Alexander Simon 等人於蘭德公司卡內基技術學院研發了資訊處理語言 IPL Information Processing Language 。它以『圖靈測試』為目標,被認為是史上第一個用於『人工智慧』── 符號演算』系統可以衍生出智慧 ── 領域的語言,首先使用了『串列』 Link List 結構與『遞迴』,啟發了之後『Lisp』的發展。一九五八年約翰‧麥卡錫 John McCarthy ── 在一九五五年的達特矛斯會議上提出了『人工智慧』這個概念── 於麻省理工學院發明了 Lisp 這個程式語言。其中採用了 IPL 語言的特徵。一九六零年麥卡錫在《ACM 通訊》上發表了一篇名為《遞迴函式的符號表達式以及由機器運算的方式,第一部》 Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I 之論文。在這篇論文中,他展示了只要透過一些簡單的運算子以及函式的記號法,也就可以建立一個具有『圖靈完備性』的 λ 演算法語言。約翰‧麥卡錫的學生史帝芬‧羅素 Steve Russell ── 著名程式設計師與計算機科學家,曾在 PDP-1 上創造了第一個電子遊戲 Spacewar ! ── 在閱讀完此論文後,認為 Lisp 程式語言當中的『eval 函式』可以用『機器碼』來實做。他於是在IBM 704 機器上,完成了第一個 LISP 『解譯器』 Interpreter。Lisp 的名稱來自於『串列處理器』 List Processor 之縮寫,最初拼寫為『LI SP』,是一個僅次於 Fortran 語言之歷史悠久的泛函式計算機程式語言,以『波蘭表示法』編程,擁有多種方言家族。

── 。

據聞,

「簡約派(the neats)」:邏輯,Prolog語言和專家系統

早在 1958 年,John McCarthy 就提出了名為「納諫者(Advice Taker)」的一個程序構想,將邏輯學引入了 AI 研究界。[94] 1963年,J. Alan Robinson發現了在計算機上實現推理的簡單方法:歸結(resolution)與合一(unification)算法。然而,根據 60 年代末McCarthy 和他的學生們的工作,對這一想法的直接實現具有極高的計算複雜度:即使是證明很簡單的定理也需要天文數字的步驟。[95] 70 年代 Robert Kowalsky 在Edinburgh大學的工作則更具成效:法國學者 Alain Colmerauer 和 Phillipe Roussel 在他的合作下開發出成功的邏輯程式語言 Prolog[96]

Dreyfus等人針對邏輯方法的批評觀點認為,人類在解決問題時並沒有使用邏輯運算。心理學家 Peter Wason,Eleanor Rosch,阿摩司·特沃斯基,Daniel Kahneman 等人的實驗證明了這一點。[97] McCarthy 則回應說,人類怎麼思考是無關緊要的:真正想要的是解題機器,而不是模仿人類進行思考的機器。

,是目前這場革命中的皎皎者。

由於實務上的學習考量,並不打算詳細介紹『Prolog』這個語言。有興趣深入的讀者可以下載閱讀

Simply Logical

Intelligent Reasoning by Example

by Peter Flach

這本教科書。

我們將把『輕量級』的『邏輯編程』帶入『派生』 Python 世界裡,探一探這個『典範』的主旨,嚐一嚐『人工智慧』的味道,談一談 pyDatalog 的一些應用。

 

from pyDatalog import pyDatalog
pyDatalog.create_terms('factorial, N')
factorial[N] = N*factorial[N-1] 
factorial[1] = 1
print (factorial[3==N) # prints N=6
  pyDatalog extends Datalog with logic functions
 Easy to learn
Based on programmer-friendly Python 

 Be productive
Write short, declarative programs
Batteries included
With full access to the extensive Python library 
Be readable
Order your statements to be literate 
Query 11 SQL databases 
and noSQL, and Python classes 
Use AI
to implement expert systems and complex algorithms
pyDatalog adds the logic programming paradigm to Python‘s extensive toolbox, in a pythonic way.  
 
Logic programmers can now use the extensive standard library of Python, and Python programmers can now express complex algorithms quickly.
Datalog is a truly declarative language derived from Prolog, with strong academic foundations.  Datalog excels at managing complexity.  Datalog programs are shorter than their Python equivalent, and Datalog statements can be specified in any order, as simply as formula in a spreadsheet. 
pyDatalog can be used for:
  • simulating intelligent behavior (for games or expert systems), 
  • querying complex sets of related information (e.g. in data integration or Natural Language Processing),
  • performing recursive algorithms (e.g. on hierarchical data structure)
pyDatalog is derived from previous work by John D. Ramsdell.  It is an open-source project (LGPL) lead by Pierre Carbonnelle (in Belgium).  It is inspired by LogicBlox.

Core technology

 Core technology in pyDatalog  Benefits  Sample applications
The resolution engine determines the best sequence of clauses to use to reach a goal Spreadsheet-style programming : faster development; fewer bugs, easier to read afterwards Rule-based models with many input and output, e.g. expert system for price calculation or tax planningaccess right managementrobot controlintelligent agent in games or automated assistants
The resolution engine can resolve recursive algorithm Easy to write queries on hierarchical structure Reporting with hierarchical reference data such as organisational structure
The same clause can solve various mixes of known and unknown parameters Maximize code reuse : shorter program, simpler query language than SQL Cross-database queries, data integration
Intermediate results are memoized. Improved speed by avoiding duplicate work. Business logic in 3-tier architecture.