Function: math-partial-fractions

math-partial-fractions is an autoloaded and byte-compiled function defined in calc-poly.el.gz.

Signature

(math-partial-fractions R DEN VAR)

Documentation

Return R divided by DEN expressed in partial fractions of VAR.

All whole factors of DEN have already been split off from R. If no partial fraction representation can be found, return nil.

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-poly.el.gz
(defun math-partial-fractions (r den var)
  "Return R divided by DEN expressed in partial fractions of VAR.
All whole factors of DEN have already been split off from R.
If no partial fraction representation can be found, return nil."
  (let* ((fden (calcFunc-factors den var))
	 (tdeg (math-polynomial-p den var))
	 (fp fden)
	 (dlist nil)
	 (eqns 0)
	 (lz nil)
	 (tz (make-list (1- tdeg) 0))
	 (calc-matrix-mode 'scalar))
    (and (not (and (= (length fden) 2) (eq (nth 2 (nth 1 fden)) 1)))
	 (progn
	   (while (setq fp (cdr fp))
	     (let ((rpt (nth 2 (car fp)))
		   (deg (math-polynomial-p (nth 1 (car fp)) var))
		   dnum dvar deg2)
	       (while (> rpt 0)
		 (setq deg2 deg
		       dnum 0)
		 (while (> deg2 0)
		   (setq dvar (append '(vec) lz '(1) tz)
			 lz (cons 0 lz)
			 tz (cdr tz)
			 deg2 (1- deg2)
			 dnum (math-add dnum (math-mul dvar
						       (math-pow var deg2)))
			 dlist (cons (and (= deg2 (1- deg))
					  (math-pow (nth 1 (car fp)) rpt))
				     dlist)))
		 (let ((fpp fden)
		       (mult 1))
		   (while (setq fpp (cdr fpp))
		     (or (eq fpp fp)
			 (setq mult (math-mul mult
					      (math-pow (nth 1 (car fpp))
							(nth 2 (car fpp)))))))
		   (setq dnum (math-mul dnum mult)))
		 (setq eqns (math-add eqns (math-mul dnum
						     (math-pow
						      (nth 1 (car fp))
						      (- (nth 2 (car fp))
							 rpt))))
		       rpt (1- rpt)))))
	   (setq eqns (math-div (cons 'vec (math-padded-polynomial r var tdeg))
				(math-transpose
				 (cons 'vec
				       (mapcar
                                        (lambda (x)
                                          (cons 'vec (math-padded-polynomial
                                                      x var tdeg)))
					(cdr eqns))))))
	   (and (math-vectorp eqns)
		(let ((res 0)
		      (num nil))
		  (setq eqns (nreverse eqns))
		  (while eqns
		    (setq num (cons (car eqns) num)
			  eqns (cdr eqns))
		    (if (car dlist)
			(setq num (math-build-polynomial-expr
				   (nreverse num) var)
			      res (math-add res (math-div num (car dlist)))
			      num nil))
		    (setq dlist (cdr dlist)))
		  (math-normalize res)))))))