2024年3月12日火曜日

量子コンピューティングを学ぶためのアプリをMIT App Inventorで開発(総集編)

----------------------------------------
この記事は、MIT App Inventorで量子コンピューティングの総集編であり、こちらの英文記事の和訳です。
----------------------------------------

I would like to thank Prof. Isaac Chuang, MIT for reviewing this blog post and providing very positive feedback.

 私は、日本の神奈川工科大学の名誉教授(コンピュータサイエンス)山本富士男です。実用的な量子コンピュータはまだ完成していないが、それが実用に供されれば社会に与える影響は非常に大きいと予測されるので、企業や大学での量子コンピューティングに関する研究開発は盛んになっている。私は、量子コンピューティングの基礎を学ぶための多数のアプリを、App Inventorを用いて開発を行なってきた。その目的は、関数電卓を使うような手軽な感覚で、少数の量子ビットを使う計算を楽しむことにある。だが、それだけではない。小規模であっても、量子回路シミュレータなどのアプリを自作するならば、理解は一層深まるに違いない。そのように考えて行ってきた取り組みを紹介したい。
 最初に、最も基本となるシングル量子ビットとはどんなものなのかを、自分の操作で確かめられるアプリを作成した。つまり、古典ビットに対する演算に該当する量子ビット操作のためのシミュレータアプリである。次に、2量子ビット、または3量子ビットを使う量子アルゴリズムのための、量子回路シミュレータアプリを開発した。実際、数例の量子アルゴリズムをそのシミュレータで再現してみた。最後に、別の観点から、大量の量子ビットのストリームを入力とする、個別のアルゴリズムについて、それぞれの動作原理の把握を容易にするアプリも開発した。

何と言ってもまずはQubit(量子ビット)
 まず、基本となる量子ビットがある。これは、0と1とを値とする従来のビットとは大きく異なる。量子ビット(Qubit)は、下図に示すようなブロッホ球と呼ばれる球面上にあると考えられる。北極点は従来の0、南極点は1に該当する。したがって、量子ビットは、一般に、北極点と南極点をある確率で重ねあわせた状態にあると言える。量子ビットは「測定」という操作を行うことによって初めて、その値が0か1かのどちらかに、確率的に確定する。測定するまでは、0と1の値が重なった状態にある。その不確定な状態のまま、種々の操作、すなわち演算を行うことができる。演算の結果として、qubitの状態、すなわちブロッホ球面上の位置が変化する。その際の変化に随伴する情報を利用して、必要な計算を進めることができる。複数の量子ビットの場合は、それらの情報の相互干渉さえも有効に利用できる。では、最初に、単一量子ビットの場合を見てみよう。
 量子ビットの状態をどのような方法で変化させるのだろうか?それに答えるのが、下図に示すアプリである。ブロッホ球面の量子ビットの緯度と経度を、(a)のようにスライダーで自由に変えることができる。しかし、通常は、むしろ、量子ゲートと呼ばれる演算で変える。例えば、アダマールゲート(H)を、北極点の状態に適用すると、それは赤道上に移動する。下図の(b)では、Hゲート適用後にさらにSゲート(赤道上を90°回転)を適用した例である。他にも多数の量子ゲートを利用できる。
2量子ビットを一つのシステムとして扱う
 一つの量子ビットだけでできることは少ないが、2量子ビットを使うと、急に様子が変わる。一般に、複数量子ビットを扱う場合には、個々の量子ビットを個別に扱うのではなく、一つのシステムとみなすことが必要となる。例えば、2量子ビットの場合、下図のように一方にHゲートを適用し、次に、両者に跨るCNOT(Controlled NOT)を適用すると、有名な量子もつれ状態(Bell状態)にすることができる。
 この場合の量子もつれとは、AliceとBobの量子ビット間に、強い相関関係が生ずることを意味する。すなわち、たとえ、AliceとBobが遠隔にあっても、Aliceが自分の量子ビットを測定して0を得た場合は、Bobの量子ビット自動的に即座に0になる。同様に、測定結果が1であれば、両者とも1となる。以下の図のアプリは、その状況を示している。
 しかしながら、現状の量子回路シミュレータや量子コンピュータでは、AliceとBobが遠隔にいるというイメージを持つことができない。そこで、私は両者の量子ビットをそれぞれ別のモバイイルフォン割り当てることにした。これらにコントロール用の1台を加えて、3台のモバイルフォンの構成で、遠隔にある量子間のもつれを模倣し、実感できるアプリを作った。下図にそれを示す。この図のトップにある、Cloud DB(リアルタイムDB)は、量子もつれの効果を表現する上で重要な役割を果たしている。

3量子ビットを使う色々な量子アルゴリズム
 次のステップとして、種々の基本的な量子アルゴリズムを試すには、3量子ビットが必要となる。だが、上記のように、各量子ビットを1台の台のスマホに割り当てる方法は、煩雑になるので採用しないことにした。それに替えて、ここでは、1台のモバイルフォンで3-qubitを扱えるように、新たに設計し直した。そのアウトラインを下図に示す。
 この3-qubitシミュレータアプリを使って、例えば、以下のような量子アルゴリズムを実装することができた。
(1) Phase kickback(制御ビットへの位相変化の戻し)
(2) Grover’s algorithm(構造化されていないデータの探索)
(3) Superdense coding(少数の量子ビットで多くの古典ビット情報を送信)
(4) Quantum Fourier Transform(to find out the frequency of coprime powers sequence)

 詳細説明は略すが、このうちの(2)のGrover’s algorithmの実行例を下図に示す。(a)では、8個の要素のうちの、探索対象をマーキングしている。(b)では、確率振幅の増幅という手法で解を求めている。
 もう一例示そう。次の図は、量子フーリエ変換QFTの利用例である。詳細説明は略すが、ここでは、ある数列(coprime powers sequence)から、その構成要素のパタンの周期、あるいは周波数を求めている。この結果は、IBM Quantumマシンでの実行結果と一致することも示している。このような周波数の検出は、Shor’s素因数分解アルゴリズムでも重要である。

大量の量子ビットのストリームを入力とするアルゴリズム 
 ここまでは、汎用的な量子回路シミュレータ利用であったが、次に、個別の量子アルゴリズムに特化した、説明用アプリを示す。例えば、大量の量子ビットのストリームを入力とするアルゴリズムがいくつかある。ここでは、光子の偏光の量子計算モデルと、量子もつれを利用する量子鍵配送を取り上げる。

(1) 量子計算モデルに基づく光子の偏光
 Qubitは、電子のspinや光子の偏光で表現される。ここでは、後者を扱う。今、偏光板3枚の軸角度を様々に変えて重ねる。その状態で物体を見た場合の明るさを問題とする。その際に必要なのは、入射される大量の光子が、それぞれの偏光板を通過する確率の計算である。作成したアプリでは、それらの通過確率を、偏光板の色の透明度に反映させて、実際の見え方を模倣した。その様子を下図に示す。

(2) 量子もつれに基づく量子鍵配送
 次のアプリは、量子鍵配送プロトコルEkertのイラストレーションである。このプロトコルでは、2者間の情報が第3者に盗聴されたか否かを確実に判定できる。その方法では、もつれた状態の量子ビット対から成る十分長いストリームを用意する。対の一方をAliceが、他方をBobが受け取る。各対毎に、両者はそれぞれ独立に、3種類の基底から一つをランダムに選び測定を行う。全ストリームの受信を完了後、両者はそれぞれ、古典ビット列(測定結果)と選択基底の列を得ることになる。
 明らかに、確率2/3で両者の基底は合致しない。もつれた状態において、両者が異なる基底で測定した結果は、確率1/4で合致することが、Bellの定理で示されている。ただし、それは、第3者による盗聴が無い場合である。
 一方、例えば、第三者Eveが、AliceとBobの測定よりも前に量子を盗聴したとする。盗聴には必ず、適当な基底での測定が必要となる。その結果、AliceとBobの量子対のもつれ状態が消失することに起因して、測定結果の一致確率は3/8に上昇する。これにより、盗聴を検出できる。これをシミュレートするアプリの様子を下図に示す。理論値通りの実行結果が得られていることが分かる。
まとめ
 量子コンピューティングの基礎に親しむためのモバイルフォンアプリとして、量子回路シミュレータや量子アルゴリズムのイラストレーションを開発してきた。これらの開発は、すべて、MIT App Inventorのみを用いて、効率的に行うことができた。App Inventorは、このように、新しい分野を学ぶためのアプリの開発に極めて有用であることを再確認できた。
 なお、この記事で省略した内容の詳細をご覧になりたい場合は、以下のブログ記事を参照いただきたい。ここには、約90件の関連記事の一覧が掲載されている。

In these developments, the books [1] , [2] and [3] written by three professors, Chirs Bernhardt, Barry Burd and Shigeru Nakayama, respectively, were very helpful.

参考文献

[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.

[2] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.

[3] Shigeru Nakayama(中山 茂): Quantum app Qni, Gaia Education series 52, 2022. (In Japanese)

 

2024年3月10日日曜日

Developing apps to learn quantum computing with App Inventor

I would like to thank Prof. Isaac Chuang, MIT for reviewing this blog post and providing very positive feedback.

Although a practical quantum computer has not yet been completed, it is predicted that if it is put into practical use it will have a huge impact on society, so research and development on quantum computing at companies and universities is increasing. I have used App Inventor to develop numerous apps for learning the basics of quantum computing. The purpose is to enjoy computations using a small number of qubits, as easily as using a scientific calculator. But that's not all. If you create your own app, such as quantum circuit simulator, even on a small scale, your understanding will definitely deepen. I would like to introduce the efforts I have made with this in mind.

First, I created an app that allows you to see what the most basic single qubit is. In other words, it is a simulator app for quantum bit operations that correspond to operations on classical bits. Next, I developed a quantum circuit simulator for quantum algorithms that use two or three qubits. In fact, I tried solving several quantum computing problems using the simulator. Finally, from a different perspective, I have also developed apps that make it easier to understand the operating principles of individual algorithms that take streams of large numbers of qubits as input. 
1. First of all, Qubit (Quantum Bit)

First, there is the fundamental quantum bit. This is significantly different from classical bits whose values are 0 and 1. A quantum bit (Qubit) is thought to lie on a spherical surface called a Bloch sphere, as shown in the figure below. The North Pole corresponds to the classical 0, and the South Pole corresponds to the classical 1. Therefore, it can be said that a quantum bit is generally in a state (superposition) in which the north and south poles are superposed with a certain probability. The value of a quantum bit is stochastically determined to be either 0 or 1 only through an operation called measurement. Until measurement, the values of 0 and 1 overlap. Various operations can be performed in this uncertain state. As a result of the operation, the state of the qubit, or its position on the Bloch sphere, changes. The necessary computations can be performed using the information accompanying the changes. In the case of multiple qubits, even the mutual interference of their information can be used effectively. First, let's look at the case of a single qubit.
How do we change the state of a qubit? The answer to this question is the app shown below. You can freely change the latitude and longitude of the qubit on the Bloch sphere using the sliders as shown in (a). However, this is usually changed using an operation called a quantum gate. For example, if you apply the Hadamard gate (H) to the state of the North Pole, it will move to the equator. In (b) of the figure below, an S gate (90° rotation on the equator) is applied after the H gate is applied. Many other quantum gates are available.
2. Two-qubit as a single system

There is little that can be done with just one qubit, but when two qubits are used, things suddenly change. In general, in the case of multiple qubits, it is necessary to consider them as a whole, rather than treating each qubit individually. For example, in the case of two qubits, by applying an H gate to one of them as shown in the figure below, and then applying a CNOT (Controlled NOT) spanning both, it is possible to create the famous quantum entangled state (Bell state).
Quantum entanglement in this case means that there is a strong correlation between Alice's and Bob's qubits. In other words, even if Alice and Bob are far apart, if Alice measures her own qubit and gets 0, Bob's qubit automatically becomes 0 immediately. Similarly, if the measurement result is 1, both will be 1. The app in the figure below shows this situation.
However, with current quantum circuit simulators and quantum computers, it is not possible to imagine Alice and Bob being far apart. Therefore, I decided to allocate both qubits to different mobile phones. With a configuration of three mobile phones (plus one more for control), I created an app that mimics entanglement between remote quanta. This is shown in the figure below. Cloud DB (real-time DB) at the top of this figure plays an important role in expressing the effects of quantum entanglement.

3. Various quantum algorithms with 3-qubit system 

As a next step, three qubits are needed to try out various basic quantum algorithms. The method described above, in which each quantum bit is assigned to a separate smartphone, will be complicated, so I will not use it here. Instead, it has been redesigned so that a single mobile phone can handle 3-qubits. The outline is shown below.
For example, using this 3-qubit simulator app, I was able to implement the following quantum algorithm.
(1) Phase kickback (returning phase change to control bits)
(2) Grover’s algorithm (exploration of unstructured data)
(3) Superdense coding (sending many classical bits of information with a small number of qubits)
(4) Quantum Fourier Transform (to find out the frequency of coprime powers sequence)

Although detailed explanation is omitted, an example of executing Grover's algorithm (2) is shown in the figure below. In (a), the search target among the eight elements is marked. In (b), the solution is found using a method called probability amplitude amplification.
The following figure shows an example of the use of quantum Fourier transform QFT in (4). Although detailed explanation is omitted, here, the period (or frequency) of the pattern of the constituent elements is detected from a certain number sequence. The results also show that they are consistent with those run on an IBM Quantum machine. Detection of such frequencies is also important in Shor's prime factorization algorithm.

4. Algorithms that take a long stream of qubits as input

Up to this point, we have used a general-purpose quantum circuit simulator, but next I will show apps to explain the operation of individual quantum algorithms. For example, there are several algorithms that take as input a long stream of qubits. Here, I will discuss quantum computational models of photon polarization and quantum key distribution using quantum entanglement.

(1) Photon polarization based on quantum computational model

Qubit is expressed by the spin of an electron or the polarization of a photon. Here, we will deal with the latter. Now, stack the three polarizing plates with various axis angles. The problem is how bright the object is when viewed in that state. What is needed in this case is calculation of the probability that a large number of incident photons will pass through each polarizing plate. In the app I created, the probability of passing these things was reflected in the transparency of the color of the polarizing plate. This imitated the actual appearance. The situation is shown in the figure below.
(2) Quantum key distribution based on quantum entanglement

The following app is an illustration of the quantum key distribution protocol Ekert. With this protocol, it is possible to reliably determine whether information between two parties has been intercepted by a third party. To prepare, we prepare a sufficiently long stream of entangled pairs of qubits. Alice receives one of each qubit pair, and Bob receives the other. For each pair, they independently select one of the three bases at random and perform measurements. After completing the reception of all streams, both parties will obtain a classical bit sequence (measurement result) and a selection basis sequence, respectively.

Obviously, the two bases do not match with probability 2/3. Bell's test shows that in an entangled state, results measured using different bases will agree with a probability of 1/4. However, this is the case where there is no eavesdropping by a third party.

On the other hand, suppose that a third party, Eve, eavesdrops on the quantum before Alice and Bob measure it. Eavesdropping always requires measurements on a suitable basis. As a result, the probability of coincidence of the measurement results increases to 3/8 due to the disappearance of the entangled state of the quantum pair of Alice and Bob. This allows wiretapping to be detected. The figure below shows an application that simulates this. It can be seen that the execution results match the theoretical values.
Summary
I have developed quantum circuit simulators and other mobile phone applications for learning the basics of quantum computing. All of these developments were done efficiently using only MIT App Inventor. I was able to reaffirm that App Inventor is extremely useful for developing apps for learning new fields like this.
If you need more details about the content omitted in this article, please refer to the blog articles below. A list of approximately 90 related articles is posted here:

In these developments, the books [1] , [2] and [3] written by three professors, Chirs Bernhardt, Barry Burd and Shigeru Nakayama, respectively, were very helpful.


References

[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.

[2] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.

[3] Shigeru Nakayama: Quantum app Qni, Gaia Education series 52, 2022. (In Japanese)

2024年3月9日土曜日

A List of my blog articles on Quantum Computing

 量子コンピューティングに関する私の記事の一覧です。約 170件あります。

Here is a list of my articles on quantum computing. There are about 170 titles in Japanese and English. English article titles have a or at the beginning.

2026年5月26日火曜日
2026年5月24日日曜日
2026年5月18日月曜日
2026年5月11日月曜日
2026年4月10日金曜日
2026年3月29日日曜日
2026年3月19日木曜日
2026年3月14日土曜日
2026年2月16日月曜日
2026年1月25日日曜日
2026年1月14日水曜日
2025年12月31日水曜日
2025年12月27日土曜日
2025年12月20日土曜日
2025年11月10日月曜日
2025年11月3日月曜日
2025年10月31日金曜日
2025年10月22日水曜日
2025年10月19日日曜日
2025年10月10日金曜日
2025年10月3日金曜日
2025年9月28日日曜日
2025年9月16日火曜日
2025年8月29日金曜日
2025年8月19日火曜日
2025年8月11日月曜日
2025年6月23日月曜日
2025年6月11日水曜日
2025年5月22日木曜日
2025年5月17日土曜日
2025年5月5日月曜日
2025年4月28日月曜日
2025年4月24日木曜日
2025年4月18日金曜日
2025年4月9日水曜日
2025年3月26日水曜日
2025年3月1日土曜日
2025年2月12日水曜日
2024年11月20日水曜日
2024年11月16日土曜日
2024年11月11日月曜日
2024年11月11日月曜日
2024年10月24日木曜日
2024年10月16日水曜日
2024年10月6日日曜日
2024年9月26日木曜日
2024年9月23日月曜日
2024年9月18日水曜日
2024年9月12日木曜日
2024年9月1日日曜日
2024年9月1日日曜日
2024年8月27日火曜日
2024年8月19日月曜日
2024年8月1日木曜日
2024年7月29日月曜日
2024年7月28日日曜日
2024年7月9日火曜日
2024年6月26日水曜日
2024年6月24日月曜日
2024年6月19日水曜日
2024年6月17日月曜日
2024年6月9日日曜日
2024年6月6日木曜日
2024年5月27日月曜日
2024年5月23日木曜日
2024年5月21日火曜日
2024年5月16日木曜日
2024年5月15日水曜日
2024年5月6日月曜日
2024年4月9日火曜日
2024年4月8日月曜日
2024年3月16日土曜日
2024年3月15日金曜日
2024年3月13日水曜日
2024年3月10日日曜日
2024年3月6日水曜日
2024年1月26日金曜日
2023年4月28日金曜日
2023年2月22日水曜日
2022-11-28
2022-09-18
2022-05-24
2022-04-08

2024年3月6日水曜日

Limited release: My mobile quantum circuit simulator

I have developed several types of original quantum circuit simulators as mobile applications. Eventually, I decided to make two of them available to the public, albeit in beta version. All of these were efficiently developed using MIT App Inventor. In these developments, the books [1] , [2] and [3] written by three professors, Chirs Bernhardt, Barry Burd and Shigeru Nakayama, respectively, were very helpful.

If you are interested in these apps and would like to try them out, please contact me. I will provide you built files (.apk format) for Android phones. Below is a very simple document to help you use it.

Japanese summary "限定公開:私のモバイル量子回路シミュレータ"
私は、これまでに数種類の独自の量子回路シミュレータを、モバイルアプリとして開発してきた。そのうちに2つを、まだベータ版ではあるが、限定公開することにした。これらは、すべてMIT App Inventorによって、効率的に開発されました。これらの開発では、3人の教授Chirs BernhardtとBarry Burdと中山茂がそれぞれ執筆された著書[1]と[2]と[3]が非常に参考になりました。これらのアプリにご興味を持ち、試用してみたいという方がおられたら、私にご連絡ください。Android phone用のビルトファイル(.apk形式)をご提供します。それをご使用いただくために、以下に極簡単なドキュメントを示します。)

Two types of mobile quantum circuit simulator
    Q1_beta1: for a single-qubit
    Q3_beta2: for 3-qubit system

------- Q1_beta1 app ----
Q1_beta1 app - Setting quantum state using sliders

Applying quantum gates

------- Q3_beta2 app ----
Overview of the Q3_beta2 app

Phase Kickback

Grover’s Algorithm

Superdense Coding

Finding the frequency of coprime powers sequence(1)

Finding the frequency of coprime powers sequence(2)

References
[1] Chris Bernhardt: Quantum Computing for Everyone, The MIT Press, 2020.
https://www.chrisbernhardt.info/

[2] Barry Burd: Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.
https://users.drew.edu/bburd/quantum/

[3] Shigeru Nakayama(中山 茂): Quantum app Qni, Gaia Education series 52, 2022. (In Japanese)

2024年2月21日水曜日

Illustrating Shor's algorithm with my quantum circuit simulator

Shor's algorithm is mathematically quite difficult, so many books on quantum computing often only briefly mention it. On the other hand, when an explanation is given, it is difficult to understand because it is a list of many mathematical formulas. In this context, the book by Prof. Barry Burd [1] is surprisingly easy to understand and explains the basics. Chapter 9 of this book takes 40 pages to thoroughly explain the essence of Shor's algorithm. Using a concrete example, he explains that if you can find the period (frequency) in a coprime powers sequence, you can factorize the public key number. He then demonstrated quantum Fourier transform (QFT) to find that frequency, expressed it in Qiskit code, and ran it on IBM Quantum Lab. This is fantastic! With this, I was able to grasp the heart of Shor's algorithm!

I have so far developed my own quantum circuit simulator for 3-qubit as a mobile phone app with MIT App Inventor. The outline is shown in Fig.1.
This time, I was able to use my simulator to identify frequencies using quantum Fourier transform, following the instructions in this book. The results matched those from IBM Quantum Lab. In other words, using just a mobile phone, they were able to perform a quantum Fourier transform and obtain the results, just like a scientific calculator. The situation is shown in Fig.2 and Fig.3.
(Notes)
As of 02/23/2024, the execution environment of Qiskit (IBM Quantum Lab) has changed, so it is necessary to modify the original Python code (for example, Chapter09.ipynb) to run it.
Here is how to fix it:
---------------------------------------------
(A)change libraries:
from qiskit import QuantumCircuit, Aer, execute
from qiskit.tools.visualization import plot_histogram
  ↓
from qiskit.primitives import Sampler
from qiskit.visualization import plot_histogram
---------------------------------------------
(B)use 'Sampler' instead of 'Aer' as follows:
sampler = Sampler()
result = sampler.run(circ, shots=1000).result()
print("result: ", result)
quasi_dists = result.quasi_dists
print("quasi_dists: ", quasi_dists) 
display(plot_histogram(quasi_dists))
---------------------------------------------
More details here:
Migration examples
---------------------------------------------

Reference
[1] Barry Burd, Quantum Computing Algorithms -Discover how a little math goes a long way, Packt Publishing, 2023.

2024年2月14日水曜日

Functional Programming in MIT App Inventor

Abstract: Functional programming blocks such as map, filter, reduce, and sort can be used in list operations in MIT App Inventor. These will allow you to create clean and easy-to-understand programs without using for loops or if-then-else. (This article has also been posted to the MIT App Inventor community. Have a look at this.)

要旨MIT App Inventorのリスト操作において、map、filter、reduce、sortなどの関数型プログラミングブロックが使える。これにより、forループやif-then-elseを使わず、すっきりとした分かりやすいプログラムが作れるであろう。(この記事は MIT App Inventor コミュニティにも投稿されています。 こちらをご覧下さい。)

MIT App InventorのFunctional List Operators
 
リスト処理において、図1に示すような関数型プログラミングのためのブロックが使える。すなわち、

  • map:要素に何らかの変換を施して新たなリストを作る。
  • filter:条件を満たす要素だけのリストを作る。
  • reduce:要素の最大値、最小値などを得るなど、縮約する。
  • sort:要素を条件に従ってソートし、新たなリストを作る。

 このような関数型プログラミングは、多くのプログラミング言語でサポートされている。しかし、MIT App Inventorのようなブロック型プログラミング環境にこれを取り入れるには多くの課題があったようである。この機能は、参考文献[1]で説明されているが、その元になる論文が[2]である。

 この論文[2]は、米国Wellesley大学(最難関の女子大らしい)の学生が2015年に発表したものであり、全98ページに及ぶ。表紙には、"Thesis advisor : Prof. Franklyn Turbak"と書かれているので(修士)学位論文のようだ。それだけ奥が深いものである。MIT App Inventorは、生徒学生を主な対象とした使いやすいプログラミング環境を提供しているが、関数型のような、高度なソフトウェア技術もしっかり取り入れて、強固なバックグラウンドを築いていることを改めて感じる。

例題1: 指定された年の"13日の金曜日"を全て求める
 よくある例題かも知れないが、"指定年の13日の金曜日"を全て求めるアプリを、上記の機能を使った書いてみた。図2はその全ブロックである。大きなブロック"get_13Fri_list"が主要部であるが、ここには、forループもif-then-elseも全く出てこない。これが典型的な関数型プログラミングの簡単な例である。
 このブロックには、関数型ブロックが3つ使われている。(a)では、mapにより、月のリストをその月の13日の日にちリストに変換している。(b)では、そのリストをfilterにより、"金曜日=曜日番号6"だけのリストに変換している。このリストの要素は日にちオブジェクトなので、それを(c)でのmapにより、通常の書式の日付に変換している。つまり、map - filter - mapを連続して適用して、一気に流れるように、答えの日付のリストを得ている。爽快感がある!

例題2: reduce(combining)も使ってみる
 上記のmapとfilterの他に、reduce(combining)も有用です。図3に、リスト要素をユークリッドノルムで正規化して新たなリストを作る例を示します。

参考文献

[1] MIT App Inventor Functional List Operators
https://ai2.appinventor.mit.edu/reference/concepts/pholo.html#map

[2] Soojin Kim, "Developing and Assessing New List Operators in App Inventor", 2015.
https://repository.wellesley.edu/object/ir558


2024年2月12日月曜日

数学グラフ計算機Desmosで偏光板アプリを作る

 以前のこのブログ記事で、量子計算に基づく、偏光板のスマホアプリを作成した。
これと同等機能のアプリを、最近知ったDesmos(2D3D数学グラフ計算機)を用いて作成してみた。Desmosの素晴らしさに感嘆!

 ノーコードで(というよりも、宣言的記述だけで)、インタラクティブに動作するアプリが簡単に作れてしまう。例えば、関数の計算式に未定義のパラメータ名が出てくると、そのパラメータを設定するスライダーが自動的に出てくる。それを動かすとパラメータを変化させたアニメーションも簡単に作れる。プログラミングにとらわれず、やりたいことを数学的に記述すれば良い、という感があって嬉しい。

 さらにwebで作成したアプリは、ほとんどそのままスマホアプリのように使うこともできる。
これで、ビジュアライゼーションの強力なツールを身につけられる!

 以下の図1、図2をご覧いただきたい。説明はほとんど不要であろう。
 以下の短いビデオもご覧ください。
 さらに、国際数学アートコンテストもやっていて、楽しく、ためになる。

 なお、上記はDemosの「幾何ツール」と呼ばれるものを使った。この中で、角度θに偏光した光子が軸角度αの偏光板を通過する確率p(θ, α)を使ったいるのだが、その3Dグラフを見たい場合は、別途「3Dgraph」で描いたものを参照できる。以下の例をご覧いただきたく。

2024年2月9日金曜日

多様体の基礎

 突然だが、私は何十年も前に、理学部数学科を卒業した。その後はコンピュータメーカの研究所でのソフトウェアの研究開発、さらに大学での教育に従事して、現在は退職している。かっての数学科での学びのうち、多様体はごく入口のところしかやっていなかった。当時は(私にとっての)適当な参考書がなく、先生の板書を追うしかなかった。もちろん、よく理解できたとは言えなかった。それでも購入した書籍は、松島与三著「多様体入門(旧版)」であったが、これが、とてつもなく難しい。だから、その後は放ってあった。

 退職後は、趣味として、量子コンピューティングという、かなり現実的なことに日々取り組んでいる。量子コンピューティングは量子物理を抽象化したものであろう。しかし、多様体論は(他の高度な数学もそうだが)、これとは比べられないほど抽象度の高い世界である。精神の世界である。なぜ、今更多様体を持ち出すのか、自分でもよく分からないが、そういう世界に入りたいという思いが強くなってきただけである。かって、ポントリャーギン著「連続群論」のほんの入口だけだが、それを読んで、そういう、精神の世界があることを知り感動した。ポントリャーギンは14歳で視力を失っていたロシアの大数学者であった。目の見えない人が、ここまで頭の中で、こんな数学の世界を作り上げられるのかという驚きであった。

 最近のことである。依然として難しいことには違いないが、それでも懇切丁寧で、読者への配慮が十分に行き届いているとの評判の、松本幸夫著「多様体の基礎」があることを知った。出版は1988年であるから、36年ほど経過しているのだが、名著と言われる。これを購入した。どう進めるのか、分からないが時間は十分あるので、一歩一歩取り組むのが楽しみである。その際は、一時的にパソコンもスマホも片付けてしまい、別世界へ行きたい。ただ、そういう世界であっても、人間は具体的イメージを求めるのが常である。そうなると、やはり、パソコンやスマホの支援アプリの出番があるかも知れない。そういう域に達するならば、それはまた嬉しい。


2024年2月2日金曜日

量子コンピューティングのための自作アプリについて

 これまで何度も、このブログに登場した「量子コンピューティング関係スマホアプリ自作」に関して、短い講演をすることにしました。15分しかないので、スライド枚数は少ないですが、その前半部を以下に示します。予告編です。1時間もあれば、量子コンピューティングをご存じない方にもご理解いただけるように作れると思いますが、短時間ではそれは無理っぽいです。それでも、なんとか、解説的な説明も含めました。
 
Qubit
Ekert protocol (when eavesdropping)

まず、表紙に凝ってみました。
positive、negativeありますが、新しいことへ挑戦するなら、positiveに!
量子コンピューティングのためのスマホアプリの開発経緯です。
Prof. Chris Bernhardtにご紹介いただいた、私のアプリ2つを取り上げます。
アプリの具体的な説明の前に、基本事項の確認をします。
異なる正規直交基底による測定、これがこの後必要になります。
アダマールゲートHなど、種々の量子ゲートを使う。
量子もつれ:これが全てではないが、こんな感じです。
 この後、Polarized filter experiment光子の偏光)とEkert protocol量子鍵配送)を詳しく述べるのですが、予告編なのでそこは省略します。本当は、Probability Amplitude Amplification(確率振幅の増幅を使うGroverアルゴリズム)もあるのですが、時間の関係で省略です。最後に、MIT App Inventorでこれらのアプリが効率的に開発できたことを述べます。