changeset 66481:2c079383436e

(calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower): New functions.
author Jay Belanger <jay.p.belanger@gmail.com>
date Fri, 28 Oct 2005 03:52:38 +0000
parents feb65aa82eeb
children 340b9157f283
files lisp/calc/calc-alg.el
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calc/calc-alg.el	Fri Oct 28 03:52:08 2005 +0000
+++ b/lisp/calc/calc-alg.el	Fri Oct 28 03:52:38 2005 +0000
@@ -91,6 +91,32 @@
 				    (calc-top-n 1))
 			      (and n (list (prefix-numeric-value n)))))))
 
+;;; Write out powers (a*b*...)^n as a*b*...*a*b*...
+(defun calcFunc-writeoutpower (expr)
+  (math-normalize (math-map-tree 'math-write-out-power expr)))
+
+(defun math-write-out-power (expr)
+  (if (eq (car-safe expr) '^)
+      (let ((a (nth 1 expr))
+            (n (nth 2 expr))
+            (prod (nth 1 expr))
+            (i 1))
+        (if (and (integerp n)
+                 (> n 0))
+            (progn
+              (while (< i n)
+                (setq prod (math-mul prod a))
+                (setq i (1+ i)))
+              prod)
+          expr))
+    expr))
+
+(defun calc-writeoutpower ()
+  (interactive)
+  (calc-slow-wrapper
+   (calc-enter-result 1 "expp"
+		      (calcFunc-writeoutpower (calc-top-n 1)))))
+
 (defun calc-collect (&optional var)
   (interactive "sCollect terms involving: ")
   (calc-slow-wrapper