W!o 的派生‧十日談之《四》

龐加萊 Poincaré 與玻爾茲曼 Boltzmann 等人創用『相空間』phase space 來描述物理上『三體問題』的時候,催生了︰

現今的混沌理論 Chaos theory 描述『非線性』系統在一定參數條件下會發生『分岔』 bifurcation 現象,周期運動與非周期運動可能相互『糾纏』,以至於通往某種非周期又可以有序之運動理論。因此它是一種兼具『定性』與『定量』的分析之思考方法,用以探討動力系統中無法僅用『一時單一』的數據,必須用『連續整體』的數據才能加以解釋或是描述該系統之行為。

220px-Double-compound-pendulum-dimensioned.svg

Double-compound-pendulum

220px-DPLE

Double_pendulum_flips_graph

混沌』chaos 一詞源自古希臘哲學家認為宇宙起源於混亂無序的狀態,逐漸由這個混沌之初形成現今有條不紊的世界。這個混沌論說︰

一切事物的初始狀態,都只是一些看似無關的碎片,然而當此混沌過程結束之時,這些碎片終自主有序的聚合成一個整體。

左圖演示一個『雙擺』Double pendulum 的運動,系統總能量取某些數量時它的運動是混沌的。假使想要對它『數值』求解,從『數值分析』的程式設計觀點來看這個數據『敏感性』問題 ── 叫做『惡劣條件』ill condition ──,通常需要作多次多種『收斂測試』,否則到底計算出來的是什麼,可就說不清的了。有興趣物理、數學或寫程式的讀者可以參考︰

Double Pendulum

Double Pendulum Demonstration

如果問大自然『作計算』嗎?假使答『』,那該如何『作計算』的呢??比方說,人類要怎麽『模擬』一莫爾 6^{23} 個氣體分子之『運動』的呢!事實上,想深入了解『三體互動』恐怕都需要借助『計算機』的哩!!那麼『自然律』果真能與『理化計算』等同的嗎???

所以就算今天已經有了『量子電腦』,那所需之『時間』 time 與『空間』 space ,在『計算』上所用之『資料』和『結構』,依然十分重要!也許有人認為,難到不能夠依賴『統計學』的嗎?只是適用於『晴天』的『統計』,誰曉得能不能用於『雨天』的呢!!

在《測不準原理》一文中,我們談到︰

如果縱觀橫看歷史源流,數學這個科學語言之王,有著『記號法』持續之『變革』一事,可以讓那些好『不容易』獲得的『成果』能以『簡潔』、『易記』與『易用』的方式『被表達』,也就是說它的『傳承』之『精煉』是有著這一個重要的『面象』,雖然它也許很容易就會『被忽略』。…

假使你將二元運算『⊕□○』看成數學上的『函數』function ── 比方說代表著 ⊕( □,○ )  ──,這就是 LISP 程式語言常用的表達式寫法,事實上許多程式語言內部都用著這樣的表達式記號法。現今『functional』泛函的或說是功能的一詞推廣之函數概念,成了一種寫程式的『典範』。由於波蘭表示法的計算方式過於麻煩,說不定還容易算錯,揚‧武卡謝維奇又提出『逆波蘭表示法』,不再把運算符號放在前面,卻是將它置於後頭的『後綴表示法』,如此二元運算寫成了『□○⊕』。這樣的寫法有什麼好處呢?最大的好處就是『計算規則』簡單︰

看到數目就將它放上『堆疊』Stack 頂端,

見著運算符號,如果堆疊頂端能取下兩數,取下運算後將結果放回堆疊頂端;如果堆疊頂端不能取下兩數,表達式有錯誤,

最終堆疊頂端將只有答案一數,否則表達式有錯誤。

下面的例子用逆波蘭表示法計算 『3 4 +  7 2 3 *  – *』,假使用【】表示右邊是頂部的堆疊,計算過程如下︰

【】『3 4 + 7 2 3 *  – *』
【3】『4 +  7 2 3 *  – *』
【3, 4】『+  7 2 3 *  – *』
【7】『7 2 3 * – *』
【7, 7】『2 3 *  – *』
【7, 7, 2,】『3 *  – *』
【7, 7, 2, 3】『*  – *』
【7, 7, 6】『- *』
【7, 1】『*』
【7】『』

……

這說明了一個好的『資料結構』,使得『特定程式』很容易撰寫,似乎無需考慮什麼『演算法』,彷彿用哪種『程式語言』都行。就像在《自我再現 ── Thue 改寫系統之補充《三》》文章裡,用『Thue』語言,也藉著『堆疊』來寫『邏輯運算式』求值的例子一般簡單。

如此我們容易明白維基百科針對『資料結構data structure 詞條所作的鋪陳︰

In computer science, a data structure is a particular way of organizing data in a computer so that it can be used effectively.

Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, databases use B-tree indexes for small percentages of data retrieval and compilers and databases use dynamic hash tables as look up tables.

Data structures provide a means to manage large amounts of data efficiently for uses such as large databases and internet indexing services. Usually, efficient data structures are key to designing efficient algorithms. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design. Storing and retrieving can be carried out on data stored in both main memory and in secondary memory. …

在電腦科學或資訊科學中,資料結構(英語:data structure)是電腦中儲存、組織資料的方式。通常情況下,精心選擇的資料結構可以帶來最優效率的演算法。

一般而言,資料結構的選擇首先會從抽象資料類型的選擇開始。一個設計良好的資料結構,應該在儘可能使用較少的時間空間資源的前提下,為各種臨界狀態下的執行提供支援。資料結構可通過編程語言所提供的資料類型、參照及其他操作加以實作。

不同種類的資料結構適合於不同種類的應用,而部分甚至專門用於特定的作業任務。例如,當電腦網路依賴於路由表運作時,B 樹高度適用於資料庫的封裝。

在 許多類型的程式設計中,選擇適當的資料結構是一個主要的考慮因素。許多大型系統的構造經驗表明,封裝的困難程度與最終成果的品質與表現,都取決於是否選擇了最優的資料結構。在許多時候,確定了資料結構後便能很容易地得到演算法。而有些時候,思路則會顛倒過來:例如當某個關鍵作業需要特定資料結構下的演算法時,會反過來確定其所使用的資料結構。然而,不管是哪種情況,資料結構的選擇都是至關重要的。

系統構造的關鍵因素是資料結構而非演算法的這 一深入理解,導致了多種形式化的設計方法與程式語言的出現。絕大多數的語言都帶有某種程度上的模組化思想,通過將資料結構的具體實作封裝隱藏於受限介面之 後的方法,來讓不同的應用程式能夠安全地重用這些資料結構。C++、Java、Python等物件導向的程式語言可使用類來完成這一功能。

……

芭芭拉‧利斯科夫』 Barbara Liskov ,本名 Barbara Jane Huberman。美國計算機科學家,她被公認為是一位 MIT 頂級女性教授,二零零四年穫約翰‧馮諾依曼獎,也是二零零八年圖靈獎得主。一九七四到一九七五年期間,她與學生發展了『 CLU 』程式語言︰

CLU is a pioneering programming language created at MIT by Barbara Liskov and her students between 1974 and 1975. While it did not find extensive use itself, it introduced many features that are now widely used, and is seen as a step in the development of object-oriented programming (OOP). However, it is not object-oriented itself, instead being considered “object-based“, as it intentionally omitted many features of OOP.

Key contributions include abstract data types, call-by-sharing, iterators, multiple return values (a form of parallel assignment), type-safe parameterized types, and type-safe variant types. It is also notable for its use of classes with constructors and methods, but without inheritance.

推動了以『物件』 Object 為基礎的『程式語言』發展,更掀起了『抽象資料型別』  abstract data types 的波瀾,深刻影響了『現今主流語言』C++/Java/Python/Ruby/C# 的建構。她所精煉的『資料抽象』思想,早已成為『軟體工學』中重要的之骨幹精髓。

所謂的『抽象資料型別』 ADT Abstract data type 是什麼呢?在此引用《樹莓 λ 者 Lisps》文中一小段︰

在計算機科學中,『資料結構』 data structure 是電腦中『儲存』 與『組織』資料的方式,通常『精心設計』或者是『擇優選取』的資料結構是可以產生執行速度『最佳化』之演算法。

408px-Singly-linked-list.svg

串列』 Linked list 是一種基礎的資料結構,它是一種『線性』的資料鏈接,是在每一個『資料節點』裡有指向下一個『資料節點』的『指標』Pointer。所以可以說它是一個『單向線性結構』的『資料容器』。假使你想要取得『n』的資料,你只能夠『從頭』一次一個的『向後』數到了『n - 1』,然後『再向後』一次,才能抵達那裡。

我們已經見識了『 λ表達式』可以定義『真假』與『自然數』這種『資料』和『資料操作』的例子,那麽它要如何定義『資料結構』的呢?就讓我們從數學上的『有序對』pair 開始,它是兩個對象的『聚集』collection,其中可以區分出一是『第一個物件』而另一是『第二個物件』,通常寫為 (a, b)。比方說『笛卡爾平面座標系』中的點 (x, y) 就是『定位座標xy 的聚集,它讓我們可以確定一個『』在這個『』上的位置。那麼我們要怎麽用 λ表達式『表徵』這樣的『概念』呢?比方講『杯子與水』,在前的物件是『』,在後的是『』。假使從『操作』的觀點講,如果 『\Box =  (杯,水)』是一個有序對,有兩個取回『操作子F, S

F(\Box) 是『第一個物件』,『
S(\Box) 是『第二個物件』,『

,就算我們不知道真正 \Box 的『結構』是什麼?但它難道會與所謂的『有序對』之操作不一樣的嗎??由於『(\Box, F, S)』── 資料封裝與資料存取方法 ── 所構成的系統是與『有序對概念』之系統『無法在操作上區分』,因此就將它『歸類』成為等效之抽象『有序對』的系統了,這個『等效』也就是所謂的『抽象資料型態』ADT  Abstract Data Type  的了!!也就是說如果我們定義了『建構有序對』、『取回第一個物件』以及『取回第二個物件』的方法函式,我們就得到了等效的『抽象有序對』。這在『 λ』裡可以定義如下︰

CONS =_{df} \lambda x. \lambda y. \lambda p. IFTHENELSE \  p \ x \ y,建構有序對
CAR =_{df}  \lambda x. \ x \ TRUE,取回第一個物件
CDR =_{df}  \lambda x. \ x \ FALSE,取回第二個物件

……

希望或可作為閱讀下文︰

In computer science, an abstract data type (ADT) is a mathematical model for data types where a data type is defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations. This contrasts with data structures, which are concrete representations of data, and are the point of view of an implementer, not a user.

Formally, an ADT may be defined as a “class of objects whose logical behavior is defined by a set of values and a set of operations”.; this is analogous to an algebraic structure in mathematics. What is meant by “behavior” varies by author, with the two main types of formal specifications for behavior being axiomatic (algebraic) specification and an abstract model. Some authors also include the computational complexity (“cost”), both in terms of time (for computing operations) and space (for representing values).

In practice many common data types are not ADTs, as the abstraction is not perfect, and users must be aware of issues like arithmetic overflow that are due to the representation. For example, integers are often implemented as fixed width (32-bit or 64-bit binary numbers), and thus experience integer overflow if the maximum value is exceeded.

ADTs are a theoretical concept in computer science, used in the design and analysis of algorithms, data structures, and software systems, and do not correspond to specific features of computer languages – mainstream computer languages do not directly support formally specified ADTs. However, various language features correspond to certain aspects of ADTs, and are easily confused with ADTs proper; these include abstract types, opaque data types, protocols, and design by contract. ADTs were first proposed by Barbara Liskov and Stephen N. Zilles in 1974, as part of the development of the CLU language.

之『階梯』。