Plankalkül

維基百科,自由的百科全書
跳至導覽 跳至搜尋
Plankalkül
編程範型過程式
設計者Konrad Zuse
釋出時間1948年,​78年前​(1948 – 概念首次發表
主要實作產品
Plankalkül-Compiler(柏林自由大學於2000年實現[1]
影響語言
Superplan英語Superplan, ALGOL 58[2]

Plankalkül德語發音:[ˈplaːnkalkyːl])是康拉德·楚澤在1942至1945年間,出於工程目的而設計的一種程式語言。它是第一種為計算機設計的高級程式語言

「Kalkül」在德語中意為形式系統。如希爾伯特演繹系統原本名為「Hilbert-Kalkül」那樣,「Plankalkül」指用於規劃(planning)的形式系統[3]

描述[編輯]

Zuse在1960年代的照片

Plankalkül可比較於APL關係代數。它包括賦值語句、子例程、條件語句、迭代、浮點算術、陣列、層級記錄結構、斷言、例外處理和其他高級特徵比如目標導向執行。Plankalkül提供了叫做「廣義」(verallgemeinerter Graph)的數據結構,它可以被用來表示幾何結構[4]

Plankalkül的很多特徵重現於後來的程式語言之中;一個例外是其特質性的使用佔據多行的表示法。

Plankalkül的一些特徵[5]

  • 只有局部變量,
  • 函數不支持遞歸,
  • 只支持傳名調用
  • 合成類型是陣列和元組,
  • 包含條件表達式,
  • 包含for循環和while循環,
  • 沒有goto

數據類型[編輯]

在Plankalkül中唯一的原始數據類型是單一的「是否值」(德語:Ja-Nein-Werte)即布爾值。它被指稱為標識符 <math>S0</math>。所有進一步的數據類型都是合成的,並且從原始類型通過「陣列」和「記錄」的方式建造而成[6]

所以8位序列(這在現代計算中被當作字節)被指稱為<math>8 \times S0</math>,而大小為 <math>m</math>乘<math>n</math>的布爾陣列,被描述為<math>m \times n \times S0</math>。還存在更短的表示法,可以將<math>n \times S0</math>替代為<math>S1 \cdot n</math>,它叫做「n是否值序列」(德語:n-stellige Folge von Ja-Nein-Werten[6]

類型<math>S0</math>有兩個可能的值<math>0</math>和<math>L</math>。所以4位序列可以寫為例如<math>L00L</math>,但是在這樣的一個序列表示一個數的情況下,編程者可以使用十進制表示法的<math>9</math>[6]

Zuse還定義了<math>S2</math>為<math>2 \times \sigma</math>(或寫為<math>2 \sigma</math>)即有序對(德語:Angabenpaar);<math>S3</math>為<math>m \times \sigma</math>即列表(德語:Liste),在元素數量不定時寫為<math>\Box \times \sigma</math>;<math>S4</math>為<math>m \times 2\sigma</math>即有序對列表(德語:Paarliste),在元素數量不定時寫為<math>\Box \times 2\sigma</math>。兩個組件(component,德語:Glieder)<math>\sigma</math>和<math>\tau</math>的結構(德語:Struktur)被寫為<math>(\sigma, \tau)</math>[6]

Plankalkül中類型(德語:Art)構成自3個元素:結構(德語:Struktur),語用意義(德語:Typ),和可能的限制(德語:Beschränkung[6]。用戶定義的類型被標示為字母<math>A</math>連帶編號,比如<math>A1</math>,即第一個用戶定義的類型。

例子[編輯]

Zuse使用了來自象棋理論的很多例子[6]

<math>A1</math> <math>S1 \cdot 3</math> 棋盤的坐標(它的大小為<math>8 \times 8</math>所以<math>3</math>位就足夠了)。
<math>A2</math> <math>2 \times A1</math> 棋盤的方格(例如<math>L00, 00L</math>指稱代數記譜法中的e2)。
<math>A3</math> <math>S1 \cdot 4</math> 棋子(例如<math>00L0</math>指稱白)。
<math>A4</math> <math>(A2, A3)</math> 棋盤上的棋子(例如<math>L00, 00L; 00L0</math>指稱白在e2中)。
<math>A5</math> <math>64 \times A3</math> 棋盤(棋子位置,描述64的方格都包含哪個棋子)。
<math>A10</math> <math>(A5, S0, S1 \cdot 4, A2)</math> 遊戲狀態(<math>A5</math>指稱棋盤,<math>S0</math>指稱行棋玩家,<math>S1 \cdot 4</math>指稱王車易位的可能性(<math>2</math>位給白棋<math>2</math>位給黒棋),<math>A2</math>指稱關於哪個單元格有可能吃過路兵)。

標識符[編輯]

標識符(德語:Bezeichnungen)是字母字符連帶編號[6]。針對變量有如下標識符種類[7]

  • 輸入值(德語:Eingabewerte, Variablen),標記以字母<math>V</math>。
  • 中介值,臨時值(德語:Zwischenwerte),標記以字母<math>Z</math>。
  • 常值(德語:Constanten),標記以字母<math>C</math>。
  • 輸出值(德語:Resultatwerte),標記以字母<math>R</math>。

特定的某種變量由寫在種類之下的編號來標示[6],例如:<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>,<math>\begin{smallmatrix} Z \\ 2 \end{smallmatrix}</math>,<math>\begin{smallmatrix} C \\ 31 \end{smallmatrix}</math>等等。

程序和子例程都被表達為過程(德語:Rechenpläne),它被標記以字母<math>P</math>,跟隨着一個程序編號(德語:Nummer),或者以點號分隔的程序組編號與程序編號。例如:<math>P12</math>、<math>P3 \cdot 7</math>[6]

子例程<math>P17</math>的輸出值保存在變量<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>中,其他子例程能在標識符<math>\begin{smallmatrix} R17 \\ 0 \end{smallmatrix}</math>之下獲得到它,而讀取這個變量的值還意味着調用有關的子例程[6]

按索引訪問元素[編輯]

Plankalkül允許使用組件(component)索引(德語:Komponenten-Index)訪問變量的單獨元素。例如,當一個程序接收輸入於具有類型<math>A10</math>(遊戲狀態)的變量<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>之中,那麼<math>\begin{smallmatrix} V \\ 0 \\ 0 \end{smallmatrix}</math>給出棋盤狀態,<math>\begin{smallmatrix} V \\ 0 \\ 0 \cdot i \end{smallmatrix}</math>給出在編號<math>i</math>方格中的棋子,而<math>\begin{smallmatrix} V \\ 0 \\ 0 \cdot i \cdot j \end{smallmatrix}</math>給出這個棋子的位編號<math>j</math>[6]

在現代程式語言中,這可以用描述為表示法類似於V0[0]V0[0][i]V0[0][i][j](儘管訪問單一的位在現代程式語言中典型的使用位掩碼)。

語法[編輯]

由於變量的索引是垂直書寫的,邏輯上一行的Plankalkül指令要求佔據4或3物理行來書寫。

第一行包含變量種類,第二行標記以<math>V</math>(德語:Variablen-Index)包含變量編號,第三行標記以<math>K</math>(德語:Komponenten-Index)包含組件索引,而第四行標記以<math>S</math>(德語:Struktur-Index)是類型描述。類型不是必需的,但是Zuse評說到這能幫助閱讀和理解程序[6]

在<math>S</math>行中類型<math>S</math>前綴可以去掉,例如[6]

<math>S \; \left| \; S1 \cdot n \quad m \times S1 \cdot n \quad S0 \quad S1 \quad \sigma \right. </math>,可以簡寫為<math> \ S \; \left| \; 1 \cdot n \quad m \times 1 \cdot n \quad 0 \quad 1 \quad \sigma \right. </math>。

進一步的類型<math>A</math>前綴也可以去掉,例如:

<math>S \; \left| \; A1 \quad A2 \quad S0 \quad A3\ \quad \sigma \right. </math>,可以簡寫為<math> \ A \; \left| \; 1 \quad 2 \quad 0 \quad 3\ \quad \sigma \right. </math>。<math>A0</math>同義於<math>S0</math>。

變量的索引的例子:

l}
   & V \\ 
 V & 3 \\
 K & \\
 S & m \times 2 \times 1 \cdot n
\end{array}</math>
變量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>,它是<math>m</math>個有序對的類型<math>S1 \cdot n</math>的值的列表。
l}
   & V \\ 
 V & 3 \\
 S & m \times 2 \times 1 \cdot n
\end{array}</math>
<math>K</math>行在其為空時可以越過。因此這個表達式含義同於前者。
l}
   & V \\ 
 V & 3 \\
 K & i \cdot 0 \cdot 7 \\
 S & 0
\end{array}</math>
變量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>的第<math>i+1</math>個有序對的第<math>1</math>(索引<math>0</math>)組件的第<math>8</math>(索引<math>7</math>)位,它擁有布爾類型<math>S0</math>。

索引可以不只是常值。變量可以被用作其他變量的索引,而這被標記為折線,它展示變量的值將在哪個組件索引中使用:

使用變量作為其他變量的索引,出自第二版的Plankalül表示法。 變量<math>\begin{smallmatrix} V \\ 3 \end{smallmatrix}</math>的第<math>\begin{smallmatrix} Z \\ 5 \end{smallmatrix}</math>個元素。等價於在很多現代語言中的表達式V3[Z5][6]

賦值運算[編輯]

Zuse在他的演算中介入了賦值算子,這個概念未知於他之前的數學中。他將其標記為<math>\Rightarrow</math>,並稱其為產生符號(德語:Ergibt-Zeichen)。使用賦值的概念是在數學和計算機科學之間的關鍵差異[8]

例如下列表達式:

lll}
   & Z &+& 1  & \Rightarrow& Z\\ 
 V & 1   & &      & & 1\\
 S & 1 \cdot n& & 1 \cdot n & &  1 \cdot n \\
\end{array}</math>
向整數中間值<math>\begin{smallmatrix} Z \\ 1 \end{smallmatrix}</math>增加數量<math>1</math>。
lll}
   & (V &,& V)  & \Rightarrow& R\\ 
 V & \;\, 0   & &   1  & & 0\\
 S & \;\, \sigma & & \sigma & & 2 \sigma \\
\end{array}</math>
將值<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>和<math>\begin{smallmatrix} V \\ 1 \end{smallmatrix}</math>合成為<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math> 所指稱的合成值。

有人宣稱Konrad Zuse最初使用圖元File:Ergibt-Zeichen.png作為賦值的符號,並在Heinz Rutishauser英語Heinz Rutishauser的影響下開始使用<math>\Rightarrow</math>[6]Knuth和Pardo相信Zuse總是寫為<math>\Rightarrow</math>,而File:Ergibt-Zeichen.png是»Über den allgemeinen Plankalkül als Mittel zur Formulierung schematisch-kombinativer Aufgaben«的出版商在1948年介入的[8]。在ZürichALGOL 58會議中,歐洲與會者提議使用Zuse介入的賦值符號,而美國代表團堅持採用:=[6]

存儲賦值結果的變量(左值)被寫在賦值算子的右側[8]。對一個變量的第一次賦值被認為是對它的初始化聲明[6]

賦值算子的左側被用作表達式(德語:Ausdrücke),它定義哪個值將被賦值到這個變量。表達式可以使用算術算子、布爾算子和比較算子(<math>=</math>,<math>\neq</math>,<math>\leq</math>等等)[6]

控制流程[編輯]

布爾值被表示為整數,「否」(<math>\mathrm{nein}</math>)為<math>0</math>,而「是」(<math>\mathrm{ja}</math>)為<math>1</math>。條件控制流程採用守衛語句<math>\,\mathcal{A} \dot{\rightarrow} \mathcal{X}\,</math>的形式,這裏的加點箭頭叫做「條件符號」(德語:Bedingt-Zeichen),它指示在<math>\mathcal{A}</math>為「是」的條件下執行塊<math>\mathcal{X}</math>。迭代算子具有如下形式:

<math>\begin{matrix} W \\ \\ \\ \end{matrix} \begin{bmatrix} \mathcal{A} \dot{\rightarrow} \mathcal{X} \\ \mathcal{B} \dot{\rightarrow} \mathcal{Y} \\ \vdots \end{bmatrix}</math>

這裏的<math>W</math>表示「重複規劃」(德語:Wiederholungsplan),它重複直到所有守衛成為「否」[9]

算子<math>\mu x(x \in l \and R(x))</math>和<math>\lambda x(x \in l \land R(x))</math>意圖用在迭代運算之中,<math>\mu x</math>對變量<math>l</math>進行遞增索引的遍歷,而<math>\lambda x</math>對其進行遞減索引的遍歷,找出其符合特定條件<math>R()</math>的下一個(含第一個)元素<math>x</math>。典型用法是將在局部變量<math>x</math>中的符合條件元素賦值到中間變量之中,然後在用豎槓<math>\left| \right. </math>分隔出的後續語句之中,在前面語句成功找到符合條件的元素之時對此中間變量做進一步處理。

術語[編輯]

Zuse稱呼一個單一的程序為「計算規劃」(德語:Rechenplan)。他設想其所稱謂的「規劃組裝設備」(德語:Planfertigungsgerät),能自動的將一個程序的數學公式轉換成機器可讀的打孔電影膠片,這是在今天稱為翻譯器編譯器的某種東西[5]

例子[編輯]

下面的例子程序計算整數的階乘

<math> \begin{align} & \quad P1.1 \\ &\; \, \begin{array}{r}

   \\ 
 V \\
 K \\
 A \\
\end{array} \left| \; \begin{array}{lll}
  R(V)  & \Rightarrow& R\\ 
  \, \quad 0 &   &  0 \\
  & & \\
  \quad 10 &  &  10 \\
\end{array} \right. \\

& \; \, \begin{array}{r}

   \\ 
 V \\
 K \\
 A \\
\end{array}  \left| \; \begin{array}{lll}
    1 & \Rightarrow& R\\ 
   &   &  0 \\
  & & \\
  10 &  &  10 \\
\end{array} \right. \left| \; \begin{array}{lll}
    V  +  1 & \Rightarrow& Z\\ 
  0  &  &  0 \\
  &  & \\
  10 \; \; \; 10 &  &  10 \\
\end{array} \right. \\

&\; \, \begin{array}{r}

   \\ 
 V \\
 K \\
 A \\
\end{array} \left| \; \begin{array}{l} W2(Z) \\ \quad \quad 0 \\ \\  \quad \quad 10 \end{array} \left [ \begin{array}{l}

i > 0 & \dot{\rightarrow} \\ \\ \\ 10 \; \; 10 & \\ \end{array} \left[ \begin{array}{lll}

            R \times i & \Rightarrow &  R\\ 0 & & 0 \\ &  & \\ 10 \; \; \; 10 & & 10 \end{array} \right] \right] \right.

\end{align} </math>

這裏的Zuse定義的用戶類型<math>A10</math>表示全部整數。第一行包含「邊界概要」(德語:Randauszug),它定義程序<math>P1.1</math>接受一個變元(實際參數),即叫做<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix}</math>的一個整數,並返回叫做<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>的一個整數。這個程序將<math>1</math>賦值到<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>,將<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix} + 1</math>賦值到<math>\begin{smallmatrix} Z \\ 0 \end{smallmatrix}</math>。接着迭代算子<math>W2</math>執行重複運算,將從<math>\begin{smallmatrix} Z \\ 0 \end{smallmatrix} - 1</math>遞減至<math>0</math>的值,依次賦值到局部變量<math>i</math>,這裏將大於<math>0</math>的<math>i</math>值累乘至<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>。當重複結束之時,值<math>\begin{smallmatrix} R \\ 0 \end{smallmatrix}</math>就包含了變元的階乘。

Zuse還定義了用戶類型<math>A8</math>表示自然數,<math>A9</math>表示非負整數,<math>A11</math>表示非負分數,<math>A12</math>表示全部分數,<math>A13</math>表示複數。迭代算子<math>W0</math>、<math>W1</math>和<math>W2</math>接受一個非負整數<math>n</math>,<math>W0</math>只重複<math>n</math>次而不賦值局部變量,<math>W1</math>重複時將從<math>0</math>遞增至<math>n-1</math>的值賦值給局部變量<math>i</math>;迭代算子<math>W3</math>、<math>W4</math>和<math>W5</math>接受兩個非負整數<math>(n,m)</math>並賦值到局部變量<math>i</math>,<math>W3</math>在<math>n<m</math>時從<math>n</math>遞增至<math>m-1</math>,<math>W4</math>在<math>n>m</math>時從<math>n</math>遞減至<math>m+1</math>,<math>W5</math>在<math>n<m</math>時從<math>n</math>遞增至<math>m-1</math>而在<math>n>m</math>時從<math>n</math>遞減至<math>m+1</math>。使用<math>W4(\begin{smallmatrix} V \\ 0 \end{smallmatrix}, 0)</math>,可以省略<math>\begin{smallmatrix} V \\ 0 \end{smallmatrix} + 1</math>的初始值設置,和<math>i > 0</math>的守衛條件判斷。

引用[編輯]

  1. ^ Rojas, Raúl; Göktekin, Cüneyt; Friedland, Gerald; Krüger, Mike; Scharf, Ludmila; Kuniß, Denis; Langmack, Olaf. Konrad Zuses Plankalkül — Seine Genese und eine moderne Implementierung (PDF). Hellige, Hans Dieter (編). Geschichten der Informatik. Visionen, Paradigmen, Leitmotive. Teil 3: Leitideen und Paradigmen in der Entwicklung der Programmiersprachen und der Programmierung 1. Berlin / Heidelberg, Germany: Springer-Verlag. January 2004: 215–235 [2–4]. ISBN 978-3-642-62208-3. doi:10.1007/978-3-642-18631-8_9. (原始內容 (PDF)存檔於2006-05-01) (Deutsch).  (21 [24] pages)
  2. ^ Rojas, Raúl; Hashagen, Ulf. The First Computers: History and Architectures. MIT Press. 2002: 292 [2013-10-25]. ISBN 978-0-26268137-7. 
  3. ^ Zenil, Héctor (編). A Computable Universe: Understanding and Exploring Nature As Computation - with a Foreword by Sir Roger Penrose. Singapore: World Scientific Publishing Company. 2012: 791. 
  4. ^ Giloi, Wolfgang K., Konrad Zuses Plankalkül als Vorläufer moderner Programmiermodelle, November 1990 (Deutsch) 
  5. ^ 5.0 5.1 Hellige, Hans Dieter (編). 寫於Bremen, Germany. Geschichten der Informatik. Visionen, Paradigmen, Leitmotive 1. Berlin / Heidelberg, Germany: Springer-Verlag. January 2004: 45, 56, 89, 104–105, 113, 152, 216–217. ISBN 978-3-540-00217-8. doi:10.1007/978-3-642-18631-8. ISBN 3-540-00217-0 (Deutsch).  (xii+514 pages)
  6. ^ 6.00 6.01 6.02 6.03 6.04 6.05 6.06 6.07 6.08 6.09 6.10 6.11 6.12 6.13 6.14 6.15 6.16 6.17 Bauer, Friedrich L.; Wössner, Hans. The "Plankalkül" of Konrad Zuse: A Forerunner of Today's Programming Languages (PDF). Communications of the ACM. 1972, 15 (7): 678–685. S2CID 17681101. doi:10.1145/361454.361515. (原始內容 (PDF)存檔於2009-02-20) (English).  (HTML頁面存檔備份,存於互聯網檔案館))
  7. ^ Zuse, Konrad. Rojas, Raúl; Wagner, G.; Scharf, Ludmila; Schöttker-Söhl [Schötke-Suhl], Susanne , 編. Der Plankalkül (In der Fassung von 1945) (Manuscript). Konrad Zuse Internet Archive. 1946: 10, 45 [2023-11-01]. ZIA ID: 0233. (原始內容存檔 (PDF)於2015-04-16) (Deutsch).  (1+1+180 pages)
  8. ^ 8.0 8.1 8.2 Knuth, Donald Ervin; Pardo, Luis Isidoro Trabb. The Early Development of Programming Languages (PDF). Stanford University, Computer Science Department: 8, 9, 14, 15. August 1976 [2017-12-28]. (原始內容 (PDF)存檔於2017-09-12). 
  9. ^ Rojas, Raúl. Plankalkül (PDF). Encyclopedia of computers and computer history. Chicago / London: Fitzroy Dearborn Publishers: 634. 2001 [26 May 2023]. ISBN 1-57958235-4. (原始內容存檔 (PDF)於2023-07-26). 

延伸閱讀[編輯]

  • Zuse, Konrad. Ansätze einer Theorie des allgemeinen Rechnens unter besonderer Berücksichtigung des Aussagenkalküls und dessen Anwendung auf Relaisschaltungen [Inception of a universal theory of computation with special consideration of the propositional calculus and its application to relay circuits] (unpublished manuscript). 1943. Zuse Papers 045/018 (Deutsch). 
  • Zuse, Konrad. 寫於Hopferau bei Füssen, Germany. Über den allgemeinen Plankalkül als Mittel zur Formulierung schematisch-kombinativer Aufgaben. Archiv der Mathematik (Karlsruhe / Stuttgart / Basel, Germany: Birkhäuser Verlag). 1948-12-06, 1 (6): 441–449. ISSN 0003-889X. doi:10.1007/BF02038459. eISSN 1420-8938 (Deutsch).  (9 pages)
  • Rojas, Raúl; Göktekin, Cüneyt; Friedland, Gerald; Krüger, Mike; Kuniß, Denis; Langmack, Olaf. Plankalkül: The First High-Level Programming Language and its Implementation (PDF). Berlin, Germany: Institut für Informatik, Freie Universität Berlin & Feinarbeit.de. February 2000. Technical Report B-3/2000. (原始內容存檔於2006-05-01) (English). [1] (22 pages)
  • Bruines, Bram. Plankalkül (PDF) (Thesis). 2010-01-08 [2023-11-02]. (原始內容存檔 (PDF)於2023-11-02).  (24 pages)

外部連結[編輯]

  • Plankalkül-Programme. Konrad Zuse Internet Archive. 2014-08-21 [2017-10-04]. (原始內容存檔於2014-08-21) (Deutsch及English).  (NB. Plankalkül Java applets and documents.)