changeset 66479:5da715ee89b8

(calc-mul-symb-fancy): Add checks for multiplication by an identity matrix, don't turn multiplication by an inverse matrix into division. (math-div-symbol-fancy): Replace division by matrices with multiplication by inverse.
author Jay Belanger <jay.p.belanger@gmail.com>
date Fri, 28 Oct 2005 03:51:36 +0000
parents 57b78015fb51
children feb65aa82eeb
files lisp/calc/calc-arith.el
diffstat 1 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calc/calc-arith.el	Fri Oct 28 03:51:00 2005 +0000
+++ b/lisp/calc/calc-arith.el	Fri Oct 28 03:51:36 2005 +0000
@@ -1386,6 +1386,7 @@
       (and (eq (car-safe b) '^)
 	   (Math-looks-negp (nth 2 b))
 	   (not (and (eq (car-safe a) '^) (Math-looks-negp (nth 2 a))))
+           (not (math-known-matrixp (nth 1 b)))
 	   (math-div a (math-normalize
 			(list '^ (nth 1 b) (math-neg (nth 2 b))))))
       (and (eq (car-safe a) '/)
@@ -1427,6 +1428,30 @@
 		    (list 'calcFunc-idn (math-mul a (nth 1 b))))
 	       (and (math-known-matrixp a)
 		    (math-mul a (nth 1 b)))))
+      (and (math-identity-matrix-p a t)
+           (or (and (eq (car-safe b) 'calcFunc-idn)
+                    (= (length b) 2)
+                    (list 'calcFunc-idn (math-mul 
+                                         (nth 1 (nth 1 a))
+                                         (nth 1 b))
+                          (1- (length a))))
+               (and (math-known-scalarp b)
+                    (list 'calcFunc-idn (math-mul 
+                                         (nth 1 (nth 1 a)) b)
+                          (1- (length a))))
+               (and (math-known-matrixp b)
+                    (math-mul (nth 1 (nth 1 a)) b))))
+      (and (math-identity-matrix-p b t)
+           (or (and (eq (car-safe a) 'calcFunc-idn)
+                    (= (length a) 2)
+                    (list 'calcFunc-idn (math-mul (nth 1 a) 
+                                                  (nth 1 (nth 1 b)))
+                          (1- (length b))))
+               (and (math-known-scalarp a)
+                    (list 'calcFunc-idn (math-mul a (nth 1 (nth 1 b))) 
+                          (1- (length b))))
+               (and (math-known-matrixp a)
+                    (math-mul a (nth 1 (nth 1 b))))))
       (and (math-looks-negp b)
 	   (math-mul (math-neg a) (math-neg b)))
       (and (eq (car-safe b) '-)
@@ -1706,7 +1731,9 @@
       (math-div-new-non-trig term))))
 
 (defun math-div-symb-fancy (a b)
-  (or (and math-simplify-only
+  (or (and (math-known-matrixp b)
+           (math-mul a (math-pow b -1)))
+      (and math-simplify-only
 	   (not (equal a math-simplify-only))
 	   (list '/ a b))
       (and (Math-equal-int b 1) a)