summaryrefslogtreecommitdiff
path: root/lisp/calc/calc-arith.el
diff options
context:
space:
mode:
authorJay Belanger <jay.p.belanger@gmail.com>2005-10-07 21:15:19 +0000
committerJay Belanger <jay.p.belanger@gmail.com>2005-10-07 21:15:19 +0000
commit05d2820548fdca099a7b1eaddeda70d1849618b0 (patch)
treeafd1efd75d3a877fea32f7cbe427d6e9a8237d3d /lisp/calc/calc-arith.el
parent36eaa68f561969b6173c235e5d180d64e6a54bb6 (diff)
(math-known-square-matrixp): New function.
(math-pow-fancy): Check for matrices before distributing exponent across products.
Diffstat (limited to 'lisp/calc/calc-arith.el')
-rw-r--r--lisp/calc/calc-arith.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/lisp/calc/calc-arith.el b/lisp/calc/calc-arith.el
index 25ccfc4801..9d4d04a575 100644
--- a/lisp/calc/calc-arith.el
+++ b/lisp/calc/calc-arith.el
@@ -305,6 +305,17 @@
(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)
@@ -1869,6 +1880,21 @@
(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))