[gnu.emacs.sources] Patch for Gnu Emacs Calc, 1.05 -> 1.06, part 1/5

daveg@near.cs.caltech.edu (Dave Gillespie) (10/24/90)

Here are patches for Calc 1.06.  Highlights include a new "calc-keypad"
mode for X users, somewhat improved error handling, better equation
solving features, some new vector stuff, and, of course, fixes for
several bugs and typos in Calc 1.05.

Compared to Calc 1.05, this is just the merest wisp of a patch---five
shar files.  Unshar all five to produce one big calc.patch file, which
in turn is suitable for use with Patch 2.0.

I am posting this patch to comp.sources.bugs and gnu.emacs.sources;
it will also appear in comp.sources.misc as usual once that group is
straightened out.

This will be the last major Calc release for a while; I plan to be
busy with other things.  Please keep sending bug reports, but for
anything not totally urgent it may be a while for the official fix
to come out.

Enjoy!

								-- Dave


#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
# This is part 1 of a multipart archive                                    
# do not concatenate these parts, unpack them in order with /bin/sh        
#
#	Run the following text with /bin/sh to create:
#	  calc.patch
#
if test -r s2_seq_.tmp
then echo "Must unpack archives in sequence!"
     next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
     exit 1; fi
sed 's/^X//' << 'SHAR_EOF' > calc.patch &&
X
XThe following patches convert Calc version 1.05 into Calc
Xversion 1.06.  To apply them automatically with Patch v2.0,
Xfirst cd into your Calc distribution directory, then execute
X"patch -p0 <calc.patch", where "calc.patch" is the name of this file.
X
XA list of changes appears near the front of calc.el below.
X
XIf you have used calc-split or calc-install, follow these steps to apply
Xthe patches (assuming you are using Unix):
X
X   1.  "cd" to your Calc home directory.
X   2.  "rm calc*.el calc*.elc".  (Removes the old files created by calc-split)
X   3.  "mv calc.elX calc.el".    (Restores the original, unsplit files)
X   4.  "mv calc-ext.elX calc-ext.el".
X   5.  Run the patch program as described above.
X
XSee the instructions at the front of the file calc-INSTALL to see how
Xto install the newly patched Calc.
X
XPatches and complete tar files are also available for anonymous FTP
Xfrom csvax.cs.caltech.edu [131.215.131.131], in the "pub" subdirectory.
X
XEnjoy!
X							-- Dave
X
XDave Gillespie
X256-80 Caltech, Pasadena CA 91125
Xdaveg@csvax.cs.caltech.edu, ...!cit-vax!daveg
X
X
X
X*** calc.el	Tue Oct  9 16:58:33 1990
X--- ../dist/calc.el	Wed Oct 24 02:03:50 1990
X***************
X*** 1,4 ****
X! ;; Calculator for GNU Emacs version 1.05
X  ;; Copyright (C) 1990 Dave Gillespie
X  
X  ;; This file is part of GNU Emacs.
X--- 1,4 ----
X! ;; Calculator for GNU Emacs version 1.06
X  ;; Copyright (C) 1990 Dave Gillespie
X  
X  ;; This file is part of GNU Emacs.
X***************
X*** 34,39 ****
X--- 34,40 ----
X  ;;;   (autoload 'calc ".../calc.elc" "Calculator Mode" t nil)
X  ;;;   (autoload 'quick-calc ".../calc.elc" "Quick Calculator" t nil)
X  ;;;   (autoload 'full-calc ".../calc.elc" "Full-screen Calculator" t nil)
X+ ;;;   (autoload 'calc-keypad ".../calc.elc" "X windows Calculator" t nil)
X  ;;;   (autoload 'calc-eval ".../calc.elc" "Call Calculator" nil nil)
X  ;;;   (autoload 'calc-grab-region ".../calc-ext.elc" nil t nil)
X  ;;;   (autoload 'defmath ".../calc-ext.elc" nil t t)
X***************
X*** 65,70 ****
X--- 66,99 ----
X  ;;; and "defmath".  User-accessible variables begin with "var-".
X  
X  
X+ ;;; Version 1.06:
X+ ;;;  * Added "calc-keypad" mode for X window system users (try it!).
X+ ;;;  * Improved "calc-eval" for calling/operating Calc from user-written Lisp.
X+ ;;;  * Moved vector accumulate command to `V U' (old `H V R' still supported).
X+ ;;;  * Added right-to-left reductions: `I V R' and `I V U'.
X+ ;;;  * Added set operations on vectors: intersect, union, diff, xor.
X+ ;;;  * Added `I v s' to remove a subvector from a vector.
X+ ;;;  * Introduced `H |' to append two vectors with no magical special cases.
X+ ;;;  * Introduced rhead, rtail, and rcons for isolating last vector element.
X+ ;;;  * Changed `g p' to keep temp files around until data actually change.
X+ ;;;  * Improved `a S' to solve many higher-order polynomial equations.
X+ ;;;  * Added `a P' to produce a vector of all solutions to an equation.
X+ ;;;  * Enhanced `a v' and `j v' to allow top-level-only evaluation.
X+ ;;;  * Changed `j DEL' to delete a side of an eqn or ineq, leaving other side.
X+ ;;;  * Fixed binding for keys `j 1' through `j 9'.
X+ ;;;  * Introduced "let" marker in rewrite rules.
X+ ;;;  * Enhanced the "sign" function to provide a two-argument version.
X+ ;;;  * Changed "max-specpdl-size exceeded" error message to be user-friendly.
X+ ;;;  * Put "<Aborted>" in the trail in above case and when user presses C-g.
X+ ;;;  * Changed TeX mode to generate \ldots instead of \dots, recognize both.
X+ ;;;  * Changed "sin(0)" etc. (for integer 0) to generate "0" instead of "0.".
X+ ;;;  * Enhanced Programming Tutorial exercise 2.
X+ ;;;  * Fixed an error in the answer to Types Tutorial exercise 3.
X+ ;;;  * Fixed several bugs relating to head, tail, and cons functions.
X+ ;;;  * Fixed some other minor typos in the manual.
X+ ;;;  * Fixed several bugs in `Z P' (calc-user-define-permanent).
X+ ;;;  * Fixed several bugs that broke the `g P' command.
X+ ;;; 
X  ;;; Version 1.05:
X  ;;;  * Created a calc-install command to ease installation.
X  ;;;  * Added lots of exercises to the Tutorial section of the manual.
X***************
X*** 171,177 ****
X  
X  (defmacro calc-record-compilation-date-macro ()
X    (` (setq calc-version (, (concat "Emacs Calc Mode"
X! 				   " v1.05 by Dave Gillespie"
X  				   ", installed "
X  				   (current-time-string)
X  				   " by "
X--- 200,206 ----
X  
X  (defmacro calc-record-compilation-date-macro ()
X    (` (setq calc-version (, (concat "Emacs Calc Mode"
X! 				   " v1.06 by Dave Gillespie"
X  				   ", installed "
X  				   (current-time-string)
X  				   " by "
X***************
X*** 229,238 ****
X  ;;;   Make it possible to Undo a selection command.
X  ;;;   Figure out how to allow selecting rows of matrices.
X  ;;;   If cursor was in selection before, move it after j n, j p, j L, etc.
X! ;;;
X! ;;;   In no-simplify mode, have a key which executes the top-level call
X! ;;;      once, but does not execute any of the arguments' calls.
X! ;;;   Put a set of evaluations in the c-prefix menu, analogous to m-prefix.
X  ;;;
X  ;;;   When the stack is truncated, put the "." on the *second*-to-bottom line.
X  ;;;   When formatting formulas, suppress extra spaces inside vectors!
X--- 258,264 ----
X  ;;;   Make it possible to Undo a selection command.
X  ;;;   Figure out how to allow selecting rows of matrices.
X  ;;;   If cursor was in selection before, move it after j n, j p, j L, etc.
X! ;;;   Consider reimplementing calc-delete-selection using rewrites.
X  ;;;
X  ;;;   When the stack is truncated, put the "." on the *second*-to-bottom line.
X  ;;;   When formatting formulas, suppress extra spaces inside vectors!
X***************
X*** 284,294 ****
X--- 310,323 ----
X  ;;;       bitwise stuff, rewrite rules, selections.
X  ;;;   Provide more Lisp programming examples in the manual.
X  ;;;   Finish the Internals section of the manual (and bring it up to date).
X+ ;;;   Make a TeX or PostScript reference card for Calc.
X  ;;;
X  ;;;   Tim suggests adding spreadsheet-like features.
X  ;;;   Is constructive real arithmetic worth implementing?
X  ;;;   Implement language modes for Eqn, Gnuplot, Lisp, Ada, ...?
X  ;;;
X+ ;;;   "2 M 7 SPC 5 M 13 * 4 M 7 *" goes into an infinite recursion.
X+ ;;;
X  
X  
X  ;;; For atan series, if x > tan(pi/12) (about 0.268) reduce using the identity
X***************
X*** 898,907 ****
X        (or (eq arg 0)
X  	  (progn
X  	    (calc-extensions)
X! 	    (if (< (prefix-numeric-value arg) 0)
X! 		(calc-grab-region (region-beginning) (region-end) nil))))
X      (if (eq major-mode 'calc-mode)
X  	(calc-quit)
X        (let ((oldbuf (current-buffer)))
X  	(calc-create-buffer)
X  	(if full-display
X--- 927,940 ----
X        (or (eq arg 0)
X  	  (progn
X  	    (calc-extensions)
X! 	    (if (= (prefix-numeric-value arg) -1)
X! 		(calc-grab-region (region-beginning) (region-end) nil)
X! 	      (if (= (prefix-numeric-value arg) -2)
X! 		  (calc-keypad)))))
X      (if (eq major-mode 'calc-mode)
X  	(calc-quit)
X+       (if (get-buffer-window "*Calc Keypad*")
X+ 	  (calc-keypad))
X        (let ((oldbuf (current-buffer)))
X  	(calc-create-buffer)
X  	(if full-display
X***************
X*** 971,981 ****
X  	   (lambda (v) (set-default v (symbol-value v)))) calc-local-var-list)
X    (let ((buf (current-buffer))
X  	(win (get-buffer-window (current-buffer))))
X      (if (and win
X! 	     (< (window-height win) (1- (screen-height))))
X  	(setq calc-window-height (- (window-height win) 2)))
X      (delete-windows-on buf)
X!     (delete-windows-on (calc-trail-buffer))
X      (bury-buffer buf)
X      (bury-buffer calc-trail-buffer))
X  )
X--- 1004,1016 ----
X  	   (lambda (v) (set-default v (symbol-value v)))) calc-local-var-list)
X    (let ((buf (current-buffer))
X  	(win (get-buffer-window (current-buffer))))
X+     (delete-windows-on (calc-trail-buffer))
X      (if (and win
X! 	     (< (window-height win) (1- (screen-height)))
X! 	     (= (window-width win) (screen-width)))  ; avoid calc-keypad mode
X  	(setq calc-window-height (- (window-height win) 2)))
X      (delete-windows-on buf)
X!     (delete-windows-on (get-buffer "*Calc Keypad*"))
X      (bury-buffer buf)
X      (bury-buffer calc-trail-buffer))
X  )
X***************
X*** 995,1000 ****
X--- 1030,1045 ----
X    (calc-do-calc-eval str separator args)
X  )
X  
X+ (defun calc-keypad ()
X+   "Invoke the Calculator in \"visual keypad\" mode.
X+ This is most useful in the X window system.
X+ In this mode, click on the Calc \"buttons\" using the left mouse button.
X+ Or, position the cursor manually and do M-x calc-keypad-press."
X+   (interactive)
X+   (calc-extensions)
X+   (calc-do-keypad)
X+ )
X+ 
X  ;;;; [calc-aent.el]
X  
X  (defun calc-do-quick-calc ()
X***************
X*** 1021,1044 ****
X  )
X  
X  (defun calc-do-calc-eval (str separator args)
X!   (save-excursion
X!     (calc-create-buffer)
X!     (let* ((calc-command-flags nil)
X! 	   (calc-language (if (memq calc-language '(nil big))
X! 			      'flat calc-language))
X! 	   (calc-dollar-values args)
X! 	   (calc-dollar-used 0)
X! 	   (res (math-read-exprs str))
X! 	   buf)
X!       (if (eq (car res) 'error)
X! 	  (cdr res)
X! 	(setq res (mapcar 'calc-normalize res))
X! 	(while res
X! 	  (setq buf (concat buf
X! 			    (and buf (or separator ", "))
X! 			    (math-format-value (car res) 1000))
X! 		res (cdr res)))
X! 	buf)))
X  )
X  
X  ;;;; [calc.el]
X--- 1066,1204 ----
X  )
X  
X  (defun calc-do-calc-eval (str separator args)
X!   (catch 'calc-error
X!     (save-excursion
X!       (calc-create-buffer)
X!       (cond
X!        ((and (consp str) (not (symbolp (car str))))
X! 	(let ((calc-language nil)
X! 	      (math-expr-opers math-standard-opers)
X! 	      (calc-internal-prec 12)
X! 	      (calc-word-size 32)
X! 	      (calc-symbolic-mode nil)
X! 	      (calc-angle-mode 'deg)
X! 	      (calc-number-radix 10)
X! 	      (calc-leading-zeros nil)
X! 	      (calc-group-digits nil)
X! 	      (calc-point-char ".")
X! 	      (calc-frac-format ":")
X! 	      (calc-prefer-frac nil)
X! 	      (calc-hms-format "%s@ %s' %s\"")
X! 	      (calc-float-format '(float 0))
X! 	      (calc-complex-format nil)
X! 	      (calc-matrix-just nil)
X! 	      (calc-full-vectors t)
X! 	      (calc-break-vectors nil)
X! 	      (calc-vector-commas ",")
X! 	      (calc-vector-brackets "[]")
X! 	      (calc-complex-mode 'cplx)
X! 	      (calc-display-strings nil)
X! 	      (calc-simplify-mode nil)
X! 	      (calc-display-working-message 'lots)
X! 	      (strp (cdr str)))
X! 	  (while strp
X! 	    (set (car strp) (nth 1 strp))
X! 	    (setq strp (cdr (cdr strp))))
X! 	  (calc-do-calc-eval (car str) separator args)))
X!        ((eq separator 'eval)
X! 	(eval str))
X!        ((eq separator 'macro)
X! 	(calc-extensions)
X! 	(let* ((calc-buffer (current-buffer))
X! 	       (calc-window (get-buffer-window calc-buffer))
X! 	       (save-window (selected-window)))
X! 	  (if calc-window
X! 	      (unwind-protect
X! 		  (progn
X! 		    (select-window calc-window)
X! 		    (calc-execute-kbd-macro str nil (car args)))
X! 		(and (window-point save-window)
X! 		     (select-window save-window)))
X! 	    (save-window-excursion
X! 	      (select-window (get-largest-window))
X! 	      (switch-to-buffer calc-buffer)
X! 	      (calc-execute-kbd-macro str nil (car args)))))
X! 	nil)
X!        ((eq separator 'pop)
X! 	(or (not (integerp str))
X! 	    (= str 0)
X! 	    (calc-pop (min str (calc-stack-size))))
X! 	(calc-stack-size))
X!        ((eq separator 'top)
X! 	(and (integerp str)
X! 	     (> str 0)
X! 	     (<= str (calc-stack-size))
X! 	     (math-format-value (calc-top-n str (car args)) 1000)))
X!        ((eq separator 'rawtop)
X! 	(and (integerp str)
X! 	     (> str 0)
X! 	     (<= str (calc-stack-size))
X! 	     (calc-top-n str (car args))))
X!        (t
X! 	(let* ((calc-command-flags nil)
X! 	       (calc-next-why nil)
X! 	       (calc-language (if (memq calc-language '(nil big))
X! 				  'flat calc-language))
X! 	       (calc-dollar-values (mapcar
X! 				    (function
X! 				     (lambda (x)
X! 				       (if (stringp x)
X! 					   (progn
X! 					     (setq x (math-read-exprs x))
X! 					     (if (eq (car-safe x)
X! 						     'error)
X! 						 (throw 'calc-error
X! 							(calc-eval-error
X! 							 (cdr x)))
X! 					       (car x)))
X! 					 x)))
X! 				    args))
X! 	       (calc-dollar-used 0)
X! 	       (res (if (stringp str)
X! 			(math-read-exprs str)
X! 		      (list str)))
X! 	       buf)
X! 	  (if (eq (car res) 'error)
X! 	      (calc-eval-error (cdr res))
X! 	    (setq res (mapcar 'calc-normalize res))
X! 	    (and (memq 'clear-message calc-command-flags)
X! 		 (message ""))
X! 	    (cond ((eq separator 'raw)
X! 		   (if (= (length res) 1)
X! 		       (car res)
X! 		     (calc-eval-error '(0 "Single value expected"))))
X! 		  ((eq separator 'list)
X! 		   res)
X! 		  ((memq separator '(num rawnum))
X! 		   (if (= (length res) 1)
X! 		       (if (math-constp (car res))
X! 			   (if (eq separator 'num)
X! 			       (math-format-value (car res) 1000)
X! 			     (car res))
X! 			 (calc-eval-error
X! 			  (list 0
X! 				(if calc-next-why
X! 				    (calc-explain-why (car calc-next-why))
X! 				  "Number expected"))))
X! 		     (calc-eval-error '(0 "Single value expected"))))
X! 		  ((eq separator 'push)
X! 		   (calc-push-list res)
X! 		   nil)
X! 		  (t (while res
X! 		       (setq buf (concat buf
X! 					 (and buf (or separator ", "))
X! 					 (math-format-value (car res) 1000))
X! 			     res (cdr res)))
X! 		     buf))))))))
X! )
X! 
X! (defun calc-eval-error (msg)
X!   (if (and (boundp 'calc-eval-error)
X! 	   calc-eval-error)
X!       (if (eq calc-eval-error 'string)
X! 	  (nth 1 msg)
X! 	(error "%s" (nth 1 msg)))
X!     msg)
X  )
X  
X  ;;;; [calc.el]
X***************
X*** 1123,1140 ****
X  
X  (defun calc-do (do-body &optional do-slow)
X    (let ((calc-command-flags nil))
X      (unwind-protect
X! 	(save-excursion
X! 	  (calc-select-buffer)
X! 	  (and do-slow calc-display-working-message
X! 	       (progn
X! 		 (message "Working...")
X! 		 (calc-set-command-flag 'clear-message)))
X! 	  (funcall do-body)
X! 	  (and (memq 'renum-stack calc-command-flags)
X! 	       (calc-renumber-stack))
X! 	  (and (memq 'clear-message calc-command-flags)
X! 	       (message "")))
X        (or (memq 'no-align calc-command-flags)
X  	  (eq major-mode 'calc-trail-mode)
X  	  (calc-align-stack-window))
X--- 1283,1314 ----
X  
X  (defun calc-do (do-body &optional do-slow)
X    (let ((calc-command-flags nil))
X+     (setq calc-aborted-prefix "")
X      (unwind-protect
X! 	(condition-case err
X! 	    (save-excursion
X! 	      (calc-select-buffer)
X! 	      (and do-slow calc-display-working-message
X! 		   (progn
X! 		     (message "Working...")
X! 		     (calc-set-command-flag 'clear-message)))
X! 	      (funcall do-body)
X! 	      (setq calc-aborted-prefix nil)
X! 	      (and (memq 'renum-stack calc-command-flags)
X! 		   (calc-renumber-stack))
X! 	      (and (memq 'clear-message calc-command-flags)
X! 		   (message "")))
X! 	  (error
X! 	   (if (and (eq (car err) 'error)
X! 		    (stringp (nth 1 err))
X! 		    (string-match "max-specpdl-size\\|max-lisp-eval-depth"
X! 				  (nth 1 err)))
X! 	       (error "Computation got stuck or ran too long.  Type `M' to increase the limit.")
X! 	     (setq calc-aborted-prefix nil)
X! 	     (signal (car err) (cdr err)))))
X!       (setq calc-old-aborted-prefix calc-aborted-prefix)
X!       (and calc-aborted-prefix
X! 	   (calc-record "<Aborted>" calc-aborted-prefix))
X        (or (memq 'no-align calc-command-flags)
X  	  (eq major-mode 'calc-trail-mode)
X  	  (calc-align-stack-window))
X***************
X*** 1143,1154 ****
X  	     (goto-line calc-final-point-line)
X  	     (move-to-column calc-final-point-column)))
X        (or (memq 'keep-flags calc-command-flags)
X! 	  (setq calc-inverse-flag nil
X! 		calc-hyperbolic-flag nil))
X        (and (memq 'do-edit calc-command-flags)
X  	   (switch-to-buffer (get-buffer-create "*Calc Edit*")))
X        (calc-set-mode-line)))
X  )
X  
X  (defun calc-set-command-flag (f)
X    (if (not (memq f calc-command-flags))
X--- 1317,1331 ----
X  	     (goto-line calc-final-point-line)
X  	     (move-to-column calc-final-point-column)))
X        (or (memq 'keep-flags calc-command-flags)
X! 	  (save-excursion
X! 	    (calc-select-buffer)
X! 	    (setq calc-inverse-flag nil
X! 		  calc-hyperbolic-flag nil)))
X        (and (memq 'do-edit calc-command-flags)
X  	   (switch-to-buffer (get-buffer-create "*Calc Edit*")))
X        (calc-set-mode-line)))
X  )
X+ (setq calc-aborted-prefix nil)
X  
X  (defun calc-set-command-flag (f)
X    (if (not (memq f calc-command-flags))
X***************
X*** 1243,1257 ****
X  )
X  
X  (defun calc-align-stack-window ()
X!   (let ((win (get-buffer-window (current-buffer))))
X!     (if win
X! 	(progn
X! 	  (calc-cursor-stack-index 0)
X! 	  (vertical-motion (- 2 (window-height)))
X! 	  (set-window-start win (point)))))
X!   (calc-cursor-stack-index 0)
X!   (if (looking-at " *\\.$")
X!       (goto-char (1- (match-end 0))))
X  )
X  
X  (defun calc-check-stack (n)
X--- 1420,1439 ----
X  )
X  
X  (defun calc-align-stack-window ()
X!   (if (eq major-mode 'calc-mode)
X!       (progn
X! 	(let ((win (get-buffer-window (current-buffer))))
X! 	  (if win
X! 	      (progn
X! 		(calc-cursor-stack-index 0)
X! 		(vertical-motion (- 2 (window-height win)))
X! 		(set-window-start win (point)))))
X! 	(calc-cursor-stack-index 0)
X! 	(if (looking-at " *\\.$")
X! 	    (goto-char (1- (match-end 0)))))
X!     (save-excursion
X!       (calc-select-buffer)
X!       (calc-align-stack-window)))
X  )
X  
X  (defun calc-check-stack (n)
X***************
X*** 1305,1310 ****
X--- 1487,1493 ----
X  )
X  
X  (defun calc-enter-result (n prefix vals &optional m)
X+   (setq calc-aborted-prefix prefix)
X    (if (and (consp vals)
X  	   (or (integerp (car vals))
X  	       (consp (car vals))))
X***************
X*** 1561,1566 ****
X--- 1744,1750 ----
X  )
X  
X  (defun calc-record (val &optional prefix)
X+   (setq calc-aborted-prefix nil)
X    (or calc-executing-macro
X        (let* ((mainbuf (current-buffer))
X  	     (buf (calc-trail-buffer))
X***************
X*** 1682,1687 ****
X--- 1866,1872 ----
X  ;;; Arithmetic commands.
X  
X  (defun calc-binary-op (name func arg &optional ident unary func2)
X+   (setq calc-aborted-prefix name)
X    (if (null arg)
X        (calc-enter-result 2 name (cons (or func2 func) (calc-top-list-n 2)))
X      (calc-extensions)
X***************
X*** 1689,1694 ****
X--- 1874,1880 ----
X  )
X  
X  (defun calc-unary-op (name func arg &optional func2)
X+   (setq calc-aborted-prefix name)
X    (if (null arg)
X        (calc-enter-result 1 name (list (or func2 func) (calc-top-n 1)))
X      (calc-extensions)
X***************
X*** 1765,1771 ****
X  ;;; Stack management commands.
X  
X  (defun calc-enter (n)
X!   "Duplicate the top N elements of the Calculator stack.
X  With a negative argument -N, duplicate the Nth element of the stack."
X    (interactive "p")
X    (calc-wrapper
X--- 1951,1957 ----
X  ;;; Stack management commands.
X  
X  (defun calc-enter (n)
X!   "Duplicate the top element (or top N elements) of the Calculator stack.
X  With a negative argument -N, duplicate the Nth element of the stack."
X    (interactive "p")
X    (calc-wrapper
X***************
X*** 1780,1786 ****
X  ;;;; [calc-misc.el]
X  
X  (defun calc-over (n)
X!   "Duplicate the Nth element of the Calculator stack.
X  With a negative argument -N, duplicate the top N elements of the stack."
X    (interactive "P")
X    (if n
X--- 1966,1972 ----
X  ;;;; [calc-misc.el]
X  
X  (defun calc-over (n)
X!   "Duplicate the second (or Nth) element of the Calculator stack.
X  With a negative argument -N, duplicate the top N elements of the stack."
X    (interactive "P")
X    (if n
X***************
X*** 1791,1798 ****
X  ;;;; [calc.el]
X  
X  (defun calc-pop (n)
X!   "Pop (and discard) the top N elements of the stack.
X! With a negative argument -N, remove the Nth element from the stack."
X    (interactive "P")
X    (calc-wrapper
X     (let* ((nn (prefix-numeric-value n))
X--- 1977,1985 ----
X  ;;;; [calc.el]
X  
X  (defun calc-pop (n)
X!   "Pop (and discard) the top element (or top N elements) of the stack.
X! With a negative argument -N, remove the Nth element from the stack.
X! With a zero prefix argument, clear the whole stack."
X    (interactive "P")
X    (calc-wrapper
X     (let* ((nn (prefix-numeric-value n))
X***************
X*** 1822,1828 ****
X  
X  (defun calc-roll-down (n)
X    "Exchange the top two elements of the Calculator stack.
X! With a numeric prefix, roll down the top N elements."
X    (interactive "P")
X    (calc-wrapper
X     (let ((nn (prefix-numeric-value n)))
X--- 2009,2017 ----
X  
X  (defun calc-roll-down (n)
X    "Exchange the top two elements of the Calculator stack.
X! With a positive numeric prefix, roll down the top N elements.
X! With a negative numeric prefix, roll down the whole stack N times.
X! With a zero prefix, reverse the order of elements in the stack."
X    (interactive "P")
X    (calc-wrapper
X     (let ((nn (prefix-numeric-value n)))
X***************
X*** 1839,1846 ****
X  )
X  
X  (defun calc-roll-up (n)
X!   "Roll up the top three elements of the Calculator stack.
X! With a numeric prefix, roll up the top N elements."
X    (interactive "P")
X    (calc-wrapper
X     (let ((nn (prefix-numeric-value n)))
X--- 2028,2037 ----
X  )
X  
X  (defun calc-roll-up (n)
X!   "Roll up (rotate) the top three elements of the Calculator stack.
X! With a numeric prefix, roll up the top N elements.
X! With a negative numeric prefix, roll up the whole stack N times.
X! With a zero prefix, reverse the order of elements in the stack."
X    (interactive "P")
X    (calc-wrapper
X     (let ((nn (prefix-numeric-value n)))
X***************
X*** 1937,1942 ****
X--- 2128,2134 ----
X        (define-key calc-alg-ent-map "\em" 'calcAlg-mod)
X        (define-key calc-alg-ent-map "\C-m" 'calcAlg-enter)
X        (define-key calc-alg-ent-map "\C-j" 'calcAlg-enter))
X+     (setq calc-aborted-prefix nil)
X      (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
X  				     (or initial "")
X  				     calc-alg-ent-map nil)))
X***************
X*** 1943,1948 ****
X--- 2135,2141 ----
X        (if (eq alg-exp 'error)
X  	  (if (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error)
X  	      (setq alg-exp nil)))
X+       (setq calc-aborted-prefix "alg'")
X        (or no-normalize
X  	  (and alg-exp (setq alg-exp (mapcar 'calc-normalize alg-exp))))
X        alg-exp))
X***************
X*** 2024,2030 ****
X  		      (= (char-after blinkpos) ?\()))
X  	     (save-excursion
X  	       (goto-char blinkpos)
X! 	       (looking-at ".+\\.\\.")))
X  	(let ((saved (aref (syntax-table) (char-after blinkpos))))
X  	  (unwind-protect
X  	      (progn
X--- 2217,2223 ----
X  		      (= (char-after blinkpos) ?\()))
X  	     (save-excursion
X  	       (goto-char blinkpos)
X! 	       (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
X  	(let ((saved (aref (syntax-table) (char-after blinkpos))))
X  	  (unwind-protect
X  	      (progn
X***************
X*** 2048,2054 ****
X    (calc-wrapper
X     (if calc-algebraic-mode
X         (calc-alg-digit-entry)
X!      (setq unread-command-char last-command-char)
X       (let* ((calc-digit-value nil)
X  	    (calc-prev-char nil)
X  	    (calc-prev-prev-char nil)
X--- 2241,2248 ----
X    (calc-wrapper
X     (if calc-algebraic-mode
X         (calc-alg-digit-entry)
X!      (setq unread-command-char last-command-char
X! 	   calc-aborted-prefix nil)
X       (let* ((calc-digit-value nil)
X  	    (calc-prev-char nil)
X  	    (calc-prev-prev-char nil)
X***************
X*** 2393,2431 ****
X      (calc-extensions)
X      (math-normalize-fancy a))
X     (t
X!     (let ((args (mapcar 'math-normalize (cdr a))))
X!       (or (and calc-simplify-mode
X! 	       (calc-extensions)
X! 	       (math-normalize-nonstandard a))
X! 	  (condition-case err
X! 	      (let ((func (assq (car a) '( ( + . math-add )
X! 					   ( - . math-sub )
X! 					   ( * . math-mul )
X! 					   ( / . math-div )
X! 					   ( % . math-mod )
X! 					   ( ^ . math-pow )
X! 					   ( neg . math-neg )
X! 					   ( | . math-concat ) ))))
X! 		(if func
X! 		    (apply (cdr func) args)
X! 		  (and (or (consp (car a))
X! 			   (fboundp (car a))
X! 			   (and (not calc-extensions-loaded)
X! 				(calc-extensions)
X! 				(fboundp (car a))))
X! 		       (apply (car a) args))))
X! 	    (wrong-number-of-arguments
X! 	     (calc-record-why "Wrong number of arguments") nil)
X! 	    (wrong-type-argument
X! 	     (or calc-next-why (calc-record-why "Wrong type of argument"))
X! 	     nil)
X! 	    (args-out-of-range
X! 	     (calc-record-why "Argument out of range") nil)
X! 	    (inexact-result
X! 	     (calc-record-why "No exact representation for result") nil))
X! 	  (if (consp (car a))
X! 	      (math-dimension-error)
X! 	    (cons (car a) args))))))
X  )
X  
X  ;;;; [calc-macs.el]
X--- 2587,2625 ----
X      (calc-extensions)
X      (math-normalize-fancy a))
X     (t
X!     (or (and calc-simplify-mode
X! 	     (calc-extensions)
X! 	     (math-normalize-nonstandard))
X! 	(let ((args (mapcar 'math-normalize (cdr a))))
X! 	  (or (condition-case err
X! 		  (let ((func (assq (car a) '( ( + . math-add )
X! 					       ( - . math-sub )
X! 					       ( * . math-mul )
X! 					       ( / . math-div )
X! 					       ( % . math-mod )
X! 					       ( ^ . math-pow )
X! 					       ( neg . math-neg )
X! 					       ( | . math-concat ) ))))
X! 		    (if func
X! 			(apply (cdr func) args)
X! 		      (and (or (consp (car a))
X! 			       (fboundp (car a))
X! 			       (and (not calc-extensions-loaded)
X! 				    (calc-extensions)
X! 				    (fboundp (car a))))
X! 			   (apply (car a) args))))
X! 		(wrong-number-of-arguments
X! 		 (calc-record-why "Wrong number of arguments") nil)
X! 		(wrong-type-argument
X! 		 (or calc-next-why (calc-record-why "Wrong type of argument"))
X! 		 nil)
X! 		(args-out-of-range
X! 		 (calc-record-why "Argument out of range") nil)
X! 		(inexact-result
X! 		 (calc-record-why "No exact representation for result") nil))
X! 	      (if (consp (car a))
X! 		  (math-dimension-error)
X! 		(cons (car a) args)))))))
X  )
X  
X  ;;;; [calc-macs.el]
X***************
X*** 3971,3977 ****
X  	     (setq exp-token 'dollar
X  		   exp-data (- (match-end 0) (match-beginning 0))
X  		   exp-pos (match-end 0)))
X! 	    ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&\\|||\\|!!"
X  			       exp-str exp-pos)
X  		 exp-pos)
X  	     (setq exp-token 'punc
X--- 4165,4171 ----
X  	     (setq exp-token 'dollar
X  		   exp-data (- (match-end 0) (match-beginning 0))
X  		   exp-pos (match-end 0)))
X! 	    ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&\\|||\\|!!"
X  			       exp-str exp-pos)
X  		 exp-pos)
X  	     (setq exp-token 'punc
X***************
X*** 4220,4226 ****
X  				       (list 'calcFunc-exp
X  					     (list '* exp2
X  						   '(var i var-i)))))))))
X! 		((equal exp-data "\\dots")
X  		 (progn
X  		   (math-read-token)
X  		   (let ((exp2 (math-read-expr-level 0)))
X--- 4414,4421 ----
X  				       (list 'calcFunc-exp
X  					     (list '* exp2
X  						   '(var i var-i)))))))))
X! 		((or (equal exp-data "\\dots")
X! 		     (equal exp-data "\\ldots"))
X  		 (progn
X  		   (math-read-token)
X  		   (let ((exp2 (math-read-expr-level 0)))
X***************
X*** 4260,4266 ****
X    (interactive "sBug Subject: ")
X    (mail nil calc-bug-address topic)
X    (goto-char (point-max))
X!   (insert "\nIn Calc 1.05, Emacs " (emacs-version) "\n\n")
X    (message (substitute-command-keys "Type \\[mail-send] to send bug report."))
X  )
X  
X--- 4455,4461 ----
X    (interactive "sBug Subject: ")
X    (mail nil calc-bug-address topic)
X    (goto-char (point-max))
X!   (insert "\nIn Calc 1.06, Emacs " (emacs-version) "\n\n")
X    (message (substitute-command-keys "Type \\[mail-send] to send bug report."))
X  )
X  
X*** calc-ext.el	Tue Oct  9 16:58:38 1990
X--- ../dist/calc-ext.el	Wed Oct 24 02:03:58 1990
X***************
X*** 1,4 ****
X! ;; Calculator for GNU Emacs version 1.05, part II
X  ;; Copyright (C) 1990 Dave Gillespie
X  
X  ;; This file is part of GNU Emacs.
X--- 1,4 ----
X! ;; Calculator for GNU Emacs version 1.06, part II
X  ;; Copyright (C) 1990 Dave Gillespie
X  
X  ;; This file is part of GNU Emacs.
X***************
X*** 110,115 ****
X--- 110,116 ----
X    (define-key calc-mode-map "aA" 'calc-abs)
X    (define-key calc-mode-map "aI" 'calc-integral-limit)
X    (define-key calc-mode-map "aN" 'calc-find-minimum)
X+   (define-key calc-mode-map "aP" 'calc-poly-roots)
X    (define-key calc-mode-map "aS" 'calc-solve-for)
X    (define-key calc-mode-map "aR" 'calc-find-root)
X    (define-key calc-mode-map "aX" 'calc-find-maximum)
X***************
X*** 414,419 ****
X--- 415,426 ----
X    (define-key calc-mode-map "vR" 'calc-reduce)
X    (define-key calc-mode-map "vS" 'calc-sort)
X    (define-key calc-mode-map "vT" 'calc-mtrace)
X+   (define-key calc-mode-map "vU" 'calc-accumulate)
X+   (define-key calc-mode-map "vV" 'calc-set-union)
X+   (define-key calc-mode-map "vX" 'calc-set-xor)
X+   (define-key calc-mode-map "v^" 'calc-set-intersect)
X+   (define-key calc-mode-map "v-" 'calc-set-difference)
X+   (define-key calc-mode-map "v+" 'calc-remove-duplicates)
X    (define-key calc-mode-map "v&" 'calc-inv)
X    (define-key calc-mode-map "v<" 'calc-matrix-left-justify)
X    (define-key calc-mode-map "v=" 'calc-matrix-center-justify)
X***************
X*** 461,469 ****
X    (mapcar (function
X  	   (lambda (x)
X  	     (define-key calc-mode-map (format "c%c" x) 'calc-clean-num)
X! 	     (define-key calc-mode-map (format "g%c" x) 'calc-select-part)))
X  	  "123456789")
X  
X  ;;;; (Autoloads here)
X  
X  )
X--- 468,484 ----
X    (mapcar (function
X  	   (lambda (x)
X  	     (define-key calc-mode-map (format "c%c" x) 'calc-clean-num)
X! 	     (define-key calc-mode-map (format "j%c" x) 'calc-select-part)))
X  	  "123456789")
X  
X+   (if (and (boundp 'calc-ext-defs)
X+ 	   calc-ext-defs)
X+       (progn
X+ 	(calc-need-macros)
X+ 	(message "Evaluating calc-ext-defs...")
X+ 	(eval (cons 'progn calc-ext-defs))
X+ 	(setq calc-ext-defs nil)))
X+ 
X  ;;;; (Autoloads here)
X  
X  )
X***************
X*** 515,526 ****
X  	   (if (math-realp s)
X  	       (math-clip (math-round s))
X  	     s)))
X! 	((eq calc-simplify-mode 'alg)
X  	 (math-simplify val))
X! 	((eq calc-simplify-mode 'ext)
X  	 (math-simplify-extended val))
X  	((eq calc-simplify-mode 'units)
X! 	 (math-simplify-units val)))
X  )
X  
X  
X--- 530,545 ----
X  	   (if (math-realp s)
X  	       (math-clip (math-round s))
X  	     s)))
X! 	((or (eq calc-simplify-mode 'alg)
X! 	     (equal calc-simplify-mode '(alg)))
X  	 (math-simplify val))
X! 	((or (eq calc-simplify-mode 'ext)
X! 	     (equal calc-simplify-mode '(ext)))
X  	 (math-simplify-extended val))
X  	((eq calc-simplify-mode 'units)
X! 	 (math-simplify-units val))
X! 	(t  ; '(nil)
X! 	 (math-normalize val)))
X  )
X  
X  
X***************
X*** 611,617 ****
X       "I + F (ceiling), R (truncate); a S (invert func)"
X       "I + a m (match-not); c h (from-hms); k n (prev prime)"
X       "I + f G (gamma-Q); f e (erfc); k B (etc., lower-tail dists)"
X!      "I + V S (reverse sort); V G (reverse grade)")
X     "inverse" nil)
X  )
X  
X--- 630,637 ----
X       "I + F (ceiling), R (truncate); a S (invert func)"
X       "I + a m (match-not); c h (from-hms); k n (prev prime)"
X       "I + f G (gamma-Q); f e (erfc); k B (etc., lower-tail dists)"
X!      "I + V S (reverse sort); V G (reverse grade)"
X!      "I + v s (remove subvec)")
X     "inverse" nil)
X  )
X  
X***************
X*** 622,631 ****
X       "H + F (float floor), R (float round); P (constant \"e\")"
X       "H + a d (total derivative); k c (permutations)"
X       "H + k b (bern-poly), k e (euler-poly); k s (stirling-2)"
X!      "H + f G (gamma-g), f B (beta-B); V R (accumulate)"
X       "H + v e (expand w/filler); V H (weighted histogram)"
X       "H + a S (general solve eqn), j I (general isolate)"
X!      "H + a R (widen/root)")
X     "hyperbolic" nil)
X  )
X  
X--- 642,651 ----
X       "H + F (float floor), R (float round); P (constant \"e\")"
X       "H + a d (total derivative); k c (permutations)"
X       "H + k b (bern-poly), k e (euler-poly); k s (stirling-2)"
X!      "H + f G (gamma-g), f B (beta-B)"
X       "H + v e (expand w/filler); V H (weighted histogram)"
X       "H + a S (general solve eqn), j I (general isolate)"
X!      "H + a R (widen/root), a N (widen/min), a X (widen/max)")
X     "hyperbolic" nil)
X  )
X  
X***************
X*** 685,693 ****
X  )
X  
X  (defun calc-invert-func ()
X!   (setq calc-inverse-flag (not (calc-is-inverse))
X! 	calc-hyperbolic-flag (calc-is-hyperbolic)
X! 	current-prefix-arg nil)
X  )
X  
X  (defun calc-is-inverse ()
X--- 705,715 ----
X  )
X  
X  (defun calc-invert-func ()
X!   (save-excursion
X!     (calc-select-buffer)
X!     (setq calc-inverse-flag (not (calc-is-inverse))
X! 	  calc-hyperbolic-flag (calc-is-hyperbolic)
X! 	  current-prefix-arg nil))
X  )
X  
X  (defun calc-is-inverse ()
X***************
X*** 706,714 ****
X  )
X  
X  (defun calc-hyperbolic-func ()
X!   (setq calc-inverse-flag (calc-is-inverse)
X! 	calc-hyperbolic-flag (not (calc-is-hyperbolic))
X! 	current-prefix-arg nil)
X  )
X  
X  (defun calc-is-hyperbolic ()
X--- 728,738 ----
X  )
X  
X  (defun calc-hyperbolic-func ()
X!   (save-excursion
X!     (calc-select-buffer)
X!     (setq calc-inverse-flag (calc-is-inverse)
X! 	  calc-hyperbolic-flag (not (calc-is-hyperbolic))
X! 	  current-prefix-arg nil))
X  )
X  
X  (defun calc-is-hyperbolic ()
X***************
X*** 1899,1904 ****
X--- 1923,1929 ----
X  With any numeric prefix argument, unsets the specified variable."
X    (interactive "P")
X    (calc-wrapper
X+    (setq calc-aborted-prefix nil)
X     (if n
X         (progn
X  	 (or var
X***************
X*** 2001,2006 ****
X--- 2026,2032 ----
X    "Recall the value of variable VAR into the Calculator stack."
X    (interactive)
X    (calc-wrapper
X+    (setq calc-aborted-prefix nil)
X     (or var
X         (setq var (let ((minibuffer-completion-table obarray)
X  		       (minibuffer-completion-predicate 'boundp)
X***************
X*** 2029,2034 ****
X--- 2055,2061 ----
X    "Evaluate second-in-stack where variable VAR equals top of stack."
X    (interactive)
X    (calc-wrapper
X+    (setq calc-aborted-prefix nil)
X     (or var
X         (setq var (let ((minibuffer-completion-table obarray)
X  		       (minibuffer-completion-predicate 'boundp)
X***************
X*** 3106,3120 ****
X  			    (eq (nth 2 parent) (nth 2 entry))))
X  		   (setq repl 1))
X  		  ((memq (car parent) '(vec calcFunc-min calcFunc-max)))
X  		  (t
X  		   (setq repl 0)))
X! 	    (if repl
X! 		(calc-push-list (list
X! 				 (calc-normalize
X! 				  (calc-replace-sub-formula (car entry)
X! 							    (nth 2 entry)
X! 							    repl)))
X! 				n)
X  	      (calc-push-list (list
X  			       (calc-normalize
X  				(calc-replace-sub-formula (car entry)
X--- 3133,3162 ----
X  			    (eq (nth 2 parent) (nth 2 entry))))
X  		   (setq repl 1))
X  		  ((memq (car parent) '(vec calcFunc-min calcFunc-max)))
X+ 		  ((and (assq (car parent) calc-tweak-eqn-table)
X+ 			(= (length parent) 3))
X+ 		   (setq repl 'del))
X  		  (t
X  		   (setq repl 0)))
X! 	    (cond
X! 	     ((eq repl 'del)
X! 	      (calc-push-list (list
X! 			       (calc-normalize
X! 				(calc-replace-sub-formula
X! 				 (car entry)
X! 				 parent
X! 				 (if (eq (nth 2 entry) (nth 1 parent))
X! 				     (nth 2 parent)
X! 				   (nth 1 parent)))))
X! 			      n))
X! 	     (repl
X! 	      (calc-push-list (list
X! 			       (calc-normalize
X! 				(calc-replace-sub-formula (car entry)
X! 							  (nth 2 entry)
X! 							  repl)))
X! 			      n))
X! 	     (t
X  	      (calc-push-list (list
X  			       (calc-normalize
X  				(calc-replace-sub-formula (car entry)
X***************
X*** 3122,3128 ****
X  							  (delq (nth 2 entry)
X  								(copy-sequence
X  								 parent)))))
X! 			      n))))
X        (calc-pop-stack 1 n t)))
X  )
X  
X--- 3164,3170 ----
X  							  (delq (nth 2 entry)
X  								(copy-sequence
X  								 parent)))))
X! 			      n)))))
X        (calc-pop-stack 1 n t)))
X  )
X  
X***************
X*** 3246,3252 ****
X    "Apply normal default simplifications to selected sub-formula.
X  \(See calc-alg-evaluate.)
X  With a prefix argument of 2, applies calc-simplify.
X! With a prefix argument of 3 or more, applies calc-simplify-extended."
X    (interactive "p")
X    (calc-slow-wrapper
X     (calc-preserve-point)
X--- 3288,3295 ----
X    "Apply normal default simplifications to selected sub-formula.
X  \(See calc-alg-evaluate.)
X  With a prefix argument of 2, applies calc-simplify.
X! With a prefix argument of 3 or more, applies calc-simplify-extended.
X! With a negative prefix argument, simplifies only top level of sub-formula."
X    (interactive "p")
X    (calc-slow-wrapper
X     (calc-preserve-point)
X***************
X*** 3255,3270 ****
X  	  (entry (calc-top num 'entry))
X  	  (sel (or (calc-auto-selection entry) (car entry))))
X       (calc-with-default-simplification
X!       (let ((val (calc-encase-atoms (cond ((>= arg 3)
X! 					   (math-simplify-extended sel))
X! 					  ((>= arg 2)
X! 					   (math-simplify sel))
X! 					  (t (calc-normalize sel))))))
X! 	(calc-pop-push-record-list 1 "gsmp"
X! 				   (list (calc-replace-sub-formula
X! 					  (car entry) sel val))
X! 				   num
X! 				   (list (and reselect val)))))
X       (calc-handle-whys)))
X  )
X  
X--- 3298,3311 ----
X  	  (entry (calc-top num 'entry))
X  	  (sel (or (calc-auto-selection entry) (car entry))))
X       (calc-with-default-simplification
X!       (let ((math-simplify-only nil))
X! 	(calc-modify-simplify-mode arg)
X! 	(let ((val (calc-encase-atoms (calc-normalize sel))))
X! 	  (calc-pop-push-record-list 1 "gsmp"
X! 				     (list (calc-replace-sub-formula
X! 					    (car entry) sel val))
X! 				     num
X! 				     (list (and reselect val))))))
X       (calc-handle-whys)))
X  )
X  
X***************
X*** 4029,4035 ****
X     '("Simplify, Extended-simplify, eVal; eXpand, Collect"
X       "Derivative, Integral, Taylor; suBstitute"
X       "Rewrite, Match"
X!      "SHIFT + Solve; Root, miN, maX; Integral-limit"
X       "relations: =, # (not =), <, >, [ (< or =), ] (> or =)"
X       "logical: & (and), | (or), ! (not); : (if)"
X       "misc: { (in-set)")
X--- 4070,4076 ----
X     '("Simplify, Extended-simplify, eVal; eXpand, Collect"
X       "Derivative, Integral, Taylor; suBstitute"
X       "Rewrite, Match"
X!      "SHIFT + Solve; Root, miN, maX; Poly-roots; Integ-limit"
X       "relations: =, # (not =), <, >, [ (< or =), ] (> or =)"
X       "logical: & (and), | (or), ! (not); : (if)"
X       "misc: { (in-set)")
X***************
X*** 4038,4050 ****
X  
X  ;;;; [calc-alg.el]
X  
X! (defun calc-alg-evaluate ()
X    "Apply normal (default) simplifications to the formula at top of stack.
X! This works even if default simplifications have been turned off."
X!   (interactive)
X!   (calc-slow-wrapper
X!    (calc-with-default-simplification
X!     (calc-enter-result 1 "dsmp" (calc-top 1))))
X  )
X  
X  (defun calc-simplify ()
X--- 4079,4106 ----
X  
X  ;;;; [calc-alg.el]
X  
X! (defun calc-alg-evaluate (arg)
X    "Apply normal (default) simplifications to the formula at top of stack.
X! This works even if default simplifications have been turned off.
X! With a prefix argument of 2, this simplifies as if by `a s'.
X! With a prefix argument of 3, this simplifies as if by `a e'.
X! With a negative prefix argument, this simplifies only the top-level function
X! call in the formula."
X!   (interactive "p")
X!   (calc-slow-wrapper
X!    (calc-with-default-simplification
X!     (let ((math-simplify-only nil))
X!       (calc-modify-simplify-mode arg)
X!       (calc-enter-result 1 "dsmp" (calc-top 1)))))
X! )
X! 
X! (defun calc-modify-simplify-mode (arg)
X!   (if (= (math-abs arg) 2)
X!       (setq calc-simplify-mode 'alg)
X!     (if (>= (math-abs arg) 3)
X! 	(setq calc-simplify-mode 'ext)))
X!   (if (< arg 0)
X!       (setq calc-simplify-mode (list calc-simplify-mode)))
X  )
X  
X  (defun calc-simplify ()
X***************
X*** 4281,4286 ****
X--- 4337,4360 ----
X  					   var))))))
X  )
X  
X+ (defun calc-poly-roots (var)
X+   "Solve a polynomial equation for a given variable.
X+ See calc-solve-for.
X+ Return the result in the form of a vector of all solutions, if possible."
X+   (interactive "sVariable to solve for: ")
X+   (calc-slow-wrapper
X+    (if (equal var "")
X+        (calc-enter-result 2 "prts" (list 'calcFunc-roots
X+ 					 (calc-top-n 2)
X+ 					 (calc-top-n 1)))
X+      (let ((var (math-read-expr var)))
X+        (if (eq (car-safe var) 'error)
X+ 	   (error "Bad format in expression: %s" (nth 1 var)))
X+        (calc-enter-result 1 "prts" (list 'calcFunc-roots
X+ 					 (calc-top-n 1)
X+ 					 var)))))
X+ )
X+ 
X  (defun calc-taylor (var nterms)
X    "Compute the Taylor expansion of a formula."
X    (interactive "sTaylor expansion variable: \nNNumber of terms: ")
X***************
X*** 5519,5524 ****
X--- 5593,5599 ----
X  (defvar calc-gnuplot-last-error-pos 1)
X  (defvar calc-graph-last-device nil)
X  (defvar calc-graph-last-output nil)
X+ (defvar calc-graph-file-cache nil)
X  (defvar calc-graph-var-cache nil)
X  (defvar calc-graph-data-cache nil)
X  (defvar calc-graph-data-cache-limit 10)
X***************
X*** 5653,5665 ****
X  		   (insert str ", ")))))))
X  )
X  
X! (defun calc-graph-print ()
X    "Print the current graph.
X  This creates the same graph that calc-graph-plot would create, except
X  that it uses the printer instead of the screen.  This command overrides
X  any previous calc-graph-device or calc-graph-output commands."
X!   (interactive)
X!   (calc-graph-plot t)
X  )
X  
X  (defun calc-graph-plot (flag &optional printing)
X--- 5728,5740 ----
X  		   (insert str ", ")))))))
X  )
X  
X! (defun calc-graph-print (flag)
X    "Print the current graph.
X  This creates the same graph that calc-graph-plot would create, except
X  that it uses the printer instead of the screen.  This command overrides
X  any previous calc-graph-device or calc-graph-output commands."
X!   (interactive "P")
X!   (calc-graph-plot flag t)
X  )
X  
X  (defun calc-graph-plot (flag &optional printing)
X***************
X*** 5679,5684 ****
X--- 5754,5763 ----
X  	 (refine (and flag (> (prefix-numeric-value flag) 0)))
X  	 (recompute (and flag (< (prefix-numeric-value flag) 0)))
X  	 resolution precision samples-pos)
X+      (or (boundp 'calc-graph-prev-kill-hook)
X+ 	 (progn
X+ 	   (setq calc-graph-prev-kill-hook kill-emacs-hook)
X+ 	   (setq kill-emacs-hook 'calc-graph-kill-hook)))
X       (save-excursion
X         (calc-graph-init)
X         (set-buffer tempbuf)
X***************
X*** 5705,5713 ****
X  		   output calc-gnuplot-print-output)
X  	   (setq device (calc-graph-find-command "terminal")
X  		 output (calc-graph-find-command "output"))
X! 	   (if device
X! 	       (setq device (car (read-from-string device)))
X! 	     (setq device calc-gnuplot-default-device))
X  	   (if output
X  	       (setq output (car (read-from-string output)))
X  	     (setq output calc-gnuplot-default-output)))
X--- 5784,5791 ----
X  		   output calc-gnuplot-print-output)
X  	   (setq device (calc-graph-find-command "terminal")
X  		 output (calc-graph-find-command "output"))
X! 	   (or device
X! 	       (setq device calc-gnuplot-default-device))
X  	   (if output
X  	       (setq output (car (read-from-string output)))
X  	     (setq output calc-gnuplot-default-output)))
X***************
X*** 5717,5723 ****
X  			      "x11" "postscript")))
X  	 (if (stringp output)
X  	     (if (equal output "auto")
X! 		 (setq tempoutfile (make-temp-file "/tmp/calc")
X  		       output tempoutfile))
X  	   (setq output (eval output)))
X  	 (or (equal device calc-graph-last-device)
X--- 5795,5801 ----
X  			      "x11" "postscript")))
X  	 (if (stringp output)
X  	     (if (equal output "auto")
X! 		 (setq tempoutfile (make-temp-name "/tmp/calc")
X  		       output tempoutfile))
X  	   (setq output (eval output)))
X  	 (or (equal device calc-graph-last-device)
X***************
X*** 5778,5784 ****
X  		(yvalue (calc-var-value yvar))
X  		filename)
X  	   (delete-region (match-beginning 0) (match-end 0))
X! 	   (setq filename (make-temp-name calc-gnuplot-tempfile))
X  	   (save-excursion
X  	     (set-buffer calcbuf)
X  	     (let (tempbuftop
X--- 5856,5862 ----
X  		(yvalue (calc-var-value yvar))
X  		filename)
X  	   (delete-region (match-beginning 0) (match-end 0))
X! 	   (setq filename (calc-temp-file-name curve-num))
X  	   (save-excursion
X  	     (set-buffer calcbuf)
X  	     (let (tempbuftop
X***************
X*** 5788,5793 ****
X--- 5866,5872 ----
X  		   xvec xval xstep var-DUMMY
X  		   yvec yval ycache ycacheptr yvector
X  		   numsteps
X+ 		   (keep-file (file-exists-p filename))
X  		   (stepcount 0)
X  		   (calc-symbolic-mode nil)
X  		   (calc-prefer-frac nil)
X***************
X*** 5839,5845 ****
X  		   (if (and (not (setq xvec (eq (car-safe xvalue) 'vec)))
X  			    refine (cdr (cdr ycache)))
X  		       (progn
X! 			 (setq ycacheptr (cdr ycache))
X  			 (if (and
X  			      (setq xval (calc-graph-find-command "xrange"))
X  			      (string-match
X--- 5918,5925 ----
X  		   (if (and (not (setq xvec (eq (car-safe xvalue) 'vec)))
X  			    refine (cdr (cdr ycache)))
X  		       (progn
X! 			 (setq keep-file nil
X! 			       ycacheptr (cdr ycache))
X  			 (if (and
X  			      (setq xval (calc-graph-find-command "xrange"))
X  			      (string-match
X***************
X*** 5891,5897 ****
X  			   (progn
X  			     (setq xp (cdr xp)
X  				   xval (car xp))
X! 			     (and (consp (car ycacheptr))
X  				  (not (math-lessp (car (car ycacheptr)) xval))
X  				  (setq ycacheptr ycache)))
X  			 (if (= numsteps 0)
X--- 5971,5978 ----
X  			   (progn
X  			     (setq xp (cdr xp)
X  				   xval (car xp))
X! 			     (and (not (eq ycacheptr ycache))
X! 				  (consp (car ycacheptr))
X  				  (not (math-lessp (car (car ycacheptr)) xval))
X  				  (setq ycacheptr ycache)))
X  			 (if (= numsteps 0)
X***************
X*** 5904,5910 ****
X  		       (or (and (cdr ycacheptr)
X  				(math-equal (car (nth 1 ycacheptr)) xval))
X  			   (progn
X! 			     (setq var-DUMMY xval)
X  			     (setcdr ycacheptr (cons (cons xval
X  							   (math-evaluate-expr
X  							    yvalue))
X--- 5985,5992 ----
X  		       (or (and (cdr ycacheptr)
X  				(math-equal (car (nth 1 ycacheptr)) xval))
X  			   (progn
X! 			     (setq keep-file nil
X! 				   var-DUMMY xval)
X  			     (setcdr ycacheptr (cons (cons xval
X  							   (math-evaluate-expr
X  							    yvalue))
X***************
X*** 5925,5985 ****
X  		 (setq tempbuftop (point))
X  		 (let ((calc-group-digits nil)
X  		       (calc-leading-zeros nil)
X! 		       (calc-number-radix 10))
X! 		   (while (<= (setq stepcount (1+ stepcount)) numsteps)
X! 		     (if xvec
X! 			 (setq xp (cdr xp)
X! 			       xval (car xp)
X! 			       yp (cdr yp)
X! 			       yval (car yp))
X! 		       (if yvec
X! 			   (setq xval xvalue
X! 				 xvalue (math-add xvalue xstep)
X! 				 yp (cdr yp)
X! 				 yval (car yp))
X! 			 (setq xval (car (car yp))
X! 			       yval (cdr (car yp))
X! 			       yp (cdr yp))
X! 			 (if (or (not yp)
X! 				 (and xhigh (equal xval xhigh)))
X! 			     (setq numsteps 0))))
X! 		     (if (and (eq (car-safe yval) 'calcFunc-xy)
X! 			      (= (length yval) 3))
X! 			 (setq xval (nth 1 yval)
X! 			       yval (nth 2 yval)))
X! 		     (if (and (Math-realp xval)
X! 			      (Math-realp yval))
X! 			 (progn
X! 			   (setq blank nil
X! 				 non-blank t)
X! 			   (if (Math-integerp xval)
X! 			       (insert (math-format-number xval))
X! 			     (if (eq (car xval) 'frac)
X! 				 (setq xval (math-float xval)))
X! 			     (insert (math-format-number (nth 1 xval))
X! 				     "e" (int-to-string (nth 2 xval))))
X! 			   (insert " ")
X! 			   (if (Math-integerp yval)
X! 			       (insert (math-format-number yval))
X! 			     (if (eq (car yval) 'frac)
X! 				 (setq yval (math-float yval)))
X! 			     (insert (math-format-number (nth 1 yval))
X! 				     "e" (int-to-string (nth 2 yval))))
X! 			   (insert "\n"))
X! 		       (and (boundp 'var-PlotRejects)
X! 			    (eq (car-safe var-PlotRejects) 'vec)
X! 			    (nconc var-PlotRejects (list (list 'vec
X! 							       curve-num
X! 							       stepcount
X! 							       xval yval))))
X! 		       (or blank
X! 			   (progn
X! 			     (insert "\n")
X! 			     (setq blank t))))))
X! 		 (or non-blank
X! 		     (error "No valid data points for %s:%s" xname yname))
X! 		 (setq tempfiles (cons filename tempfiles))
X! 		 (write-region tempbuftop (point-max) filename nil 'quiet))))
X  	   (insert (prin1-to-string filename))))
X         (if (= curve-num 0)
X  	   (progn
X--- 6007,6077 ----
X  		 (setq tempbuftop (point))
X  		 (let ((calc-group-digits nil)
X  		       (calc-leading-zeros nil)
X! 		       (calc-number-radix 10)
X! 		       (entry (list xp yp xhigh numsteps)))
X! 		   (or (equal entry
X! 			      (nth 1 (nth curve-num calc-graph-file-cache)))
X! 		       (setq keep-file nil))
X! 		   (setcar (cdr (nth curve-num calc-graph-file-cache)) entry)
X! 		   (or keep-file
X! 		       (while (<= (setq stepcount (1+ stepcount)) numsteps)
X! 			 (if xvec
X! 			     (setq xp (cdr xp)
X! 				   xval (car xp)
X! 				   yp (cdr yp)
X! 				   yval (car yp))
X! 			   (if yvec
X! 			       (setq xval xvalue
X! 				     xvalue (math-add xvalue xstep)
X! 				     yp (cdr yp)
X! 				     yval (car yp))
X! 			     (setq xval (car (car yp))
X! 				   yval (cdr (car yp))
X! 				   yp (cdr yp))
X! 			     (if (or (not yp)
X! 				     (and xhigh (equal xval xhigh)))
X! 				 (setq numsteps 0))))
X! 			 (if (and (eq (car-safe yval) 'calcFunc-xy)
X! 				  (= (length yval) 3))
X! 			     (setq xval (nth 1 yval)
X! 				   yval (nth 2 yval)))
X! 			 (if (and (Math-realp xval)
X! 				  (Math-realp yval))
X! 			     (progn
X! 			       (setq blank nil
X! 				     non-blank t)
X! 			       (if (Math-integerp xval)
X! 				   (insert (math-format-number xval))
X! 				 (if (eq (car xval) 'frac)
X! 				     (setq xval (math-float xval)))
X! 				 (insert (math-format-number (nth 1 xval))
X! 					 "e" (int-to-string (nth 2 xval))))
X! 			       (insert " ")
X! 			       (if (Math-integerp yval)
X! 				   (insert (math-format-number yval))
X! 				 (if (eq (car yval) 'frac)
X! 				     (setq yval (math-float yval)))
X! 				 (insert (math-format-number (nth 1 yval))
X! 					 "e" (int-to-string (nth 2 yval))))
X! 			       (insert "\n"))
X! 			   (and (boundp 'var-PlotRejects)
X! 				(eq (car-safe var-PlotRejects) 'vec)
X! 				(nconc var-PlotRejects
X! 				       (list (list 'vec
X! 						   curve-num
X! 						   stepcount
X! 						   xval yval))))
X! 			   (or blank
X! 			       (progn
X! 				 (insert "\n")
X! 				 (setq blank t)))))))
X! 		 (or keep-file
X! 		     (progn
X! 		       (or non-blank
X! 			   (error "No valid data points for %s:%s"
X! 				  xname yname))
X! 		       (write-region tempbuftop (point-max) filename
X! 				     nil 'quiet))))))
X  	   (insert (prin1-to-string filename))))
X         (if (= curve-num 0)
X  	   (progn
X***************
X*** 5987,5993 ****
X  	     (message "No data to plot!"))
X  	 (setq calc-graph-data-cache-limit (max curve-num
X  						calc-graph-data-cache-limit)
X! 	       filename (make-temp-name calc-gnuplot-tempfile)
X  	       tempfiles (cons filename tempfiles))
X  	 (write-region (point-min) (point-max) filename nil 'quiet)
X  	 (calc-gnuplot-command "load" (prin1-to-string filename))
X--- 6079,6085 ----
X  	     (message "No data to plot!"))
X  	 (setq calc-graph-data-cache-limit (max curve-num
X  						calc-graph-data-cache-limit)
X! 	       filename (calc-temp-file-name 0)
X  	       tempfiles (cons filename tempfiles))
X  	 (write-region (point-min) (point-max) filename nil 'quiet)
X  	 (calc-gnuplot-command "load" (prin1-to-string filename))
X***************
X*** 6004,6009 ****
X--- 6096,6125 ----
X  	 (calc-gnuplot-command "! rm" (mapconcat 'identity tempfiles " "))))))
X  )
X  
X+ (defun calc-temp-file-name (num)
X+   (while (<= (length calc-graph-file-cache) num)
X+     (setq calc-graph-file-cache (nconc calc-graph-file-cache (list nil))))
X+   (car (or (nth num calc-graph-file-cache)
X+ 	   (setcar (nthcdr num calc-graph-file-cache)
X+ 		   (list (make-temp-name calc-gnuplot-tempfile) nil))))
X+ )
X+ 
X+ (defun calc-graph-delete-temps ()
X+   (while calc-graph-file-cache
X+     (and (car calc-graph-file-cache)
X+ 	 (file-exists-p (car (car calc-graph-file-cache)))
X+ 	 (condition-case err
X+ 	     (delete-file (car calc-graph-file-cache))
X+ 	   (error nil)))
X+     (setq calc-graph-file-cache (cdr calc-graph-file-cache)))
X+ )
X+ 
X+ (defun calc-graph-kill-hook ()
X+   (calc-graph-delete-temps)
X+   (if calc-graph-prev-kill-hook
X+       (funcall calc-graph-prev-kill-hook))
X+ )
X+ 
X  (defun calc-graph-clear ()
X    "Clear the graphics display.  In X11, remove the graphics window."
X    (interactive)
X***************
X*** 6378,6383 ****
X--- 6494,6500 ----
X  (defun calc-graph-kill ()
X    "Kill the current GNUPLOT process."
X    (interactive)
X+   (calc-graph-delete-temps)
X    (if (calc-gnuplot-alive)
X        (calc-wrapper
X         (calc-graph-view-trail)
X***************
X*** 7581,7587 ****
X       "Tranpose, Arrange, reVerse; rNorm"
X       "SHIFT + Det, & (inverse), LUD, Trace, conJtrn, Cross"
X       "SHIFT + Sort, Grade, Histogram; cNorm"
X!      "SHIFT + Reduce, Map, Apply, Inner-prod, Outer-prod"
X       "<, =, > (justification); , (commas); [, {, ( (brackets)"
X       ". (abbreviate); / (multi-lines)")
X     "vec/mat" ?v)
X--- 7698,7705 ----
X       "Tranpose, Arrange, reVerse; rNorm"
X       "SHIFT + Det, & (inverse), LUD, Trace, conJtrn, Cross"
X       "SHIFT + Sort, Grade, Histogram; cNorm"
X!      "SHIFT + Apply, Map, Reduce, accUm, Inner-, Outer-prod"
X!      "SHIFT + V (union), ^ (isect), - (diff), Xor, + (rdup)"
X       "<, =, > (justification); , (commas); [, {, ( (brackets)"
X       ". (abbreviate); / (multi-lines)")
X     "vec/mat" ?v)
X***************
X*** 7589,7598 ****
X  
X  (defun calc-concat (arg)
X    "Concatenate the two vectors at the top of the stack.
X! Or concatenate a scalar value and a vector."
X    (interactive "P")
X    (calc-wrapper
X!    (calc-binary-op "|" 'calcFunc-vconcat arg '(vec) nil '|))
X  )
X  
X  ;;;; [calc-mode.el]
X--- 7707,7727 ----
X  
X  (defun calc-concat (arg)
X    "Concatenate the two vectors at the top of the stack.
X! Or concatenate a scalar value and a vector.
X! Or concatenate a matrix and a vector (as a new row of the matrix).
X! With Hyperbolic flag, literally appends two vectors with no special cases."
X    (interactive "P")
X    (calc-wrapper
X!    (if (calc-is-hyperbolic)
X!        (calc-binary-op "apnd" 'calcFunc-append arg '(vec))
X!      (calc-binary-op "|" 'calcFunc-vconcat arg '(vec) nil '|)))
X! )
X! 
X! (defun calc-append (arg)
SHAR_EOF
echo "End of part 1, continue with part 2"
echo "2" > s2_seq_.tmp
exit 0
--
Dave Gillespie
  256-80 Caltech Pasadena CA USA 91125
  daveg@csvax.cs.caltech.edu, ...!cit-vax!daveg