]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-poly.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / calc / calc-poly.el
index e27705de98aec679acc838a38ab4f190c8665d00..de2cf2e01660bfbfb2796778a4a7e2ac102a602a 100644 (file)
@@ -1,27 +1,27 @@
 ;;; calc-poly.el --- polynomial functions for Calc
 
 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainer: Jay Belanger <belanger@truman.edu>
+;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 ;; This file is part of GNU Emacs.
 
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
 ;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY.  No author or distributor
-;; accepts responsibility to anyone for the consequences of using it
-;; or for whether it serves any particular purpose or works at all,
-;; unless he says so in writing.  Refer to the GNU Emacs General Public
-;; License for full details.
-
-;; Everyone is granted permission to copy, modify and redistribute
-;; GNU Emacs, but only under the conditions described in the
-;; GNU Emacs General Public License.   A copy of this license is
-;; supposed to have been given to you along with GNU Emacs so you
-;; can know your rights and responsibilities.  It should be in a
-;; file named COPYING.  Among other things, the copyright notice
-;; and this notice must be preserved on all copies.
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 
 
 (defun math-padded-polynomial (expr var deg)
+  "Return a polynomial as list of coefficients.
+If EXPR is of the form \"a + bx + cx^2 + ...\" in the variable VAR, return
+the list (a b c ...) with at least DEG elements, else return NIL."
   (let ((p (math-is-polynomial expr var deg)))
     (append p (make-list (- deg (length p)) 0))))
 
 (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)
         (math-add-or-sub (list '/ (nth 1 (nth 1 expr)) (nth 2 expr))
                          (list '/ (nth 2 (nth 1 expr)) (nth 2 expr))
                          nil (eq (car (nth 1 expr)) '-)))
-        ((and (eq calc-matrix-mode 'matrix)
-              (eq (car-safe expr) '^)
-              (natnump (nth 2 expr))
-              (> (nth 2 expr) 1)
-              (memq (car-safe (nth 1 expr)) '(+ -)))
-         (if (= (nth 2 expr) 2)
-             (math-add-or-sub (list '* (nth 1 (nth 1 expr)) (nth 1 expr))
-                              (list '* (nth 2 (nth 1 expr)) (nth 1 expr))
-                              nil (eq (car (nth 1 expr)) '-))
-           (math-add-or-sub (list '* (nth 1 (nth 1 expr)) (list '^ (nth 1 expr) 
-                                                                (1- (nth 2 expr))))
-                            (list '* (nth 2 (nth 1 expr)) (list '^ (nth 1 expr) 
-                                                                (1- (nth 2 expr))))
-                            nil (eq (car (nth 1 expr)) '-))))
        ((and (eq (car-safe expr) '^)
              (memq (car-safe (nth 1 expr)) '(+ -))
              (integerp (nth 2 expr))
-              (if (and (eq calc-matrix-mode 'matrix)
-                       (> (nth 2 expr) 1))
+              (if (and 
+                   (or (math-known-matrixp (nth 1 (nth 1 expr)))
+                       (math-known-matrixp (nth 2 (nth 1 expr)))
+                       (and
+                        calc-matrix-mode
+                        (not (eq calc-matrix-mode 'scalar))
+                        (not (and (math-known-scalarp (nth 1 (nth 1 expr)))
+                                  (math-known-scalarp (nth 2 (nth 1 expr)))))))
+                   (> (nth 2 expr) 1))
                   (if (= (nth 2 expr) 2)
                       (math-add-or-sub (list '* (nth 1 (nth 1 expr)) (nth 1 expr))
                                        (list '* (nth 2 (nth 1 expr)) (nth 1 expr))