Simulate a Qubit in Rust

The source code I used on this article is upload on my Github

https://github.com/cfr2ak/qubit-rust

What is the Qubit?

Qubit is the most fundamental components of the quantum computer. It is same as a bit on a classical one and is called qubit because it is a ‘quantum bit’. The state of the qubit is defined as the equation below.

|\psi \rangle = \alpha |0\rangle + \beta |1\rangle

With this state, when you measure the qubit, you can get the ‘0’ and ‘1’ with the probability of square of alpha and beta on each. Alpha and beta has a relation of equation

\alpha^2 + \beta^2 = 1

so that make it sure that the total sum of probability becomes 1.

Using the Bloch sphere, we can make this term more expressively.

|\psi \rangle = \cos{\frac{\theta}{2}}|0\rangle + e^{i\phi}\sin{\frac{\theta}{2}}|1\rangle

Therefore each alpha and beta becomes

\alpha = cos{\frac{\theta}{2}}
\beta = e^{i\phi}\sin{\frac{\theta}{2}}

Implement Qubit in Rust

Why Rust?

The most difference between the classical bit and the qubit is that the qubit is not able to copy to produce another qubit. But in the most of the programming language, to copy the value of the variable, struct, or the instance of the class is too easy thing to avoid it.

In Rust, there is a paradigm which is called ‘ownership’. This makes copying a variable as a nontrivial job. To enable the copy of the variable in Rust, you should implement Copy trait for your struct intentionally. On the other language, you have to implement more code to prohibit copy on a qubit but in Rust, it is default and you even can get compiler error when you make a mistake.

Create a project

Run the command below to create you project. We will edit main.rs to implement all the code in this article.

cargo new qubit-rust

Implement Qubit type

First, let’s define the test for a qubit type.

https://gist.github.com/cfr2ak/2511bdc870808b2e26eccec2f0ae4662.js

Then define the qubit and its default value

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init_qubit() {
let qubit: Qubit = Default::default();
assert_eq!(qubit.theta, 0.0);
assert_eq!(qubit.phi, 0.0);
}
}
view raw qubit-test.rs hosted with ❤ by GitHub

Run cargo test to check your code works well.

Implement the measurement

Add a test for measurement. You should get value 0 when its theta has initialized as a 0.0 and 1 when it has initialized as a pi.

#[test]
fn test_neasure_default_qubit() {
let mut qubit: Qubit = Default::default();
let want = 0;
let got = Qubit::measure(&mut qubit);
assert_eq!(got, want);
}
#[test]
fn test_measure_configured_as_one_qubit() {
let mut qubit = Qubit{ theta: f64::consts::PI, phi: 0.0 };
let want = 1;
let got = Qubit::measure(&mut qubit);
assert_eq!(got, want);
}

Before writing a implementation, you have to define your dependency on a Cargo.toml as below

...
[dependencies]
rand = "0.7"

If you finished to add the dependency, add the code below to the top of your main.rs

extern crate rand;

use rand::Rng;

Then implement the measurement.

impl Qubit {
fn measure(qubit: &mut Qubit) -> i32 {
let mut rng = rand::thread_rng();
let rn = rng.gen::<f64>();
if rn < (qubit.theta / 2.0).cos().powf(2.0) {
return 0
}
return 1
}
}

Run cargo test to check the code works well.

Implement collapse of the state

Qubit can have a state somewhere between 0 and 1 and can be detected only with that values (it is wrong actually, but let’s assume it). Fun part of the qubit is that its state collapse to the state it returned after measurement which means that if you get 0 on the first measurement, you only can get 0 on the further measurement. Let’s implement this property to our Qubit type. First, define the test.

#[test]
fn test_collapes_of_state() {
let mut qubit = Qubit{ theta: f64::consts::PI / 2.0, phi: 0.0 };
let want = Qubit::measure(&mut qubit);
for _n in 0..100 {
let got = Qubit::measure(&mut qubit);
assert_eq!(got, want);
}
}
}

Then edit measure function to change qubit’s state after its measurement.

impl Qubit {
fn measure(qubit: &mut Qubit) -> i32 {
let mut rng = rand::thread_rng();
let rn = rng.gen::<f64>();
if rn < (qubit.theta / 2.0).cos().powf(2.0) {
qubit.theta = 0.0;
return 0
}
qubit.theta = f64::consts::PI;
return 1
}
}

You’ve done! You implemented a simulator of a qubit in a Rust. Let’s check whether our code works well by changing our main code as below.

Run and test

fn main() {
for _n in 0..1000 {
let mut qubit = Qubit{ theta: f64::consts::PI / 2.0, phi: 0.0 };
let result = Qubit::measure(&mut qubit);
print!("{}", result);
}
println!("");
}
view raw qubit-main.rs hosted with ❤ by GitHub

This should prints out random thousand of 0, 1 values.

What is not implemented here

Actually, there is a phase factor on a equation I’ve introduced very early of this article but we’ve never used that. Phase is not able to measure directly but you can apply its relative phase to the state between 0 and 1 with the process using quantum gates. And there is a phenomenon which is called entanglement. Qubit itself is not really interesting since we can get the same result really easily on a classical computer using random seeds too. The entanglement and the phase are the phenomenon which qubit only has while classical one does not. I would like to recommend you to research on your own about these topic.

 

What is the communication about?

Communication is about become completely open yourself to the person who you targeted. This is a bit different from the frankness since to open yourself does not means that you express yourself as you are, but allow someone to see inside you as they want.

Being frank can make other person a bit uncomfortable since you can say more than they want regardless of whether you are trying to be frank or not. Unneeded, or unwanted information can make people feel bad because there is always a possibility that they intent to avoid them because they don’t want to know. Especially when you are on a higher position than a person you want to communicate well, then your frankness can make them feel unsafe.

But being open is different. You answer everything they ask. They asked because they wanted to know. Unlike frankness, being open does not mean that you express all the bad feelings you feel to the person you front but to be frank to yourself instead. You can not open yourself completely if you cannot be straightforward yourself as you are.

Good communication can accomplished only when you face yourself as it is. Frankness can harm people, but your openness not.

My goal of the 2020

  • Write one book (may be about the simulation of the quantum computer)
  • Write one paper about AI (maybe about optimizing the AI model on IoT). And write one paper about quantum computing (quantum programming mode, simulation model, etc)
  • Enjoy my weekends (I have worked 8 A.M. to 9 P.M. everyday last year. I think I need my life back)
  • Be brave. Taking any risks I can get
  • Do exercise once a week
  • Become 2-dan of Iaido
  • Read one book a week and write a review on the blog (here!)
  • Finish toy projects I’ve started on 2019

My thought on the AI era

Are you interested in it? I mean, really?

I work in the company which sells the AI solution and I saw many people says ‘I want to try AI on my own’, and after a half a year of their experience, the same people says ‘I think I’m not interested in AI actually’ and they go to find another cool things such as block chain, singularity, robotics and says ‘I think this is not my way’ again and again. I know you know what I’m saying about if you’re engaged in this absolutely bubbled AI industry. And here is my perspective.

First, I’m an applied physics student

I’m an applied physics undergraduate student. And I saw many of my classmates interested in quantum physics at the very first time of their major. They do the exactly same thing: ‘this is not what I’ve thought’. Yes, quantum physics is not even close to the multi-universe in an SF novel. It is full of math with which excludes any comprehensive interpretation intent. Because the physicist like Dirac had found (experienced) that any human language failed to explain the quantum phenomena with good accuracy, they simply gave up doing that. They believe that the result of the experiment is the sole base of the scientific truth, not their language. They rather choose to engineer the microscopic nature with the math. As Feynman said ‘Shut up and just calculate!’.

Shut up and just code

There was Newton dynamics in physics. And there is an Dijkstra’s formalism on the structured programming. Common part between them? They have failed on more complex problem. Newton dynamics is mathematically beautiful and can be explained with human language flawlessly. Just as same, the Dijkstra’s structured programming model is mathematically beautiful and can be explained with human language which is called algorithm.

Many people says something like ‘The AI no more than that of the bleeding edge tech of automation’. I don’t agree, because the things the vocabulary ‘AI’ directs to is not a mere automation. This is a fundamental paradigm transformation in the computer science industry.

Until now, most of the programs are can be described by the human’s natural language and that is what we called algorithm. And some of the programs has a concrete base of math beneath of it which assures the true value (not the same meaning when we call true in the boolean algebra. Right value maybe closer to this context) can be retrieved if the mathematical theorems are right (And they are almost always right).

AI cannot be described by algorithm. Only training them can have algorithms but the actions they take base on the input which is retrieved from the environment are a pure stochastic process. Programmer may able to check how a feature (of the environment it observes) is analyzed on each layer inside of it, but the true anatomy of the AI does not exist. We can see how they act on certain input space, but we cannot assure it works same on a completely new environment since we have no model to predict that.

I feels like this flow is identical to what physicist experienced on the early 20 century. We can see the result, but how they work? Can we explain and control them or have to admit them as it is and do something just like ‘Shut up and just code!’?

Conclusion

I think this is the time to admit that the AI is not on our hand, or at least cannot be described by our language which is a mere procedure ties of meanings. May be it is better to code than to try explain them, as physicist did a hundred years ago.

My 2019

Trying analog

These are the notes I have took for a year in a class.

At the start of the year, I made an assumption that there may be a something powerful I didn’t realized at all, in an analog tools (or, not digital things). I’m a Korean but I’m currently studying in Japan. And as you know (may be not), Japan is quite similar to German in a sense that they loves analog things too much even that habit causes nonsense sometimes. I have graduated from the highschool which has a major of software engineering and I believed that the digital evolution has changed our lives in every aspects, and to make everything digital is the way we have to go, not analog. So, to substitute all my things into the analog feels to me an exiting challenge.

The most big change is to take note on my hand, instead of my laptop. The conclusion I have made is

  1. To write a note by hand certainly better than to note by a laptop especially when I take classes which includes a lot of graphical resources not only equations.
  2. Managing the notes and searching its contents is too difficult to make me forgive.
  3. The physical papers (not a digital files) certainly gives me a satisfaction (that volumes! lol)

In a 2020, I think I would like to take a middle way: to take a note on ipad so that I can manage and search my contents freely and can use my own hand to draw things.

Snow in Sapporo

Just upload some pictures I’ve took this year.

The north entrance of the Hokkaido university.
Snow man in the Hokkaido University. It resembles bear, not human
Illumination at Christmas
Wonderful river covered with snow at jyou-zan-kei near Sapporo

Exercise

I’ve wondered when looking at the people who has so much enthusiasm. What makes them different from me? Why I cannot become like them? My conclusion at the first month of this year is the stamina. Very basically, if you want to influence the people around you or even world, you cannot give them a change more than your energy your heart can produce. Keep it simple, this is the first law of the thermodynamics. Your influence never exceeds the energy you produced. Therefore I’ve started to workout.

At school gym.
I’ve started to play the Iaido. I’ve got certification of syou-dan this year.

My career

I’m working on the company named AWL, inc. which is the startup sells the AI solution targeted for the retail market such as drug store. I’ve read the books (I mean, the finished books)

  • Clean agile, back to basic
  • Soft skills
  • Pragmatic programmer
  • Test driven development with Python
  • Manager’s path
  • Professional CUDA C programming
  • Clean architecture
  • Clean code
  • Generative deep learning
  • Deep learning and the game of go
  • Cloud native devops with kubernetes
  • Reinforcement learning with tensorflow
  • Quantum computing with IBM QX
  • 光の量子コンピューター (Quantum computer of light)
  • 量子テレポーテーション (Quantum teleportation)
  • 一般相対性理論を数式で理解する (Understand general relativity theory with math)
  • ガウス過程と深層学習 (Gauss process and deep learning)
  • And so on (like novels, or the books I’ve used on the class, etc)

I increased my working time so that I can engage in a more big problem in a company than before. Consequently, I’ve succeed to show my ability to my manager and have got more opportunity to research my own thing or so.

And I contacted to the laboratory of the Hokkaido University which uses its own distributed HPC system depends on GPGPU and I got opportunity to manage the whole server and to optimize the program they have made for there research. I feels like 2019 was the really important year for me because many of my career has begun.

My goals on 2020

  1. I want to start my own research on quantum computing (in more detail, I want to write my first paper)
  2. Back to digital. I will stop taking my notes on loose leaf paper. Instead, I will take my note on iPad with descent apps.
  3. Make a hobby. I would like to buy a cheap camera and travel sometimes

Why not set goals on a solution?

What is the problem here?

I many cases, especially when working with a company that is on bleeding sharp new technology, I heard someone saying like “I want to try it as a solution for some problem”. First, I want to make it clear, it is not a totally wrong thing to say that sort of thing, or decide technology before the problem is actually on. But here is a condition: that problem must be a trivial one, not business-critical one.

The problem is if you choose a technology or solution to solve a business-critical project even before the problem itself is well defined, it will lead you to fail with a large probability.

This is because deciding the solution even before the problem appeared makes the decision process extremely inflexible. There can be two cases of it.

  1. The company is a startup which is required to use certain technology by investors
  2. The company is quite mature which means that it has many experiences in many problems. In this case, the company does not prefer to take risk when the stable solution already exists.

As you can presume, both cases are quite problematic.

Why we stick to the solution rather than define the problem more precisely?

When we attend a conference, read a book, or check other’s reports, we care about what kind of solutions they have which seems like their business more successful than yours. No, don’t do that way. The key is not their solution. The key is their problem which makes them solve that with that certain way they present in front of you.

‘But we all have problems, what we need is a solution to that’, right? If you can’t think of any solution to your problem, then there is a high probability that you didn’t define the problem precisely enough.

Stick to the solution is the comfort zone. It is a really easy thing to think like ‘Let’s solve something with this awesome AI! It’ll solve anything we will ever face because many people said that AI solves their problems with magical performance and their business really succeed with AI’. When you think this way, you don’t need to understand your problem from its true nature and even don’t need to face the problem which makes you feel stress because you know the sword, the solution you have will solve all the problems on your way.

Why the problem itself is more important than a solution to it?

Where the solutions came from? Where the whole technologies came from? The problem is the source which creates all the technologies. Problems we happen to face is always changing because the time is running. And there are many cases the solution which was great at the past is not good anymore from any perspective.

Let’s make an analogy. What do you think about the person who uses a bow to make a crack on a rock? Maybe that person decides to use awesome, new, bleeding-edge arrow because he heard that bow makes other people able to hunt the giant bear with any scar. But the problem is different, what you want to do is break a rock in front of you not hunting. To decide a solution beforehand the problem which it aims is exactly the same case. You should consider your goal before choosing a tool.

If you are just a programmer and interested in AI, then it is totally okay to set AI as a solution and finds any problem to solve for your toy project. But if you run your own business or you are a manager who decides the way to precedes the project you got, then you should not go that way. It is not a solution that matters, what you matter should be the problem first.

Isn’t it collides with agile’s Mantra?

In the agile manifesto, there is

Working software over comprehensive documentation

It maybe makes you feel the time you spend to define the problem more precisely is not worthy as the solution itself. But remember the other manifesto, the first one

Individuals and interactions over processes and tools

or the fourth one

Responding to change over following a plan

These two cannot be done if you do not know the problem you try to solve.

Why you should try the Pomodoro technique?

What is Pomodoro?

Pomodoro is a technique to manage your time. Here’s the process of it.

  1. Decide what to do for next 25 minutes
  2. One Pomodori
    1. Set up your timer to 25 minutes and start
    1. Focus hard for the task
    2. DO NOT go to the toilet
    3. DO NOT fill up your mug
  3. Short break
    1. Set up your timer to 5 minutes for rest and start the timer
    1. Now, go to toilet, fill up your mug with coffee, and so on
  4. Repeat 1 to 3 three times more (4 times in total)
  5. Long break
    1. Set up your timer to 15 minutes for rest and start the timer
  6. Back to number 1 and repeat

That’s all. What you really need is only a timer (I prefer to use a tool above this like Trello + Pomello) and the time you can focus without disturbance while you’re executing a cycle.

Why people using it?

People say the reason for using Pomodoro is to measure their productivity. For example, if you finished 16 Pomodori a day, then you did a 8 hours job done with focus (it’s not exactly 8 hours but approximately). You don’t need to worry you work a minute or two more or less than you thought because you can be confidence that you focused while you’re in each cycle.

Why is it useful?

The first condition of your focus is not pushing hard yourself, but the absence of disturbance. Of course, you can focus without Pomodoro technique thinking like ‘I’ll focus on next 2 hours for this one’. But Pomodoro helps you to focus more easily than you used to. It’s about methodology.

Let’s make an analogy to make this more clear. If you’re someone from the CS background, then you should be familiar with multi-threading. And you should know that multi-threading is the source of many untrackable errors (which makes you find where’s the aspirin in). For example, if you run two thread increments the variable in the same address, like 1000 each, your expectation of the result is 2000 but the actual one is around 1300 or so. It’s not because of the computation is jumped in each thread. It is caused from the memory shared with two computation running at the same time.

Programmers usually solve this problem by lock their memory with something like mutex lock which protects the memory shared with multiple threads.

Now let’s think about us, the human. We can do several jobs at the same time, but our memory, our brain, is only one. It results in the same outcome with computer; you put 2000 efforts of your computing resource but you got 1300 only because you got only one for your brain, not two.

Pomodoro acts like mutex lock for us. Pomodoro locks 25 minutes as a chunk and protects your brain from shared along the tasks you should do. Unlike you’re doing your work simultaenously and get the result less than your effort, Pomodoro makes you produce exactly proportional to your effort.

Give it a try. It does not hurt you anyway.

合理という言葉の意味は何なんだろうか?

周りからよく聞く「合理的」は何を意味するのか?

僕らはよくある人や意見が「合理的だ」という表現を使ったり聞いたりする。大体の場合そのことが意味するのは「自ら考えても確かそうである」と思う同意以上のものではない。しかし、僕が思うには合理的はよくつかわれる文脈での意味以上の哲学を含んでいる。

人が合理的だというとき僕らは何を感じるのか?

ある人が自分自身のことに対して「俺は合理を重視する」と話しているとき、僕らが感じる感情は大きく二つである。

  1. うむうむ、確かそういう人だよな
  2. 自分の口でそのことを言ってるところでもうお前は合理的じゃねえよ

なぜ同じことに対して僕らの感情は二つに分けられるのか?

それはそもそも、合理的という言葉の意味が二つあるからである。合理的だという前にはまず、合理を理解しなければならない。漢字ですぐわかるように合理とは理が合うことを意味する。

ここで僕らが他人の意見を尊重することを漏らす表現がある。「一理ある」。よって理が合うということは基本、相手の意見と自分の意見が雑音少なく合うことなのだ。このことを僕は「外的合理」と表現したい。

しかし、たまにこの合理のことを自分の中で再帰させて感じる人が存在する。例えば、自分の意見に自ら納得しすぎて相手の意見を完全に無視しながら「こっちがごり的なんだ」と人のことである。僕はこういうことを「内的合理」と表現したい。

つまり、同じく「合理」ということを聞いても都合によってその人に対する認証が違われる理由はその人が言う合理の本の意味に基づいている。相手のことを無視しながら自分だけが正しいという「内的合理」の人に対しては反発感を感じ、相手の意見やデータなど、自分がどうしようもならないことと意見を調整する「外的合理」の人に対しては好意を持つようになるのである。

合理という言葉の意味は何か?

合理という言葉は要するに二つ以上の異なる理が接するところのことを意味する。この表現を人が使うたびにはその人がどれぐらい外の世界とやり取りをしているかによって「内的合理」、「外的合理」の二つの意味に分けられるのであろう。

한자 병용을 해야 하나?

왜 이런 생각을 하게 되었나?

오늘 통번역을 잠시나마 공부한 적이 있는 동생과 대화를 하다가 문득 궁금해져 질문을 했다.

“통번역이라는건 보통 뭘 말하는 거냐”
“통역과 번역”
“아”
“통으로 번역하는게 아니야”

이 뿐만 아니라, 이전의 이런 저런 대화에서 한국어의 발음에 숨겨져 있는 한자로 그 의미를 풀어서 생각해보면 의외로 굉장히 그럴듯한 설명이 붙는다는 것을 여러번 경험했었다. 이를테면, ‘미안하다’의 미안은 未安이며 한자를 보면 바로 ‘편하지 않음’ 을 죄스러움을 표현하기 위해 사용한다는 사실을 알 수 있다.

나는 일본의 대학에 다니고 있고, 그렇기 때문에 일본어를 일상적으로 쓰고 있다. 일본어를 해본 사람이라면 응당 알고 있듯, 일본어는 한자를 병용하는 언어이다. 일본어를 공부 하면서 한자에 익숙해진 것이 이런 생각을 하게 된 계기라 생각한다.

한자 병용을 하면 뭐가 좋은가?

한자 병용을 하면 좋은 점은 언어의 의미가 명확해 진다는 점이다. 미안하다에서 본것 이외에도 자유의 의미라던지, 무리, 일리, 진리, 합리가 같은 선상에 있는 개념이라는 사실 등을 파악 할 수 있게 된다. 특히 나는 자유가 동양철학에서 유래한, 개발된 신조어 였으며 (어떤 단어가 안그러겠냐만은 당시의 나에게는 신선한 사실이었다, 실존 또한 그러지 않은가) 서양에서 말하는 Freedom과는 그 성격이 많이 다르다는 사실을 알았을때 뇌에 전류가 흘렀던 느낌을 아직도 잊을 수 없다. 사춘기를 겪으며 자기 자신을 인식하게 되는 시기에 언어의 의미를 깊게 탐구할 도구가 있는 것과 없는 것의 차이는, 둘다 경험할 수는 없기에 정말로 어떨지는 개인으로서는 알 수 없지만, 꽤 클 것이라고 예상한다.

시대가 변화하고 인간의 의식이 발전하면서 모두가 의식하지만 통일 되지 못한 추상적 개념을 철학적 사고로부터 단어로 변환하는 행위가, 한자 없이 한국어 만으로는 어렵지 않을까. 인터넷이나 책에서 보이는 신조어가, 새로운 의미를 나타내는 진정한 의미의 신조어보다는 (이 또한 한자로 풀어 쓰면 내 말의 의도를 금방 알 수 있다) 어떤 긴 명사의 축약어에 그치는 경향을 보이는 것도, 한국어 이면에 있는 한자에 대한 이해가 적기 때문이지 않을까. 한자를 잃은 것은 언어를 창조할 능력을 잃었음을 의미 할지도 모른다.

한자 병용을 하면 뭐가 안좋은가?

한자 병용을 하면 안 좋은 점은 교육하는 비용이 많이 들고, 문맹율이 높아진다는 것, 이른바 식자층과 일반 대중의 경계에 어떤 건널 수 없는 선이 생기는 것 같은 결과를 낳을 수 있다는 점이다.

한자를 쓰지 않으면 내가 통번역에서 한것과 마찬가지로 의사소통의 오류가 생기지만, 반대의 경우또한 마찬가지이다. 한자를 몰라서 의사소통에 오류가 조금 들어가는 것과, 글을 아예 읽지 못하여 의미를 파악할 시도조차 할 수 없는 것 사이에서 선택해야 한다면 당연히 전자를 선택해야 하기 때문이다.

결국 한자 병용의 문제점은 교육 자원은 무한한 것이 아니라 한정된 것이라는 현실에 의해서 생겨난다. 자원은 한정되어 있기 때문에 모두가 원하는 만큼 가질 수 없고, 그럴때 우리가 생각해야 하는것은 가장 많은 자원을 가진 사람이 어디까지 효율을 추구할 수 있느냐가 아니라, 가장 소외된 사람이 최소한의 선을 어디서 보장받느냐이다.

그럼 어떻게 해야하나?

단순히 내가 일본어를 배웠기 때문에 이렇게 생각하는 것일 수도 있지만, 한국어에 한자 병용을 다시 되돌리는 무리수를 두는 것보다는, 가까운 나라들, 중국과 일본, 의 언어에 조금 더 중점을 두고 교육을 하는 것은 어떨까 싶다.

지금은 또 많이 바뀌어 있을거라고 생각하지만, 내 기억 상으로는 중학교때 한자 수업에서 한시를 배웠던 기억이 난다. 그 과목으로 부터 고대 언어에 관심을 가지고 학문의 길을 걷게 되는 사람또한 있을 것이기 때문에 필요없다고 가볍게 말할 수는 없지만, 그 시간에 실제로 사용할 수 있는 일본어나 중국어를 좀더 중점적으로 배우면서, 이 언어들에서 쓰이는 한자들을 한국어와 연결시키는 교육을 하는 것이 실용적 면에서 조금은 더 학생들의 관심을 모을 수 있지 않을까 싶다.

Why the teaching is conceived as the best way to learn something by the people?

What it means when we say ‘teach someone’?

Teaching someone else means that we transfer our instincts by our language. We sometimes use white board, power points, and videos for teaching but we do not say someone teaching us if he only gives you a bunch of books instead of saying something to you in brief.

When we say someone teaches us or we teach someone, it means that we communicates somebody who has more or less knowledge compared to us.

Which method I think the best for learning?

As I said on my blog’s post before, I value questions way more than conclusions, because conclusions itself does not mean anything.

https://gun-forge.com/2019/10/04/what-ive-learned-from-tdd/

For example, it has no meaning you know F = ma if you do not care about how things are accelerated by force, or you do not make inquiries about the true nature of moves of the things you encounter including stars. And even more, F = ma is not the absolute truth as proved by many quantum experiments. If you do not knows the question below some knowledge, not even you cannot create your new, original conclusions, you cannot use that knowledge fully in practical terms.

Therefore, I think the question is the key to learn anything. We cannot create knowledge first. We always throw questions first and we make conclusions on it based on our experiences.

Why the teaching is so effective?

When you’re teaching somebody else than you, you cannot avoid questions from them. If you’re learning something from somebody else, then you should throw questions to make all things clear in your mind.

This is the reason why the teaching is conceived as the best way to learn something. You and I cannot avoid uncomfortable questions which disrupts our minds which is easy to avoid when we are study alone. We’ve heard it a lot from the influencers; ‘Get out of your comfort zone’. Yes, what you need is question to follow that mantra on your own.

Teaching is just a catalyst prohibit yourself to get into your comfort zone so easily. The key is the question, not teaching.