Mercurial > emacs
annotate lisp/calc/calc-rules.el @ 60482:29c6b4b182a3
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 07 Mar 2005 11:00:07 +0000 |
parents | c3660f1897f5 |
children | 842c8b2c2940 7e3f621f1dd4 |
rev | line source |
---|---|
41413 | 1 ;;; calc-rules.el --- rules for simplifying algebraic expressions in Calc |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58670
f5725a8f81c8
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
58670
f5725a8f81c8
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
30 |
40785 | 31 (require 'calc-ext) |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-compile-rule-set (name rules) | |
35 (prog2 | |
36 (message "Preparing rule set %s..." name) | |
37 (math-read-plain-expr rules t) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
38 (message "Preparing rule set %s...done" name))) |
40785 | 39 |
40 (defun calc-CommuteRules () | |
41 "CommuteRules" | |
42 (calc-compile-rule-set | |
43 "CommuteRules" "[ | |
44 iterations(1), | |
45 select(plain(a + b)) := select(plain(b + a)), | |
46 select(plain(a - b)) := select(plain((-b) + a)), | |
47 select(plain((1/a) * b)) := select(b / a), | |
48 select(plain(a * b)) := select(b * a), | |
49 select((1/a) / b) := select((1/b) / a), | |
50 select(a / b) := select((1/b) * a), | |
51 select((a^b) ^ c) := select((a^c) ^ b), | |
52 select(log(a, b)) := select(1 / log(b, a)), | |
53 select(plain(a && b)) := select(b && a), | |
54 select(plain(a || b)) := select(b || a), | |
55 select(plain(a = b)) := select(b = a), | |
56 select(plain(a != b)) := select(b != a), | |
57 select(a < b) := select(b > a), | |
58 select(a > b) := select(b < a), | |
59 select(a <= b) := select(b >= a), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
60 select(a >= b) := select(b <= a) ]")) |
40785 | 61 |
62 (defun calc-JumpRules () | |
63 "JumpRules" | |
64 (calc-compile-rule-set | |
65 "JumpRules" "[ | |
66 iterations(1), | |
67 plain(select(x) = y) := 0 = select(-x) + y, | |
68 plain(a + select(x) = y) := a = select(-x) + y, | |
69 plain(a - select(x) = y) := a = select(x) + y, | |
70 plain(select(x) + a = y) := a = select(-x) + y, | |
71 plain(a * select(x) = y) := a = y / select(x), | |
72 plain(a / select(x) = y) := a = select(x) * y, | |
73 plain(select(x) / a = y) := 1/a = y / select(x), | |
74 plain(a ^ select(2) = y) := a = select(sqrt(y)), | |
75 plain(a ^ select(x) = y) := a = y ^ select(1/x), | |
76 plain(select(x) ^ a = y) := a = log(y, select(x)), | |
77 plain(log(a, select(x)) = y) := a = select(x) ^ y, | |
78 plain(log(select(x), a) = y) := a = select(x) ^ (1/y), | |
79 plain(y = select(x)) := y - select(x) = 0, | |
80 plain(y = a + select(x)) := y - select(x) = a, | |
81 plain(y = a - select(x)) := y + select(x) = a, | |
82 plain(y = select(x) + a) := y - select(x) = a, | |
83 plain(y = a * select(x)) := y / select(x) = a, | |
84 plain(y = a / select(x)) := y * select(x) = a, | |
85 plain(y = select(x) / a) := y / select(x) = 1/a, | |
86 plain(y = a ^ select(2)) := select(sqrt(y)) = a, | |
87 plain(y = a ^ select(x)) := y ^ select(1/x) = a, | |
88 plain(y = select(x) ^ a) := log(y, select(x)) = a, | |
89 plain(y = log(a, select(x))) := select(x) ^ y = a, | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
90 plain(y = log(select(x), a)) := select(x) ^ (1/y) = a ]")) |
40785 | 91 |
92 (defun calc-DistribRules () | |
93 "DistribRules" | |
94 (calc-compile-rule-set | |
95 "DistribRules" "[ | |
96 iterations(1), | |
97 x * select(a + b) := x*select(a) + x*b, | |
98 x * select(sum(a,b,c,d)) := sum(x*select(a),b,c,d), | |
99 x / select(a + b) := 1 / (select(a)/x + b/x), | |
100 select(a + b) / x := select(a)/x + b/x, | |
101 sum(select(a),b,c,d) / x := sum(select(a)/x,b,c,d), | |
102 x ^ select(a + b) := x^select(a) * x^b, | |
103 x ^ select(sum(a,b,c,d)) := prod(x^select(a),b,c,d), | |
104 x ^ select(a * b) := (x^a)^select(b), | |
105 x ^ select(a / b) := (x^a)^select(1/b), | |
106 select(a + b) ^ n := select(x) | |
107 :: integer(n) :: n >= 2 | |
108 :: let(x, expandpow(a+b,n)) | |
109 :: quote(matches(x,y+z)), | |
110 select(a + b) ^ x := a*select(a+b)^(x-1) + b*select(a+b)^(x-1), | |
111 select(a * b) ^ x := a^x * select(b)^x, | |
112 select(prod(a,b,c,d)) ^ x := prod(select(a)^x,b,c,d), | |
113 select(a / b) ^ x := select(a)^x / b^x, | |
114 select(- a) ^ x := (-1)^x * select(a)^x, | |
115 plain(-select(a + b)) := select(-a) - b, | |
116 plain(-select(sum(a,b,c,d))) := sum(select(-a),b,c,d), | |
117 plain(-select(a * b)) := select(-a) * b, | |
118 plain(-select(a / b)) := select(-a) / b, | |
119 sqrt(select(a * b)) := sqrt(select(a)) * sqrt(b), | |
120 sqrt(select(prod(a,b,c,d))) := prod(sqrt(select(a)),b,c,d), | |
121 sqrt(select(a / b)) := sqrt(select(a)) / sqrt(b), | |
122 sqrt(select(- a)) := sqrt(-1) sqrt(select(a)), | |
123 exp(select(a + b)) := exp(select(a)) / exp(-b) :: negative(b), | |
124 exp(select(a + b)) := exp(select(a)) * exp(b), | |
125 exp(select(sum(a,b,c,d))) := prod(exp(select(a)),b,c,d), | |
126 exp(select(a * b)) := exp(select(a)) ^ b :: constant(b), | |
127 exp(select(a * b)) := exp(select(a)) ^ b, | |
128 exp(select(a / b)) := exp(select(a)) ^ (1/b), | |
129 ln(select(a * b)) := ln(select(a)) + ln(b), | |
130 ln(select(prod(a,b,c,d))) := sum(ln(select(a)),b,c,d), | |
131 ln(select(a / b)) := ln(select(a)) - ln(b), | |
132 ln(select(a ^ b)) := ln(select(a)) * b, | |
133 log10(select(a * b)) := log10(select(a)) + log10(b), | |
134 log10(select(prod(a,b,c,d))) := sum(log10(select(a)),b,c,d), | |
135 log10(select(a / b)) := log10(select(a)) - log10(b), | |
136 log10(select(a ^ b)) := log10(select(a)) * b, | |
137 log(select(a * b), x) := log(select(a), x) + log(b,x), | |
138 log(select(prod(a,b,c,d)),x) := sum(log(select(a),x),b,c,d), | |
139 log(select(a / b), x) := log(select(a), x) - log(b,x), | |
140 log(select(a ^ b), x) := log(select(a), x) * b, | |
141 log(a, select(b)) := ln(a) / select(ln(b)), | |
142 sin(select(a + b)) := sin(select(a)) cos(b) + cos(a) sin(b), | |
143 sin(select(2 a)) := 2 sin(select(a)) cos(a), | |
144 sin(select(n a)) := 2sin((n-1) select(a)) cos(a) - sin((n-2) a) | |
145 :: integer(n) :: n > 2, | |
146 cos(select(a + b)) := cos(select(a)) cos(b) - sin(a) sin(b), | |
147 cos(select(2 a)) := 2 cos(select(a))^2 - 1, | |
148 cos(select(n a)) := 2cos((n-1) select(a)) cos(a) - cos((n-2) a) | |
149 :: integer(n) :: n > 2, | |
150 tan(select(a + b)) := (tan(select(a)) + tan(b)) / | |
151 (1 - tan(a) tan(b)), | |
152 tan(select(2 a)) := 2 tan(select(a)) / (1 - tan(a)^2), | |
153 tan(select(n a)) := (tan((n-1) select(a)) + tan(a)) / | |
154 (1 - tan((n-1) a) tan(a)) | |
155 :: integer(n) :: n > 2, | |
60080
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
156 cot(select(a + b)) := (cot(select(a)) cot(b) - 1) / |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
157 (cot(a) + cot(b)), |
40785 | 158 sinh(select(a + b)) := sinh(select(a)) cosh(b) + cosh(a) sinh(b), |
159 cosh(select(a + b)) := cosh(select(a)) cosh(b) + sinh(a) sinh(b), | |
160 tanh(select(a + b)) := (tanh(select(a)) + tanh(b)) / | |
161 (1 + tanh(a) tanh(b)), | |
60080
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
162 coth(select(a + b)) := (coth(select(a)) coth(b) + 1) / |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
163 (coth(a) + coth(b)), |
40785 | 164 x && select(a || b) := (x && select(a)) || (x && b), |
165 select(a || b) && x := (select(a) && x) || (b && x), | |
166 ! select(a && b) := (!a) || (!b), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
167 ! select(a || b) := (!a) && (!b) ]")) |
40785 | 168 |
169 (defun calc-MergeRules () | |
170 "MergeRules" | |
171 (calc-compile-rule-set | |
172 "MergeRules" "[ | |
173 iterations(1), | |
174 (x*opt(a)) + select(x*b) := x * (a + select(b)), | |
175 (x*opt(a)) - select(x*b) := x * (a - select(b)), | |
176 sum(select(x)*a,b,c,d) := x * sum(select(a),b,c,d), | |
177 (a/x) + select(b/x) := (a + select(b)) / x, | |
178 (a/x) - select(b/x) := (a - select(b)) / x, | |
179 sum(a/select(x),b,c,d) := sum(select(a),b,c,d) / x, | |
180 (a/opt(b)) + select(c/d) := ((select(a)*d) + (b*c)) / (b*d), | |
181 (a/opt(b)) - select(c/d) := ((select(a)*d) - (b*c)) / (b*d), | |
182 (x^opt(a)) * select(x^b) := x ^ (a + select(b)), | |
183 (x^opt(a)) / select(x^b) := x ^ (a - select(b)), | |
184 select(x^a) / (x^opt(b)) := x ^ (select(a) - b), | |
185 prod(select(x)^a,b,c,d) := x ^ sum(select(a),b,c,d), | |
186 select(x^a) / (x^opt(b)) := x ^ (select(a) - b), | |
187 (a^x) * select(b^x) := select((a * b) ^x), | |
188 (a^x) / select(b^x) := select((b / b) ^ x), | |
189 select(a^x) / (b^x) := select((a / b) ^ x), | |
190 prod(a^select(x),b,c,d) := select(prod(a,b,c,d) ^ x), | |
191 (a^x) * select(b^y) := select((a * b^(y-x)) ^x), | |
192 (a^x) / select(b^y) := select((b / b^(y-x)) ^ x), | |
193 select(a^x) / (b^y) := select((a / b^(y-x)) ^ x), | |
194 select(x^a) ^ b := x ^ select(a * b), | |
195 (x^a) ^ select(b) := x ^ select(a * b), | |
196 select(sqrt(a)) ^ b := select(a ^ (b / 2)), | |
197 sqrt(a) ^ select(b) := select(a ^ (b / 2)), | |
198 sqrt(select(a) ^ b) := select(a ^ (b / 2)), | |
199 sqrt(a ^ select(b)) := select(a ^ (b / 2)), | |
200 sqrt(a) * select(sqrt(b)) := select(sqrt(a * b)), | |
201 sqrt(a) / select(sqrt(b)) := select(sqrt(a / b)), | |
202 select(sqrt(a)) / sqrt(b) := select(sqrt(a / b)), | |
203 prod(select(sqrt(a)),b,c,d) := select(sqrt(prod(a,b,c,d))), | |
204 exp(a) * select(exp(b)) := select(exp(a + b)), | |
205 exp(a) / select(exp(b)) := select(exp(a - b)), | |
206 select(exp(a)) / exp(b) := select(exp(a - b)), | |
207 prod(select(exp(a)),b,c,d) := select(exp(sum(a,b,c,d))), | |
208 select(exp(a)) ^ b := select(exp(a * b)), | |
209 exp(a) ^ select(b) := select(exp(a * b)), | |
210 ln(a) + select(ln(b)) := select(ln(a * b)), | |
211 ln(a) - select(ln(b)) := select(ln(a / b)), | |
212 select(ln(a)) - ln(b) := select(ln(a / b)), | |
213 sum(select(ln(a)),b,c,d) := select(ln(prod(a,b,c,d))), | |
214 b * select(ln(a)) := select(ln(a ^ b)), | |
215 select(b) * ln(a) := select(ln(a ^ b)), | |
216 select(ln(a)) / ln(b) := select(log(a, b)), | |
217 ln(a) / select(ln(b)) := select(log(a, b)), | |
218 select(ln(a)) / b := select(ln(a ^ (1/b))), | |
219 ln(a) / select(b) := select(ln(a ^ (1/b))), | |
220 log10(a) + select(log10(b)) := select(log10(a * b)), | |
221 log10(a) - select(log10(b)) := select(log10(a / b)), | |
222 select(log10(a)) - log10(b) := select(log10(a / b)), | |
223 sum(select(log10(a)),b,c,d) := select(log10(prod(a,b,c,d))), | |
224 b * select(log10(a)) := select(log10(a ^ b)), | |
225 select(b) * log10(a) := select(log10(a ^ b)), | |
226 select(log10(a)) / log10(b) := select(log(a, b)), | |
227 log10(a) / select(log10(b)) := select(log(a, b)), | |
228 select(log10(a)) / b := select(log10(a ^ (1/b))), | |
229 log10(a) / select(b) := select(log10(a ^ (1/b))), | |
230 log(a,x) + select(log(b,x)) := select(log(a * b,x)), | |
231 log(a,x) - select(log(b,x)) := select(log(a / b,x)), | |
232 select(log(a,x)) - log(b,x) := select(log(a / b,x)), | |
233 sum(select(log(a,x)),b,c,d) := select(log(prod(a,b,c,d),x)), | |
234 b * select(log(a,x)) := select(log(a ^ b,x)), | |
235 select(b) * log(a,x) := select(log(a ^ b,x)), | |
236 select(log(a,x)) / log(b,x) := select(log(a, b)), | |
237 log(a,x) / select(log(b,x)) := select(log(a, b)), | |
238 select(log(a,x)) / b := select(log(a ^ (1/b),x)), | |
239 log(a,x) / select(b) := select(log(a ^ (1/b),x)), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
240 select(x && a) || (x && opt(b)) := x && (select(a) || b) ]")) |
40785 | 241 |
242 (defun calc-NegateRules () | |
243 "NegateRules" | |
244 (calc-compile-rule-set | |
245 "NegateRules" "[ | |
246 iterations(1), | |
247 a + select(x) := a - select(-x), | |
248 a - select(x) := a + select(-x), | |
249 sum(select(x),b,c,d) := -sum(select(-x),b,c,d), | |
250 a * select(x) := -a * select(-x), | |
251 a / select(x) := -a / select(-x), | |
252 select(x) / a := -select(-x) / a, | |
253 prod(select(x),b,c,d) := (-1)^(d-c+1) * prod(select(-x),b,c,d), | |
254 select(x) ^ n := select(-x) ^ a :: integer(n) :: n%2 = 0, | |
255 select(x) ^ n := -(select(-x) ^ a) :: integer(n) :: n%2 = 1, | |
256 select(x) ^ a := (-select(-x)) ^ a, | |
257 a ^ select(x) := (1 / a)^select(-x), | |
258 abs(select(x)) := abs(select(-x)), | |
259 i sqrt(select(x)) := -sqrt(select(-x)), | |
260 sqrt(select(x)) := i sqrt(select(-x)), | |
261 re(select(x)) := -re(select(-x)), | |
262 im(select(x)) := -im(select(-x)), | |
263 conj(select(x)) := -conj(select(-x)), | |
264 trunc(select(x)) := -trunc(select(-x)), | |
265 round(select(x)) := -round(select(-x)), | |
266 floor(select(x)) := -ceil(select(-x)), | |
267 ceil(select(x)) := -floor(select(-x)), | |
268 ftrunc(select(x)) := -ftrunc(select(-x)), | |
269 fround(select(x)) := -fround(select(-x)), | |
270 ffloor(select(x)) := -fceil(select(-x)), | |
271 fceil(select(x)) := -ffloor(select(-x)), | |
272 exp(select(x)) := 1 / exp(select(-x)), | |
273 sin(select(x)) := -sin(select(-x)), | |
274 cos(select(x)) := cos(select(-x)), | |
275 tan(select(x)) := -tan(select(-x)), | |
60080
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
276 sec(select(x)) := sec(select(-x)), |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
277 csc(select(x)) := -csc(select(-x)), |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
278 cot(select(x)) := -cot(select(-x)), |
40785 | 279 arcsin(select(x)) := -arcsin(select(-x)), |
280 arccos(select(x)) := 4 arctan(1) - arccos(select(-x)), | |
281 arctan(select(x)) := -arctan(select(-x)), | |
282 sinh(select(x)) := -sinh(select(-x)), | |
283 cosh(select(x)) := cosh(select(-x)), | |
284 tanh(select(x)) := -tanh(select(-x)), | |
60080
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
285 sech(select(x)) := sech(select(-x)), |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
286 csch(select(x)) := -csch(select(-x)), |
c3660f1897f5
(calc-DistribRules, calc-NegateRules): Add rules.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58670
diff
changeset
|
287 coth(select(x)) := -coth(select(-x)), |
40785 | 288 arcsinh(select(x)) := -arcsinh(select(-x)), |
289 arctanh(select(x)) := -arctanh(select(-x)), | |
290 select(x) = a := select(-x) = -a, | |
291 select(x) != a := select(-x) != -a, | |
292 select(x) < a := select(-x) > -a, | |
293 select(x) > a := select(-x) < -a, | |
294 select(x) <= a := select(-x) >= -a, | |
295 select(x) >= a := select(-x) <= -a, | |
296 a < select(x) := -a > select(-x), | |
297 a > select(x) := -a < select(-x), | |
298 a <= select(x) := -a >= select(-x), | |
299 a >= select(x) := -a <= select(-x), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
300 select(x) := -select(-x) ]")) |
40785 | 301 |
302 (defun calc-InvertRules () | |
303 "InvertRules" | |
304 (calc-compile-rule-set | |
305 "InvertRules" "[ | |
306 iterations(1), | |
307 a * select(x) := a / select(1/x), | |
308 a / select(x) := a * select(1/x), | |
309 select(x) / a := 1 / (select(1/x) a), | |
310 prod(select(x),b,c,d) := 1 / prod(select(1/x),b,c,d), | |
311 abs(select(x)) := 1 / abs(select(1/x)), | |
312 sqrt(select(x)) := 1 / sqrt(select(1/x)), | |
313 ln(select(x)) := -ln(select(1/x)), | |
314 log10(select(x)) := -log10(select(1/x)), | |
315 log(select(x), a) := -log(select(1/x), a), | |
316 log(a, select(x)) := -log(a, select(1/x)), | |
317 arctan(select(x)) := simplify(2 arctan(1))-arctan(select(1/x)), | |
318 select(x) = a := select(1/x) = 1/a, | |
319 select(x) != a := select(1/x) != 1/a, | |
320 select(x) < a := select(1/x) > 1/a, | |
321 select(x) > a := select(1/x) < 1/a, | |
322 select(x) <= a := select(1/x) >= 1/a, | |
323 select(x) >= a := select(1/x) <= 1/a, | |
324 a < select(x) := 1/a > select(1/x), | |
325 a > select(x) := 1/a < select(1/x), | |
326 a <= select(x) := 1/a >= select(1/x), | |
327 a >= select(x) := 1/a <= select(1/x), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
328 select(x) := 1 / select(1/x) ]")) |
40785 | 329 |
330 | |
331 (defun calc-FactorRules () | |
332 "FactorRules" | |
333 (calc-compile-rule-set | |
334 "FactorRules" "[ | |
335 thecoefs(x, [z, a+b, c]) := thefactors(x, [d x + d a/c, (c/d) x + (b/d)]) | |
336 :: z = a b/c :: let(d := pgcd(pcont(c), pcont(b))), | |
337 thecoefs(x, [z, a, c]) := thefactors(x, [(r x + a/(2 r))^2]) | |
338 :: z = (a/2)^2/c :: let(r := esimplify(sqrt(c))) | |
339 :: !matches(r, sqrt(rr)), | |
340 thecoefs(x, [z, 0, c]) := thefactors(x, [rc x + rz, rc x - rz]) | |
341 :: negative(z) | |
342 :: let(rz := esimplify(sqrt(-z))) :: !matches(rz, sqrt(rzz)) | |
343 :: let(rc := esimplify(sqrt(c))) :: !matches(rc, sqrt(rcc)), | |
344 thecoefs(x, [z, 0, c]) := thefactors(x, [rz + rc x, rz - rc x]) | |
345 :: negative(c) | |
346 :: let(rz := esimplify(sqrt(z))) :: !matches(rz, sqrt(rzz)) | |
347 :: let(rc := esimplify(sqrt(-c))) :: !matches(rc, sqrt(rcc)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
348 ]")) |
40785 | 349 ;;(setq var-FactorRules 'calc-FactorRules) |
350 | |
351 | |
352 (defun calc-IntegAfterRules () | |
353 "IntegAfterRules" | |
354 (calc-compile-rule-set | |
355 "IntegAfterRules" "[ | |
356 opt(a) ln(x) + opt(b) ln(y) := 2 a esimplify(arctanh(x-1)) | |
357 :: a + b = 0 :: nrat(x + y) = 2 || nrat(x - y) = 2, | |
358 a * (b + c) := a b + a c :: constant(a) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
359 ]")) |
40785 | 360 |
361 ;;(setq var-IntegAfterRules 'calc-IntegAfterRules) | |
362 | |
363 | |
364 (defun calc-FitRules () | |
365 "FitRules" | |
366 (calc-compile-rule-set | |
367 "FitRules" "[ | |
368 | |
369 schedule(1,2,3,4), | |
370 iterations(inf), | |
371 | |
372 phase(1), | |
373 e^x := exp(x), | |
374 x^y := exp(y ln(x)) :: !istrue(constant(y)), | |
375 x/y := x fitinv(y), | |
376 fitinv(x y) := fitinv(x) fitinv(y), | |
377 exp(a) exp(b) := exp(a + b), | |
378 a exp(b) := exp(ln(a) + b) :: !hasfitvars(a), | |
379 fitinv(exp(a)) := exp(-a), | |
380 ln(a b) := ln(a) + ln(b), | |
381 ln(fitinv(a)) := -ln(a), | |
382 log10(a b) := log10(a) + log10(b), | |
383 log10(fitinv(a)) := -log10(a), | |
384 log(a,b) := ln(a)/ln(b), | |
385 ln(exp(a)) := a, | |
386 a*(b+c) := a*b + a*c, | |
387 (a+b)^n := x :: integer(n) :: n >= 2 | |
388 :: let(x, expandpow(a+b,n)) | |
389 :: quote(matches(x,y+z)), | |
390 | |
391 phase(1,2), | |
392 fitmodel(y = x) := fitmodel(0, y - x), | |
393 fitmodel(y, x+c) := fitmodel(y-c, x) :: !hasfitparams(c), | |
394 fitmodel(y, x c) := fitmodel(y/c, x) :: !hasfitparams(c), | |
395 fitmodel(y, x/(c opt(d))) := fitmodel(y c, x/d) :: !hasfitparams(c), | |
396 fitmodel(y, apply(f,[x])) := fitmodel(yy, x) | |
397 :: hasfitparams(x) | |
398 :: let(FTemp() = yy, | |
399 solve(apply(f,[FTemp()]) = y, | |
400 FTemp())), | |
401 fitmodel(y, apply(f,[x,c])) := fitmodel(yy, x) | |
402 :: !hasfitparams(c) | |
403 :: let(FTemp() = yy, | |
404 solve(apply(f,[FTemp(),c]) = y, | |
405 FTemp())), | |
406 fitmodel(y, apply(f,[c,x])) := fitmodel(yy, x) | |
407 :: !hasfitparams(c) | |
408 :: let(FTemp() = yy, | |
409 solve(apply(f,[c,FTemp()]) = y, | |
410 FTemp())), | |
411 | |
412 phase(2,3), | |
413 fitmodel(y, x) := fitsystem(y, [], [], fitpart(1,1,x)), | |
414 fitpart(a,b,plain(x + y)) := fitpart(a,b,x) + fitpart(a,b,y), | |
415 fitpart(a,b,plain(x - y)) := fitpart(a,b,x) + fitpart(-a,b,y), | |
416 fitpart(a,b,plain(-x)) := fitpart(-a,b,x), | |
417 fitpart(a,b,x opt(c)) := fitpart(a,x b,c) :: !hasfitvars(x), | |
418 fitpart(a,x opt(b),c) := fitpart(x a,b,c) :: !hasfitparams(x), | |
419 fitpart(a,x y + x opt(z),c) := fitpart(a,x*(y+z),c), | |
420 fitpart(a,b,c) := fitpart2(a,b,c), | |
421 | |
422 phase(3), | |
423 fitpart2(a1,b1,x) + fitpart2(a2,b2,x) := fitpart(1, a1 b1 + a2 b2, x), | |
424 fitpart2(a1,x,c1) + fitpart2(a2,x,c2) := fitpart2(1, x, a1 c1 + a2 c2), | |
425 | |
426 phase(4), | |
427 fitinv(x) := 1 / x, | |
428 exp(x + ln(y)) := y exp(x), | |
429 exp(x ln(y)) := y^x, | |
430 ln(x) + ln(y) := ln(x y), | |
431 ln(x) - ln(y) := ln(x/y), | |
432 x*y + x*z := x*(y+z), | |
433 fitsystem(y, xv, pv, fitpart2(a,fitparam(b),c) + opt(d)) | |
434 := fitsystem(y, rcons(xv, a c), | |
435 rcons(pv, fitdummy(b) = fitparam(b)), d) | |
436 :: b = vlen(pv)+1, | |
437 fitsystem(y, xv, pv, fitpart2(a,b,c) + opt(d)) | |
438 := fitsystem(y, rcons(xv, a c), | |
439 rcons(pv, fitdummy(vlen(pv)+1) = b), d), | |
440 fitsystem(y, xv, pv, 0) := fitsystem(y, xv, cons(fvh,fvt)) | |
441 :: !hasfitparams(xv) | |
442 :: let(cons(fvh,fvt), | |
443 solve(pv, table(fitparam(j), j, 1, | |
444 hasfitparams(pv)))), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
445 fitparam(n) = x := x ]")) |
40785 | 446 |
58670
f5725a8f81c8
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
447 (provide 'calc-rules) |
f5725a8f81c8
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
448 |
52401 | 449 ;;; arch-tag: 0ed54a52-38f3-4ed7-9ca7-b8ecf8f2febe |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
450 ;;; calc-rules.el ends here |