November 06, 2006

程式語言的啟發性與科學史

每次閱讀 Embedded.com 眾多見解精闢的文章,都會有新的感受。早上拜讀 Jack W. Crenshaw 撰文 [Motivationally speaking],Jack W. Crenshaw 博士的技術背景主要是計算動力學領域,所以本文也以相關工程應用為主。副標題是 "A vector means many things to many people. Pilot, mathematician, physicist: all of their definitions can help you do your job",這讓我想到 Thomas Kuhn 的《科學革命的結構》,大量將「典範」(paradigm) 與「革命」等概念套用於科學史中,不僅侷限於科學史,事實上,「典範」的提出,幾乎滿足所有領域的需要。

所謂「典範」,是指一具有內部統一性與穩定性的解釋模式,當一個周密整合的典範某一部份發生了問題,一定導致整個典範的動搖,產生一個新的典範來取代舊的。Jack W. Crenshaw 這篇文章也讓我感到程式語言變遷的歷程中,「典範」概念的落實。C/C++ 無疑是當今使用最廣、跨越多種領域的通用程式語言,但 C 語言的初衷是設計作業系統 (很可惜,許多教材並未強調此點),其思考模式極難涵蓋於工程數學運算,稍後在 C++ 提出修正,大幅以 template 與 operator overriding 作為補強,也因此,許多通行的代數與數學 class library 也得兼顧效能、平台相容性,以及思維模式對應的便利性,然而,正如文章提到:
    Physicists saw things differently. They recognized the three-dimensional universe thing, and used vectors to describe real, physical quantities like position, velocity, momentum, etc. They used the algebra of the mathematicians, alright, but they only used the parts that related to the real world. And, as you'll see in a moment, they defined some new operations that the mathematicians hadn't thought of. To these physicists, vectors weren't merely a pleasant intellectual exercise. They were useful because they made our computations easier. Their interest in vectors increased tremendously with the discovery of electric and magnetic fields. It's hard to even imagine Maxwell's equations without vectors.
電子學經典的 Maxwell 方程式若以 C/C++ 表示,絕對相當彆扭且難懂,遑論缺乏 native 3D primitives 的 C/C++ 語言該如何表示空間與時間的轉換,此類「典範」的轉變,可說是當今工程技術的挑戰,這印證了 Thomas Kuhn 的核心觀點:科學發展不是一種直線累積的進步,而是一種革命性的結構轉變。

無論如何,在編譯器技術、SIMD/DSP,與 NUMA 等等技術大幅提昇的今日,已經有很大的改觀,要描述一個分子動力系統,可透過許多 modeling 途徑,最終也可轉換成高效能的計算模式,不啻是結構轉變的例證。
由 jserv 發表於 November 6, 2006 01:26 PM
迴響

可看看以下這篇文章的說法:
The "C is Efficient" Language Fallacy
http://scienceblogs.com/goodmath/2006/11/the_c_is_efficient_language_fa.php

C and C++ suck rocks as languages for numerical computing. They are not the fastest, not by a longshot. In fact, the fundamental design of them makes it pretty much impossible to make really good, efficient code in C/C++. There's a good reason that Fortran is still the language of choice for real, intense scientific applications that require the absolute best performance that can be drawn out of our machines - applications like computational fluid dynamics.

william 發表於 November 7, 2006 11:10 AM