Mercurial > emacs
annotate lisp/calc/calc-rules.el @ 88988:cd3317b3e1a9
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 15 Aug 2002 02:30:08 +0000 |
parents | df473d700a16 |
children | f4d68f97221e |
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> |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Maintainer: Colin Walters <walters@debian.org> |
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. | |
30 (require 'calc-ext) | |
31 | |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-Need-calc-rules () nil) | |
35 | |
36 | |
37 (defun calc-compile-rule-set (name rules) | |
38 (prog2 | |
39 (message "Preparing rule set %s..." name) | |
40 (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
|
41 (message "Preparing rule set %s...done" name))) |
40785 | 42 |
43 (defun calc-CommuteRules () | |
44 "CommuteRules" | |
45 (calc-compile-rule-set | |
46 "CommuteRules" "[ | |
47 iterations(1), | |
48 select(plain(a + b)) := select(plain(b + a)), | |
49 select(plain(a - b)) := select(plain((-b) + a)), | |
50 select(plain((1/a) * b)) := select(b / a), | |
51 select(plain(a * b)) := select(b * a), | |
52 select((1/a) / b) := select((1/b) / a), | |
53 select(a / b) := select((1/b) * a), | |
54 select((a^b) ^ c) := select((a^c) ^ b), | |
55 select(log(a, b)) := select(1 / log(b, a)), | |
56 select(plain(a && b)) := select(b && a), | |
57 select(plain(a || b)) := select(b || a), | |
58 select(plain(a = b)) := select(b = a), | |
59 select(plain(a != b)) := select(b != a), | |
60 select(a < b) := select(b > a), | |
61 select(a > b) := select(b < a), | |
62 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
|
63 select(a >= b) := select(b <= a) ]")) |
40785 | 64 |
65 (defun calc-JumpRules () | |
66 "JumpRules" | |
67 (calc-compile-rule-set | |
68 "JumpRules" "[ | |
69 iterations(1), | |
70 plain(select(x) = y) := 0 = select(-x) + y, | |
71 plain(a + select(x) = y) := a = select(-x) + y, | |
72 plain(a - select(x) = y) := a = select(x) + y, | |
73 plain(select(x) + a = y) := a = select(-x) + y, | |
74 plain(a * select(x) = y) := a = y / select(x), | |
75 plain(a / select(x) = y) := a = select(x) * y, | |
76 plain(select(x) / a = y) := 1/a = y / select(x), | |
77 plain(a ^ select(2) = y) := a = select(sqrt(y)), | |
78 plain(a ^ select(x) = y) := a = y ^ select(1/x), | |
79 plain(select(x) ^ a = y) := a = log(y, select(x)), | |
80 plain(log(a, select(x)) = y) := a = select(x) ^ y, | |
81 plain(log(select(x), a) = y) := a = select(x) ^ (1/y), | |
82 plain(y = select(x)) := y - select(x) = 0, | |
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) = a, | |
86 plain(y = a * select(x)) := y / select(x) = a, | |
87 plain(y = a / select(x)) := y * select(x) = a, | |
88 plain(y = select(x) / a) := y / select(x) = 1/a, | |
89 plain(y = a ^ select(2)) := select(sqrt(y)) = a, | |
90 plain(y = a ^ select(x)) := y ^ select(1/x) = a, | |
91 plain(y = select(x) ^ a) := log(y, select(x)) = a, | |
92 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
|
93 plain(y = log(select(x), a)) := select(x) ^ (1/y) = a ]")) |
40785 | 94 |
95 (defun calc-DistribRules () | |
96 "DistribRules" | |
97 (calc-compile-rule-set | |
98 "DistribRules" "[ | |
99 iterations(1), | |
100 x * select(a + b) := x*select(a) + x*b, | |
101 x * select(sum(a,b,c,d)) := sum(x*select(a),b,c,d), | |
102 x / select(a + b) := 1 / (select(a)/x + b/x), | |
103 select(a + b) / x := select(a)/x + b/x, | |
104 sum(select(a),b,c,d) / x := sum(select(a)/x,b,c,d), | |
105 x ^ select(a + b) := x^select(a) * x^b, | |
106 x ^ select(sum(a,b,c,d)) := prod(x^select(a),b,c,d), | |
107 x ^ select(a * b) := (x^a)^select(b), | |
108 x ^ select(a / b) := (x^a)^select(1/b), | |
109 select(a + b) ^ n := select(x) | |
110 :: integer(n) :: n >= 2 | |
111 :: let(x, expandpow(a+b,n)) | |
112 :: quote(matches(x,y+z)), | |
113 select(a + b) ^ x := a*select(a+b)^(x-1) + b*select(a+b)^(x-1), | |
114 select(a * b) ^ x := a^x * select(b)^x, | |
115 select(prod(a,b,c,d)) ^ x := prod(select(a)^x,b,c,d), | |
116 select(a / b) ^ x := select(a)^x / b^x, | |
117 select(- a) ^ x := (-1)^x * select(a)^x, | |
118 plain(-select(a + b)) := select(-a) - b, | |
119 plain(-select(sum(a,b,c,d))) := sum(select(-a),b,c,d), | |
120 plain(-select(a * b)) := select(-a) * b, | |
121 plain(-select(a / b)) := select(-a) / b, | |
122 sqrt(select(a * b)) := sqrt(select(a)) * sqrt(b), | |
123 sqrt(select(prod(a,b,c,d))) := prod(sqrt(select(a)),b,c,d), | |
124 sqrt(select(a / b)) := sqrt(select(a)) / sqrt(b), | |
125 sqrt(select(- a)) := sqrt(-1) sqrt(select(a)), | |
126 exp(select(a + b)) := exp(select(a)) / exp(-b) :: negative(b), | |
127 exp(select(a + b)) := exp(select(a)) * exp(b), | |
128 exp(select(sum(a,b,c,d))) := prod(exp(select(a)),b,c,d), | |
129 exp(select(a * b)) := exp(select(a)) ^ b :: constant(b), | |
130 exp(select(a * b)) := exp(select(a)) ^ b, | |
131 exp(select(a / b)) := exp(select(a)) ^ (1/b), | |
132 ln(select(a * b)) := ln(select(a)) + ln(b), | |
133 ln(select(prod(a,b,c,d))) := sum(ln(select(a)),b,c,d), | |
134 ln(select(a / b)) := ln(select(a)) - ln(b), | |
135 ln(select(a ^ b)) := ln(select(a)) * b, | |
136 log10(select(a * b)) := log10(select(a)) + log10(b), | |
137 log10(select(prod(a,b,c,d))) := sum(log10(select(a)),b,c,d), | |
138 log10(select(a / b)) := log10(select(a)) - log10(b), | |
139 log10(select(a ^ b)) := log10(select(a)) * b, | |
140 log(select(a * b), x) := log(select(a), x) + log(b,x), | |
141 log(select(prod(a,b,c,d)),x) := sum(log(select(a),x),b,c,d), | |
142 log(select(a / b), x) := log(select(a), x) - log(b,x), | |
143 log(select(a ^ b), x) := log(select(a), x) * b, | |
144 log(a, select(b)) := ln(a) / select(ln(b)), | |
145 sin(select(a + b)) := sin(select(a)) cos(b) + cos(a) sin(b), | |
146 sin(select(2 a)) := 2 sin(select(a)) cos(a), | |
147 sin(select(n a)) := 2sin((n-1) select(a)) cos(a) - sin((n-2) a) | |
148 :: integer(n) :: n > 2, | |
149 cos(select(a + b)) := cos(select(a)) cos(b) - sin(a) sin(b), | |
150 cos(select(2 a)) := 2 cos(select(a))^2 - 1, | |
151 cos(select(n a)) := 2cos((n-1) select(a)) cos(a) - cos((n-2) a) | |
152 :: integer(n) :: n > 2, | |
153 tan(select(a + b)) := (tan(select(a)) + tan(b)) / | |
154 (1 - tan(a) tan(b)), | |
155 tan(select(2 a)) := 2 tan(select(a)) / (1 - tan(a)^2), | |
156 tan(select(n a)) := (tan((n-1) select(a)) + tan(a)) / | |
157 (1 - tan((n-1) a) tan(a)) | |
158 :: integer(n) :: n > 2, | |
159 sinh(select(a + b)) := sinh(select(a)) cosh(b) + cosh(a) sinh(b), | |
160 cosh(select(a + b)) := cosh(select(a)) cosh(b) + sinh(a) sinh(b), | |
161 tanh(select(a + b)) := (tanh(select(a)) + tanh(b)) / | |
162 (1 + tanh(a) tanh(b)), | |
163 x && select(a || b) := (x && select(a)) || (x && b), | |
164 select(a || b) && x := (select(a) && x) || (b && x), | |
165 ! 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
|
166 ! select(a || b) := (!a) && (!b) ]")) |
40785 | 167 |
168 (defun calc-MergeRules () | |
169 "MergeRules" | |
170 (calc-compile-rule-set | |
171 "MergeRules" "[ | |
172 iterations(1), | |
173 (x*opt(a)) + select(x*b) := x * (a + select(b)), | |
174 (x*opt(a)) - select(x*b) := x * (a - select(b)), | |
175 sum(select(x)*a,b,c,d) := x * sum(select(a),b,c,d), | |
176 (a/x) + select(b/x) := (a + select(b)) / x, | |
177 (a/x) - select(b/x) := (a - select(b)) / x, | |
178 sum(a/select(x),b,c,d) := sum(select(a),b,c,d) / x, | |
179 (a/opt(b)) + select(c/d) := ((select(a)*d) + (b*c)) / (b*d), | |
180 (a/opt(b)) - select(c/d) := ((select(a)*d) - (b*c)) / (b*d), | |
181 (x^opt(a)) * select(x^b) := x ^ (a + select(b)), | |
182 (x^opt(a)) / select(x^b) := x ^ (a - select(b)), | |
183 select(x^a) / (x^opt(b)) := x ^ (select(a) - b), | |
184 prod(select(x)^a,b,c,d) := x ^ sum(select(a),b,c,d), | |
185 select(x^a) / (x^opt(b)) := x ^ (select(a) - b), | |
186 (a^x) * select(b^x) := select((a * b) ^x), | |
187 (a^x) / select(b^x) := select((b / b) ^ x), | |
188 select(a^x) / (b^x) := select((a / b) ^ x), | |
189 prod(a^select(x),b,c,d) := select(prod(a,b,c,d) ^ x), | |
190 (a^x) * select(b^y) := select((a * b^(y-x)) ^x), | |
191 (a^x) / select(b^y) := select((b / b^(y-x)) ^ x), | |
192 select(a^x) / (b^y) := select((a / b^(y-x)) ^ x), | |
193 select(x^a) ^ b := x ^ select(a * b), | |
194 (x^a) ^ select(b) := x ^ select(a * b), | |
195 select(sqrt(a)) ^ b := select(a ^ (b / 2)), | |
196 sqrt(a) ^ select(b) := select(a ^ (b / 2)), | |
197 sqrt(select(a) ^ b) := select(a ^ (b / 2)), | |
198 sqrt(a ^ select(b)) := select(a ^ (b / 2)), | |
199 sqrt(a) * select(sqrt(b)) := select(sqrt(a * b)), | |
200 sqrt(a) / select(sqrt(b)) := select(sqrt(a / b)), | |
201 select(sqrt(a)) / sqrt(b) := select(sqrt(a / b)), | |
202 prod(select(sqrt(a)),b,c,d) := select(sqrt(prod(a,b,c,d))), | |
203 exp(a) * select(exp(b)) := select(exp(a + b)), | |
204 exp(a) / select(exp(b)) := select(exp(a - b)), | |
205 select(exp(a)) / exp(b) := select(exp(a - b)), | |
206 prod(select(exp(a)),b,c,d) := select(exp(sum(a,b,c,d))), | |
207 select(exp(a)) ^ b := select(exp(a * b)), | |
208 exp(a) ^ select(b) := select(exp(a * b)), | |
209 ln(a) + select(ln(b)) := select(ln(a * b)), | |
210 ln(a) - select(ln(b)) := select(ln(a / b)), | |
211 select(ln(a)) - ln(b) := select(ln(a / b)), | |
212 sum(select(ln(a)),b,c,d) := select(ln(prod(a,b,c,d))), | |
213 b * select(ln(a)) := select(ln(a ^ b)), | |
214 select(b) * ln(a) := select(ln(a ^ b)), | |
215 select(ln(a)) / ln(b) := select(log(a, b)), | |
216 ln(a) / select(ln(b)) := select(log(a, b)), | |
217 select(ln(a)) / b := select(ln(a ^ (1/b))), | |
218 ln(a) / select(b) := select(ln(a ^ (1/b))), | |
219 log10(a) + select(log10(b)) := select(log10(a * b)), | |
220 log10(a) - select(log10(b)) := select(log10(a / b)), | |
221 select(log10(a)) - log10(b) := select(log10(a / b)), | |
222 sum(select(log10(a)),b,c,d) := select(log10(prod(a,b,c,d))), | |
223 b * select(log10(a)) := select(log10(a ^ b)), | |
224 select(b) * log10(a) := select(log10(a ^ b)), | |
225 select(log10(a)) / log10(b) := select(log(a, b)), | |
226 log10(a) / select(log10(b)) := select(log(a, b)), | |
227 select(log10(a)) / b := select(log10(a ^ (1/b))), | |
228 log10(a) / select(b) := select(log10(a ^ (1/b))), | |
229 log(a,x) + select(log(b,x)) := select(log(a * b,x)), | |
230 log(a,x) - select(log(b,x)) := select(log(a / b,x)), | |
231 select(log(a,x)) - log(b,x) := select(log(a / b,x)), | |
232 sum(select(log(a,x)),b,c,d) := select(log(prod(a,b,c,d),x)), | |
233 b * select(log(a,x)) := select(log(a ^ b,x)), | |
234 select(b) * log(a,x) := select(log(a ^ b,x)), | |
235 select(log(a,x)) / log(b,x) := select(log(a, b)), | |
236 log(a,x) / select(log(b,x)) := select(log(a, b)), | |
237 select(log(a,x)) / b := select(log(a ^ (1/b),x)), | |
238 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
|
239 select(x && a) || (x && opt(b)) := x && (select(a) || b) ]")) |
40785 | 240 |
241 (defun calc-NegateRules () | |
242 "NegateRules" | |
243 (calc-compile-rule-set | |
244 "NegateRules" "[ | |
245 iterations(1), | |
246 a + select(x) := a - select(-x), | |
247 a - select(x) := a + select(-x), | |
248 sum(select(x),b,c,d) := -sum(select(-x),b,c,d), | |
249 a * select(x) := -a * select(-x), | |
250 a / select(x) := -a / select(-x), | |
251 select(x) / a := -select(-x) / a, | |
252 prod(select(x),b,c,d) := (-1)^(d-c+1) * prod(select(-x),b,c,d), | |
253 select(x) ^ n := select(-x) ^ a :: integer(n) :: n%2 = 0, | |
254 select(x) ^ n := -(select(-x) ^ a) :: integer(n) :: n%2 = 1, | |
255 select(x) ^ a := (-select(-x)) ^ a, | |
256 a ^ select(x) := (1 / a)^select(-x), | |
257 abs(select(x)) := abs(select(-x)), | |
258 i sqrt(select(x)) := -sqrt(select(-x)), | |
259 sqrt(select(x)) := i sqrt(select(-x)), | |
260 re(select(x)) := -re(select(-x)), | |
261 im(select(x)) := -im(select(-x)), | |
262 conj(select(x)) := -conj(select(-x)), | |
263 trunc(select(x)) := -trunc(select(-x)), | |
264 round(select(x)) := -round(select(-x)), | |
265 floor(select(x)) := -ceil(select(-x)), | |
266 ceil(select(x)) := -floor(select(-x)), | |
267 ftrunc(select(x)) := -ftrunc(select(-x)), | |
268 fround(select(x)) := -fround(select(-x)), | |
269 ffloor(select(x)) := -fceil(select(-x)), | |
270 fceil(select(x)) := -ffloor(select(-x)), | |
271 exp(select(x)) := 1 / exp(select(-x)), | |
272 sin(select(x)) := -sin(select(-x)), | |
273 cos(select(x)) := cos(select(-x)), | |
274 tan(select(x)) := -tan(select(-x)), | |
275 arcsin(select(x)) := -arcsin(select(-x)), | |
276 arccos(select(x)) := 4 arctan(1) - arccos(select(-x)), | |
277 arctan(select(x)) := -arctan(select(-x)), | |
278 sinh(select(x)) := -sinh(select(-x)), | |
279 cosh(select(x)) := cosh(select(-x)), | |
280 tanh(select(x)) := -tanh(select(-x)), | |
281 arcsinh(select(x)) := -arcsinh(select(-x)), | |
282 arctanh(select(x)) := -arctanh(select(-x)), | |
283 select(x) = a := select(-x) = -a, | |
284 select(x) != a := select(-x) != -a, | |
285 select(x) < a := select(-x) > -a, | |
286 select(x) > a := select(-x) < -a, | |
287 select(x) <= a := select(-x) >= -a, | |
288 select(x) >= a := select(-x) <= -a, | |
289 a < select(x) := -a > select(-x), | |
290 a > select(x) := -a < select(-x), | |
291 a <= select(x) := -a >= select(-x), | |
292 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
|
293 select(x) := -select(-x) ]")) |
40785 | 294 |
295 (defun calc-InvertRules () | |
296 "InvertRules" | |
297 (calc-compile-rule-set | |
298 "InvertRules" "[ | |
299 iterations(1), | |
300 a * select(x) := a / select(1/x), | |
301 a / select(x) := a * select(1/x), | |
302 select(x) / a := 1 / (select(1/x) a), | |
303 prod(select(x),b,c,d) := 1 / prod(select(1/x),b,c,d), | |
304 abs(select(x)) := 1 / abs(select(1/x)), | |
305 sqrt(select(x)) := 1 / sqrt(select(1/x)), | |
306 ln(select(x)) := -ln(select(1/x)), | |
307 log10(select(x)) := -log10(select(1/x)), | |
308 log(select(x), a) := -log(select(1/x), a), | |
309 log(a, select(x)) := -log(a, select(1/x)), | |
310 arctan(select(x)) := simplify(2 arctan(1))-arctan(select(1/x)), | |
311 select(x) = a := select(1/x) = 1/a, | |
312 select(x) != a := select(1/x) != 1/a, | |
313 select(x) < a := select(1/x) > 1/a, | |
314 select(x) > a := select(1/x) < 1/a, | |
315 select(x) <= a := select(1/x) >= 1/a, | |
316 select(x) >= a := select(1/x) <= 1/a, | |
317 a < select(x) := 1/a > select(1/x), | |
318 a > select(x) := 1/a < select(1/x), | |
319 a <= select(x) := 1/a >= select(1/x), | |
320 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
|
321 select(x) := 1 / select(1/x) ]")) |
40785 | 322 |
323 | |
324 (defun calc-FactorRules () | |
325 "FactorRules" | |
326 (calc-compile-rule-set | |
327 "FactorRules" "[ | |
328 thecoefs(x, [z, a+b, c]) := thefactors(x, [d x + d a/c, (c/d) x + (b/d)]) | |
329 :: z = a b/c :: let(d := pgcd(pcont(c), pcont(b))), | |
330 thecoefs(x, [z, a, c]) := thefactors(x, [(r x + a/(2 r))^2]) | |
331 :: z = (a/2)^2/c :: let(r := esimplify(sqrt(c))) | |
332 :: !matches(r, sqrt(rr)), | |
333 thecoefs(x, [z, 0, c]) := thefactors(x, [rc x + rz, rc x - rz]) | |
334 :: negative(z) | |
335 :: let(rz := esimplify(sqrt(-z))) :: !matches(rz, sqrt(rzz)) | |
336 :: let(rc := esimplify(sqrt(c))) :: !matches(rc, sqrt(rcc)), | |
337 thecoefs(x, [z, 0, c]) := thefactors(x, [rz + rc x, rz - rc x]) | |
338 :: negative(c) | |
339 :: let(rz := esimplify(sqrt(z))) :: !matches(rz, sqrt(rzz)) | |
340 :: 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
|
341 ]")) |
40785 | 342 ;;(setq var-FactorRules 'calc-FactorRules) |
343 | |
344 | |
345 (defun calc-IntegAfterRules () | |
346 "IntegAfterRules" | |
347 (calc-compile-rule-set | |
348 "IntegAfterRules" "[ | |
349 opt(a) ln(x) + opt(b) ln(y) := 2 a esimplify(arctanh(x-1)) | |
350 :: a + b = 0 :: nrat(x + y) = 2 || nrat(x - y) = 2, | |
351 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
|
352 ]")) |
40785 | 353 |
354 ;;(setq var-IntegAfterRules 'calc-IntegAfterRules) | |
355 | |
356 | |
357 (defun calc-FitRules () | |
358 "FitRules" | |
359 (calc-compile-rule-set | |
360 "FitRules" "[ | |
361 | |
362 schedule(1,2,3,4), | |
363 iterations(inf), | |
364 | |
365 phase(1), | |
366 e^x := exp(x), | |
367 x^y := exp(y ln(x)) :: !istrue(constant(y)), | |
368 x/y := x fitinv(y), | |
369 fitinv(x y) := fitinv(x) fitinv(y), | |
370 exp(a) exp(b) := exp(a + b), | |
371 a exp(b) := exp(ln(a) + b) :: !hasfitvars(a), | |
372 fitinv(exp(a)) := exp(-a), | |
373 ln(a b) := ln(a) + ln(b), | |
374 ln(fitinv(a)) := -ln(a), | |
375 log10(a b) := log10(a) + log10(b), | |
376 log10(fitinv(a)) := -log10(a), | |
377 log(a,b) := ln(a)/ln(b), | |
378 ln(exp(a)) := a, | |
379 a*(b+c) := a*b + a*c, | |
380 (a+b)^n := x :: integer(n) :: n >= 2 | |
381 :: let(x, expandpow(a+b,n)) | |
382 :: quote(matches(x,y+z)), | |
383 | |
384 phase(1,2), | |
385 fitmodel(y = x) := fitmodel(0, y - x), | |
386 fitmodel(y, x+c) := fitmodel(y-c, x) :: !hasfitparams(c), | |
387 fitmodel(y, x c) := fitmodel(y/c, x) :: !hasfitparams(c), | |
388 fitmodel(y, x/(c opt(d))) := fitmodel(y c, x/d) :: !hasfitparams(c), | |
389 fitmodel(y, apply(f,[x])) := fitmodel(yy, x) | |
390 :: hasfitparams(x) | |
391 :: let(FTemp() = yy, | |
392 solve(apply(f,[FTemp()]) = y, | |
393 FTemp())), | |
394 fitmodel(y, apply(f,[x,c])) := fitmodel(yy, x) | |
395 :: !hasfitparams(c) | |
396 :: let(FTemp() = yy, | |
397 solve(apply(f,[FTemp(),c]) = y, | |
398 FTemp())), | |
399 fitmodel(y, apply(f,[c,x])) := fitmodel(yy, x) | |
400 :: !hasfitparams(c) | |
401 :: let(FTemp() = yy, | |
402 solve(apply(f,[c,FTemp()]) = y, | |
403 FTemp())), | |
404 | |
405 phase(2,3), | |
406 fitmodel(y, x) := fitsystem(y, [], [], fitpart(1,1,x)), | |
407 fitpart(a,b,plain(x + y)) := fitpart(a,b,x) + fitpart(a,b,y), | |
408 fitpart(a,b,plain(x - y)) := fitpart(a,b,x) + fitpart(-a,b,y), | |
409 fitpart(a,b,plain(-x)) := fitpart(-a,b,x), | |
410 fitpart(a,b,x opt(c)) := fitpart(a,x b,c) :: !hasfitvars(x), | |
411 fitpart(a,x opt(b),c) := fitpart(x a,b,c) :: !hasfitparams(x), | |
412 fitpart(a,x y + x opt(z),c) := fitpart(a,x*(y+z),c), | |
413 fitpart(a,b,c) := fitpart2(a,b,c), | |
414 | |
415 phase(3), | |
416 fitpart2(a1,b1,x) + fitpart2(a2,b2,x) := fitpart(1, a1 b1 + a2 b2, x), | |
417 fitpart2(a1,x,c1) + fitpart2(a2,x,c2) := fitpart2(1, x, a1 c1 + a2 c2), | |
418 | |
419 phase(4), | |
420 fitinv(x) := 1 / x, | |
421 exp(x + ln(y)) := y exp(x), | |
422 exp(x ln(y)) := y^x, | |
423 ln(x) + ln(y) := ln(x y), | |
424 ln(x) - ln(y) := ln(x/y), | |
425 x*y + x*z := x*(y+z), | |
426 fitsystem(y, xv, pv, fitpart2(a,fitparam(b),c) + opt(d)) | |
427 := fitsystem(y, rcons(xv, a c), | |
428 rcons(pv, fitdummy(b) = fitparam(b)), d) | |
429 :: b = vlen(pv)+1, | |
430 fitsystem(y, xv, pv, fitpart2(a,b,c) + opt(d)) | |
431 := fitsystem(y, rcons(xv, a c), | |
432 rcons(pv, fitdummy(vlen(pv)+1) = b), d), | |
433 fitsystem(y, xv, pv, 0) := fitsystem(y, xv, cons(fvh,fvt)) | |
434 :: !hasfitparams(xv) | |
435 :: let(cons(fvh,fvt), | |
436 solve(pv, table(fitparam(j), j, 1, | |
437 hasfitparams(pv)))), | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
438 fitparam(n) = x := x ]")) |
40785 | 439 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
440 ;;; calc-rules.el ends here |