Mercurial > emacs
annotate lisp/calc/calc-arith.el @ 66594:d39ae3be63d4
(iswitchb-define-mode-map): Re-enabled the toggle-ignore keybinding
(C-a). The author said it had been disabled much earlier due to a
possible incompatibility, but after many months of usage I have
encountered no problems (and it is a rather useful option, especially
for switching to " *temp*").
author | John Wiegley <johnw@newartisans.com> |
---|---|
date | Tue, 01 Nov 2005 07:10:49 +0000 |
parents | 5da715ee89b8 |
children | 2a1202853ff4 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
1 ;;; calc-arith.el --- arithmetic functions for Calc |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49263
diff
changeset
|
2 |
64325
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
5 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
6 ;; Author: David Gillespie <daveg@synaptics.com> |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
7 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc-ext.el. | |
58647
e655efbeebac
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58626
diff
changeset
|
31 |
40785 | 32 (require 'calc-ext) |
33 (require 'calc-macs) | |
34 | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
35 ;;; The following lists are not exhaustive. |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
36 (defvar math-scalar-functions '(calcFunc-det |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
37 calcFunc-cnorm calcFunc-rnorm |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
38 calcFunc-vlen calcFunc-vcount |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
39 calcFunc-vsum calcFunc-vprod |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
40 calcFunc-vmin calcFunc-vmax)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
41 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
42 (defvar math-nonscalar-functions '(vec calcFunc-idn calcFunc-diag |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
43 calcFunc-cvec calcFunc-index |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
44 calcFunc-trn |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
45 | calcFunc-append |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
46 calcFunc-cons calcFunc-rcons |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
47 calcFunc-tail calcFunc-rhead)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
48 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
49 (defvar math-scalar-if-args-functions '(+ - * / neg)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
50 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
51 (defvar math-real-functions '(calcFunc-arg |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
52 calcFunc-re calcFunc-im |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
53 calcFunc-floor calcFunc-ceil |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
54 calcFunc-trunc calcFunc-round |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
55 calcFunc-rounde calcFunc-roundu |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
56 calcFunc-ffloor calcFunc-fceil |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
57 calcFunc-ftrunc calcFunc-fround |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
58 calcFunc-frounde calcFunc-froundu)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
59 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
60 (defvar math-positive-functions '()) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
61 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
62 (defvar math-nonnegative-functions '(calcFunc-cnorm calcFunc-rnorm |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
63 calcFunc-vlen calcFunc-vcount)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
64 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
65 (defvar math-real-scalar-functions '(% calcFunc-idiv calcFunc-abs |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
66 calcFunc-choose calcFunc-perm |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
67 calcFunc-eq calcFunc-neq |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
68 calcFunc-lt calcFunc-gt |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
69 calcFunc-leq calcFunc-geq |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
70 calcFunc-lnot |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
71 calcFunc-max calcFunc-min)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
72 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
73 (defvar math-real-if-arg-functions '(calcFunc-sin calcFunc-cos |
60077
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
74 calcFunc-tan calcFunc-sec |
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
75 calcFunc-csc calcFunc-cot |
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
76 calcFunc-arctan |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
77 calcFunc-sinh calcFunc-cosh |
60077
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
78 calcFunc-tanh calcFunc-sech |
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
79 calcFunc-csch calcFunc-coth |
14957017dad7
(math-real-if-arg-functions): Add functions to list.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58688
diff
changeset
|
80 calcFunc-exp |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
81 calcFunc-gamma calcFunc-fact)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
82 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
83 (defvar math-integer-functions '(calcFunc-idiv |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
84 calcFunc-isqrt calcFunc-ilog |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
85 calcFunc-vlen calcFunc-vcount)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
86 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
87 (defvar math-num-integer-functions '()) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
88 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
89 (defvar math-rounding-functions '(calcFunc-floor |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
90 calcFunc-ceil |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
91 calcFunc-round calcFunc-trunc |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
92 calcFunc-rounde calcFunc-roundu)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
93 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
94 (defvar math-float-rounding-functions '(calcFunc-ffloor |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
95 calcFunc-fceil |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
96 calcFunc-fround calcFunc-ftrunc |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
97 calcFunc-frounde calcFunc-froundu)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
98 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
99 (defvar math-integer-if-args-functions '(+ - * % neg calcFunc-abs |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
100 calcFunc-min calcFunc-max |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
101 calcFunc-choose calcFunc-perm)) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
102 |
40785 | 103 |
104 ;;; Arithmetic. | |
105 | |
106 (defun calc-min (arg) | |
107 (interactive "P") | |
108 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
109 (calc-binary-op "min" 'calcFunc-min arg '(var inf var-inf)))) |
40785 | 110 |
111 (defun calc-max (arg) | |
112 (interactive "P") | |
113 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
114 (calc-binary-op "max" 'calcFunc-max arg '(neg (var inf var-inf))))) |
40785 | 115 |
116 (defun calc-abs (arg) | |
117 (interactive "P") | |
118 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
119 (calc-unary-op "abs" 'calcFunc-abs arg))) |
40785 | 120 |
121 | |
122 (defun calc-idiv (arg) | |
123 (interactive "P") | |
124 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
125 (calc-binary-op "\\" 'calcFunc-idiv arg 1))) |
40785 | 126 |
127 | |
128 (defun calc-floor (arg) | |
129 (interactive "P") | |
130 (calc-slow-wrapper | |
131 (if (calc-is-inverse) | |
132 (if (calc-is-hyperbolic) | |
133 (calc-unary-op "ceil" 'calcFunc-fceil arg) | |
134 (calc-unary-op "ceil" 'calcFunc-ceil arg)) | |
135 (if (calc-is-hyperbolic) | |
136 (calc-unary-op "flor" 'calcFunc-ffloor arg) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
137 (calc-unary-op "flor" 'calcFunc-floor arg))))) |
40785 | 138 |
139 (defun calc-ceiling (arg) | |
140 (interactive "P") | |
141 (calc-invert-func) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
142 (calc-floor arg)) |
40785 | 143 |
144 (defun calc-round (arg) | |
145 (interactive "P") | |
146 (calc-slow-wrapper | |
147 (if (calc-is-inverse) | |
148 (if (calc-is-hyperbolic) | |
149 (calc-unary-op "trnc" 'calcFunc-ftrunc arg) | |
150 (calc-unary-op "trnc" 'calcFunc-trunc arg)) | |
151 (if (calc-is-hyperbolic) | |
152 (calc-unary-op "rond" 'calcFunc-fround arg) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
153 (calc-unary-op "rond" 'calcFunc-round arg))))) |
40785 | 154 |
155 (defun calc-trunc (arg) | |
156 (interactive "P") | |
157 (calc-invert-func) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
158 (calc-round arg)) |
40785 | 159 |
160 (defun calc-mant-part (arg) | |
161 (interactive "P") | |
162 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
163 (calc-unary-op "mant" 'calcFunc-mant arg))) |
40785 | 164 |
165 (defun calc-xpon-part (arg) | |
166 (interactive "P") | |
167 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
168 (calc-unary-op "xpon" 'calcFunc-xpon arg))) |
40785 | 169 |
170 (defun calc-scale-float (arg) | |
171 (interactive "P") | |
172 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
173 (calc-binary-op "scal" 'calcFunc-scf arg))) |
40785 | 174 |
175 (defun calc-abssqr (arg) | |
176 (interactive "P") | |
177 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
178 (calc-unary-op "absq" 'calcFunc-abssqr arg))) |
40785 | 179 |
180 (defun calc-sign (arg) | |
181 (interactive "P") | |
182 (calc-slow-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
183 (calc-unary-op "sign" 'calcFunc-sign arg))) |
40785 | 184 |
185 (defun calc-increment (arg) | |
186 (interactive "p") | |
187 (calc-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
188 (calc-enter-result 1 "incr" (list 'calcFunc-incr (calc-top-n 1) arg)))) |
40785 | 189 |
190 (defun calc-decrement (arg) | |
191 (interactive "p") | |
192 (calc-wrapper | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
193 (calc-enter-result 1 "decr" (list 'calcFunc-decr (calc-top-n 1) arg)))) |
40785 | 194 |
195 | |
196 (defun math-abs-approx (a) | |
197 (cond ((Math-negp a) | |
198 (math-neg a)) | |
199 ((Math-anglep a) | |
200 a) | |
201 ((eq (car a) 'cplx) | |
202 (math-add (math-abs (nth 1 a)) (math-abs (nth 2 a)))) | |
203 ((eq (car a) 'polar) | |
204 (nth 1 a)) | |
205 ((eq (car a) 'sdev) | |
206 (math-abs-approx (nth 1 a))) | |
207 ((eq (car a) 'intv) | |
208 (math-max (math-abs (nth 2 a)) (math-abs (nth 3 a)))) | |
209 ((eq (car a) 'date) | |
210 a) | |
211 ((eq (car a) 'vec) | |
212 (math-reduce-vec 'math-add-abs-approx a)) | |
213 ((eq (car a) 'calcFunc-abs) | |
214 (car a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
215 (t a))) |
40785 | 216 |
217 (defun math-add-abs-approx (a b) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
218 (math-add (math-abs-approx a) (math-abs-approx b))) |
40785 | 219 |
220 | |
221 ;;;; Declarations. | |
222 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
223 (defvar math-decls-cache-tag nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
224 (defvar math-decls-cache nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
225 (defvar math-decls-all nil) |
40785 | 226 |
227 ;;; Math-decls-cache is an a-list where each entry is a list of the form: | |
228 ;;; (VAR TYPES RANGE) | |
229 ;;; where VAR is a variable name (with var- prefix) or function name; | |
230 ;;; TYPES is a list of type symbols (any, int, frac, ...) | |
231 ;;; RANGE is a sorted vector of intervals describing the range. | |
232 | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
233 (defvar math-super-types |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
234 '((int numint rat real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
235 (numint real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
236 (frac rat real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
237 (rat real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
238 (float real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
239 (real number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
240 (number) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
241 (scalar) |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
242 (sqmatrix matrix vector) |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
243 (matrix vector) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
244 (vector) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
245 (const))) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
246 |
40785 | 247 (defun math-setup-declarations () |
248 (or (eq math-decls-cache-tag (calc-var-value 'var-Decls)) | |
249 (let ((p (calc-var-value 'var-Decls)) | |
250 vec type range) | |
251 (setq math-decls-cache-tag p | |
252 math-decls-cache nil) | |
253 (and (eq (car-safe p) 'vec) | |
254 (while (setq p (cdr p)) | |
255 (and (eq (car-safe (car p)) 'vec) | |
256 (setq vec (nth 2 (car p))) | |
257 (condition-case err | |
258 (let ((v (nth 1 (car p)))) | |
259 (setq type nil range nil) | |
260 (or (eq (car-safe vec) 'vec) | |
261 (setq vec (list 'vec vec))) | |
262 (while (and (setq vec (cdr vec)) | |
263 (not (Math-objectp (car vec)))) | |
264 (and (eq (car-safe (car vec)) 'var) | |
265 (let ((st (assq (nth 1 (car vec)) | |
266 math-super-types))) | |
267 (cond (st (setq type (append type st))) | |
268 ((eq (nth 1 (car vec)) 'pos) | |
269 (setq type (append type | |
270 '(real number)) | |
271 range | |
272 '(intv 1 0 (var inf var-inf)))) | |
273 ((eq (nth 1 (car vec)) 'nonneg) | |
274 (setq type (append type | |
275 '(real number)) | |
276 range | |
277 '(intv 3 0 | |
278 (var inf var-inf)))))))) | |
279 (if vec | |
280 (setq type (append type '(real number)) | |
281 range (math-prepare-set (cons 'vec vec)))) | |
282 (setq type (list type range)) | |
283 (or (eq (car-safe v) 'vec) | |
284 (setq v (list 'vec v))) | |
285 (while (setq v (cdr v)) | |
286 (if (or (eq (car-safe (car v)) 'var) | |
287 (not (Math-primp (car v)))) | |
288 (setq math-decls-cache | |
289 (cons (cons (if (eq (car (car v)) 'var) | |
290 (nth 2 (car v)) | |
291 (car (car v))) | |
292 type) | |
293 math-decls-cache))))) | |
294 (error nil))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
295 (setq math-decls-all (assq 'var-All math-decls-cache))))) |
40785 | 296 |
297 (defun math-known-scalarp (a &optional assume-scalar) | |
298 (math-setup-declarations) | |
299 (if (if calc-matrix-mode | |
300 (eq calc-matrix-mode 'scalar) | |
301 assume-scalar) | |
302 (not (math-check-known-matrixp a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
303 (math-check-known-scalarp a))) |
40785 | 304 |
305 (defun math-known-matrixp (a) | |
306 (and (not (Math-scalarp a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
307 (not (math-known-scalarp a t)))) |
40785 | 308 |
65899
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
309 (defun math-known-square-matrixp (a) |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
310 (and (math-known-matrixp a) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
311 (math-check-known-square-matrixp a))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
312 |
40785 | 313 ;;; Try to prove that A is a scalar (i.e., a non-vector). |
314 (defun math-check-known-scalarp (a) | |
315 (cond ((Math-objectp a) t) | |
316 ((memq (car a) math-scalar-functions) | |
317 t) | |
318 ((memq (car a) math-real-scalar-functions) | |
319 t) | |
320 ((memq (car a) math-scalar-if-args-functions) | |
321 (while (and (setq a (cdr a)) | |
322 (math-check-known-scalarp (car a)))) | |
323 (null a)) | |
324 ((eq (car a) '^) | |
325 (math-check-known-scalarp (nth 1 a))) | |
326 ((math-const-var a) t) | |
327 (t | |
328 (let ((decl (if (eq (car a) 'var) | |
329 (or (assq (nth 2 a) math-decls-cache) | |
330 math-decls-all) | |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
331 (assq (car a) math-decls-cache))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
332 val) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
333 (cond |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
334 ((memq 'scalar (nth 1 decl)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
335 t) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
336 ((and (eq (car a) 'var) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
337 (boundp (nth 2 a)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
338 (setq val (symbol-value (nth 2 a)))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
339 (math-check-known-scalarp val)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
340 (t |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
341 nil)))))) |
40785 | 342 |
343 ;;; Try to prove that A is *not* a scalar. | |
344 (defun math-check-known-matrixp (a) | |
345 (cond ((Math-objectp a) nil) | |
346 ((memq (car a) math-nonscalar-functions) | |
347 t) | |
348 ((memq (car a) math-scalar-if-args-functions) | |
349 (while (and (setq a (cdr a)) | |
350 (not (math-check-known-matrixp (car a))))) | |
351 a) | |
352 ((eq (car a) '^) | |
353 (math-check-known-matrixp (nth 1 a))) | |
354 ((math-const-var a) nil) | |
355 (t | |
356 (let ((decl (if (eq (car a) 'var) | |
357 (or (assq (nth 2 a) math-decls-cache) | |
358 math-decls-all) | |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
359 (assq (car a) math-decls-cache))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
360 val) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
361 (cond |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
362 ((memq 'matrix (nth 1 decl)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
363 t) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
364 ((and (eq (car a) 'var) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
365 (boundp (nth 2 a)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
366 (setq val (symbol-value (nth 2 a)))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
367 (math-check-known-matrixp val)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
368 (t |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
369 nil)))))) |
40785 | 370 |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
371 ;;; Given that A is a matrix, try to prove that it is a square matrix. |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
372 (defun math-check-known-square-matrixp (a) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
373 (cond ((math-square-matrixp a) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
374 t) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
375 ((eq (car-safe a) '^) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
376 (math-check-known-square-matrixp (nth 1 a))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
377 (t |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
378 (let ((decl (if (eq (car a) 'var) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
379 (or (assq (nth 2 a) math-decls-cache) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
380 math-decls-all) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
381 (assq (car a) math-decls-cache))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
382 val) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
383 (cond |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
384 ((memq 'sqmatrix (nth 1 decl)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
385 t) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
386 ((and (eq (car a) 'var) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
387 (boundp (nth 2 a)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
388 (setq val (symbol-value (nth 2 a)))) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
389 (math-check-known-square-matrixp val)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
390 ((and (or |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
391 (integerp calc-matrix-mode) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
392 (eq calc-matrix-mode 'sqmatrix)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
393 (eq (car-safe a) 'var)) |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
394 t) |
65993
7e915ad64a71
(math-check-known-square-matrixp): Change order in which value is checked.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65987
diff
changeset
|
395 ((memq 'matrix (nth 1 decl)) |
7e915ad64a71
(math-check-known-square-matrixp): Change order in which value is checked.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65987
diff
changeset
|
396 nil) |
65987
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
397 (t |
16a03d245dee
(math-check-known-scalarp, math-check-known-matrixp): Check the values of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65899
diff
changeset
|
398 nil)))))) |
40785 | 399 |
400 ;;; Try to prove that A is a real (i.e., not complex). | |
401 (defun math-known-realp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
402 (< (math-possible-signs a) 8)) |
40785 | 403 |
404 ;;; Try to prove that A is real and positive. | |
405 (defun math-known-posp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
406 (eq (math-possible-signs a) 4)) |
40785 | 407 |
408 ;;; Try to prove that A is real and negative. | |
409 (defun math-known-negp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
410 (eq (math-possible-signs a) 1)) |
40785 | 411 |
412 ;;; Try to prove that A is real and nonnegative. | |
413 (defun math-known-nonnegp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
414 (memq (math-possible-signs a) '(2 4 6))) |
40785 | 415 |
416 ;;; Try to prove that A is real and nonpositive. | |
417 (defun math-known-nonposp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
418 (memq (math-possible-signs a) '(1 2 3))) |
40785 | 419 |
420 ;;; Try to prove that A is nonzero. | |
421 (defun math-known-nonzerop (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
422 (memq (math-possible-signs a) '(1 4 5 8 9 12 13))) |
40785 | 423 |
424 ;;; Return true if A is negative, or looks negative but we don't know. | |
425 (defun math-guess-if-neg (a) | |
426 (let ((sgn (math-possible-signs a))) | |
427 (if (memq sgn '(1 3)) | |
428 t | |
429 (if (memq sgn '(2 4 6)) | |
430 nil | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
431 (math-looks-negp a))))) |
40785 | 432 |
433 ;;; Find the possible signs of A, assuming A is a number of some kind. | |
434 ;;; Returns an integer with bits: 1 may be negative, | |
435 ;;; 2 may be zero, | |
436 ;;; 4 may be positive, | |
437 ;;; 8 may be nonreal. | |
438 | |
439 (defun math-possible-signs (a &optional origin) | |
440 (cond ((Math-objectp a) | |
441 (if origin (setq a (math-sub a origin))) | |
442 (cond ((Math-posp a) 4) | |
443 ((Math-negp a) 1) | |
444 ((Math-zerop a) 2) | |
445 ((eq (car a) 'intv) | |
58688
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
446 (cond |
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
447 ((math-known-posp (nth 2 a)) 4) |
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
448 ((math-known-negp (nth 3 a)) 1) |
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
449 ((Math-zerop (nth 2 a)) 6) |
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
450 ((Math-zerop (nth 3 a)) 3) |
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
451 (t 7))) |
40785 | 452 ((eq (car a) 'sdev) |
453 (if (math-known-realp (nth 1 a)) 7 15)) | |
454 (t 8))) | |
455 ((memq (car a) '(+ -)) | |
456 (cond ((Math-realp (nth 1 a)) | |
457 (if (eq (car a) '-) | |
458 (math-neg-signs | |
459 (math-possible-signs (nth 2 a) | |
460 (if origin | |
461 (math-add origin (nth 1 a)) | |
462 (nth 1 a)))) | |
463 (math-possible-signs (nth 2 a) | |
464 (if origin | |
465 (math-sub origin (nth 1 a)) | |
466 (math-neg (nth 1 a)))))) | |
467 ((Math-realp (nth 2 a)) | |
468 (let ((org (if (eq (car a) '-) | |
469 (nth 2 a) | |
470 (math-neg (nth 2 a))))) | |
471 (math-possible-signs (nth 1 a) | |
472 (if origin | |
473 (math-add origin org) | |
474 org)))) | |
475 (t | |
476 (let ((s1 (math-possible-signs (nth 1 a) origin)) | |
477 (s2 (math-possible-signs (nth 2 a)))) | |
478 (if (eq (car a) '-) (setq s2 (math-neg-signs s2))) | |
479 (cond ((eq s1 s2) s1) | |
480 ((eq s1 2) s2) | |
481 ((eq s2 2) s1) | |
482 ((>= s1 8) 15) | |
483 ((>= s2 8) 15) | |
484 ((and (eq s1 4) (eq s2 6)) 4) | |
485 ((and (eq s2 4) (eq s1 6)) 4) | |
486 ((and (eq s1 1) (eq s2 3)) 1) | |
487 ((and (eq s2 1) (eq s1 3)) 1) | |
488 (t 7)))))) | |
489 ((eq (car a) 'neg) | |
490 (math-neg-signs (math-possible-signs | |
491 (nth 1 a) | |
492 (and origin (math-neg origin))))) | |
493 ((and origin (Math-zerop origin) (setq origin nil) | |
494 nil)) | |
495 ((and (or (eq (car a) '*) | |
496 (and (eq (car a) '/) origin)) | |
497 (Math-realp (nth 1 a))) | |
498 (let ((s (if (eq (car a) '*) | |
499 (if (Math-zerop (nth 1 a)) | |
500 (math-possible-signs 0 origin) | |
501 (math-possible-signs (nth 2 a) | |
502 (math-div (or origin 0) | |
503 (nth 1 a)))) | |
504 (math-neg-signs | |
505 (math-possible-signs (nth 2 a) | |
506 (math-div (nth 1 a) | |
507 origin)))))) | |
508 (if (Math-negp (nth 1 a)) (math-neg-signs s) s))) | |
509 ((and (memq (car a) '(* /)) (Math-realp (nth 2 a))) | |
510 (let ((s (math-possible-signs (nth 1 a) | |
511 (if (eq (car a) '*) | |
512 (math-mul (or origin 0) (nth 2 a)) | |
513 (math-div (or origin 0) (nth 2 a)))))) | |
514 (if (Math-negp (nth 2 a)) (math-neg-signs s) s))) | |
515 ((eq (car a) 'vec) | |
516 (let ((signs 0)) | |
517 (while (and (setq a (cdr a)) (< signs 15)) | |
518 (setq signs (logior signs (math-possible-signs | |
519 (car a) origin)))) | |
520 signs)) | |
521 (t (let ((sign | |
522 (cond | |
523 ((memq (car a) '(* /)) | |
524 (let ((s1 (math-possible-signs (nth 1 a))) | |
525 (s2 (math-possible-signs (nth 2 a)))) | |
526 (cond ((>= s1 8) 15) | |
527 ((>= s2 8) 15) | |
528 ((and (eq (car a) '/) (memq s2 '(2 3 6 7))) 15) | |
529 (t | |
530 (logior (if (memq s1 '(4 5 6 7)) s2 0) | |
531 (if (memq s1 '(2 3 6 7)) 2 0) | |
532 (if (memq s1 '(1 3 5 7)) | |
533 (math-neg-signs s2) 0)))))) | |
534 ((eq (car a) '^) | |
535 (let ((s1 (math-possible-signs (nth 1 a))) | |
536 (s2 (math-possible-signs (nth 2 a)))) | |
537 (cond ((>= s1 8) 15) | |
538 ((>= s2 8) 15) | |
539 ((eq s1 4) 4) | |
540 ((eq s1 2) (if (eq s2 4) 2 15)) | |
541 ((eq s2 2) (if (memq s1 '(1 5)) 2 15)) | |
542 ((Math-integerp (nth 2 a)) | |
543 (if (math-evenp (nth 2 a)) | |
544 (if (memq s1 '(3 6 7)) 6 4) | |
545 s1)) | |
546 ((eq s1 6) (if (eq s2 4) 6 15)) | |
547 (t 7)))) | |
548 ((eq (car a) '%) | |
549 (let ((s2 (math-possible-signs (nth 2 a)))) | |
550 (cond ((>= s2 8) 7) | |
551 ((eq s2 2) 2) | |
552 ((memq s2 '(4 6)) 6) | |
553 ((memq s2 '(1 3)) 3) | |
554 (t 7)))) | |
555 ((and (memq (car a) '(calcFunc-abs calcFunc-abssqr)) | |
556 (= (length a) 2)) | |
557 (let ((s1 (math-possible-signs (nth 1 a)))) | |
558 (cond ((eq s1 2) 2) | |
559 ((memq s1 '(1 4 5)) 4) | |
560 (t 6)))) | |
561 ((and (eq (car a) 'calcFunc-exp) (= (length a) 2)) | |
562 (let ((s1 (math-possible-signs (nth 1 a)))) | |
563 (if (>= s1 8) | |
564 15 | |
565 (if (or (not origin) (math-negp origin)) | |
566 4 | |
567 (setq origin (math-sub (or origin 0) 1)) | |
568 (if (Math-zerop origin) (setq origin nil)) | |
569 s1)))) | |
570 ((or (and (memq (car a) '(calcFunc-ln calcFunc-log10)) | |
571 (= (length a) 2)) | |
572 (and (eq (car a) 'calcFunc-log) | |
573 (= (length a) 3) | |
574 (math-known-posp (nth 2 a)))) | |
575 (if (math-known-nonnegp (nth 1 a)) | |
576 (math-possible-signs (nth 1 a) 1) | |
577 15)) | |
578 ((and (eq (car a) 'calcFunc-sqrt) (= (length a) 2)) | |
579 (let ((s1 (math-possible-signs (nth 1 a)))) | |
580 (if (memq s1 '(2 4 6)) s1 15))) | |
581 ((memq (car a) math-nonnegative-functions) 6) | |
582 ((memq (car a) math-positive-functions) 4) | |
583 ((memq (car a) math-real-functions) 7) | |
584 ((memq (car a) math-real-scalar-functions) 7) | |
585 ((and (memq (car a) math-real-if-arg-functions) | |
586 (= (length a) 2)) | |
587 (if (math-known-realp (nth 1 a)) 7 15))))) | |
588 (cond (sign | |
589 (if origin | |
590 (+ (logand sign 8) | |
591 (if (Math-posp origin) | |
592 (if (memq sign '(1 2 3 8 9 10 11)) 1 7) | |
593 (if (memq sign '(2 4 6 8 10 12 14)) 4 7))) | |
594 sign)) | |
595 ((math-const-var a) | |
596 (cond ((eq (nth 2 a) 'var-pi) | |
597 (if origin | |
598 (math-possible-signs (math-pi) origin) | |
599 4)) | |
600 ((eq (nth 2 a) 'var-e) | |
601 (if origin | |
602 (math-possible-signs (math-e) origin) | |
603 4)) | |
604 ((eq (nth 2 a) 'var-inf) 4) | |
605 ((eq (nth 2 a) 'var-uinf) 13) | |
606 ((eq (nth 2 a) 'var-i) 8) | |
607 (t 15))) | |
608 (t | |
609 (math-setup-declarations) | |
610 (let ((decl (if (eq (car a) 'var) | |
611 (or (assq (nth 2 a) math-decls-cache) | |
612 math-decls-all) | |
613 (assq (car a) math-decls-cache)))) | |
614 (if (and origin | |
615 (memq 'int (nth 1 decl)) | |
616 (not (Math-num-integerp origin))) | |
617 5 | |
618 (if (nth 2 decl) | |
619 (math-possible-signs (nth 2 decl) origin) | |
620 (if (memq 'real (nth 1 decl)) | |
621 7 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
622 15)))))))))) |
40785 | 623 |
624 (defun math-neg-signs (s1) | |
625 (if (>= s1 8) | |
626 (+ 8 (math-neg-signs (- s1 8))) | |
627 (+ (if (memq s1 '(1 3 5 7)) 4 0) | |
628 (if (memq s1 '(2 3 6 7)) 2 0) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
629 (if (memq s1 '(4 5 6 7)) 1 0)))) |
40785 | 630 |
631 | |
632 ;;; Try to prove that A is an integer. | |
633 (defun math-known-integerp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
634 (eq (math-possible-types a) 1)) |
40785 | 635 |
636 (defun math-known-num-integerp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
637 (<= (math-possible-types a t) 3)) |
40785 | 638 |
639 (defun math-known-imagp (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
640 (= (math-possible-types a) 16)) |
40785 | 641 |
642 | |
643 ;;; Find the possible types of A. | |
644 ;;; Returns an integer with bits: 1 may be integer. | |
645 ;;; 2 may be integer-valued float. | |
646 ;;; 4 may be fraction. | |
647 ;;; 8 may be non-integer-valued float. | |
648 ;;; 16 may be imaginary. | |
649 ;;; 32 may be non-real, non-imaginary. | |
650 ;;; Real infinities count as integers for the purposes of this function. | |
651 (defun math-possible-types (a &optional num) | |
652 (cond ((Math-objectp a) | |
653 (cond ((Math-integerp a) (if num 3 1)) | |
654 ((Math-messy-integerp a) (if num 3 2)) | |
655 ((eq (car a) 'frac) (if num 12 4)) | |
656 ((eq (car a) 'float) (if num 12 8)) | |
657 ((eq (car a) 'intv) | |
658 (if (equal (nth 2 a) (nth 3 a)) | |
659 (math-possible-types (nth 2 a)) | |
660 15)) | |
661 ((eq (car a) 'sdev) | |
662 (if (math-known-realp (nth 1 a)) 15 63)) | |
663 ((eq (car a) 'cplx) | |
664 (if (math-zerop (nth 1 a)) 16 32)) | |
665 ((eq (car a) 'polar) | |
666 (if (or (Math-equal (nth 2 a) (math-quarter-circle nil)) | |
667 (Math-equal (nth 2 a) | |
668 (math-neg (math-quarter-circle nil)))) | |
669 16 48)) | |
670 (t 63))) | |
671 ((eq (car a) '/) | |
672 (let* ((t1 (math-possible-types (nth 1 a) num)) | |
673 (t2 (math-possible-types (nth 2 a) num)) | |
674 (t12 (logior t1 t2))) | |
675 (if (< t12 16) | |
676 (if (> (logand t12 10) 0) | |
677 10 | |
678 (if (or (= t1 4) (= t2 4) calc-prefer-frac) | |
679 5 | |
680 15)) | |
681 (if (< t12 32) | |
682 (if (= t1 16) | |
683 (if (= t2 16) 15 | |
684 (if (< t2 16) 16 31)) | |
685 (if (= t2 16) | |
686 (if (< t1 16) 16 31) | |
687 31)) | |
688 63)))) | |
689 ((memq (car a) '(+ - * %)) | |
690 (let* ((t1 (math-possible-types (nth 1 a) num)) | |
691 (t2 (math-possible-types (nth 2 a) num)) | |
692 (t12 (logior t1 t2))) | |
693 (if (eq (car a) '%) | |
694 (setq t1 (logand t1 15) t2 (logand t2 15) t12 (logand t12 15))) | |
695 (if (< t12 16) | |
696 (let ((mask (if (<= t12 3) | |
697 1 | |
698 (if (and (or (and (<= t1 3) (= (logand t2 3) 0)) | |
699 (and (<= t2 3) (= (logand t1 3) 0))) | |
700 (memq (car a) '(+ -))) | |
701 4 | |
702 5)))) | |
703 (if num | |
704 (* mask 3) | |
705 (logior (if (and (> (logand t1 5) 0) (> (logand t2 5) 0)) | |
706 mask 0) | |
707 (if (> (logand t12 10) 0) | |
708 (* mask 2) 0)))) | |
709 (if (< t12 32) | |
710 (if (eq (car a) '*) | |
711 (if (= t1 16) | |
712 (if (= t2 16) 15 | |
713 (if (< t2 16) 16 31)) | |
714 (if (= t2 16) | |
715 (if (< t1 16) 16 31) | |
716 31)) | |
717 (if (= t12 16) 16 | |
718 (if (or (and (= t1 16) (< t2 16)) | |
719 (and (= t2 16) (< t1 16))) 32 63))) | |
720 63)))) | |
721 ((eq (car a) 'neg) | |
722 (math-possible-types (nth 1 a))) | |
723 ((eq (car a) '^) | |
724 (let* ((t1 (math-possible-types (nth 1 a) num)) | |
725 (t2 (math-possible-types (nth 2 a) num)) | |
726 (t12 (logior t1 t2))) | |
727 (if (and (<= t2 3) (math-known-nonnegp (nth 2 a)) (< t1 16)) | |
728 (let ((mask (logior (if (> (logand t1 3) 0) 1 0) | |
729 (logand t1 4) | |
730 (if (> (logand t1 12) 0) 5 0)))) | |
731 (if num | |
732 (* mask 3) | |
733 (logior (if (and (> (logand t1 5) 0) (> (logand t2 5) 0)) | |
734 mask 0) | |
735 (if (> (logand t12 10) 0) | |
736 (* mask 2) 0)))) | |
737 (if (and (math-known-nonnegp (nth 1 a)) | |
738 (math-known-posp (nth 2 a))) | |
739 15 | |
740 63)))) | |
741 ((eq (car a) 'calcFunc-sqrt) | |
742 (let ((t1 (math-possible-signs (nth 1 a)))) | |
743 (logior (if (> (logand t1 2) 0) 3 0) | |
744 (if (> (logand t1 1) 0) 16 0) | |
745 (if (> (logand t1 4) 0) 15 0) | |
746 (if (> (logand t1 8) 0) 32 0)))) | |
747 ((eq (car a) 'vec) | |
748 (let ((types 0)) | |
749 (while (and (setq a (cdr a)) (< types 63)) | |
750 (setq types (logior types (math-possible-types (car a) t)))) | |
751 types)) | |
752 ((or (memq (car a) math-integer-functions) | |
753 (and (memq (car a) math-rounding-functions) | |
754 (math-known-nonnegp (or (nth 2 a) 0)))) | |
755 1) | |
756 ((or (memq (car a) math-num-integer-functions) | |
757 (and (memq (car a) math-float-rounding-functions) | |
758 (math-known-nonnegp (or (nth 2 a) 0)))) | |
759 2) | |
760 ((eq (car a) 'calcFunc-frac) | |
761 5) | |
762 ((and (eq (car a) 'calcFunc-float) (= (length a) 2)) | |
763 (let ((t1 (math-possible-types (nth 1 a)))) | |
764 (logior (if (> (logand t1 3) 0) 2 0) | |
765 (if (> (logand t1 12) 0) 8 0) | |
766 (logand t1 48)))) | |
767 ((and (memq (car a) '(calcFunc-abs calcFunc-abssqr)) | |
768 (= (length a) 2)) | |
769 (let ((t1 (math-possible-types (nth 1 a)))) | |
770 (if (>= t1 16) | |
771 15 | |
772 t1))) | |
773 ((math-const-var a) | |
774 (cond ((memq (nth 2 a) '(var-e var-pi var-phi var-gamma)) 8) | |
775 ((eq (nth 2 a) 'var-inf) 1) | |
776 ((eq (nth 2 a) 'var-i) 16) | |
777 (t 63))) | |
778 (t | |
779 (math-setup-declarations) | |
780 (let ((decl (if (eq (car a) 'var) | |
781 (or (assq (nth 2 a) math-decls-cache) | |
782 math-decls-all) | |
783 (assq (car a) math-decls-cache)))) | |
784 (cond ((memq 'int (nth 1 decl)) | |
785 1) | |
786 ((memq 'numint (nth 1 decl)) | |
787 3) | |
788 ((memq 'frac (nth 1 decl)) | |
789 4) | |
790 ((memq 'rat (nth 1 decl)) | |
791 5) | |
792 ((memq 'float (nth 1 decl)) | |
793 10) | |
794 ((nth 2 decl) | |
795 (math-possible-types (nth 2 decl))) | |
796 ((memq 'real (nth 1 decl)) | |
797 15) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
798 (t 63)))))) |
40785 | 799 |
800 (defun math-known-evenp (a) | |
801 (cond ((Math-integerp a) | |
802 (math-evenp a)) | |
803 ((Math-messy-integerp a) | |
804 (or (> (nth 2 a) 0) | |
805 (math-evenp (math-trunc a)))) | |
806 ((eq (car a) '*) | |
807 (if (math-known-evenp (nth 1 a)) | |
808 (math-known-num-integerp (nth 2 a)) | |
809 (if (math-known-num-integerp (nth 1 a)) | |
810 (math-known-evenp (nth 2 a))))) | |
811 ((memq (car a) '(+ -)) | |
812 (or (and (math-known-evenp (nth 1 a)) | |
813 (math-known-evenp (nth 2 a))) | |
814 (and (math-known-oddp (nth 1 a)) | |
815 (math-known-oddp (nth 2 a))))) | |
816 ((eq (car a) 'neg) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
817 (math-known-evenp (nth 1 a))))) |
40785 | 818 |
819 (defun math-known-oddp (a) | |
820 (cond ((Math-integerp a) | |
821 (math-oddp a)) | |
822 ((Math-messy-integerp a) | |
823 (and (<= (nth 2 a) 0) | |
824 (math-oddp (math-trunc a)))) | |
825 ((memq (car a) '(+ -)) | |
826 (or (and (math-known-evenp (nth 1 a)) | |
827 (math-known-oddp (nth 2 a))) | |
828 (and (math-known-oddp (nth 1 a)) | |
829 (math-known-evenp (nth 2 a))))) | |
830 ((eq (car a) 'neg) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
831 (math-known-oddp (nth 1 a))))) |
40785 | 832 |
833 | |
834 (defun calcFunc-dreal (expr) | |
835 (let ((types (math-possible-types expr))) | |
836 (if (< types 16) 1 | |
837 (if (= (logand types 15) 0) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
838 (math-reject-arg expr 'realp 'quiet))))) |
40785 | 839 |
840 (defun calcFunc-dimag (expr) | |
841 (let ((types (math-possible-types expr))) | |
842 (if (= types 16) 1 | |
843 (if (= (logand types 16) 0) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
844 (math-reject-arg expr "Expected an imaginary number"))))) |
40785 | 845 |
846 (defun calcFunc-dpos (expr) | |
847 (let ((signs (math-possible-signs expr))) | |
848 (if (eq signs 4) 1 | |
849 (if (memq signs '(1 2 3)) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
850 (math-reject-arg expr 'posp 'quiet))))) |
40785 | 851 |
852 (defun calcFunc-dneg (expr) | |
853 (let ((signs (math-possible-signs expr))) | |
854 (if (eq signs 1) 1 | |
855 (if (memq signs '(2 4 6)) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
856 (math-reject-arg expr 'negp 'quiet))))) |
40785 | 857 |
858 (defun calcFunc-dnonneg (expr) | |
859 (let ((signs (math-possible-signs expr))) | |
860 (if (memq signs '(2 4 6)) 1 | |
861 (if (eq signs 1) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
862 (math-reject-arg expr 'posp 'quiet))))) |
40785 | 863 |
864 (defun calcFunc-dnonzero (expr) | |
865 (let ((signs (math-possible-signs expr))) | |
866 (if (memq signs '(1 4 5 8 9 12 13)) 1 | |
867 (if (eq signs 2) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
868 (math-reject-arg expr 'nonzerop 'quiet))))) |
40785 | 869 |
870 (defun calcFunc-dint (expr) | |
871 (let ((types (math-possible-types expr))) | |
872 (if (= types 1) 1 | |
873 (if (= (logand types 1) 0) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
874 (math-reject-arg expr 'integerp 'quiet))))) |
40785 | 875 |
876 (defun calcFunc-dnumint (expr) | |
877 (let ((types (math-possible-types expr t))) | |
878 (if (<= types 3) 1 | |
879 (if (= (logand types 3) 0) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
880 (math-reject-arg expr 'integerp 'quiet))))) |
40785 | 881 |
882 (defun calcFunc-dnatnum (expr) | |
883 (let ((res (calcFunc-dint expr))) | |
884 (if (eq res 1) | |
885 (calcFunc-dnonneg expr) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
886 res))) |
40785 | 887 |
888 (defun calcFunc-deven (expr) | |
889 (if (math-known-evenp expr) | |
890 1 | |
891 (if (or (math-known-oddp expr) | |
892 (= (logand (math-possible-types expr) 3) 0)) | |
893 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
894 (math-reject-arg expr "Can't tell if expression is odd or even")))) |
40785 | 895 |
896 (defun calcFunc-dodd (expr) | |
897 (if (math-known-oddp expr) | |
898 1 | |
899 (if (or (math-known-evenp expr) | |
900 (= (logand (math-possible-types expr) 3) 0)) | |
901 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
902 (math-reject-arg expr "Can't tell if expression is odd or even")))) |
40785 | 903 |
904 (defun calcFunc-drat (expr) | |
905 (let ((types (math-possible-types expr))) | |
906 (if (memq types '(1 4 5)) 1 | |
907 (if (= (logand types 5) 0) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
908 (math-reject-arg expr "Rational number expected"))))) |
40785 | 909 |
910 (defun calcFunc-drange (expr) | |
911 (math-setup-declarations) | |
912 (let (range) | |
913 (if (Math-realp expr) | |
914 (list 'vec expr) | |
915 (if (eq (car-safe expr) 'intv) | |
916 expr | |
917 (if (eq (car-safe expr) 'var) | |
918 (setq range (nth 2 (or (assq (nth 2 expr) math-decls-cache) | |
919 math-decls-all))) | |
920 (setq range (nth 2 (assq (car-safe expr) math-decls-cache)))) | |
921 (if range | |
922 (math-clean-set (copy-sequence range)) | |
923 (setq range (math-possible-signs expr)) | |
924 (if (< range 8) | |
925 (aref [(vec) | |
926 (intv 2 (neg (var inf var-inf)) 0) | |
927 (vec 0) | |
928 (intv 3 (neg (var inf var-inf)) 0) | |
929 (intv 1 0 (var inf var-inf)) | |
930 (vec (intv 2 (neg (var inf var-inf)) 0) | |
931 (intv 1 0 (var inf var-inf))) | |
932 (intv 3 0 (var inf var-inf)) | |
933 (intv 3 (neg (var inf var-inf)) (var inf var-inf))] range) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
934 (math-reject-arg expr 'realp 'quiet))))))) |
40785 | 935 |
936 (defun calcFunc-dscalar (a) | |
937 (if (math-known-scalarp a) 1 | |
938 (if (math-known-matrixp a) 0 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
939 (math-reject-arg a 'objectp 'quiet)))) |
40785 | 940 |
941 | |
942 ;;;; Arithmetic. | |
943 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
944 (defsubst calcFunc-neg (a) |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
945 (math-normalize (list 'neg a))) |
40785 | 946 |
947 (defun math-neg-fancy (a) | |
948 (cond ((eq (car a) 'polar) | |
949 (list 'polar | |
950 (nth 1 a) | |
951 (if (math-posp (nth 2 a)) | |
952 (math-sub (nth 2 a) (math-half-circle nil)) | |
953 (math-add (nth 2 a) (math-half-circle nil))))) | |
954 ((eq (car a) 'mod) | |
955 (if (math-zerop (nth 1 a)) | |
956 a | |
957 (list 'mod (math-sub (nth 2 a) (nth 1 a)) (nth 2 a)))) | |
958 ((eq (car a) 'sdev) | |
959 (list 'sdev (math-neg (nth 1 a)) (nth 2 a))) | |
960 ((eq (car a) 'intv) | |
961 (math-make-intv (aref [0 2 1 3] (nth 1 a)) | |
962 (math-neg (nth 3 a)) | |
963 (math-neg (nth 2 a)))) | |
964 ((and math-simplify-only | |
965 (not (equal a math-simplify-only))) | |
966 (list 'neg a)) | |
967 ((eq (car a) '+) | |
968 (math-sub (math-neg (nth 1 a)) (nth 2 a))) | |
969 ((eq (car a) '-) | |
970 (math-sub (nth 2 a) (nth 1 a))) | |
971 ((and (memq (car a) '(* /)) | |
972 (math-okay-neg (nth 1 a))) | |
973 (list (car a) (math-neg (nth 1 a)) (nth 2 a))) | |
974 ((and (memq (car a) '(* /)) | |
975 (math-okay-neg (nth 2 a))) | |
976 (list (car a) (nth 1 a) (math-neg (nth 2 a)))) | |
977 ((and (memq (car a) '(* /)) | |
978 (or (math-objectp (nth 1 a)) | |
979 (and (eq (car (nth 1 a)) '*) | |
980 (math-objectp (nth 1 (nth 1 a)))))) | |
981 (list (car a) (math-neg (nth 1 a)) (nth 2 a))) | |
982 ((and (eq (car a) '/) | |
983 (or (math-objectp (nth 2 a)) | |
984 (and (eq (car (nth 2 a)) '*) | |
985 (math-objectp (nth 1 (nth 2 a)))))) | |
986 (list (car a) (nth 1 a) (math-neg (nth 2 a)))) | |
987 ((and (eq (car a) 'var) (memq (nth 2 a) '(var-uinf var-nan))) | |
988 a) | |
989 ((eq (car a) 'neg) | |
990 (nth 1 a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
991 (t (list 'neg a)))) |
40785 | 992 |
993 (defun math-okay-neg (a) | |
994 (or (math-looks-negp a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
995 (eq (car-safe a) '-))) |
40785 | 996 |
997 (defun math-neg-float (a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
998 (list 'float (Math-integer-neg (nth 1 a)) (nth 2 a))) |
40785 | 999 |
1000 | |
1001 (defun calcFunc-add (&rest rest) | |
1002 (if rest | |
1003 (let ((a (car rest))) | |
1004 (while (setq rest (cdr rest)) | |
1005 (setq a (list '+ a (car rest)))) | |
1006 (math-normalize a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1007 0)) |
40785 | 1008 |
1009 (defun calcFunc-sub (&rest rest) | |
1010 (if rest | |
1011 (let ((a (car rest))) | |
1012 (while (setq rest (cdr rest)) | |
1013 (setq a (list '- a (car rest)))) | |
1014 (math-normalize a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1015 0)) |
40785 | 1016 |
1017 (defun math-add-objects-fancy (a b) | |
1018 (cond ((and (Math-numberp a) (Math-numberp b)) | |
1019 (let ((aa (math-complex a)) | |
1020 (bb (math-complex b))) | |
1021 (math-normalize | |
1022 (let ((res (list 'cplx | |
1023 (math-add (nth 1 aa) (nth 1 bb)) | |
1024 (math-add (nth 2 aa) (nth 2 bb))))) | |
1025 (if (math-want-polar a b) | |
1026 (math-polar res) | |
1027 res))))) | |
1028 ((or (Math-vectorp a) (Math-vectorp b)) | |
1029 (math-map-vec-2 'math-add a b)) | |
1030 ((eq (car-safe a) 'sdev) | |
1031 (if (eq (car-safe b) 'sdev) | |
1032 (math-make-sdev (math-add (nth 1 a) (nth 1 b)) | |
1033 (math-hypot (nth 2 a) (nth 2 b))) | |
1034 (and (or (Math-scalarp b) | |
1035 (not (Math-objvecp b))) | |
1036 (math-make-sdev (math-add (nth 1 a) b) (nth 2 a))))) | |
1037 ((and (eq (car-safe b) 'sdev) | |
1038 (or (Math-scalarp a) | |
1039 (not (Math-objvecp a)))) | |
1040 (math-make-sdev (math-add a (nth 1 b)) (nth 2 b))) | |
1041 ((eq (car-safe a) 'intv) | |
1042 (if (eq (car-safe b) 'intv) | |
1043 (math-make-intv (logior (logand (nth 1 a) (nth 1 b)) | |
1044 (if (equal (nth 2 a) | |
1045 '(neg (var inf var-inf))) | |
1046 (logand (nth 1 a) 2) 0) | |
1047 (if (equal (nth 2 b) | |
1048 '(neg (var inf var-inf))) | |
1049 (logand (nth 1 b) 2) 0) | |
1050 (if (equal (nth 3 a) '(var inf var-inf)) | |
1051 (logand (nth 1 a) 1) 0) | |
1052 (if (equal (nth 3 b) '(var inf var-inf)) | |
1053 (logand (nth 1 b) 1) 0)) | |
1054 (math-add (nth 2 a) (nth 2 b)) | |
1055 (math-add (nth 3 a) (nth 3 b))) | |
1056 (and (or (Math-anglep b) | |
1057 (eq (car b) 'date) | |
1058 (not (Math-objvecp b))) | |
1059 (math-make-intv (nth 1 a) | |
1060 (math-add (nth 2 a) b) | |
1061 (math-add (nth 3 a) b))))) | |
1062 ((and (eq (car-safe b) 'intv) | |
1063 (or (Math-anglep a) | |
1064 (eq (car a) 'date) | |
1065 (not (Math-objvecp a)))) | |
1066 (math-make-intv (nth 1 b) | |
1067 (math-add a (nth 2 b)) | |
1068 (math-add a (nth 3 b)))) | |
1069 ((eq (car-safe a) 'date) | |
1070 (cond ((eq (car-safe b) 'date) | |
1071 (math-add (nth 1 a) (nth 1 b))) | |
1072 ((eq (car-safe b) 'hms) | |
1073 (let ((parts (math-date-parts (nth 1 a)))) | |
1074 (list 'date | |
1075 (math-add (car parts) ; this minimizes roundoff | |
1076 (math-div (math-add | |
1077 (math-add (nth 1 parts) | |
1078 (nth 2 parts)) | |
1079 (math-add | |
1080 (math-mul (nth 1 b) 3600) | |
1081 (math-add (math-mul (nth 2 b) 60) | |
1082 (nth 3 b)))) | |
1083 86400))))) | |
1084 ((Math-realp b) | |
1085 (list 'date (math-add (nth 1 a) b))) | |
1086 (t nil))) | |
1087 ((eq (car-safe b) 'date) | |
1088 (math-add-objects-fancy b a)) | |
1089 ((and (eq (car-safe a) 'mod) | |
1090 (eq (car-safe b) 'mod) | |
1091 (equal (nth 2 a) (nth 2 b))) | |
1092 (math-make-mod (math-add (nth 1 a) (nth 1 b)) (nth 2 a))) | |
1093 ((and (eq (car-safe a) 'mod) | |
1094 (Math-anglep b)) | |
1095 (math-make-mod (math-add (nth 1 a) b) (nth 2 a))) | |
1096 ((and (eq (car-safe b) 'mod) | |
1097 (Math-anglep a)) | |
1098 (math-make-mod (math-add a (nth 1 b)) (nth 2 b))) | |
1099 ((and (or (eq (car-safe a) 'hms) (eq (car-safe b) 'hms)) | |
1100 (and (Math-anglep a) (Math-anglep b))) | |
1101 (or (eq (car-safe a) 'hms) (setq a (math-to-hms a))) | |
1102 (or (eq (car-safe b) 'hms) (setq b (math-to-hms b))) | |
1103 (math-normalize | |
1104 (if (math-negp a) | |
1105 (math-neg (math-add (math-neg a) (math-neg b))) | |
1106 (if (math-negp b) | |
1107 (let* ((s (math-add (nth 3 a) (nth 3 b))) | |
1108 (m (math-add (nth 2 a) (nth 2 b))) | |
1109 (h (math-add (nth 1 a) (nth 1 b)))) | |
1110 (if (math-negp s) | |
1111 (setq s (math-add s 60) | |
1112 m (math-add m -1))) | |
1113 (if (math-negp m) | |
1114 (setq m (math-add m 60) | |
1115 h (math-add h -1))) | |
1116 (if (math-negp h) | |
1117 (math-add b a) | |
1118 (list 'hms h m s))) | |
1119 (let* ((s (math-add (nth 3 a) (nth 3 b))) | |
1120 (m (math-add (nth 2 a) (nth 2 b))) | |
1121 (h (math-add (nth 1 a) (nth 1 b)))) | |
1122 (list 'hms h m s)))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1123 (t (calc-record-why "*Incompatible arguments for +" a b)))) |
40785 | 1124 |
1125 (defun math-add-symb-fancy (a b) | |
1126 (or (and math-simplify-only | |
1127 (not (equal a math-simplify-only)) | |
1128 (list '+ a b)) | |
1129 (and (eq (car-safe b) '+) | |
1130 (math-add (math-add a (nth 1 b)) | |
1131 (nth 2 b))) | |
1132 (and (eq (car-safe b) '-) | |
1133 (math-sub (math-add a (nth 1 b)) | |
1134 (nth 2 b))) | |
1135 (and (eq (car-safe b) 'neg) | |
1136 (eq (car-safe (nth 1 b)) '+) | |
1137 (math-sub (math-sub a (nth 1 (nth 1 b))) | |
1138 (nth 2 (nth 1 b)))) | |
1139 (and (or (and (Math-vectorp a) (math-known-scalarp b)) | |
1140 (and (Math-vectorp b) (math-known-scalarp a))) | |
1141 (math-map-vec-2 'math-add a b)) | |
1142 (let ((inf (math-infinitep a))) | |
1143 (cond | |
1144 (inf | |
1145 (let ((inf2 (math-infinitep b))) | |
1146 (if inf2 | |
1147 (if (or (memq (nth 2 inf) '(var-uinf var-nan)) | |
1148 (memq (nth 2 inf2) '(var-uinf var-nan))) | |
1149 '(var nan var-nan) | |
1150 (let ((dir (math-infinite-dir a inf)) | |
1151 (dir2 (math-infinite-dir b inf2))) | |
1152 (if (and (Math-objectp dir) (Math-objectp dir2)) | |
1153 (if (Math-equal dir dir2) | |
1154 a | |
1155 '(var nan var-nan))))) | |
1156 (if (and (equal a '(var inf var-inf)) | |
1157 (eq (car-safe b) 'intv) | |
1158 (memq (nth 1 b) '(2 3)) | |
1159 (equal (nth 2 b) '(neg (var inf var-inf)))) | |
1160 (list 'intv 3 (nth 2 b) a) | |
1161 (if (and (equal a '(neg (var inf var-inf))) | |
1162 (eq (car-safe b) 'intv) | |
1163 (memq (nth 1 b) '(1 3)) | |
1164 (equal (nth 3 b) '(var inf var-inf))) | |
1165 (list 'intv 3 a (nth 3 b)) | |
1166 a))))) | |
1167 ((math-infinitep b) | |
1168 (if (eq (car-safe a) 'intv) | |
1169 (math-add b a) | |
1170 b)) | |
1171 ((eq (car-safe a) '+) | |
1172 (let ((temp (math-combine-sum (nth 2 a) b nil nil t))) | |
1173 (and temp | |
1174 (math-add (nth 1 a) temp)))) | |
1175 ((eq (car-safe a) '-) | |
1176 (let ((temp (math-combine-sum (nth 2 a) b t nil t))) | |
1177 (and temp | |
1178 (math-add (nth 1 a) temp)))) | |
1179 ((and (Math-objectp a) (Math-objectp b)) | |
1180 nil) | |
1181 (t | |
1182 (math-combine-sum a b nil nil nil)))) | |
1183 (and (Math-looks-negp b) | |
1184 (list '- a (math-neg b))) | |
1185 (and (Math-looks-negp a) | |
1186 (list '- b (math-neg a))) | |
1187 (and (eq (car-safe a) 'calcFunc-idn) | |
1188 (= (length a) 2) | |
1189 (or (and (eq (car-safe b) 'calcFunc-idn) | |
1190 (= (length b) 2) | |
1191 (list 'calcFunc-idn (math-add (nth 1 a) (nth 1 b)))) | |
1192 (and (math-square-matrixp b) | |
1193 (math-add (math-mimic-ident (nth 1 a) b) b)) | |
1194 (and (math-known-scalarp b) | |
1195 (math-add (nth 1 a) b)))) | |
1196 (and (eq (car-safe b) 'calcFunc-idn) | |
1197 (= (length a) 2) | |
1198 (or (and (math-square-matrixp a) | |
1199 (math-add a (math-mimic-ident (nth 1 b) a))) | |
1200 (and (math-known-scalarp a) | |
1201 (math-add a (nth 1 b))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1202 (list '+ a b))) |
40785 | 1203 |
1204 | |
1205 (defun calcFunc-mul (&rest rest) | |
1206 (if rest | |
1207 (let ((a (car rest))) | |
1208 (while (setq rest (cdr rest)) | |
1209 (setq a (list '* a (car rest)))) | |
1210 (math-normalize a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1211 1)) |
40785 | 1212 |
1213 (defun math-mul-objects-fancy (a b) | |
1214 (cond ((and (Math-numberp a) (Math-numberp b)) | |
1215 (math-normalize | |
1216 (if (math-want-polar a b) | |
1217 (let ((a (math-polar a)) | |
1218 (b (math-polar b))) | |
1219 (list 'polar | |
1220 (math-mul (nth 1 a) (nth 1 b)) | |
1221 (math-fix-circular (math-add (nth 2 a) (nth 2 b))))) | |
1222 (setq a (math-complex a) | |
1223 b (math-complex b)) | |
1224 (list 'cplx | |
1225 (math-sub (math-mul (nth 1 a) (nth 1 b)) | |
1226 (math-mul (nth 2 a) (nth 2 b))) | |
1227 (math-add (math-mul (nth 1 a) (nth 2 b)) | |
1228 (math-mul (nth 2 a) (nth 1 b))))))) | |
1229 ((Math-vectorp a) | |
1230 (if (Math-vectorp b) | |
1231 (if (math-matrixp a) | |
1232 (if (math-matrixp b) | |
1233 (if (= (length (nth 1 a)) (length b)) | |
1234 (math-mul-mats a b) | |
1235 (math-dimension-error)) | |
1236 (if (= (length (nth 1 a)) 2) | |
1237 (if (= (length a) (length b)) | |
1238 (math-mul-mats a (list 'vec b)) | |
1239 (math-dimension-error)) | |
1240 (if (= (length (nth 1 a)) (length b)) | |
1241 (math-mul-mat-vec a b) | |
1242 (math-dimension-error)))) | |
1243 (if (math-matrixp b) | |
1244 (if (= (length a) (length b)) | |
1245 (nth 1 (math-mul-mats (list 'vec a) b)) | |
1246 (math-dimension-error)) | |
1247 (if (= (length a) (length b)) | |
1248 (math-dot-product a b) | |
1249 (math-dimension-error)))) | |
1250 (math-map-vec-2 'math-mul a b))) | |
1251 ((Math-vectorp b) | |
1252 (math-map-vec-2 'math-mul a b)) | |
1253 ((eq (car-safe a) 'sdev) | |
1254 (if (eq (car-safe b) 'sdev) | |
1255 (math-make-sdev (math-mul (nth 1 a) (nth 1 b)) | |
1256 (math-hypot (math-mul (nth 2 a) (nth 1 b)) | |
1257 (math-mul (nth 2 b) (nth 1 a)))) | |
1258 (and (or (Math-scalarp b) | |
1259 (not (Math-objvecp b))) | |
1260 (math-make-sdev (math-mul (nth 1 a) b) | |
1261 (math-mul (nth 2 a) b))))) | |
1262 ((and (eq (car-safe b) 'sdev) | |
1263 (or (Math-scalarp a) | |
1264 (not (Math-objvecp a)))) | |
1265 (math-make-sdev (math-mul a (nth 1 b)) (math-mul a (nth 2 b)))) | |
1266 ((and (eq (car-safe a) 'intv) (Math-anglep b)) | |
1267 (if (Math-negp b) | |
1268 (math-neg (math-mul a (math-neg b))) | |
1269 (math-make-intv (nth 1 a) | |
1270 (math-mul (nth 2 a) b) | |
1271 (math-mul (nth 3 a) b)))) | |
1272 ((and (eq (car-safe b) 'intv) (Math-anglep a)) | |
1273 (math-mul b a)) | |
1274 ((and (eq (car-safe a) 'intv) (math-intv-constp a) | |
1275 (eq (car-safe b) 'intv) (math-intv-constp b)) | |
1276 (let ((lo (math-mul a (nth 2 b))) | |
1277 (hi (math-mul a (nth 3 b)))) | |
1278 (or (eq (car-safe lo) 'intv) | |
1279 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) lo lo))) | |
1280 (or (eq (car-safe hi) 'intv) | |
1281 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) hi hi))) | |
1282 (math-combine-intervals | |
1283 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3)) | |
1284 (math-infinitep (nth 2 lo))) | |
1285 (memq (nth 1 lo) '(2 3))) | |
1286 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3)) | |
1287 (math-infinitep (nth 3 lo))) | |
1288 (memq (nth 1 lo) '(1 3))) | |
1289 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3)) | |
1290 (math-infinitep (nth 2 hi))) | |
1291 (memq (nth 1 hi) '(2 3))) | |
1292 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3)) | |
1293 (math-infinitep (nth 3 hi))) | |
1294 (memq (nth 1 hi) '(1 3)))))) | |
1295 ((and (eq (car-safe a) 'mod) | |
1296 (eq (car-safe b) 'mod) | |
1297 (equal (nth 2 a) (nth 2 b))) | |
1298 (math-make-mod (math-mul (nth 1 a) (nth 1 b)) (nth 2 a))) | |
1299 ((and (eq (car-safe a) 'mod) | |
1300 (Math-anglep b)) | |
1301 (math-make-mod (math-mul (nth 1 a) b) (nth 2 a))) | |
1302 ((and (eq (car-safe b) 'mod) | |
1303 (Math-anglep a)) | |
1304 (math-make-mod (math-mul a (nth 1 b)) (nth 2 b))) | |
1305 ((and (eq (car-safe a) 'hms) (Math-realp b)) | |
1306 (math-with-extra-prec 2 | |
1307 (math-to-hms (math-mul (math-from-hms a 'deg) b) 'deg))) | |
1308 ((and (eq (car-safe b) 'hms) (Math-realp a)) | |
1309 (math-mul b a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1310 (t (calc-record-why "*Incompatible arguments for *" a b)))) |
40785 | 1311 |
1312 ;;; Fast function to multiply floating-point numbers. | |
1313 (defun math-mul-float (a b) ; [F F F] | |
1314 (math-make-float (math-mul (nth 1 a) (nth 1 b)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1315 (+ (nth 2 a) (nth 2 b)))) |
40785 | 1316 |
1317 (defun math-sqr-float (a) ; [F F] | |
1318 (math-make-float (math-mul (nth 1 a) (nth 1 a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1319 (+ (nth 2 a) (nth 2 a)))) |
40785 | 1320 |
1321 (defun math-intv-constp (a &optional finite) | |
1322 (and (or (Math-anglep (nth 2 a)) | |
1323 (and (equal (nth 2 a) '(neg (var inf var-inf))) | |
1324 (or (not finite) | |
1325 (memq (nth 1 a) '(0 1))))) | |
1326 (or (Math-anglep (nth 3 a)) | |
1327 (and (equal (nth 3 a) '(var inf var-inf)) | |
1328 (or (not finite) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1329 (memq (nth 1 a) '(0 2))))))) |
40785 | 1330 |
1331 (defun math-mul-zero (a b) | |
1332 (if (math-known-matrixp b) | |
1333 (if (math-vectorp b) | |
1334 (math-map-vec-2 'math-mul a b) | |
1335 (math-mimic-ident 0 b)) | |
1336 (if (math-infinitep b) | |
1337 '(var nan var-nan) | |
1338 (let ((aa nil) (bb nil)) | |
1339 (if (and (eq (car-safe b) 'intv) | |
1340 (progn | |
1341 (and (equal (nth 2 b) '(neg (var inf var-inf))) | |
1342 (memq (nth 1 b) '(2 3)) | |
1343 (setq aa (nth 2 b))) | |
1344 (and (equal (nth 3 b) '(var inf var-inf)) | |
1345 (memq (nth 1 b) '(1 3)) | |
1346 (setq bb (nth 3 b))) | |
1347 (or aa bb))) | |
1348 (if (or (math-posp a) | |
1349 (and (math-zerop a) | |
1350 (or (memq calc-infinite-mode '(-1 1)) | |
1351 (setq aa '(neg (var inf var-inf)) | |
1352 bb '(var inf var-inf))))) | |
1353 (list 'intv 3 (or aa 0) (or bb 0)) | |
1354 (if (math-negp a) | |
1355 (math-neg (list 'intv 3 (or aa 0) (or bb 0))) | |
1356 '(var nan var-nan))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1357 (if (or (math-floatp a) (math-floatp b)) '(float 0 0) 0)))))) |
40785 | 1358 |
1359 | |
1360 (defun math-mul-symb-fancy (a b) | |
1361 (or (and math-simplify-only | |
1362 (not (equal a math-simplify-only)) | |
1363 (list '* a b)) | |
1364 (and (Math-equal-int a 1) | |
1365 b) | |
1366 (and (Math-equal-int a -1) | |
1367 (math-neg b)) | |
1368 (and (or (and (Math-vectorp a) (math-known-scalarp b)) | |
1369 (and (Math-vectorp b) (math-known-scalarp a))) | |
1370 (math-map-vec-2 'math-mul a b)) | |
1371 (and (Math-objectp b) (not (Math-objectp a)) | |
1372 (math-mul b a)) | |
1373 (and (eq (car-safe a) 'neg) | |
1374 (math-neg (math-mul (nth 1 a) b))) | |
1375 (and (eq (car-safe b) 'neg) | |
1376 (math-neg (math-mul a (nth 1 b)))) | |
1377 (and (eq (car-safe a) '*) | |
1378 (math-mul (nth 1 a) | |
1379 (math-mul (nth 2 a) b))) | |
1380 (and (eq (car-safe a) '^) | |
1381 (Math-looks-negp (nth 2 a)) | |
1382 (not (and (eq (car-safe b) '^) (Math-looks-negp (nth 2 b)))) | |
1383 (math-known-scalarp b t) | |
1384 (math-div b (math-normalize | |
1385 (list '^ (nth 1 a) (math-neg (nth 2 a)))))) | |
1386 (and (eq (car-safe b) '^) | |
1387 (Math-looks-negp (nth 2 b)) | |
1388 (not (and (eq (car-safe a) '^) (Math-looks-negp (nth 2 a)))) | |
66479
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1389 (not (math-known-matrixp (nth 1 b))) |
40785 | 1390 (math-div a (math-normalize |
1391 (list '^ (nth 1 b) (math-neg (nth 2 b)))))) | |
1392 (and (eq (car-safe a) '/) | |
1393 (or (math-known-scalarp a t) (math-known-scalarp b t)) | |
1394 (let ((temp (math-combine-prod (nth 2 a) b t nil t))) | |
1395 (if temp | |
1396 (math-mul (nth 1 a) temp) | |
1397 (math-div (math-mul (nth 1 a) b) (nth 2 a))))) | |
1398 (and (eq (car-safe b) '/) | |
1399 (math-div (math-mul a (nth 1 b)) (nth 2 b))) | |
1400 (and (eq (car-safe b) '+) | |
1401 (Math-numberp a) | |
1402 (or (Math-numberp (nth 1 b)) | |
1403 (Math-numberp (nth 2 b))) | |
1404 (math-add (math-mul a (nth 1 b)) | |
1405 (math-mul a (nth 2 b)))) | |
1406 (and (eq (car-safe b) '-) | |
1407 (Math-numberp a) | |
1408 (or (Math-numberp (nth 1 b)) | |
1409 (Math-numberp (nth 2 b))) | |
1410 (math-sub (math-mul a (nth 1 b)) | |
1411 (math-mul a (nth 2 b)))) | |
1412 (and (eq (car-safe b) '*) | |
1413 (Math-numberp (nth 1 b)) | |
1414 (not (Math-numberp a)) | |
1415 (math-mul (nth 1 b) (math-mul a (nth 2 b)))) | |
1416 (and (eq (car-safe a) 'calcFunc-idn) | |
1417 (= (length a) 2) | |
1418 (or (and (eq (car-safe b) 'calcFunc-idn) | |
1419 (= (length b) 2) | |
1420 (list 'calcFunc-idn (math-mul (nth 1 a) (nth 1 b)))) | |
1421 (and (math-known-scalarp b) | |
1422 (list 'calcFunc-idn (math-mul (nth 1 a) b))) | |
1423 (and (math-known-matrixp b) | |
1424 (math-mul (nth 1 a) b)))) | |
1425 (and (eq (car-safe b) 'calcFunc-idn) | |
1426 (= (length b) 2) | |
1427 (or (and (math-known-scalarp a) | |
1428 (list 'calcFunc-idn (math-mul a (nth 1 b)))) | |
1429 (and (math-known-matrixp a) | |
1430 (math-mul a (nth 1 b))))) | |
66479
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1431 (and (math-identity-matrix-p a t) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1432 (or (and (eq (car-safe b) 'calcFunc-idn) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1433 (= (length b) 2) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1434 (list 'calcFunc-idn (math-mul |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1435 (nth 1 (nth 1 a)) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1436 (nth 1 b)) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1437 (1- (length a)))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1438 (and (math-known-scalarp b) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1439 (list 'calcFunc-idn (math-mul |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1440 (nth 1 (nth 1 a)) b) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1441 (1- (length a)))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1442 (and (math-known-matrixp b) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1443 (math-mul (nth 1 (nth 1 a)) b)))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1444 (and (math-identity-matrix-p b t) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1445 (or (and (eq (car-safe a) 'calcFunc-idn) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1446 (= (length a) 2) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1447 (list 'calcFunc-idn (math-mul (nth 1 a) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1448 (nth 1 (nth 1 b))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1449 (1- (length b)))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1450 (and (math-known-scalarp a) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1451 (list 'calcFunc-idn (math-mul a (nth 1 (nth 1 b))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1452 (1- (length b)))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1453 (and (math-known-matrixp a) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1454 (math-mul a (nth 1 (nth 1 b)))))) |
40785 | 1455 (and (math-looks-negp b) |
1456 (math-mul (math-neg a) (math-neg b))) | |
1457 (and (eq (car-safe b) '-) | |
1458 (math-looks-negp a) | |
1459 (math-mul (math-neg a) (math-neg b))) | |
1460 (cond | |
1461 ((eq (car-safe b) '*) | |
1462 (let ((temp (math-combine-prod a (nth 1 b) nil nil t))) | |
1463 (and temp | |
1464 (math-mul temp (nth 2 b))))) | |
1465 (t | |
1466 (math-combine-prod a b nil nil nil))) | |
1467 (and (equal a '(var nan var-nan)) | |
1468 a) | |
1469 (and (equal b '(var nan var-nan)) | |
1470 b) | |
1471 (and (equal a '(var uinf var-uinf)) | |
1472 a) | |
1473 (and (equal b '(var uinf var-uinf)) | |
1474 b) | |
1475 (and (equal b '(var inf var-inf)) | |
1476 (let ((s1 (math-possible-signs a))) | |
1477 (cond ((eq s1 4) | |
1478 b) | |
1479 ((eq s1 6) | |
1480 '(intv 3 0 (var inf var-inf))) | |
1481 ((eq s1 1) | |
1482 (math-neg b)) | |
1483 ((eq s1 3) | |
1484 '(intv 3 (neg (var inf var-inf)) 0)) | |
1485 ((and (eq (car a) 'intv) (math-intv-constp a)) | |
1486 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))) | |
1487 ((and (eq (car a) 'cplx) | |
1488 (math-zerop (nth 1 a))) | |
1489 (list '* (list 'cplx 0 (calcFunc-sign (nth 2 a))) b)) | |
1490 ((eq (car a) 'polar) | |
1491 (list '* (list 'polar 1 (nth 2 a)) b))))) | |
1492 (and (equal a '(var inf var-inf)) | |
1493 (math-mul b a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1494 (list '* a b))) |
40785 | 1495 |
1496 | |
1497 (defun calcFunc-div (a &rest rest) | |
1498 (while rest | |
1499 (setq a (list '/ a (car rest)) | |
1500 rest (cdr rest))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1501 (math-normalize a)) |
40785 | 1502 |
1503 (defun math-div-objects-fancy (a b) | |
1504 (cond ((and (Math-numberp a) (Math-numberp b)) | |
1505 (math-normalize | |
1506 (cond ((math-want-polar a b) | |
1507 (let ((a (math-polar a)) | |
1508 (b (math-polar b))) | |
1509 (list 'polar | |
1510 (math-div (nth 1 a) (nth 1 b)) | |
1511 (math-fix-circular (math-sub (nth 2 a) | |
1512 (nth 2 b)))))) | |
1513 ((Math-realp b) | |
1514 (setq a (math-complex a)) | |
1515 (list 'cplx (math-div (nth 1 a) b) | |
1516 (math-div (nth 2 a) b))) | |
1517 (t | |
1518 (setq a (math-complex a) | |
1519 b (math-complex b)) | |
1520 (math-div | |
1521 (list 'cplx | |
1522 (math-add (math-mul (nth 1 a) (nth 1 b)) | |
1523 (math-mul (nth 2 a) (nth 2 b))) | |
1524 (math-sub (math-mul (nth 2 a) (nth 1 b)) | |
1525 (math-mul (nth 1 a) (nth 2 b)))) | |
1526 (math-add (math-sqr (nth 1 b)) | |
1527 (math-sqr (nth 2 b)))))))) | |
1528 ((math-matrixp b) | |
1529 (if (math-square-matrixp b) | |
1530 (let ((n1 (length b))) | |
1531 (if (Math-vectorp a) | |
1532 (if (math-matrixp a) | |
1533 (if (= (length a) n1) | |
1534 (math-lud-solve (math-matrix-lud b) a b) | |
1535 (if (= (length (nth 1 a)) n1) | |
1536 (math-transpose | |
1537 (math-lud-solve (math-matrix-lud | |
1538 (math-transpose b)) | |
1539 (math-transpose a) b)) | |
1540 (math-dimension-error))) | |
1541 (if (= (length a) n1) | |
1542 (math-mat-col (math-lud-solve (math-matrix-lud b) | |
1543 (math-col-matrix a) b) | |
1544 1) | |
1545 (math-dimension-error))) | |
1546 (if (Math-equal-int a 1) | |
1547 (calcFunc-inv b) | |
1548 (math-mul a (calcFunc-inv b))))) | |
1549 (math-reject-arg b 'square-matrixp))) | |
1550 ((and (Math-vectorp a) (Math-objectp b)) | |
1551 (math-map-vec-2 'math-div a b)) | |
1552 ((eq (car-safe a) 'sdev) | |
1553 (if (eq (car-safe b) 'sdev) | |
1554 (let ((x (math-div (nth 1 a) (nth 1 b)))) | |
1555 (math-make-sdev x | |
1556 (math-div (math-hypot (nth 2 a) | |
1557 (math-mul (nth 2 b) x)) | |
1558 (nth 1 b)))) | |
1559 (if (or (Math-scalarp b) | |
1560 (not (Math-objvecp b))) | |
1561 (math-make-sdev (math-div (nth 1 a) b) (math-div (nth 2 a) b)) | |
1562 (math-reject-arg 'realp b)))) | |
1563 ((and (eq (car-safe b) 'sdev) | |
1564 (or (Math-scalarp a) | |
1565 (not (Math-objvecp a)))) | |
1566 (let ((x (math-div a (nth 1 b)))) | |
1567 (math-make-sdev x | |
1568 (math-div (math-mul (nth 2 b) x) (nth 1 b))))) | |
1569 ((and (eq (car-safe a) 'intv) (Math-anglep b)) | |
1570 (if (Math-negp b) | |
1571 (math-neg (math-div a (math-neg b))) | |
1572 (math-make-intv (nth 1 a) | |
1573 (math-div (nth 2 a) b) | |
1574 (math-div (nth 3 a) b)))) | |
1575 ((and (eq (car-safe b) 'intv) (Math-anglep a)) | |
1576 (if (or (Math-posp (nth 2 b)) | |
1577 (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1)) | |
1578 calc-infinite-mode))) | |
1579 (if (Math-negp a) | |
1580 (math-neg (math-div (math-neg a) b)) | |
1581 (let ((calc-infinite-mode 1)) | |
1582 (math-make-intv (aref [0 2 1 3] (nth 1 b)) | |
1583 (math-div a (nth 3 b)) | |
1584 (math-div a (nth 2 b))))) | |
1585 (if (or (Math-negp (nth 3 b)) | |
1586 (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2)) | |
1587 calc-infinite-mode))) | |
1588 (math-neg (math-div a (math-neg b))) | |
1589 (if calc-infinite-mode | |
1590 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) | |
1591 (math-reject-arg b "*Division by zero"))))) | |
1592 ((and (eq (car-safe a) 'intv) (math-intv-constp a) | |
1593 (eq (car-safe b) 'intv) (math-intv-constp b)) | |
1594 (if (or (Math-posp (nth 2 b)) | |
1595 (and (Math-zerop (nth 2 b)) (or (memq (nth 1 b) '(0 1)) | |
1596 calc-infinite-mode))) | |
1597 (let* ((calc-infinite-mode 1) | |
1598 (lo (math-div a (nth 2 b))) | |
1599 (hi (math-div a (nth 3 b)))) | |
1600 (or (eq (car-safe lo) 'intv) | |
1601 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) | |
1602 lo lo))) | |
1603 (or (eq (car-safe hi) 'intv) | |
1604 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) | |
1605 hi hi))) | |
1606 (math-combine-intervals | |
1607 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3)) | |
1608 (and (math-infinitep (nth 2 lo)) | |
1609 (not (math-zerop (nth 2 b))))) | |
1610 (memq (nth 1 lo) '(2 3))) | |
1611 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3)) | |
1612 (and (math-infinitep (nth 3 lo)) | |
1613 (not (math-zerop (nth 2 b))))) | |
1614 (memq (nth 1 lo) '(1 3))) | |
1615 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3)) | |
1616 (and (math-infinitep (nth 2 hi)) | |
1617 (not (math-zerop (nth 3 b))))) | |
1618 (memq (nth 1 hi) '(2 3))) | |
1619 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3)) | |
1620 (and (math-infinitep (nth 3 hi)) | |
1621 (not (math-zerop (nth 3 b))))) | |
1622 (memq (nth 1 hi) '(1 3))))) | |
1623 (if (or (Math-negp (nth 3 b)) | |
1624 (and (Math-zerop (nth 3 b)) (or (memq (nth 1 b) '(0 2)) | |
1625 calc-infinite-mode))) | |
1626 (math-neg (math-div a (math-neg b))) | |
1627 (if calc-infinite-mode | |
1628 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) | |
1629 (math-reject-arg b "*Division by zero"))))) | |
1630 ((and (eq (car-safe a) 'mod) | |
1631 (eq (car-safe b) 'mod) | |
1632 (equal (nth 2 a) (nth 2 b))) | |
1633 (math-make-mod (math-div-mod (nth 1 a) (nth 1 b) (nth 2 a)) | |
1634 (nth 2 a))) | |
1635 ((and (eq (car-safe a) 'mod) | |
1636 (Math-anglep b)) | |
1637 (math-make-mod (math-div-mod (nth 1 a) b (nth 2 a)) (nth 2 a))) | |
1638 ((and (eq (car-safe b) 'mod) | |
1639 (Math-anglep a)) | |
1640 (math-make-mod (math-div-mod a (nth 1 b) (nth 2 b)) (nth 2 b))) | |
1641 ((eq (car-safe a) 'hms) | |
1642 (if (eq (car-safe b) 'hms) | |
1643 (math-with-extra-prec 1 | |
1644 (math-div (math-from-hms a 'deg) | |
1645 (math-from-hms b 'deg))) | |
1646 (math-with-extra-prec 2 | |
1647 (math-to-hms (math-div (math-from-hms a 'deg) b) 'deg)))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1648 (t (calc-record-why "*Incompatible arguments for /" a b)))) |
40785 | 1649 |
1650 (defun math-div-by-zero (a b) | |
1651 (if (math-infinitep a) | |
1652 (if (or (equal a '(var nan var-nan)) | |
1653 (equal b '(var uinf var-uinf)) | |
1654 (memq calc-infinite-mode '(-1 1))) | |
1655 a | |
1656 '(var uinf var-uinf)) | |
1657 (if calc-infinite-mode | |
1658 (if (math-zerop a) | |
1659 '(var nan var-nan) | |
1660 (if (eq calc-infinite-mode 1) | |
1661 (math-mul a '(var inf var-inf)) | |
1662 (if (eq calc-infinite-mode -1) | |
1663 (math-mul a '(neg (var inf var-inf))) | |
1664 (if (eq (car-safe a) 'intv) | |
1665 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) | |
1666 '(var uinf var-uinf))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1667 (math-reject-arg a "*Division by zero")))) |
40785 | 1668 |
1669 (defun math-div-zero (a b) | |
1670 (if (math-known-matrixp b) | |
1671 (if (math-vectorp b) | |
1672 (math-map-vec-2 'math-div a b) | |
1673 (math-mimic-ident 0 b)) | |
1674 (if (equal b '(var nan var-nan)) | |
1675 b | |
1676 (if (and (eq (car-safe b) 'intv) (math-intv-constp b) | |
1677 (not (math-posp b)) (not (math-negp b))) | |
1678 (if calc-infinite-mode | |
1679 (list 'intv 3 | |
1680 (if (and (math-zerop (nth 2 b)) | |
1681 (memq calc-infinite-mode '(1 -1))) | |
1682 (nth 2 b) '(neg (var inf var-inf))) | |
1683 (if (and (math-zerop (nth 3 b)) | |
1684 (memq calc-infinite-mode '(1 -1))) | |
1685 (nth 3 b) '(var inf var-inf))) | |
1686 (math-reject-arg b "*Division by zero")) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1687 a)))) |
40785 | 1688 |
60154
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1689 ;; For math-div-symb-fancy |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1690 (defvar math-trig-inverses |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1691 '((calcFunc-sin . calcFunc-csc) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1692 (calcFunc-cos . calcFunc-sec) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1693 (calcFunc-tan . calcFunc-cot) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1694 (calcFunc-sec . calcFunc-cos) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1695 (calcFunc-csc . calcFunc-sin) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1696 (calcFunc-cot . calcFunc-tan) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1697 (calcFunc-sinh . calcFunc-csch) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1698 (calcFunc-cosh . calcFunc-sech) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1699 (calcFunc-tanh . calcFunc-coth) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1700 (calcFunc-sech . calcFunc-cosh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1701 (calcFunc-csch . calcFunc-sinh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1702 (calcFunc-coth . calcFunc-tanh))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1703 |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1704 (defvar math-div-trig) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1705 (defvar math-div-non-trig) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1706 |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1707 (defun math-div-new-trig (tr) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1708 (if math-div-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1709 (setq math-div-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1710 (list '* tr math-div-trig)) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1711 (setq math-div-trig tr))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1712 |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1713 (defun math-div-new-non-trig (ntr) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1714 (if math-div-non-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1715 (setq math-div-non-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1716 (list '* ntr math-div-non-trig)) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1717 (setq math-div-non-trig ntr))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1718 |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1719 (defun math-div-isolate-trig (expr) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1720 (if (eq (car-safe expr) '*) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1721 (progn |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1722 (math-div-isolate-trig-term (nth 1 expr)) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1723 (math-div-isolate-trig (nth 2 expr))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1724 (math-div-isolate-trig-term expr))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1725 |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1726 (defun math-div-isolate-trig-term (term) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1727 (let ((fn (assoc (car-safe term) math-trig-inverses))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1728 (if fn |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1729 (math-div-new-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1730 (cons (cdr fn) (cdr term))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1731 (math-div-new-non-trig term)))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1732 |
40785 | 1733 (defun math-div-symb-fancy (a b) |
66479
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1734 (or (and (math-known-matrixp b) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1735 (math-mul a (math-pow b -1))) |
5da715ee89b8
(calc-mul-symb-fancy): Add checks for multiplication by an identity
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65993
diff
changeset
|
1736 (and math-simplify-only |
40785 | 1737 (not (equal a math-simplify-only)) |
1738 (list '/ a b)) | |
1739 (and (Math-equal-int b 1) a) | |
1740 (and (Math-equal-int b -1) (math-neg a)) | |
1741 (and (Math-vectorp a) (math-known-scalarp b) | |
1742 (math-map-vec-2 'math-div a b)) | |
1743 (and (eq (car-safe b) '^) | |
1744 (or (Math-looks-negp (nth 2 b)) (Math-equal-int a 1)) | |
1745 (math-mul a (math-normalize | |
1746 (list '^ (nth 1 b) (math-neg (nth 2 b)))))) | |
1747 (and (eq (car-safe a) 'neg) | |
1748 (math-neg (math-div (nth 1 a) b))) | |
1749 (and (eq (car-safe b) 'neg) | |
1750 (math-neg (math-div a (nth 1 b)))) | |
1751 (and (eq (car-safe a) '/) | |
1752 (math-div (nth 1 a) (math-mul (nth 2 a) b))) | |
1753 (and (eq (car-safe b) '/) | |
1754 (or (math-known-scalarp (nth 1 b) t) | |
1755 (math-known-scalarp (nth 2 b) t)) | |
1756 (math-div (math-mul a (nth 2 b)) (nth 1 b))) | |
1757 (and (eq (car-safe b) 'frac) | |
1758 (math-mul (math-make-frac (nth 2 b) (nth 1 b)) a)) | |
1759 (and (eq (car-safe a) '+) | |
1760 (or (Math-numberp (nth 1 a)) | |
1761 (Math-numberp (nth 2 a))) | |
1762 (Math-numberp b) | |
1763 (math-add (math-div (nth 1 a) b) | |
1764 (math-div (nth 2 a) b))) | |
1765 (and (eq (car-safe a) '-) | |
1766 (or (Math-numberp (nth 1 a)) | |
1767 (Math-numberp (nth 2 a))) | |
1768 (Math-numberp b) | |
1769 (math-sub (math-div (nth 1 a) b) | |
1770 (math-div (nth 2 a) b))) | |
1771 (and (or (eq (car-safe a) '-) | |
1772 (math-looks-negp a)) | |
1773 (math-looks-negp b) | |
1774 (math-div (math-neg a) (math-neg b))) | |
1775 (and (eq (car-safe b) '-) | |
1776 (math-looks-negp a) | |
1777 (math-div (math-neg a) (math-neg b))) | |
1778 (and (eq (car-safe a) 'calcFunc-idn) | |
1779 (= (length a) 2) | |
1780 (or (and (eq (car-safe b) 'calcFunc-idn) | |
1781 (= (length b) 2) | |
1782 (list 'calcFunc-idn (math-div (nth 1 a) (nth 1 b)))) | |
1783 (and (math-known-scalarp b) | |
1784 (list 'calcFunc-idn (math-div (nth 1 a) b))) | |
1785 (and (math-known-matrixp b) | |
1786 (math-div (nth 1 a) b)))) | |
1787 (and (eq (car-safe b) 'calcFunc-idn) | |
1788 (= (length b) 2) | |
1789 (or (and (math-known-scalarp a) | |
1790 (list 'calcFunc-idn (math-div a (nth 1 b)))) | |
1791 (and (math-known-matrixp a) | |
1792 (math-div a (nth 1 b))))) | |
60154
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1793 (and math-simplifying |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1794 (let ((math-div-trig nil) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1795 (math-div-non-trig nil)) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1796 (math-div-isolate-trig b) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1797 (if math-div-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1798 (if math-div-non-trig |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1799 (math-div (math-mul a math-div-trig) math-div-non-trig) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1800 (math-mul a math-div-trig)) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
1801 nil))) |
40785 | 1802 (if (and calc-matrix-mode |
1803 (or (math-known-matrixp a) (math-known-matrixp b))) | |
1804 (math-combine-prod a b nil t nil) | |
1805 (if (eq (car-safe a) '*) | |
1806 (if (eq (car-safe b) '*) | |
1807 (let ((c (math-combine-prod (nth 1 a) (nth 1 b) nil t t))) | |
1808 (and c | |
1809 (math-div (math-mul c (nth 2 a)) (nth 2 b)))) | |
1810 (let ((c (math-combine-prod (nth 1 a) b nil t t))) | |
1811 (and c | |
1812 (math-mul c (nth 2 a))))) | |
1813 (if (eq (car-safe b) '*) | |
1814 (let ((c (math-combine-prod a (nth 1 b) nil t t))) | |
1815 (and c | |
1816 (math-div c (nth 2 b)))) | |
1817 (math-combine-prod a b nil t nil)))) | |
1818 (and (math-infinitep a) | |
1819 (if (math-infinitep b) | |
1820 '(var nan var-nan) | |
1821 (if (or (equal a '(var nan var-nan)) | |
1822 (equal a '(var uinf var-uinf))) | |
1823 a | |
1824 (if (equal a '(var inf var-inf)) | |
1825 (if (or (math-posp b) | |
1826 (and (eq (car-safe b) 'intv) | |
1827 (math-zerop (nth 2 b)))) | |
1828 (if (and (eq (car-safe b) 'intv) | |
1829 (not (math-intv-constp b t))) | |
1830 '(intv 3 0 (var inf var-inf)) | |
1831 a) | |
1832 (if (or (math-negp b) | |
1833 (and (eq (car-safe b) 'intv) | |
1834 (math-zerop (nth 3 b)))) | |
1835 (if (and (eq (car-safe b) 'intv) | |
1836 (not (math-intv-constp b t))) | |
1837 '(intv 3 (neg (var inf var-inf)) 0) | |
1838 (math-neg a)) | |
1839 (if (and (eq (car-safe b) 'intv) | |
1840 (math-negp (nth 2 b)) (math-posp (nth 3 b))) | |
1841 '(intv 3 (neg (var inf var-inf)) | |
1842 (var inf var-inf))))))))) | |
1843 (and (math-infinitep b) | |
1844 (if (equal b '(var nan var-nan)) | |
1845 b | |
1846 (let ((calc-infinite-mode 1)) | |
1847 (math-mul-zero b a)))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1848 (list '/ a b))) |
40785 | 1849 |
1850 | |
1851 (defun calcFunc-mod (a b) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1852 (math-normalize (list '% a b))) |
40785 | 1853 |
1854 (defun math-mod-fancy (a b) | |
1855 (cond ((equal b '(var inf var-inf)) | |
1856 (if (or (math-posp a) (math-zerop a)) | |
1857 a | |
1858 (if (math-negp a) | |
1859 b | |
1860 (if (eq (car-safe a) 'intv) | |
1861 (if (math-negp (nth 2 a)) | |
1862 '(intv 3 0 (var inf var-inf)) | |
1863 a) | |
1864 (list '% a b))))) | |
1865 ((and (eq (car-safe a) 'mod) (Math-realp b) (math-posp b)) | |
1866 (math-make-mod (nth 1 a) b)) | |
1867 ((and (eq (car-safe a) 'intv) (math-intv-constp a t) (math-posp b)) | |
1868 (math-mod-intv a b)) | |
1869 (t | |
1870 (if (Math-anglep a) | |
1871 (calc-record-why 'anglep b) | |
1872 (calc-record-why 'anglep a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1873 (list '% a b)))) |
40785 | 1874 |
1875 | |
1876 (defun calcFunc-pow (a b) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1877 (math-normalize (list '^ a b))) |
40785 | 1878 |
1879 (defun math-pow-of-zero (a b) | |
58626
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1880 "Raise A to the power of B, where A is a form of zero." |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1881 (if (math-floatp b) (setq a (math-float a))) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1882 (cond |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1883 ;; 0^0 = 1 |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1884 ((eq b 0) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1885 1) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1886 ;; 0^0.0, etc., are undetermined |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1887 ((Math-zerop b) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1888 (if calc-infinite-mode |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1889 '(var nan var-nan) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1890 (math-reject-arg (list '^ a b) "*Indeterminate form"))) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1891 ;; 0^positive = 0 |
58688
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
1892 ((math-known-posp b) |
58626
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1893 a) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1894 ;; 0^negative is undefined (let math-div handle it) |
58688
e5b1db7d4396
(math-possible-signs): Added checks to intervals.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58647
diff
changeset
|
1895 ((math-known-negp b) |
58626
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1896 (math-div 1 a)) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1897 ;; 0^infinity is undefined |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1898 ((math-infinitep b) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1899 '(var nan var-nan)) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1900 ;; Some intervals |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1901 ((and (eq (car b) 'intv) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1902 calc-infinite-mode |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1903 (math-negp (nth 2 b)) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1904 (math-posp (nth 3 b))) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1905 '(intv 3 (neg (var inf var-inf)) (var inf var-inf))) |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1906 ;; If none of the above, leave it alone. |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1907 (t |
f6af195898b4
(math-pow-of-zero): Take into account different cases.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58510
diff
changeset
|
1908 (list '^ a b)))) |
40785 | 1909 |
1910 (defun math-pow-zero (a b) | |
1911 (if (eq (car-safe a) 'mod) | |
1912 (math-make-mod 1 (nth 2 a)) | |
1913 (if (math-known-matrixp a) | |
1914 (math-mimic-ident 1 a) | |
1915 (if (math-infinitep a) | |
1916 '(var nan var-nan) | |
1917 (if (and (eq (car a) 'intv) (math-intv-constp a) | |
1918 (or (and (not (math-posp a)) (not (math-negp a))) | |
1919 (not (math-intv-constp a t)))) | |
1920 '(intv 3 (neg (var inf var-inf)) (var inf var-inf)) | |
1921 (if (or (math-floatp a) (math-floatp b)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
1922 '(float 1 0) 1)))))) |
40785 | 1923 |
1924 (defun math-pow-fancy (a b) | |
1925 (cond ((and (Math-numberp a) (Math-numberp b)) | |
1926 (or (if (memq (math-quarter-integer b) '(1 2 3)) | |
1927 (let ((sqrt (math-sqrt (if (math-floatp b) | |
1928 (math-float a) a)))) | |
1929 (and (Math-numberp sqrt) | |
1930 (math-pow sqrt (math-mul 2 b)))) | |
1931 (and (eq (car b) 'frac) | |
1932 (integerp (nth 2 b)) | |
1933 (<= (nth 2 b) 10) | |
1934 (let ((root (math-nth-root a (nth 2 b)))) | |
1935 (and root (math-ipow root (nth 1 b)))))) | |
1936 (and (or (eq a 10) (equal a '(float 1 1))) | |
1937 (math-num-integerp b) | |
1938 (calcFunc-scf '(float 1 0) b)) | |
1939 (and calc-symbolic-mode | |
1940 (list '^ a b)) | |
1941 (math-with-extra-prec 2 | |
1942 (math-exp-raw | |
1943 (math-float (math-mul b (math-ln-raw (math-float a)))))))) | |
1944 ((or (not (Math-objvecp a)) | |
1945 (not (Math-objectp b))) | |
1946 (let (temp) | |
1947 (cond ((and math-simplify-only | |
1948 (not (equal a math-simplify-only))) | |
1949 (list '^ a b)) | |
65899
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1950 ((and (eq (car-safe a) '*) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1951 (or |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1952 (and |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1953 (math-known-matrixp (nth 1 a)) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1954 (math-known-matrixp (nth 2 a))) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1955 (and |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1956 calc-matrix-mode |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1957 (not (eq calc-matrix-mode 'scalar)) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1958 (and (not (math-known-scalarp (nth 1 a))) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1959 (not (math-known-scalarp (nth 2 a))))))) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1960 (if (and (= b -1) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1961 (math-known-square-matrixp (nth 1 a)) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1962 (math-known-square-matrixp (nth 2 a))) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1963 (list '* (list '^ (nth 2 a) -1) (list '^ (nth 1 a) -1)) |
94998ac839a5
(math-known-square-matrixp): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
1964 (list '^ a b))) |
40785 | 1965 ((and (eq (car-safe a) '*) |
1966 (or (math-known-num-integerp b) | |
1967 (math-known-nonnegp (nth 1 a)) | |
1968 (math-known-nonnegp (nth 2 a)))) | |
1969 (math-mul (math-pow (nth 1 a) b) | |
1970 (math-pow (nth 2 a) b))) | |
1971 ((and (eq (car-safe a) '/) | |
1972 (or (math-known-num-integerp b) | |
1973 (math-known-nonnegp (nth 2 a)))) | |
1974 (math-div (math-pow (nth 1 a) b) | |
1975 (math-pow (nth 2 a) b))) | |
1976 ((and (eq (car-safe a) '/) | |
1977 (math-known-nonnegp (nth 1 a)) | |
1978 (not (math-equal-int (nth 1 a) 1))) | |
1979 (math-mul (math-pow (nth 1 a) b) | |
1980 (math-pow (math-div 1 (nth 2 a)) b))) | |
1981 ((and (eq (car-safe a) '^) | |
1982 (or (math-known-num-integerp b) | |
1983 (math-known-nonnegp (nth 1 a)))) | |
1984 (math-pow (nth 1 a) (math-mul (nth 2 a) b))) | |
1985 ((and (eq (car-safe a) 'calcFunc-sqrt) | |
1986 (or (math-known-num-integerp b) | |
1987 (math-known-nonnegp (nth 1 a)))) | |
1988 (math-pow (nth 1 a) (math-div b 2))) | |
1989 ((and (eq (car-safe a) '^) | |
1990 (math-known-evenp (nth 2 a)) | |
1991 (memq (math-quarter-integer b) '(1 2 3)) | |
1992 (math-known-realp (nth 1 a))) | |
1993 (math-abs (math-pow (nth 1 a) (math-mul (nth 2 a) b)))) | |
1994 ((and (math-looks-negp a) | |
1995 (math-known-integerp b) | |
1996 (setq temp (or (and (math-known-evenp b) | |
1997 (math-pow (math-neg a) b)) | |
1998 (and (math-known-oddp b) | |
1999 (math-neg (math-pow (math-neg a) | |
2000 b)))))) | |
2001 temp) | |
2002 ((and (eq (car-safe a) 'calcFunc-abs) | |
2003 (math-known-realp (nth 1 a)) | |
2004 (math-known-evenp b)) | |
2005 (math-pow (nth 1 a) b)) | |
2006 ((math-infinitep a) | |
2007 (cond ((equal a '(var nan var-nan)) | |
2008 a) | |
2009 ((eq (car a) 'neg) | |
2010 (math-mul (math-pow -1 b) (math-pow (nth 1 a) b))) | |
2011 ((math-posp b) | |
2012 a) | |
2013 ((math-negp b) | |
2014 (if (math-floatp b) '(float 0 0) 0)) | |
2015 ((and (eq (car-safe b) 'intv) | |
2016 (math-intv-constp b)) | |
2017 '(intv 3 0 (var inf var-inf))) | |
2018 (t | |
2019 '(var nan var-nan)))) | |
2020 ((math-infinitep b) | |
2021 (let (scale) | |
2022 (cond ((math-negp b) | |
2023 (math-pow (math-div 1 a) (math-neg b))) | |
2024 ((not (math-posp b)) | |
2025 '(var nan var-nan)) | |
2026 ((math-equal-int (setq scale (calcFunc-abssqr a)) 1) | |
2027 '(var nan var-nan)) | |
2028 ((Math-lessp scale 1) | |
2029 (if (math-floatp a) '(float 0 0) 0)) | |
2030 ((Math-lessp 1 a) | |
2031 b) | |
2032 ((Math-lessp a -1) | |
2033 '(var uinf var-uinf)) | |
2034 ((and (eq (car a) 'intv) | |
2035 (math-intv-constp a)) | |
2036 (if (Math-lessp -1 a) | |
2037 (if (math-equal-int (nth 3 a) 1) | |
2038 '(intv 3 0 1) | |
2039 '(intv 3 0 (var inf var-inf))) | |
2040 '(intv 3 (neg (var inf var-inf)) | |
2041 (var inf var-inf)))) | |
2042 (t (list '^ a b))))) | |
2043 ((and (eq (car-safe a) 'calcFunc-idn) | |
2044 (= (length a) 2) | |
2045 (math-known-num-integerp b)) | |
2046 (list 'calcFunc-idn (math-pow (nth 1 a) b))) | |
2047 (t (if (Math-objectp a) | |
2048 (calc-record-why 'objectp b) | |
2049 (calc-record-why 'objectp a)) | |
2050 (list '^ a b))))) | |
2051 ((and (eq (car-safe a) 'sdev) (eq (car-safe b) 'sdev)) | |
2052 (if (and (math-constp a) (math-constp b)) | |
2053 (math-with-extra-prec 2 | |
2054 (let* ((ln (math-ln-raw (math-float (nth 1 a)))) | |
2055 (pow (math-exp-raw | |
2056 (math-float (math-mul (nth 1 b) ln))))) | |
2057 (math-make-sdev | |
2058 pow | |
2059 (math-mul | |
2060 pow | |
2061 (math-hypot (math-mul (nth 2 a) | |
2062 (math-div (nth 1 b) (nth 1 a))) | |
2063 (math-mul (nth 2 b) ln)))))) | |
2064 (let ((pow (math-pow (nth 1 a) (nth 1 b)))) | |
2065 (math-make-sdev | |
2066 pow | |
2067 (math-mul pow | |
2068 (math-hypot (math-mul (nth 2 a) | |
2069 (math-div (nth 1 b) (nth 1 a))) | |
2070 (math-mul (nth 2 b) (calcFunc-ln | |
2071 (nth 1 a))))))))) | |
2072 ((and (eq (car-safe a) 'sdev) (Math-numberp b)) | |
2073 (if (math-constp a) | |
2074 (math-with-extra-prec 2 | |
2075 (let ((pow (math-pow (nth 1 a) (math-sub b 1)))) | |
2076 (math-make-sdev (math-mul pow (nth 1 a)) | |
2077 (math-mul pow (math-mul (nth 2 a) b))))) | |
2078 (math-make-sdev (math-pow (nth 1 a) b) | |
2079 (math-mul (math-pow (nth 1 a) (math-add b -1)) | |
2080 (math-mul (nth 2 a) b))))) | |
2081 ((and (eq (car-safe b) 'sdev) (Math-numberp a)) | |
2082 (math-with-extra-prec 2 | |
2083 (let* ((ln (math-ln-raw (math-float a))) | |
2084 (pow (calcFunc-exp (math-mul (nth 1 b) ln)))) | |
2085 (math-make-sdev pow (math-mul pow (math-mul (nth 2 b) ln)))))) | |
2086 ((and (eq (car-safe a) 'intv) (math-intv-constp a) | |
2087 (Math-realp b) | |
2088 (or (Math-natnump b) | |
2089 (Math-posp (nth 2 a)) | |
2090 (and (math-zerop (nth 2 a)) | |
2091 (or (Math-posp b) | |
2092 (and (Math-integerp b) calc-infinite-mode))) | |
2093 (Math-negp (nth 3 a)) | |
2094 (and (math-zerop (nth 3 a)) | |
2095 (or (Math-posp b) | |
2096 (and (Math-integerp b) calc-infinite-mode))))) | |
2097 (if (math-evenp b) | |
2098 (setq a (math-abs a))) | |
2099 (let ((calc-infinite-mode (if (math-zerop (nth 3 a)) -1 1))) | |
2100 (math-sort-intv (nth 1 a) | |
2101 (math-pow (nth 2 a) b) | |
2102 (math-pow (nth 3 a) b)))) | |
2103 ((and (eq (car-safe b) 'intv) (math-intv-constp b) | |
2104 (Math-realp a) (Math-posp a)) | |
2105 (math-sort-intv (nth 1 b) | |
2106 (math-pow a (nth 2 b)) | |
2107 (math-pow a (nth 3 b)))) | |
2108 ((and (eq (car-safe a) 'intv) (math-intv-constp a) | |
2109 (eq (car-safe b) 'intv) (math-intv-constp b) | |
2110 (or (and (not (Math-negp (nth 2 a))) | |
2111 (not (Math-negp (nth 2 b)))) | |
2112 (and (Math-posp (nth 2 a)) | |
2113 (not (Math-posp (nth 3 b)))))) | |
2114 (let ((lo (math-pow a (nth 2 b))) | |
2115 (hi (math-pow a (nth 3 b)))) | |
2116 (or (eq (car-safe lo) 'intv) | |
2117 (setq lo (list 'intv (if (memq (nth 1 b) '(2 3)) 3 0) lo lo))) | |
2118 (or (eq (car-safe hi) 'intv) | |
2119 (setq hi (list 'intv (if (memq (nth 1 b) '(1 3)) 3 0) hi hi))) | |
2120 (math-combine-intervals | |
2121 (nth 2 lo) (and (or (memq (nth 1 b) '(2 3)) | |
2122 (math-infinitep (nth 2 lo))) | |
2123 (memq (nth 1 lo) '(2 3))) | |
2124 (nth 3 lo) (and (or (memq (nth 1 b) '(2 3)) | |
2125 (math-infinitep (nth 3 lo))) | |
2126 (memq (nth 1 lo) '(1 3))) | |
2127 (nth 2 hi) (and (or (memq (nth 1 b) '(1 3)) | |
2128 (math-infinitep (nth 2 hi))) | |
2129 (memq (nth 1 hi) '(2 3))) | |
2130 (nth 3 hi) (and (or (memq (nth 1 b) '(1 3)) | |
2131 (math-infinitep (nth 3 hi))) | |
2132 (memq (nth 1 hi) '(1 3)))))) | |
2133 ((and (eq (car-safe a) 'mod) (eq (car-safe b) 'mod) | |
2134 (equal (nth 2 a) (nth 2 b))) | |
2135 (math-make-mod (math-pow-mod (nth 1 a) (nth 1 b) (nth 2 a)) | |
2136 (nth 2 a))) | |
2137 ((and (eq (car-safe a) 'mod) (Math-anglep b)) | |
2138 (math-make-mod (math-pow-mod (nth 1 a) b (nth 2 a)) (nth 2 a))) | |
2139 ((and (eq (car-safe b) 'mod) (Math-anglep a)) | |
2140 (math-make-mod (math-pow-mod a (nth 1 b) (nth 2 b)) (nth 2 b))) | |
2141 ((not (Math-numberp a)) | |
2142 (math-reject-arg a 'numberp)) | |
2143 (t | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2144 (math-reject-arg b 'numberp)))) |
40785 | 2145 |
2146 (defun math-quarter-integer (x) | |
2147 (if (Math-integerp x) | |
2148 0 | |
2149 (if (math-negp x) | |
2150 (progn | |
2151 (setq x (math-quarter-integer (math-neg x))) | |
2152 (and x (- 4 x))) | |
2153 (if (eq (car x) 'frac) | |
2154 (if (eq (nth 2 x) 2) | |
2155 2 | |
2156 (and (eq (nth 2 x) 4) | |
2157 (progn | |
2158 (setq x (nth 1 x)) | |
2159 (% (if (consp x) (nth 1 x) x) 4)))) | |
2160 (if (eq (car x) 'float) | |
2161 (if (>= (nth 2 x) 0) | |
2162 0 | |
2163 (if (= (nth 2 x) -1) | |
2164 (progn | |
2165 (setq x (nth 1 x)) | |
2166 (and (= (% (if (consp x) (nth 1 x) x) 10) 5) 2)) | |
2167 (if (= (nth 2 x) -2) | |
2168 (progn | |
2169 (setq x (nth 1 x) | |
2170 x (% (if (consp x) (nth 1 x) x) 100)) | |
2171 (if (= x 25) 1 | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2172 (if (= x 75) 3))))))))))) |
40785 | 2173 |
2174 ;;; This assumes A < M and M > 0. | |
2175 (defun math-pow-mod (a b m) ; [R R R R] | |
2176 (if (and (Math-integerp a) (Math-integerp b) (Math-integerp m)) | |
2177 (if (Math-negp b) | |
2178 (math-div-mod 1 (math-pow-mod a (Math-integer-neg b) m) m) | |
2179 (if (eq m 1) | |
2180 0 | |
2181 (math-pow-mod-step a b m))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2182 (math-mod (math-pow a b) m))) |
40785 | 2183 |
2184 (defun math-pow-mod-step (a n m) ; [I I I I] | |
2185 (math-working "pow" a) | |
2186 (let ((val (cond | |
2187 ((eq n 0) 1) | |
2188 ((eq n 1) a) | |
2189 (t | |
2190 (let ((rest (math-pow-mod-step | |
2191 (math-imod (math-mul a a) m) | |
2192 (math-div2 n) | |
2193 m))) | |
2194 (if (math-evenp n) | |
2195 rest | |
2196 (math-mod (math-mul a rest) m))))))) | |
2197 (math-working "pow" val) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2198 val)) |
40785 | 2199 |
2200 | |
2201 ;;; Compute the minimum of two real numbers. [R R R] [Public] | |
2202 (defun math-min (a b) | |
2203 (if (and (consp a) (eq (car a) 'intv)) | |
2204 (if (and (consp b) (eq (car b) 'intv)) | |
2205 (let ((lo (nth 2 a)) | |
2206 (lom (memq (nth 1 a) '(2 3))) | |
2207 (hi (nth 3 a)) | |
2208 (him (memq (nth 1 a) '(1 3))) | |
2209 res) | |
2210 (if (= (setq res (math-compare (nth 2 b) lo)) -1) | |
2211 (setq lo (nth 2 b) lom (memq (nth 1 b) '(2 3))) | |
2212 (if (= res 0) | |
2213 (setq lom (or lom (memq (nth 1 b) '(2 3)))))) | |
2214 (if (= (setq res (math-compare (nth 3 b) hi)) -1) | |
2215 (setq hi (nth 3 b) him (memq (nth 1 b) '(1 3))) | |
2216 (if (= res 0) | |
2217 (setq him (or him (memq (nth 1 b) '(1 3)))))) | |
2218 (math-make-intv (+ (if lom 2 0) (if him 1 0)) lo hi)) | |
2219 (math-min a (list 'intv 3 b b))) | |
2220 (if (and (consp b) (eq (car b) 'intv)) | |
2221 (math-min (list 'intv 3 a a) b) | |
2222 (let ((res (math-compare a b))) | |
2223 (if (= res 1) | |
2224 b | |
2225 (if (= res 2) | |
2226 '(var nan var-nan) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2227 a)))))) |
40785 | 2228 |
2229 (defun calcFunc-min (&optional a &rest b) | |
2230 (if (not a) | |
2231 '(var inf var-inf) | |
2232 (if (not (or (Math-anglep a) (eq (car a) 'date) | |
2233 (and (eq (car a) 'intv) (math-intv-constp a)) | |
2234 (math-infinitep a))) | |
2235 (math-reject-arg a 'anglep)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2236 (math-min-list a b))) |
40785 | 2237 |
2238 (defun math-min-list (a b) | |
2239 (if b | |
2240 (if (or (Math-anglep (car b)) (eq (car b) 'date) | |
2241 (and (eq (car (car b)) 'intv) (math-intv-constp (car b))) | |
2242 (math-infinitep (car b))) | |
2243 (math-min-list (math-min a (car b)) (cdr b)) | |
2244 (math-reject-arg (car b) 'anglep)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2245 a)) |
40785 | 2246 |
2247 ;;; Compute the maximum of two real numbers. [R R R] [Public] | |
2248 (defun math-max (a b) | |
2249 (if (or (and (consp a) (eq (car a) 'intv)) | |
2250 (and (consp b) (eq (car b) 'intv))) | |
2251 (math-neg (math-min (math-neg a) (math-neg b))) | |
2252 (let ((res (math-compare a b))) | |
2253 (if (= res -1) | |
2254 b | |
2255 (if (= res 2) | |
2256 '(var nan var-nan) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2257 a))))) |
40785 | 2258 |
2259 (defun calcFunc-max (&optional a &rest b) | |
2260 (if (not a) | |
2261 '(neg (var inf var-inf)) | |
2262 (if (not (or (Math-anglep a) (eq (car a) 'date) | |
2263 (and (eq (car a) 'intv) (math-intv-constp a)) | |
2264 (math-infinitep a))) | |
2265 (math-reject-arg a 'anglep)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2266 (math-max-list a b))) |
40785 | 2267 |
2268 (defun math-max-list (a b) | |
2269 (if b | |
2270 (if (or (Math-anglep (car b)) (eq (car b) 'date) | |
2271 (and (eq (car (car b)) 'intv) (math-intv-constp (car b))) | |
2272 (math-infinitep (car b))) | |
2273 (math-max-list (math-max a (car b)) (cdr b)) | |
2274 (math-reject-arg (car b) 'anglep)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2275 a)) |
40785 | 2276 |
2277 | |
2278 ;;; Compute the absolute value of A. [O O; r r] [Public] | |
2279 (defun math-abs (a) | |
2280 (cond ((Math-negp a) | |
2281 (math-neg a)) | |
2282 ((Math-anglep a) | |
2283 a) | |
2284 ((eq (car a) 'cplx) | |
2285 (math-hypot (nth 1 a) (nth 2 a))) | |
2286 ((eq (car a) 'polar) | |
2287 (nth 1 a)) | |
2288 ((eq (car a) 'vec) | |
2289 (if (cdr (cdr (cdr a))) | |
2290 (math-sqrt (calcFunc-abssqr a)) | |
2291 (if (cdr (cdr a)) | |
2292 (math-hypot (nth 1 a) (nth 2 a)) | |
2293 (if (cdr a) | |
2294 (math-abs (nth 1 a)) | |
2295 a)))) | |
2296 ((eq (car a) 'sdev) | |
2297 (list 'sdev (math-abs (nth 1 a)) (nth 2 a))) | |
2298 ((and (eq (car a) 'intv) (math-intv-constp a)) | |
2299 (if (Math-posp a) | |
2300 a | |
2301 (let* ((nlo (math-neg (nth 2 a))) | |
2302 (res (math-compare nlo (nth 3 a)))) | |
2303 (cond ((= res 1) | |
2304 (math-make-intv (if (memq (nth 1 a) '(0 1)) 2 3) 0 nlo)) | |
2305 ((= res 0) | |
2306 (math-make-intv (if (eq (nth 1 a) 0) 2 3) 0 nlo)) | |
2307 (t | |
2308 (math-make-intv (if (memq (nth 1 a) '(0 2)) 2 3) | |
2309 0 (nth 3 a))))))) | |
2310 ((math-looks-negp a) | |
2311 (list 'calcFunc-abs (math-neg a))) | |
2312 ((let ((signs (math-possible-signs a))) | |
2313 (or (and (memq signs '(2 4 6)) a) | |
2314 (and (memq signs '(1 3)) (math-neg a))))) | |
2315 ((let ((inf (math-infinitep a))) | |
2316 (and inf | |
2317 (if (equal inf '(var nan var-nan)) | |
2318 inf | |
2319 '(var inf var-inf))))) | |
2320 (t (calc-record-why 'numvecp a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2321 (list 'calcFunc-abs a)))) |
40785 | 2322 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2323 (defalias 'calcFunc-abs 'math-abs) |
40785 | 2324 |
2325 (defun math-float-fancy (a) | |
2326 (cond ((eq (car a) 'intv) | |
2327 (cons (car a) (cons (nth 1 a) (mapcar 'math-float (nthcdr 2 a))))) | |
2328 ((and (memq (car a) '(* /)) | |
2329 (math-numberp (nth 1 a))) | |
2330 (list (car a) (math-float (nth 1 a)) | |
2331 (list 'calcFunc-float (nth 2 a)))) | |
2332 ((and (eq (car a) '/) | |
2333 (eq (car (nth 1 a)) '*) | |
2334 (math-numberp (nth 1 (nth 1 a)))) | |
2335 (list '* (math-float (nth 1 (nth 1 a))) | |
2336 (list 'calcFunc-float (list '/ (nth 2 (nth 1 a)) (nth 2 a))))) | |
2337 ((math-infinitep a) a) | |
2338 ((eq (car a) 'calcFunc-float) a) | |
2339 ((let ((func (assq (car a) '((calcFunc-floor . calcFunc-ffloor) | |
2340 (calcFunc-ceil . calcFunc-fceil) | |
2341 (calcFunc-trunc . calcFunc-ftrunc) | |
2342 (calcFunc-round . calcFunc-fround) | |
2343 (calcFunc-rounde . calcFunc-frounde) | |
2344 (calcFunc-roundu . calcFunc-froundu))))) | |
2345 (and func (cons (cdr func) (cdr a))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2346 (t (math-reject-arg a 'objectp)))) |
40785 | 2347 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2348 (defalias 'calcFunc-float 'math-float) |
40785 | 2349 |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2350 ;; The variable math-trunc-prec is local to math-trunc in calc-misc.el, |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2351 ;; but used by math-trunc-fancy which is called by math-trunc. |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2352 (defvar math-trunc-prec) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2353 |
40785 | 2354 (defun math-trunc-fancy (a) |
2355 (cond ((eq (car a) 'frac) (math-quotient (nth 1 a) (nth 2 a))) | |
2356 ((eq (car a) 'cplx) (math-trunc (nth 1 a))) | |
2357 ((eq (car a) 'polar) (math-trunc (math-complex a))) | |
2358 ((eq (car a) 'hms) (list 'hms (nth 1 a) 0 0)) | |
2359 ((eq (car a) 'date) (list 'date (math-trunc (nth 1 a)))) | |
2360 ((eq (car a) 'mod) | |
2361 (if (math-messy-integerp (nth 2 a)) | |
2362 (math-trunc (math-make-mod (nth 1 a) (math-trunc (nth 2 a)))) | |
2363 (math-make-mod (math-trunc (nth 1 a)) (nth 2 a)))) | |
2364 ((eq (car a) 'intv) | |
2365 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf))) | |
2366 (memq (nth 1 a) '(0 1))) | |
2367 0 2) | |
2368 (if (and (equal (nth 3 a) '(var inf var-inf)) | |
2369 (memq (nth 1 a) '(0 2))) | |
2370 0 1)) | |
2371 (if (and (Math-negp (nth 2 a)) | |
2372 (Math-num-integerp (nth 2 a)) | |
2373 (memq (nth 1 a) '(0 1))) | |
2374 (math-add (math-trunc (nth 2 a)) 1) | |
2375 (math-trunc (nth 2 a))) | |
2376 (if (and (Math-posp (nth 3 a)) | |
2377 (Math-num-integerp (nth 3 a)) | |
2378 (memq (nth 1 a) '(0 2))) | |
2379 (math-add (math-trunc (nth 3 a)) -1) | |
2380 (math-trunc (nth 3 a))))) | |
2381 ((math-provably-integerp a) a) | |
2382 ((Math-vectorp a) | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2383 (math-map-vec (function (lambda (x) (math-trunc x math-trunc-prec))) a)) |
40785 | 2384 ((math-infinitep a) |
2385 (if (or (math-posp a) (math-negp a)) | |
2386 a | |
2387 '(var nan var-nan))) | |
2388 ((math-to-integer a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2389 (t (math-reject-arg a 'numberp)))) |
40785 | 2390 |
2391 (defun math-trunc-special (a prec) | |
2392 (if (Math-messy-integerp prec) | |
2393 (setq prec (math-trunc prec))) | |
2394 (or (integerp prec) | |
2395 (math-reject-arg prec 'fixnump)) | |
2396 (if (and (<= prec 0) | |
2397 (math-provably-integerp a)) | |
2398 a | |
2399 (calcFunc-scf (math-trunc (let ((calc-prefer-frac t)) | |
2400 (calcFunc-scf a prec))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2401 (- prec)))) |
40785 | 2402 |
2403 (defun math-to-integer (a) | |
2404 (let ((func (assq (car-safe a) '((calcFunc-ffloor . calcFunc-floor) | |
2405 (calcFunc-fceil . calcFunc-ceil) | |
2406 (calcFunc-ftrunc . calcFunc-trunc) | |
2407 (calcFunc-fround . calcFunc-round) | |
2408 (calcFunc-frounde . calcFunc-rounde) | |
2409 (calcFunc-froundu . calcFunc-roundu))))) | |
2410 (and func (= (length a) 2) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2411 (cons (cdr func) (cdr a))))) |
40785 | 2412 |
2413 (defun calcFunc-ftrunc (a &optional prec) | |
2414 (if (and (Math-messy-integerp a) | |
2415 (or (not prec) (and (integerp prec) | |
2416 (<= prec 0)))) | |
2417 a | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2418 (math-float (math-trunc a prec)))) |
40785 | 2419 |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2420 ;; The variable math-floor-prec is local to math-floor in calc-misc.el, |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2421 ;; but used by math-floor-fancy which is called by math-floor. |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2422 (defvar math-floor-prec) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2423 |
40785 | 2424 (defun math-floor-fancy (a) |
2425 (cond ((math-provably-integerp a) a) | |
2426 ((eq (car a) 'hms) | |
2427 (if (or (math-posp a) | |
2428 (and (math-zerop (nth 2 a)) | |
2429 (math-zerop (nth 3 a)))) | |
2430 (math-trunc a) | |
2431 (math-add (math-trunc a) -1))) | |
2432 ((eq (car a) 'date) (list 'date (math-floor (nth 1 a)))) | |
2433 ((eq (car a) 'intv) | |
2434 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf))) | |
2435 (memq (nth 1 a) '(0 1))) | |
2436 0 2) | |
2437 (if (and (equal (nth 3 a) '(var inf var-inf)) | |
2438 (memq (nth 1 a) '(0 2))) | |
2439 0 1)) | |
2440 (math-floor (nth 2 a)) | |
2441 (if (and (Math-num-integerp (nth 3 a)) | |
2442 (memq (nth 1 a) '(0 2))) | |
2443 (math-add (math-floor (nth 3 a)) -1) | |
2444 (math-floor (nth 3 a))))) | |
2445 ((Math-vectorp a) | |
58510
b1042b68790c
Finish making previous change.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58479
diff
changeset
|
2446 (math-map-vec (function (lambda (x) (math-floor x math-floor-prec))) a)) |
40785 | 2447 ((math-infinitep a) |
2448 (if (or (math-posp a) (math-negp a)) | |
2449 a | |
2450 '(var nan var-nan))) | |
2451 ((math-to-integer a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2452 (t (math-reject-arg a 'anglep)))) |
40785 | 2453 |
2454 (defun math-floor-special (a prec) | |
2455 (if (Math-messy-integerp prec) | |
2456 (setq prec (math-trunc prec))) | |
2457 (or (integerp prec) | |
2458 (math-reject-arg prec 'fixnump)) | |
2459 (if (and (<= prec 0) | |
2460 (math-provably-integerp a)) | |
2461 a | |
2462 (calcFunc-scf (math-floor (let ((calc-prefer-frac t)) | |
2463 (calcFunc-scf a prec))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2464 (- prec)))) |
40785 | 2465 |
2466 (defun calcFunc-ffloor (a &optional prec) | |
2467 (if (and (Math-messy-integerp a) | |
2468 (or (not prec) (and (integerp prec) | |
2469 (<= prec 0)))) | |
2470 a | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2471 (math-float (math-floor a prec)))) |
40785 | 2472 |
2473 ;;; Coerce A to be an integer (by truncation toward plus infinity). [I N] | |
2474 (defun math-ceiling (a &optional prec) ; [Public] | |
2475 (cond (prec | |
2476 (if (Math-messy-integerp prec) | |
2477 (setq prec (math-trunc prec))) | |
2478 (or (integerp prec) | |
2479 (math-reject-arg prec 'fixnump)) | |
2480 (if (and (<= prec 0) | |
2481 (math-provably-integerp a)) | |
2482 a | |
2483 (calcFunc-scf (math-ceiling (let ((calc-prefer-frac t)) | |
2484 (calcFunc-scf a prec))) | |
2485 (- prec)))) | |
2486 ((Math-integerp a) a) | |
2487 ((Math-messy-integerp a) (math-trunc a)) | |
2488 ((Math-realp a) | |
2489 (if (Math-posp a) | |
2490 (math-add (math-trunc a) 1) | |
2491 (math-trunc a))) | |
2492 ((math-provably-integerp a) a) | |
2493 ((eq (car a) 'hms) | |
2494 (if (or (math-negp a) | |
2495 (and (math-zerop (nth 2 a)) | |
2496 (math-zerop (nth 3 a)))) | |
2497 (math-trunc a) | |
2498 (math-add (math-trunc a) 1))) | |
2499 ((eq (car a) 'date) (list 'date (math-ceiling (nth 1 a)))) | |
2500 ((eq (car a) 'intv) | |
2501 (math-make-intv (+ (if (and (equal (nth 2 a) '(neg (var inf var-inf))) | |
2502 (memq (nth 1 a) '(0 1))) | |
2503 0 2) | |
2504 (if (and (equal (nth 3 a) '(var inf var-inf)) | |
2505 (memq (nth 1 a) '(0 2))) | |
2506 0 1)) | |
2507 (if (and (Math-num-integerp (nth 2 a)) | |
2508 (memq (nth 1 a) '(0 1))) | |
2509 (math-add (math-floor (nth 2 a)) 1) | |
2510 (math-ceiling (nth 2 a))) | |
2511 (math-ceiling (nth 3 a)))) | |
2512 ((Math-vectorp a) | |
2513 (math-map-vec (function (lambda (x) (math-ceiling x prec))) a)) | |
2514 ((math-infinitep a) | |
2515 (if (or (math-posp a) (math-negp a)) | |
2516 a | |
2517 '(var nan var-nan))) | |
2518 ((math-to-integer a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2519 (t (math-reject-arg a 'anglep)))) |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2520 |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2521 (defalias 'calcFunc-ceil 'math-ceiling) |
40785 | 2522 |
2523 (defun calcFunc-fceil (a &optional prec) | |
2524 (if (and (Math-messy-integerp a) | |
2525 (or (not prec) (and (integerp prec) | |
2526 (<= prec 0)))) | |
2527 a | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2528 (math-float (math-ceiling a prec)))) |
40785 | 2529 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
2530 (defvar math-rounding-mode nil) |
40785 | 2531 |
2532 ;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public] | |
2533 (defun math-round (a &optional prec) | |
2534 (cond (prec | |
2535 (if (Math-messy-integerp prec) | |
2536 (setq prec (math-trunc prec))) | |
2537 (or (integerp prec) | |
2538 (math-reject-arg prec 'fixnump)) | |
2539 (if (and (<= prec 0) | |
2540 (math-provably-integerp a)) | |
2541 a | |
2542 (calcFunc-scf (math-round (let ((calc-prefer-frac t)) | |
2543 (calcFunc-scf a prec))) | |
2544 (- prec)))) | |
2545 ((Math-anglep a) | |
2546 (if (Math-num-integerp a) | |
2547 (math-trunc a) | |
2548 (if (and (Math-negp a) (not (eq math-rounding-mode 'up))) | |
2549 (math-neg (math-round (math-neg a))) | |
2550 (setq a (let ((calc-angle-mode 'deg)) ; in case of HMS forms | |
2551 (math-add a (if (Math-ratp a) | |
2552 '(frac 1 2) | |
2553 '(float 5 -1))))) | |
2554 (if (and (Math-num-integerp a) (eq math-rounding-mode 'even)) | |
2555 (progn | |
2556 (setq a (math-floor a)) | |
2557 (or (math-evenp a) | |
2558 (setq a (math-sub a 1))) | |
2559 a) | |
2560 (math-floor a))))) | |
2561 ((math-provably-integerp a) a) | |
2562 ((eq (car a) 'date) (list 'date (math-round (nth 1 a)))) | |
2563 ((eq (car a) 'intv) | |
2564 (math-floor (math-add a '(frac 1 2)))) | |
2565 ((Math-vectorp a) | |
2566 (math-map-vec (function (lambda (x) (math-round x prec))) a)) | |
2567 ((math-infinitep a) | |
2568 (if (or (math-posp a) (math-negp a)) | |
2569 a | |
2570 '(var nan var-nan))) | |
2571 ((math-to-integer a)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2572 (t (math-reject-arg a 'anglep)))) |
40785 | 2573 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2574 (defalias 'calcFunc-round 'math-round) |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2575 |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2576 (defsubst calcFunc-rounde (a &optional prec) |
40785 | 2577 (let ((math-rounding-mode 'even)) |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2578 (math-round a prec))) |
40785 | 2579 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2580 (defsubst calcFunc-roundu (a &optional prec) |
40785 | 2581 (let ((math-rounding-mode 'up)) |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2582 (math-round a prec))) |
40785 | 2583 |
2584 (defun calcFunc-fround (a &optional prec) | |
2585 (if (and (Math-messy-integerp a) | |
2586 (or (not prec) (and (integerp prec) | |
2587 (<= prec 0)))) | |
2588 a | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2589 (math-float (math-round a prec)))) |
40785 | 2590 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2591 (defsubst calcFunc-frounde (a &optional prec) |
40785 | 2592 (let ((math-rounding-mode 'even)) |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2593 (calcFunc-fround a prec))) |
40785 | 2594 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2595 (defsubst calcFunc-froundu (a &optional prec) |
40785 | 2596 (let ((math-rounding-mode 'up)) |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2597 (calcFunc-fround a prec))) |
40785 | 2598 |
2599 ;;; Pull floating-point values apart into mantissa and exponent. | |
2600 (defun calcFunc-mant (x) | |
2601 (if (Math-realp x) | |
2602 (if (or (Math-ratp x) | |
2603 (eq (nth 1 x) 0)) | |
2604 x | |
2605 (list 'float (nth 1 x) (- 1 (math-numdigs (nth 1 x))))) | |
2606 (calc-record-why 'realp x) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2607 (list 'calcFunc-mant x))) |
40785 | 2608 |
2609 (defun calcFunc-xpon (x) | |
2610 (if (Math-realp x) | |
2611 (if (or (Math-ratp x) | |
2612 (eq (nth 1 x) 0)) | |
2613 0 | |
2614 (math-normalize (+ (nth 2 x) (1- (math-numdigs (nth 1 x)))))) | |
2615 (calc-record-why 'realp x) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2616 (list 'calcFunc-xpon x))) |
40785 | 2617 |
2618 (defun calcFunc-scf (x n) | |
2619 (if (integerp n) | |
2620 (cond ((eq n 0) | |
2621 x) | |
2622 ((Math-integerp x) | |
2623 (if (> n 0) | |
2624 (math-scale-int x n) | |
2625 (math-div x (math-scale-int 1 (- n))))) | |
2626 ((eq (car x) 'frac) | |
2627 (if (> n 0) | |
2628 (math-make-frac (math-scale-int (nth 1 x) n) (nth 2 x)) | |
2629 (math-make-frac (nth 1 x) (math-scale-int (nth 2 x) (- n))))) | |
2630 ((eq (car x) 'float) | |
2631 (math-make-float (nth 1 x) (+ (nth 2 x) n))) | |
2632 ((memq (car x) '(cplx sdev)) | |
2633 (math-normalize | |
2634 (list (car x) | |
2635 (calcFunc-scf (nth 1 x) n) | |
2636 (calcFunc-scf (nth 2 x) n)))) | |
2637 ((memq (car x) '(polar mod)) | |
2638 (math-normalize | |
2639 (list (car x) | |
2640 (calcFunc-scf (nth 1 x) n) | |
2641 (nth 2 x)))) | |
2642 ((eq (car x) 'intv) | |
2643 (math-normalize | |
2644 (list (car x) | |
2645 (nth 1 x) | |
2646 (calcFunc-scf (nth 2 x) n) | |
2647 (calcFunc-scf (nth 3 x) n)))) | |
2648 ((eq (car x) 'vec) | |
2649 (math-map-vec (function (lambda (x) (calcFunc-scf x n))) x)) | |
2650 ((math-infinitep x) | |
2651 x) | |
2652 (t | |
2653 (calc-record-why 'realp x) | |
2654 (list 'calcFunc-scf x n))) | |
2655 (if (math-messy-integerp n) | |
2656 (if (< (nth 2 n) 10) | |
2657 (calcFunc-scf x (math-trunc n)) | |
2658 (math-overflow n)) | |
2659 (if (math-integerp n) | |
2660 (math-overflow n) | |
2661 (calc-record-why 'integerp n) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2662 (list 'calcFunc-scf x n))))) |
40785 | 2663 |
2664 | |
2665 (defun calcFunc-incr (x &optional step relative-to) | |
2666 (or step (setq step 1)) | |
2667 (cond ((not (Math-integerp step)) | |
2668 (math-reject-arg step 'integerp)) | |
2669 ((Math-integerp x) | |
2670 (math-add x step)) | |
2671 ((eq (car x) 'float) | |
2672 (if (and (math-zerop x) | |
2673 (eq (car-safe relative-to) 'float)) | |
2674 (math-mul step | |
2675 (calcFunc-scf relative-to (- 1 calc-internal-prec))) | |
2676 (math-add-float x (math-make-float | |
2677 step | |
2678 (+ (nth 2 x) | |
2679 (- (math-numdigs (nth 1 x)) | |
2680 calc-internal-prec)))))) | |
2681 ((eq (car x) 'date) | |
2682 (if (Math-integerp (nth 1 x)) | |
2683 (math-add x step) | |
2684 (math-add x (list 'hms 0 0 step)))) | |
2685 (t | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2686 (math-reject-arg x 'realp)))) |
40785 | 2687 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2688 (defsubst calcFunc-decr (x &optional step relative-to) |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2689 (calcFunc-incr x (math-neg (or step 1)) relative-to)) |
40785 | 2690 |
2691 (defun calcFunc-percent (x) | |
2692 (if (math-objectp x) | |
2693 (let ((calc-prefer-frac nil)) | |
2694 (math-div x 100)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2695 (list 'calcFunc-percent x))) |
40785 | 2696 |
2697 (defun calcFunc-relch (x y) | |
2698 (if (and (math-objectp x) (math-objectp y)) | |
2699 (math-div (math-sub y x) x) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2700 (list 'calcFunc-relch x y))) |
40785 | 2701 |
2702 ;;; Compute the absolute value squared of A. [F N] [Public] | |
2703 (defun calcFunc-abssqr (a) | |
2704 (cond ((Math-realp a) | |
2705 (math-mul a a)) | |
2706 ((eq (car a) 'cplx) | |
2707 (math-add (math-sqr (nth 1 a)) | |
2708 (math-sqr (nth 2 a)))) | |
2709 ((eq (car a) 'polar) | |
2710 (math-sqr (nth 1 a))) | |
2711 ((and (memq (car a) '(sdev intv)) (math-constp a)) | |
2712 (math-sqr (math-abs a))) | |
2713 ((eq (car a) 'vec) | |
2714 (math-reduce-vec 'math-add (math-map-vec 'calcFunc-abssqr a))) | |
2715 ((math-known-realp a) | |
2716 (math-pow a 2)) | |
2717 ((let ((inf (math-infinitep a))) | |
2718 (and inf | |
2719 (math-mul (calcFunc-abssqr (math-infinite-dir a inf)) inf)))) | |
2720 (t (calc-record-why 'numvecp a) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2721 (list 'calcFunc-abssqr a)))) |
40785 | 2722 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2723 (defsubst math-sqr (a) |
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2724 (math-mul a a)) |
40785 | 2725 |
2726 ;;;; Number theory. | |
2727 | |
2728 (defun calcFunc-idiv (a b) ; [I I I] [Public] | |
2729 (cond ((and (Math-natnump a) (Math-natnump b) (not (eq b 0))) | |
2730 (math-quotient a b)) | |
2731 ((Math-realp a) | |
2732 (if (Math-realp b) | |
2733 (let ((calc-prefer-frac t)) | |
2734 (math-floor (math-div a b))) | |
2735 (math-reject-arg b 'realp))) | |
2736 ((eq (car-safe a) 'hms) | |
2737 (if (eq (car-safe b) 'hms) | |
2738 (let ((calc-prefer-frac t)) | |
2739 (math-floor (math-div a b))) | |
2740 (math-reject-arg b 'hmsp))) | |
2741 ((and (or (eq (car-safe a) 'intv) (Math-realp a)) | |
2742 (or (eq (car-safe b) 'intv) (Math-realp b))) | |
2743 (math-floor (math-div a b))) | |
2744 ((or (math-infinitep a) | |
2745 (math-infinitep b)) | |
2746 (math-div a b)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2747 (t (math-reject-arg a 'anglep)))) |
40785 | 2748 |
2749 | |
2750 ;;; Combine two terms being added, if possible. | |
2751 (defun math-combine-sum (a b nega negb scalar-okay) | |
2752 (if (and scalar-okay (Math-objvecp a) (Math-objvecp b)) | |
2753 (math-add-or-sub a b nega negb) | |
2754 (let ((amult 1) (bmult 1)) | |
2755 (and (consp a) | |
2756 (cond ((and (eq (car a) '*) | |
2757 (Math-objectp (nth 1 a))) | |
2758 (setq amult (nth 1 a) | |
2759 a (nth 2 a))) | |
2760 ((and (eq (car a) '/) | |
2761 (Math-objectp (nth 2 a))) | |
2762 (setq amult (if (Math-integerp (nth 2 a)) | |
2763 (list 'frac 1 (nth 2 a)) | |
2764 (math-div 1 (nth 2 a))) | |
2765 a (nth 1 a))) | |
2766 ((eq (car a) 'neg) | |
2767 (setq amult -1 | |
2768 a (nth 1 a))))) | |
2769 (and (consp b) | |
2770 (cond ((and (eq (car b) '*) | |
2771 (Math-objectp (nth 1 b))) | |
2772 (setq bmult (nth 1 b) | |
2773 b (nth 2 b))) | |
2774 ((and (eq (car b) '/) | |
2775 (Math-objectp (nth 2 b))) | |
2776 (setq bmult (if (Math-integerp (nth 2 b)) | |
2777 (list 'frac 1 (nth 2 b)) | |
2778 (math-div 1 (nth 2 b))) | |
2779 b (nth 1 b))) | |
2780 ((eq (car b) 'neg) | |
2781 (setq bmult -1 | |
2782 b (nth 1 b))))) | |
2783 (and (if math-simplifying | |
2784 (Math-equal a b) | |
2785 (equal a b)) | |
2786 (progn | |
2787 (if nega (setq amult (math-neg amult))) | |
2788 (if negb (setq bmult (math-neg bmult))) | |
2789 (setq amult (math-add amult bmult)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2790 (math-mul amult a)))))) |
40785 | 2791 |
2792 (defun math-add-or-sub (a b aneg bneg) | |
2793 (if aneg (setq a (math-neg a))) | |
2794 (if bneg (setq b (math-neg b))) | |
2795 (if (or (Math-vectorp a) (Math-vectorp b)) | |
2796 (math-normalize (list '+ a b)) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2797 (math-add a b))) |
40785 | 2798 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
2799 (defvar math-combine-prod-e '(var e var-e)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41041
diff
changeset
|
2800 |
40785 | 2801 ;;; The following is expanded out four ways for speed. |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2802 |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2803 ;; math-unit-prefixes is defined in calc-units.el, |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2804 ;; but used here. |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2805 (defvar math-unit-prefixes) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
2806 |
40785 | 2807 (defun math-combine-prod (a b inva invb scalar-okay) |
2808 (cond | |
2809 ((or (and inva (Math-zerop a)) | |
2810 (and invb (Math-zerop b))) | |
2811 nil) | |
2812 ((and scalar-okay (Math-objvecp a) (Math-objvecp b)) | |
2813 (setq a (math-mul-or-div a b inva invb)) | |
2814 (and (Math-objvecp a) | |
2815 a)) | |
2816 ((and (eq (car-safe a) '^) | |
2817 inva | |
2818 (math-looks-negp (nth 2 a))) | |
2819 (math-mul (math-pow (nth 1 a) (math-neg (nth 2 a))) b)) | |
2820 ((and (eq (car-safe b) '^) | |
2821 invb | |
2822 (math-looks-negp (nth 2 b))) | |
2823 (math-mul a (math-pow (nth 1 b) (math-neg (nth 2 b))))) | |
60154
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2824 ((and math-simplifying |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2825 (math-combine-prod-trig a b))) |
40785 | 2826 (t (let ((apow 1) (bpow 1)) |
2827 (and (consp a) | |
2828 (cond ((and (eq (car a) '^) | |
2829 (or math-simplifying | |
2830 (Math-numberp (nth 2 a)))) | |
2831 (setq apow (nth 2 a) | |
2832 a (nth 1 a))) | |
2833 ((eq (car a) 'calcFunc-sqrt) | |
2834 (setq apow '(frac 1 2) | |
2835 a (nth 1 a))) | |
2836 ((and (eq (car a) 'calcFunc-exp) | |
2837 (or math-simplifying | |
2838 (Math-numberp (nth 1 a)))) | |
2839 (setq apow (nth 1 a) | |
2840 a math-combine-prod-e)))) | |
2841 (and (consp a) (eq (car a) 'frac) | |
2842 (Math-lessp (nth 1 a) (nth 2 a)) | |
2843 (setq a (math-div 1 a) apow (math-neg apow))) | |
2844 (and (consp b) | |
2845 (cond ((and (eq (car b) '^) | |
2846 (or math-simplifying | |
2847 (Math-numberp (nth 2 b)))) | |
2848 (setq bpow (nth 2 b) | |
2849 b (nth 1 b))) | |
2850 ((eq (car b) 'calcFunc-sqrt) | |
2851 (setq bpow '(frac 1 2) | |
2852 b (nth 1 b))) | |
2853 ((and (eq (car b) 'calcFunc-exp) | |
2854 (or math-simplifying | |
2855 (Math-numberp (nth 1 b)))) | |
2856 (setq bpow (nth 1 b) | |
2857 b math-combine-prod-e)))) | |
2858 (and (consp b) (eq (car b) 'frac) | |
2859 (Math-lessp (nth 1 b) (nth 2 b)) | |
2860 (setq b (math-div 1 b) bpow (math-neg bpow))) | |
2861 (if inva (setq apow (math-neg apow))) | |
2862 (if invb (setq bpow (math-neg bpow))) | |
2863 (or (and (if math-simplifying | |
2864 (math-commutative-equal a b) | |
2865 (equal a b)) | |
2866 (let ((sumpow (math-add apow bpow))) | |
2867 (and (or (not (Math-integerp a)) | |
2868 (Math-zerop sumpow) | |
2869 (eq (eq (car-safe apow) 'frac) | |
2870 (eq (car-safe bpow) 'frac))) | |
2871 (progn | |
2872 (and (math-looks-negp sumpow) | |
2873 (Math-ratp a) (Math-posp a) | |
2874 (setq a (math-div 1 a) | |
2875 sumpow (math-neg sumpow))) | |
2876 (cond ((equal sumpow '(frac 1 2)) | |
2877 (list 'calcFunc-sqrt a)) | |
2878 ((equal sumpow '(frac -1 2)) | |
2879 (math-div 1 (list 'calcFunc-sqrt a))) | |
2880 ((and (eq a math-combine-prod-e) | |
2881 (eq a b)) | |
2882 (list 'calcFunc-exp sumpow)) | |
2883 (t | |
2884 (condition-case err | |
2885 (math-pow a sumpow) | |
2886 (inexact-result (list '^ a sumpow))))))))) | |
2887 (and math-simplifying-units | |
2888 math-combining-units | |
2889 (let* ((ua (math-check-unit-name a)) | |
2890 ub) | |
2891 (and ua | |
2892 (eq ua (setq ub (math-check-unit-name b))) | |
2893 (progn | |
2894 (setq ua (if (eq (nth 1 a) (car ua)) | |
2895 1 | |
2896 (nth 1 (assq (aref (symbol-name (nth 1 a)) | |
2897 0) | |
2898 math-unit-prefixes))) | |
2899 ub (if (eq (nth 1 b) (car ub)) | |
2900 1 | |
2901 (nth 1 (assq (aref (symbol-name (nth 1 b)) | |
2902 0) | |
2903 math-unit-prefixes)))) | |
2904 (if (Math-lessp ua ub) | |
2905 (let (temp) | |
2906 (setq temp a a b b temp | |
2907 temp ua ua ub ub temp | |
2908 temp apow apow bpow bpow temp))) | |
2909 (math-mul (math-pow (math-div ua ub) apow) | |
2910 (math-pow b (math-add apow bpow))))))) | |
2911 (and (equal apow bpow) | |
2912 (Math-natnump a) (Math-natnump b) | |
2913 (cond ((equal apow '(frac 1 2)) | |
2914 (list 'calcFunc-sqrt (math-mul a b))) | |
2915 ((equal apow '(frac -1 2)) | |
2916 (math-div 1 (list 'calcFunc-sqrt (math-mul a b)))) | |
2917 (t | |
2918 (setq a (math-mul a b)) | |
2919 (condition-case err | |
2920 (math-pow a apow) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2921 (inexact-result (list '^ a apow))))))))))) |
40785 | 2922 |
60154
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2923 (defun math-combine-prod-trig (a b) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2924 (cond |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2925 ((and (eq (car-safe a) 'calcFunc-sin) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2926 (eq (car-safe b) 'calcFunc-csc) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2927 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2928 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2929 ((and (eq (car-safe a) 'calcFunc-sin) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2930 (eq (car-safe b) 'calcFunc-sec) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2931 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2932 (cons 'calcFunc-tan (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2933 ((and (eq (car-safe a) 'calcFunc-sin) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2934 (eq (car-safe b) 'calcFunc-cot) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2935 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2936 (cons 'calcFunc-cos (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2937 ((and (eq (car-safe a) 'calcFunc-cos) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2938 (eq (car-safe b) 'calcFunc-sec) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2939 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2940 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2941 ((and (eq (car-safe a) 'calcFunc-cos) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2942 (eq (car-safe b) 'calcFunc-csc) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2943 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2944 (cons 'calcFunc-cot (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2945 ((and (eq (car-safe a) 'calcFunc-cos) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2946 (eq (car-safe b) 'calcFunc-tan) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2947 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2948 (cons 'calcFunc-sin (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2949 ((and (eq (car-safe a) 'calcFunc-tan) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2950 (eq (car-safe b) 'calcFunc-cot) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2951 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2952 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2953 ((and (eq (car-safe a) 'calcFunc-tan) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2954 (eq (car-safe b) 'calcFunc-csc) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2955 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2956 (cons 'calcFunc-sec (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2957 ((and (eq (car-safe a) 'calcFunc-sec) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2958 (eq (car-safe b) 'calcFunc-cot) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2959 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2960 (cons 'calcFunc-csc (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2961 ((and (eq (car-safe a) 'calcFunc-sinh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2962 (eq (car-safe b) 'calcFunc-csch) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2963 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2964 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2965 ((and (eq (car-safe a) 'calcFunc-sinh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2966 (eq (car-safe b) 'calcFunc-sech) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2967 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2968 (cons 'calcFunc-tanh (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2969 ((and (eq (car-safe a) 'calcFunc-sinh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2970 (eq (car-safe b) 'calcFunc-coth) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2971 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2972 (cons 'calcFunc-cosh (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2973 ((and (eq (car-safe a) 'calcFunc-cosh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2974 (eq (car-safe b) 'calcFunc-sech) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2975 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2976 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2977 ((and (eq (car-safe a) 'calcFunc-cosh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2978 (eq (car-safe b) 'calcFunc-csch) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2979 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2980 (cons 'calcFunc-coth (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2981 ((and (eq (car-safe a) 'calcFunc-cosh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2982 (eq (car-safe b) 'calcFunc-tanh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2983 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2984 (cons 'calcFunc-sinh (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2985 ((and (eq (car-safe a) 'calcFunc-tanh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2986 (eq (car-safe b) 'calcFunc-coth) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2987 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2988 1) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2989 ((and (eq (car-safe a) 'calcFunc-tanh) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2990 (eq (car-safe b) 'calcFunc-csch) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2991 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2992 (cons 'calcFunc-sech (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2993 ((and (eq (car-safe a) 'calcFunc-sech) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2994 (eq (car-safe b) 'calcFunc-coth) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2995 (= 0 (math-simplify (math-sub (cdr a) (cdr b))))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2996 (cons 'calcFunc-csch (cdr a))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2997 (t |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2998 nil))) |
71985e6ee53a
(math-trig-inverses, math-div-trig, math-div-non-trig): New variables.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60077
diff
changeset
|
2999 |
40785 | 3000 (defun math-mul-or-div (a b ainv binv) |
3001 (if (or (Math-vectorp a) (Math-vectorp b)) | |
3002 (math-normalize | |
3003 (if ainv | |
3004 (if binv | |
3005 (list '/ (math-div 1 a) b) | |
3006 (list '/ b a)) | |
3007 (if binv | |
3008 (list '/ a b) | |
3009 (list '* a b)))) | |
3010 (if ainv | |
3011 (if binv | |
3012 (math-div (math-div 1 a) b) | |
3013 (math-div b a)) | |
3014 (if binv | |
3015 (math-div a b) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3016 (math-mul a b))))) |
40785 | 3017 |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3018 ;; The variable math-com-bterms is local to math-commutative-equal, |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3019 ;; but is used by math-commutative collect, which is called by |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3020 ;; math-commutative-equal. |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3021 (defvar math-com-bterms) |
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3022 |
40785 | 3023 (defun math-commutative-equal (a b) |
3024 (if (memq (car-safe a) '(+ -)) | |
3025 (and (memq (car-safe b) '(+ -)) | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3026 (let ((math-com-bterms nil) aterms p) |
40785 | 3027 (math-commutative-collect b nil) |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3028 (setq aterms math-com-bterms math-com-bterms nil) |
40785 | 3029 (math-commutative-collect a nil) |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3030 (and (= (length aterms) (length math-com-bterms)) |
40785 | 3031 (progn |
3032 (while (and aterms | |
3033 (progn | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3034 (setq p math-com-bterms) |
40785 | 3035 (while (and p (not (equal (car aterms) |
3036 (car p)))) | |
3037 (setq p (cdr p))) | |
3038 p)) | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3039 (setq math-com-bterms (delq (car p) math-com-bterms) |
40785 | 3040 aterms (cdr aterms))) |
3041 (not aterms))))) | |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3042 (equal a b))) |
40785 | 3043 |
3044 (defun math-commutative-collect (b neg) | |
3045 (if (eq (car-safe b) '+) | |
3046 (progn | |
3047 (math-commutative-collect (nth 1 b) neg) | |
3048 (math-commutative-collect (nth 2 b) neg)) | |
3049 (if (eq (car-safe b) '-) | |
3050 (progn | |
3051 (math-commutative-collect (nth 1 b) neg) | |
3052 (math-commutative-collect (nth 2 b) (not neg))) | |
58479
562c6a62c99e
(math-scalar-functions, math-nonscalar-functions)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
3053 (setq math-com-bterms (cons (if neg (math-neg b) b) math-com-bterms))))) |
40785 | 3054 |
58647
e655efbeebac
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58626
diff
changeset
|
3055 (provide 'calc-arith) |
e655efbeebac
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58626
diff
changeset
|
3056 |
52401 | 3057 ;;; arch-tag: 6c396b5b-14c6-40ed-bb2a-7cc2e8111465 |
41041
45130b458dac
(calcFunc-abs, calcFunc-float, calcFunc-ceil, calcFunc-round): Use
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3058 ;;; calc-arith.el ends here |