Folding an infinite list

One big difference is that right folds work on infinite lists, whereas left ones don’t! To put it plainly, if you take an infinite list at some point and you fold it up from the right, you’ll eventually reach the beginning of the list. However, if you take an infinite list at a point and you try to fold it up from the left, you’ll never reach an end!

Learn You a Haskell for Great Good!

Note that the key difference between a left and a right fold is not the order in which the list is traversed, which is always from left to right, but rather how the resulting function applications are nested.

  • With foldr, they are nested on “the inside”

    foldr f y (x:xs) = f x (foldr f y xs)

    Here, the first iteration will result in the outermost application of f. Thus, f has the opportunity to be lazy so that the second argument is either not always evaluated, or it can produce some part of a data structure without forcing its second argument.

  • With foldl, they are nested on “the outside”

    foldl f y (x:xs) = foldl f (f x y) xs

    Here, we can’t evaluate anything until we have reached the outermost application of f, which we will never reach in the case of an infinite list, regardless of whether f is strict or not.

— edited Oct 24 ’11 at 12:21, answered Sep 13 ’11 at 5:17, hammar

— Stack Overflow

2015.08.23 Sunday by ACHK

Problem 14.1b

A First Course in String Theory
 
 
14.1 Counting bosonic states

~~~

Let N(n, k) = {n + k - 1 \choose k - 1}, the number of ways to put n indistinguishable balls into k boxes.

p.318 “For open bosonic strings \alpha' M^2 = N^\perp - 1, …”

 
When \alpha' M^2 = 3, N^\perp = 4, the cases are: 

1. four a_1^\dagger‘s:

N(4,24) = 17550

2. one a_2^\dagger and two a_1^\dagger‘s:

24 \times N(2,24) = 24 \times 300

3. two a_2^\dagger‘s:

N(2,24) = 300

4. one a_3^\dagger and one a_1^\dagger:

24 \times 24 = 576

5. one a_4^\dagger:

24

 
Total number of possible states for N^\perp = 4 is 25650.

— Me@2015-08-13 12:05:57 PM
 
 
 
2015.08.13 Thursday (c) All rights reserved by ACHK

回到過去 1.2

甲:這次考得這麼差。如果可以回到過去,我一定可以考得好一點。

乙:那樣,回到過去前,你必須先清除試題記憶。否則,那就是作弊。
   
甲:那樣,「回到過去」還有什麼用?

乙:沒有用。

— Me@2015-07-27 09:01:17 PM

— Me@2015-08-07 08:01:48 PM

2015.08.08 Saturday (c) All rights reserved by ACHK

注定外傳 1.3

我不能話你這個講法錯。但是,如果你真是這樣問,我大概只可以答「不可以」,因為,如果真的是「百份百相同」的情境,又怎可能有不同的結果呢?

如果有可能有不同結果,那樣,引起另一結果的因素,總會與引起原本結果的因素,至少有一點不同。

(問:不是呀。在量子力學中,即使有兩組百分百一樣的物理系統,即使它們獲得完全相同的輸入,都可能有不同的輸出。)

你大概正確。但是,你要留意,量子力學中的「百分百一樣」物理系統,未必是你心目中的「百分百一樣」。

第一,量子力學(或其他任何科學)中的數學公式,只是數學模型,簡稱「理論」。模型的意思是,現實的近似,而不是現實的全部細節。

例如,地圖是實地的大概。試想想,一幅地圖比實地小那麼多,又怎可能包含了實地的所有細節呢?

作為實地的大概,只要令到閱者,準確到達目的地,一幅地圖,就已經盡了它的責任。

假設有一位地圖顧客(甲),向一位地圖製作人(乙),要求一幅準確一點的地圖。

乙:沒有問題。如果想令一幅地圖準確一點,我可以把地圖畫得大一點,那就可以包括更多細節。

甲:不行。那還不夠準確。

乙:沒有問題。我可以把地圖畫得再大一點,以包括再多細節。

甲:不行。那還不夠準確。

乙:沒有問題。我可以把地圖畫得又再大一點,以包括又再多細節。

甲:不行。那還不夠準確。

乙:你想多準確?

甲:完全、百分百、鉅細無遺、分毫不差。

乙:那唯有造一張「一比一的地圖」。

甲:什麼是「一比一的地圖」?

乙:即是與實地一樣大小的地圖。

換句話說,即是以實地為地圖。那樣,地圖就會失去了它原本的意義。

甲:什麼是「意義」?

乙:用途就是意義。

地圖本來的用途,是把實地的重點表達出來,從而帶領你,找到要去的地方。

當地圖的比例是一比一,與實地一樣大時,你就不能使用它了。以實地為地圖,即是沒有地圖。

地圖不是百分百準確,並不是地圖的缺點。相反,那是地圖的優點,因為,正正由於地圖只是實地的大概,它比實地小很多,可以指出重點,引導你到達目的地。

同理,科學理論中的數學模型,並不是現實的全部。理論不會包括實際的所有細節,並不是理論的缺點。

— Me@2015-08-04 07:57:59 AM

2015.08.05 Wednesday (c) All rights reserved by ACHK