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