Function: calcFunc-prfac
calcFunc-prfac is an autoloaded and byte-compiled function defined in
calc-comb.el.gz.
Signature
(calcFunc-prfac N)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-comb.el.gz
;;; Theory: summing base-10^6 digits modulo 111111 is "casting out 999999s".
;;; Initial probability that N is prime is 1/ln(N) = log10(e)/log10(N).
;;; After culling [2,3,5,7,11,13,37], probability of primality is 5.36 x more.
;;; Initial reported probability of non-primality is thus 100% - this.
;;; Each Fermat step multiplies this probability by 25%.
;;; The Fermat step is algorithm P from Knuth section 4.5.4.
(defun calcFunc-prfac (n)
(setq math-prime-factors-finished t)
(if (Math-messy-integerp n)
(setq n (math-trunc n)))
(if (Math-natnump n)
(if (< 2 n)
(let (factors res p (i 0))
(while (and (not (eq n 1))
(< i (length math-primes-table)))
(setq p (aref math-primes-table i))
(while (eq (cdr (setq res (cond ((eq n p) (cons 1 0))
((eq n 1) (cons 0 1))
((consp n) (math-idivmod n p))
(t (cons (/ n p) (% n p))))))
0)
(math-working "factor" p)
(setq factors (nconc factors (list p))
n (car res)))
(or (eq n 1)
(< p (car res))
(setq factors (nconc factors (list n))
n 1))
(setq i (1+ i)))
(or (setq math-prime-factors-finished (eq n 1))
(setq factors (nconc factors (list n))))
(cons 'vec factors))
(list 'vec n))
(if (Math-integerp n)
(if (eq n -1)
(list 'vec n)
(cons 'vec (cons -1 (cdr (calcFunc-prfac (math-neg n))))))
(calc-record-why 'integerp n)
(list 'calcFunc-prfac n))))