]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-poly.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / calc / calc-poly.el
index 95fdba2562c0cd40d99da4089e2258db85578080..de2cf2e01660bfbfb2796778a4a7e2ac102a602a 100644 (file)
@@ -1,26 +1,27 @@
 ;;; calc-poly.el --- polynomial functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
+;;   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:
 
 
          ;; Check if linear in math-fet-x.
          ((not (cdr (cdr p)))
-          (math-add (math-factor-protect
-                     (math-sort-terms
-                      (math-factor-expr (car p))))
-                    (math-mul math-fet-x (math-factor-protect
-                                 (math-sort-terms
-                                  (math-factor-expr (nth 1 p)))))))
+           (math-sort-terms
+            (math-add (math-factor-protect
+                       (math-sort-terms
+                        (math-factor-expr (car p))))
+                      (math-mul math-fet-x (math-factor-protect
+                                            (math-sort-terms
+                                             (math-factor-expr (nth 1 p))))))))
 
          ;; If symbolic coefficients, use FactorRules.
          ((let ((pp p))
 
 
 (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)
        ((and (eq (car-safe expr) '^)
              (memq (car-safe (nth 1 expr)) '(+ -))
              (integerp (nth 2 expr))
-             (if (> (nth 2 expr) 0)
-                 (or (and (or (> math-mt-many 500000) (< math-mt-many -500000))
-                          (math-expand-power (nth 1 expr) (nth 2 expr)
-                                             nil t))
-                     (list '*
-                           (nth 1 expr)
-                           (list '^ (nth 1 expr) (1- (nth 2 expr)))))
-               (if (< (nth 2 expr) 0)
-                   (list '/ 1 (list '^ (nth 1 expr) (- (nth 2 expr))))))))
+              (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))
+                                       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)) '-)))
+                (if (> (nth 2 expr) 0)
+                    (or (and (or (> math-mt-many 500000) (< math-mt-many -500000))
+                             (math-expand-power (nth 1 expr) (nth 2 expr)
+                                                nil t))
+                        (list '*
+                              (nth 1 expr)
+                              (list '^ (nth 1 expr) (1- (nth 2 expr)))))
+                  (if (< (nth 2 expr) 0)
+                      (list '/ 1 (list '^ (nth 1 expr) (- (nth 2 expr)))))))))
        (t expr)))
 
 (defun calcFunc-expand (expr &optional many)