5 F(n,k) = k binomial(n,k)
6 (F(n,k) + F(n,k-1)) / F(n+1,k)
10 k! n! n! (1 - k + n)! k! n!
11 -------------------- + -------------------- - ----------------------
12 (-1 + k)! (1 + n)! (1 + n)! (-k + n)! k (-1 + k)! (1 + n)!
14 Simplify each term to get
17 ------- + ----------- - -------
20 Then simplify the sum to get
31 static void simfac_term(void);
32 static int yysimfac(int);
34 // simplify factorials term-by-term
52 if (car(p1
) == symbol(ADD
)) {
55 while (p1
!= symbol(NIL
)) {
76 if (car(p1
) == symbol(ADD
)) {
79 while (p1
!= symbol(NIL
)) {
86 if (find(p1
, symbol(FACTORIAL
))) {
88 if (car(p1
) == symbol(ADD
)) {
111 // if not a product of factors then done
113 if (car(p1
) != symbol(MULTIPLY
)) {
123 while (p1
!= symbol(NIL
)) {
128 // keep trying until no more to do
133 multiply_all_noexpand(tos
- h
);
138 // try all pairs of factors
145 for (i
= h
; i
< tos
; i
++) {
147 for (j
= h
; j
< tos
; j
++) {
152 // n! / n -> (n - 1)!
154 if (car(p1
) == symbol(FACTORIAL
)
155 && car(p2
) == symbol(POWER
)
156 && isminusone(caddr(p2
))
157 && equal(cadr(p1
), cadr(p2
))) {
167 // n / n! -> 1 / (n - 1)!
169 if (car(p2
) == symbol(POWER
)
170 && isminusone(caddr(p2
))
171 && caadr(p2
) == symbol(FACTORIAL
)
172 && equal(p1
, cadadr(p2
))) {
183 // (n + 1) n! -> (n + 1)!
185 if (car(p2
) == symbol(FACTORIAL
)) {
199 // 1 / ((n + 1) n!) -> 1 / (n + 1)!
201 if (car(p1
) == symbol(POWER
)
202 && isminusone(caddr(p1
))
203 && car(p2
) == symbol(POWER
)
204 && isminusone(caddr(p2
))
205 && caadr(p2
) == symbol(FACTORIAL
)) {
207 push(cadr(cadr(p2
)));
220 // (n + 1)! / n! -> n + 1
222 // n! / (n + 1)! -> 1 / (n + 1)
224 if (car(p1
) == symbol(FACTORIAL
)
225 && car(p2
) == symbol(POWER
)
226 && isminusone(caddr(p2
))
227 && caadr(p2
) == symbol(FACTORIAL
)) {
229 push(cadr(cadr(p2
)));
237 if (isminusone(p3
)) {
238 push(cadr(cadr(p2
)));
252 if (equaln(p3
, -2)) {
253 push(cadr(cadr(p2
)));
256 push(cadr(cadr(p2
)));