2.7.69 Programming Tutorial Exercise 12

This turns out to be a much easier way to solve the problem. Let’s denote Stirling numbers as calls of the function ‘s’.

First, we store the rewrite rules corresponding to the definition of Stirling numbers in a convenient variable:

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

Now, it’s just a matter of applying the rules:

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

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

As in the case of the fib rules, it would be useful to put these rules in EvalRules and to add a ‘:: remember’ condition to the last rule.