nset divisors



Hello Barton:

While you are looking at nset, you may be interested in
borrowing part of this code for collecting divisors.
Note that the time and memory use are reduced.

(%i1) length(idivisors(30!));
Evaluation took 1.2800 seconds (1.2710 elapsed) using 54.870 MB.
(%o1) 2332800
(%i2) length(divisors(30!));
(%o2) 2332800
Evaluation took 8.1000 seconds (8.0970 elapsed) using 643.524 MB

(defun divisors-mext (l)
   (if (equal l '(1 1)) (setq l nil))
   (do ((ans (list 1 ))
        (l l (cddr l)))
       ((null l) (sort ans #'<))
     (do ((u ans)
      (factor (car l))
      (mult (cadr l) (1- mult)))
     ((zerop mult))
       (setq u (mapcar #'(lambda (q) (* factor q)) u))
       (setq ans (nconc ans u)))))

(defmfun1 ($idivisors :doc) ((n :pos-int :thread))
   :desc
   ("Lists the divisors of the integer " :argdot "n"
    " This is similar to " :emrefcomma "divisors"
    " but it is faster and returns a list and is not
    a simplfying function.")
   (mk-mlist (divisors-mext (cfactorw n))))

--John