home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume15 / calc-1.05 / part07 < prev    next >
Lisp/Scheme  |  1990-10-14  |  57KB  |  1,743 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: daveg@csvax.cs.caltech.edu
  3. subject: v15i034: Patch for GNU Emacs Calc, version 1.04 -> 1.05, part 07/20
  4. from: daveg@csvax.cs.caltech.edu (David Gillespie)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 15, Issue 34
  8. Submitted-by: daveg@csvax.cs.caltech.edu (David Gillespie)
  9. Archive-name: calc-1.05/part07
  10.  
  11. #!/bin/sh
  12. # this is part 7 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file calc.patch continued
  15. #
  16. CurArch=7
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. sed 's/^X//' << 'SHAR_EOF' >> calc.patch
  27. X+ which correspond to zeros in mask are deleted.  The length of the
  28. X+ result vector is the number of nonzero elements of the mask."
  29. X+   (interactive "P")
  30. X+   (calc-wrapper
  31. X+    (calc-binary-op "vmsk" 'calcFunc-vmask arg))
  32. X+ )
  33. X+ 
  34. X+ (defun calc-expand-vector (arg)
  35. X+   "Expand a vector according to a mask vector.
  36. X+ Vector is in top of stack, mask is in second-to-top.
  37. X+ The result is a vector of the same length as mask.  Each nonzero element
  38. X+ of mask is replaced by the next element of vec.  If vec has more elements
  39. X+ than mask has nonzero elements, some are omitted.  If vec has fewer
  40. X+ elements, the last few nonzero elements of mask are left the same.
  41. X+ With Hyperbolic flag, top-of-stack is a filler element which is used
  42. X+ instead of zero for zero mask elements; vector and mask are in stack
  43. X+ levels two and three."
  44. X+   (interactive "P")
  45. X+   (calc-wrapper
  46. X+    (if (calc-is-hyperbolic)
  47. X+        (calc-enter-result 3 "vexp" (cons 'calcFunc-vexp (calc-top-list-n 3)))
  48. X+      (calc-binary-op "vexp" 'calcFunc-vexp arg)))
  49. X+ )
  50. X+ 
  51. X  (defun calc-sort ()
  52. X    "Sort the matrix at top of stack into increasing order.
  53. X! With Inverse flag, sort into decreasing order.
  54. X! With Hyperbolic flag, return a permutation vector which would sort the input."
  55. X    (interactive)
  56. X    (calc-slow-wrapper
  57. X     (if (calc-is-inverse)
  58. X***************
  59. X*** 4292,4297 ****
  60. X--- 7907,7922 ----
  61. X       (calc-enter-result 1 "sort" (list 'calcFunc-sort (calc-top-n 1)))))
  62. X  )
  63. X  
  64. X+ (defun calc-grade ()
  65. X+   "Grade the matrix at top of stack into increasing order.
  66. X+ This produces a permutation vector which would sort the input."
  67. X+   (interactive)
  68. X+   (calc-slow-wrapper
  69. X+    (if (calc-is-inverse)
  70. X+        (calc-enter-result 1 "rgrd" (list 'calcFunc-rgrade (calc-top-n 1)))
  71. X+      (calc-enter-result 1 "grad" (list 'calcFunc-grade (calc-top-n 1)))))
  72. X+ )
  73. X+ 
  74. X  (defun calc-histogram (n)
  75. X    "Compile a histogram of a vector of integers in the range [0..N).
  76. X  N is the numeric prefix argument.
  77. X***************
  78. X*** 4375,4410 ****
  79. X     (calc-unary-op "cnrm" 'calcFunc-cnorm arg))
  80. X  )
  81. X  
  82. X! (defun calc-mrow (n)
  83. X    "Replace matrix at top of stack with its Nth row.
  84. X  Numeric prefix N must be between 1 and the height of the matrix.
  85. X  If top of stack is a non-matrix vector, extract its Nth element.
  86. X  If N is negative, remove the Nth row (or element)."
  87. X!   (interactive "NRow number: ")
  88. X    (calc-wrapper
  89. X!    (setq n (prefix-numeric-value n))
  90. X!    (if (= n 0)
  91. X!        (calc-enter-result 1 "getd" (list 'calcFunc-getdiag (calc-top-n 1)))
  92. X!      (if (< n 0)
  93. X!      (calc-enter-result 1 "rrow" (list 'calcFunc-mrrow
  94. X!                        (calc-top-n 1) (- n)))
  95. X!        (calc-enter-result 1 "mrow" (list 'calcFunc-mrow (calc-top-n 1) n)))))
  96. X  )
  97. X  
  98. X! (defun calc-mcol (n)
  99. X    "Replace matrix at top of stack with its Nth column.
  100. X  Numeric prefix N must be between 1 and the width of the matrix.
  101. X  If top of stack is a non-matrix vector, extract its Nth element.
  102. X  If N is negative, remove the Nth column (or element)."
  103. X!   (interactive "NColumn number: ")
  104. X    (calc-wrapper
  105. X!    (setq n (prefix-numeric-value n))
  106. X!    (if (= n 0)
  107. X!        (calc-enter-result 1 "getd" (list 'calcFunc-getdiag (calc-top-n 1)))
  108. X!      (if (< n 0)
  109. X!      (calc-enter-result 1 "rcol" (list 'calcFunc-mrcol
  110. X!                        (calc-top-n 1) (- n)))
  111. X!        (calc-enter-result 1 "mcol" (list 'calcFunc-mcol (calc-top-n 1) n)))))
  112. X  )
  113. X  
  114. X  ;;;; [calc-map.el]
  115. X--- 8000,8041 ----
  116. X     (calc-unary-op "cnrm" 'calcFunc-cnorm arg))
  117. X  )
  118. X  
  119. X! (defun calc-mrow (n &optional nn)
  120. X    "Replace matrix at top of stack with its Nth row.
  121. X  Numeric prefix N must be between 1 and the height of the matrix.
  122. X  If top of stack is a non-matrix vector, extract its Nth element.
  123. X  If N is negative, remove the Nth row (or element)."
  124. X!   (interactive "NRow number: \nP")
  125. X    (calc-wrapper
  126. X!    (if (consp nn)
  127. X!        (calc-enter-result 2 "mrow" (cons 'calcFunc-mrow (calc-top-list-n 2)))
  128. X!      (setq n (prefix-numeric-value n))
  129. X!      (if (= n 0)
  130. X!      (calc-enter-result 1 "getd" (list 'calcFunc-getdiag (calc-top-n 1)))
  131. X!        (if (< n 0)
  132. X!        (calc-enter-result 1 "rrow" (list 'calcFunc-mrrow
  133. X!                          (calc-top-n 1) (- n)))
  134. X!      (calc-enter-result 1 "mrow" (list 'calcFunc-mrow
  135. X!                        (calc-top-n 1) n))))))
  136. X  )
  137. X  
  138. X! (defun calc-mcol (n &optional nn)
  139. X    "Replace matrix at top of stack with its Nth column.
  140. X  Numeric prefix N must be between 1 and the width of the matrix.
  141. X  If top of stack is a non-matrix vector, extract its Nth element.
  142. X  If N is negative, remove the Nth column (or element)."
  143. X!   (interactive "NColumn number: \nP")
  144. X    (calc-wrapper
  145. X!    (if (consp nn)
  146. X!        (calc-enter-result 2 "mcol" (cons 'calcFunc-mcol (calc-top-list-n 2)))
  147. X!      (setq n (prefix-numeric-value n))
  148. X!      (if (= n 0)
  149. X!      (calc-enter-result 1 "getd" (list 'calcFunc-getdiag (calc-top-n 1)))
  150. X!        (if (< n 0)
  151. X!        (calc-enter-result 1 "rcol" (list 'calcFunc-mrcol
  152. X!                          (calc-top-n 1) (- n)))
  153. X!      (calc-enter-result 1 "mcol" (list 'calcFunc-mcol
  154. X!                        (calc-top-n 1) n))))))
  155. X  )
  156. X  
  157. X  ;;;; [calc-map.el]
  158. X***************
  159. X*** 4414,4420 ****
  160. X  For example, applying f to [1, 2, 3] produces f(1, 2, 3)."
  161. X    (interactive)
  162. X    (calc-wrapper
  163. X!    (let* ((calc-dollar-values (mapcar 'car-safe
  164. X                        (nthcdr calc-stack-top calc-stack)))
  165. X        (calc-dollar-used 0)
  166. X        (oper (or oper (calc-get-operator "Apply"
  167. X--- 8045,8052 ----
  168. X  For example, applying f to [1, 2, 3] produces f(1, 2, 3)."
  169. X    (interactive)
  170. X    (calc-wrapper
  171. X!    (let* ((sel-mode nil)
  172. X!       (calc-dollar-values (mapcar 'calc-get-stack-element
  173. X                        (nthcdr calc-stack-top calc-stack)))
  174. X        (calc-dollar-used 0)
  175. X        (oper (or oper (calc-get-operator "Apply"
  176. X***************
  177. X*** 4433,4452 ****
  178. X  
  179. X  (defun calc-reduce (&optional oper)
  180. X    "Apply a binary operator across all elements of a vector.
  181. X! For example, applying + computes the sum of vector elements."
  182. X    (interactive)
  183. X    (calc-wrapper
  184. X!    (let* ((calc-dollar-values (mapcar 'car-safe
  185. X                        (nthcdr calc-stack-top calc-stack)))
  186. X        (calc-dollar-used 0)
  187. X!       (oper (or oper (calc-get-operator "Reduce" 2))))
  188. X       (message "Working...")
  189. X       (calc-set-command-flag 'clear-message)
  190. X       (calc-enter-result (1+ calc-dollar-used)
  191. X!             (concat (substring "red" 0 (- 4 (length (nth 2 oper))))
  192. X                  (nth 2 oper))
  193. X!             (list (intern (concat "calcFunc-reduce"
  194. X!                           (or calc-mapping-dir "")))
  195. X                    (math-calcFunc-to-var (nth 1 oper))
  196. X                    (calc-top-n (1+ calc-dollar-used))))))
  197. X  )
  198. X--- 8065,8091 ----
  199. X  
  200. X  (defun calc-reduce (&optional oper)
  201. X    "Apply a binary operator across all elements of a vector.
  202. X! For example, applying + computes the sum of vector elements.
  203. X! With Hyperbolic flag, accumulate intermediate results into a vector."
  204. X    (interactive)
  205. X    (calc-wrapper
  206. X!    (let* ((sel-mode nil)
  207. X!       (accum (calc-is-hyperbolic))
  208. X!       (calc-dollar-values (mapcar 'calc-get-stack-element
  209. X                        (nthcdr calc-stack-top calc-stack)))
  210. X        (calc-dollar-used 0)
  211. X!       (oper (or oper (calc-get-operator (if accum "Accumulate" "Reduce")
  212. X!                         2))))
  213. X       (message "Working...")
  214. X       (calc-set-command-flag 'clear-message)
  215. X       (calc-enter-result (1+ calc-dollar-used)
  216. X!             (concat (substring (if accum "acc" "red")
  217. X!                        0 (- 4 (length (nth 2 oper))))
  218. X                  (nth 2 oper))
  219. X!             (list (if accum
  220. X!                   'calcFunc-accum
  221. X!                 (intern (concat "calcFunc-reduce"
  222. X!                         (or calc-mapping-dir ""))))
  223. X                    (math-calcFunc-to-var (nth 1 oper))
  224. X                    (calc-top-n (1+ calc-dollar-used))))))
  225. X  )
  226. X***************
  227. X*** 4456,4462 ****
  228. X  For example, applying * computes a vector of products."
  229. X    (interactive)
  230. X    (calc-wrapper
  231. X!    (let* ((calc-dollar-values (mapcar 'car-safe
  232. X                        (nthcdr calc-stack-top calc-stack)))
  233. X        (calc-dollar-used 0)
  234. X        (oper (or oper (calc-get-operator "Map")))
  235. X--- 8095,8102 ----
  236. X  For example, applying * computes a vector of products."
  237. X    (interactive)
  238. X    (calc-wrapper
  239. X!    (let* ((sel-mode nil)
  240. X!       (calc-dollar-values (mapcar 'calc-get-stack-element
  241. X                        (nthcdr calc-stack-top calc-stack)))
  242. X        (calc-dollar-used 0)
  243. X        (oper (or oper (calc-get-operator "Map")))
  244. X***************
  245. X*** 4477,4493 ****
  246. X                       (1+ calc-dollar-used)))))))
  247. X  )
  248. X  
  249. X  ;;; Return a list of the form (nargs func name)
  250. X  (defun calc-get-operator (msg &optional nargs)
  251. X    (let ((inv nil) (hyp nil) (prefix nil)
  252. X      done key oper (which 0)
  253. X      (msgs '( "(Press ? for help)"
  254. X!          "+, -, *, /, ^, %, \\, :, !, |, Neg"
  255. X           "SHIFT + Abs, conJ, arG; maX, miN; Floor, Round; sQrt"
  256. X           "SHIFT + Inv, Hyp; Sin, Cos, Tan; Exp, Ln, logB"
  257. X!          "Binary + And, Or, Xor, Diff; Not, Clip"
  258. X           "Conversions + Deg, Rad, HMS; Float; SHIFT + Fraction"
  259. X!          "Kombinatorics + Dfact, Lcm, Gcd, Binomial, Perms; Random"
  260. X           "Matrix-dir + Elements, Rows, Cols, Across, Down"
  261. X           "X or Z = any function by name; ' = alg entry; $ = stack")))
  262. X      (while (not done)
  263. X--- 8117,8181 ----
  264. X                       (1+ calc-dollar-used)))))))
  265. X  )
  266. X  
  267. X+ (defun calc-outer-product (&optional oper)
  268. X+   "Compute the generalized outer product of two vectors.
  269. X+ For example, using * produces a multiplication table."
  270. X+   (interactive)
  271. X+   (calc-wrapper
  272. X+    (let* ((sel-mode nil)
  273. X+       (calc-dollar-values (mapcar 'calc-get-stack-element
  274. X+                       (nthcdr calc-stack-top calc-stack)))
  275. X+       (calc-dollar-used 0)
  276. X+       (oper (or oper (calc-get-operator "Outer" 2))))
  277. X+      (message "Working...")
  278. X+      (calc-set-command-flag 'clear-message)
  279. X+      (calc-enter-result (+ 2 calc-dollar-used)
  280. X+             (concat (substring "out" 0 (- 4 (length (nth 2 oper))))
  281. X+                 (nth 2 oper))
  282. X+             (cons 'calcFunc-outer
  283. X+                   (cons (math-calcFunc-to-var (nth 1 oper))
  284. X+                     (calc-top-list-n
  285. X+                      2 (1+ calc-dollar-used)))))))
  286. X+ )
  287. X+ 
  288. X+ (defun calc-inner-product (&optional mul-oper add-oper)
  289. X+   "Compute the generalized inner product of two vectors or matrices.
  290. X+ You specify the multiplicative and additive operators or functions to use.
  291. X+ For example, using * and + respectively does a matrix multiplication."
  292. X+   (interactive)
  293. X+   (calc-wrapper
  294. X+    (let* ((sel-mode nil)
  295. X+       (calc-dollar-values (mapcar 'calc-get-stack-element
  296. X+                       (nthcdr calc-stack-top calc-stack)))
  297. X+       (calc-dollar-used 0)
  298. X+       (mul-oper (or mul-oper (calc-get-operator "Inner (Mult)" 2)))
  299. X+       (add-oper (or add-oper (calc-get-operator "Inner (Add)" 2))))
  300. X+      (message "Working...")
  301. X+      (calc-set-command-flag 'clear-message)
  302. X+      (calc-enter-result (+ 2 calc-dollar-used)
  303. X+             (concat "in"
  304. X+                 (substring (nth 2 mul-oper) 0 1)
  305. X+                 (substring (nth 2 add-oper) 0 1))
  306. X+             (nconc (list 'calcFunc-inner
  307. X+                      (math-calcFunc-to-var (nth 1 mul-oper))
  308. X+                      (math-calcFunc-to-var (nth 1 add-oper)))
  309. X+                    (calc-top-list-n 2 (1+ calc-dollar-used))))))
  310. X+ )
  311. X+ 
  312. X  ;;; Return a list of the form (nargs func name)
  313. X  (defun calc-get-operator (msg &optional nargs)
  314. X    (let ((inv nil) (hyp nil) (prefix nil)
  315. X      done key oper (which 0)
  316. X      (msgs '( "(Press ? for help)"
  317. X!          "+, -, *, /, ^, %, \\, :, &, !, |, Neg"
  318. X           "SHIFT + Abs, conJ, arG; maX, miN; Floor, Round; sQrt"
  319. X           "SHIFT + Inv, Hyp; Sin, Cos, Tan; Exp, Ln, logB"
  320. X!          "Algebra + Simp, Esimp, Deriv, Integ, !, =, etc."
  321. X!          "Binary + And, Or, Xor, Diff; l/r/t/L/R shifts; Not, Clip"
  322. X           "Conversions + Deg, Rad, HMS; Float; SHIFT + Fraction"
  323. X!          "Functions + Re, Im; Hypot; Mant, Expon, Scale; etc."
  324. X!          "Kombinatorics + Dfact, Lcm, Gcd, Choose; Random; etc."
  325. X!          "Vectors + Length, Row, Col, Diag, Mask, etc."
  326. X           "Matrix-dir + Elements, Rows, Cols, Across, Down"
  327. X           "X or Z = any function by name; ' = alg entry; $ = stack")))
  328. X      (while (not done)
  329. X***************
  330. X*** 4506,4522 ****
  331. X           (keyboard-quit))
  332. X          ((= key ??)
  333. X           (setq which (% (1+ which) (length msgs))))
  334. X!         ((= key ?I)
  335. X!          (setq inv (not inv)
  336. X!            prefix nil))
  337. X!         ((= key ?H)
  338. X!          (setq hyp (not hyp)
  339. X!            prefix nil))
  340. X          ((eq key prefix)
  341. X           (setq prefix nil))
  342. X!         ((and (memq key '(?b ?c ?k ?m)) (null prefix))
  343. X!          (setq inv nil hyp nil
  344. X!            prefix key))
  345. X          ((eq prefix ?m)
  346. X           (setq prefix nil)
  347. X           (if (eq key ?e)
  348. X--- 8194,8207 ----
  349. X           (keyboard-quit))
  350. X          ((= key ??)
  351. X           (setq which (% (1+ which) (length msgs))))
  352. X!         ((and (= key ?I) (null prefix))
  353. X!          (setq inv (not inv)))
  354. X!         ((and (= key ?H) (null prefix))
  355. X!          (setq hyp (not hyp)))
  356. X          ((eq key prefix)
  357. X           (setq prefix nil))
  358. X!         ((and (memq key '(?a ?b ?c ?f ?k ?m ?v ?V)) (null prefix))
  359. X!          (setq prefix (downcase key)))
  360. X          ((eq prefix ?m)
  361. X           (setq prefix nil)
  362. X           (if (eq key ?e)
  363. X***************
  364. X*** 4562,4576 ****
  365. X                         arglist)
  366. X                        expr))
  367. X                 done t))))
  368. X!         ((setq oper (assq key (cond ((eq prefix ?b) calc-b-oper-keys)
  369. X!                     ((eq prefix ?c) calc-c-oper-keys)
  370. X!                     ((eq prefix ?k) calc-k-oper-keys)
  371. X!                     (inv (if hyp
  372. X!                          calc-inv-hyp-oper-keys
  373. X!                            calc-inv-oper-keys))
  374. X!                     (t (if hyp
  375. X!                            calc-hyp-oper-keys
  376. X!                          calc-oper-keys)))))
  377. X           (if (eq (nth 1 oper) 'user)
  378. X           (let ((func (intern
  379. X                    (completing-read "Function name: "
  380. X--- 8247,8260 ----
  381. X                         arglist)
  382. X                        expr))
  383. X                 done t))))
  384. X!         ((setq oper (assq key (nth (if inv (if hyp 3 1) (if hyp 2 0))
  385. X!                        (cond ((eq prefix ?a) calc-a-oper-keys)
  386. X!                          ((eq prefix ?b) calc-b-oper-keys)
  387. X!                          ((eq prefix ?c) calc-c-oper-keys)
  388. X!                          ((eq prefix ?f) calc-f-oper-keys)
  389. X!                          ((eq prefix ?k) calc-k-oper-keys)
  390. X!                          ((eq prefix ?v) calc-v-oper-keys)
  391. X!                          (t calc-oper-keys)))))
  392. X           (if (eq (nth 1 oper) 'user)
  393. X           (let ((func (intern
  394. X                    (completing-read "Function name: "
  395. X***************
  396. X*** 4612,4703 ****
  397. X       (error "Must be a %d-argument operator" nargs))
  398. X      (append (cdr oper)
  399. X          (list
  400. X!          (concat (if prefix (char-to-string prefix) "")
  401. X!              (if inv "I" "") (if hyp "H" "")
  402. X!              (char-to-string key)))))
  403. X! )
  404. X! 
  405. X! (defconst calc-oper-keys '( ( ?+ 2 calcFunc-add )
  406. X!                 ( ?- 2 calcFunc-sub )
  407. X!                 ( ?* 2 calcFunc-mul )
  408. X!                 ( ?/ 2 calcFunc-div )
  409. X!                 ( ?^ 2 calcFunc-pow )
  410. X!                 ( ?| 2 calcFunc-vconcat )
  411. X!                 ( ?% 2 calcFunc-mod )
  412. X!                 ( ?\\ 2 calcFunc-idiv )
  413. X!                 ( ?: 2 calcFunc-fdiv )
  414. X!                 ( ?! 1 calcFunc-fact )
  415. X!                 ( ?n 1 calcFunc-neg )
  416. X!                 ( ?x user )
  417. X!                 ( ?z user )
  418. X!                 ( ?A 1 calcFunc-abs )
  419. X!                 ( ?J 1 calcFunc-conj )
  420. X!                 ( ?G 1 calcFunc-arg )
  421. X!                 ( ?Q 1 calcFunc-sqrt )
  422. X!                 ( ?N 2 calcFunc-min )
  423. X!                 ( ?X 2 calcFunc-max )
  424. X!                 ( ?F 1 calcFunc-floor )
  425. X!                 ( ?R 1 calcFunc-round )
  426. X!                 ( ?S 1 calcFunc-sin )
  427. X!                 ( ?C 1 calcFunc-cos )
  428. X!                 ( ?T 1 calcFunc-tan )
  429. X!                 ( ?L 1 calcFunc-ln )
  430. X!                 ( ?E 1 calcFunc-exp )
  431. X!                 ( ?B 2 calcFunc-log )
  432. X! ))
  433. X! (defconst calc-b-oper-keys '( ( ?a 2 calcFunc-and )
  434. X!                   ( ?o 2 calcFunc-or )
  435. X!                   ( ?x 2 calcFunc-xor )
  436. X!                   ( ?d 2 calcFunc-diff )
  437. X!                   ( ?n 1 calcFunc-not )
  438. X!                   ( ?c 1 calcFunc-clip )
  439. X!                   ( ?l 2 calcFunc-lsh )
  440. X!                   ( ?r 2 calcFunc-rsh )
  441. X!                   ( ?L 2 calcFunc-ash )
  442. X!                   ( ?R 2 calcFunc-rash )
  443. X!                   ( ?t 2 calcFunc-rot )
  444. X! ))
  445. X! (defconst calc-c-oper-keys '( ( ?d 1 calcFunc-deg )
  446. X!                   ( ?r 1 calcFunc-rad )
  447. X!                   ( ?h 1 calcFunc-hms )
  448. X!                   ( ?f 1 calcFunc-float )
  449. X!                   ( ?F 1 calcFunc-frac )
  450. X! ))
  451. X! (defconst calc-k-oper-keys '( ( ?g 2 calcFunc-gcd )
  452. X!                   ( ?l 2 calcFunc-lcm )
  453. X!                   ( ?b 2 calcFunc-choose )
  454. X!                   ( ?d 1 calcFunc-dfact )
  455. X!                   ( ?m 1 calcFunc-moebius )
  456. X!                   ( ?p 2 calcFunc-perm )
  457. X!                   ( ?r 1 calcFunc-random )
  458. X!                   ( ?t 1 calcFunc-totient )
  459. X! ))
  460. X! (defconst calc-inv-oper-keys '( ( ?F 1 calcFunc-ceil )
  461. X!                 ( ?R 1 calcFunc-trunc )
  462. X!                 ( ?Q 1 calcFunc-sqr )
  463. X!                 ( ?S 1 calcFunc-arcsin )
  464. X!                 ( ?C 1 calcFunc-arccos )
  465. X!                 ( ?T 1 calcFunc-arctan )
  466. X!                 ( ?L 1 calcFunc-exp )
  467. X!                 ( ?E 1 calcFunc-ln )
  468. X! ))
  469. X! (defconst calc-hyp-oper-keys '( ( ?F 1 calcFunc-ffloor )
  470. X!                 ( ?R 1 calcFunc-fround )
  471. X!                 ( ?S 1 calcFunc-sinh )
  472. X!                 ( ?C 1 calcFunc-cosh )
  473. X!                 ( ?T 1 calcFunc-tanh )
  474. X!                 ( ?L 1 calcFunc-log10 )
  475. X!                 ( ?E 1 calcFunc-exp10 )
  476. X! ))
  477. X! (defconst calc-inv-hyp-oper-keys '( ( ?F 1 calcFunc-fceil )
  478. X!                     ( ?R 1 calcFunc-ftrunc )
  479. X!                     ( ?S 1 calcFunc-arcsinh )
  480. X!                     ( ?C 1 calcFunc-arccosh )
  481. X!                     ( ?T 1 calcFunc-arctanh )
  482. X!                     ( ?L 1 calcFunc-exp10 )
  483. X!                     ( ?E 1 calcFunc-log10 )
  484. X! ))
  485. X! 
  486. X  
  487. X  
  488. X  
  489. X--- 8296,8488 ----
  490. X       (error "Must be a %d-argument operator" nargs))
  491. X      (append (cdr oper)
  492. X          (list
  493. X!          (let ((name (concat (if inv "I" "") (if hyp "H" "")
  494. X!                  (if prefix (char-to-string prefix) "")
  495. X!                  (char-to-string key))))
  496. X!            (if (> (length name) 3)
  497. X!            (substring name 0 3)
  498. X!          name)))))
  499. X! )
  500. X! 
  501. X! (defconst calc-oper-keys '( ( ( ?+ 2 calcFunc-add )
  502. X!                   ( ?- 2 calcFunc-sub )
  503. X!                   ( ?* 2 calcFunc-mul )
  504. X!                   ( ?/ 2 calcFunc-div )
  505. X!                   ( ?^ 2 calcFunc-pow )
  506. X!                   ( ?| 2 calcFunc-vconcat )
  507. X!                   ( ?% 2 calcFunc-mod )
  508. X!                   ( ?\\ 2 calcFunc-idiv )
  509. X!                   ( ?: 2 calcFunc-fdiv )
  510. X!                   ( ?! 1 calcFunc-fact )
  511. X!                   ( ?& 1 calcFunc-inv )
  512. X!                   ( ?n 1 calcFunc-neg )
  513. X!                   ( ?x user )
  514. X!                   ( ?z user )
  515. X!                   ( ?A 1 calcFunc-abs )
  516. X!                   ( ?J 1 calcFunc-conj )
  517. X!                   ( ?G 1 calcFunc-arg )
  518. X!                   ( ?Q 1 calcFunc-sqrt )
  519. X!                   ( ?N 2 calcFunc-min )
  520. X!                   ( ?X 2 calcFunc-max )
  521. X!                   ( ?F 1 calcFunc-floor )
  522. X!                   ( ?R 1 calcFunc-round )
  523. X!                   ( ?S 1 calcFunc-sin )
  524. X!                   ( ?C 1 calcFunc-cos )
  525. X!                   ( ?T 1 calcFunc-tan )
  526. X!                   ( ?L 1 calcFunc-ln )
  527. X!                   ( ?E 1 calcFunc-exp )
  528. X!                   ( ?B 2 calcFunc-log ) )
  529. X!                 ( ( ?F 1 calcFunc-ceil )     ; inverse
  530. X!                   ( ?R 1 calcFunc-trunc )
  531. X!                   ( ?Q 1 calcFunc-sqr )
  532. X!                   ( ?S 1 calcFunc-arcsin )
  533. X!                   ( ?C 1 calcFunc-arccos )
  534. X!                   ( ?T 1 calcFunc-arctan )
  535. X!                   ( ?L 1 calcFunc-exp )
  536. X!                   ( ?E 1 calcFunc-ln )
  537. X!                   ( ?B 2 calcFunc-alog )
  538. X!                   ( ?^ 2 calcFunc-nroot ) )
  539. X!                 ( ( ?F 1 calcFunc-ffloor )   ; hyperbolic
  540. X!                   ( ?R 1 calcFunc-fround )
  541. X!                   ( ?S 1 calcFunc-sinh )
  542. X!                   ( ?C 1 calcFunc-cosh )
  543. X!                   ( ?T 1 calcFunc-tanh )
  544. X!                   ( ?L 1 calcFunc-log10 )
  545. X!                   ( ?E 1 calcFunc-exp10 ) )
  546. X!                 ( ( ?F 1 calcFunc-fceil )    ; inverse-hyperbolic
  547. X!                   ( ?R 1 calcFunc-ftrunc )
  548. X!                   ( ?S 1 calcFunc-arcsinh )
  549. X!                   ( ?C 1 calcFunc-arccosh )
  550. X!                   ( ?T 1 calcFunc-arctanh )
  551. X!                   ( ?L 1 calcFunc-exp10 )
  552. X!                   ( ?E 1 calcFunc-log10 ) )
  553. X! ))
  554. X! (defconst calc-a-oper-keys '( ( ( ?s 1 calcFunc-simplify )
  555. X!                 ( ?e 1 calcFunc-esimplify )
  556. X!                 ( ?d 2 calcFunc-deriv )
  557. X!                 ( ?i 2 calcFunc-integ )
  558. X!                 ( ?S 2 calcFunc-solve )
  559. X!                 ( ?= 2 calcFunc-eq )
  560. X!                 ( ?\# 2 calcFunc-neq )
  561. X!                 ( ?< 2 calcFunc-lt )
  562. X!                 ( ?> 2 calcFunc-gt )
  563. X!                 ( ?\[ 2 calcFunc-leq )
  564. X!                 ( ?\] 2 calcFunc-geq )
  565. X!                 ( ?{ 2 calcFunc-in )
  566. X!                 ( ?! 1 calcFunc-lnot )
  567. X!                 ( ?& 2 calcFunc-land )
  568. X!                 ( ?\| 2 calcFunc-lor )
  569. X!                 ( ?: 3 calcFunc-if ) )
  570. X!                   ( ( ?S 2 calcFunc-finv ) )
  571. X!                   ( ( ?S 2 calcFunc-fsolve ) )
  572. X!                   ( ( ?S 2 calcFunc-ffinv ) )
  573. X! ))
  574. X! (defconst calc-b-oper-keys '( ( ( ?a 2 calcFunc-and )
  575. X!                 ( ?o 2 calcFunc-or )
  576. X!                 ( ?x 2 calcFunc-xor )
  577. X!                 ( ?d 2 calcFunc-diff )
  578. X!                 ( ?n 1 calcFunc-not )
  579. X!                 ( ?c 1 calcFunc-clip )
  580. X!                 ( ?l 2 calcFunc-lsh )
  581. X!                 ( ?r 2 calcFunc-rsh )
  582. X!                 ( ?L 2 calcFunc-ash )
  583. X!                 ( ?R 2 calcFunc-rash )
  584. X!                 ( ?t 2 calcFunc-rot ) )
  585. X! ))
  586. X! (defconst calc-c-oper-keys '( ( ( ?d 1 calcFunc-deg )
  587. X!                 ( ?r 1 calcFunc-rad )
  588. X!                 ( ?h 1 calcFunc-hms )
  589. X!                 ( ?f 1 calcFunc-float )
  590. X!                 ( ?F 1 calcFunc-frac ) )
  591. X! ))
  592. X! (defconst calc-f-oper-keys '( ( ( ?b 2 calcFunc-beta )
  593. X!                 ( ?e 1 calcFunc-erf )
  594. X!                 ( ?g 1 calcFunc-gamma )
  595. X!                 ( ?h 2 calcFunc-hypot )
  596. X!                 ( ?i 1 calcFunc-im )
  597. X!                 ( ?j 2 calcFunc-besJ )
  598. X!                 ( ?n 2 calcFunc-min )
  599. X!                 ( ?r 1 calcFunc-re )
  600. X!                 ( ?s 1 calcFunc-sign )
  601. X!                 ( ?x 2 calcFunc-max )
  602. X!                 ( ?y 2 calcFunc-besY )
  603. X!                 ( ?A 1 calcFunc-abssqr )
  604. X!                 ( ?B 3 calcFunc-betaI )
  605. X!                 ( ?E 1 calcFunc-expm1 )
  606. X!                 ( ?G 2 calcFunc-gammaP )
  607. X!                 ( ?I 2 calcFunc-ilog )
  608. X!                 ( ?L 1 calcFunc-lnp1 )
  609. X!                 ( ?M 1 calcFunc-mant )
  610. X!                 ( ?Q 1 calcFunc-isqrt )
  611. X!                 ( ?S 1 calcFunc-scf )
  612. X!                 ( ?T 2 calcFunc-arctan2 )
  613. X!                 ( ?X 1 calcFunc-xpon )
  614. X!                 ( ?\[ 2 calcFunc-decr )
  615. X!                 ( ?\] 2 calcFunc-incr ) )
  616. X!                   ( ( ?e 1 calcFunc-erfc )
  617. X!                 ( ?E 1 calcFunc-lnp1 )
  618. X!                 ( ?G 2 calcFunc-gammaQ )
  619. X!                 ( ?L 1 calcFunc-expm1 ) )
  620. X!                   ( ( ?B 3 calcFunc-betaB )
  621. X!                 ( ?G 2 calcFunc-gammag) )
  622. X!                   ( ( ?G 2 calcFunc-gammaG ) )
  623. X! ))
  624. X! (defconst calc-k-oper-keys '( ( ( ?b 1 calcFunc-bern )
  625. X!                 ( ?c 2 calcFunc-choose )
  626. X!                 ( ?d 1 calcFunc-dfact )
  627. X!                 ( ?e 1 calcFunc-euler )
  628. X!                 ( ?f 1 calcFunc-prfac )
  629. X!                 ( ?g 2 calcFunc-gcd )
  630. X!                 ( ?h 2 calcFunc-shuffle )
  631. X!                 ( ?l 2 calcFunc-lcm )
  632. X!                 ( ?m 1 calcFunc-moebius )
  633. X!                 ( ?n 1 calcFunc-nextprime )
  634. X!                 ( ?r 1 calcFunc-random )
  635. X!                 ( ?s 2 calcFunc-stir1 )
  636. X!                 ( ?t 1 calcFunc-totient )
  637. X!                 ( ?B 3 calcFunc-utpb )
  638. X!                 ( ?C 2 calcFunc-utpc )
  639. X!                 ( ?F 3 calcFunc-utpf )
  640. X!                 ( ?N 3 calcFunc-utpn )
  641. X!                 ( ?P 2 calcFunc-utpp )
  642. X!                 ( ?T 2 calcFunc-utpt ) )
  643. X!                   ( ( ?n 1 calcFunc-prevprime )
  644. X!                 ( ?B 3 calcFunc-ltpb )
  645. X!                 ( ?C 2 calcFunc-ltpc )
  646. X!                 ( ?F 3 calcFunc-ltpf )
  647. X!                 ( ?N 3 calcFunc-ltpn )
  648. X!                 ( ?P 2 calcFunc-ltpp )
  649. X!                 ( ?T 2 calcFunc-ltpt ) )
  650. X!                   ( ( ?b 2 calcFunc-bern )
  651. X!                 ( ?c 2 calcFunc-perm )
  652. X!                 ( ?e 2 calcFunc-euler )
  653. X!                 ( ?s 2 calcFunc-stir2 ) )
  654. X! ))
  655. X! (defconst calc-v-oper-keys '( ( ( ?a 2 calcFunc-arrange )
  656. X!                 ( ?b 2 calcFunc-cvec )
  657. X!                 ( ?c 2 calcFunc-mcol )
  658. X!                 ( ?d 2 calcFunc-diag )
  659. X!                 ( ?e 2 calcFunc-vexp )
  660. X!                 ( ?f 2 calcFunc-find )
  661. X!                 ( ?l 1 calcFunc-vlen )
  662. X!                 ( ?m 2 calcFunc-vmask )
  663. X!                 ( ?n 1 calcFunc-rnorm )
  664. X!                 ( ?r 2 calcFunc-mrow )
  665. X!                 ( ?s 3 calcFunc-subvec )
  666. X!                 ( ?t 1 calcFunc-trn )
  667. X!                 ( ?x 1 calcFunc-index )
  668. X!                 ( ?D 1 calcFunc-det )
  669. X!                 ( ?C 1 calcFunc-cross )
  670. X!                 ( ?G 1 calcFunc-grade )
  671. X!                 ( ?H 2 calcFunc-histogram )
  672. X!                 ( ?N 1 calcFunc-cnorm )
  673. X!                 ( ?S 1 calcFunc-sort )
  674. X!                 ( ?T 1 calcFunc-tr ) )
  675. X!                   ( ( ?G 1 calcFunc-rgrade )
  676. X!                 ( ?S 1 calcFunc-rsort ) )
  677. X!                   ( ( ?e 3 calcFunc-vexp )
  678. X!                 ( ?H 3 calcFunc-histogram ) )
  679. X! ))
  680. X  
  681. X  
  682. X  
  683. X***************
  684. X*** 4918,4923 ****
  685. X--- 8703,8709 ----
  686. X               "Leave it symbolic for non-constant arguments? ")))
  687. X       (if cmd
  688. X       (progn
  689. X+        (calc-need-macros)
  690. X         (fset cmd
  691. X           (list 'lambda
  692. X                 '()
  693. X***************
  694. X*** 4959,4965 ****
  695. X    (if (consp form)
  696. X        (if (eq (car form) 'var)
  697. X        (if (or (memq (nth 1 form) arglist)
  698. X!           (boundp (nth 2 form)))
  699. X            ()
  700. X          (setq arglist (cons (nth 1 form) arglist)))
  701. X      (calc-default-formula-arglist-step (cdr form))))
  702. X--- 8745,8751 ----
  703. X    (if (consp form)
  704. X        (if (eq (car form) 'var)
  705. X        (if (or (memq (nth 1 form) arglist)
  706. X!           (calc-var-value (nth 2 form)))
  707. X            ()
  708. X          (setq arglist (cons (nth 1 form) arglist)))
  709. X      (calc-default-formula-arglist-step (cdr form))))
  710. X***************
  711. X*** 5030,5036 ****
  712. X              '(arg)
  713. X              '(interactive "P")
  714. X              (list 'calc-execute-kbd-macro
  715. X!                   last-kbd-macro
  716. X                    'arg))))
  717. X        (let* ((kmap (calc-user-key-map))
  718. X           (old (assq key kmap)))
  719. X--- 8816,8823 ----
  720. X              '(arg)
  721. X              '(interactive "P")
  722. X              (list 'calc-execute-kbd-macro
  723. X!                   (vector (key-description last-kbd-macro)
  724. X!                       last-kbd-macro)
  725. X                    'arg))))
  726. X        (let* ((kmap (calc-user-key-map))
  727. X           (old (assq key kmap)))
  728. X***************
  729. X*** 5075,5095 ****
  730. X                    (lambda (cmd)
  731. X                      (if (stringp (symbol-function cmd))
  732. X                      (symbol-function cmd)
  733. X!                       (nth 1 (nth 3 (symbol-function cmd))))))
  734. X                   (function
  735. X                    (lambda (new cmd)
  736. X                      (if (stringp (symbol-function cmd))
  737. X                      (fset cmd new)
  738. X!                       (setcar (cdr (nth 3 (symbol-function
  739. X!                                cmd)))
  740. X!                           new))))))
  741. X!          (calc-wrapper
  742. X!           (calc-edit-mode (list 'calc-finish-macro-edit
  743. X!                     (list 'quote def)))
  744. X!           (insert (if (stringp cmd)
  745. X!               cmd
  746. X!             (nth 1 (nth 3 cmd)))))
  747. X!          (calc-show-edit-buffer)))
  748. X        (t (let* ((func (calc-stack-command-p cmd))
  749. X              (defn (and func
  750. X                     (symbolp func)
  751. X--- 8862,8919 ----
  752. X                    (lambda (cmd)
  753. X                      (if (stringp (symbol-function cmd))
  754. X                      (symbol-function cmd)
  755. X!                       (let ((mac (nth 1 (nth 3 (symbol-function
  756. X!                                 cmd)))))
  757. X!                     (if (vectorp mac)
  758. X!                         (aref mac 1)
  759. X!                       mac)))))
  760. X                   (function
  761. X                    (lambda (new cmd)
  762. X                      (if (stringp (symbol-function cmd))
  763. X                      (fset cmd new)
  764. X!                       (let ((mac (cdr (nth 3 (symbol-function
  765. X!                                   cmd)))))
  766. X!                     (if (vectorp (car mac))
  767. X!                         (progn
  768. X!                           (aset (car mac) 0
  769. X!                             (key-description new))
  770. X!                           (aset (car mac) 1 new))
  771. X!                       (setcar mac new))))))))
  772. X!          (let ((keys (progn (and (fboundp 'edit-kbd-macro)
  773. X!                      (edit-kbd-macro nil))
  774. X!                 (fboundp 'MacEdit-parse-keys))))
  775. X!            (calc-wrapper
  776. X!         (calc-edit-mode (list 'calc-finish-macro-edit
  777. X!                       (list 'quote def)
  778. X!                       keys)
  779. X!                 t)
  780. X!         (if keys
  781. X!             (let (top
  782. X!               (fill-column 70)
  783. X!               (fill-prefix nil))
  784. X!               (insert "Notations: RET, SPC, TAB, DEL, LFD, NUL"
  785. X!                   ", C-xxx, M-xxx.\n\n")
  786. X!               (setq top (point))
  787. X!               (insert (if (stringp cmd)
  788. X!                   (key-description cmd)
  789. X!                 (if (vectorp (nth 1 (nth 3 cmd)))
  790. X!                     (aref (nth 1 (nth 3 cmd)) 0)
  791. X!                   (key-description (nth 1 (nth 3 cmd)))))
  792. X!                   "\n")
  793. X!               (if (>= (prog2 (forward-char -1)
  794. X!                      (current-column)
  795. X!                      (forward-char 1))
  796. X!                   (screen-width))
  797. X!               (fill-region top (point))))
  798. X!           (insert "Press C-q to quote control characters like RET"
  799. X!               " and TAB.\n"
  800. X!               (if (stringp cmd)
  801. X!                   cmd
  802. X!                 (if (vectorp (nth 1 (nth 3 cmd)))
  803. X!                 (aref (nth 1 (nth 3 cmd)) 1)
  804. X!                   (nth 1 (nth 3 cmd)))))))
  805. X!            (calc-show-edit-buffer)
  806. X!            (forward-line (if keys 2 1)))))
  807. X        (t (let* ((func (calc-stack-command-p cmd))
  808. X              (defn (and func
  809. X                     (symbolp func)
  810. X***************
  811. X*** 5099,5115 ****
  812. X               (calc-wrapper
  813. X                (calc-edit-mode (list 'calc-finish-formula-edit
  814. X                          (list 'quote func)))
  815. X!               (insert (math-format-flat-expr defn 0) "\n"))
  816. X               (calc-show-edit-buffer))
  817. X           (error "That command's definition cannot be edited"))))))
  818. X  )
  819. X  
  820. X! (defun calc-finish-macro-edit (def)
  821. X!   (let ((str (buffer-substring (point) (point-max))))
  822. X      (if (symbolp (cdr def))
  823. X      (if (stringp (symbol-function (cdr def)))
  824. X          (fset (cdr def) str)
  825. X!       (setcar (cdr (nth 3 (symbol-function (cdr def)))) str))
  826. X        (setcdr def str)))
  827. X  )
  828. X  
  829. X--- 8923,8949 ----
  830. X               (calc-wrapper
  831. X                (calc-edit-mode (list 'calc-finish-formula-edit
  832. X                          (list 'quote func)))
  833. X!               (insert (math-format-nice-expr defn (screen-width))
  834. X!                   "\n"))
  835. X               (calc-show-edit-buffer))
  836. X           (error "That command's definition cannot be edited"))))))
  837. X  )
  838. X  
  839. X! (defun calc-finish-macro-edit (def keys)
  840. X!   (forward-line 1)
  841. X!   (if (and keys (looking-at "\n")) (forward-line 1))
  842. X!   (let* ((true-str (buffer-substring (point) (point-max)))
  843. X!      (str true-str))
  844. X!     (if keys (setq str (MacEdit-parse-keys str)))
  845. X      (if (symbolp (cdr def))
  846. X      (if (stringp (symbol-function (cdr def)))
  847. X          (fset (cdr def) str)
  848. X!       (let ((mac (cdr (nth 3 (symbol-function (cdr def))))))
  849. X!         (if (vectorp (car mac))
  850. X!         (progn
  851. X!           (aset (car mac) 0 (if keys true-str (key-description str)))
  852. X!           (aset (car mac) 1 str))
  853. X!           (setcar mac str))))
  854. X        (setcdr def str)))
  855. X  )
  856. X  
  857. X***************
  858. X*** 5191,5197 ****
  859. X        (insert "\"\n"))))
  860. X  )
  861. X  (put 'calc-algebraic-entry 'MacEdit-print 'calc-macro-edit-algebraic)
  862. X- (put 'calc-dollar-sign 'MacEdit-print 'calc-macro-edit-algebraic)
  863. X  
  864. X  (defun calc-macro-edit-variable ()
  865. X    (let ((str "") ch)
  866. X--- 9025,9030 ----
  867. X***************
  868. X*** 5285,5300 ****
  869. X       (let* ((cmd (cdr def))
  870. X          (fcmd (and cmd (symbolp cmd) (symbol-function cmd)))
  871. X          (pt (point))
  872. X!         (fill-column 70))
  873. X         (if (and fcmd
  874. X          (eq (car-safe fcmd) 'lambda)
  875. X          (get cmd 'calc-user-defn))
  876. X         (progn
  877. X!          (insert (prin1-to-string
  878. X!               (cons 'defun (cons cmd (cdr fcmd))))
  879. X               "\n")
  880. X!          (fill-region pt (point))
  881. X!          (indent-rigidly pt (point) 3)
  882. X           (delete-region pt (1+ pt))
  883. X           (let* ((func (calc-stack-command-p cmd))
  884. X              (ffunc (and func (symbolp func) (symbol-function func)))
  885. X--- 9118,9143 ----
  886. X       (let* ((cmd (cdr def))
  887. X          (fcmd (and cmd (symbolp cmd) (symbol-function cmd)))
  888. X          (pt (point))
  889. X!         (fill-column 70)
  890. X!         (fill-prefix nil)
  891. X!         str q-ok)
  892. X         (if (and fcmd
  893. X          (eq (car-safe fcmd) 'lambda)
  894. X          (get cmd 'calc-user-defn))
  895. X         (progn
  896. X!          (and (eq (car-safe (nth 3 fcmd)) 'calc-execute-kbd-macro)
  897. X!           (vectorp (nth 1 (nth 3 fcmd)))
  898. X!           (progn (and (fboundp 'edit-kbd-macro)
  899. X!                   (edit-kbd-macro nil))
  900. X!              (fboundp 'MacEdit-parse-keys))
  901. X!           (setq q-ok t)
  902. X!           (aset (nth 1 (nth 3 fcmd)) 1 nil))
  903. X!          (insert (setq str (prin1-to-string
  904. X!                 (cons 'defun (cons cmd (cdr fcmd)))))
  905. X               "\n")
  906. X!          (or (and (string-match "\"" str) (not q-ok))
  907. X!          (progn (fill-region pt (point))
  908. X!             (indent-rigidly pt (point) 3)))
  909. X           (delete-region pt (1+ pt))
  910. X           (let* ((func (calc-stack-command-p cmd))
  911. X              (ffunc (and func (symbolp func) (symbol-function func)))
  912. X***************
  913. X*** 5303,5313 ****
  914. X              (eq (car-safe ffunc) 'lambda)
  915. X              (get func 'calc-user-defn)
  916. X              (progn
  917. X!               (insert (prin1-to-string
  918. X!                    (cons 'defun (cons func (cdr ffunc))))
  919. X                    "\n")
  920. X!               (fill-region pt (point))
  921. X!               (indent-rigidly pt (point) 3)
  922. X                (delete-region pt (1+ pt))))))
  923. X       (and (stringp fcmd)
  924. X            (insert "  (fset '" (prin1-to-string cmd)
  925. X--- 9146,9158 ----
  926. X              (eq (car-safe ffunc) 'lambda)
  927. X              (get func 'calc-user-defn)
  928. X              (progn
  929. X!               (insert (setq str (prin1-to-string
  930. X!                      (cons 'defun (cons func
  931. X!                                 (cdr ffunc)))))
  932. X                    "\n")
  933. X!               (or (and (string-match "\"" str) (not q-ok))
  934. X!               (progn (fill-region pt (point))
  935. X!                  (indent-rigidly pt (point) 3)))
  936. X                (delete-region pt (1+ pt))))))
  937. X       (and (stringp fcmd)
  938. X            (insert "  (fset '" (prin1-to-string cmd)
  939. X***************
  940. X*** 5356,5363 ****
  941. X       (mapatoms (function
  942. X              (lambda (x)
  943. X                (and (string-match "\\`var-" (symbol-name x))
  944. X!                (boundp x)
  945. X!                (symbol-value x)
  946. X                 (not (eq (car-safe (symbol-value x))
  947. X                      'special-const))
  948. X                 (calc-insert-permanent-variable x)))))
  949. X--- 9201,9207 ----
  950. X       (mapatoms (function
  951. X              (lambda (x)
  952. X                (and (string-match "\\`var-" (symbol-name x))
  953. X!                (calc-var-value x)
  954. X                 (not (eq (car-safe (symbol-value x))
  955. X                      'special-const))
  956. X                 (calc-insert-permanent-variable x)))))
  957. X***************
  958. X*** 5388,5394 ****
  959. X          (symbol-name var)
  960. X          " ')\n")
  961. X      (backward-char 2))
  962. X!   (insert (prin1-to-string (symbol-value var)))
  963. X    (forward-line 1)
  964. X  )
  965. X  
  966. X--- 9232,9238 ----
  967. X          (symbol-name var)
  968. X          " ')\n")
  969. X      (backward-char 2))
  970. X!   (insert (prin1-to-string (calc-var-value var)))
  971. X    (forward-line 1)
  972. X  )
  973. X  
  974. X***************
  975. X*** 5401,5408 ****
  976. X      (mapatoms (function
  977. X             (lambda (x)
  978. X           (and (string-match "\\`var-" (symbol-name x))
  979. X!               (boundp x)
  980. X!               (symbol-value x)
  981. X                (not (eq (car-safe (symbol-value x)) 'special-const))
  982. X                (insert "(setq "
  983. X                    (symbol-name x)
  984. X--- 9245,9251 ----
  985. X      (mapatoms (function
  986. X             (lambda (x)
  987. X           (and (string-match "\\`var-" (symbol-name x))
  988. X!               (calc-var-value x)
  989. X                (not (eq (car-safe (symbol-value x)) 'special-const))
  990. X                (insert "(setq "
  991. X                    (symbol-name x)
  992. X***************
  993. X*** 5426,5431 ****
  994. X--- 9269,9279 ----
  995. X  )
  996. X  
  997. X  (defun calc-execute-kbd-macro (mac arg)
  998. X+   (if (vectorp mac)
  999. X+       (setq mac (or (aref mac 1)
  1000. X+             (aset mac 1 (progn (and (fboundp 'edit-kbd-macro)
  1001. X+                         (edit-kbd-macro nil))
  1002. X+                        (MacEdit-parse-keys (aref mac 0)))))))
  1003. X    (if (< (prefix-numeric-value arg) 0)
  1004. X        (execute-kbd-macro mac (- (prefix-numeric-value arg)))
  1005. X      (if calc-executing-macro
  1006. X***************
  1007. X*** 5458,5467 ****
  1008. X             (delete-region (point) (point-max))
  1009. X             (while new-stack
  1010. X               (calc-record-undo (list 'push 1))
  1011. X!              (let ((fmt (math-format-stack-value
  1012. X!                  (car (car new-stack)))))
  1013. X!                (setcar (cdr (car new-stack)) (calc-count-lines fmt))
  1014. X!                (insert fmt "\n"))
  1015. X               (setq new-stack (cdr new-stack)))
  1016. X             (calc-renumber-stack))
  1017. X             (while new-stack
  1018. X--- 9306,9312 ----
  1019. X             (delete-region (point) (point-max))
  1020. X             (while new-stack
  1021. X               (calc-record-undo (list 'push 1))
  1022. X!              (insert (math-format-stack-value (car new-stack)) "\n")
  1023. X               (setq new-stack (cdr new-stack)))
  1024. X             (calc-renumber-stack))
  1025. X             (while new-stack
  1026. X***************
  1027. X*** 5471,5476 ****
  1028. X--- 9316,9337 ----
  1029. X           (calc-record-undo (list 'set 'saved-stack-top 0))))))))
  1030. X  )
  1031. X  
  1032. X+ (defun calc-push-list-in-macro (vals m sels)
  1033. X+   (let ((entry (list (car vals) 1 (car sels)))
  1034. X+     (mm (+ (or m 1) calc-stack-top)))
  1035. X+     (if (> mm 1)
  1036. X+     (setcdr (nthcdr (- mm 2) calc-stack)
  1037. X+         (cons entry (nthcdr (1- mm) calc-stack)))
  1038. X+       (setq calc-stack (cons entry calc-stack))))
  1039. X+ )
  1040. X+ 
  1041. X+ (defun calc-pop-stack-in-macro (n mm)
  1042. X+   (if (> mm 1)
  1043. X+       (setcdr (nthcdr (- mm 2) calc-stack)
  1044. X+           (nthcdr (+ n mm -1) calc-stack))
  1045. X+     (setq calc-stack (nthcdr n calc-stack)))
  1046. X+ )
  1047. X+ 
  1048. X  
  1049. X  (defun calc-kbd-if ()
  1050. X    "An \"if\" statement in a Calc keyboard macro.
  1051. X***************
  1052. X*** 5678,5684 ****
  1053. X  )
  1054. X  
  1055. X  (defun calc-kbd-break ()
  1056. X!   "Break out of a keyboard macro, or out of a Z< Z> or Z{ Z} loop in a macro.
  1057. X  Usage:  cond  Z/    breaks only if cond is true.  Use \"1 Z/\" to break always."
  1058. X    (interactive)
  1059. X    (calc-wrapper
  1060. X--- 9539,9545 ----
  1061. X  )
  1062. X  
  1063. X  (defun calc-kbd-break ()
  1064. X!   "Break out of a keyboard macro, or out of a Z< Z>, Z{ Z}, or Z( Z) loop.
  1065. X  Usage:  cond  Z/    breaks only if cond is true.  Use \"1 Z/\" to break always."
  1066. X    (interactive)
  1067. X    (calc-wrapper
  1068. X***************
  1069. X*** 5714,5719 ****
  1070. X--- 9575,9581 ----
  1071. X        (calc-simplify-mode calc-simplify-mode)
  1072. X        (calc-mapping-dir calc-mapping-dir)
  1073. X        (calc-algebraic-mode calc-algebraic-mode)
  1074. X+       (calc-incomplete-algebraic-mode calc-incomplete-algebraic-mode)
  1075. X        (calc-symbolic-mode calc-symbolic-mode)
  1076. X        (calc-prefer-frac calc-prefer-frac)
  1077. X        (calc-complex-mode calc-complex-mode)
  1078. X***************
  1079. X*** 5849,5854 ****
  1080. X--- 9711,9725 ----
  1081. X  (math-defcache math-pi-over-180 nil
  1082. X    (math-div-float (math-pi) '(float 18 1)))
  1083. X  
  1084. X+ (math-defcache math-sqrt-pi nil
  1085. X+   (math-sqrt-float (math-pi)))
  1086. X+ 
  1087. X+ (math-defcache math-sqrt-2 nil
  1088. X+   (math-sqrt-float '(float 2 0)))
  1089. X+ 
  1090. X+ (math-defcache math-sqrt-two-pi nil
  1091. X+   (math-sqrt-float (math-two-pi)))
  1092. X+ 
  1093. X  (math-defcache math-sqrt-e (float (bigpos 849 146 128 700 270 721 648 1) -21)
  1094. X    (math-add-float '(float 1 0) (math-exp-minus-1-raw '(float 5 -1))))
  1095. X  
  1096. X***************
  1097. X*** 5885,5890 ****
  1098. X--- 9756,9822 ----
  1099. X      (/= (% a 2) 0))
  1100. X  )
  1101. X  
  1102. X+ ;;; True if A is a small or big integer.  [P x] [Public]
  1103. X+ (defun math-integerp (a)
  1104. X+   (or (integerp a)
  1105. X+       (memq (car-safe a) '(bigpos bigneg)))
  1106. X+ )
  1107. X+ 
  1108. X+ ;;; True if A is (numerically) a non-negative integer.  [P N] [Public]
  1109. X+ (defun math-natnump (a)
  1110. X+   (or (natnump a)
  1111. X+       (eq (car-safe a) 'bigpos))
  1112. X+ )
  1113. X+ 
  1114. X+ ;;; True if A is a rational (or integer).  [P x] [Public]
  1115. X+ (defun math-ratp (a)
  1116. X+   (or (integerp a)
  1117. X+       (memq (car-safe a) '(bigpos bigneg frac)))
  1118. X+ )
  1119. X+ 
  1120. X+ ;;; True if A is a real (or rational).  [P x] [Public]
  1121. X+ (defun math-realp (a)
  1122. X+   (or (integerp a)
  1123. X+       (memq (car-safe a) '(bigpos bigneg frac float)))
  1124. X+ )
  1125. X+ 
  1126. X+ ;;; True if A is a real or HMS form.  [P x] [Public]
  1127. X+ (defun math-anglep (a)
  1128. X+   (or (integerp a)
  1129. X+       (memq (car-safe a) '(bigpos bigneg frac float hms)))
  1130. X+ )
  1131. X+ 
  1132. X+ ;;; True if A is a number of any kind.  [P x] [Public]
  1133. X+ (defun math-numberp (a)
  1134. X+   (or (integerp a)
  1135. X+       (memq (car-safe a) '(bigpos bigneg frac float cplx polar)))
  1136. X+ )
  1137. X+ 
  1138. X+ ;;; True if A is a complex number or angle.  [P x] [Public]
  1139. X+ (defun math-scalarp (a)
  1140. X+   (or (integerp a)
  1141. X+       (memq (car-safe a) '(bigpos bigneg frac float cplx polar hms)))
  1142. X+ )
  1143. X+ 
  1144. X+ ;;; True if A is a vector.  [P x] [Public]
  1145. X+ (defun math-vectorp (a)
  1146. X+   (eq (car-safe a) 'vec)
  1147. X+ )
  1148. X+ 
  1149. X+ ;;; True if A is any vector or scalar data object.  [P x]
  1150. X+ (defun math-objvecp (a)    ;  [Public]
  1151. X+   (or (integerp a)
  1152. X+       (memq (car-safe a) '(bigpos bigneg frac float cplx polar
  1153. X+                   hms sdev intv mod vec incomplete)))
  1154. X+ )
  1155. X+ 
  1156. X+ ;;; True if A is numerically (but not literally) an integer.  [P x] [Public]
  1157. X+ (defun math-messy-integerp (a)
  1158. X+   (cond
  1159. X+    ((eq (car-safe a) 'float) (>= (nth 2 a) 0))
  1160. X+    ((eq (car-safe a) 'frac) (Math-integerp (math-normalize a))))
  1161. X+ )
  1162. X+ 
  1163. X  ;;; True if A is numerically an integer.  [P x] [Public]
  1164. X  (defun math-num-integerp (a)
  1165. X    (or (Math-integerp a)
  1166. X***************
  1167. X*** 5959,5964 ****
  1168. X--- 9891,9908 ----
  1169. X       (= (car dims) (nth 1 dims))))
  1170. X  )
  1171. X  
  1172. X+ ;;; True if A is any scalar data object.  [P x]
  1173. X+ (defun math-objectp (a)    ;  [Public]
  1174. X+   (or (integerp a)
  1175. X+       (memq (car-safe a) '(bigpos bigneg frac float cplx
  1176. X+                   polar hms sdev intv mod)))
  1177. X+ )
  1178. X+ (defmacro Math-objectp (a)    ;  [Public]
  1179. X+   (` (or (not (consp (, a)))
  1180. X+      (memq (car (, a))
  1181. X+            '(bigpos bigneg frac float cplx polar hms sdev intv mod))))
  1182. X+ )
  1183. X+ 
  1184. X  ;;; True if A is any real scalar data object.  [P x]
  1185. X  (defun math-real-objectp (a)    ;  [Public]
  1186. X    (or (integerp a)
  1187. X***************
  1188. X*** 5965,5981 ****
  1189. X        (memq (car-safe a) '(bigpos bigneg frac float hms sdev intv mod)))
  1190. X  )
  1191. X  
  1192. X! ;;; True if A is an object not composed of sub-formulas .  [P x] [Public]
  1193. X! (defun math-primp (a)
  1194. X!   (or (integerp a)
  1195. X!       (memq (car-safe a) '(bigpos bigneg frac float cplx polar
  1196. X!                   hms mod var)))
  1197. X! )
  1198. X! (defmacro Math-primp (a)
  1199. X!   (` (or (not (consp (, a)))
  1200. X!      (memq (car (, a)) '(bigpos bigneg frac float cplx polar
  1201. X!                     hms mod var))))
  1202. X! )
  1203. X  
  1204. X  ;;; True if A is a constant or vector of constants.  [P x] [Public]
  1205. X  (defun math-constp (a)
  1206. X--- 9909,9915 ----
  1207. X        (memq (car-safe a) '(bigpos bigneg frac float hms sdev intv mod)))
  1208. X  )
  1209. X  
  1210. X! ;;; Math-primp moved up so calc-select stuff can use it.
  1211. X  
  1212. X  ;;; True if A is a constant or vector of constants.  [P x] [Public]
  1213. X  (defun math-constp (a)
  1214. X***************
  1215. X*** 6058,6063 ****
  1216. X--- 9992,10072 ----
  1217. X  )
  1218. X  
  1219. X  
  1220. X+ (defun math-normalize-fancy (a)
  1221. X+   (cond ((eq (car a) 'frac)
  1222. X+      (math-make-frac (math-normalize (nth 1 a))
  1223. X+              (math-normalize (nth 2 a))))
  1224. X+     ((eq (car a) 'cplx)
  1225. X+      (let ((real (math-normalize (nth 1 a)))
  1226. X+            (imag (math-normalize (nth 2 a))))
  1227. X+        (if (math-zerop imag) real (list 'cplx real imag))))
  1228. X+     ((eq (car a) 'polar)
  1229. X+      (math-normalize-polar a))
  1230. X+     ((eq (car a) 'hms)
  1231. X+      (math-normalize-hms a))
  1232. X+     ((eq (car a) 'mod)
  1233. X+      (math-normalize-mod a))
  1234. X+     ((eq (car a) 'sdev)
  1235. X+      (let ((x (math-normalize (nth 1 a)))
  1236. X+            (s (math-normalize (nth 2 a))))
  1237. X+        (if (or (and (Math-objectp x) (not (Math-anglep x)))
  1238. X+            (and (Math-objectp s) (not (Math-anglep s))))
  1239. X+            (list 'calcFunc-sdev x s)
  1240. X+          (math-make-sdev x s))))
  1241. X+     ((eq (car a) 'intv)
  1242. X+      (let ((mask (math-normalize (nth 1 a)))
  1243. X+            (lo (math-normalize (nth 2 a)))
  1244. X+            (hi (math-normalize (nth 3 a))))
  1245. X+        (if (or (and (Math-objectp lo) (not (Math-anglep lo)))
  1246. X+            (and (Math-objectp hi) (not (Math-anglep hi))))
  1247. X+            (list 'calcFunc-intv mask lo hi)
  1248. X+          (math-make-intv mask lo hi))))
  1249. X+     ((eq (car a) 'vec)
  1250. X+      (cons 'vec (mapcar 'math-normalize (cdr a))))
  1251. X+     ((eq (car a) 'quote)
  1252. X+      (math-normalize (nth 1 a)))
  1253. X+     ((eq (car a) 'special-const)
  1254. X+      (calc-with-default-simplification
  1255. X+       (math-normalize (nth 1 a))))
  1256. X+     ((eq (car a) 'var)
  1257. X+      (cons 'var (cdr a)))   ; need to re-cons for selection routines
  1258. X+     ((eq (car a) 'calcFunc-if)
  1259. X+      (math-normalize-logical-op a))
  1260. X+     ((memq (car a) '(calcFunc-lambda calcFunc-quote))
  1261. X+      (let ((calc-simplify-mode 'none))
  1262. X+        (cons (car a) (mapcar 'math-normalize (cdr a)))))
  1263. X+     ((or (integerp (car a)) (consp (car a)))
  1264. X+      (if (null (cdr a))
  1265. X+          (math-normalize (car a))
  1266. X+        (error "Can't use multi-valued function in an expression"))))
  1267. X+ )
  1268. X+ 
  1269. X+ (defun math-normalize-nonstandard (a)
  1270. X+   (and (symbolp (car a))
  1271. X+        (or (eq calc-simplify-mode 'none)
  1272. X+        (and (eq calc-simplify-mode 'num)
  1273. X+         (let ((aptr args))
  1274. X+           (while (and aptr (or (math-scalarp (car aptr))
  1275. X+                        (eq (car-safe (car aptr))
  1276. X+                        'mod)))
  1277. X+             (setq aptr (cdr aptr)))
  1278. X+           aptr)))
  1279. X+        (cons (car a) args))
  1280. X+ )
  1281. X+ 
  1282. X+ 
  1283. X+ ;;; Normalize a bignum digit list by trimming high-end zeros.  [L l]
  1284. X+ (defun math-norm-bignum (a)
  1285. X+   (let ((digs a) (last nil))
  1286. X+     (while digs
  1287. X+       (or (eq (car digs) 0) (setq last digs))
  1288. X+       (setq digs (cdr digs)))
  1289. X+     (and last
  1290. X+      (progn
  1291. X+        (setcdr last nil)
  1292. X+        a)))
  1293. X+ )
  1294. X+ 
  1295. X  (defun math-bignum-test (a)   ; [B N; B s; b b]
  1296. X    (if (consp a)
  1297. X        a
  1298. X***************
  1299. X*** 6105,6111 ****
  1300. X       (math-compare (math-mul a (nth 2 b)) (nth 1 b)))
  1301. X      ((and (eq (car-safe a) 'float) (eq (car-safe b) 'float))
  1302. X       (if (math-lessp-float a b) -1 1))
  1303. X!     ((and (Math-anglep a) (Math-anglep b))
  1304. X       (math-sign (math-add a (math-neg b))))
  1305. X      ((eq (car-safe a) 'var)
  1306. X       2)
  1307. X--- 10114,10123 ----
  1308. X       (math-compare (math-mul a (nth 2 b)) (nth 1 b)))
  1309. X      ((and (eq (car-safe a) 'float) (eq (car-safe b) 'float))
  1310. X       (if (math-lessp-float a b) -1 1))
  1311. X!     ((and (or (Math-anglep a)
  1312. X!           (and (eq (car a) 'cplx) (eq (nth 2 a) 0)))
  1313. X!           (or (Math-anglep b)
  1314. X!           (and (eq (car b) 'cplx) (eq (nth 2 b) 0))))
  1315. X       (math-sign (math-add a (math-neg b))))
  1316. X      ((eq (car-safe a) 'var)
  1317. X       2)
  1318. X***************
  1319. X*** 6146,6157 ****
  1320. X    (let ((ediff (- (nth 2 a) (nth 2 b))))
  1321. X      (if (>= ediff 0)
  1322. X      (if (>= ediff (+ calc-internal-prec calc-internal-prec))
  1323. X!         (Math-integer-negp (nth 1 a))
  1324. X        (Math-lessp (math-scale-int (nth 1 a) ediff)
  1325. X                (nth 1 b)))
  1326. X        (if (>= (setq ediff (- ediff))
  1327. X            (+ calc-internal-prec calc-internal-prec))
  1328. X!       (Math-integer-posp (nth 1 b))
  1329. X      (Math-lessp (nth 1 a)
  1330. X              (math-scale-int (nth 1 b) ediff)))))
  1331. X  )
  1332. X--- 10158,10173 ----
  1333. X    (let ((ediff (- (nth 2 a) (nth 2 b))))
  1334. X      (if (>= ediff 0)
  1335. X      (if (>= ediff (+ calc-internal-prec calc-internal-prec))
  1336. X!         (if (eq (nth 1 a) 0)
  1337. X!         (Math-integer-posp (nth 1 b))
  1338. X!           (Math-integer-negp (nth 1 a)))
  1339. X        (Math-lessp (math-scale-int (nth 1 a) ediff)
  1340. X                (nth 1 b)))
  1341. X        (if (>= (setq ediff (- ediff))
  1342. X            (+ calc-internal-prec calc-internal-prec))
  1343. X!       (if (eq (nth 1 b) 0)
  1344. X!           (Math-integer-negp (nth 1 a))
  1345. X!         (Math-integer-posp (nth 1 b)))
  1346. X      (Math-lessp (nth 1 a)
  1347. X              (math-scale-int (nth 1 b) ediff)))))
  1348. X  )
  1349. X***************
  1350. X*** 6199,6207 ****
  1351. X  ;;; Convert a function name into a like-looking variable name formula.
  1352. X  (defun math-calcFunc-to-var (f)
  1353. X    (if (symbolp f)
  1354. X!       (let ((base (if (string-match "\\`calcFunc-\\(.+\\)\\'" (symbol-name f))
  1355. X!               (math-match-substring (symbol-name f) 1)
  1356. X!             (symbol-name f))))
  1357. X      (list 'var
  1358. X            (intern base)
  1359. X            (intern (concat "var-" base))))
  1360. X--- 10215,10233 ----
  1361. X  ;;; Convert a function name into a like-looking variable name formula.
  1362. X  (defun math-calcFunc-to-var (f)
  1363. X    (if (symbolp f)
  1364. X!       (let* ((func (or (cdr (assq f '( ( + . calcFunc-add )
  1365. X!                        ( - . calcFunc-sub )
  1366. X!                        ( * . calcFunc-mul )
  1367. X!                        ( / . calcFunc-div )
  1368. X!                        ( ^ . calcFunc-pow )
  1369. X!                        ( % . calcFunc-mod )
  1370. X!                        ( neg . calcFunc-neg )
  1371. X!                        ( | . calcFunc-vconcat ) )))
  1372. X!                f))
  1373. X!          (base (if (string-match "\\`calcFunc-\\(.+\\)\\'"
  1374. X!                      (symbol-name func))
  1375. X!                (math-match-substring (symbol-name func) 1)
  1376. X!              (symbol-name func))))
  1377. X      (list 'var
  1378. X            (intern base)
  1379. X            (intern (concat "var-" base))))
  1380. X***************
  1381. X*** 6221,6227 ****
  1382. X              argvals (cdr argvals)))
  1383. X          res)
  1384. X      (cons 'calcFunc-call (cons (math-calcFunc-to-var f) args)))
  1385. X!     (cons f args))
  1386. X  )
  1387. X  
  1388. X  (defun calcFunc-call (f &rest args)
  1389. X--- 10247,10265 ----
  1390. X              argvals (cdr argvals)))
  1391. X          res)
  1392. X      (cons 'calcFunc-call (cons (math-calcFunc-to-var f) args)))
  1393. X!     (if (and (eq f 'calcFunc-neg)
  1394. X!          (= (length args) 1))
  1395. X!     (list 'neg (car args))
  1396. X!       (let ((func (assq f '( ( calcFunc-add . + )
  1397. X!                  ( calcFunc-sub . - )
  1398. X!                  ( calcFunc-mul . * )
  1399. X!                  ( calcFunc-div . / )
  1400. X!                  ( calcFunc-pow . ^ )
  1401. X!                  ( calcFunc-mod . % )
  1402. X!                  ( calcFunc-vconcat . | ) ))))
  1403. X!     (if (and func (= (length args) 2))
  1404. X!         (cons (cdr func) args)
  1405. X!       (cons f args)))))
  1406. X  )
  1407. X  
  1408. X  (defun calcFunc-call (f &rest args)
  1409. X***************
  1410. X*** 6239,6244 ****
  1411. X--- 10277,10341 ----
  1412. X  
  1413. X  
  1414. X  
  1415. X+ ;;;; [calc-frac.el]
  1416. X+ 
  1417. X+ ;;;; Fractions.
  1418. X+ 
  1419. X+ ;;; Build a normalized fraction.  [R I I]
  1420. X+ ;;; (This could probably be implemented more efficiently than using
  1421. X+ ;;;  the plain gcd algorithm.)
  1422. X+ (defun math-make-frac (num den)
  1423. X+   (if (Math-integer-negp den)
  1424. X+       (setq num (math-neg num)
  1425. X+         den (math-neg den)))
  1426. X+   (let ((gcd (math-gcd num den)))
  1427. X+     (if (eq gcd 1)
  1428. X+     (if (eq den 1)
  1429. X+         num
  1430. X+       (list 'frac num den))
  1431. X+       (if (equal gcd den)
  1432. X+       (math-quotient num gcd)
  1433. X+     (list 'frac (math-quotient num gcd) (math-quotient den gcd)))))
  1434. X+ )
  1435. X+ 
  1436. X+ (defun calc-add-fractions (a b)
  1437. X+   (if (eq (car-safe a) 'frac)
  1438. X+       (if (eq (car-safe b) 'frac)
  1439. X+       (math-make-frac (math-add (math-mul (nth 1 a) (nth 2 b))
  1440. X+                     (math-mul (nth 2 a) (nth 1 b)))
  1441. X+               (math-mul (nth 2 a) (nth 2 b)))
  1442. X+     (math-make-frac (math-add (nth 1 a)
  1443. X+                   (math-mul (nth 2 a) b))
  1444. X+             (nth 2 a)))
  1445. X+     (math-make-frac (math-add (math-mul a (nth 2 b))
  1446. X+                   (nth 1 b))
  1447. X+             (nth 2 b)))
  1448. X+ )
  1449. X+ 
  1450. X+ (defun calc-mul-fractions (a b)
  1451. X+   (if (eq (car-safe a) 'frac)
  1452. X+       (if (eq (car-safe b) 'frac)
  1453. X+       (math-make-frac (math-mul (nth 1 a) (nth 1 b))
  1454. X+               (math-mul (nth 2 a) (nth 2 b)))
  1455. X+     (math-make-frac (math-mul (nth 1 a) b)
  1456. X+             (nth 2 a)))
  1457. X+     (math-make-frac (math-mul a (nth 1 b))
  1458. X+             (nth 2 b)))
  1459. X+ )
  1460. X+ 
  1461. X+ (defun calc-div-fractions (a b)
  1462. X+   (if (eq (car-safe a) 'frac)
  1463. X+       (if (eq (car-safe b) 'frac)
  1464. X+       (math-make-frac (math-mul (nth 1 a) (nth 2 b))
  1465. X+               (math-mul (nth 2 a) (nth 1 b)))
  1466. X+     (math-make-frac (nth 1 a)
  1467. X+             (math-mul (nth 2 a) b)))
  1468. X+     (math-make-frac (math-mul a (nth 2 b))
  1469. X+             (nth 1 b)))
  1470. X+ )
  1471. X+ 
  1472. X+ 
  1473. X+ 
  1474. X  ;;;; [calc-vec.el]
  1475. X  
  1476. X  ;;;; Vectors.
  1477. X***************
  1478. X*** 6293,6298 ****
  1479. X--- 10390,10421 ----
  1480. X      obj)
  1481. X  )
  1482. X  
  1483. X+ (defun math-vector-head (vec)
  1484. X+   (if (and (Math-vectorp vec)
  1485. X+        (cdr (cdr vec)))
  1486. X+       (nth 1 vec)
  1487. X+     (math-record-why 'vectorp vec)
  1488. X+     (list 'calcFunc-head vec))
  1489. X+ )
  1490. X+ (fset 'calcFunc-head (symbol-function 'math-vector-head))
  1491. X+ 
  1492. X+ (defun math-vector-tail (vec)
  1493. X+   (if (and (Math-vectorp vec)
  1494. X+        (cdr (cdr vec)))
  1495. X+       (cdr (cdr vec))
  1496. X+     (math-record-why 'vectorp vec)
  1497. X+     (list 'calcFunc-tail vec))
  1498. X+ )
  1499. X+ (fset 'calcFunc-tail (symbol-function 'math-vector-tail))
  1500. X+ 
  1501. X+ (defun math-cons-vec (head tail)
  1502. X+   (if (Math-vectorp tail)
  1503. X+       (cons 'vec (cons head (cdr tail)))
  1504. X+     (math-record-why 'vectorp tail)
  1505. X+     (list 'calcFunc-cons head tail))
  1506. X+ )
  1507. X+ (fset 'calcFunc-cons (symbol-function 'math-cons-vec))
  1508. X+ 
  1509. X  
  1510. X  ;;;; [calc-mat.el]
  1511. X  
  1512. X***************
  1513. X*** 6400,6421 ****
  1514. X       (vec nil)
  1515. X       (i -1)
  1516. X       len cols obj expr)
  1517. X!     (if (eq mode 'rows)
  1518. X!     ()
  1519. X!       (while (and (< (setq i (1+ i)) nargs)
  1520. X!           (not (math-matrixp (aref ptrs i)))))
  1521. X!       (if (< i nargs)
  1522. X!       (if (eq mode 'elems)
  1523. X!           (setq func (list 'lambda '(&rest x)
  1524. X!                    (list 'math-symb-map
  1525. X!                      (list 'quote f) '(quote elems) 'x))
  1526. X!             mode 'rows)
  1527. X!         (while (< i nargs)
  1528. X!           (if (math-matrixp (aref ptrs i))
  1529. X!           (aset ptrs i (math-transpose (aref ptrs i))))
  1530. X!           (setq i (1+ i))))
  1531. X!     (setq mode 'elems))
  1532. X!       (setq i -1))
  1533. X      (while (< (setq i (1+ i)) nargs)
  1534. X        (setq obj (aref ptrs i))
  1535. X        (if (and (eq (car-safe obj) 'vec)
  1536. X--- 10523,10543 ----
  1537. X       (vec nil)
  1538. X       (i -1)
  1539. X       len cols obj expr)
  1540. X!     (while (and (< (setq i (1+ i)) nargs)
  1541. X!         (not (math-matrixp (aref ptrs i)))))
  1542. X!     (if (< i nargs)
  1543. X!     (if (eq mode 'elems)
  1544. X!         (setq func (list 'lambda '(&rest x)
  1545. X!                  (list 'math-symb-map
  1546. X!                    (list 'quote f) '(quote elems) 'x))
  1547. X!           mode 'rows)
  1548. X!       (if (eq mode 'cols)
  1549. X!           (while (< i nargs)
  1550. X!         (if (math-matrixp (aref ptrs i))
  1551. X!             (aset ptrs i (math-transpose (aref ptrs i))))
  1552. X!         (setq i (1+ i)))))
  1553. X!       (setq mode 'elems))
  1554. X!     (setq i -1)
  1555. X      (while (< (setq i (1+ i)) nargs)
  1556. X        (setq obj (aref ptrs i))
  1557. X        (if (and (eq (car-safe obj) 'vec)
  1558. X***************
  1559. X*** 6566,6571 ****
  1560. X--- 10688,10764 ----
  1561. X      (calcFunc-reducer func vec))
  1562. X  )
  1563. X  
  1564. X+ (defun calcFunc-accum (func vec)
  1565. X+   (setq func (math-var-to-calcFunc func))
  1566. X+   (or (math-vectorp vec)
  1567. X+       (math-reject-arg vec 'vectorp))
  1568. X+   (let* ((expr (car (setq vec (cdr vec))))
  1569. X+      (res (list 'vec expr)))
  1570. X+     (or expr
  1571. X+     (math-reject-arg vec "Vector is empty"))
  1572. X+     (while (setq vec (cdr vec))
  1573. X+       (setq expr (math-build-call func (list expr (car vec)))
  1574. X+         res (nconc res (list expr))))
  1575. X+     (math-normalize res))
  1576. X+ )
  1577. X+ 
  1578. X+ 
  1579. X+ (defun calcFunc-outer (func a b)
  1580. X+   (or (math-vectorp a) (math-reject-arg a 'vectorp))
  1581. X+   (or (math-vectorp b) (math-reject-arg b 'vectorp))
  1582. X+   (setq func (math-var-to-calcFunc func))
  1583. X+   (let ((mat nil))
  1584. X+     (while (setq a (cdr a))
  1585. X+       (setq mat (cons (cons 'vec
  1586. X+                 (mapcar (function (lambda (x)
  1587. X+                         (math-build-call func
  1588. X+                                  (list (car a)
  1589. X+                                        x))))
  1590. X+                     (cdr b)))
  1591. X+               mat)))
  1592. X+     (math-normalize (cons 'vec (nreverse mat))))
  1593. X+ )
  1594. X+ 
  1595. X+ 
  1596. X+ (defun calcFunc-inner (mul-func add-func a b)
  1597. X+   (or (math-vectorp a) (math-reject-arg a 'vectorp))
  1598. X+   (or (math-vectorp b) (math-reject-arg b 'vectorp))
  1599. X+   (if (math-matrixp a)
  1600. X+       (if (math-matrixp b)
  1601. X+       (cons 'vec (math-inner-mats (cdr a) (mapcar 'cdr (cdr b))))
  1602. X+     (math-mat-col
  1603. X+      (cons 'vec
  1604. X+            (if (= (length (nth 1 a)) 2)
  1605. X+            (math-inner-mats (cdr a)
  1606. X+                   (mapcar 'cdr (cdr (math-row-matrix b))))
  1607. X+          (math-inner-mats (cdr a)
  1608. X+                   (mapcar 'cdr (cdr (math-col-matrix b))))))
  1609. X+      1))
  1610. X+     (if (math-matrixp b)
  1611. X+     (cons 'vec (math-inner-mat-row a (mapcar 'cdr (cdr b))))
  1612. X+       (car (math-inner-mat-row a
  1613. X+                  (mapcar 'cdr (cdr (math-col-matrix b)))))))
  1614. X+ )
  1615. X+ 
  1616. X+ (defun math-inner-mats (a b)
  1617. X+   (and a
  1618. X+        (cons (cons 'vec (math-inner-mat-row (car a) b))
  1619. X+          (math-inner-mats (cdr a) b)))
  1620. X+ )
  1621. X+ 
  1622. X+ (defun math-inner-mat-row (a b)    ; uses "mul-func", "add-func"
  1623. X+   (if (math-no-empty-rows b)
  1624. X+       (cons
  1625. X+        (calcFunc-reduce add-func
  1626. X+             (calcFunc-map mul-func
  1627. X+                       a
  1628. X+                       (cons 'vec (mapcar 'car b))))
  1629. X+        (math-inner-mat-row a (mapcar 'cdr b)))
  1630. X+     (if (math-list-all-nil b)
  1631. X+     nil
  1632. X+       (math-dimension-error)))
  1633. X+ )
  1634. X+ 
  1635. X  
  1636. X  ;;;; [calc-mat.el]
  1637. X  
  1638. X***************
  1639. X*** 6618,6627 ****
  1640. X  )
  1641. X  
  1642. X  (defun calcFunc-mrow (mat n)   ; [Public]
  1643. X!   (and (integerp (setq n (math-check-integer n)))
  1644. X!        (> n 0)
  1645. X!        (math-vectorp mat)
  1646. X!        (nth n mat))
  1647. X  )
  1648. X  
  1649. X  ;;; Get the Nth column of a matrix.
  1650. X--- 10811,10826 ----
  1651. X  )
  1652. X  
  1653. X  (defun calcFunc-mrow (mat n)   ; [Public]
  1654. X!   (if (Math-vectorp n)
  1655. X!       (math-map-vec (function (lambda (x) (calcFunc-mrow mat x))) n)
  1656. X!     (if (eq (car-safe n) 'intv)
  1657. X!     (math-subvector mat
  1658. X!             (math-add (nth 2 n) (if (memq (nth 1 n) '(2 3)) 0 1))
  1659. X!             (math-add (nth 3 n) (if (memq (nth 1 n) '(1 3)) 1 0)))
  1660. X!       (and (integerp (setq n (math-check-integer n)))
  1661. X!        (> n 0)
  1662. X!        (Math-vectorp mat)
  1663. X!        (nth n mat))))
  1664. X  )
  1665. X  
  1666. X  ;;; Get the Nth column of a matrix.
  1667. X***************
  1668. X*** 6630,6642 ****
  1669. X  )
  1670. X  
  1671. X  (defun calcFunc-mcol (mat n)   ; [Public]
  1672. X!   (and (integerp (setq n (math-check-integer n)))
  1673. X!        (> n 0)
  1674. X!        (math-vectorp mat)
  1675. X!        (if (math-matrixp mat)
  1676. X!        (and (< n (length (nth 1 mat)))
  1677. X!         (math-mat-col mat n))
  1678. X!      (nth n mat)))
  1679. X  )
  1680. X  
  1681. X  ;;; Remove the Nth row from a matrix.
  1682. X--- 10829,10847 ----
  1683. X  )
  1684. X  
  1685. X  (defun calcFunc-mcol (mat n)   ; [Public]
  1686. X!   (if (Math-vectorp n)
  1687. X!       (math-map-vec (function (lambda (x) (calcFunc-mcol mat x))) n)
  1688. X!     (if (eq (car-safe n) 'intv)
  1689. X!     (if (math-matrixp mat)
  1690. X!         (math-map-vec (function (lambda (x) (calcFunc-mrow x n))) mat)
  1691. X!       (calcFunc-mrow mat n))
  1692. X!       (and (integerp (setq n (math-check-integer n)))
  1693. X!        (> n 0)
  1694. X!        (Math-vectorp mat)
  1695. X!        (if (math-matrixp mat)
  1696. X!            (and (< n (length (nth 1 mat)))
  1697. X!             (math-mat-col mat n))
  1698. X!          (nth n mat)))))
  1699. X  )
  1700. X  
  1701. X  ;;; Remove the Nth row from a matrix.
  1702. X***************
  1703. X*** 6767,6784 ****
  1704. X  )
  1705. X  
  1706. X  ;;; Create a vector of consecutive integers. [Public]
  1707. X! (defun math-vec-index (n)
  1708. X!   (and (not (integerp n))
  1709. X!        (setq n (math-check-fixnum n)))
  1710. X!   (or (natnump n) (math-reject-arg n 'natnump))
  1711. X!   (let ((vec nil))
  1712. X!     (while (> n 0)
  1713. X!       (setq vec (cons n vec)
  1714. X!         n (1- n)))
  1715. X!     (cons 'vec vec))
  1716. X  )
  1717. X  (fset 'calcFunc-index (symbol-function 'math-vec-index))
  1718. X  
  1719. X  
  1720. X  ;;; Compute the row and column norms of a vector or matrix.  [Public]
  1721. X  (defun math-rnorm (a)
  1722. X--- 10972,11081 ----
  1723. X  )
  1724. X  
  1725. X  ;;; Create a vector of consecutive integers. [Public]
  1726. X! (defun math-vec-index (n &optional start incr)
  1727. X!   (if (math-messy-integerp n)
  1728. X!       (math-float (math-vec-index (math-trunc n)))
  1729. X!     (and (not (integerp n))
  1730. X!      (setq n (math-check-fixnum n)))
  1731. X!     (let ((vec nil))
  1732. X!       (if start
  1733. X!       (progn
  1734. X!         (if (>= n 0)
  1735. X!         (while (>= (setq n (1- n)) 0)
  1736. X!           (setq vec (cons start vec)
  1737. X!             start (math-add start (or incr 1))))
  1738. SHAR_EOF
  1739. echo "End of part 7, continue with part 8"
  1740. echo "8" > s2_seq_.tmp
  1741. exit 0
  1742.  
  1743.