]> git.eshelyaron.com Git - emacs.git/commitdiff
(math-known-square-matrixp): New function.
authorJay Belanger <jay.p.belanger@gmail.com>
Fri, 7 Oct 2005 21:15:19 +0000 (21:15 +0000)
committerJay Belanger <jay.p.belanger@gmail.com>
Fri, 7 Oct 2005 21:15:19 +0000 (21:15 +0000)
(math-pow-fancy): Check for matrices before distributing exponent
across products.

lisp/calc/calc-arith.el

index 25ccfc4801958250e99100cd4bb33fc663f6703b..9d4d04a5758f616c09018fdb52936497219562ec 100644 (file)
   (and (not (Math-scalarp a))
        (not (math-known-scalarp a t))))
 
+(defun math-known-square-matrixp (a)
+  (if (eq (car-safe a) '^)
+      (math-known-square-matrixp (nth 1 a))
+    (and (math-known-matrixp a)
+         (or (math-square-matrixp a)
+             (and (or
+                   (integerp calc-matrix-mode)
+                   (eq calc-matrix-mode 'square))
+                  (eq (car-safe a) 'var)
+                  (not (math-const-var a)))))))
+                  
 ;;; Try to prove that A is a scalar (i.e., a non-vector).
 (defun math-check-known-scalarp (a)
   (cond ((Math-objectp a) t)
           (cond ((and math-simplify-only
                       (not (equal a math-simplify-only)))
                  (list '^ a b))
+                 ((and (eq (car-safe a) '*)
+                       (or 
+                        (and
+                         (math-known-matrixp (nth 1 a))
+                         (math-known-matrixp (nth 2 a)))
+                        (and
+                         calc-matrix-mode
+                         (not (eq calc-matrix-mode 'scalar))
+                         (and (not (math-known-scalarp (nth 1 a)))
+                              (not (math-known-scalarp (nth 2 a)))))))
+                  (if (and (= b -1)
+                           (math-known-square-matrixp (nth 1 a))
+                           (math-known-square-matrixp (nth 2 a)))
+                      (list '* (list '^ (nth 2 a) -1) (list '^ (nth 1 a) -1))
+                    (list '^ a b)))
                 ((and (eq (car-safe a) '*)
                       (or (math-known-num-integerp b)
                           (math-known-nonnegp (nth 1 a))