Further work on genfact, Double factorial and related functions ...



Meanwhile I have committed code to generalize the function Factorial. Then, I
had a further look into the Maxima function genfact(x,y,z). The documentation
says:

"Returns the generalized factorial, defined as x (x-z) (x - 2 z) ... (x - (y -
1) z). Thus, for integral x, genfact (x, x, 1) = x! and genfact (x, x/2, 2) =
x!!."

We know from the algorithm that the general factorial is evaluated as

genfact(x,y,z) := product(x-k*z, k, 0, y-1)

The argument z can be interpreted as a stepsize and the argument y as the number
of terms for which we have to expand the product.

We get for n a positve integer and a stepsize of 1 the following:

genfact(n,n,1)     = n!;
genfact(n,(n-1),1) = n! / 1;
genfact(n,(n-2),1) = n! / (1 * 2);
genfact(n,(n-3),1) = n! / (1 * 2 * 3);
.
.
.
genfact(n,(n-(n-1),1) = n;
genfact(n,0,1)        = 1;

For a stepsize of 2 we get results which correspond to the Double factorial for
n a positive integer.

I think the function genfact(x,y,z) is defineable for the following ranges of
values:

x,y,z positive integer and z <= x and y <= x/z.

The following code consequently test the arguments and does the numerically
evaluation only for this range of values. For all other numbers a noun form is
returned. The testsuite has no problems.

(defmfun simpgfact (x vestigial z)
  (declare (ignore vestigial))
  (if (not (= (length x) 4)) (wna-err '$genfact))
  (setq z (mapcar #'(lambda (q) (simpcheck q z)) (cdr x)))
  (let ((a (car z)) (b (take '($floor) (cadr z))) (c (caddr z)))
    (cond ((and (fixnump a)
                (fixnump b)
                (fixnump c))
           (if (and (> a -1)
                    (> b -1) 
                    (or (<= c a) (= b 0))
                    (<= b (/ a c)))
             (gfact a b c)
             (merror "Bad argument to `genfact'")))
          (t (eqtest (list '(%genfact) a
                       (if (and (not (atom b))
                                (eq (caar b) '$floor))
                         (cadr b)
                         b)
                       c)
                     x)))))

I would like to commit this specialization of genfact. In a next step we can
implement a function for Double factorials which is generalized to real and
complex values and connect this function to the operator !!.

I have further finished some code for the Incomplete Gamma function including
the numerically evaluation for real and complex values. This code and the code
for the Double factorial I would like to commit in a separated file "gamma.lisp"
in the directory maxima/src. All tests I would like to collect in the file
"gamma.mac!.

I know after all changes have been done we have to update the documentation
(this is more difficult for me then to write algorithm but I would try to do my
best).

Dieter Kaiser