annotate lisp/calc/calc-alg.el @ 104768:17d2ae0948e2

Remove unnecessary bindings of default-major-mode (all are followed by major-mode check and possible mode switch).
author Glenn Morris <rgm@gnu.org>
date Tue, 01 Sep 2009 03:02:25 +0000
parents 209d73c6ff96
children a7d7a357c195
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
1 ;;; calc-alg.el --- algebraic functions for Calc
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
2
64325
1db49616ce05 Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 62165
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 99929
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
5
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
6 ;; Author: David Gillespie <daveg@synaptics.com>
77465
1154f082efd9 Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 76595
diff changeset
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15
76595
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
19 ;; GNU General Public License for more details.
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
20
497d17a80bb8 Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94654
6c9af2bfcfee Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
24 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
26 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28 ;; This file is autoloaded from calc-ext.el.
58646
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
29
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33 ;;; Algebra commands.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 (defun calc-alg-evaluate (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (calc-with-default-simplification
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 (let ((math-simplify-only nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (calc-modify-simplify-mode arg)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
41 (calc-enter-result 1 "dsmp" (calc-top 1))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
42
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (defun calc-modify-simplify-mode (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 (if (= (math-abs arg) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (setq calc-simplify-mode 'alg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (if (>= (math-abs arg) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 (setq calc-simplify-mode 'ext)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 (if (< arg 0)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
49 (setq calc-simplify-mode (list calc-simplify-mode))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
50
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
51 (defun calc-simplify ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 (calc-slow-wrapper
104565
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
54 (let ((top (calc-top-n 1)))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
55 (if (calc-is-inverse)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
56 (setq top
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
57 (let ((calc-simplify-mode nil))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
58 (math-normalize (math-trig-rewrite top)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
59 (if (calc-is-hyperbolic)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
60 (setq top
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
61 (let ((calc-simplify-mode nil))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
62 (math-normalize (math-hyperbolic-trig-rewrite top)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
63 (calc-with-default-simplification
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
64 (calc-enter-result 1 "simp" (math-simplify top))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (defun calc-simplify-extended ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (interactive)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (calc-with-default-simplification
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
70 (calc-enter-result 1 "esmp" (math-simplify-extended (calc-top-n 1))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (defun calc-expand-formula (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (interactive "p")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
75 (calc-with-default-simplification
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76 (let ((math-simplify-only nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (calc-modify-simplify-mode arg)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
78 (calc-enter-result 1 "expf"
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (if (> arg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
80 (let ((math-expand-formulas t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81 (calc-top-n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (let ((top (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (or (math-expand-formula top)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
84 top))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
85
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86 (defun calc-factor (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (calc-unary-op "fctr" (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
90 'calcFunc-factors 'calcFunc-factor)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
91 arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (defun calc-expand (n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
95 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96 (calc-enter-result 1 "expa"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (append (list 'calcFunc-expand
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (calc-top-n 1))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
99 (and n (list (prefix-numeric-value n)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
101 ;;; Write out powers (a*b*...)^n as a*b*...*a*b*...
66863
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
102 (defun calcFunc-powerexpand (expr)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
103 (math-normalize (math-map-tree 'math-powerexpand expr)))
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
104
66863
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
105 (defun math-powerexpand (expr)
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
106 (if (eq (car-safe expr) '^)
66863
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
107 (let ((n (nth 2 expr)))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
108 (cond ((and (integerp n)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
109 (> n 0))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
110 (let ((i 1)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
111 (a (nth 1 expr))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
112 (prod (nth 1 expr)))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
113 (while (< i n)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
114 (setq prod (math-mul prod a))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
115 (setq i (1+ i)))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
116 prod))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
117 ((and (integerp n)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
118 (< n 0))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
119 (let ((i -1)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
120 (a (math-pow (nth 1 expr) -1))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
121 (prod (math-pow (nth 1 expr) -1)))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
122 (while (> i n)
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
123 (setq prod (math-mul a prod))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
124 (setq i (1- i)))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
125 prod))
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
126 (t
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
127 expr)))
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
128 expr))
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
129
66863
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
130 (defun calc-powerexpand ()
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
131 (interactive)
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
132 (calc-slow-wrapper
66863
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
133 (calc-enter-result 1 "pexp"
78e895e87663 (calcFunc-write-out-power): Rename calcFunc-powerexpand.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 66481
diff changeset
134 (calcFunc-powerexpand (calc-top-n 1)))))
66481
2c079383436e (calcFunc-writeoutpower, math-write-out-power, calc-writeoutpower):
Jay Belanger <jay.p.belanger@gmail.com>
parents: 64325
diff changeset
135
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 (defun calc-collect (&optional var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 (interactive "sCollect terms involving: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (if (or (equal var "") (equal var "$") (null var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (calc-enter-result 2 "clct" (cons 'calcFunc-collect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (calc-top-list-n 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (let ((var (math-read-expr var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 (calc-enter-result 1 "clct" (list 'calcFunc-collect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 (calc-top-n 1)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
147 var))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (defun calc-apart (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (calc-slow-wrapper
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
152 (calc-unary-op "aprt" 'calcFunc-apart arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (defun calc-normalize-rat (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 (calc-slow-wrapper
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
157 (calc-unary-op "nrat" 'calcFunc-nrat arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159 (defun calc-poly-gcd (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
160 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
161 (calc-slow-wrapper
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
162 (calc-binary-op "pgcd" 'calcFunc-pgcd arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
163
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
164
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
165 (defun calc-poly-div (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
166 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
167 (calc-slow-wrapper
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
168 (let ((calc-poly-div-remainder nil))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
169 (calc-binary-op "pdiv" 'calcFunc-pdiv arg)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
170 (if (and calc-poly-div-remainder (null arg))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
171 (progn
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
172 (calc-clear-command-flag 'clear-message)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
173 (calc-record calc-poly-div-remainder "prem")
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
174 (if (not (Math-zerop calc-poly-div-remainder))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
175 (message "(Remainder was %s)"
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
176 (math-format-flat-expr calc-poly-div-remainder 0))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
177 (message "(No remainder)")))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (defun calc-poly-rem (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (calc-slow-wrapper
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
182 (calc-binary-op "prem" 'calcFunc-prem arg)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 (defun calc-poly-div-rem (arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (if (calc-is-hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (calc-binary-op "pdvr" 'calcFunc-pdivide arg)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
189 (calc-binary-op "pdvr" 'calcFunc-pdivrem arg))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
190
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191 (defun calc-substitute (&optional oldname newname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (interactive "sSubstitute old: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (let (old new (num 1) expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (if (or (equal oldname "") (equal oldname "$") (null oldname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (setq new (calc-top-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 old (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 expr (calc-top-n 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 num 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 (or newname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
201 (progn (calc-unread-command ?\C-a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202 (setq newname (read-string (concat "Substitute old: "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203 oldname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
204 ", new: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
205 oldname))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
206 (if (or (equal newname "") (equal newname "$") (null newname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
207 (setq new (calc-top-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
208 expr (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
209 num 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
210 (setq new (if (stringp newname) (math-read-expr newname) newname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
211 (if (eq (car-safe new) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 (error "Bad format in expression: %s" (nth 1 new)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213 (setq expr (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (setq old (if (stringp oldname) (math-read-expr oldname) oldname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
215 (if (eq (car-safe old) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
216 (error "Bad format in expression: %s" (nth 1 old)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (or (math-expr-contains expr old)
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41040
diff changeset
218 (error "No occurrences found")))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
219 (calc-enter-result num "sbst" (math-expr-subst expr old new)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 (defun calc-has-rules (name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 (setq name (calc-var-value name))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 (and (consp name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (memq (car name) '(vec calcFunc-assign calcFunc-condition))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
226 name))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
228 ;; math-eval-rules-cache and math-eval-rules-cache-other are
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
229 ;; declared in calc.el, but are used here by math-recompile-eval-rules.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
230 (defvar math-eval-rules-cache)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
231 (defvar math-eval-rules-cache-other)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
232
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
233 (defun math-recompile-eval-rules ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234 (setq math-eval-rules-cache (and (calc-has-rules 'var-EvalRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
235 (math-compile-rewrites
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
236 '(var EvalRules var-EvalRules)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 math-eval-rules-cache-other (assq nil math-eval-rules-cache)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
238 math-eval-rules-cache-tag (calc-var-value 'var-EvalRules)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
239
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
240
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
241 ;;; Try to expand a formula according to its definition.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
242 (defun math-expand-formula (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243 (and (consp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244 (symbolp (car expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (or (get (car expr) 'calc-user-defn)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (get (car expr) 'math-expandable))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (let ((res (let ((math-expand-formulas t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
248 (apply (car expr) (cdr expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249 (and (not (eq (car-safe res) (car expr)))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
250 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255 ;;; True if A comes before B in a canonical ordering of expressions. [P X X]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256 (defun math-beforep (a b) ; [Public]
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 (cond ((and (Math-realp a) (Math-realp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 (let ((comp (math-compare a b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
259 (or (eq comp -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 (and (eq comp 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 (not (equal a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (> (length (memq (car-safe a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 '(bigneg nil bigpos frac float)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 (length (memq (car-safe b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 '(bigneg nil bigpos frac float))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 ((equal b '(neg (var inf var-inf))) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 ((equal a '(neg (var inf var-inf))) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 ((equal a '(var inf var-inf)) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 ((equal b '(var inf var-inf)) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
270 ((Math-realp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 (if (and (eq (car-safe b) 'intv) (math-intv-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 (if (or (math-beforep a (nth 2 b)) (Math-equal a (nth 2 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
274 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
275 t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 ((Math-realp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 (if (and (eq (car-safe a) 'intv) (math-intv-constp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278 (if (math-beforep (nth 2 a) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 ((and (eq (car a) 'intv) (eq (car b) 'intv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (math-intv-constp a) (math-intv-constp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 (let ((comp (math-compare (nth 2 a) (nth 2 b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (cond ((eq comp -1) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 ((eq comp 1) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 ((and (memq (nth 1 a) '(2 3)) (memq (nth 1 b) '(0 1))) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
288 ((and (memq (nth 1 a) '(0 1)) (memq (nth 1 b) '(2 3))) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 ((eq (setq comp (math-compare (nth 3 a) (nth 3 b))) -1) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 ((eq comp 1) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
291 ((and (memq (nth 1 a) '(0 2)) (memq (nth 1 b) '(1 3))) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (t nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 ((not (eq (not (Math-objectp a)) (not (Math-objectp b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (Math-objectp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 ((eq (car a) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (if (eq (car b) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
297 (string-lessp (symbol-name (nth 1 a)) (symbol-name (nth 1 b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (not (Math-numberp b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
299 ((eq (car b) 'var) (Math-numberp a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 ((eq (car a) (car b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
301 (while (and (setq a (cdr a) b (cdr b)) a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (equal (car a) (car b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (and b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (or (null a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 (math-beforep (car a) (car b)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
306 (t (string-lessp (symbol-name (car a)) (symbol-name (car b))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
309 (defsubst math-simplify-extended (a)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (let ((math-living-dangerously t))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
311 (math-simplify a)))
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
312
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
313 (defalias 'calcFunc-esimplify 'math-simplify-extended)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314
104565
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
315 ;;; Rewrite the trig functions in a form easier to simplify.
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
316 (defun math-trig-rewrite (fn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
317 "Rewrite trigonometric functions in terms of sines and cosines."
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
318 (cond
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
319 ((not (consp fn))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
320 fn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
321 ((eq (car-safe fn) 'calcFunc-sec)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
322 (list '/ 1 (cons 'calcFunc-cos (math-trig-rewrite (cdr fn)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
323 ((eq (car-safe fn) 'calcFunc-csc)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
324 (list '/ 1 (cons 'calcFunc-sin (math-trig-rewrite (cdr fn)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
325 ((eq (car-safe fn) 'calcFunc-tan)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
326 (let ((newfn (math-trig-rewrite (cdr fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
327 (list '/ (cons 'calcFunc-sin newfn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
328 (cons 'calcFunc-cos newfn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
329 ((eq (car-safe fn) 'calcFunc-cot)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
330 (let ((newfn (math-trig-rewrite (cdr fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
331 (list '/ (cons 'calcFunc-cos newfn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
332 (cons 'calcFunc-sin newfn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
333 (t
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
334 (mapcar 'math-trig-rewrite fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
335
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
336 (defun math-hyperbolic-trig-rewrite (fn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
337 "Rewrite hyperbolic functions in terms of sinhs and coshs."
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
338 (cond
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
339 ((not (consp fn))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
340 fn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
341 ((eq (car-safe fn) 'calcFunc-sech)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
342 (list '/ 1 (cons 'calcFunc-cosh (math-hyperbolic-trig-rewrite (cdr fn)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
343 ((eq (car-safe fn) 'calcFunc-csch)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
344 (list '/ 1 (cons 'calcFunc-sinh (math-hyperbolic-trig-rewrite (cdr fn)))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
345 ((eq (car-safe fn) 'calcFunc-tanh)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
346 (let ((newfn (math-hyperbolic-trig-rewrite (cdr fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
347 (list '/ (cons 'calcFunc-sinh newfn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
348 (cons 'calcFunc-cosh newfn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
349 ((eq (car-safe fn) 'calcFunc-coth)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
350 (let ((newfn (math-hyperbolic-trig-rewrite (cdr fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
351 (list '/ (cons 'calcFunc-cosh newfn)
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
352 (cons 'calcFunc-sinh newfn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
353 (t
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
354 (mapcar 'math-hyperbolic-trig-rewrite fn))))
209d73c6ff96 (math-trig-rewrite, math-hyperbolic-trig-rewrite): New functions.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 100908
diff changeset
355
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
356 ;; math-top-only is local to math-simplify, but is used by
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
357 ;; math-simplify-step, which is called by math-simplify.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
358 (defvar math-top-only)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
359
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
360 (defun math-simplify (top-expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361 (let ((math-simplifying t)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
362 (math-top-only (consp calc-simplify-mode))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 (simp-rules (append (and (calc-has-rules 'var-AlgSimpRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364 '((var AlgSimpRules var-AlgSimpRules)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (and math-living-dangerously
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (calc-has-rules 'var-ExtSimpRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367 '((var ExtSimpRules var-ExtSimpRules)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 (and math-simplifying-units
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (calc-has-rules 'var-UnitSimpRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370 '((var UnitSimpRules var-UnitSimpRules)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (and math-integrating
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (calc-has-rules 'var-IntegSimpRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373 '((var IntegSimpRules var-IntegSimpRules)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 res)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
375 (if math-top-only
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376 (let ((r simp-rules))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377 (setq res (math-simplify-step (math-normalize top-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
378 calc-simplify-mode '(nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379 top-expr (math-normalize res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 (while r
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381 (setq top-expr (math-rewrite top-expr (car r)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 '(neg (var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 r (cdr r))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384 (calc-with-default-simplification
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 (while (let ((r simp-rules))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
386 (setq res (math-normalize top-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 (while r
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (setq res (math-rewrite res (car r))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
389 r (cdr r)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
390 (not (equal top-expr (setq res (math-simplify-step res)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391 (setq top-expr res)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
392 top-expr)
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
393
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
394 (defalias 'calcFunc-simplify 'math-simplify)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 ;;; The following has a "bug" in that if any recursive simplifications
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397 ;;; occur only the first handler will be tried; this doesn't really
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
398 ;;; matter, since math-simplify-step is iterated to a fixed point anyway.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399 (defun math-simplify-step (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400 (if (Math-primp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 a
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
402 (let ((aa (if (or math-top-only
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403 (memq (car a) '(calcFunc-quote calcFunc-condition
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404 calcFunc-evalto)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 (cons (car a) (mapcar 'math-simplify-step (cdr a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407 (and (symbolp (car aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (let ((handler (get (car aa) 'math-simplify)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (and handler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 (while (and handler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 (equal (setq aa (or (funcall (car handler) aa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412 aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 (setq handler (cdr handler))))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
415 aa)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417
58646
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
418 (defmacro math-defsimplify (funcs &rest code)
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
419 (append '(progn)
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
420 (mapcar (function
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
421 (lambda (func)
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
422 (list 'put (list 'quote func) ''math-simplify
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
423 (list 'nconc
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
424 (list 'get (list 'quote func) ''math-simplify)
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
425 (list 'list
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
426 (list 'function
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
427 (append '(lambda (math-simplify-expr))
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
428 code)))))))
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
429 (if (symbolp funcs) (list funcs) funcs))))
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
430 (put 'math-defsimplify 'lisp-indent-hook 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
432 ;; The function created by math-defsimplify uses the variable
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
433 ;; math-simplify-expr, and so is used by functions in math-defsimplify
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
434 (defvar math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
435
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436 (math-defsimplify (+ -)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (math-simplify-plus))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439 (defun math-simplify-plus ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
440 (cond ((and (memq (car-safe (nth 1 math-simplify-expr)) '(+ -))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
441 (Math-numberp (nth 2 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
442 (not (Math-numberp (nth 2 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
443 (let ((x (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
444 (op (car math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
445 (setcar (cdr (cdr math-simplify-expr)) (nth 2 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
446 (setcar math-simplify-expr (car (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
447 (setcar (cdr (cdr (nth 1 math-simplify-expr))) x)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
448 (setcar (nth 1 math-simplify-expr) op)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
449 ((and (eq (car math-simplify-expr) '+)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
450 (Math-numberp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
451 (not (Math-numberp (nth 2 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
452 (let ((x (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
453 (setcar (cdr (cdr math-simplify-expr)) (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
454 (setcar (cdr math-simplify-expr) x))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
455 (let ((aa math-simplify-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 aaa temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 (while (memq (car-safe (setq aaa (nth 1 aa))) '(+ -))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
458 (if (setq temp (math-combine-sum (nth 2 aaa) (nth 2 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
459 (eq (car aaa) '-)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
460 (eq (car math-simplify-expr) '-) t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
462 (setcar (cdr (cdr math-simplify-expr)) temp)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
463 (setcar math-simplify-expr '+)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (setcar (cdr (cdr aaa)) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (setq aa (nth 1 aa)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
466 (if (setq temp (math-combine-sum aaa (nth 2 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
467 nil (eq (car math-simplify-expr) '-) t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
469 (setcar (cdr (cdr math-simplify-expr)) temp)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
470 (setcar math-simplify-expr '+)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (setcar (cdr aa) 0)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
472 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 (math-defsimplify *
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (math-simplify-times))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 (defun math-simplify-times ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
478 (if (eq (car-safe (nth 2 math-simplify-expr)) '*)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
479 (and (math-beforep (nth 1 (nth 2 math-simplify-expr)) (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
480 (or (math-known-scalarp (nth 1 math-simplify-expr) t)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
481 (math-known-scalarp (nth 1 (nth 2 math-simplify-expr)) t))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
482 (let ((x (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
483 (setcar (cdr math-simplify-expr) (nth 1 (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
484 (setcar (cdr (nth 2 math-simplify-expr)) x)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
485 (and (math-beforep (nth 2 math-simplify-expr) (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
486 (or (math-known-scalarp (nth 1 math-simplify-expr) t)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
487 (math-known-scalarp (nth 2 math-simplify-expr) t))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
488 (let ((x (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
489 (setcar (cdr (cdr math-simplify-expr)) (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
490 (setcar (cdr math-simplify-expr) x))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
491 (let ((aa math-simplify-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 aaa temp
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
493 (safe t) (scalar (math-known-scalarp (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
494 (if (and (Math-ratp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
495 (setq temp (math-common-constant-factor (nth 2 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
497 (setcar (cdr (cdr math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
498 (math-cancel-common-factor (nth 2 math-simplify-expr) temp))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
499 (setcar (cdr math-simplify-expr) (math-mul (nth 1 math-simplify-expr) temp))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 (while (and (eq (car-safe (setq aaa (nth 2 aa))) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 safe)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
502 (if (setq temp (math-combine-prod (nth 1 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
503 (nth 1 aaa) nil nil t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
505 (setcar (cdr math-simplify-expr) temp)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 (setcar (cdr aaa) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (setq safe (or scalar (math-known-scalarp (nth 1 aaa) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
508 aa (nth 2 aa)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
509 (if (and (setq temp (math-combine-prod aaa (nth 1 math-simplify-expr) nil nil t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 safe)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
512 (setcar (cdr math-simplify-expr) temp)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (setcar (cdr (cdr aa)) 1)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
514 (if (and (eq (car-safe (nth 1 math-simplify-expr)) 'frac)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
515 (memq (nth 1 (nth 1 math-simplify-expr)) '(1 -1)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
516 (math-div (math-mul (nth 2 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
517 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
518 (nth 2 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
519 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521 (math-defsimplify /
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 (math-simplify-divide))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 (defun math-simplify-divide ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
525 (let ((np (cdr math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (nover nil)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
527 (nn (and (or (eq (car math-simplify-expr) '/)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
528 (not (Math-realp (nth 2 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
529 (math-common-constant-factor (nth 2 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 n op)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 (if nn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
533 (setq n (and (or (eq (car math-simplify-expr) '/)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
534 (not (Math-realp (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
535 (math-common-constant-factor (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536 (if (and (eq (car-safe nn) 'frac) (eq (nth 1 nn) 1) (not n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
538 (setcar (cdr math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
539 (math-mul (nth 2 nn) (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
540 (setcar (cdr (cdr math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
541 (math-cancel-common-factor (nth 2 math-simplify-expr) nn))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (if (and (math-negp nn)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
543 (setq op (assq (car math-simplify-expr) calc-tweak-eqn-table)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
544 (setcar math-simplify-expr (nth 1 op))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545 (if (and n (not (eq (setq n (math-frac-gcd n nn)) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
547 (setcar (cdr math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
548 (math-cancel-common-factor (nth 1 math-simplify-expr) n))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
549 (setcar (cdr (cdr math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
550 (math-cancel-common-factor (nth 2 math-simplify-expr) n))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
551 (if (and (math-negp n)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
552 (setq op (assq (car math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
553 calc-tweak-eqn-table)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
554 (setcar math-simplify-expr (nth 1 op))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 (if (and (eq (car-safe (car np)) '/)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
556 (math-known-scalarp (nth 2 math-simplify-expr) t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (progn
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
558 (setq np (cdr (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (while (eq (car-safe (setq n (car np))) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (and (math-known-scalarp (nth 2 n) t)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
561 (math-simplify-divisor (cdr n) (cdr (cdr math-simplify-expr)) nil t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 (setq np (cdr (cdr n))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
563 (math-simplify-divisor np (cdr (cdr math-simplify-expr)) nil t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (setq nover t
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
565 np (cdr (cdr (nth 1 math-simplify-expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 (while (eq (car-safe (setq n (car np))) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (and (math-known-scalarp (nth 2 n) t)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
568 (math-simplify-divisor (cdr n) (cdr (cdr math-simplify-expr)) nover t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 (setq np (cdr (cdr n))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
570 (math-simplify-divisor np (cdr (cdr math-simplify-expr)) nover t)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
571 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
573 ;; The variables math-simplify-divisor-nover and math-simplify-divisor-dover
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
574 ;; are local variables for math-simplify-divisor, but are used by
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
575 ;; math-simplify-one-divisor.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
576 (defvar math-simplify-divisor-nover)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
577 (defvar math-simplify-divisor-dover)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
578
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
579 (defun math-simplify-divisor (np dp math-simplify-divisor-nover
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
580 math-simplify-divisor-dover)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (cond ((eq (car-safe (car dp)) '/)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
582 (math-simplify-divisor np (cdr (car dp))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
583 math-simplify-divisor-nover
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
584 math-simplify-divisor-dover)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
585 (and (math-known-scalarp (nth 1 (car dp)) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 (math-simplify-divisor np (cdr (cdr (car dp)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
587 math-simplify-divisor-nover
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
588 (not math-simplify-divisor-dover))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
589 ((or (or (eq (car math-simplify-expr) '/)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 (let ((signs (math-possible-signs (car np))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591 (or (memq signs '(1 4))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
592 (and (memq (car math-simplify-expr) '(calcFunc-eq calcFunc-neq))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (eq signs 5))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 math-living-dangerously)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (math-numberp (car np)))
58311
4f2b521da5aa (math-simplify-divisor): Remove unnecessary variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58300
diff changeset
596 (let (d
4f2b521da5aa (math-simplify-divisor): Remove unnecessary variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58300
diff changeset
597 (safe t)
4f2b521da5aa (math-simplify-divisor): Remove unnecessary variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58300
diff changeset
598 (scalar (math-known-scalarp (car np))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599 (while (and (eq (car-safe (setq d (car dp))) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 safe)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 (math-simplify-one-divisor np (cdr d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 (setq safe (or scalar (math-known-scalarp (nth 1 d) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 dp (cdr (cdr d))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 (if safe
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
605 (math-simplify-one-divisor np dp))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607 (defun math-simplify-one-divisor (np dp)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
608 (let ((temp (math-combine-prod (car np) (car dp) math-simplify-divisor-nover
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
609 math-simplify-divisor-dover t))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
610 op)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
611 (if temp
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
612 (progn
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
613 (and (not (memq (car math-simplify-expr) '(/ calcFunc-eq calcFunc-neq)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
614 (math-known-negp (car dp))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
615 (setq op (assq (car math-simplify-expr) calc-tweak-eqn-table))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
616 (setcar math-simplify-expr (nth 1 op)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
617 (setcar np (if math-simplify-divisor-nover (math-div 1 temp) temp))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
618 (setcar dp 1))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
619 (and math-simplify-divisor-dover (not math-simplify-divisor-nover)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
620 (eq (car math-simplify-expr) '/)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
621 (eq (car-safe (car dp)) 'calcFunc-sqrt)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
622 (Math-integerp (nth 1 (car dp)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
623 (progn
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
624 (setcar np (math-mul (car np)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
625 (list 'calcFunc-sqrt (nth 1 (car dp)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
626 (setcar dp (nth 1 (car dp))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
627
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
628 (defun math-common-constant-factor (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (if (Math-realp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630 (if (Math-ratp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 (and (not (memq expr '(0 1 -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 (math-abs expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633 (if (math-ratp (setq expr (math-to-simple-fraction expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 (math-common-constant-factor expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (if (memq (car expr) '(+ - cplx sdev))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 (let ((f1 (math-common-constant-factor (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 (f2 (math-common-constant-factor (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 (and f1 f2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 (not (eq (setq f1 (math-frac-gcd f1 f2)) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 f1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641 (if (memq (car expr) '(* polar))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (math-common-constant-factor (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 (if (eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
644 (or (math-common-constant-factor (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645 (and (Math-integerp (nth 2 expr))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
646 (list 'frac 1 (math-abs (nth 2 expr))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 (defun math-cancel-common-factor (expr val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 (if (memq (car-safe expr) '(+ - cplx sdev))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 (setcar (cdr expr) (math-cancel-common-factor (nth 1 expr) val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 (setcar (cdr (cdr expr)) (math-cancel-common-factor (nth 2 expr) val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
653 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
654 (if (eq (car-safe expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
655 (math-mul (math-cancel-common-factor (nth 1 expr) val) (nth 2 expr))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
656 (math-div expr val))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
657
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
658 (defun math-frac-gcd (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
659 (if (Math-zerop a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
660 b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
661 (if (Math-zerop b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
662 a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
663 (if (and (Math-integerp a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
664 (Math-integerp b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
665 (math-gcd a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
666 (and (Math-integerp a) (setq a (list 'frac a 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
667 (and (Math-integerp b) (setq b (list 'frac b 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
668 (math-make-frac (math-gcd (nth 1 a) (nth 1 b))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
669 (math-gcd (nth 2 a) (nth 2 b)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
670
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
671 (math-defsimplify %
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (math-simplify-mod))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
673
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
674 (defun math-simplify-mod ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
675 (and (Math-realp (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
676 (Math-posp (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
677 (let ((lin (math-is-linear (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 t1 t2 t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679 (or (and lin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
680 (or (math-negp (car lin))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
681 (not (Math-lessp (car lin) (nth 2 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (list '%
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
683 (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
684 (math-mul (nth 1 lin) (nth 2 lin))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
685 (math-mod (car lin) (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
686 (nth 2 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
687 (and lin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 (not (math-equal-int (nth 1 lin) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
689 (math-num-integerp (nth 1 lin))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
690 (math-num-integerp (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
691 (setq t1 (calcFunc-gcd (nth 1 lin) (nth 2 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
692 (not (math-equal-int t1 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 (list '*
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 t1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695 (list '%
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
696 (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 (math-mul (math-div (nth 1 lin) t1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (nth 2 lin))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (math-div (car lin) t1)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
701 (math-div (nth 2 math-simplify-expr) t1))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
702 (and (math-equal-int (nth 2 math-simplify-expr) 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (math-known-integerp (if lin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 (math-mul (nth 1 lin) (nth 2 lin))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
705 (nth 1 math-simplify-expr)))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
706 (if lin (math-mod (car lin) 1) 0))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
707
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
708 (math-defsimplify (calcFunc-eq calcFunc-neq calcFunc-lt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 calcFunc-gt calcFunc-leq calcFunc-geq)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
710 (if (= (length math-simplify-expr) 3)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (math-simplify-ineq)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
712
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 (defun math-simplify-ineq ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
714 (let ((np (cdr math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 (while (memq (car-safe (setq n (car np))) '(+ -))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
717 (math-simplify-add-term (cdr (cdr n)) (cdr (cdr math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 (eq (car n) '-) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 (setq np (cdr n)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
720 (math-simplify-add-term np (cdr (cdr math-simplify-expr)) nil
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
721 (eq np (cdr math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 (math-simplify-divide)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
723 (let ((signs (math-possible-signs (cons '- (cdr math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
724 (or (cond ((eq (car math-simplify-expr) 'calcFunc-eq)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 (or (and (eq signs 2) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (and (memq signs '(1 4 5)) 0)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
727 ((eq (car math-simplify-expr) 'calcFunc-neq)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 (or (and (eq signs 2) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 (and (memq signs '(1 4 5)) 1)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
730 ((eq (car math-simplify-expr) 'calcFunc-lt)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
731 (or (and (eq signs 1) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (and (memq signs '(2 4 6)) 0)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
733 ((eq (car math-simplify-expr) 'calcFunc-gt)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
734 (or (and (eq signs 4) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 (and (memq signs '(1 2 3)) 0)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
736 ((eq (car math-simplify-expr) 'calcFunc-leq)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 (or (and (eq signs 4) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 (and (memq signs '(1 2 3)) 1)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
739 ((eq (car math-simplify-expr) 'calcFunc-geq)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (or (and (eq signs 1) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 (and (memq signs '(2 4 6)) 1))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
742 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 (defun math-simplify-add-term (np dp minus lplain)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 (or (math-vectorp (car np))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 (let ((rplain t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 n d dd temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 (while (memq (car-safe (setq n (car np) d (car dp))) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 (setq rplain nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 (if (setq temp (math-combine-sum n (nth 2 d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 minus (eq (car d) '+) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 (if (or lplain (eq (math-looks-negp temp) minus))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
753 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
754 (setcar np (setq n (if minus (math-neg temp) temp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755 (setcar (cdr (cdr d)) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (setcar np 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 (setcar (cdr (cdr d)) (setq n (if (eq (car d) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 (math-neg temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 temp))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 (setq dp (cdr d)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
762 (if (setq temp (math-combine-sum n d minus t t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
763 (if (or lplain
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
764 (and (not rplain)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
765 (eq (math-looks-negp temp) minus)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
766 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 (setcar np (setq n (if minus (math-neg temp) temp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 (setcar dp 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
770 (setcar np 0)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
771 (setcar dp (setq n (math-neg temp)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 (math-defsimplify calcFunc-sin
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
774 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
775 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
776 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
777 (math-neg (list 'calcFunc-sin (math-neg (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
778 (and (eq calc-angle-mode 'rad)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
779 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
780 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
781 (math-known-sin (car n) (nth 1 n) 120 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
782 (and (eq calc-angle-mode 'deg)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
783 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
784 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
785 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
786 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
787 (list 'calcFunc-sqrt (math-sub 1 (math-sqr
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
788 (nth 1 (nth 1 math-simplify-expr))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
789 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
790 (math-div (nth 1 (nth 1 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
791 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
792 (math-add 1 (math-sqr
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
793 (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
794 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
795 (and m (integerp (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
796 (let ((n (car m)) (a (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
797 (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
798 (list '* (list 'calcFunc-sin (list '* (1- n) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
799 (list 'calcFunc-cos a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
800 (list '* (list 'calcFunc-cos (list '* (1- n) a))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
801 (list 'calcFunc-sin a))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
803 (math-defsimplify calcFunc-cos
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
804 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
805 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
806 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
807 (list 'calcFunc-cos (math-neg (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (and (eq calc-angle-mode 'rad)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
809 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
810 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
811 (math-known-sin (car n) (nth 1 n) 120 300))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
812 (and (eq calc-angle-mode 'deg)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
813 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
814 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
815 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
816 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
817 (list 'calcFunc-sqrt
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
818 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
819 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 (math-div 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
821 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
822 (math-add 1
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
823 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
824 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
825 (and m (integerp (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
826 (let ((n (car m)) (a (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
827 (list '-
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
828 (list '* (list 'calcFunc-cos (list '* (1- n) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
829 (list 'calcFunc-cos a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
830 (list '* (list 'calcFunc-sin (list '* (1- n) a))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
831 (list 'calcFunc-sin a))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
832
60076
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
833 (math-defsimplify calcFunc-sec
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
834 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
835 (list 'calcFunc-sec (math-neg (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
836 (and (eq calc-angle-mode 'rad)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
837 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
838 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
839 (math-div 1 (math-known-sin (car n) (nth 1 n) 120 300)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
840 (and (eq calc-angle-mode 'deg)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
841 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
842 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
843 (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
844 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
845 (math-div
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
846 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
847 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
848 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
849 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
850 (math-div
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
851 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
852 (nth 1 (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
853 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
854 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
855 (math-add 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
856 (math-sqr (nth 1 (nth 1 math-simplify-expr))))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
857
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
858 (math-defsimplify calcFunc-csc
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
859 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
860 (math-neg (list 'calcFunc-csc (math-neg (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
861 (and (eq calc-angle-mode 'rad)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
862 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
863 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
864 (math-div 1 (math-known-sin (car n) (nth 1 n) 120 0)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
865 (and (eq calc-angle-mode 'deg)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
866 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
867 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
868 (math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
869 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
870 (math-div 1 (nth 1 (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
871 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
872 (math-div
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
873 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
874 (list 'calcFunc-sqrt (math-sub 1 (math-sqr
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
875 (nth 1 (nth 1 math-simplify-expr)))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
876 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
877 (math-div (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
878 (math-add 1 (math-sqr
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
879 (nth 1 (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
880 (nth 1 (nth 1 math-simplify-expr))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
881
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
882 (defun math-should-expand-trig (x &optional hyperbolic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
883 (let ((m (math-is-multiple x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
884 (and math-living-dangerously
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
885 m (or (and (integerp (car m)) (> (car m) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
886 (equal (car m) '(frac 1 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
887 (or math-integrating
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
888 (memq (car-safe (nth 1 m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
889 (if hyperbolic
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
890 '(calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
891 '(calcFunc-arcsin calcFunc-arccos calcFunc-arctan)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
892 (and (eq (car-safe (nth 1 m)) 'calcFunc-ln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
893 (eq hyperbolic 'exp)))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
894 m)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
895
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
896 (defun math-known-sin (plus n mul off)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
897 (setq n (math-mul n mul))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
898 (and (math-num-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
899 (setq n (math-mod (math-add (math-trunc n) off) 240))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
900 (if (>= n 120)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
901 (and (setq n (math-known-sin plus (- n 120) 1 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
902 (math-neg n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
903 (if (> n 60)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
904 (setq n (- 120 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
905 (if (math-zerop plus)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
906 (and (or calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
907 (memq n '(0 20 60)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
908 (cdr (assq n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
909 '( (0 . 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
910 (10 . (/ (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
911 (- 2 (calcFunc-sqrt 3))) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
912 (12 . (/ (- (calcFunc-sqrt 5) 1) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
913 (15 . (/ (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
914 (- 2 (calcFunc-sqrt 2))) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
915 (20 . (/ 1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
916 (24 . (* (^ (/ 1 2) (/ 3 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
917 (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
918 (- 5 (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
919 (30 . (/ (calcFunc-sqrt 2) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
920 (36 . (/ (+ (calcFunc-sqrt 5) 1) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
921 (40 . (/ (calcFunc-sqrt 3) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
922 (45 . (/ (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
923 (+ 2 (calcFunc-sqrt 2))) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
924 (48 . (* (^ (/ 1 2) (/ 3 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
925 (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
926 (+ 5 (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
927 (50 . (/ (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
928 (+ 2 (calcFunc-sqrt 3))) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
929 (60 . 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
930 (cond ((eq n 0) (math-normalize (list 'calcFunc-sin plus)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
931 ((eq n 60) (math-normalize (list 'calcFunc-cos plus)))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
932 (t nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
933
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
934 (math-defsimplify calcFunc-tan
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
935 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
936 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
937 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
938 (math-neg (list 'calcFunc-tan (math-neg (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
939 (and (eq calc-angle-mode 'rad)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
940 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
941 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
942 (math-known-tan (car n) (nth 1 n) 120))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
943 (and (eq calc-angle-mode 'deg)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
944 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
946 (math-known-tan (car n) (nth 1 n) '(frac 2 3)))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
947 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
948 (math-div (nth 1 (nth 1 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
949 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
950 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
951 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
952 (math-div (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
953 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
954 (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
955 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
956 (and m
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
957 (if (equal (car m) '(frac 1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
958 (math-div (math-sub 1 (list 'calcFunc-cos (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
959 (list 'calcFunc-sin (nth 1 m)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
960 (math-div (list 'calcFunc-sin (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
961 (list 'calcFunc-cos (nth 1 math-simplify-expr))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
962
60076
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
963 (math-defsimplify calcFunc-cot
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
964 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
965 (math-neg (list 'calcFunc-cot (math-neg (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
966 (and (eq calc-angle-mode 'rad)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
967 (let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
968 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
969 (math-div 1 (math-known-tan (car n) (nth 1 n) 120)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
970 (and (eq calc-angle-mode 'deg)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
971 (let ((n (math-integer-plus (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
972 (and n
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
973 (math-div 1 (math-known-tan (car n) (nth 1 n) '(frac 2 3))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
974 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
975 (math-div (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
976 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
977 (nth 1 (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
978 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
979 (math-div (nth 1 (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
980 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
981 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
982 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctan)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
983 (math-div 1 (nth 1 (nth 1 math-simplify-expr))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
984
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985 (defun math-known-tan (plus n mul)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
986 (setq n (math-mul n mul))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (and (math-num-integerp n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
988 (setq n (math-mod (math-trunc n) 120))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989 (if (> n 60)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (and (setq n (math-known-tan plus (- 120 n) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 (math-neg n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
992 (if (math-zerop plus)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993 (and (or calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 (memq n '(0 30 60)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995 (cdr (assq n '( (0 . 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
996 (10 . (- 2 (calcFunc-sqrt 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997 (12 . (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
998 (- 1 (* (/ 2 5) (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999 (15 . (- (calcFunc-sqrt 2) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 (20 . (/ (calcFunc-sqrt 3) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1001 (24 . (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1002 (- 5 (* 2 (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003 (30 . 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (36 . (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1005 (+ 1 (* (/ 2 5) (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1006 (40 . (calcFunc-sqrt 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007 (45 . (+ (calcFunc-sqrt 2) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 (48 . (calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (+ 5 (* 2 (calcFunc-sqrt 5)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (50 . (+ 2 (calcFunc-sqrt 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (60 . (var uinf var-uinf))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1012 (cond ((eq n 0) (math-normalize (list 'calcFunc-tan plus)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 ((eq n 60) (math-normalize (list '/ -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1014 (list 'calcFunc-tan plus))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1015 (t nil))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1016
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1017 (math-defsimplify calcFunc-sinh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1018 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1019 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1020 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1021 (math-neg (list 'calcFunc-sinh (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1022 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1023 math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1024 (list 'calcFunc-sqrt
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1025 (math-sub (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1026 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1027 math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1028 (math-div (nth 1 (nth 1 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1029 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1030 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1031 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr) t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (and m (integerp (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 (let ((n (car m)) (a (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1034 (if (> n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035 (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1036 (list '* (list 'calcFunc-sinh (list '* (1- n) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1037 (list 'calcFunc-cosh a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1038 (list '* (list 'calcFunc-cosh (list '* (1- n) a))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1039 (list 'calcFunc-sinh a)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1040
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1041 (math-defsimplify calcFunc-cosh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1042 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1043 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1044 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1045 (list 'calcFunc-cosh (math-neg (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1046 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1047 math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1048 (list 'calcFunc-sqrt
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1049 (math-add (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1050 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1051 math-living-dangerously
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1052 (math-div 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1053 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1054 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1055 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr) t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1056 (and m (integerp (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1057 (let ((n (car m)) (a (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1058 (if (> n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1060 (list '* (list 'calcFunc-cosh (list '* (1- n) a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1061 (list 'calcFunc-cosh a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1062 (list '* (list 'calcFunc-sinh (list '* (1- n) a))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1063 (list 'calcFunc-sinh a)))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1064
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1065 (math-defsimplify calcFunc-tanh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1066 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1067 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1068 (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1069 (math-neg (list 'calcFunc-tanh (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1070 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1072 (math-div (nth 1 (nth 1 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1074 (math-add (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1075 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1076 math-living-dangerously
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1077 (math-div (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1078 (math-sub (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1079 (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1080 (let ((m (math-should-expand-trig (nth 1 math-simplify-expr) t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (and m
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1082 (if (equal (car m) '(frac 1 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1083 (math-div (math-sub (list 'calcFunc-cosh (nth 1 m)) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084 (list 'calcFunc-sinh (nth 1 m)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1085 (math-div (list 'calcFunc-sinh (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1086 (list 'calcFunc-cosh (nth 1 math-simplify-expr))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1087
60076
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1088 (math-defsimplify calcFunc-sech
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1089 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1090 (list 'calcFunc-sech (math-neg (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1091 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1092 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1093 (math-div
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1094 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1095 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1096 (math-add (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1097 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1098 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1099 (math-div 1 (nth 1 (nth 1 math-simplify-expr))) 1)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1100 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1101 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1102 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1103 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr))))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1104
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1105 (math-defsimplify calcFunc-csch
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1106 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1107 (math-neg (list 'calcFunc-csch (math-neg (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1108 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1109 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1110 (math-div 1 (nth 1 (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1111 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1112 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1113 (math-div
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1114 1
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1115 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1116 (math-sub (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1117 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1118 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1119 (math-div (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1120 (math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1121 (nth 1 (nth 1 math-simplify-expr))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1122
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1123 (math-defsimplify calcFunc-coth
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1124 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1125 (math-neg (list 'calcFunc-coth (math-neg (nth 1 math-simplify-expr)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1126 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsinh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1127 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1128 (math-div (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1129 (math-add (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1130 (nth 1 (nth 1 math-simplify-expr))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1131 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccosh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1132 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1133 (math-div (nth 1 (nth 1 math-simplify-expr))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1134 (list 'calcFunc-sqrt
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1135 (math-sub (math-sqr (nth 1 (nth 1 math-simplify-expr))) 1))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1136 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arctanh)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1137 math-living-dangerously
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1138 (math-div 1 (nth 1 (nth 1 math-simplify-expr))))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1139
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1140 (math-defsimplify calcFunc-arcsin
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1141 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1142 (math-neg (list 'calcFunc-arcsin (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1143 (and (eq (nth 1 math-simplify-expr) 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1144 (math-quarter-circle t))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1145 (and (equal (nth 1 math-simplify-expr) '(frac 1 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1146 (math-div (math-half-circle t) 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1147 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1148 (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-sin)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1149 (nth 1 (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1150 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1151 (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-cos)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1152 (math-sub (math-quarter-circle t)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1153 (nth 1 (nth 1 math-simplify-expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1154
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1155 (math-defsimplify calcFunc-arccos
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1156 (or (and (eq (nth 1 math-simplify-expr) 0)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1157 (math-quarter-circle t))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1158 (and (eq (nth 1 math-simplify-expr) -1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 (math-half-circle t))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1160 (and (equal (nth 1 math-simplify-expr) '(frac 1 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1161 (math-div (math-half-circle t) 3))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1162 (and (equal (nth 1 math-simplify-expr) '(frac -1 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1163 (math-div (math-mul (math-half-circle t) 2) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1165 (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-cos)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1166 (nth 1 (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1167 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1168 (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-sin)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169 (math-sub (math-quarter-circle t)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1170 (nth 1 (nth 1 math-simplify-expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (math-defsimplify calcFunc-arctan
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1173 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1174 (math-neg (list 'calcFunc-arctan (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1175 (and (eq (nth 1 math-simplify-expr) 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 (math-div (math-half-circle t) 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1178 (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-tan)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1179 (nth 1 (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1180
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181 (math-defsimplify calcFunc-arcsinh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1182 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1183 (math-neg (list 'calcFunc-arcsinh (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1184 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-sinh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1186 (math-known-realp (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1187 (nth 1 (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (math-defsimplify calcFunc-arccosh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1190 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-cosh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1192 (math-known-realp (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1193 (nth 1 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1195 (math-defsimplify calcFunc-arctanh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1196 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1197 (math-neg (list 'calcFunc-arctanh (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1198 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-tanh)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1200 (math-known-realp (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1201 (nth 1 (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1203 (math-defsimplify calcFunc-sqrt
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1204 (math-simplify-sqrt))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1205
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 (defun math-simplify-sqrt ()
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1207 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'frac)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1208 (math-div (list 'calcFunc-sqrt
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1209 (math-mul (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1210 (nth 2 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1211 (nth 2 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1212 (let ((fac (if (math-objectp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1213 (math-squared-factor (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1214 (math-common-constant-factor (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215 (and fac (not (eq fac 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1216 (math-mul (math-normalize (list 'calcFunc-sqrt fac))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1217 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1218 (list 'calcFunc-sqrt
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1219 (math-cancel-common-factor
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1220 (nth 1 math-simplify-expr) fac))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221 (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1222 (or (and (eq (car-safe (nth 1 math-simplify-expr)) '-)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1223 (math-equal-int (nth 1 (nth 1 math-simplify-expr)) 1)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1224 (eq (car-safe (nth 2 (nth 1 math-simplify-expr))) '^)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1225 (math-equal-int (nth 2 (nth 2 (nth 1 math-simplify-expr))) 2)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1226 (or (and (eq (car-safe (nth 1 (nth 2 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 'calcFunc-sin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1228 (list 'calcFunc-cos
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1229 (nth 1 (nth 1 (nth 2 (nth 1 math-simplify-expr))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1230 (and (eq (car-safe (nth 1 (nth 2 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1231 'calcFunc-cos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1232 (list 'calcFunc-sin
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1233 (nth 1 (nth 1 (nth 2
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1234 (nth 1 math-simplify-expr))))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1235 (and (eq (car-safe (nth 1 math-simplify-expr)) '-)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1236 (math-equal-int (nth 2 (nth 1 math-simplify-expr)) 1)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1237 (eq (car-safe (nth 1 (nth 1 math-simplify-expr))) '^)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1238 (math-equal-int (nth 2 (nth 1 (nth 1 math-simplify-expr))) 2)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1239 (and (eq (car-safe (nth 1 (nth 1 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 'calcFunc-cosh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1241 (list 'calcFunc-sinh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1242 (nth 1 (nth 1 (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1243 (and (eq (car-safe (nth 1 math-simplify-expr)) '+)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1244 (let ((a (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1245 (b (nth 2 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1246 (and (or (and (math-equal-int a 1)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1247 (setq a b b (nth 1 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1248 (math-equal-int b 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1249 (eq (car-safe a) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1250 (math-equal-int (nth 2 a) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 (or (and (eq (car-safe (nth 1 a)) 'calcFunc-sinh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1252 (list 'calcFunc-cosh (nth 1 (nth 1 a))))
60076
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1253 (and (eq (car-safe (nth 1 a)) 'calcFunc-csch)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1254 (list 'calcFunc-coth (nth 1 (nth 1 a))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255 (and (eq (car-safe (nth 1 a)) 'calcFunc-tan)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256 (list '/ 1 (list 'calcFunc-cos
60076
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1257 (nth 1 (nth 1 a)))))
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1258 (and (eq (car-safe (nth 1 a)) 'calcFunc-cot)
7796027f64bd Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58646
diff changeset
1259 (list '/ 1 (list 'calcFunc-sin
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1260 (nth 1 (nth 1 a)))))))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1261 (and (eq (car-safe (nth 1 math-simplify-expr)) '^)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1262 (list '^
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1263 (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1264 (math-div (nth 2 (nth 1 math-simplify-expr)) 2)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1265 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-sqrt)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1266 (list '^ (nth 1 (nth 1 math-simplify-expr)) (math-div 1 4)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1267 (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1268 (list (car (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1269 (list 'calcFunc-sqrt (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1270 (list 'calcFunc-sqrt (nth 2 (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1271 (and (memq (car-safe (nth 1 math-simplify-expr)) '(+ -))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1272 (not (math-any-floats (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1273 (let ((f (calcFunc-factors (calcFunc-expand
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1274 (nth 1 math-simplify-expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1275 (and (math-vectorp f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 (or (> (length f) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (> (nth 2 (nth 1 f)) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (let ((out 1) (rest 1) (sums 1) fac pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 (while (setq f (cdr f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1280 (setq fac (nth 1 (car f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1281 pow (nth 2 (car f)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1282 (if (> pow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1283 (setq out (math-mul out (math-pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1284 fac (/ pow 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 pow (% pow 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 (if (> pow 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1287 (if (memq (car-safe fac) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1288 (setq sums (math-mul-thru sums fac))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (setq rest (math-mul rest fac)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1290 (and (not (and (eq out 1) (memq rest '(1 -1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1291 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1292 out
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1293 (list 'calcFunc-sqrt
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1294 (math-mul sums rest))))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1295
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296 ;;; Rather than factoring x into primes, just check for the first ten primes.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1297 (defun math-squared-factor (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1298 (if (Math-integerp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (let ((prsqr '(4 9 25 49 121 169 289 361 529 841))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1300 (fac 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1301 res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1302 (while prsqr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1303 (if (eq (cdr (setq res (math-idivmod x (car prsqr)))) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1304 (setq x (car res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1305 fac (math-mul fac (car prsqr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1306 (setq prsqr (cdr prsqr))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1307 fac)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1308
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1309 (math-defsimplify calcFunc-exp
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1310 (math-simplify-exp (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 (defun math-simplify-exp (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1313 (or (and (eq (car-safe x) 'calcFunc-ln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1314 (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1315 (and math-living-dangerously
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1316 (or (and (eq (car-safe x) 'calcFunc-arcsinh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1317 (math-add (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1318 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319 (math-add (math-sqr (nth 1 x)) 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1320 (and (eq (car-safe x) 'calcFunc-arccosh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1321 (math-add (nth 1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1322 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1323 (math-sub (math-sqr (nth 1 x)) 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1324 (and (eq (car-safe x) 'calcFunc-arctanh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 (math-div (list 'calcFunc-sqrt (math-add 1 (nth 1 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1326 (list 'calcFunc-sqrt (math-sub 1 (nth 1 x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327 (let ((m (math-should-expand-trig x 'exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 (and m (integerp (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (list '^ (list 'calcFunc-exp (nth 1 m)) (car m))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1330 (and calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1331 (math-known-imagp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1332 (let* ((ip (calcFunc-im x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1333 (n (math-linear-in ip '(var pi var-pi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 s c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1335 (and n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1336 (setq s (math-known-sin (car n) (nth 1 n) 120 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1337 (setq c (math-known-sin (car n) (nth 1 n) 120 300))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1338 (list '+ c (list '* s '(var i var-i))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1339
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1340 (math-defsimplify calcFunc-ln
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1341 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-exp)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1342 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1343 (math-known-realp (nth 1 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1344 (nth 1 (nth 1 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1345 (and (eq (car-safe (nth 1 math-simplify-expr)) '^)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1346 (equal (nth 1 (nth 1 math-simplify-expr)) '(var e var-e))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1348 (math-known-realp (nth 2 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1349 (nth 2 (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1350 (and calc-symbolic-mode
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1351 (math-known-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1352 (math-add (list 'calcFunc-ln (math-neg (nth 1 math-simplify-expr)))
47813
eeaba883e50a (calcFunc-ln): In symbolic manipulations,
David Kastrup <dak@gnu.org>
parents: 46272
diff changeset
1353 '(* (var pi var-pi) (var i var-i))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (and calc-symbolic-mode
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1355 (math-known-imagp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1356 (let* ((ip (calcFunc-im (nth 1 math-simplify-expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357 (ips (math-possible-signs ip)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1358 (or (and (memq ips '(4 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1359 (math-add (list 'calcFunc-ln ip)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360 '(/ (* (var pi var-pi) (var i var-i)) 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (and (memq ips '(1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 (math-sub (list 'calcFunc-ln (math-neg ip))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1363 '(/ (* (var pi var-pi) (var i var-i)) 2))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1364
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365 (math-defsimplify ^
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366 (math-simplify-pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1367
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368 (defun math-simplify-pow ()
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1369 (or (and math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1370 (or (and (eq (car-safe (nth 1 math-simplify-expr)) '^)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1371 (list '^
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1372 (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1373 (math-mul (nth 2 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1374 (nth 2 (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1375 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-sqrt)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1376 (list '^
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1377 (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1378 (math-div (nth 2 math-simplify-expr) 2)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1379 (and (memq (car-safe (nth 1 math-simplify-expr)) '(* /))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1380 (list (car (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1381 (list '^ (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1382 (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1383 (list '^ (nth 2 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1384 (nth 2 math-simplify-expr))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1385 (and (math-equal-int (nth 1 math-simplify-expr) 10)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1386 (eq (car-safe (nth 2 math-simplify-expr)) 'calcFunc-log10)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1387 (nth 1 (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1388 (and (equal (nth 1 math-simplify-expr) '(var e var-e))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1389 (math-simplify-exp (nth 2 math-simplify-expr)))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1390 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-exp)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (not math-integrating)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1392 (list 'calcFunc-exp (math-mul (nth 1 (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1393 (nth 2 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1394 (and (equal (nth 1 math-simplify-expr) '(var i var-i))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1395 (math-imaginary-i)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1396 (math-num-integerp (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1397 (let ((x (math-mod (math-trunc (nth 2 math-simplify-expr)) 4)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1398 (cond ((eq x 0) 1)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1399 ((eq x 1) (nth 1 math-simplify-expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1400 ((eq x 2) -1)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1401 ((eq x 3) (math-neg (nth 1 math-simplify-expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1402 (and math-integrating
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1403 (integerp (nth 2 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1404 (>= (nth 2 math-simplify-expr) 2)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1405 (or (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-cos)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1406 (math-mul (math-pow (nth 1 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1407 (- (nth 2 math-simplify-expr) 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1408 (math-sub 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1409 (math-sqr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1410 (list 'calcFunc-sin
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1411 (nth 1 (nth 1 math-simplify-expr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1412 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-cosh)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1413 (math-mul (math-pow (nth 1 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1414 (- (nth 2 math-simplify-expr) 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1415 (math-add 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1416 (math-sqr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1417 (list 'calcFunc-sinh
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1418 (nth 1 (nth 1 math-simplify-expr)))))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1419 (and (eq (car-safe (nth 2 math-simplify-expr)) 'frac)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1420 (Math-ratp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1421 (Math-posp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1422 (if (equal (nth 2 math-simplify-expr) '(frac 1 2))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1423 (list 'calcFunc-sqrt (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1424 (let ((flr (math-floor (nth 2 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1425 (and (not (Math-zerop flr))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1426 (list '* (list '^ (nth 1 math-simplify-expr) flr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1427 (list '^ (nth 1 math-simplify-expr)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1428 (math-sub (nth 2 math-simplify-expr) flr)))))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1429 (and (eq (math-quarter-integer (nth 2 math-simplify-expr)) 2)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1430 (let ((temp (math-simplify-sqrt)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1431 (and temp
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1432 (list '^ temp (math-mul (nth 2 math-simplify-expr) 2)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1433
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1434 (math-defsimplify calcFunc-log10
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1435 (and (eq (car-safe (nth 1 math-simplify-expr)) '^)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1436 (math-equal-int (nth 1 (nth 1 math-simplify-expr)) 10)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1437 (or math-living-dangerously
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1438 (math-known-realp (nth 2 (nth 1 math-simplify-expr))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1439 (nth 2 (nth 1 math-simplify-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1440
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1441
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1442 (math-defsimplify calcFunc-erf
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1443 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1444 (math-neg (list 'calcFunc-erf (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1445 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-conj)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1446 (list 'calcFunc-conj
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1447 (list 'calcFunc-erf (nth 1 (nth 1 math-simplify-expr)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1448
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1449 (math-defsimplify calcFunc-erfc
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1450 (or (and (math-looks-negp (nth 1 math-simplify-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1451 (math-sub 2 (list 'calcFunc-erfc (math-neg (nth 1 math-simplify-expr)))))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1452 (and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-conj)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1453 (list 'calcFunc-conj
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1454 (list 'calcFunc-erfc (nth 1 (nth 1 math-simplify-expr)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1455
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1456
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1457 (defun math-linear-in (expr term &optional always)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1458 (if (math-expr-contains expr term)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1459 (let* ((calc-prefer-frac t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1460 (p (math-is-polynomial expr term 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1461 (and (cdr p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1462 p))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1463 (and always (list expr 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1464
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1465 (defun math-multiple-of (expr term)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1466 (let ((p (math-linear-in expr term)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1467 (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1468 (math-zerop (car p))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1469 (nth 1 p))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1470
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1471 ; not perfect, but it'll do
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1472 (defun math-integer-plus (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1473 (cond ((Math-integerp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1474 (list 0 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1475 ((and (memq (car expr) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1476 (Math-integerp (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1477 (list (if (eq (car expr) '+) (nth 2 expr) (math-neg (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1478 (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1479 ((and (memq (car expr) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1480 (Math-integerp (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1481 (list (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1482 (if (eq (car expr) '+) (nth 2 expr) (math-neg (nth 2 expr)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1483 (t nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1484
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1485 (defun math-is-linear (expr &optional always)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1486 (let ((offset nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1487 (coef nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1488 (if (eq (car-safe expr) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1489 (if (Math-objectp (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1490 (setq offset (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1491 expr (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1492 (if (Math-objectp (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1493 (setq offset (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1494 expr (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1495 (if (eq (car-safe expr) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1496 (if (Math-objectp (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1497 (setq offset (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1498 expr (math-neg (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1499 (if (Math-objectp (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1500 (setq offset (math-neg (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1501 expr (nth 1 expr))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1502 (setq coef (math-is-multiple expr always))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1503 (if offset
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1504 (list offset (or (car coef) 1) (or (nth 1 coef) expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1505 (if coef
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1506 (cons 0 coef)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1507
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1508 (defun math-is-multiple (expr &optional always)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1509 (or (if (eq (car-safe expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1510 (if (Math-objectp (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1511 (list (nth 1 expr) (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1512 (if (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1513 (if (and (Math-objectp (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1514 (not (math-equal-int (nth 1 expr) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1515 (list (nth 1 expr) (math-div 1 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1516 (if (Math-objectp (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1517 (list (math-div 1 (nth 2 expr)) (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1518 (let ((res (math-is-multiple (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1519 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1520 (list (car res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1521 (math-div (nth 2 (nth 1 expr)) (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1522 (setq res (math-is-multiple (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1523 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1524 (list (math-div 1 (car res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1525 (math-div (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1526 (nth 2 (nth 2 expr)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1527 (if (eq (car-safe expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1528 (list -1 (nth 1 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1529 (if (Math-objvecp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1530 (and (eq always 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1531 (list expr 1))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
1532 (and always
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1533 (list 1 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1534
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1535 (defun calcFunc-lin (expr &optional var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1536 (if var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1537 (let ((res (math-linear-in expr var t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1538 (or res (math-reject-arg expr "Linear term expected"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1539 (list 'vec (car res) (nth 1 res) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1540 (let ((res (math-is-linear expr t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1541 (or res (math-reject-arg expr "Linear term expected"))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1542 (cons 'vec res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1543
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1544 (defun calcFunc-linnt (expr &optional var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1545 (if var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1546 (let ((res (math-linear-in expr var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1547 (or res (math-reject-arg expr "Linear term expected"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1548 (list 'vec (car res) (nth 1 res) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1549 (let ((res (math-is-linear expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1550 (or res (math-reject-arg expr "Linear term expected"))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1551 (cons 'vec res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1552
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1553 (defun calcFunc-islin (expr &optional var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1554 (if (and (Math-objvecp expr) (not var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1555 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1556 (calcFunc-lin expr var)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1557 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1558
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1559 (defun calcFunc-islinnt (expr &optional var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1560 (if (Math-objvecp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1561 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1562 (calcFunc-linnt expr var)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1563 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1564
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1565
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1566
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1567
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1568 ;;; Simple operations on expressions.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1569
46272
2406cf2da1d4 Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 41271
diff changeset
1570 ;;; Return number of occurrences of thing in expr, or nil if none.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1571 (defun math-expr-contains-count (expr thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1572 (cond ((equal expr thing) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1573 ((Math-primp expr) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1574 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1575 (let ((num 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1576 (while (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1577 (setq num (+ num (or (math-expr-contains-count
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1578 (car expr) thing) 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1579 (and (> num 0)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1580 num)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1581
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1582 (defun math-expr-contains (expr thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1583 (cond ((equal expr thing) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1584 ((Math-primp expr) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1585 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1586 (while (and (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1587 (not (math-expr-contains (car expr) thing))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1588 expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1589
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1590 ;;; Return non-nil if any variable of thing occurs in expr.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1591 (defun math-expr-depends (expr thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1592 (if (Math-primp thing)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1593 (and (eq (car-safe thing) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1594 (math-expr-contains expr thing))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1595 (while (and (setq thing (cdr thing))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1596 (not (math-expr-depends expr (car thing)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1597 thing))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1598
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1599 ;;; Substitute all occurrences of old for new in expr (non-destructive).
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1600
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1601 ;; The variables math-expr-subst-old and math-expr-subst-new are local
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1602 ;; for math-expr-subst, but used by math-expr-subst-rec.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1603 (defvar math-expr-subst-old)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1604 (defvar math-expr-subst-new)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1605
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1606 (defun math-expr-subst (expr math-expr-subst-old math-expr-subst-new)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1607 (math-expr-subst-rec expr))
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1608
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1609 (defalias 'calcFunc-subst 'math-expr-subst)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1610
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1611 (defun math-expr-subst-rec (expr)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1612 (cond ((equal expr math-expr-subst-old) math-expr-subst-new)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1613 ((Math-primp expr) expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1614 ((memq (car expr) '(calcFunc-deriv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1615 calcFunc-tderiv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1616 (if (= (length expr) 2)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1617 (if (equal (nth 1 expr) math-expr-subst-old)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1618 (append expr (list math-expr-subst-new))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1619 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1620 (list (car expr) (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1621 (math-expr-subst-rec (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1622 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1623 (cons (car expr)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1624 (mapcar 'math-expr-subst-rec (cdr expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1625
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1626 ;;; Various measures of the size of an expression.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1627 (defun math-expr-weight (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1628 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1629 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1630 (let ((w 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1631 (while (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1632 (setq w (+ w (math-expr-weight (car expr)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1633 w)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1634
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1635 (defun math-expr-height (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1636 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1637 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1638 (let ((h 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1639 (while (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1640 (setq h (max h (math-expr-height (car expr)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1641 (1+ h))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1642
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1643
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1644
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1645
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1646 ;;; Polynomial operations (to support the integrator and solve-for).
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1647
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1648 (defun calcFunc-collect (expr base)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1649 (let ((p (math-is-polynomial expr base 50 t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1650 (if (cdr p)
99929
2a48557d7247 (calcFunc-collect): Normalize the coefficients of the
Jay Belanger <jay.p.belanger@gmail.com>
parents: 99335
diff changeset
1651 (math-build-polynomial-expr (mapcar 'math-normalize p) base)
99335
91df9fb880c4 (calcFunc-collect): Return constant polynomial when appropriate.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 94654
diff changeset
1652 (car p))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1653
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1654 ;;; If expr is of the form "a + bx + cx^2 + ...", return the list (a b c ...),
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1655 ;;; else return nil if not in polynomial form. If "loose" (math-is-poly-loose),
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1656 ;;; coefficients may contain x, e.g., sin(x) + cos(x) x^2 is a loose polynomial in x.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1657
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1658 ;; The variables math-is-poly-degree and math-is-poly-loose are local to
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1659 ;; math-is-polynomial, but are used by math-is-poly-rec
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1660 (defvar math-is-poly-degree)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1661 (defvar math-is-poly-loose)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1662
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1663 (defun math-is-polynomial (expr var &optional math-is-poly-degree math-is-poly-loose)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1664 (let* ((math-poly-base-variable (if math-is-poly-loose
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1665 (if (eq math-is-poly-loose 'gen) var '(var XXX XXX))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1666 math-poly-base-variable))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1667 (poly (math-is-poly-rec expr math-poly-neg-powers)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1668 (and (or (null math-is-poly-degree)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1669 (<= (length poly) (1+ math-is-poly-degree)))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1670 poly)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1671
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1672 (defun math-is-poly-rec (expr negpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1673 (math-poly-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1674 (or (cond ((or (equal expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1675 (eq (car-safe expr) '^))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1676 (let ((pow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1677 (expr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1678 (or (equal expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1679 (setq pow (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1680 expr (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1681 (or (eq math-poly-mult-powers 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1682 (setq pow (let ((m (math-is-multiple pow 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1683 (and (eq (car-safe (car m)) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1684 (Math-zerop (nth 1 (car m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1685 (setq m (list (nth 2 (car m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1686 (math-mul (nth 1 m)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1687 '(var i var-i)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1688 (and (if math-poly-mult-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1689 (equal math-poly-mult-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1690 (nth 1 m))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1691 (setq math-poly-mult-powers (nth 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1692 (or (equal expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1693 (eq math-poly-mult-powers 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1694 (car m)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1695 (if (consp pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1696 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1697 (setq pow (math-to-simple-fraction pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1698 (and (eq (car-safe pow) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1699 math-poly-frac-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1700 (equal expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1701 (setq math-poly-frac-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1702 (calcFunc-lcm math-poly-frac-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1703 (nth 2 pow))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1704 (or (memq math-poly-frac-powers '(1 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1705 (setq pow (math-mul pow math-poly-frac-powers)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1706 (if (integerp pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1707 (if (and (= pow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1708 (equal expr var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1709 (list 0 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1710 (if (natnump pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1711 (let ((p1 (if (equal expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1712 (list 0 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1713 (math-is-poly-rec expr nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1714 (n pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1715 (accum (list 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1716 (and p1
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1717 (or (null math-is-poly-degree)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1718 (<= (* (1- (length p1)) n) math-is-poly-degree))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1719 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1720 (while (>= n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1721 (setq accum (math-poly-mul accum p1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1722 n (1- n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1723 accum)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1724 (and negpow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1725 (math-is-poly-rec expr nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1726 (setq math-poly-neg-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1727 (cons (math-pow expr (- pow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1728 math-poly-neg-powers))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1729 (list (list '^ expr pow))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1730 ((Math-objectp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1731 (list expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1732 ((memq (car expr) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1733 (let ((p1 (math-is-poly-rec (nth 1 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1734 (and p1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1735 (let ((p2 (math-is-poly-rec (nth 2 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1736 (and p2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1737 (math-poly-mix p1 1 p2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1738 (if (eq (car expr) '+) 1 -1)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1739 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1740 (mapcar 'math-neg (math-is-poly-rec (nth 1 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1741 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1742 (let ((p1 (math-is-poly-rec (nth 1 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1743 (and p1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1744 (let ((p2 (math-is-poly-rec (nth 2 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1745 (and p2
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1746 (or (null math-is-poly-degree)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1747 (<= (- (+ (length p1) (length p2)) 2)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1748 math-is-poly-degree))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1749 (math-poly-mul p1 p2))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1750 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1751 (and (or (not (math-poly-depends (nth 2 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1752 (and negpow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1753 (math-is-poly-rec (nth 2 expr) nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1754 (setq math-poly-neg-powers
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1755 (cons (nth 2 expr) math-poly-neg-powers))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1756 (not (Math-zerop (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1757 (let ((p1 (math-is-poly-rec (nth 1 expr) negpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1758 (mapcar (function (lambda (x) (math-div x (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1759 p1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1760 ((and (eq (car expr) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1761 (equal var '(var e var-e)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1762 (math-is-poly-rec (list '^ var (nth 1 expr)) negpow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1763 ((and (eq (car expr) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1764 math-poly-frac-powers)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1765 (math-is-poly-rec (list '^ (nth 1 expr) '(frac 1 2)) negpow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1766 (t nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1767 (and (or (not (math-poly-depends expr var))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1768 math-is-poly-loose)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1769 (not (eq (car expr) 'vec))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1770 (list expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1771
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1772 ;;; Check if expr is a polynomial in var; if so, return its degree.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1773 (defun math-polynomial-p (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1774 (cond ((equal expr var) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1775 ((Math-primp expr) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1776 ((memq (car expr) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1777 (let ((p1 (math-polynomial-p (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1778 p2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1779 (and p1 (setq p2 (math-polynomial-p (nth 2 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1780 (max p1 p2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1781 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1782 (let ((p1 (math-polynomial-p (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1783 p2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1784 (and p1 (setq p2 (math-polynomial-p (nth 2 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1785 (+ p1 p2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1786 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1787 (math-polynomial-p (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1788 ((and (eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1789 (not (math-poly-depends (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1790 (math-polynomial-p (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1791 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1792 (natnump (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1793 (let ((p1 (math-polynomial-p (nth 1 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1794 (and p1 (* p1 (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1795 ((math-poly-depends expr var) nil)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1796 (t 0)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1797
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1798 (defun math-poly-depends (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1799 (if math-poly-base-variable
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1800 (math-expr-contains expr math-poly-base-variable)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1801 (math-expr-depends expr var)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1802
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1803 ;;; Find the variable (or sub-expression) which is the base of polynomial expr.
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1804 ;; The variables math-poly-base-const-ok and math-poly-base-pred are
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1805 ;; local to math-polynomial-base, but are used by math-polynomial-base-rec.
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1806 (defvar math-poly-base-const-ok)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1807 (defvar math-poly-base-pred)
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1808
58506
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1809 ;; The variable math-poly-base-top-expr is local to math-polynomial-base,
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1810 ;; but is used by math-polynomial-p1 in calc-poly.el, which is called
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1811 ;; by math-polynomial-base.
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1812
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1813 (defun math-polynomial-base (math-poly-base-top-expr &optional math-poly-base-pred)
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1814 (or math-poly-base-pred
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1815 (setq math-poly-base-pred (function (lambda (base) (math-polynomial-p
58506
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1816 math-poly-base-top-expr base)))))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1817 (or (let ((math-poly-base-const-ok nil))
58506
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1818 (math-polynomial-base-rec math-poly-base-top-expr))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1819 (let ((math-poly-base-const-ok t))
58506
9e42b44110bf Added comment.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58311
diff changeset
1820 (math-polynomial-base-rec math-poly-base-top-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1821
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1822 (defun math-polynomial-base-rec (mpb-expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1823 (and (not (Math-objvecp mpb-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1824 (or (and (memq (car mpb-expr) '(+ - *))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1825 (or (math-polynomial-base-rec (nth 1 mpb-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1826 (math-polynomial-base-rec (nth 2 mpb-expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1827 (and (memq (car mpb-expr) '(/ neg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1828 (math-polynomial-base-rec (nth 1 mpb-expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1829 (and (eq (car mpb-expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1830 (math-polynomial-base-rec (nth 1 mpb-expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1831 (and (eq (car mpb-expr) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1832 (math-polynomial-base-rec '(var e var-e)))
58300
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1833 (and (or math-poly-base-const-ok (math-expr-contains-vars mpb-expr))
7b70b40dbfc7 (calc-poly-div): Made calc-poly-div-remainder a local variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1834 (funcall math-poly-base-pred mpb-expr)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1835 mpb-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1836
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1837 ;;; Return non-nil if expr refers to any variables.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1838 (defun math-expr-contains-vars (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1839 (or (eq (car-safe expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1840 (and (not (Math-primp expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1841 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1842 (while (and (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1843 (not (math-expr-contains-vars (car expr)))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1844 expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1845
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1846 ;;; Simplify a polynomial in list form by stripping off high-end zeros.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1847 ;;; This always leaves the constant part, i.e., nil->nil and nonnil->nonnil.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1848 (defun math-poly-simplify (p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1849 (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1850 (if (Math-zerop (nth (1- (length p)) p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1851 (let ((pp (copy-sequence p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1852 (while (and (cdr pp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1853 (Math-zerop (nth (1- (length pp)) pp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1854 (setcdr (nthcdr (- (length pp) 2) pp) nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1855 pp)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1856 p)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1857
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1858 ;;; Compute ac*a + bc*b for polynomials in list form a, b and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1859 ;;; coefficients ac, bc. Result may be unsimplified.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1860 (defun math-poly-mix (a ac b bc)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1861 (and (or a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1862 (cons (math-add (math-mul (or (car a) 0) ac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1863 (math-mul (or (car b) 0) bc))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1864 (math-poly-mix (cdr a) ac (cdr b) bc))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1865
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1866 (defun math-poly-zerop (a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1867 (or (null a)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1868 (and (null (cdr a)) (Math-zerop (car a)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1869
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1870 ;;; Multiply two polynomials in list form.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1871 (defun math-poly-mul (a b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1872 (and a b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1873 (math-poly-mix b (car a)
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1874 (math-poly-mul (cdr a) (cons 0 b)) 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1875
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1876 ;;; Build an expression from a polynomial list.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1877 (defun math-build-polynomial-expr (p var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1878 (if p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1879 (if (Math-numberp var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1880 (math-with-extra-prec 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1881 (let* ((rp (reverse p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1882 (accum (car rp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1883 (while (setq rp (cdr rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1884 (setq accum (math-add (car rp) (math-mul accum var))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1885 accum))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1886 (let* ((rp (reverse p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1887 (n (1- (length rp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1888 (accum (math-mul (car rp) (math-pow var n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1889 term)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1890 (while (setq rp (cdr rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1891 (setq n (1- n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1892 (or (math-zerop (car rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1893 (setq accum (list (if (math-looks-negp (car rp)) '- '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1894 accum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1895 (math-mul (if (math-looks-negp (car rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1896 (math-neg (car rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1897 (car rp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1898 (math-pow var n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1899 accum))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1900 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1901
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1902
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1903 (defun math-to-simple-fraction (f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1904 (or (and (eq (car-safe f) 'float)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1905 (or (and (>= (nth 2 f) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1906 (math-scale-int (nth 1 f) (nth 2 f)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1907 (and (integerp (nth 1 f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1908 (> (nth 1 f) -1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1909 (< (nth 1 f) 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1910 (math-make-frac (nth 1 f)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1911 (math-scale-int 1 (- (nth 2 f)))))))
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1912 f))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1913
58646
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
1914 (provide 'calc-alg)
5a5ce0d66410 Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58506
diff changeset
1915
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79702
diff changeset
1916 ;; arch-tag: 52e7dcdf-9688-464d-a02b-4bbe789348d0
41040
3e8874c2e70c (calcFunc-esimplify, calcFunc-simplify, calcFunc-subst): Use
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1917 ;;; calc-alg.el ends here