Monday, 27 November 2023

古早遊戲BGM巡遊(6): Csikos Post

在遊戲裡使用古典樂remix作為配樂可謂屢見不鮮,一個遠古的例子是任天堂俄羅斯方塊C模式的音樂實際上來自巴哈的BWV 814 Minuett。那麼,如果要你選一首古典樂配樂的代表作的話你又會選哪首呢?

我會選Csikos Post。說英文可能還不夠明確,但如果我叫它郵遞馬車呢?還是不懂?那如果我叫它熱血行進曲呢?


嚴格來說,熱血行進曲只是遊戲名字,而這個BGM在遊戲中依然被叫作跟郵遞馬車差不多的東西(馬車馬のように),但這不影響它成為遊戲的代表配曲之一。

非常具張力的一首樂曲而且長度適中,很適合放在遊戲裡作配樂使用。最特別的是其原曲作者並不怎樣出名也沒有別的代表作:比如給愛麗絲你會叫給愛麗絲或者貝多芬的給愛麗絲,叫不出來像上面的BMV 814你至少也會叫巴哈那首;可這首郵遞馬車作曲家叫不出名字,曲名也不容易叫出來,於是命名權就落到將其發揚光大的遊戲裡。

但這首音樂被使用的廣泛程度絕對不限於熱血高校。遠的有耀西曲奇(Yoshi's cookie/類似瑪莉醫生的spin off)或GBC哈姆太郎,近的則有NDS右腦爽解2012瑪莉奧x索尼克奧運會等。其在音遊上的版本就更多了:pop'nReflec BeatO2JamDDR Mario MixNostalgia都有自己的版本,但我最愛的還是PIU的Banya版本

對於那些太年輕(與熱血系列的紅白-超任年代相比)的香港觀眾來說,接觸這首樂曲的契機更可能是麥兜故事的「一二三四五六七」:



顯然一二三四五六七的選曲本身和MV都以熱血系列為靈感就是。當時還沒有聽過熱血系列的我看到這MV第一眼就已經在想,不知道這遊戲有沒有被實裝出來呢?答案應該是有,在某一時空黃巴士網站遊戲頁面裡的一個Flash小遊戲,現在已經石沉大海。

最後說一下為甚麼會選這首以及為甚麼在BGM巡遊出現。那是因為右腦爽解(Quickspot)是我喜愛的遊戲之一,遊戲中所有BGM其實都來自古典樂,郵遞馬車就是其中一首。這遊戲半年前也出了個switch版本,但我覺得新版在計分上過於複雜,各項目花樣也過多,還不如兩個NDS版來得單純。不過至少它是一個switch上的好玩小遊戲就是了,在廁所殺時間一流,有興趣的朋友可以玩玩看。

不過……過幾天……洛克人EXE冷飯就要出來了……(*本文完成於9/4/2023。)

上面介紹了十幾隻基於郵遞馬車的遊戲BGM,但其實還有漏網之魚:更詳盡的列表在這裡。不知道你又聽過多少呢?

Saturday, 18 November 2023

Simon Marais 23B4 revisited + comments on official solution

(SM2023, B4) Let $n$ be a non-square number. 

(a) Find all pairs of natural numbers $(a,b)$ so that $r^a+\sqrt{n}, r^b+\sqrt{n}$ are both rational for some positive real $r$.
(b) Find all pairs of natural numbers $(a,b)$ so that $r^a+\sqrt{n}, r^b+\sqrt{n}$ are both rational for some real $r$. This is an open question currently.


When I first drafted my quick comment I simply omitted this question because a Q4 is a Q4 and has to be respected, so I only left one or two sentences there. Later on I found this one of interest so I dived in and wrote a simple answer. But then some gap in the solution had been lingering in my mind, and unsurprisingly I missed out something important so the answer is not fully correct. But I feel like I am close to the answer since the math behind is nothing overly complicated.

Below is my later attempt. There is a gap still, not recommended for readers.

****

Obviously, every $a=b$ pair is a solution because you can easily make up $r = (n-\sqrt{n})^{1/a}$. Next, if $(a,b)$ is a solution then so as its multiples $(ka,kb)$ because you can take $r' = r^{1/k}$. 

As a result we can now assume that $a,b$ are coprime. As $r^a, r^b \in \mathbb{Q}[\sqrt{n}]$, we know that $r\in \mathbb{Q}[\sqrt{n}]$ as well. I think this is well known -- but in case that is not, think about Euclidean algorithm (recall that a field is Euclidean...or even simpler the algorithm where you find gcd) that you can divide each other until you reach $r^1 = r$. 

Now write $r= p-q\sqrt{n}$ for some positive rational $p,q$ (the proofs are similar for different sign combination. Like you can write $r = p+q\sqrt{n}$ can the argument below proceeds the same). If you still remember your linear algebra lesson you can solve the recurrence by writing $p_k-q_k \sqrt{n} = (p-q\sqrt{n})^k$ for rational $(p_k), (q_k)$. For $v_k = (p_k,q_k)^t$, we have $v_k = A^{k}v_0$ where $A = \begin{bmatrix}p & nq\\ q & p\end{bmatrix}$.

The general formula for $p_k,q_k$ can be easily obtained by either method of eigenvectors or if you know how expand binomial powers. Anyway we have: 
$p_k = \frac{1}{2}((p+q\sqrt{n})^k+(p-q\sqrt{n})^k)$
$q_k = \frac{1}{2\sqrt{n}}((p+q\sqrt{n})^k-(p-q\sqrt{n})^k)$.
Notice that the formula is the same for $(p+q\sqrt{n})^k$. For negative $p,q$ the sign just alternates. 

Clearly $q_k$ is an alternating almost exponential series. More precisely we expect $q_{2k}-1 \approx q(p+q\sqrt{n})^{2k-2}$ and $q_{2k}\approx 2pq(p+q\sqrt{n})^{2k-2}$. The two subsequences are surely strictly monotonic and would not give us any non-trivial answer. The difficult task is however to find $k,k'$ so that $q_{2k} = q_{2k'-1}$.

A few approaches are there: first you may want to show that $q_n$ may not even be an integer if $p,q$ are (non-integral) fractions past a certain $k$. Secondly you may consider something even stronger that $q_k$ can't be 1 for largr $k$ because exponential sequences are either diverging or goes to zero, but the problem is you can always make very marginal case where $(p+q\sqrt{n})$ is very close to 1 (e.g. using continued fractions) so that the 'rate of divergence' is not properly bounded.

The problem for us is (1) we can't calculate terms manually for anything past $k=4$ -- even that is nasty enough as you can see below, and (2) what is the meaning of (b) being unsolved? Most arguments, if we assume that $r\in \mathbb{Q}[\sqrt{n}]$, does not really care about its positivity. In fact, we care if $(p-q\sqrt{n})$ being negative or not more so $(1-2\sqrt{2})^k$ is easier to handle than $(1+2\sqrt{2})^k$!

My approach is basically the observation that the last $k$ where $q_k$ can easily be made as an integer when $p,q\notin \mathbb{Z}$ is $q_4$ with where $(\frac{1}{2} + \frac{3}{2}\sqrt{3}) = \frac{223}{4} + 21\sqrt{3}$. One suspects that for larger $k$ the expansion looks like $q_k = kp^{k-1}q + cnp^{k-3}q^3 + c'n^2q^5(...)$, where the $n^2$ is causing problems when we want to solve integrality or doing mod checks. But at the end the approach does not distinguish between (a) and (b). Now I am really confused...and I see nothing wrong in the Euclidean argument too. 

Still, let us try to check the lower $q_k$'s:

$q_1 = q$
$q_2 = 2pq$
$q_3 = 3p^2q + nq^3$
$q_4 = 4pq(p^2+nq^2)$

As claimed, $q_1\neq q_3$ and $q_2\neq q_4$ so we only need to solve the 12,14,23,34 pairs.

$q_1=q_2=1$: this is easy with $p = \frac{1}{2}$ and $q=1$. Possibly a solution that students would have noticed without going through all these hassle.

$q_2=q_3=1$: Substitution gives the quintic equation $8p^4 - 4p^3 + n = 0$ with discriminant $256n^2(512n-27)$. By checking $(512n-27)$ mod 8 we know this is a non-square so that gives no rational solution.

$q_1=q_4=1$: Substitution gives the equation $4p(p^2+n)-1 = 4p^3 + 4np-1 = 0$. Surely one real root but the discriminant of a cubic equation doesn't tell much about rationality. Instead we convert $p$ into a fraction $p = \frac{s}{t}$ so $4p(p^2+n)$ becomes $\frac{4s(s^2+nt^2)}{t^3}$ for some $(s,t)=1$ but then we require $t^2\mid s^2$ which is absurd.

$q_3=q_4=1$: this is of course the hardest...but the technique never changes. From $q_3=1$ we obtain $q = (4p-1)/8p^3$. Substitution into $q_4=1$ gives a horrible degree 9 equation 
$3p^2((4p-1)/(8p^3)) + n((4p-1)/(8p^3))^3$
$ = (n(4p-1)^3 - 3\times 64p^2 + 3\times 256p^3)/512p^9 = 1$. 
Looks horrible but all we need is to take mod $p^2$ which eliminates the last two terms. Since $(p,4p-1)=1$ that forces $n$ to be non-square-free, hence the contradiction. So $(a,b) = (k,k)$ or $(k,2k)$ are all the possible pairs.

Other than discriminant checking, the main trick is to force a term to be multiple of $p^2$ (or anything else) if you want the sum to be a multiple of $n^2$ and so does the rest of the terms, then we can apply the square-free assumption. I believe this can be applied for higher $q_k$'s because we can check higher powers of $p$ against the $n^2$ factor. But clearly (b) being open does not support that.

So, basically the sure answers are in forms of $(a,b) = (k,k)$ or $(k,2k)$. But are there more? I don't know.

The more I think about this question the more I like it with so many different scattered technique that were used. This is the type of question we would like to see more. I would not hide the fact that my first attempt is a miserable fail as I overlooked a large part of it. I wrote that we look at $A^2$ again we know from there that the denominator would sure to stack up every 2 steps, but what about consecutive terms $q_k$ and $q_{k+1}$? I stared at what I wrote before I finally realized what should be corrected...but nope I am probably not getting 7 this time.

Just food for thought...what if we are now in $\mathbb{Q}[\sqrt{-n}]$, or that $(a,b)$ are simply integers instead? 

--------------------(NEW 08/12/2023)---------------------------

The solution is out and below is my answer-checking...

A1. No surprise, but their solution 3 is neat. If you skipped that while reading the solution you should go and have a check.

A2. The idea is right but I got the lower bound wrong for not considering $S$ to be set of all possible convex functions, but that is still easy.

A3. Completely wrong...hmmm I totally missed the 'unequal size' condition. Instead I took the sets $A_i$ in the way that $A_i$'s are not pairwise subsets and supsets. The correct version of A3 is much easier. Still I appreciate they put all the details unlike me (especially A2 and A3).

A4. As expected but their approach of finding the 'crtical point' is more elegant than calculus bashing.

B1-B3 are all as expected. But they spent more words on B2 that I would have thought. At this point I think all Simon Marais contestants should learn generating functions before they come -- such question appears almost every year!

B4. Here is the big thing -- I say that I can't see how should I tweak the solution to accustom the condition that distinguishes (a) and (b). How about scrapping the whole approach? It is now clear that my approach is more for (b) the open problem. (a) is much easier. I also missed that fact that for $(a,b) = (1,2)$ we actually got a negative solution so that does not count in (a) but in (b)...

No surprise in C1-C3 again, though C3 should deserve only a one-line solution if any.

Monday, 13 November 2023

Rains and returning period

Auckland's 1-in-200 years flood was given the name Anniversary Weekend flood 2023 on wiki...or simply just the Anniversary flood. The scars are still visible around, and recently a review has just been concluded from the Metservice side. The conclusion is that their rain prediction is poor.

Um...thank you.

I think most Aucklanders aren't surprised as the forecast tends to underestimate rains heavily all the time, where longer forecasts on precipitation are merely better than flip of a coin. We used to read radar directly because we can pinpoint the location of interest and is more accurate in general. We can at least tell whether a region is going to rain in an hour while the forecast can't!

When I wrote about the flood earlier this year, I said it's not a good time to talk about the 1-in-N-years thing because it's not the right time to do so. I think we are in the position to do it now especially when a comparable event happened later this year: the torrential rainfall over Hong Kong on early September 2023: record breaking 158mm in one hour, 800mm+ widely over the Island over 12-24 hours. A rare city wide flood that immediately recalls what happened over Auckland some times ago. It ended up being described as a 1-in-500-years event but was taken as excuse to inability of the government.

There are too many things we can talk about the two storms here like crisis management or building standards but I just want to focus on the numerical and scientific bits here as below.

Auckland's major flood on 27 January was caused by atmospheric river dragged near NZ by remnants of Tropical Depression 06F and blocked or forced stationary by a nearby anticyclone/high. At the same time, Hong Kong's flood was caused by the remnants of Typhoon Hanna (11W), stuck in a saddle field right above Hong Kong so that rain bands kept sweeping in.

The similarity is clear: both floods were caused by remnants of tropical systems that are stuck so that the affecting period is prolonged. But then it seems like this is the only recipe for such rainfall: normal lows can't be that powerful so it must be something related to tropical systems; mature systems (e.g. typhoons) are primarily driven by higher atmospheric features and seldom stuck like that so it has to be as weak as depressions or lows as remnants of the previous systems. Even so we need that to get stuck over an extended period (e.g. 12h) and provide enough water vapor to the system for that to work. Without considering other more extreme events like volcanic eruption/nuclear winters etc, is there any other possible way to produce such rainfall?

I suspect that the long tail on rainfall distribution over considerable period of time -- is not normal, because it is only produced under a specific combination of meteorological events. The distribution is composed of some 'common raining events', then events like what caused the above floods that is responsible for part of the tail, then more extreme event for the rest of the tail. Just think of adding three unequal Poisson (not saying these distribution is Poisson of course) distributions together and what would you get? Of course these are more speculation than anything, but that should allow us to get into what causes these rainfall outliers.

The next thing we should think about is the returning period which is the most talked about. If the distribution is not even normal how can we calculate the returning period? Another problem is, even with the returning period on our hands how should we set standards using that? 

The 1-in-500-years claim of the Hong Kong flood is based on the peak 1 hour rainfall 158.1mm which exceeds the 500 years mark (~155mm) on the 1hr rainfall returning period table. Auckland's 1-in-200-years flood is based on NIWA's claim but I can't find any numerical evidence supporting that. They were referring to the specific flood on 27 Jan so it might be 24hrs cumulative rainfall (or least 12, considering this is how long it lasted). Of course the flood is record breaking in all timeframes like the monthly precipitation of 539mm easily exceeding any of the months in the last 170 years. 

It is clear that the officials picked 200 and 500 respectively because this is the greatest that can be interpreted out of the numbers so that it sounds as serious as possible. But to those who want to use the returning period for risk management what's the proper timeframe to look at?

Unlike water level for dams where the returning period is duration independent, drainage capacity isn't and could have very different implication over different timeframe. A 1-in-200-years 2mins rainfall may sounds scary but is nothing to the drainage. The returning period of monthly rainfall is also pretty useless for drainage system because all you care is whether or not you can handle the spike. If the 538mm rainfall is distributed evenly then we will receive ~0.7mm of precipitation per hour nonstop for a month. Bad to have in the summer but no big harm at all.

Now suppose we take 1hr and 12hr rainfall into consideration more than anything else. Does it make the returning period a reliable indicator? On one side you say yes because it covers flash floods that are  immediately visible as well as the whole raining period that the system is designed to withstand. But consider this: a typhoon just swept through Hong Kong exactly a week before the flood that introduces significant amount of trash into the drainage which of course weakens its capability to drain. Should we take the two as independent event? If not, is it necessary to take returning period of longer timeframe back into consideration? Same thing happened to Auckland as a subtropical low hit Auckland 4 days after bringing more precipitation, then there came Gabrielle early February that again broke the still sagged SH1.

The lesson here is that the returning period is a highly on-paper number, easily manipulated by the data interpreter, highly confusing to the public and hard to use as a reliable reference. The bottom line is that it's something that you can always calculate and compare...but that's it. 

Oh and before I conclude it's unfair not to say something for the forecast institutes. Precipitation forecasting is a very complicated task even in 2023: it is very random in locality and intensity. The difference between rain and no rain could just be hundreds of meters apart, and there is no point to forecast upon such precision. Even if we can tell if it's going to rain or not, the cloud may develop or dissipate at any moment. This is particularly true in case of heavy rains. Just look at the radar -- the chances of actual heavy rain is much higher than finding signals of "heavy rains" on the chart! These are true limitations of technology up to now and are things that can't improve overnight. Still I am grateful that they are thinking to improve. Let us hope that floods like that don't ever happen again.