Arantium Maestum

プログラミング、囲碁、読書の話題

なぜプログラミングでは掛け算をアステリスクで表すのか、などの文字コードの話

現代のプログラミング言語で「整数を掛け合わせる」という処理を書く場合、掛け算を意味する記号としてはアステリスク*を使う場合がほとんどである。例えば比較的最近の言語で整数の割り算には÷が使えるJuliaでも、掛け算は*で統一されている

Wikipediamultiplication signの項目にもこう書いてある:

Historically, computer language syntax was restricted to the ASCII character set, and the asterisk * became the de facto symbol for the multiplication operator.

しかしじゃあなぜASCIIに×記号が入っていないのか?という

こういうツイートを見たところから、個人的にも気になって調べてみた。

プログラミング言語*を使い出す経緯

そもそも上記のWikipedia記事は間違っている。Wikipediaの別項目Multiplicationを見るとこう書いてある:

This usage originated in the FORTRAN programming language.[citation needed]

FORTRANの初出は1957年、ASCIIが制定されたのは1963年なので「ASCIIに*しかなかったからそれを掛け算に使った」というのは順番が間違っている。逆にFORTRANなどで*を掛け算に使っていたからASCII制定時に×記号は必要ないと判断された、という可能性の方が高い。

FORTRANとパンチカード由来だという説はこちらのブログにも載っている:

nekonenene.hatenablog.com

こうなると説の真偽を確かめたくなる。

ちなみにFORTRANの開発者たちも初めから*で掛け算を表そうと考えていたわけではないようで:

cormullion.github.io

というブログによるとFORTRANの1954年のデザイン文書では×記号しか使われていないとのこと。それが実際に実装されるようになって、使える文字にマップしたというのが真相のようだ。

History of Programming LanguagesのFORTRAN資料*を採用した時の判断基準などが書いてあるかとも思ったが何もなくて残念。ただし1957年のFORTRAN User Manualに

The symbol • denotes multiplication.

と書いてあったことは明記されている。

WikipediaFORTRANが初出との箇所に[citation needed]とあるのでほんとかな?と調べたところ、確実にそうとは言えないが、KnuthらのEarly Development of Programming Languagesに載っている最初期のプログラミング言語の中では掛け算を*で表しているのはFORTRANが最古だった。プログラミング言語としては FORTRANの前にPlankalkulやらA-0やらAutocodeやらがあったが、この論文に載っているそれらの記法を見ると掛け算は*を使っていない。

というわけでFORTRANプログラミング言語として初めて*を掛け算に使った、ということでよさそうだ。

パンチカードの文字の変遷

そもそも何故パンチカードに*の文字があったのか?

Coded Character Sets, History and Developmentという資料の66ページによると、IBMFORTRANを開発したのはIBMだ)のパンチカードの歴史はHerman Hollerithがアメリカ合衆国国勢調査のために発明したシステムが元になっているとのこと。その大元のパンチカードには数字0~9と「コントロール・パンチ」2つ(CtrlとかAltみたいなものか?)の12「文字」しかなかった。そこから1932年ごろにアルファベット26文字と-*&の3文字が加えられたようだ。その時点ではパンチカードを利用するシステムは主に会計用に使われていて、そのドメインでその時点で必要な特殊記号を追加したということらしい。

The minus sign had replaced the credit symbol, the asterisk was used for check protection, and ampersand was used in name-and-address applications

とのこと。

ちなみにその後IBMのパンチカードのことを発明者の名前をとってHollerithカードと呼んでいたらしい。

ASCIIから×が外された経緯

さて、FORTRANでなぜ掛け算が×ではなくて*で表されたかについては「パンチカードにある文字で済ませた」でまず間違いないかと思う。

しかしそれでもASCII制定時をいい機会として×記号を追加しても良かったのではないか?

実はASCII制定時の文字案は非常に二転三転していて、スパッと決まったわけではない。そしてなんと初期の案には×は含まれていたようだ。

The Evolution of Character Codes, 1874-1968というASCII制定への道についての歴史を書いた論文があった。これによるとASCII制定委員会であるAmerican Standards Association (ASA)のX3.2 subcommittee for Coded Character Sets and Data Formatが1961年6月に考えていた文字セットでは×が含まれている(14ページ参照)。

しかし同年9月に

The angular tilde, multiplication sign (×), and vertical line (|) were deleted and replaced by an at sign (@) and less-than- or-equal-to (≤) and greater-than-or-equal-to (≥) operators.

そして

On September 28, 1961, Bemer wrote to the members of X3.2 that he should have suggested at the meeting that the committee not add less-than-or- equal-to (≤) and greater-than-or-equal-to (≥) signs to the code, but instead also remove the not-equal-to (≠) sign and assign the three characters’ positions to left ([) and right (]) brackets and a reverse slash (). He cited statistics indicating that the three symbols he proposed to replace were rarely used in actual Algol programs and that the brackets were very frequently used.

...

At the November 8-10, 1961 X3.2 meeting, the proposed character substitutions were unanimously approved and the control characters were repeatedly rearranged.

となる(15ページ参照)。FORTRANだけではなく、むしろALGOLのプログラムを表記できることがかなり重要視されていたようだ。ALGOLにも×もあるのだが、そこはやはりFORTRAN*で代用されるのが慣例となっているので必要ないと判断されたのではないか。

ASCIIに他の記号が含まれた経緯

しかし何故頑張って×を削って

のように使用頻度の低そうな記号は残したのか?

ツイートにもあるとおり、アクセント用らしい:

On January 1, 1957, the CCIT and its former tele- phonic counterpart, the Comité Consultatif Interna- tional Téléphonique (CCIF), were merged into a single International Telegraph and Telephone Consultative Committee (CCITT). So it was the CCITT that held a special meeting in Warsaw in May, 1958 to consider an expanded code. There was ‘‘general agreement... that it was premature at that time to standardise a new telegraph alphabet,’’ but the meeting did result in a list of the diacritical marks that would have to appear in any code that was standardized: the acute, grave, circumflex, umlaut, and tilde accents.

(The Evolution of Character Codes 9ページ目)

At its October 29-31, 1963 meeting,144 ISO/TC 97/SC 2 made changes to the proposed ISO code to meet the CCITT’s needs. ... accented letters were to be transmitted as a sequence of three characters: the letter, backspace, and the accent. The quotation mark and apostrophe were modified in appearance so they could also serve as umlaut and acute accents, and the up and left arrows were removed and replaced with circumflex and grave accents. The number sign (#) was given an alternate meaning as the tilde.

(22ページ目)

このISOコードというのはASCIIの国際版なわけだが、どちらもほぼ同時に相互作用的に影響しあって制定されたようだ。

他の記号については下記のブログにいろいろと面白い話が載っている:

jkorpela.fi

数学の掛け算記号

ちなみに掛け算を*で表現するのはFORTRAN以前では例がなかったことなのか?

前述の「Asterisk」という記事によれば

cormullion.github.io

In 1668, the Swiss author Johan Heinrich Rahn was the first to introduce the asterisk to indicate multiplication, in his algebraic treatise Teutsche Algebra.

...

His book also contains, on another page, the first printed use of the division symbol ÷.

とのこと。

Earlier, in 1631, William Oughtred had published the Clavis Mathematicae, The Key to Mathematics, and this famous textbook, with its profusion of new symbols, was very influential and studied by many, including the young Isaac Newton. Oughtred’s book popularized the saltire, a rotated plus sign, for use as the visible multiplication symbol.

ということで×が書籍に初登場した30年ほどのちに*を使った記法も(÷と同時に)登場している。

結局×に押されて流行らなかったようだが、FORTRANの300年ほど前に*を掛け算に使う前例があったわけだ。