莫非定律

《別子才司令》宋‧方岳
不如意事常八九,
可與語人無二三。
自識荆門子才甫,
夢馳鐵馬戰城南。

 

俗話說︰智者千慮終有一失,愚者千慮總有一得。這麼看來所謂的『人生不如意事十常八九』,是因為『思慮』難得『完備』之故!為什麼『思慮』無法『完備』的呢?是由於『偶發』之『無常』!那麼為什麼西諺也講︰

I never had a slice of bread particularly large and wide that did not fall upon the floor and always on the buttered side.

麵包落地的時候,永遠是抹奶油的一面著地。

 

雖我們曾在《布林代數》談及過這個『莫非定律』的由來︰

近年來根據美國方言學會 ADS American Dialect Society Stephen Goranson 的研究,一八七七年的一次工程學會會議上 Alfred Holt 的報告上提出︰

It is found that anything that can go wrong at sea generally does go wrong sooner or later, so it is not to be wondered that owners prefer the safe to the scientific …. Sufficient stress can hardly be laid on the advantages of simplicity. The human factor cannot be safely neglected in planning machinery. If attention is to be obtained, the engine must be such that the engineer will be disposed to attend to it.

,由此看來,說不定是 De Morgan 錯記『莫非』Murphy 的

Mathematician Augustus De Morgan wrote on June 23, 1866: “The first experiment already illustrates a truth of the theory, well confirmed by practice, what-ever can happen will happen if we make trials enough.” In later publications “whatever can happen will happen” occasionally is termed “Murphy’s law,” which raises the possibility — if something went wrong — that “Murphy” is “De Morgan” misremembered (an option, among others, raised by Goranson on American Dialect Society list).

這個大名鼎鼎的『莫非定律』說︰

凡事要可能出錯,必定會出錯!!

從科學和演算法方面來講,它和『最糟情境』worst-case scenario 分析同義,然而就文化層面而言,它代表著一種反諷式的幽默,也許能排解日常生活中諸多遭遇的不滿。

那人們該如何設想『莫非之機率』的呢?一九零九年時法國數學家埃米爾‧博雷爾 Félix-Édouard-Justin-Émile Borel 在一本機率書中介紹了一個『打字猴子』的概念︰

讓一隻猴子在打字機上隨機地按鍵,當這樣作的時間趨近無窮時,似乎必然能夠打出任何指定的文本,比如說整套莎士比亞的著作。

他用這隻猴子來比喻一種能夠產生無窮的隨機語詞字串之『抽象設備』。這個『無限猴子定理』理論是說︰把一個很大但有限的數看成無限的推論是錯誤的。猴子能否完全無誤的敲打出一部莎士比亞的哈姆雷特,縱使它發生的機率非常之小然而絕非是零!就像戰國時期的列禦寇在《列子‧湯問》中寫到︰

愚公移山

太行、王屋二山,方七百里,高萬仞,本在冀州之南,河陽之北。

北 山愚公者,年且九十,面山而居。懲山北之塞,出入之迂也。聚室而謀曰:「吾與汝畢力平險,指通豫南,達於漢陰,可乎?」雜然相許。其妻獻疑曰:「以君之 力,曾不能損魁父之丘,如太行、王屋何?且焉置土石?」雜曰:「投諸渤海之尾,隱土之北。」遂率子孫荷擔者三夫,叩石墾壤,箕畚運於渤海之尾。鄰人京城氏 之孀妻有遺男,始齔,跳往助之。寒暑易節,始一反焉。

河曲智叟笑而止之曰:「甚矣,汝之不惠。以殘年餘力,曾不能毀山之一毛,其如土石何?」北山愚公長息曰:「汝心之固,固不可徹,曾不若孀妻弱子。雖我之死,有子存焉;子又生孫,孫又生子 ;子又有子,子又有孫;子子孫孫無窮匱也,而山不加增,何苦而不平?」河曲智叟亡以應。

操蛇之神聞之,懼其不已也,告之於帝。帝感其誠,命誇娥氏二子負二山,一厝朔東,一厝雍南。自此,冀之南,漢之陰,無隴斷焉 。

───

 

不過依舊很難解釋到底為什麼︰

凡事要可能出錯,必定會出錯!!

彷彿總墜無窮思辯之中!!

設想只知道

\lim \limits_{Time \to \infty} \ IS_{OK}(Time) \ \to 0

,果能邏輯推斷

\lim \limits_{Time \to \infty} \ Time \times \ IS_{OK}(Time) \ \to \ ?

是多少的乎??

或許這正是古話︰

何謂『明智』?能將『事後之明』,用於『臨事』也。

希冀之事耶!!

莫非『派生』 Python 深知其理,於是有

29.12. inspect — Inspect live objects

Source code: Lib/inspect.py


The inspect module provides several useful functions to help get information about live objects such as modules, classes, methods, functions, tracebacks, frame objects, and code objects. For example, it can help you examine the contents of a class, retrieve the source code of a method, extract and format the argument list for a function, or get all the information you need to display a detailed traceback.

There are four main kinds of services provided by this module: type checking, getting source code, inspecting classes and functions, and examining the interpreter stack.

───

 

程式庫的嗎??所以有『派生者』 Pythonian 追隨其理念,創作

Python object browser implemented in Qt

objbrowser

Extensible Python object inspection tool implemented in Qt.

Displays objects as trees and allows you to inspect their attributes recursively (e.g. browse through a list of dictionaries). You can add your own inspection methods as new columns to the tree view, or as radio buttons to the details pane. Altering existing inspection methods is possible as well.

Installation:

  1. Install PySide: http://qt-project.org/wiki/Category:LanguageBindings::PySide
  2. Run the installer:
pip install objbrowser

User interface:

objbrowser screen shot

From the View menu you can select some extra columns, for instance the objects’ id column. This can also be done by right-clicking on the table header.

If the Show routine attributes from the View menu is checked, functions and methods that are attributes of the object are shown, otherwise they are hidden. Routines that are not an object attribute, for instance functions that are an element in a list, are always displayed.

If the Show special attributes from the View menu is checked, attributes whos name start and end with two underscores are displayed.

The details pane at the bottom shows object properties that do not fit on one line, such as the docstrings and the output of various functions of the inspect module from the Python standard library.

───

 

,將之宣揚於天下的也!!