勇闖新世界︰ 《 pyDatalog 》 導引《四》

既然探討『邏輯編程』,也許可以從不同抽象系統之『邏輯程式』的『比較』中,看出『理則概念』的『精深』,它的『表現』多重多樣,體會雖是『簡易自然』,實在是『難以窮盡』的哩!於此以兩篇文章片段為例︰

‧ 《自我再現 ── Thue 改寫系統之補充《三》

之前在《測不準原理》一文中,我們談過了揚‧武卡謝維奇的『逆波蘭表示法』,於此我們就利用這種表示法的運算並不需要使用括號的特性,寫一個  Thue 的『非、且、或、則』之邏輯符號的真假表達式之求值演算法︰

P 非  ︰P 的否定,
P Q 且︰PQ 的連言,
P Q 或︰PQ 的選言,
P Q 則︰若 PQ 的斷言。

在程式中『 』是使用者輸入的真假表達式,『』用以顯示單步逆波蘭表示法之堆疊推導進行點,『』表示逆波蘭表示法推導結束處,『』告知使用者推導結束。此時如果只剩下『』或『』表示推導正確完成,否則就是說表達式有錯誤。

───  程式起始 ───

真》非::=假》
假》非::=真》
真真》且::=真》
假真》且::=假》
真假》且::=假》
假假》且::=假》
真真》或::=真》
假真》或::=真》
真假》或::=真》
假假》或::=假》
真真》則::=真》
假真》則::=真》
真假》則::=假》
假假》則::=真》
》真::=真》
》假::=假》
》。::=~!
□::=:::
::=
》□。

─── 程式結束 ───

測試輸入︰

□ = 真非真且假非假或則;真
□ = 真真假假則則非則;假
□ = 假假真真則則且非;真
□ = 假假真真且非;假假假

 

‧   《λ 運算︰概念導引之《補充》※真假祇是個選擇??

就讓我們用 Lambda Calculator 之『純 λ 運算』,寫個『孤虛』NAND 邏輯,推算到底『牛郎織女』是『相會的成』還是『相會不成』的呢??

下面是『孤虛語』的『字典定義』︰

[\p. \q. p q 假] = \p.\q.p q 假
[\x. \y. y] = \x.\y.y
孤虛 [\u. \v. 非 ( 且 u v )] = \u.\v.u v 假 假 真
[\p. \q. p 真 q] = \p.\q.p 真 q
有數 [\f. \x. (f x)] = \f.\x.f x
沒嗎? [\n. n (\x. 假) 真] = \n.n (\x.假) 真
[\x. \y. x] = \x.\y.x
若則否則 [\p. \x. \y. p x y] = \p.\x.\y.p x y
[\p. p 假 真] = \p.p 假 真

已知『且 (孤虛 假 假) (孤虛 真 真) 』為『』,那麼

若則否則  (且 (孤虛 假 (非 假) ) (孤虛 真 (非 真) ))  (沒嗎? 假) (沒嗎? 有數) 』是『』還是『不成』的呢??

認真思索推導『歸結』 resolution 步驟之『意義』,所謂的『後設 』 meta 理論之『論述邏輯』難道能是不同的『理則』嗎?如此談『後設』之『後設』之……是否會有個『不動點』的呢??

假如我們用著電子學中的『反相器Inverter (logic gate) 來研究『矛盾律』,比方將它的『輸出』回饋成『輸入』,如是得到

I_{out} \ = \ not \ I_{in} \ = \ not \ I_{out}

,用示波器來看,也許得到的『答案』是『震盪』!有人解釋說︰反相器變換需要時間,因此不能代表上面的式子,這裡一點矛盾都沒有。如果我們將『時間』因素放入『邏輯系統』,比方說思考『時間邏輯』吧,這個『震盪』的意思就是

E_t_1  \ is \ True ,  \ E_{t_1 + \Delta t}  \ is \ False , \cdots \ E_{t_1 + n \times \Delta t}  \ is \ ?  \ \cdots

,那麼對此『事件』要如何『賦予真假』的呢?如果再講那個 \Delta t 可能遠小於人類的『觀測能力』,將怎樣『議論有無』的耶??假使又把『偶然性』和『必然性』加到『邏輯體系』裡,形成所謂的『模態邏輯』,那麼

必然的任何命題只有真假二值

是必然的真嘛!!??

俗話說︰萬丈高樓平地起。學問之道當如金字塔,否則容易不穩固 ,事實上也難架空中閣樓。這也就是

M♪o 之學習筆記本《卯》基件︰【䷗】正言若反

一文中, Clive Maxfield 先生的感嘆︰

Design How-To

Logic 101 – Part 2 – Positive vs Negative Logic

Clive Maxfield
11/21/2006 04:00 AM EST

The terms positive logic and negative logic refer to two conventions that dictate the relationship between logical values and the physical voltages used to represent them. Unfortunately, although the core concepts are relatively simple, fully comprehending all of the implications associated with these conventions requires an exercise in lateral thinking sufficient to make even the strongest amongst us break down and weep!

Before plunging into the fray, it is important to understand that logic 0 and logic 1 are always equivalent to the Boolean logic concepts of False and True, respectively (unless you’re really taking a walk on the wild side, in which case all bets are off). The reason these terms are used interchangeably is that digital functions can be considered to represent either logical or arithmetic operations (Fig 1).

 


1. Logical versus arithmetic views of a digital function.
Having said this, it is generally preferable to employ a single consistent format to cover both cases, and it is easier to view logical operations in terms of “0s” and “1s” than it is to view arithmetic operations in terms of “Fs” and “Ts”. The key point to remember as we go forward is that logic 0 and logic 1 are logical concepts that have no direct relationship to any physical values.

其實『邏輯運算』是『抽象世界』中的事,『物理裝置』存在於『自然宇宙』裡,若說『物理裝置』實現了『邏輯運算』,它當然需要一種『參考詮釋』,抽象的講︰『邏輯運算』與『物理狀態』之間的『映射』,用以『翻譯』和『解譯』什麼 □ 代表什麼 ○ 。有如一根『對數尺』透過『 log 函數』將『乘除』的計算變換為『加減』之計算一般。那個『映射』將『真、假』與電壓『高、低 』或電流『有、無』連繫起來的辦法,也許卻不只一種,所以真正令人『困惑』的到底又是什麼的呢??

如此我們容易明白『邏輯編程』 的『句式』與『推導規則』之選擇的務實面,它的表達力之『有限性』和應用領域的『特定性』 說明尚待未來者開疆闢土。或許有興趣讀者可以瀏覽維基百科 DSL 以及專家系統詞條,多得到一些了解。

因為『pyDatalog』中『述詞』 predicate 或叫『謂語』一般是用『二元 』或『多元』關係來表示。── 那有沒有『unary』關係或者述詞的呢? ── 所以清楚知道什麼是『關係』?就十分的重要,也許可以讀讀

‧ 《Thue 之改寫系統《一》

‧ 《Thue 之改寫系統《二》

作個開始。想想什麼是『語言』?我們可能從

Thue 之改寫系統《三》

一篇文章了解它嗎?假使我們已經了解了『Thue 語言』,我們可以藉著它了解『 λ運算』嗎?……終至於容易了解『pyDatalog』這個語言嗎?『學習』是否有一條『邏輯鍊索』?如果有,它會是什麼 ?如果沒,『學習』的『先後次序』豈非胡言亂語!還是它在似有若無之間,等待有心人去發掘!!

於是人們問︰只靠『巴科斯範式Backus–Naur Form 的描述,我們能夠對『pyDatalog』

Grammar of pyDatalog

The terminal symbols in this grammar are defined in BNF as follows :
  • simple_predicate ::= [a-zA-Z_] [0-9a-zA-Z_]*
  • constant ::= [a-z] [0-9a-zA-Z_]* | python literals | python object
  • variable ::= [A-Z_] [0-9a-ZA-Z_]*, thus starting with an uppercase
  • Note : words starting with _pyD_ are reserved for pyDatalog

 

grammar0.13_a

grammar0.13_b

 

知道多少呢??