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