Go to the first, previous, next, last section, table of contents.


プログラミング 練習問題12 解答「書替えによるスターリング数」

これはずっと簡単な問題解決方法になります。 スターリング数を関数 `s' の呼出しとして表しましょう。

まず、スターリング数の定義に基づいた書替え規則群を適当な変数にストアします。

s e StirlingRules RET
[ s(n,n) := 1  :: n >= 0,
  s(n,0) := 0  :: n > 0,
  s(n,m) := s(n-1,m-1) - (n-1) s(n-1,m) :: n >= m :: m >= 1 ]
C-c C-c

これで、あとは規則群を適用するだけです。

2:  4          1:  s(4, 2)              1:  11
1:  2              .                        .
    .

  4 RET 2       C-x (  ' s($$,$) RET     a r StirlingRules RET  C-x )

fib 規則の時のように、 最後の規則に `:: remember' 条件を付けたり、 規則群を EvalRules に入れたりすると便利でしょう。


Go to the first, previous, next, last section, table of contents.     利用度数