數字派 NumPy ︰陣列運算‧《外傳二》APL ㄅ

事實上 Von Neumann 的計算機架構,對於電腦程式語言的發展,有著極為深遠的影響,產生了現在叫做 Von Neumann 程式語言,與Von Neumann 的計算機架構,同形 isomorphism 同構

program variables ↔ computer storage cells
程式變數 對映  計算機的儲存單元

control statements ↔ computer test-and-jump instructions
控制陳述 對映 計算機的『測試.跳至』指令

assignment statements ↔ fetching, storing instructions
賦值陳述 對映 計算機的取得、儲存指令

expressions ↔ memory reference and arithmetic instructions.
表達式 對映 記憶體參照和算術指令

John Warner Backus 曾經斷言,由於電腦圈長期過度強調 Von Neumann 的程式語言與計算機架構,已經產生了『惡性循環』,使得非此類的語言由於不符合經濟而日漸式微,比方 APL 語言 ── 註︰有興趣的,可以參照這裡在 Raspbian 上安裝 ──。

─── 《CPU 機器語言的『解譯器』

 

並非因 APL 不是

Von Neumann programming languages

A von Neumann language is any of those programming languages that are high-level abstract isomorphic copies of von Neumann architectures.[1] As of 2009, most current programming languages fit into this description[citation needed], likely as a consequence of the extensive domination of the von Neumann computer architecture during the past 50 years.

The differences between Fortran, C, and even Java, although considerable, are ultimately constrained by all three being based on the programming style of the von Neumann computer.[citation needed] If, for example, Java objects were all executed in parallel with asynchronous message passing and attribute-based declarative addressing, then Java would not be in the group.

The isomorphism between von Neumann programming languages and architectures is in the following manner:

  • program variables ↔ computer storage cells
  • control statements ↔ computer test-and-jump instructions
  • assignment statements ↔ fetching, storing instructions
  • expressions ↔ memory reference and arithmetic instructions.

 

亦無關乎 John Warner Backus 的

Criticism

John Backus asserted that assignment statements in von Neumann languages split programming into two worlds. The first world consists of expressions, an orderly mathematical space with potentially useful algebraic properties: most computation takes place here. The second world consists of statements, a disorderly mathematical space with few useful mathematical properties (structured programming can be seen as a limited heuristic that does apply in this space, though).

Backus[2] claimed that there exists now in computer science a vicious cycle where the long-standing emphasis on von Neumann languages has continued the primacy of the von Neumann computer architecture, and dependency on it has made non-von Neumann languages uneconomical and thus limited their further development: the lack of widely available and effective non-von Neumann languages has deprived computer designers of the motivation and the intellectual foundation needed to develop new computer architectures.[3]

Some examples of non-von Neumann languages are: APL, FP, FL, J, Lucid, NGL, ZPL, Mercury, and Plankalkül.[citation needed]

 

所以特寫

APL語言

概述

在許多應用場合下(數學、科學、工程技術、電腦設計、機器人、數據顯示、保險技術、傳統的數據處理等等)APL是一種非常有力的、表達豐富的和簡明的程式語言。它一般被用在一個與用戶接口的環境中。它最初的設計目的是將數學公式寫成一種電腦可以理解的方式。學它一般很容易,但要分析 APL 寫成的程序往往需要一段時間。與傳統的結構式程式語言不同的是,APL 的程序一般由一系列使用在序列上的單元的或雙元的函數或運算符號組成。由於APL擁有許多非標準的運算符號,這些符號之間沒有優先性(比如一般數學中的乘號、除號較加號、減號有優先權,APL中沒有這樣的優先權)。最初的APL語言沒有任何控制結構如循環(do-while)或者條件選擇(if-then-else),但一些序列運算符號可以用來模擬編程結構,比如iota(用來獲得一個從1至N的序列)可以用來模擬循環(for)。

APL 的工作環境被稱為工作場。在這個工作場內用戶可以定義程序和數據。數據也可以在工作場在程序外存在。用戶可以在程序外改變數據,比如:

\displaystyle N\leftarrow 4\ 5\ 6\ 7

將一個系列的數據4、5、6、7授予N。

\displaystyle N+4\,\!

輸出8、9、10、11。

\displaystyle +/N\,\!

輸出N內所有數的和,即22。

用戶可以將工作場連同其中的所有數據和程序儲存起來。在任何情況下,這些程序不是編譯執行,而是解釋執行的。

APL 最著名的就是它使用一組非ASCII符號。這些符號比一般常見的代數和計算符號要多。有人開玩笑說,用兩行這樣的奇形怪狀的符號就可以將所有航空控制的問題解決了。事實上,在一些APL版本中,用一行程序就可以將任何可計算的函數表達出來。在用一行你可以將這個函數的結構表達出來。由於它的精密的結構和非標準的符號,也有人將APL稱為「只寫語言」。除數學家外,其他人要讀APL寫的程序都感到非常困難。有些數學家覺得其它語言比APL難懂。由於APL使用不尋常的符號,許多編程員在寫APL程序時使用專門的APL鍵盤。今天也有不同的只使用ASCII字母寫APL的方法。

艾佛森後來還設計了一個APL的後續,稱為J語言,這個語言只使用ASCII符號。至今為止只有一種J語言。一些其它語言也提供類似APL的功能。A+是一種開源的程式語言,其許多指令與APL相同。

下面這個例子排列一個存在X里的詞的序列,排列標準是每個詞的長度:

X[X+.¬' ';]

下面是一個尋找所有1和R之間的質數的例子:

\displaystyle \left(\sim R\in R\circ .\times R\right)/R\leftarrow 1\downarrow \iota R

下面是這個程序的讀法(從右向左):

  1. \displaystyle \iota \,\! 建立含有從1到R的自然數的系列(假如程序開始時R=6,那麼 \displaystyle \iota R\,\! 是1 2 3 4 5 6)
  2. 放棄這個系列中的第一個元素(\displaystyle \downarrow)(\displaystyle 1\downarrow \iota R 是2 3 4 5 6)
  3. 令R成為這個系列(\displaystyle \leftarrow 是授值符號)
  4. 令R與R相乘而組成一個矩陣,實際上是組成一個R乘R的乘法表(\displaystyle \circ .\times
  5. 建立一個長度與R相同的系列,假如R中相應位置的數在乘法矩陣中出現,那麼在這個位置上的數就應該是1,否則0(\displaystyle \in),這個運算的結果是0 0 1 0 1
  6. 邏輯地否定的系列中的數,也就是說,1成為0,0成為1(\displaystyle \sim),結果是1 1 0 1 0
  7. 選擇R中相應的在新的系列中為1的數,這些數是質數(\displaystyle /\,\!),結果為2 3 5

 

只為『陣列運算』之『思維方法』故而已◎

為何不用 ROCK 64 耶?蓋無有,方才借樹莓派說也!

Repository

Debian/Raspbian

First you will need to set your Raspberry Pi up to connect to our public repository, This will allow you to keep your APL installation up to date with new releases.

The following are the supported Operating System codenames:

  • Raspbian (Debian)
    • wheezy (ARMHF) – Hardware Float: suitable for Dyalog 15.0 and earlier
    • jessie or later (ARMHF) – Hardware Float: this is required for Dyalog 16.0 and later

Please Note: We do not support ARMEL (Software Float) as we consider the performance of software float to be unacceptable on the Raspberry Pi.

wget -O - http://packages.dyalog.com/dyalog-apt-key.gpg.key | sudo apt-key add -
CODENAME=(lsb_release -sc) echo "deb http://packages.dyalog.com{CODENAME} main" | sudo tee /etc/apt/sources.list.d/dyalog.list

Please note: if you update the operating system on your Pi, then you should re-run these last two commands so that /etc/apt/sources.list.d/dyalog.list accurately reflects the codename of the version of the distribution that you are running.

【安裝】

sudo apt-get install dyalog-unicode

【測試】

pi@raspberrypi:~ $ dyalog
Dyalog APL/S Version 17.0.35961
Unicode Edition
Fri Apr 12 15:47:18 2019
/opt/mdyalog/17.0/32/unicode/Samples/fun/intro.dws saved Thu Mar 21 09:19:24 201
9

Rebuilding user command cache... done

                   Welcome to Dyalog APL.

    This message will only be displayed on your first run of Dyalog APL.
    If you would like to display this again run the following:

        )load intro

        *** Make sure you have saved any workspaces
            you have open before loading intro.     ***

                Try the following commands

    get_started     ⍝ useful commands to get you started
    APLKeys         ⍝ APL Keyboard Layout
    workspaces      ⍝ some example workspaces to try
    references      ⍝ list of useful websites

        To type APL Characters, hold down your windows key
                    while typing a character.

 

※ 參考︰

APL2 keyboard function to symbol mapping

Note the APL On/Off Key – topmost-rightmost key, just below. Also note the keyboard had some 55 unique (68 listed per tables above, including comparative symbols but several symbols appear in both monadic and dyadic tables) APL symbol keys (55 APL functions (operators) are listed in IBM’s 5110 APL Reference Manual), thus with the use of alt, shift and ctrl keys – it would theoretically have allowed a maximum of some 59 (keys) *4 (with 2-key pressing) *3 (with tri-key pressing, e.g., ctrl-alt-del) or some 472 different maximum key combinations, approaching the 512 EBCDIC character max (256 chars times 2 codes for each keys-combination). Again, in theory the keyboard pictured below would have allowed for about 472 different APL symbols/functions to be keyboard-input, actively used. In practice, early versions were only using something roughly equivalent to 55 APL special symbols (excluding letters, numbers, punctuation, etc. keys). Thus, early APL was then only using about 11% (55/472) of a symbolic language’s at-that-time utilization potential, based on keyboard # keys limits, again excluding numbers, letters, punctuation, etc. In another sense keyboard symbols utilization was closer to 100%, highly efficient, since EBCDIC only allowed 256 distinct chars, and ASCII only 128.

 

      N ← 4 5 6 7
      N + 4
8 9 10 11
      +/N
22
      R ← 6
      (~ R ∊ R ∘.× R)/R ← 1 ↓ ⍳ R
2 3 5