Hi Al,
Johann's version below is my vote for the best. Very nice use of
Derive's vector functions! You might consider handling the cases when
n or k is negative. Maybe something like replacing the first line with
STIRLING1(n, k) := IF(k = n AND n >= 0, 1, IF(k > n OR k <= 0 OR n <= 0, 0,
IF(k = 1, (n - 1)!,
Ralph
> Date: Wed, 30 Dec 1998 19:37:06 -1000
> To: Johann Wiesenbauer <[log in to unmask]>, Ralph Freese
<[log in to unmask]>
> From: "Soft Warehouse, Inc. (Albert Rich)" <[log in to unmask]>
> Subject: The ultimate STIRLING1
>
> Hi Ralph and Johann,
>
> Let me know when you two perfect the ultimate STIRLING1, and I will include
> it in COMBINAT.MTH for DfW5.
>
> Aloha,
> Albert
Johann wrote:
> this is what I think to be the "ultimate" STIRLING1. (It may well be that
> Ralph has still a better one, but I'm at the end of my tether!)
>
> STIRLING1(n, k) := IF(k >= n, MAX(n - k + 1, 0), IF(k,0,IF(k = 1, (n - 1)!,
> IF(k = n - 1, COMB(n, 2), IF(k > n/2, (ITERATE([DELETE_ELEMENT(n_
> APPEND(v_, [0]) + APPEND([0], v_)), n_ + 1], [v_, n_], ITERATE([n_
> APPEND(v_, [0]) + APPEND([0], v_), n_ + 1], [v_, n_], [[1], 0], n - k),
> k))SUB1SUB1, (ITERATE([DELETE_ELEMENT(n_ APPEND([0], v_) + APPEND(v_,
> [0])), n_ + 1], [v_, n_], ITERATE([n_ APPEND([0], v_) + APPEND(v_, [0]), n_
> + 1], [v_, n_], [[1], 0], k), n - k))SUB1SUB1)))))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|