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