home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume24 / gnucalc / part27 < prev    next >
Encoding:
Text File  |  1991-10-31  |  55.4 KB  |  1,907 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@synaptics.com (David Gillespie)
  3. Subject:  v24i075:  gnucalc - GNU Emacs Calculator, v2.00, Part27/56
  4. Message-ID: <1991Oct31.072838.18393@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9dd6a9f30938340a6dcdffcc4e7274d1
  6. Date: Thu, 31 Oct 1991 07:28:38 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: daveg@synaptics.com (David Gillespie)
  10. Posting-number: Volume 24, Issue 75
  11. Archive-name: gnucalc/part27
  12. Environment: Emacs
  13. Supersedes: gmcalc: Volume 13, Issue 27-45
  14.  
  15. ---- Cut Here and unpack ----
  16. #!/bin/sh
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file calc-sel.el continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 27; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping calc-sel.el'
  34. else
  35. echo 'x - continuing file calc-sel.el'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'calc-sel.el' &&
  37. X                       num
  38. X                       (list (and reselect alg)))))
  39. X     (calc-handle-whys)))
  40. )
  41. X
  42. (defun calc-sel-sub-both-sides (no-simp)
  43. X  (interactive "P")
  44. X  (calc-sel-add-both-sides no-simp t)
  45. )
  46. X
  47. SHAR_EOF
  48. echo 'File calc-sel.el is complete' &&
  49. chmod 0644 calc-sel.el ||
  50. echo 'restore of calc-sel.el failed'
  51. Wc_c="`wc -c < 'calc-sel.el'`"
  52. test 25519 -eq "$Wc_c" ||
  53.     echo 'calc-sel.el: original size 25519, current size' "$Wc_c"
  54. rm -f _shar_wnt_.tmp
  55. fi
  56. # ============= calc-stat.el ==============
  57. if test -f 'calc-stat.el' -a X"$1" != X"-c"; then
  58.     echo 'x - skipping calc-stat.el (File already exists)'
  59.     rm -f _shar_wnt_.tmp
  60. else
  61. > _shar_wnt_.tmp
  62. echo 'x - extracting calc-stat.el (Text)'
  63. sed 's/^X//' << 'SHAR_EOF' > 'calc-stat.el' &&
  64. ;; Calculator for GNU Emacs, part II [calc-stat.el]
  65. ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  66. ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
  67. X
  68. ;; This file is part of GNU Emacs.
  69. X
  70. ;; GNU Emacs is distributed in the hope that it will be useful,
  71. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  72. ;; accepts responsibility to anyone for the consequences of using it
  73. ;; or for whether it serves any particular purpose or works at all,
  74. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  75. ;; License for full details.
  76. X
  77. ;; Everyone is granted permission to copy, modify and redistribute
  78. ;; GNU Emacs, but only under the conditions described in the
  79. ;; GNU Emacs General Public License.   A copy of this license is
  80. ;; supposed to have been given to you along with GNU Emacs so you
  81. ;; can know your rights and responsibilities.  It should be in a
  82. ;; file named COPYING.  Among other things, the copyright notice
  83. ;; and this notice must be preserved on all copies.
  84. X
  85. X
  86. X
  87. ;; This file is autoloaded from calc-ext.el.
  88. (require 'calc-ext)
  89. X
  90. (require 'calc-macs)
  91. X
  92. (defun calc-Need-calc-stat () nil)
  93. X
  94. X
  95. ;;; Statistical operations on vectors.
  96. X
  97. (defun calc-vector-count (arg)
  98. X  (interactive "P")
  99. X  (calc-slow-wrapper
  100. X   (calc-vector-op "coun" 'calcFunc-vcount arg))
  101. )
  102. X
  103. (defun calc-vector-sum (arg)
  104. X  (interactive "P")
  105. X  (calc-slow-wrapper
  106. X   (if (calc-is-hyperbolic)
  107. X       (calc-vector-op "vprd" 'calcFunc-vprod arg)
  108. X     (calc-vector-op "vsum" 'calcFunc-vsum arg)))
  109. )
  110. X
  111. (defun calc-vector-product (arg)
  112. X  (interactive "P")
  113. X  (calc-hyperbolic-func)
  114. X  (calc-vector-sum arg)
  115. )
  116. X
  117. (defun calc-vector-max (arg)
  118. X  (interactive "P")
  119. X  (calc-slow-wrapper
  120. X   (if (calc-is-inverse)
  121. X       (calc-vector-op "vmin" 'calcFunc-vmin arg)
  122. X     (calc-vector-op "vmax" 'calcFunc-vmax arg)))
  123. )
  124. X
  125. (defun calc-vector-min (arg)
  126. X  (interactive "P")
  127. X  (calc-invert-func)
  128. X  (calc-vector-max arg)
  129. )
  130. X
  131. (defun calc-vector-mean (arg)
  132. X  (interactive "P")
  133. X  (calc-slow-wrapper
  134. X   (if (calc-is-hyperbolic)
  135. X       (if (calc-is-inverse)
  136. X       (calc-vector-op "harm" 'calcFunc-vhmean arg)
  137. X     (calc-vector-op "medn" 'calcFunc-vmedian arg))
  138. X     (if (calc-is-inverse)
  139. X     (calc-vector-op "meae" 'calcFunc-vmeane arg)
  140. X       (calc-vector-op "mean" 'calcFunc-vmean arg))))
  141. )
  142. X
  143. (defun calc-vector-mean-error (arg)
  144. X  (interactive "P")
  145. X  (calc-invert-func)
  146. X  (calc-vector-mean arg)
  147. )
  148. X
  149. (defun calc-vector-median (arg)
  150. X  (interactive "P")
  151. X  (calc-hyperbolic-func)
  152. X  (calc-vector-mean arg)
  153. )
  154. X
  155. (defun calc-vector-harmonic-mean (arg)
  156. X  (interactive "P")
  157. X  (calc-invert-func)
  158. X  (calc-hyperbolic-func)
  159. X  (calc-vector-mean arg)
  160. )
  161. X
  162. (defun calc-vector-geometric-mean (arg)
  163. X  (interactive "P")
  164. X  (calc-slow-wrapper
  165. X   (if (calc-is-hyperbolic)
  166. X       (calc-binary-op "geom" 'calcFunc-agmean arg)
  167. X     (calc-vector-op "geom" 'calcFunc-vgmean arg)))
  168. )
  169. X
  170. (defun calc-vector-sdev (arg)
  171. X  (interactive "P")
  172. X  (calc-slow-wrapper
  173. X   (if (calc-is-hyperbolic)
  174. X       (if (calc-is-inverse)
  175. X       (calc-vector-op "pvar" 'calcFunc-vpvar arg)
  176. X     (calc-vector-op "var" 'calcFunc-vvar arg))
  177. X     (if (calc-is-inverse)
  178. X     (calc-vector-op "psdv" 'calcFunc-vpsdev arg)
  179. X       (calc-vector-op "sdev" 'calcFunc-vsdev arg))))
  180. )
  181. X
  182. (defun calc-vector-pop-sdev (arg)
  183. X  (interactive "P")
  184. X  (calc-invert-func)
  185. X  (calc-vector-sdev arg)
  186. )
  187. X
  188. (defun calc-vector-variance (arg)
  189. X  (interactive "P")
  190. X  (calc-hyperbolic-func)
  191. X  (calc-vector-sdev arg)
  192. )
  193. X
  194. (defun calc-vector-pop-variance (arg)
  195. X  (interactive "P")
  196. X  (calc-invert-func)
  197. X  (calc-hyperbolic-func)
  198. X  (calc-vector-sdev arg)
  199. )
  200. X
  201. (defun calc-vector-covariance (arg)
  202. X  (interactive "P")
  203. X  (calc-slow-wrapper
  204. X   (let ((n (if (eq arg 1) 1 2)))
  205. X     (if (calc-is-hyperbolic)
  206. X     (calc-enter-result n "corr" (cons 'calcFunc-vcorr
  207. X                       (calc-top-list-n n)))
  208. X       (if (calc-is-inverse)
  209. X       (calc-enter-result n "pcov" (cons 'calcFunc-vpcov
  210. X                         (calc-top-list-n n)))
  211. X     (calc-enter-result n "cov" (cons 'calcFunc-vcov
  212. X                      (calc-top-list-n n)))))))
  213. )
  214. X
  215. (defun calc-vector-pop-covariance (arg)
  216. X  (interactive "P")
  217. X  (calc-invert-func)
  218. X  (calc-vector-covariance arg)
  219. )
  220. X
  221. (defun calc-vector-correlation (arg)
  222. X  (interactive "P")
  223. X  (calc-hyperbolic-func)
  224. X  (calc-vector-covariance arg)
  225. )
  226. X
  227. (defun calc-vector-op (name func arg)
  228. X  (setq calc-aborted-prefix name
  229. X    arg (prefix-numeric-value arg))
  230. X  (if (< arg 0)
  231. X      (error "Negative arguments not allowed"))
  232. X  (calc-enter-result arg name (cons func (calc-top-list-n arg)))
  233. )
  234. X
  235. X
  236. X
  237. X
  238. ;;; Useful statistical functions
  239. X
  240. ;;; Sum, product, etc., of one or more values or vectors.
  241. ;;; Each argument must be either a number or a vector.  Vectors
  242. ;;; are flattened, but variables inside are assumed to represent
  243. ;;; non-vectors.
  244. X
  245. (defun calcFunc-vsum (&rest vecs)
  246. X  (math-reduce-many-vecs 'calcFunc-add 'calcFunc-vsum vecs 0)
  247. )
  248. X
  249. (defun calcFunc-vprod (&rest vecs)
  250. X  (math-reduce-many-vecs 'calcFunc-mul 'calcFunc-vprod vecs 1)
  251. )
  252. X
  253. (defun calcFunc-vmax (&rest vecs)
  254. X  (if (eq (car-safe (car vecs)) 'sdev)
  255. X      '(var inf var-inf)
  256. X    (if (eq (car-safe (car vecs)) 'intv)
  257. X    (nth 3 (math-fix-int-intv (car vecs)))
  258. X      (math-reduce-many-vecs 'calcFunc-max 'calcFunc-vmax vecs
  259. X                 '(neg (var inf var-inf)))))
  260. )
  261. X
  262. (defun calcFunc-vmin (&rest vecs)
  263. X  (if (eq (car-safe (car vecs)) 'sdev)
  264. X      '(neg (var inf var-inf))
  265. X    (if (eq (car-safe (car vecs)) 'intv)
  266. X    (nth 2 (math-fix-int-intv (car vecs)))
  267. X      (math-reduce-many-vecs 'calcFunc-min 'calcFunc-vmin vecs
  268. X                 '(var inf var-inf))))
  269. )
  270. X
  271. (defun math-reduce-many-vecs (func whole-func vecs ident)
  272. X  (let ((const-part nil)
  273. X    (symb-part nil)
  274. X    val vec)
  275. X    (let ((calc-internal-prec (+ calc-internal-prec 2)))
  276. X      (while vecs
  277. X    (setq val (car vecs))
  278. X    (and (eq (car-safe val) 'var)
  279. X         (eq (car-safe (calc-var-value (nth 2 val))) 'vec)
  280. X         (setq val (symbol-value (nth 2 val))))
  281. X    (cond ((Math-vectorp val)
  282. X           (setq vec (append (and const-part (list const-part))
  283. X                 (math-flatten-vector val)))
  284. X           (setq const-part (if vec
  285. X                    (calcFunc-reducer
  286. X                     (math-calcFunc-to-var func)
  287. X                     (cons 'vec vec))
  288. X                  ident)))
  289. X          ((or (Math-objectp val) (math-infinitep val))
  290. X           (setq const-part (if const-part
  291. X                    (funcall func const-part val)
  292. X                  val)))
  293. X          (t
  294. X           (setq symb-part (nconc symb-part (list val)))))
  295. X    (setq vecs (cdr vecs))))
  296. X    (if const-part
  297. X    (progn
  298. X      (setq const-part (math-normalize const-part))
  299. X      (if symb-part
  300. X          (funcall func const-part (cons whole-func symb-part))
  301. X        const-part))
  302. X      (if symb-part (cons whole-func symb-part) ident)))
  303. )
  304. X
  305. X
  306. ;;; Return the number of data elements among the arguments.
  307. (defun calcFunc-vcount (&rest vecs)
  308. X  (let ((count 0))
  309. X    (while vecs
  310. X      (setq count (if (Math-vectorp (car vecs))
  311. X              (+ count (math-count-elements (car vecs)))
  312. X            (if (Math-objectp (car vecs))
  313. X            (1+ count)
  314. X              (if (and (eq (car-safe (car vecs)) 'var)
  315. X                   (eq (car-safe (calc-var-value
  316. X                          (nth 2 (car vecs))))
  317. X                   'vec))
  318. X              (+ count (math-count-elements
  319. X                    (symbol-value (nth 2 (car vecs)))))
  320. X            (math-reject-arg (car vecs) 'numvecp))))
  321. X        vecs (cdr vecs)))
  322. X    count)
  323. )
  324. X
  325. (defun math-count-elements (vec)
  326. X  (let ((count 0))
  327. X    (while (setq vec (cdr vec))
  328. X      (setq count (if (Math-vectorp (car vec))
  329. X              (+ count (math-count-elements (car vec)))
  330. X            (1+ count))))
  331. X    count)
  332. )
  333. X
  334. X
  335. (defun math-flatten-many-vecs (vecs)
  336. X  (let ((p vecs)
  337. X    (vec (list 'vec)))
  338. X    (while p
  339. X      (setq vec (nconc vec
  340. X               (if (Math-vectorp (car p))
  341. X               (math-flatten-vector (car p))
  342. X             (if (Math-objectp (car p))
  343. X                 (list (car p))
  344. X               (if (and (eq (car-safe (car p)) 'var)
  345. X                    (eq (car-safe (calc-var-value
  346. X                           (nth 2 (car p)))) 'vec))
  347. X                   (math-flatten-vector (symbol-value
  348. X                             (nth 2 (car p))))
  349. X                 (math-reject-arg (car p) 'numvecp)))))
  350. X        p (cdr p)))
  351. X    vec)
  352. )
  353. X
  354. (defun calcFunc-vflat (&rest vecs)
  355. X  (math-flatten-many-vecs vecs)
  356. )
  357. X
  358. (defun math-split-sdev-vec (vec zero-ok)
  359. X  (let ((means (list 'vec))
  360. X    (wts (list 'vec))
  361. X    (exact nil)
  362. X    (p vec))
  363. X    (while (and (setq p (cdr p))
  364. X        (not (and (consp (car p))
  365. X              (eq (car (car p)) 'sdev)))))
  366. X    (if (null p)
  367. X    (list vec nil)
  368. X      (while (setq vec (cdr vec))
  369. X    (if (and (consp (setq p (car vec)))
  370. X         (eq (car p) 'sdev))
  371. X        (or exact
  372. X        (setq means (cons (nth 1 p) means)
  373. X              wts (cons (nth 2 p) wts)))
  374. X      (if zero-ok
  375. X          (setq means (cons (nth 1 p) means)
  376. X            wts (cons 0 wts))
  377. X        (or exact
  378. X        (setq means (list 'vec)
  379. X              wts nil
  380. X              exact t))
  381. X        (setq means (cons p means)))))
  382. X      (list (nreverse means)
  383. X        (and wts (nreverse wts)))))
  384. )
  385. X
  386. X
  387. ;;; Return the arithmetic mean of the argument numbers or vectors.
  388. ;;; (If numbers are error forms, computes the weighted mean.)
  389. (defun calcFunc-vmean (&rest vecs)
  390. X  (let* ((split (math-split-sdev-vec (math-flatten-many-vecs vecs) nil))
  391. X     (means (car split))
  392. X     (wts (nth 1 split))
  393. X     (len (1- (length means))))
  394. X    (if (= len 0)
  395. X    (math-reject-arg nil "*Must be at least 1 argument")
  396. X      (if (and (= len 1) (eq (car-safe (nth 1 means)) 'intv))
  397. X      (let ((x (math-fix-int-intv (nth 1 means))))
  398. X        (calcFunc-vmean (nth 2 x) (nth 3 x)))
  399. X    (math-with-extra-prec 2
  400. X      (if (and wts (> len 1))
  401. X          (let* ((sqrwts (calcFunc-map '(var mul var-mul) wts wts))
  402. X             (suminvsqrwts (calcFunc-reduce
  403. X                    '(var add var-add)
  404. X                    (calcFunc-map '(var div var-div)
  405. X                          1 sqrwts))))
  406. X        (math-div (calcFunc-reduce '(var add var-add)
  407. X                       (calcFunc-map '(var div var-div)
  408. X                             means sqrwts))
  409. X              suminvsqrwts))
  410. X        (math-div (calcFunc-reduce '(var add var-add) means) len))))))
  411. )
  412. X
  413. (defun math-fix-int-intv (x)
  414. X  (if (math-floatp x)
  415. X      x
  416. X    (list 'intv 3
  417. X      (if (memq (nth 1 x) '(2 3)) (nth 2 x) (math-add (nth 2 x) 1))
  418. X      (if (memq (nth 1 x) '(1 3)) (nth 3 x) (math-sub (nth 3 x) 1))))
  419. )
  420. X
  421. ;;; Compute the mean with an error estimate.
  422. (defun calcFunc-vmeane (&rest vecs)
  423. X  (let* ((split (math-split-sdev-vec (math-flatten-many-vecs vecs) nil))
  424. X     (means (car split))
  425. X     (wts (nth 1 split))
  426. X     (len (1- (length means))))
  427. X    (if (= len 0)
  428. X    (math-reject-arg nil "*Must be at least 1 argument")
  429. X      (math-with-extra-prec 2
  430. X    (if wts
  431. X        (let* ((sqrwts (calcFunc-map '(var mul var-mul) wts wts))
  432. X           (suminvsqrwts (calcFunc-reduce
  433. X                  '(var add var-add)
  434. X                  (calcFunc-map '(var div var-div)
  435. X                        1 sqrwts))))
  436. X          (math-make-sdev
  437. X           (math-div (calcFunc-reduce '(var add var-add)
  438. X                      (calcFunc-map '(var div var-div)
  439. X                            means sqrwts))
  440. X             suminvsqrwts)
  441. X           (list 'calcFunc-sqrt (math-div 1 suminvsqrwts))))
  442. X      (let ((mean (math-div (calcFunc-reduce '(var add var-add) means)
  443. X                len)))
  444. X        (math-make-sdev
  445. X         mean
  446. X         (list 'calcFunc-sqrt
  447. X           (math-div (calcFunc-reducer
  448. X                  '(var add var-add)
  449. X                  (calcFunc-map '(var pow var-pow)
  450. X                        (calcFunc-map '(var abs var-abs)
  451. X                              (calcFunc-map
  452. X                               '(var add var-add)
  453. X                               means
  454. X                               (math-neg mean)))
  455. X                        2))
  456. X                 (math-mul len (1- len))))))))))
  457. )
  458. X
  459. X
  460. ;;; Compute the median of a list of values.
  461. (defun calcFunc-vmedian (&rest vecs)
  462. X  (let* ((flat (copy-sequence (cdr (math-flatten-many-vecs vecs))))
  463. X     (p flat)
  464. X     (len (length flat))
  465. X     (hlen (/ len 2)))
  466. X    (if (= len 0)
  467. X    (math-reject-arg nil "*Must be at least 1 argument")
  468. X      (if (and (= len 1) (memq (car-safe (car flat)) '(sdev intv)))
  469. X      (calcFunc-vmean (car flat))
  470. X    (while p
  471. X      (if (eq (car-safe (car p)) 'sdev)
  472. X          (setcar p (nth 1 (car p))))
  473. X      (or (Math-anglep (car p))
  474. X          (math-reject-arg (car p) 'anglep))
  475. X      (setq p (cdr p)))
  476. X    (setq flat (sort flat 'math-lessp))
  477. X    (if (= (% len 2) 0)
  478. X        (math-div (math-add (nth (1- hlen) flat) (nth hlen flat)) 2)
  479. X      (nth hlen flat)))))
  480. )
  481. X
  482. X
  483. (defun calcFunc-vgmean (&rest vecs)
  484. X  (let* ((flat (math-flatten-many-vecs vecs))
  485. X     (len (1- (length flat))))
  486. X    (if (= len 0)
  487. X    (math-reject-arg nil "*Must be at least 1 argument")
  488. X      (math-with-extra-prec 2
  489. X    (let ((x (calcFunc-reduce '(var mul math-mul) flat)))
  490. X      (if (= len 2)
  491. X          (math-sqrt x)
  492. X        (math-pow x (list 'frac 1 len)))))))
  493. )
  494. X
  495. X
  496. (defun calcFunc-agmean (a b)
  497. X  (cond ((Math-equal a b) a)
  498. X    ((math-zerop a) a)
  499. X    ((math-zerop b) b)
  500. X    (calc-symbolic-mode (math-inexact-result))
  501. X    ((not (Math-realp a)) (math-reject-arg a 'realp))
  502. X    ((not (Math-realp b)) (math-reject-arg b 'realp))
  503. X    (t
  504. X     (math-with-extra-prec 2
  505. X       (setq a (math-float (math-abs a))
  506. X         b (math-float (math-abs b)))
  507. X       (let (mean)
  508. X         (while (not (math-nearly-equal-float a b))
  509. X           (setq mean (math-mul-float (math-add-float a b) '(float 5 -1))
  510. X             b (math-sqrt-float (math-mul-float a b))
  511. X             a mean))
  512. X         a))))
  513. )
  514. X
  515. X
  516. (defun calcFunc-vhmean (&rest vecs)
  517. X  (let* ((flat (math-flatten-many-vecs vecs))
  518. X     (len (1- (length flat))))
  519. X    (if (= len 0)
  520. X    (math-reject-arg nil "*Must be at least 1 argument")
  521. X      (math-with-extra-prec 2
  522. X    (math-div len
  523. X          (calcFunc-reduce '(var add math-add)
  524. X                   (calcFunc-map '(var inv var-inv) flat))))))
  525. )
  526. X
  527. X
  528. X
  529. ;;; Compute the sample variance or standard deviation of numbers or vectors.
  530. ;;; (If the numbers are error forms, only the mean part of them is used.)
  531. (defun calcFunc-vvar (&rest vecs)
  532. X  (if (and (= (length vecs) 1)
  533. X       (memq (car-safe (car vecs)) '(sdev intv)))
  534. X      (if (eq (car-safe (car vecs)) 'intv)
  535. X      (math-intv-variance (car vecs) nil)
  536. X    (math-sqr (nth 2 (car vecs))))
  537. X    (math-covariance vecs nil nil 0))
  538. )
  539. X
  540. (defun calcFunc-vsdev (&rest vecs)
  541. X  (if (and (= (length vecs) 1)
  542. X       (memq (car-safe (car vecs)) '(sdev intv)))
  543. X      (if (eq (car-safe (car vecs)) 'intv)
  544. X      (if (math-floatp (car vecs))
  545. X          (math-div (math-sub (nth 3 (car vecs)) (nth 2 (car vecs)))
  546. X            (math-sqrt-12))
  547. X        (math-sqrt (calcFunc-vvar (car vecs))))
  548. X    (nth 2 (car vecs)))
  549. X    (math-sqrt (math-covariance vecs nil nil 0)))
  550. )
  551. X
  552. ;;; Compute the population variance or std deviation of numbers or vectors.
  553. (defun calcFunc-vpvar (&rest vecs)
  554. X  (if (and (= (length vecs) 1)
  555. X       (memq (car-safe (car vecs)) '(sdev intv)))
  556. X      (if (eq (car-safe (car vecs)) 'intv)
  557. X      (math-intv-variance (car vecs) t)
  558. X    (math-sqr (nth 2 (car vecs))))
  559. X    (math-covariance vecs nil t 0))
  560. )
  561. X
  562. (defun calcFunc-vpsdev (&rest vecs)
  563. X  (if (and (= (length vecs) 1)
  564. X       (memq (car-safe (car vecs)) '(sdev intv)))
  565. X      (if (eq (car-safe (car vecs)) 'intv)
  566. X      (if (math-floatp (car vecs))
  567. X          (math-div (math-sub (nth 3 (car vecs)) (nth 2 (car vecs)))
  568. X            (math-sqrt-12))
  569. X        (math-sqrt (calcFunc-vpvar (car vecs))))
  570. X    (nth 2 (car vecs)))
  571. X    (math-sqrt (math-covariance vecs nil t 0)))
  572. )
  573. X
  574. (defun math-intv-variance (x pop)
  575. X  (or (math-constp x) (math-reject-arg x 'constp))
  576. X  (if (math-floatp x)
  577. X      (math-div (math-sqr (math-sub (nth 3 x) (nth 2 x))) 12)
  578. X    (let* ((x (math-fix-int-intv x))
  579. X       (len (math-sub (nth 3 x) (nth 2 x)))
  580. X       (hlen (math-quotient len 2)))
  581. X      (math-div (if (math-evenp len)
  582. X            (calcFunc-sum '(^ (var X var-X) 2) '(var X var-X)
  583. X                  (math-neg hlen) hlen)
  584. X          (calcFunc-sum '(^ (- (var X var-X) (/ 1 2)) 2)
  585. X                '(var X var-X)
  586. X                (math-neg hlen) (math-add hlen 1)))
  587. X        (if pop (math-add len 1) len))))
  588. )
  589. X
  590. ;;; Compute the covariance and linear correlation coefficient.
  591. (defun calcFunc-vcov (vec1 &optional vec2)
  592. X  (math-covariance (list vec1) (list vec2) nil 1)
  593. )
  594. X
  595. (defun calcFunc-vpcov (vec1 &optional vec2)
  596. X  (math-covariance (list vec1) (list vec2) t 1)
  597. )
  598. X
  599. (defun calcFunc-vcorr (vec1 &optional vec2)
  600. X  (math-covariance (list vec1) (list vec2) nil 2)
  601. )
  602. X
  603. X
  604. (defun math-covariance (vec1 vec2 pop mode)
  605. X  (or (car vec2) (= mode 0)
  606. X      (progn
  607. X    (if (and (eq (car-safe (car vec1)) 'var)
  608. X         (eq (car-safe (calc-var-value (nth 2 (car vec1)))) 'vec))
  609. X        (setq vec1 (symbol-value (nth 2 (car vec1))))
  610. X      (setq vec1 (car vec1)))
  611. X    (or (math-matrixp vec1) (math-dimension-error))
  612. X    (or (= (length (nth 1 vec1)) 3) (math-dimension-error))
  613. X    (setq vec2 (list (math-mat-col vec1 2))
  614. X          vec1 (list (math-mat-col vec1 1)))))
  615. X  (math-with-extra-prec 2
  616. X    (let* ((split1 (math-split-sdev-vec (math-flatten-many-vecs vec1) nil))
  617. X       (means1 (car split1))
  618. X       (wts1 (nth 1 split1))
  619. X       split2 means2 (wts2 nil)
  620. X       (sqrwts nil)
  621. X       suminvsqrwts
  622. X       (len (1- (length means1))))
  623. X      (if (< len (if pop 1 2))
  624. X      (math-reject-arg nil (if pop
  625. X                   "*Must be at least 1 argument"
  626. X                 "*Must be at least 2 arguments")))
  627. X      (if (or wts1 wts2)
  628. X      (setq sqrwts (math-add
  629. X            (if wts1
  630. X                (calcFunc-map '(var mul var-mul) wts1 wts1)
  631. X              0)
  632. X            (if wts2
  633. X                (calcFunc-map '(var mul var-mul) wts2 wts2)
  634. X              0))
  635. X        suminvsqrwts (calcFunc-reduce
  636. X                  '(var add var-add)
  637. X                  (calcFunc-map '(var div var-div) 1 sqrwts))))
  638. X      (or (= mode 0)
  639. X      (progn
  640. X        (setq split2 (math-split-sdev-vec (math-flatten-many-vecs vec2)
  641. X                          nil)
  642. X          means2 (car split2)
  643. X          wts2 (nth 2 split1))
  644. X        (or (= len (1- (length means2))) (math-dimension-error))))
  645. X      (let* ((diff1 (calcFunc-map
  646. X             '(var add var-add)
  647. X             means1
  648. X             (if sqrwts
  649. X             (math-div (calcFunc-reduce
  650. X                    '(var add var-add)
  651. X                    (calcFunc-map '(var div var-div)
  652. X                          means1 sqrwts))
  653. X                   (math-neg suminvsqrwts))
  654. X               (math-div (calcFunc-reducer '(var add var-add) means1)
  655. X                 (- len)))))
  656. X         (diff2 (if (= mode 0)
  657. X            diff1
  658. X              (calcFunc-map
  659. X               '(var add var-add)
  660. X               means2
  661. X               (if sqrwts
  662. X               (math-div (calcFunc-reduce
  663. X                      '(var add var-add)
  664. X                      (calcFunc-map '(var div var-div)
  665. X                            means2 sqrwts))
  666. X                     (math-neg suminvsqrwts))
  667. X             (math-div (calcFunc-reducer '(var add var-add) means2)
  668. X                   (- len))))))
  669. X         (covar (calcFunc-map '(var mul var-mul) diff1 diff2)))
  670. X    (if sqrwts
  671. X        (setq covar (calcFunc-map '(var div var-div) covar sqrwts)))
  672. X    (math-div
  673. X     (calcFunc-reducer '(var add var-add) covar)
  674. X     (if (= mode 2)
  675. X         (let ((var1 (calcFunc-map '(var mul var-mul) diff1 diff1))
  676. X           (var2 (calcFunc-map '(var mul var-mul) diff2 diff2)))
  677. X           (if sqrwts
  678. X           (setq var1 (calcFunc-map '(var div var-div) var1 sqrwts)
  679. X             var2 (calcFunc-map '(var div var-div) var2 sqrwts)))
  680. X           (math-sqrt
  681. X        (math-mul (calcFunc-reducer '(var add var-add) var1)
  682. X              (calcFunc-reducer '(var add var-add) var2))))
  683. X       (if sqrwts
  684. X           (if pop
  685. X           suminvsqrwts
  686. X         (math-div (math-mul suminvsqrwts (1- len)) len))
  687. X         (if pop len (1- len))))))))
  688. )
  689. X
  690. X
  691. X
  692. X
  693. SHAR_EOF
  694. chmod 0644 calc-stat.el ||
  695. echo 'restore of calc-stat.el failed'
  696. Wc_c="`wc -c < 'calc-stat.el'`"
  697. test 18079 -eq "$Wc_c" ||
  698.     echo 'calc-stat.el: original size 18079, current size' "$Wc_c"
  699. rm -f _shar_wnt_.tmp
  700. fi
  701. # ============= calc-store.el ==============
  702. if test -f 'calc-store.el' -a X"$1" != X"-c"; then
  703.     echo 'x - skipping calc-store.el (File already exists)'
  704.     rm -f _shar_wnt_.tmp
  705. else
  706. > _shar_wnt_.tmp
  707. echo 'x - extracting calc-store.el (Text)'
  708. sed 's/^X//' << 'SHAR_EOF' > 'calc-store.el' &&
  709. ;; Calculator for GNU Emacs, part II [calc-store.el]
  710. ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  711. ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
  712. X
  713. ;; This file is part of GNU Emacs.
  714. X
  715. ;; GNU Emacs is distributed in the hope that it will be useful,
  716. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  717. ;; accepts responsibility to anyone for the consequences of using it
  718. ;; or for whether it serves any particular purpose or works at all,
  719. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  720. ;; License for full details.
  721. X
  722. ;; Everyone is granted permission to copy, modify and redistribute
  723. ;; GNU Emacs, but only under the conditions described in the
  724. ;; GNU Emacs General Public License.   A copy of this license is
  725. ;; supposed to have been given to you along with GNU Emacs so you
  726. ;; can know your rights and responsibilities.  It should be in a
  727. ;; file named COPYING.  Among other things, the copyright notice
  728. ;; and this notice must be preserved on all copies.
  729. X
  730. X
  731. X
  732. ;; This file is autoloaded from calc-ext.el.
  733. (require 'calc-ext)
  734. X
  735. (require 'calc-macs)
  736. X
  737. (defun calc-Need-calc-store () nil)
  738. X
  739. X
  740. ;;; Memory commands.
  741. X
  742. (defun calc-store (&optional var)
  743. X  (interactive)
  744. X  (let ((calc-store-keep t))
  745. X    (calc-store-into var))
  746. )
  747. (setq calc-store-keep nil)
  748. X
  749. (defun calc-store-into (&optional var)
  750. X  (interactive)
  751. X  (calc-wrapper
  752. X   (let ((calc-given-value nil)
  753. X     (calc-given-value-flag 1))
  754. X     (or var (setq var (calc-read-var-name "Store: " t)))
  755. X     (if var
  756. X     (let ((found (assq var '( ( + . calc-store-plus )
  757. X                   ( - . calc-store-minus )
  758. X                   ( * . calc-store-times )
  759. X                   ( / . calc-store-div )
  760. X                   ( ^ . calc-store-power )
  761. X                   ( | . calc-store-concat ) ))))
  762. X       (if found
  763. X           (funcall (cdr found))
  764. X         (calc-store-value var (or calc-given-value (calc-top 1))
  765. X                   "" calc-given-value-flag)
  766. X         (message "Stored to variable \"%s\"" (calc-var-name var))))
  767. X       (setq var (calc-is-assignments (calc-top 1)))
  768. X       (if var
  769. X       (while var
  770. X         (calc-store-value (car (car var)) (cdr (car var))
  771. X                   (if (not (cdr var)) "")
  772. X                   (if (not (cdr var)) 1))
  773. X         (setq var (cdr var)))))))
  774. )
  775. X
  776. (defun calc-store-plus (&optional var)
  777. X  (interactive)
  778. X  (calc-store-binary var "+" '+)
  779. )
  780. X
  781. (defun calc-store-minus (&optional var)
  782. X  (interactive)
  783. X  (calc-store-binary var "-" '-)
  784. )
  785. X
  786. (defun calc-store-times (&optional var)
  787. X  (interactive)
  788. X  (calc-store-binary var "*" '*)
  789. )
  790. X
  791. (defun calc-store-div (&optional var)
  792. X  (interactive)
  793. X  (calc-store-binary var "/" '/)
  794. )
  795. X
  796. (defun calc-store-power (&optional var)
  797. X  (interactive)
  798. X  (calc-store-binary var "^" '^)
  799. )
  800. X
  801. (defun calc-store-concat (&optional var)
  802. X  (interactive)
  803. X  (calc-store-binary var "|" '|)
  804. )
  805. X
  806. (defun calc-store-neg (n &optional var)
  807. X  (interactive "p")
  808. X  (calc-store-binary var "n" '/ (- n))
  809. )
  810. X
  811. (defun calc-store-inv (n &optional var)
  812. X  (interactive "p")
  813. X  (calc-store-binary var "&" '^ (- n))
  814. )
  815. X
  816. (defun calc-store-incr (n &optional var)
  817. X  (interactive "p")
  818. X  (calc-store-binary var "n" '- (- n))
  819. )
  820. X
  821. (defun calc-store-decr (n &optional var)
  822. X  (interactive "p")
  823. X  (calc-store-binary var "n" '- n)
  824. )
  825. X
  826. (defun calc-store-value (var value tag &optional pop)
  827. X  (if var
  828. X      (let ((old (calc-var-value var)))
  829. X    (set var value)
  830. X    (if pop (or calc-store-keep (calc-pop-stack pop)))
  831. X    (calc-record-undo (list 'store (symbol-name var) old))
  832. X    (if tag
  833. X        (calc-record value (format ">%s%s" tag (calc-var-name var))))
  834. X    (and (memq var '(var-e var-i var-pi var-phi var-gamma))
  835. X         (eq (car-safe old) 'special-const)
  836. X         (message "(Note: Built-in definition of %s has been lost)" var))
  837. X    (and (memq var '(var-inf var-uinf var-nan))
  838. X         (null old)
  839. X         (message "(Note: %s has built-in meanings which may interfere)"
  840. X              var))
  841. X    (calc-refresh-evaltos var)))
  842. )
  843. X
  844. (defun calc-var-name (var)
  845. X  (if (symbolp var) (setq var (symbol-name var)))
  846. X  (if (string-match "\\`var-." var)
  847. X      (substring var 4)
  848. X    var)
  849. )
  850. X
  851. (defun calc-store-binary (var tag func &optional val)
  852. X  (calc-wrapper
  853. X   (let ((calc-simplify-mode (if (eq calc-simplify-mode 'none)
  854. X                 'num calc-simplify-mode))
  855. X     (value (or val (calc-top 1))))
  856. X     (or var (setq var (calc-read-var-name (format "Store %s: " tag))))
  857. X     (if var
  858. X     (let ((old (calc-var-value var)))
  859. X       (or old
  860. X           (error "No such variable: \"%s\"" (calc-var-name var)))
  861. X       (if (stringp old)
  862. X           (setq old (math-read-expr old)))
  863. X       (if (eq (car-safe old) 'error)
  864. X           (error "Bad format in variable contents: %s" (nth 2 old)))
  865. X       (calc-store-value var
  866. X                 (calc-normalize (if (calc-is-inverse)
  867. X                         (list func value old)
  868. X                           (list func old value)))
  869. X                 tag (and (not val) 1))
  870. X       (message "Stored to variable \"%s\"" (calc-var-name var))))))
  871. )
  872. X
  873. (defun calc-read-var-name (prompt &optional calc-store-opers)
  874. X  (setq calc-given-value nil
  875. X    calc-aborted-prefix nil)
  876. X  (let ((var (let ((minibuffer-completion-table obarray)
  877. X           (minibuffer-completion-predicate 'boundp)
  878. X           (minibuffer-completion-confirm t))
  879. X           (read-from-minibuffer prompt "var-" calc-var-name-map nil))))
  880. X    (setq calc-aborted-prefix "")
  881. X    (and (not (equal var ""))
  882. X     (not (equal var "var-"))
  883. X     (if (string-match "\\`\\([-a-zA-Z0-9]+\\) *:?=" var)
  884. X         (if (null calc-given-value-flag)
  885. X         (error "Assignment is not allowed in this command")
  886. X           (let ((svar (intern (substring var 0 (match-end 1)))))
  887. X         (setq calc-given-value-flag 0
  888. X               calc-given-value (math-read-expr
  889. X                     (substring var (match-end 0))))
  890. X         (if (eq (car-safe calc-given-value) 'error)
  891. X             (error "Bad format: %s" (nth 2 calc-given-value)))
  892. X         (setq calc-given-value (math-evaluate-expr calc-given-value))
  893. X         svar))
  894. X       (intern var))))
  895. )
  896. (setq calc-given-value-flag nil)
  897. X
  898. (defvar calc-var-name-map nil "Keymap for reading Calc variable names.")
  899. (if calc-var-name-map
  900. X    ()
  901. X  (setq calc-var-name-map (copy-keymap minibuffer-local-completion-map))
  902. X  (define-key calc-var-name-map " " 'self-insert-command)
  903. X  (mapcar (function
  904. X       (lambda (x)
  905. X         (define-key calc-var-name-map (char-to-string x)
  906. X           'calcVar-digit)))
  907. X      "0123456789")
  908. X  (mapcar (function
  909. X       (lambda (x)
  910. X         (define-key calc-var-name-map (char-to-string x)
  911. X           'calcVar-oper)))
  912. X      "+-*/^|")
  913. )
  914. X
  915. (defun calcVar-digit ()
  916. X  (interactive)
  917. X  (if (calc-minibuffer-contains "var-\\'")
  918. X      (if (eq calc-store-opers 0)
  919. X      (beep)
  920. X    (insert "q")
  921. X    (self-insert-and-exit))
  922. X    (self-insert-command 1))
  923. )
  924. X
  925. (defun calcVar-oper ()
  926. X  (interactive)
  927. X  (if (and (eq calc-store-opers t)
  928. X       (calc-minibuffer-contains "var-\\'"))
  929. X      (progn
  930. X    (erase-buffer)
  931. X    (self-insert-and-exit))
  932. X    (self-insert-command 1))
  933. )
  934. X
  935. (defun calc-store-map (&optional oper var)
  936. X  (interactive)
  937. X  (calc-wrapper
  938. X   (let* ((sel-mode nil)
  939. X      (calc-dollar-values (mapcar 'calc-get-stack-element
  940. X                      (nthcdr calc-stack-top calc-stack)))
  941. X      (calc-dollar-used 0)
  942. X      (oper (or oper (calc-get-operator "Store Mapping")))
  943. X      (nargs (car oper)))
  944. X     (or var (setq var (calc-read-var-name (format "Store Mapping %s: "
  945. X                           (nth 2 oper)))))
  946. X     (if var
  947. X     (let ((old (or (calc-var-value var)
  948. X            (error "No such variable: \"%s\""
  949. X                   (calc-var-name var))))
  950. X           (calc-simplify-mode (if (eq calc-simplify-mode 'none)
  951. X                       'num calc-simplify-mode))
  952. X           (values (and (> nargs 1)
  953. X                (calc-top-list (1- nargs) (1+ calc-dollar-used)))))
  954. X       (message "Working...")
  955. X       (calc-set-command-flag 'clear-message)
  956. X       (if (stringp old)
  957. X           (setq old (math-read-expr old)))
  958. X       (if (eq (car-safe old) 'error)
  959. X           (error "Bad format in variable contents: %s" (nth 2 old)))
  960. X       (setq values (if (calc-is-inverse)
  961. X                (append values (list old))
  962. X              (append (list old) values)))
  963. X       (calc-store-value var
  964. X                 (calc-normalize (cons (nth 1 oper) values))
  965. X                 (nth 2 oper)
  966. X                 (+ calc-dollar-used (1- nargs)))))))
  967. )
  968. X
  969. (defun calc-store-exchange (&optional var)
  970. X  (interactive)
  971. X  (calc-wrapper
  972. X   (let ((calc-given-value nil)
  973. X     (calc-given-value-flag 1)
  974. X     top)
  975. X     (or var (setq var (calc-read-var-name "Exchange with: ")))
  976. X     (if var
  977. X     (let ((value (calc-var-value var)))
  978. X       (or value
  979. X           (error "No such variable: \"%s\"" (calc-var-name var)))
  980. X       (if (eq (car-safe value) 'special-const)
  981. X           (error "%s is a special constant" var))
  982. X       (setq top (or calc-given-value (calc-top 1)))
  983. X       (calc-store-value var top nil)
  984. X       (calc-pop-push-record calc-given-value-flag
  985. X                 (concat "<>" (calc-var-name var)) value)))))
  986. )
  987. X
  988. (defun calc-unstore (&optional var)
  989. X  (interactive)
  990. X  (calc-wrapper
  991. X   (or var (setq var (calc-read-var-name "Unstore: ")))
  992. X   (if var
  993. X       (progn
  994. X     (and (memq var '(var-e var-i var-pi var-phi var-gamma))
  995. X          (eq (car-safe (calc-var-value var)) 'special-const)
  996. X          (message "(Note: Built-in definition of %s has been lost)" var))
  997. X     (if (and (boundp var) (symbol-value var))
  998. X         (message "Unstored variable \"%s\"" (calc-var-name var))
  999. X       (message "Variable \"%s\" remains unstored" (calc-var-name var)))
  1000. X     (makunbound var)
  1001. X     (calc-refresh-evaltos var))))
  1002. )
  1003. X
  1004. (defun calc-let (&optional var)
  1005. X  (interactive)
  1006. X  (calc-wrapper
  1007. X   (let* ((calc-given-value nil)
  1008. X      (calc-given-value-flag 1)
  1009. X      thing value)
  1010. X     (or var (setq var (calc-read-var-name "Let variable: ")))
  1011. X     (if calc-given-value
  1012. X     (setq value calc-given-value
  1013. X           thing (calc-top 1))
  1014. X       (setq value (calc-top 1)
  1015. X         thing (calc-top 2)))
  1016. X     (setq var (if var
  1017. X           (list (cons var value))
  1018. X         (calc-is-assignments value)))
  1019. X     (if var
  1020. X     (calc-pop-push-record
  1021. X      (1+ calc-given-value-flag)
  1022. X      (concat "=" (calc-var-name (car (car var))))
  1023. X      (let ((saved-val (mapcar (function
  1024. X                    (lambda (v)
  1025. X                      (and (boundp (car v))
  1026. X                       (symbol-value (car v)))))
  1027. X                   var)))
  1028. X        (unwind-protect
  1029. X        (let ((vv var))
  1030. X          (while vv
  1031. X            (set (car (car vv)) (calc-normalize (cdr (car vv))))
  1032. X            (calc-refresh-evaltos (car (car vv)))
  1033. X            (setq vv (cdr vv)))
  1034. X          (math-evaluate-expr thing))
  1035. X          (while saved-val
  1036. X        (if (car saved-val)
  1037. X            (set (car (car var)) (car saved-val))
  1038. X          (makunbound (car (car var))))
  1039. X        (setq saved-val (cdr saved-val)
  1040. X              var (cdr var)))
  1041. X          (calc-handle-whys)))))))
  1042. )
  1043. X
  1044. (defun calc-is-assignments (value)
  1045. X  (if (memq (car-safe value) '(calcFunc-eq calcFunc-assign))
  1046. X      (and (eq (car-safe (nth 1 value)) 'var)
  1047. X       (list (cons (nth 2 (nth 1 value)) (nth 2 value))))
  1048. X    (if (eq (car-safe value) 'vec)
  1049. X    (let ((vv nil))
  1050. X      (while (and (setq value (cdr value))
  1051. X              (memq (car-safe (car value))
  1052. X                '(calcFunc-eq calcFunc-assign))
  1053. X              (eq (car-safe (nth 1 (car value))) 'var))
  1054. X        (setq vv (cons (cons (nth 2 (nth 1 (car value)))
  1055. X                 (nth 2 (car value)))
  1056. X               vv)))
  1057. X      (and (not value)
  1058. X           vv))))
  1059. )
  1060. X
  1061. (defun calc-recall (&optional var)
  1062. X  (interactive)
  1063. X  (calc-wrapper
  1064. X   (or var (setq var (calc-read-var-name "Recall: ")))
  1065. X   (if var
  1066. X       (let ((value (calc-var-value var)))
  1067. X     (or value
  1068. X         (error "No such variable: \"%s\"" (calc-var-name var)))
  1069. X     (if (stringp value)
  1070. X         (setq value (math-read-expr value)))
  1071. X     (if (eq (car-safe value) 'error)
  1072. X         (error "Bad format in variable contents: %s" (nth 2 value)))
  1073. X     (setq value (calc-normalize value))
  1074. X     (calc-record value (concat "<" (calc-var-name var)))
  1075. X     (calc-push value))))
  1076. )
  1077. X
  1078. (defun calc-store-quick ()
  1079. X  (interactive)
  1080. X  (calc-store (intern (format "var-q%c" last-command-char)))
  1081. )
  1082. X
  1083. (defun calc-store-into-quick ()
  1084. X  (interactive)
  1085. X  (calc-store-into (intern (format "var-q%c" last-command-char)))
  1086. )
  1087. X
  1088. (defun calc-recall-quick ()
  1089. X  (interactive)
  1090. X  (calc-recall (intern (format "var-q%c" last-command-char)))
  1091. )
  1092. X
  1093. (defun calc-copy-variable (&optional var1 var2)
  1094. X  (interactive)
  1095. X  (calc-wrapper
  1096. X   (or var1 (setq var1 (calc-read-var-name "Copy variable: ")))
  1097. X   (if var1
  1098. X       (let ((value (calc-var-value var1)))
  1099. X     (or value
  1100. X         (error "No such variable: \"%s\"" (calc-var-name var)))
  1101. X     (or var2 (setq var2 (calc-read-var-name
  1102. X                  (format "Copy variable: %s, to: " var1))))
  1103. X     (if var2
  1104. X         (calc-store-value var2 value "")))))
  1105. )
  1106. X
  1107. (defun calc-edit-variable (&optional var)
  1108. X  (interactive)
  1109. X  (calc-wrapper
  1110. X   (or var (setq var (calc-read-var-name
  1111. X              (if calc-last-edited-variable
  1112. X              (format "Edit: (default %s) "
  1113. X                  (calc-var-name calc-last-edited-variable))
  1114. X            "Edit: "))))
  1115. X   (or var (setq var calc-last-edited-variable))
  1116. X   (if var
  1117. X       (let* ((value (calc-var-value var)))
  1118. X     (if (eq (car-safe value) 'special-const)
  1119. X         (error "%s is a special constant" var))
  1120. X     (setq calc-last-edited-variable var)
  1121. X     (calc-edit-mode (list 'calc-finish-stack-edit (list 'quote var))
  1122. X             t
  1123. X             (concat "Editing " (calc-var-name var)))
  1124. X     (and value
  1125. X          (insert (math-format-nice-expr value (screen-width)) "\n")))))
  1126. X  (calc-show-edit-buffer)
  1127. )
  1128. (setq calc-last-edited-variable nil)
  1129. X
  1130. (defun calc-edit-Decls ()
  1131. X  (interactive)
  1132. X  (calc-edit-variable 'var-Decls)
  1133. )
  1134. X
  1135. (defun calc-edit-EvalRules ()
  1136. X  (interactive)
  1137. X  (calc-edit-variable 'var-EvalRules)
  1138. )
  1139. X
  1140. (defun calc-edit-FitRules ()
  1141. X  (interactive)
  1142. X  (calc-edit-variable 'var-FitRules)
  1143. )
  1144. X
  1145. (defun calc-edit-GenCount ()
  1146. X  (interactive)
  1147. X  (calc-edit-variable 'var-GenCount)
  1148. )
  1149. X
  1150. (defun calc-edit-LineStyles ()
  1151. X  (interactive)
  1152. X  (calc-edit-variable 'var-LineStyles)
  1153. )
  1154. X
  1155. (defun calc-edit-PointStyles ()
  1156. X  (interactive)
  1157. X  (calc-edit-variable 'var-PointStyles)
  1158. )
  1159. X
  1160. (defun calc-edit-PlotRejects ()
  1161. X  (interactive)
  1162. X  (calc-edit-variable 'var-PlotRejects)
  1163. )
  1164. X
  1165. (defun calc-edit-AlgSimpRules ()
  1166. X  (interactive)
  1167. X  (calc-edit-variable 'var-AlgSimpRules)
  1168. )
  1169. X
  1170. (defun calc-edit-TimeZone ()
  1171. X  (interactive)
  1172. X  (calc-edit-variable 'var-TimeZone)
  1173. )
  1174. X
  1175. (defun calc-edit-UnitSimpRules ()
  1176. X  (interactive)
  1177. X  (calc-edit-variable 'var-UnitSimpRules)
  1178. )
  1179. X
  1180. (defun calc-edit-ExtSimpRules ()
  1181. X  (interactive)
  1182. X  (calc-edit-variable 'var-ExtSimpRules)
  1183. )
  1184. X
  1185. (defun calc-declare-variable (&optional var)
  1186. X  (interactive)
  1187. X  (calc-wrapper
  1188. X   (or var (setq var (calc-read-var-name "Declare: " 0)))
  1189. X   (or var (setq var 'var-All))
  1190. X   (let* (dp decl def row rp)
  1191. X     (or (and (calc-var-value 'var-Decls)
  1192. X          (eq (car-safe var-Decls) 'vec))
  1193. X     (setq var-Decls (list 'vec)))
  1194. X     (setq dp var-Decls)
  1195. X     (while (and (setq dp (cdr dp))
  1196. X         (or (not (eq (car-safe (car dp)) 'vec))
  1197. X             (/= (length (car dp)) 3)
  1198. X             (progn
  1199. X               (setq row (nth 1 (car dp))
  1200. X                 rp row)
  1201. X               (if (eq (car-safe row) 'vec)
  1202. X               (progn
  1203. X                 (while
  1204. X                 (and (setq rp (cdr rp))
  1205. X                      (or (not (eq (car-safe (car rp)) 'var))
  1206. X                      (not (eq (nth 2 (car rp)) var)))))
  1207. X                 (setq rp (car rp)))
  1208. X             (if (or (not (eq (car-safe row) 'var))
  1209. X                 (not (eq (nth 2 row) var)))
  1210. X                 (setq rp nil)))
  1211. X               (not rp)))))
  1212. X     (setq unread-command-char ?\C-a
  1213. X       decl (read-string (format "Declare: %s  to be: " var)
  1214. X                 (and rp
  1215. X                  (math-format-flat-expr (nth 2 (car dp)) 0))))
  1216. X     (setq decl (and (string-match "[^ \t]" decl)
  1217. X             (math-read-exprs decl)))
  1218. X     (if (eq (car-safe decl) 'error)
  1219. X     (error "Bad format in declaration: %s" (nth 2 decl)))
  1220. X     (if (cdr decl)
  1221. X     (setq decl (cons 'vec decl))
  1222. X       (setq decl (car decl)))
  1223. X     (and (eq (car-safe decl) 'vec)
  1224. X      (= (length decl) 2)
  1225. X      (setq decl (nth 1 decl)))
  1226. X     (calc-record (append '(vec) (list (math-build-var-name var))
  1227. X              (and decl (list decl)))
  1228. X          "decl")
  1229. X     (setq var-Decls (copy-sequence var-Decls))
  1230. X     (if (eq (car-safe row) 'vec)
  1231. X     (progn
  1232. X       (setcdr row (delq rp (cdr row)))
  1233. X       (or (cdr row)
  1234. X           (setq var-Decls (delq (car dp) var-Decls))))
  1235. X       (setq var-Decls (delq (car dp) var-Decls)))
  1236. X     (if decl
  1237. X     (progn
  1238. X       (setq dp (and (not (eq var 'var-All)) var-Decls))
  1239. X       (while (and (setq dp (cdr dp))
  1240. X               (or (not (eq (car-safe (car dp)) 'vec))
  1241. X               (/= (length (car dp)) 3)
  1242. X               (not (equal (nth 2 (car dp)) decl)))))
  1243. X       (if dp
  1244. X           (setcar (cdr (car dp))
  1245. X               (append (if (eq (car-safe (nth 1 (car dp))) 'vec)
  1246. X                   (nth 1 (car dp))
  1247. X                 (list 'vec (nth 1 (car dp))))
  1248. X                   (list (math-build-var-name var))))
  1249. X         (setq var-Decls (append var-Decls
  1250. X                     (list (list 'vec
  1251. X                         (math-build-var-name var)
  1252. X                         decl)))))))
  1253. X     (calc-refresh-evaltos 'var-Decls)))
  1254. )
  1255. X
  1256. (defun calc-permanent-variable (&optional var)
  1257. X  (interactive)
  1258. X  (calc-wrapper
  1259. X   (or var (setq var (calc-read-var-name "Save variable (default=all): ")))
  1260. X   (let (pos)
  1261. X     (and var (or (and (boundp var) (symbol-value var))
  1262. X          (error "No such variable")))
  1263. X     (set-buffer (find-file-noselect (substitute-in-file-name
  1264. X                      calc-settings-file)))
  1265. X     (if var
  1266. X     (calc-insert-permanent-variable var)
  1267. X       (mapatoms (function
  1268. X          (lambda (x)
  1269. X            (and (string-match "\\`var-" (symbol-name x))
  1270. X             (not (memq x calc-dont-insert-variables))
  1271. X             (calc-var-value x)
  1272. X             (not (eq (car-safe (symbol-value x)) 'special-const))
  1273. X             (calc-insert-permanent-variable x))))))
  1274. X     (save-buffer)))
  1275. )
  1276. (defvar calc-dont-insert-variables '(var-FitRules var-FactorRules
  1277. X                     var-CommuteRules var-JumpRules
  1278. X                     var-DistribRules var-MergeRules
  1279. X                     var-NegateRules var-InvertRules
  1280. X                     var-IntegAfterRules
  1281. X                     var-TimeZone var-PlotRejects
  1282. X                     var-PlotData1 var-PlotData2
  1283. X                     var-PlotData3 var-PlotData4
  1284. X                     var-PlotData5 var-PlotData6
  1285. X                     var-DUMMY
  1286. ))
  1287. X
  1288. (defun calc-insert-permanent-variable (var)
  1289. X  (goto-char (point-min))
  1290. X  (if (search-forward (concat "(setq " (symbol-name var) " '") nil t)
  1291. X      (progn
  1292. X    (setq pos (point-marker))
  1293. X    (forward-line -1)
  1294. X    (if (looking-at ";;; Variable .* stored by Calc on ")
  1295. X        (progn
  1296. X          (delete-region (match-end 0) (progn (end-of-line) (point)))
  1297. X          (insert (current-time-string))))
  1298. X    (goto-char (- pos 8 (length (symbol-name var))))
  1299. X    (forward-sexp 1)
  1300. X    (backward-char 1)
  1301. X    (delete-region pos (point)))
  1302. X    (goto-char (point-max))
  1303. X    (insert "\n;;; Variable \""
  1304. X        (symbol-name var)
  1305. X        "\" stored by Calc on "
  1306. X        (current-time-string)
  1307. X        "\n(setq "
  1308. X        (symbol-name var)
  1309. X        " ')\n")
  1310. X    (backward-char 2))
  1311. X  (insert (prin1-to-string (calc-var-value var)))
  1312. X  (forward-line 1)
  1313. )
  1314. X
  1315. (defun calc-insert-variables (buf)
  1316. X  (interactive "bBuffer in which to save variable values: ")
  1317. X  (save-excursion
  1318. X    (set-buffer buf)
  1319. X    (mapatoms (function
  1320. X           (lambda (x)
  1321. X         (and (string-match "\\`var-" (symbol-name x))
  1322. X              (not (memq x calc-dont-insert-variables))
  1323. X              (calc-var-value x)
  1324. X              (not (eq (car-safe (symbol-value x)) 'special-const))
  1325. X              (or (not (eq x 'var-Decls))
  1326. X              (not (equal var-Decls '(vec))))
  1327. X              (insert "(setq "
  1328. X                  (symbol-name x)
  1329. X                  " "
  1330. X                  (prin1-to-string
  1331. X                   (let ((calc-language
  1332. X                      (if (memq calc-language '(nil big))
  1333. X                      'flat
  1334. X                    calc-language)))
  1335. X                 (math-format-value (symbol-value x) 100000)))
  1336. X                  ")\n"))))))
  1337. )
  1338. X
  1339. (defun calc-assign (arg)
  1340. X  (interactive "P")
  1341. X  (calc-slow-wrapper
  1342. X   (calc-binary-op ":=" 'calcFunc-assign arg))
  1343. )
  1344. X
  1345. (defun calc-evalto (arg)
  1346. X  (interactive "P")
  1347. X  (calc-slow-wrapper
  1348. X   (calc-unary-op "=>" 'calcFunc-evalto arg))
  1349. )
  1350. X
  1351. (defun calc-subscript (arg)
  1352. X  (interactive "P")
  1353. X  (calc-slow-wrapper
  1354. X   (calc-binary-op "sub" 'calcFunc-subscr arg))
  1355. )
  1356. X
  1357. SHAR_EOF
  1358. chmod 0644 calc-store.el ||
  1359. echo 'restore of calc-store.el failed'
  1360. Wc_c="`wc -c < 'calc-store.el'`"
  1361. test 18912 -eq "$Wc_c" ||
  1362.     echo 'calc-store.el: original size 18912, current size' "$Wc_c"
  1363. rm -f _shar_wnt_.tmp
  1364. fi
  1365. # ============= calc-stuff.el ==============
  1366. if test -f 'calc-stuff.el' -a X"$1" != X"-c"; then
  1367.     echo 'x - skipping calc-stuff.el (File already exists)'
  1368.     rm -f _shar_wnt_.tmp
  1369. else
  1370. > _shar_wnt_.tmp
  1371. echo 'x - extracting calc-stuff.el (Text)'
  1372. sed 's/^X//' << 'SHAR_EOF' > 'calc-stuff.el' &&
  1373. ;; Calculator for GNU Emacs, part II [calc-stuff.el]
  1374. ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  1375. ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
  1376. X
  1377. ;; This file is part of GNU Emacs.
  1378. X
  1379. ;; GNU Emacs is distributed in the hope that it will be useful,
  1380. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  1381. ;; accepts responsibility to anyone for the consequences of using it
  1382. ;; or for whether it serves any particular purpose or works at all,
  1383. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  1384. ;; License for full details.
  1385. X
  1386. ;; Everyone is granted permission to copy, modify and redistribute
  1387. ;; GNU Emacs, but only under the conditions described in the
  1388. ;; GNU Emacs General Public License.   A copy of this license is
  1389. ;; supposed to have been given to you along with GNU Emacs so you
  1390. ;; can know your rights and responsibilities.  It should be in a
  1391. ;; file named COPYING.  Among other things, the copyright notice
  1392. ;; and this notice must be preserved on all copies.
  1393. X
  1394. X
  1395. X
  1396. ;; This file is autoloaded from calc-ext.el.
  1397. (require 'calc-ext)
  1398. X
  1399. (require 'calc-macs)
  1400. X
  1401. (defun calc-Need-calc-stuff () nil)
  1402. X
  1403. X
  1404. (defun calc-num-prefix (n)
  1405. X  "Use the number at the top of stack as the numeric prefix for the next command.
  1406. With a prefix, push that prefix as a number onto the stack."
  1407. X  (interactive "P")
  1408. X  (calc-wrapper
  1409. X   (if n
  1410. X       (calc-enter-result 0 "" (prefix-numeric-value n))
  1411. X     (let ((num (calc-top 1)))
  1412. X       (if (math-messy-integerp num)
  1413. X       (setq num (math-trunc num)))
  1414. X       (or (integerp num)
  1415. X       (error "Argument must be a small integer"))
  1416. X       (calc-pop-stack 1)
  1417. X       (setq prefix-arg num)
  1418. X       (message "%d-" num))))    ; a (lame) simulation of the real thing...
  1419. )
  1420. X
  1421. X
  1422. (defun calc-more-recursion-depth (n)
  1423. X  (interactive "P")
  1424. X  (calc-wrapper
  1425. X   (if (calc-is-inverse)
  1426. X       (calc-less-recursion-depth n)
  1427. X     (let ((n (if n (prefix-numeric-value n) 2)))
  1428. X       (if (> n 1)
  1429. X       (setq max-specpdl-size (* max-specpdl-size n)
  1430. X         max-lisp-eval-depth (* max-lisp-eval-depth n))))
  1431. X     (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth)))
  1432. )
  1433. X
  1434. (defun calc-less-recursion-depth (n)
  1435. X  (interactive "P")
  1436. X  (let ((n (if n (prefix-numeric-value n) 2)))
  1437. X    (if (> n 1)
  1438. X    (setq max-specpdl-size
  1439. X          (max (/ max-specpdl-size n) 600)
  1440. X          max-lisp-eval-depth
  1441. X          (max (/ max-lisp-eval-depth n) 200))))
  1442. X  (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth)
  1443. )
  1444. X
  1445. X
  1446. (defun calc-explain-why (why &optional more)
  1447. X  (if (eq (car why) '*)
  1448. X      (setq why (cdr why)))
  1449. X  (let* ((pred (car why))
  1450. X     (arg (nth 1 why))
  1451. X     (msg (cond ((not pred) "Wrong type of argument")
  1452. X            ((stringp pred) pred)
  1453. X            ((eq pred 'integerp) "Integer expected")
  1454. X            ((eq pred 'natnump)
  1455. X             (if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
  1456. X             "Integer expected"
  1457. X               "Nonnegative integer expected"))
  1458. X            ((eq pred 'posintp)
  1459. X             (if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
  1460. X             "Integer expected"
  1461. X               "Positive integer expected"))
  1462. X            ((eq pred 'fixnump)
  1463. X             (if (and arg (Math-integerp arg))
  1464. X             "Small integer expected"
  1465. X               "Integer expected"))
  1466. X            ((eq pred 'fixnatnump)
  1467. X             (if (and arg (Math-natnump arg))
  1468. X             "Small integer expected"
  1469. X               (if (and arg (Math-objvecp arg)
  1470. X                (not (Math-integerp arg)))
  1471. X               "Integer expected"
  1472. X             "Nonnegative integer expected")))
  1473. X            ((eq pred 'fixposintp)
  1474. X             (if (and arg (Math-integerp arg) (Math-posp arg))
  1475. X             "Small integer expected"
  1476. X               (if (and arg (Math-objvecp arg)
  1477. X                (not (Math-integerp arg)))
  1478. X               "Integer expected"
  1479. X             "Positive integer expected")))
  1480. X            ((eq pred 'posp) "Positive number expected")
  1481. X            ((eq pred 'negp) "Negative number expected")
  1482. X            ((eq pred 'nonzerop) "Nonzero number expected")
  1483. X            ((eq pred 'realp) "Real number expected")
  1484. X            ((eq pred 'anglep) "Real number expected")
  1485. X            ((eq pred 'hmsp) "HMS form expected")
  1486. X            ((eq pred 'datep)
  1487. X             (if (and arg (Math-objectp arg))
  1488. X             "Real number or date form expected"
  1489. X               "Date form expected"))
  1490. X            ((eq pred 'numberp) "Number expected")
  1491. X            ((eq pred 'scalarp) "Number expected")
  1492. X            ((eq pred 'vectorp) "Vector or matrix expected")
  1493. X            ((eq pred 'numvecp) "Number or vector expected")
  1494. X            ((eq pred 'matrixp) "Matrix expected")
  1495. X            ((eq pred 'square-matrixp)
  1496. X             (if (and arg (math-matrixp arg))
  1497. X             "Square matrix expected"
  1498. X               "Matrix expected"))
  1499. X            ((eq pred 'objectp) "Number expected")
  1500. X            ((eq pred 'constp) "Constant expected")
  1501. X            ((eq pred 'range) "Argument out of range")
  1502. X            (t (format "%s expected" pred))))
  1503. X     (punc ": ")
  1504. X     (calc-can-abbrev-vectors t))
  1505. X    (while (setq why (cdr why))
  1506. X      (and (car why)
  1507. X       (setq msg (concat msg punc (if (stringp (car why))
  1508. X                      (car why)
  1509. X                    (math-format-flat-expr (car why) 0)))
  1510. X         punc ", ")))
  1511. X    (message "%s%s" msg (if more "  [w=more]" "")))
  1512. )
  1513. X
  1514. (defun calc-why ()
  1515. X  (interactive)
  1516. X  (if (not (eq this-command last-command))
  1517. X      (if (eq last-command calc-last-why-command)
  1518. X      (setq calc-which-why (cdr calc-why))
  1519. X    (setq calc-which-why calc-why)))
  1520. X  (if calc-which-why
  1521. X      (progn
  1522. X    (calc-explain-why (car calc-which-why) (cdr calc-which-why))
  1523. X    (setq calc-which-why (cdr calc-which-why)))
  1524. X    (if calc-why
  1525. X    (progn
  1526. X      (message "(No further explanations available)")
  1527. X      (setq calc-which-why calc-why))
  1528. X      (message "No explanations available")))
  1529. )
  1530. (setq calc-which-why nil)
  1531. (setq calc-last-why-command nil)
  1532. X
  1533. X
  1534. (defun calc-version ()
  1535. X  (interactive)
  1536. X  (message "Calc %s, installed %s" calc-version calc-installed-date))
  1537. X
  1538. X
  1539. (defun calc-flush-caches ()
  1540. X  (interactive)
  1541. X  (calc-wrapper
  1542. X   (setq math-lud-cache nil
  1543. X     math-log2-cache nil
  1544. X     math-radix-digits-cache nil
  1545. X     math-radix-float-cache-tag nil
  1546. X     math-random-cache nil
  1547. X     math-max-digits-cache nil
  1548. X     math-checked-rewrites nil
  1549. X     math-integral-cache nil
  1550. X     math-units-table nil
  1551. X     math-decls-cache-tag nil
  1552. X     math-eval-rules-cache-tag t
  1553. X     math-graph-var-cache nil
  1554. X     math-graph-data-cache nil
  1555. X     math-format-date-cache nil)
  1556. X   (mapcar (function (lambda (x) (set x -100))) math-cache-list)
  1557. X   (message "All internal calculator caches have been reset."))
  1558. )
  1559. X
  1560. X
  1561. ;;; Conversions.
  1562. X
  1563. (defun calc-clean (n)
  1564. X  (interactive "P")
  1565. X  (calc-slow-wrapper
  1566. X   (calc-with-default-simplification
  1567. X    (let ((func (if (calc-is-hyperbolic) 'calcFunc-clean 'calcFunc-pclean)))
  1568. X      (calc-enter-result 1 "cln"
  1569. X             (if n
  1570. X                 (let ((n (prefix-numeric-value n)))
  1571. X                   (list func
  1572. X                     (calc-top-n 1)
  1573. X                     (if (<= n 0)
  1574. X                     (+ n calc-internal-prec)
  1575. X                       n)))
  1576. X               (list func (calc-top-n 1)))))))
  1577. )
  1578. X
  1579. (defun calc-clean-num (num)
  1580. X  (interactive "P")
  1581. X  (calc-clean (- (if num
  1582. X             (prefix-numeric-value num) 
  1583. X           (if (and (>= last-command-char ?0)
  1584. X                (<= last-command-char ?9))
  1585. X               (- last-command-char ?0)
  1586. X             (error "Number required")))))
  1587. )
  1588. X
  1589. X
  1590. (defun calcFunc-clean (a &optional prec)   ; [X X S] [Public]
  1591. X  (if prec
  1592. X      (cond ((Math-messy-integerp prec)
  1593. X         (calcFunc-clean a (math-trunc prec)))
  1594. X        ((or (not (integerp prec))
  1595. X         (< prec 3))
  1596. X         (calc-record-why "*Precision must be an integer 3 or above")
  1597. X         (list 'calcFunc-clean a prec))
  1598. X        ((not (Math-objvecp a))
  1599. X         (list 'calcFunc-clean a prec))
  1600. X        (t (let ((calc-internal-prec prec)
  1601. X             (math-chopping-small t))
  1602. X         (calcFunc-clean (math-normalize a)))))
  1603. X    (cond ((eq (car-safe a) 'polar)
  1604. X       (let ((theta (math-mod (nth 2 a)
  1605. X                  (if (eq calc-angle-mode 'rad)
  1606. X                      (math-two-pi)
  1607. X                    360))))
  1608. X         (math-neg
  1609. X          (math-neg
  1610. X           (math-normalize
  1611. X        (list 'polar
  1612. X              (calcFunc-clean (nth 1 a))
  1613. X              (calcFunc-clean theta)))))))
  1614. X      ((memq (car-safe a) '(vec date hms))
  1615. X       (cons (car a) (mapcar 'calcFunc-clean (cdr a))))
  1616. X      ((memq (car-safe a) '(cplx mod sdev intv))
  1617. X       (math-normalize (cons (car a) (mapcar 'calcFunc-clean (cdr a)))))
  1618. X      ((eq (car-safe a) 'float)
  1619. X       (if math-chopping-small
  1620. X           (if (or (> (nth 2 a) (- calc-internal-prec))
  1621. X               (Math-lessp (- calc-internal-prec) (calcFunc-xpon a)))
  1622. X           (if (and (math-num-integerp a)
  1623. X                (math-lessp (calcFunc-xpon a) calc-internal-prec))
  1624. X               (math-trunc a)
  1625. X             a)
  1626. X         0)
  1627. X         a))
  1628. X      ((Math-objectp a) a)
  1629. X      ((math-infinitep a) a)
  1630. X      (t (list 'calcFunc-clean a))))
  1631. )
  1632. (setq math-chopping-small nil)
  1633. X
  1634. (defun calcFunc-pclean (a &optional prec)
  1635. X  (math-map-over-constants (function (lambda (x) (calcFunc-clean x prec)))
  1636. X               a)
  1637. )
  1638. X
  1639. (defun calcFunc-pfloat (a)
  1640. X  (math-map-over-constants 'math-float a)
  1641. )
  1642. X
  1643. (defun calcFunc-pfrac (a &optional tol)
  1644. X  (math-map-over-constants (function (lambda (x) (calcFunc-frac x tol)))
  1645. X               a)
  1646. )
  1647. X
  1648. (defun math-map-over-constants (func expr)
  1649. X  (math-map-over-constants-rec expr)
  1650. )
  1651. X
  1652. (defun math-map-over-constants-rec (expr)
  1653. X  (cond ((or (Math-primp expr)
  1654. X         (memq (car expr) '(intv sdev)))
  1655. X     (or (and (Math-objectp expr)
  1656. X          (funcall func expr))
  1657. X         expr))
  1658. X    ((and (memq (car expr) '(^ calcFunc-subscr))
  1659. X          (eq func 'math-float)
  1660. X          (= (length expr) 3)
  1661. X          (Math-integerp (nth 2 expr)))
  1662. X     (list (car expr)
  1663. X           (math-map-over-constants-rec (nth 1 expr))
  1664. X           (nth 2 expr)))
  1665. X    (t (cons (car expr) (mapcar 'math-map-over-constants-rec (cdr expr)))))
  1666. )
  1667. X
  1668. X
  1669. X
  1670. X
  1671. SHAR_EOF
  1672. chmod 0644 calc-stuff.el ||
  1673. echo 'restore of calc-stuff.el failed'
  1674. Wc_c="`wc -c < 'calc-stuff.el'`"
  1675. test 9150 -eq "$Wc_c" ||
  1676.     echo 'calc-stuff.el: original size 9150, current size' "$Wc_c"
  1677. rm -f _shar_wnt_.tmp
  1678. fi
  1679. # ============= calc-trail.el ==============
  1680. if test -f 'calc-trail.el' -a X"$1" != X"-c"; then
  1681.     echo 'x - skipping calc-trail.el (File already exists)'
  1682.     rm -f _shar_wnt_.tmp
  1683. else
  1684. > _shar_wnt_.tmp
  1685. echo 'x - extracting calc-trail.el (Text)'
  1686. sed 's/^X//' << 'SHAR_EOF' > 'calc-trail.el' &&
  1687. ;; Calculator for GNU Emacs, part II [calc-trail.el]
  1688. ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  1689. ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
  1690. X
  1691. ;; This file is part of GNU Emacs.
  1692. X
  1693. ;; GNU Emacs is distributed in the hope that it will be useful,
  1694. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  1695. ;; accepts responsibility to anyone for the consequences of using it
  1696. ;; or for whether it serves any particular purpose or works at all,
  1697. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  1698. ;; License for full details.
  1699. X
  1700. ;; Everyone is granted permission to copy, modify and redistribute
  1701. ;; GNU Emacs, but only under the conditions described in the
  1702. ;; GNU Emacs General Public License.   A copy of this license is
  1703. ;; supposed to have been given to you along with GNU Emacs so you
  1704. ;; can know your rights and responsibilities.  It should be in a
  1705. ;; file named COPYING.  Among other things, the copyright notice
  1706. ;; and this notice must be preserved on all copies.
  1707. X
  1708. X
  1709. X
  1710. ;; This file is autoloaded from calc-ext.el.
  1711. (require 'calc-ext)
  1712. X
  1713. (require 'calc-macs)
  1714. X
  1715. (defun calc-Need-calc-trail () nil)
  1716. X
  1717. X
  1718. ;;; Trail commands.
  1719. X
  1720. (defun calc-trail-in ()
  1721. X  (interactive)
  1722. X  (let ((win (get-buffer-window (calc-trail-display t))))
  1723. X    (and win (select-window win)))
  1724. )
  1725. X
  1726. (defun calc-trail-out ()
  1727. X  (interactive)
  1728. X  (calc-select-buffer)
  1729. X  (let ((win (get-buffer-window (current-buffer))))
  1730. X    (if win
  1731. X    (progn
  1732. X      (select-window win)
  1733. X      (calc-align-stack-window))
  1734. X      (calc)))
  1735. )
  1736. X
  1737. (defun calc-trail-next (n)
  1738. X  (interactive "p")
  1739. X  (calc-with-trail-buffer
  1740. X   (forward-line n)
  1741. X   (calc-trail-here))
  1742. )
  1743. X
  1744. (defun calc-trail-previous (n)
  1745. X  (interactive "p")
  1746. X  (calc-with-trail-buffer
  1747. X   (forward-line (- n))
  1748. X   (calc-trail-here))
  1749. )
  1750. X
  1751. (defun calc-trail-first (n)
  1752. X  (interactive "p")
  1753. X  (calc-with-trail-buffer
  1754. X   (goto-char (point-min))
  1755. X   (forward-line n)
  1756. X   (calc-trail-here))
  1757. )
  1758. X
  1759. (defun calc-trail-last (n)
  1760. X  (interactive "p")
  1761. X  (calc-with-trail-buffer
  1762. X   (goto-char (point-max))
  1763. X   (forward-line (- n))
  1764. X   (calc-trail-here))
  1765. )
  1766. X
  1767. (defun calc-trail-scroll-left (n)
  1768. X  (interactive "P")
  1769. X  (let ((curwin (selected-window)))
  1770. X    (calc-with-trail-buffer
  1771. X     (unwind-protect
  1772. X     (progn
  1773. X       (select-window (get-buffer-window (current-buffer)))
  1774. X       (calc-scroll-left n))
  1775. X       (select-window curwin))))
  1776. )
  1777. X
  1778. (defun calc-trail-scroll-right (n)
  1779. X  (interactive "P")
  1780. X  (let ((curwin (selected-window)))
  1781. X    (calc-with-trail-buffer
  1782. X     (unwind-protect
  1783. X     (progn
  1784. X       (select-window (get-buffer-window (current-buffer)))
  1785. X       (calc-scroll-right n))
  1786. X       (select-window curwin))))
  1787. )
  1788. X
  1789. (defun calc-trail-forward (n)
  1790. X  (interactive "p")
  1791. X  (calc-with-trail-buffer
  1792. X   (forward-line (* n (1- (window-height))))
  1793. X   (calc-trail-here))
  1794. )
  1795. X
  1796. (defun calc-trail-backward (n)
  1797. X  (interactive "p")
  1798. X  (calc-with-trail-buffer
  1799. X   (forward-line (- (* n (1- (window-height)))))
  1800. X   (calc-trail-here))
  1801. )
  1802. X
  1803. (defun calc-trail-isearch-forward ()
  1804. X  (interactive)
  1805. X  (calc-with-trail-buffer
  1806. X   (save-window-excursion
  1807. X     (select-window (get-buffer-window (current-buffer)))
  1808. X     (let ((search-exit-char ?\r))
  1809. X       (isearch t nil)))
  1810. X   (calc-trail-here))
  1811. )
  1812. X
  1813. (defun calc-trail-isearch-backward ()
  1814. X  (interactive)
  1815. X  (calc-with-trail-buffer
  1816. X   (save-window-excursion
  1817. X     (select-window (get-buffer-window (current-buffer)))
  1818. X     (let ((search-exit-char ?\r))
  1819. X       (isearch nil nil)))
  1820. X   (calc-trail-here))
  1821. )
  1822. X
  1823. (defun calc-trail-yank (arg)
  1824. X  (interactive "P")
  1825. X  (calc-wrapper
  1826. X   (or arg (calc-set-command-flag 'hold-trail))
  1827. X   (calc-enter-result 0 "yank"
  1828. X              (calc-with-trail-buffer
  1829. X               (if arg
  1830. X               (forward-line (- (prefix-numeric-value arg))))
  1831. X               (if (or (looking-at "Emacs Calc")
  1832. X                   (looking-at "----")
  1833. X                   (looking-at " ? ? ?[^ \n]* *$")
  1834. X                   (looking-at "..?.?$"))
  1835. X               (error "Can't yank that line"))
  1836. X               (if (looking-at ".*, \\.\\.\\., ")
  1837. X               (error "Can't yank (vector was abbreviated)"))
  1838. X               (forward-char 4)
  1839. X               (search-forward " ")
  1840. X               (let* ((next (save-excursion (forward-line 1) (point)))
  1841. X                  (str (buffer-substring (point) (1- next)))
  1842. X                  (val (save-excursion
  1843. X                     (set-buffer save-buf)
  1844. X                     (math-read-plain-expr str))))
  1845. X             (if (eq (car-safe val) 'error)
  1846. X                 (error "Can't yank that line: %s" (nth 2 val))
  1847. X               val)))))
  1848. )
  1849. X
  1850. (defun calc-trail-marker (str)
  1851. X  (interactive "sText to insert in trail: ")
  1852. X  (calc-with-trail-buffer
  1853. X   (forward-line 1)
  1854. X   (let ((buffer-read-only nil))
  1855. X     (insert "---- " str "\n"))
  1856. X   (forward-line -1)
  1857. X   (calc-trail-here))
  1858. )
  1859. X
  1860. (defun calc-trail-kill (n)
  1861. X  (interactive "p")
  1862. X  (calc-with-trail-buffer
  1863. X   (let ((buffer-read-only nil))
  1864. X     (save-restriction
  1865. X       (narrow-to-region   ; don't delete "Emacs Trail" header
  1866. X    (save-excursion
  1867. X      (goto-char (point-min))
  1868. X      (forward-line 1)
  1869. X      (point))
  1870. X    (point-max))
  1871. X       (kill-line n)))
  1872. X   (calc-trail-here))
  1873. )
  1874. X
  1875. X
  1876. X
  1877. SHAR_EOF
  1878. chmod 0644 calc-trail.el ||
  1879. echo 'restore of calc-trail.el failed'
  1880. Wc_c="`wc -c < 'calc-trail.el'`"
  1881. test 4845 -eq "$Wc_c" ||
  1882.     echo 'calc-trail.el: original size 4845, current size' "$Wc_c"
  1883. rm -f _shar_wnt_.tmp
  1884. fi
  1885. # ============= calc-undo.el ==============
  1886. if test -f 'calc-undo.el' -a X"$1" != X"-c"; then
  1887.     echo 'x - skipping calc-undo.el (File already exists)'
  1888.     rm -f _shar_wnt_.tmp
  1889. else
  1890. > _shar_wnt_.tmp
  1891. echo 'x - extracting calc-undo.el (Text)'
  1892. sed 's/^X//' << 'SHAR_EOF' > 'calc-undo.el' &&
  1893. ;; Calculator for GNU Emacs, part II [calc-undo.el]
  1894. SHAR_EOF
  1895. true || echo 'restore of calc-undo.el failed'
  1896. fi
  1897. echo 'End of  part 27'
  1898. echo 'File calc-undo.el is continued in part 28'
  1899. echo 28 > _shar_seq_.tmp
  1900. exit 0
  1901. exit 0 # Just in case...
  1902. -- 
  1903. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1904. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1905. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1906. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1907.