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