aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2009-08-24 18:43:50 +0000
committerJay Belanger2009-08-24 18:43:50 +0000
commit42110eaf95a7ca8c08d15926e901eb0301e8a751 (patch)
tree531fce20a1c5e2fcab56680e0d62adf14a4a9271
parent88421f3e11449351b0815a3f06993fc8e29edb2a (diff)
downloademacs-42110eaf95a7ca8c08d15926e901eb0301e8a751.tar.gz
emacs-42110eaf95a7ca8c08d15926e901eb0301e8a751.zip
(math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
(calc-simplify): Simplify trig functions when asked.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/calc/calc-alg.el54
2 files changed, 58 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6d4db938378..eb11c0aaa8c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12009-08-24 Jay Belanger <jay.p.belanger@gmail.com>
2
3 * calc/calc-alg.el (math-trig-rewrite)
4 (math-hyperbolic-trig-rewrite): New functions.
5 (calc-simplify): Simplify trig functions when asked.
6
12009-08-24 Stefan Monnier <monnier@iro.umontreal.ca> 72009-08-24 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * diff-mode.el (diff-find-source-location): Avoid goto-line. 9 * diff-mode.el (diff-find-source-location): Avoid goto-line.
diff --git a/lisp/calc/calc-alg.el b/lisp/calc/calc-alg.el
index 9b3083f83d3..f4be1a5e036 100644
--- a/lisp/calc/calc-alg.el
+++ b/lisp/calc/calc-alg.el
@@ -51,8 +51,17 @@
51(defun calc-simplify () 51(defun calc-simplify ()
52 (interactive) 52 (interactive)
53 (calc-slow-wrapper 53 (calc-slow-wrapper
54 (calc-with-default-simplification 54 (let ((top (calc-top-n 1)))
55 (calc-enter-result 1 "simp" (math-simplify (calc-top-n 1)))))) 55 (if (calc-is-inverse)
56 (setq top
57 (let ((calc-simplify-mode nil))
58 (math-normalize (math-trig-rewrite top)))))
59 (if (calc-is-hyperbolic)
60 (setq top
61 (let ((calc-simplify-mode nil))
62 (math-normalize (math-hyperbolic-trig-rewrite top)))))
63 (calc-with-default-simplification
64 (calc-enter-result 1 "simp" (math-simplify top))))))
56 65
57(defun calc-simplify-extended () 66(defun calc-simplify-extended ()
58 (interactive) 67 (interactive)
@@ -303,6 +312,47 @@
303 312
304(defalias 'calcFunc-esimplify 'math-simplify-extended) 313(defalias 'calcFunc-esimplify 'math-simplify-extended)
305 314
315;;; Rewrite the trig functions in a form easier to simplify.
316(defun math-trig-rewrite (fn)
317 "Rewrite trigonometric functions in terms of sines and cosines."
318 (cond
319 ((not (consp fn))
320 fn)
321 ((eq (car-safe fn) 'calcFunc-sec)
322 (list '/ 1 (cons 'calcFunc-cos (math-trig-rewrite (cdr fn)))))
323 ((eq (car-safe fn) 'calcFunc-csc)
324 (list '/ 1 (cons 'calcFunc-sin (math-trig-rewrite (cdr fn)))))
325 ((eq (car-safe fn) 'calcFunc-tan)
326 (let ((newfn (math-trig-rewrite (cdr fn))))
327 (list '/ (cons 'calcFunc-sin newfn)
328 (cons 'calcFunc-cos newfn))))
329 ((eq (car-safe fn) 'calcFunc-cot)
330 (let ((newfn (math-trig-rewrite (cdr fn))))
331 (list '/ (cons 'calcFunc-cos newfn)
332 (cons 'calcFunc-sin newfn))))
333 (t
334 (mapcar 'math-trig-rewrite fn))))
335
336(defun math-hyperbolic-trig-rewrite (fn)
337 "Rewrite hyperbolic functions in terms of sinhs and coshs."
338 (cond
339 ((not (consp fn))
340 fn)
341 ((eq (car-safe fn) 'calcFunc-sech)
342 (list '/ 1 (cons 'calcFunc-cosh (math-hyperbolic-trig-rewrite (cdr fn)))))
343 ((eq (car-safe fn) 'calcFunc-csch)
344 (list '/ 1 (cons 'calcFunc-sinh (math-hyperbolic-trig-rewrite (cdr fn)))))
345 ((eq (car-safe fn) 'calcFunc-tanh)
346 (let ((newfn (math-hyperbolic-trig-rewrite (cdr fn))))
347 (list '/ (cons 'calcFunc-sinh newfn)
348 (cons 'calcFunc-cosh newfn))))
349 ((eq (car-safe fn) 'calcFunc-coth)
350 (let ((newfn (math-hyperbolic-trig-rewrite (cdr fn))))
351 (list '/ (cons 'calcFunc-cosh newfn)
352 (cons 'calcFunc-sinh newfn))))
353 (t
354 (mapcar 'math-hyperbolic-trig-rewrite fn))))
355
306;; math-top-only is local to math-simplify, but is used by 356;; math-top-only is local to math-simplify, but is used by
307;; math-simplify-step, which is called by math-simplify. 357;; math-simplify-step, which is called by math-simplify.
308(defvar math-top-only) 358(defvar math-top-only)