v15i033: Patch for GNU Emacs Calc, version 1.04 -> 1.05, part 06/20
David Gillespie
daveg at csvax.cs.caltech.edu
Mon Oct 15 11:16:26 AEST 1990
Posting-number: Volume 15, Issue 33
Submitted-by: daveg at csvax.cs.caltech.edu (David Gillespie)
Archive-name: calc-1.05/part06
#!/bin/sh
# this is part 6 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file calc.patch continued
#
CurArch=6
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> calc.patch
X! "Not breaking long lines in Stack display.")))
X )
X
X+ ;;;; [calc-vec.el]
X+
X (defun calc-display-strings (n)
X "Toggle display of vectors of byte-sized integers as strings.
X With positive numeric prefix, turn mode on.
X***************
X*** 2484,2492 ****
X (setq calc-display-strings (if n
X (> (prefix-numeric-value n) 0)
X (not calc-display-strings)))
X! (calc-refresh))
X )
X
X (defun calc-left-justify ()
X "Display stack entries left-justified in the window."
X (interactive)
X--- 4852,4865 ----
X (setq calc-display-strings (if n
X (> (prefix-numeric-value n) 0)
X (not calc-display-strings)))
X! (calc-refresh)
X! (message (if calc-display-strings
X! "Displaying vectors of integers as quoted strings."
X! "Displaying vectors of integers normally.")))
X )
X
X+ ;;;; [calc-mode.el]
X+
X (defun calc-left-justify ()
X "Display stack entries left-justified in the window."
X (interactive)
X***************
X*** 2717,2723 ****
X (max 1 (calc-locate-cursor-element (point)))))
X (if (= newtop oldtop)
X ()
X! (calc-pop-stack 1 oldtop)
X (calc-push-list '(top-of-stack) newtop)
X (if calc-line-numbering
X (calc-refresh))))
X--- 5090,5096 ----
X (max 1 (calc-locate-cursor-element (point)))))
X (if (= newtop oldtop)
X ()
X! (calc-pop-stack 1 oldtop t)
X (calc-push-list '(top-of-stack) newtop)
X (if calc-line-numbering
X (calc-refresh))))
X***************
X*** 3107,3120 ****
X
X ;;;; [calc-ext.el]
X
X ;;; Combinatorics
X
X (defun calc-k-prefix-help ()
X (interactive)
X (calc-do-prefix-help
X! '("GCD, LCM; Binomial, Dbl-fact; Random, random-Again"
X "Factors, Prime-test, Next-prime, Totient, Moebius"
X! "SHIFT + extended-GCD")
X "combinatorics" ?k)
X )
X
X--- 5480,6557 ----
X
X ;;;; [calc-ext.el]
X
X+ ;;; Graphics
X+
X+ (defun calc-g-prefix-help ()
X+ (interactive)
X+ (calc-do-prefix-help
X+ '("Fast; Add, Delete, Juggle; Plot, Clear"
X+ "Header, Name, Grid, Key, Numpts"
X+ "View-commands, X-display"
X+ "x-axis: Range, Title, Log; lineStyle"
X+ "SHIFT + y-axis: Range, Title, Log; pointStyle"
X+ "SHIFT + Print; Device, Output-file; X-geometry"
X+ "SHIFT + Command, Kill, View-trail")
X+ "graph" ?g)
X+ )
X+
X+ (defvar calc-gnuplot-process nil)
X+
X+ ;;;; [calc-graph.el]
X+
X+ ;;; Note that some of the following initial values also occur in calc.el.
X+ (defvar calc-gnuplot-tempfile "/tmp/calc")
X+
X+ (defvar calc-gnuplot-default-device "default")
X+ (defvar calc-gnuplot-default-output "/dev/null")
X+ (defvar calc-gnuplot-print-device "postscript")
X+ (defvar calc-gnuplot-print-output "auto")
X+
X+ (defvar calc-gnuplot-display (getenv "DISPLAY"))
X+ (defvar calc-gnuplot-geometry nil)
X+
X+ (defvar calc-graph-default-resolution 15)
X+ (defvar calc-graph-default-precision 5)
X+
X+ (defvar calc-gnuplot-buffer nil)
X+ (defvar calc-gnuplot-input nil)
X+
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-var-cache nil)
X+ (defvar calc-graph-data-cache nil)
X+ (defvar calc-graph-data-cache-limit 10)
X+
X+ (defun calc-graph-fast (many)
X+ "Graph the two vectors or other x/y values on the top of the stack.
X+ This is shorthand for calc-graph-delete for all existing curves followed
X+ by calc-graph-add and calc-graph-plot."
X+ (interactive "P")
X+ (let ((calc-graph-no-auto-view t))
X+ (calc-graph-delete t)
X+ (calc-graph-add many)
X+ (calc-graph-plot nil))
X+ )
X+
X+ (defun calc-graph-delete (all)
X+ "Delete the most recently added curve from the current graph.
X+ With a numeric prefix argument, delete all curves from the graph."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-graph-init)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (and (calc-graph-find-plot t all)
X+ (progn
X+ (if (looking-at "plot")
X+ (progn
X+ (setq calc-graph-var-cache nil)
X+ (delete-region (point) (point-max)))
X+ (delete-region (point) (1- (point-max))))))
X+ (calc-graph-view-commands)))
X+ )
X+
X+ (defun calc-graph-find-plot (&optional before all)
X+ (goto-char (point-min))
X+ (and (re-search-forward "^plot[ \t]+" nil t)
X+ (let ((beg (point)))
X+ (goto-char (point-max))
X+ (if (or all
X+ (not (search-backward "," nil t))
X+ (< (point) beg))
X+ (progn
X+ (goto-char beg)
X+ (if before
X+ (beginning-of-line)))
X+ (or before
X+ (re-search-forward ",[ \t]+")))
X+ t))
X+ )
X+
X+ (defun calc-graph-add (many)
X+ "Add a curve to the current graph.
X+ The y data is taken from top of stack; the x data is taken from second-to-top.
X+ The x data may be a vector or an interval.
X+ The y data may be a vector or a formula in a single variable.
X+ Each may also be the name of a variable that contains a suitable value.
X+
X+ With any numeric prefix argument, the value on the top of the stack is
X+ a vector of y-data values, all of which are added (with the same common
X+ x data) as separate curves."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-graph-init)
X+ (let ((xdata (calc-graph-lookup (calc-top-n 2)))
X+ (ylist (calc-top-n 1))
X+ ydata)
X+ (if many
X+ (if (eq (car-safe ylist) 'vec)
X+ (setq ylist (cdr ylist))
X+ (error "Y argument must be a vector")))
X+ (while ylist
X+ (if many
X+ (setq ydata (calc-graph-lookup (car ylist))
X+ ylist (cdr ylist))
X+ (setq ydata (calc-graph-lookup ylist)
X+ ylist nil))
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (goto-char (point-min))
X+ (if (re-search-forward "^plot[ \t]" nil t)
X+ (progn
X+ (end-of-line)
X+ (insert ", "))
X+ (goto-char (point-max))
X+ (or (eq (preceding-char) ?\n)
X+ (insert "\n"))
X+ (insert "plot \n")
X+ (forward-char -1))
X+ (insert "{" (symbol-name (nth 1 xdata))
X+ ":" (symbol-name (nth 1 ydata)) "} "
X+ "title \"" (symbol-name (nth 1 ydata)) "\" "
X+ "with "
X+ (if (eq (car-safe (calc-var-value (nth 2 ydata))) 'vec)
X+ "linespoints"
X+ "lines")))))
X+ (calc-graph-view-commands))
X+ )
X+
X+ (defun calc-graph-lookup (thing)
X+ (if (and (eq (car-safe thing) 'var)
X+ (calc-var-value (nth 2 thing)))
X+ thing
X+ (let ((found (assoc thing calc-graph-var-cache)))
X+ (or found
X+ (progn
X+ (setq varname (concat "PlotData"
X+ (int-to-string
X+ (1+ (length calc-graph-var-cache))))
X+ var (list 'var (intern varname)
X+ (intern (concat "var-" varname)))
X+ found (cons thing var)
X+ calc-graph-var-cache (cons found calc-graph-var-cache))
X+ (set (nth 2 var) thing)))
X+ (cdr found)))
X+ )
X+
X+ (defun calc-graph-juggle ()
X+ "Move the last curve on the list to the front, exposing the next-to-last."
X+ (interactive)
X+ (calc-graph-init)
X+ (save-excursion
X+ (let (base)
X+ (set-buffer calc-gnuplot-input)
X+ (and (calc-graph-find-plot t t)
X+ (progn
X+ (setq base (point))
X+ (calc-graph-find-plot t nil)
X+ (or (eq base (point))
X+ (let ((str (buffer-substring (+ (point) 2) (1- (point-max)))))
X+ (delete-region (point) (1- (point-max)))
X+ (goto-char (+ base 5))
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+ "Draw a graph according to the current plotting parameters.
X+ Use calc-graph-add to add curves to the current graph.
X+ Use other calc-graph-... commands to set titles, styles, etc.
X+ A negative prefix argument forces recomputation of all curve data.
X+ A positive prefix argument causes existing data to be further refined."
X+ (interactive "P")
X+ (calc-slow-wrapper
X+ (let ((calcbuf (current-buffer))
X+ (tempbuf (get-buffer-create "*Gnuplot Temp-2*"))
X+ (tempbuftop 1)
X+ (tempfiles nil)
X+ (tempoutfile nil)
X+ (curve-num 0)
X+ (refine (and flag (> (prefix-numeric-value flag) 0)))
X+ (recompute (and flag (< (prefix-numeric-value flag) 0)))
X+ resolution precision samples-pos)
X+ (save-excursion
X+ (calc-graph-init)
X+ (set-buffer tempbuf)
X+ (erase-buffer)
X+ (set-buffer calc-gnuplot-input)
X+ (let ((str (buffer-string)))
X+ (set-buffer (get-buffer-create "*Gnuplot Temp*"))
X+ (erase-buffer)
X+ (insert "# (Note: This is a temporary copy---do not edit!)\n"
X+ "set noarrow\nset nolabel\n"
X+ "set autoscale xy\nset nologscale xy\n"
X+ "set xlabel\nset ylabel\nset title\n"
X+ "set noclip points\nset clip one\nset clip two\n"
X+ "set format \"%g\"\nset tics\nset xtics\nset ytics\n"
X+ "set data style linespoints\n"
X+ "set nogrid\nset nokey\nset nopolar\n")
X+ (setq samples-pos (point))
X+ (insert "\n\n" str))
X+ (let ((calc-gnuplot-input (current-buffer))
X+ (calc-graph-no-auto-view t)
X+ device output)
X+ (if printing
X+ (setq device calc-gnuplot-print-device
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+ (if (or (equal device "") (equal device "default"))
X+ (setq device (if (and (not printing)
X+ (getenv "DISPLAY"))
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+ (progn
X+ (setq calc-graph-last-device device)
X+ (calc-gnuplot-command "set terminal" device)))
X+ (or (equal output calc-graph-last-output)
X+ (progn
X+ (setq calc-graph-last-output output)
X+ (calc-gnuplot-command "set output" (prin1-to-string output))))
X+ (setq resolution (calc-graph-find-command "samples"))
X+ (if resolution
X+ (setq resolution (string-to-int resolution))
X+ (setq resolution calc-graph-default-resolution))
X+ (setq precision (calc-graph-find-command "precision"))
X+ (if precision
X+ (setq precision (string-to-int precision))
X+ (setq precision calc-graph-default-precision))
X+ (calc-graph-set-command "terminal")
X+ (calc-graph-set-command "output")
X+ (calc-graph-set-command "samples")
X+ (calc-graph-set-command "precision"))
X+ (and tempoutfile (setq tempfiles (cons tempoutfile tempfiles)))
X+ (goto-char samples-pos)
X+ (insert "set samples " (int-to-string (max 200 (+ 5 resolution))) "\n")
X+ (while (re-search-forward "{\\*[^}]+}[^,\n]*" nil t)
X+ (delete-region (match-beginning 0) (match-end 0))
X+ (if (looking-at ",")
X+ (delete-char 1)
X+ (while (memq (preceding-char) '(?\ ?\t))
X+ (forward-char -1))
X+ (if (eq (preceding-char) ?\,)
X+ (delete-backward-char 1))))
X+ (save-excursion
X+ (set-buffer calcbuf)
X+ (let ((cache-env (list calc-angle-mode
X+ calc-complex-mode
X+ calc-simplify-mode
X+ calc-word-size
X+ precision)))
X+ (if (and (not recompute)
X+ (equal (cdr (car calc-graph-data-cache)) cache-env))
X+ (while (> (length calc-graph-data-cache)
X+ calc-graph-data-cache-limit)
X+ (setcdr calc-graph-data-cache
X+ (cdr (cdr calc-graph-data-cache))))
X+ (setq calc-graph-data-cache (list (cons nil cache-env))))))
X+ (calc-graph-find-plot t t)
X+ (while (re-search-forward "{\\([^{}:\n]+\\):\\([^{}:\n]+\\)}" nil t)
X+ (setq curve-num (1+ curve-num))
X+ (let* ((xname (buffer-substring (match-beginning 1)
X+ (match-end 1)))
X+ (xvar (intern (concat "var-" xname)))
X+ (xvalue (calc-var-value xvar))
X+ (yname (buffer-substring (match-beginning 2)
X+ (match-end 2)))
X+ (yvar (intern (concat "var-" yname)))
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+ (xp xvalue)
X+ (yp yvalue)
X+ (xlow nil) (xhigh nil)
X+ xvec xval xstep var-DUMMY
X+ yvec yval ycache ycacheptr yvector
X+ numsteps
X+ (stepcount 0)
X+ (calc-symbolic-mode nil)
X+ (calc-prefer-frac nil)
X+ (calc-internal-prec (max 3 precision))
X+ (calc-simplify-mode (and (not (memq calc-simplify-mode
X+ '(none num)))
X+ calc-simplify-mode))
X+ (blank t)
X+ (non-blank nil))
X+ (save-excursion
X+ (if (setq yvec (eq (car-safe yvalue) 'vec))
X+ (if (= (setq numsteps (1- (length yvalue))) 0)
X+ (error "Can't plot an empty vector")
X+ (if (setq xvec (eq (car-safe xvalue) 'vec))
X+ (or (= (1- (length xvalue)) numsteps)
X+ (error "%s and %s have different lengths"
X+ xname yname))
X+ (if (eq (car-safe xvalue) 'intv)
X+ (setq xstep (math-div (math-sub (nth 3 xvalue)
X+ (nth 2 xvalue))
X+ (1- numsteps))
X+ xvalue (nth 2 xvalue))
X+ (if (math-realp xvalue)
X+ (setq xstep 1)
X+ (error "%s is not a suitable basis for %s"
X+ xname yname)))))
X+ (or (math-realp yvalue)
X+ (let ((arglist nil))
X+ (setq yvalue (math-evaluate-expr yvalue))
X+ (calc-default-formula-arglist yvalue)
X+ (or arglist
X+ (error "%s does not contain any unassigned variables"
X+ yname))
X+ (and (cdr arglist)
X+ (error "%s contains several variables: %s"
X+ yname arglist))
X+ (setq yvalue (math-expr-subst
X+ yvalue
X+ (list 'var
X+ (car arglist)
X+ (intern (concat "var-"
X+ (symbol-name
X+ (car arglist)))))
X+ '(var DUMMY var-DUMMY)))))
X+ (setq ycache (assoc yvalue calc-graph-data-cache))
X+ (delq ycache calc-graph-data-cache)
X+ (nconc calc-graph-data-cache
X+ (list (or ycache (setq ycache (list yvalue)))))
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+ "\\`\\[\\([0-9.eE+-]*\\):\\([0-9.eE+-]*\\)\\]\\'"
X+ xval))
X+ (let ((b2 (match-beginning 2))
X+ (e2 (match-end 2)))
X+ (setq xlow (math-read-number
X+ (substring xval
X+ (match-beginning 1)
X+ (match-end 1)))
X+ xhigh (math-read-number
X+ (substring xval b2 e2))))
X+ (if xlow
X+ (while (and (cdr ycacheptr)
X+ (math-lessp (car (nth 1 ycacheptr))
X+ xlow))
X+ (setq ycacheptr (cdr ycacheptr)))))
X+ (while (and (cdr ycacheptr)
X+ (or (not xhigh)
X+ (math-lessp (car (car ycacheptr))
X+ xhigh)))
X+ (setq var-DUMMY (math-div
X+ (math-add (car (car ycacheptr))
X+ (car (nth 1 ycacheptr)))
X+ 2)
X+ yval (math-evaluate-expr yvalue))
X+ (setcdr ycacheptr (cons (cons var-DUMMY yval)
X+ (cdr ycacheptr)))
X+ (setq ycacheptr (cdr (cdr ycacheptr))))
X+ (setq yp ycache
X+ numsteps 1000000))
X+ (setq ycacheptr ycache)
X+ (if xvec
X+ (setq numsteps (1- (length xvalue))
X+ yvector nil)
X+ (if (eq (car-safe xvalue) 'intv)
X+ (setq numsteps resolution
X+ yp nil
X+ xlow (nth 2 xvalue)
X+ xhigh (nth 3 xvalue)
X+ xstep (math-div (math-sub xhigh xlow)
X+ (1- numsteps))
X+ xvalue (nth 2 xvalue))
X+ (error "%s is not a suitable basis for %s"
X+ xname yname)))
X+ (while (>= (setq numsteps (1- numsteps)) 0)
X+ (if xvec
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+ (setq xval xhigh) ; avoid cumulative roundoff
X+ (setq xval xvalue
X+ xvalue (math-add xvalue xstep))))
X+ (while (and (cdr ycacheptr)
X+ (math-lessp (car (nth 1 ycacheptr)) xval))
X+ (setq ycacheptr (cdr ycacheptr)))
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+ (cdr ycacheptr)))))
X+ (setq ycacheptr (cdr ycacheptr))
X+ (if xvec
X+ (setq yvector (cons (cdr (car ycacheptr)) yvector))
X+ (or yp (setq yp ycacheptr))))
X+ (if xvec
X+ (setq xp xvalue
X+ yvec t
X+ yp (cons 'vec (nreverse yvector))
X+ numsteps (1- (length xp)))
X+ (setq numsteps 1000000))))
X+ (set-buffer tempbuf)
X+ (goto-char (point-max))
X+ (insert "\n" xname ":" yname "\n\n")
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+ (calc-gnuplot-command "clear")
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+ (let ((command (if printing
X+ calc-gnuplot-print-command
X+ calc-gnuplot-plot-command)))
X+ (if command
X+ (if (stringp command)
X+ (calc-gnuplot-command
X+ "!" (format command
X+ (or tempoutfile
X+ calc-gnuplot-print-output)))
X+ (eval command))))
X+ (calc-gnuplot-command "! rm" (mapconcat 'identity tempfiles " "))))))
X+ )
X+
X+ (defun calc-graph-clear ()
X+ "Clear the graphics display. In X11, remove the graphics window."
X+ (interactive)
X+ (if (or (equal calc-graph-last-device "x11")
X+ (equal calc-graph-last-device "X11"))
X+ (calc-gnuplot-command "set output"
X+ (prin1-to-string calc-graph-last-output))
X+ (calc-gnuplot-command "clear"))
X+ )
X+
X+ (defun calc-graph-title-x (title)
X+ "Specify the title for the x-axis of the graph."
X+ (interactive "sX axis title: ")
X+ (calc-graph-set-command "xlabel" (if (not (equal title ""))
X+ (prin1-to-string title)))
X+ )
X+
X+ (defun calc-graph-title-y (title)
X+ "Specify the title for the y-axis of the graph."
X+ (interactive "sY axis title: ")
X+ (calc-graph-set-command "ylabel" (if (not (equal title ""))
X+ (prin1-to-string title)))
X+ )
X+
X+ (defun calc-graph-range-x (range)
X+ "Enter the range of values on the x-axis of the graph: \"min:max\".
X+ Enter a blank line for auto-scaling of the x-axis.
X+ Enter \"$\" to pull the range from top-of-stack as an interval or 2-vector."
X+ (interactive "sX axis range: ")
X+ (calc-graph-set-range "xrange" range)
X+ )
X+
X+ (defun calc-graph-range-y (range)
X+ "Enter the range of values on the y-axis of the graph: \"min:max\".
X+ Enter a blank line for auto-scaling of the y-axis.
X+ Enter \"$\" to pull the range from top-of-stack as an interval or 2-vector."
X+ (interactive "sY axis range: ")
X+ (calc-graph-set-range "yrange" range)
X+ )
X+
X+ (defun calc-graph-set-range (cmd range)
X+ (if (equal range "$")
X+ (calc-wrapper
X+ (let ((val (calc-top-n 1)))
X+ (if (eq (car-safe val) 'intv)
X+ (setq range (concat
X+ (math-format-number (math-float (nth 2 val))) ":"
X+ (math-format-number (math-float (nth 3 val)))))
X+ (if (and (eq (car-safe val) 'vec)
X+ (= (length val) 3))
X+ (setq range (concat
X+ (math-format-number (math-float (nth 1 val))) ":"
X+ (math-format-number (math-float (nth 2 val)))))
X+ (error "Range specification must be an interval or 2-vector")))
X+ (calc-pop-stack 1))))
X+ (if (string-match "\\[.+\\]" range)
X+ (setq range (substring range 1 -1)))
X+ (if (and (not (string-match ":" range))
X+ (or (string-match "," range)
X+ (string-match " " range)))
X+ (aset range (match-beginning 0) ?\:))
X+ (calc-graph-set-command cmd (if (not (equal range ""))
X+ (concat "[" range "]")))
X+ )
X+
X+ (defun calc-graph-log-x (flag)
X+ "Toggle whether the x-axis uses a logarithmic scale.
X+ With a numeric prefix argument, turn it on if positive, off if negative."
X+ (interactive "P")
X+ (calc-graph-set-log flag 0)
X+ )
X+
X+ (defun calc-graph-log-y (flag)
X+ "Toggle whether the y-axis uses a logarithmic scale.
X+ With a numeric prefix argument, turn it on if positive, off if negative."
X+ (interactive "P")
X+ (calc-graph-set-log 0 flag)
X+ )
X+
X+ (defun calc-graph-set-log (xflag yflag)
X+ (let* ((old (or (calc-graph-find-command "logscale") ""))
X+ (xold (string-match "x" old))
X+ (yold (string-match "y" old))
X+ str)
X+ (setq str (concat (if (if xflag
X+ (if (eq xflag 0) xold
X+ (> (prefix-numeric-value xflag)))
X+ (not xold)) "x" "")
X+ (if (if yflag
X+ (if (eq yflag 0) yold
X+ (> (prefix-numeric-value yflag)))
X+ (not yold)) "y" "")))
X+ (calc-graph-set-command "logscale" (if (not (equal str "")) str)))
X+ )
X+
X+ (defun calc-graph-line-style (style)
X+ "Toggle lines connecting data points, or set line style.
X+ This applies to the most recently added curve in the graph.
X+ Normally, turn lines on or off without affecting current style.
X+ With a numeric prefix argument, turn lines on and set the style number."
X+ (interactive "P")
X+ (calc-graph-set-styles style t)
X+ )
X+
X+ (defun calc-graph-point-style (style)
X+ "Toggle points on the data points, or set point style.
X+ This applies to the most recently added curve in the graph.
X+ Normally, turn points on or off without affecting current style.
X+ With a numeric prefix argument, turn points on and set the style number."
X+ (interactive "P")
X+ (calc-graph-set-styles t style)
X+ )
X+
X+ (defun calc-graph-set-styles (lines points)
X+ (calc-graph-init)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (or (calc-graph-find-plot nil nil)
X+ (error "No data points have been set!"))
X+ (let ((base (point))
X+ (mode nil) (lstyle nil) (pstyle nil)
X+ start end lenbl penbl)
X+ (re-search-forward "[,\n]")
X+ (forward-char -1)
X+ (setq end (point) start end)
X+ (goto-char base)
X+ (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+with\\)")
X+ (progn
X+ (setq start (match-beginning 1))
X+ (goto-char (match-end 0))
X+ (if (looking-at "[ \t]+\\([a-z]+\\)")
X+ (setq mode (buffer-substring (match-beginning 1)
X+ (match-end 1))))
X+ (if (looking-at "[ \ta-z]+\\([0-9]+\\)")
X+ (setq lstyle (string-to-int
X+ (buffer-substring (match-beginning 1)
X+ (match-end 1)))))
X+ (if (looking-at "[ \ta-z]+[0-9]+[ \t]+\\([0-9]+\\)")
X+ (setq pstyle (string-to-int
X+ (buffer-substring (match-beginning 1)
X+ (match-end 1)))))))
X+ (setq lenbl (or (equal mode "lines") (equal mode "linespoints"))
X+ penbl (or (equal mode "points") (equal mode "linespoints")))
X+ (if lines
X+ (or (eq lines t)
X+ (setq lstyle lines
X+ lenbl t))
X+ (setq lenbl (not lenbl)))
X+ (if points
X+ (or (eq points t)
X+ (setq pstyle points
X+ penbl t))
X+ (setq penbl (not penbl)))
X+ (delete-region start end)
X+ (goto-char start)
X+ (insert " with "
X+ (if lenbl
X+ (if penbl "linespoints" "lines")
X+ (if penbl "points" "dots")))
X+ (if (and pstyle (> pstyle 0))
X+ (insert " " (if (and lstyle (> lstyle 0)) (int-to-string lstyle) "1")
X+ " " (int-to-string pstyle))
X+ (if (and lstyle (> lstyle 0))
X+ (insert " " (int-to-string lstyle))))))
X+ (calc-graph-view-commands)
X+ )
X+
X+ (defun calc-graph-name (name)
X+ "Specify the title for the most recently added curve in the graph."
X+ (interactive "sTitle for current curve: ")
X+ (calc-graph-init)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (or (calc-graph-find-plot nil nil)
X+ (error "No data points have been set!"))
X+ (let ((base (point))
X+ start)
X+ (re-search-forward "[,\n]\\|[ \t]+with")
X+ (setq end (match-beginning 0))
X+ (goto-char base)
X+ (if (looking-at "[^,\n]*[^,\n \t]\\([ \t]+title\\)")
X+ (progn
X+ (goto-char (match-beginning 1))
X+ (delete-region (point) end))
X+ (goto-char end))
X+ (insert " title " (prin1-to-string name))))
X+ (calc-graph-view-commands)
X+ )
X+
X+ (defun calc-graph-hide (flag)
X+ "Hide or unhide the most recently added curve in the graph."
X+ (interactive "P")
X+ (calc-graph-init)
X+ (and (calc-graph-find-plot nil nil)
X+ (progn
X+ (or (looking-at "{")
X+ (error "Can't hide this curve (wrong format)"))
X+ (forward-char 1)
X+ (if (looking-at "*")
X+ (if (or (null flag) (<= (prefix-numeric-value flag) 0))
X+ (delete-char 1))
X+ (if (or (null flag) (> (prefix-numeric-value flag) 0))
X+ (insert "*")))))
X+ )
X+
X+ (defun calc-graph-header (title)
X+ "Specify the title for the entire graph."
X+ (interactive "sTitle for entire graph: ")
X+ (calc-graph-set-command "title" (if (not (equal title ""))
X+ (prin1-to-string title)))
X+ )
X+
X+ (defun calc-graph-grid (flag)
X+ "Toggle the grid (as opposed to plain tick marks) on and off.
X+ With a numeric prefix argument, turn it on if positive, off if negative."
X+ (interactive "P")
X+ (calc-graph-set-command "grid" (and (if flag
X+ (> (prefix-numeric-value flag) 0)
X+ (not (calc-graph-find-command "grid")))
X+ " "))
X+ )
X+
X+ (defun calc-graph-key (flag)
X+ "Toggle the key (legend of curves vs. line styles) on and off.
X+ With a numeric prefix argument, turn it on if positive, off if negative."
X+ (interactive "P")
X+ (calc-graph-set-command "key" (and (if flag
X+ (> (prefix-numeric-value flag) 0)
X+ (not (calc-graph-find-command "key")))
X+ " "))
X+ )
X+
X+ (defun calc-graph-num-points (res flag)
X+ "Specify the number of data points to use when plotting functions.
X+ If you enter a blank line, the resolution reverts to the default.
X+
X+ With a numeric prefix argument, set the default number of data points.
X+ In this case, a blank entry displays the current setting."
X+ (interactive "sNumber of data points: \nP")
X+ (if flag
X+ (if (equal res "")
X+ (message "Default resolution is %d." calc-graph-default-resolution)
X+ (setq calc-graph-default-resolution (string-to-int res)))
X+ (calc-graph-set-command "samples" (if (not (equal res "")) res)))
X+ )
X+
X+ (defun calc-graph-device (name flag)
X+ "Set the GNUPLOT device name to use for this plot.
X+ If you enter a blank line, the device name reverts to the default.
X+ If you enter \"?\", you are given a list of possible device names.
X+
X+ With a positive numeric prefix, you set the default device name.
X+ With a negative numeric prefix, you set the printer device name.
X+ In these cases, a blank entry displays the current setting.
X+
X+ The default device may be \"default\"; this will use \"x11\" if the
X+ X window system is available, else \"postscript\"."
X+ (interactive "sDevice name: \nP")
X+ (if (equal name "?")
X+ (progn
X+ (calc-gnuplot-command "set terminal")
X+ (calc-graph-view-trail))
X+ (if flag
X+ (if (> (prefix-numeric-value flag) 0)
X+ (if (equal name "")
X+ (message "Default GNUPLOT device is \"%s\"."
X+ calc-gnuplot-default-device)
X+ (setq calc-gnuplot-default-device name))
X+ (if (equal name "")
X+ (message "GNUPLOT device for Print command is \"%s\"."
X+ calc-gnuplot-print-device)
X+ (setq calc-gnuplot-print-device name)))
X+ (calc-graph-set-command "terminal" (if (not (equal name ""))
X+ name))))
X+ )
X+
X+ (defun calc-graph-output (name flag)
X+ "Set the GNUPLOT output file name to use for this plot.
X+ If you enter a blank line, the output file name reverts to the default.
X+
X+ With a positive numeric prefix, you set the default output file name.
X+ With a negative numeric prefix, you set the printer output file name.
X+ In these cases, a blank entry displays the current setting.
X+
X+ The default and/oor printer file may be \"auto\"; this will generate a random
X+ file name on the fly for each calc-graph-plot or calc-graph-print command."
X+ (interactive "sOutput file name: \nP")
X+ (if flag
X+ (if (> (prefix-numeric-value flag) 0)
X+ (if (equal name "")
X+ (message "Default GNUPLOT output file is \"%s\"."
X+ calc-gnuplot-default-output)
X+ (setq calc-gnuplot-default-output name))
X+ (if (equal name "")
X+ (message "GNUPLOT output file for Print command is \"%s\"."
X+ calc-gnuplot-print-output)
X+ (setq calc-gnuplot-print-output name)))
X+ (calc-graph-set-command "output" (if (not (equal name ""))
X+ (prin1-to-string name))))
X+ )
X+
X+ (defun calc-graph-display (name)
X+ "Set the X display to be used with GNUPLOT.
X+ Enter a blank line to see the current display name.
X+ This has no effect unless the X window system is being used."
X+ (interactive "sX display name: ")
X+ (if (equal name "")
X+ (message "Current X display is \"%s\"."
X+ (or calc-gnuplot-display "<none>"))
X+ (setq calc-gnuplot-display name)
X+ (if (calc-gnuplot-alive)
X+ (calc-gnuplot-command "exit")))
X+ )
X+
X+ (defun calc-graph-geometry (name)
X+ "Set the X geometry specification to be used with GNUPLOT.
X+ Enter a blank line to see the current geometry specification.
X+ This has no effect unless the X window system is being used."
X+ (interactive "sX geometry spec (or \"default\"): ")
X+ (if (equal name "")
X+ (message "Current X geometry is \"%s\"."
X+ (or calc-gnuplot-geometry "default"))
X+ (setq calc-gnuplot-geometry (and (not (equal name "default")) name))
X+ (if (calc-gnuplot-alive)
X+ (calc-gnuplot-command "exit")))
X+ )
X+
X+ (defun calc-graph-find-command (cmd)
X+ (calc-graph-init)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (goto-char (point-min))
X+ (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t]*\\(.*\\)$") nil t)
X+ (buffer-substring (match-beginning 1) (match-end 1))))
X+ )
X+
X+ (defun calc-graph-set-command (cmd &rest args)
X+ (calc-graph-init)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (goto-char (point-min))
X+ (if (re-search-forward (concat "^set[ \t]+" cmd "[ \t\n]") nil t)
X+ (progn
X+ (forward-char -1)
X+ (end-of-line)
X+ (let ((end (point)))
X+ (beginning-of-line)
X+ (delete-region (point) (1+ end))))
X+ (if (calc-graph-find-plot t t)
X+ (if (eq (preceding-char) ?\n)
X+ (forward-char -1))
X+ (goto-char (1- (point-max)))))
X+ (if (and args (car args))
X+ (progn
X+ (or (bolp)
X+ (insert "\n"))
X+ (insert "set " (mapconcat 'identity (cons cmd args) " ") "\n"))))
X+ (calc-graph-view-commands)
X+ )
X+
X+ (defun calc-graph-command (cmd)
X+ "Send an arbitrary command to the current GNUPLOT process."
X+ (interactive "sGNUPLOT command: ")
X+ (calc-wrapper
X+ (calc-graph-init)
X+ (calc-graph-view-trail)
X+ (calc-gnuplot-command cmd)
X+ (accept-process-output)
X+ (calc-graph-view-trail))
X+ )
X+
X+ (defun calc-graph-kill ()
X+ "Kill the current GNUPLOT process."
X+ (interactive)
X+ (if (calc-gnuplot-alive)
X+ (calc-wrapper
X+ (calc-graph-view-trail)
X+ (let ((calc-graph-no-wait t))
X+ (calc-gnuplot-command "exit"))
X+ (sit-for 1)
X+ (if (process-status calc-gnuplot-process)
X+ (delete-process calc-gnuplot-process))
X+ (setq calc-gnuplot-process nil)))
X+ )
X+
X+ (defun calc-graph-view-commands (&optional no-need)
X+ "Display the current GNUPLOT input commands in another window."
X+ (interactive "p")
X+ (or calc-graph-no-auto-view (calc-graph-init-buffers))
X+ (calc-graph-view calc-gnuplot-input calc-gnuplot-buffer (null no-need))
X+ )
X+
X+ (defun calc-graph-view-trail (&optional no-need)
X+ "Display the GNUPLOT session transcript in another window."
X+ (interactive "p")
X+ (or calc-graph-no-auto-view (calc-graph-init-buffers))
X+ (calc-graph-view calc-gnuplot-buffer calc-gnuplot-input (null no-need))
X+ )
X+
X+ (defun calc-graph-view (buf other-buf need)
X+ (let (win)
X+ (or calc-graph-no-auto-view
X+ (if (setq win (get-buffer-window buf))
X+ (or need
X+ (and (eq buf calc-gnuplot-buffer)
X+ (save-excursion
X+ (set-buffer buf)
X+ (not (pos-visible-in-window-p (point-max) win))))
X+ (progn
X+ (bury-buffer buf)
X+ (bury-buffer other-buf)
X+ (let ((curwin (selected-window)))
X+ (select-window win)
X+ (switch-to-buffer nil)
X+ (select-window curwin))))
X+ (if (setq win (get-buffer-window other-buf))
X+ (set-window-buffer win buf)
X+ (if (eq major-mode 'calc-mode)
X+ (if (or need
X+ (< (window-height) (1- (screen-height))))
X+ (display-buffer buf))
X+ (switch-to-buffer buf)))))
X+ (save-excursion
X+ (set-buffer buf)
X+ (if (and (eq buf calc-gnuplot-buffer)
X+ (setq win (get-buffer-window buf))
X+ (not (pos-visible-in-window-p (point-max) win)))
X+ (progn
X+ (goto-char (point-max))
X+ (vertical-motion (- 6 (window-height win)))
X+ (set-window-start win (point))
X+ (goto-char (point-max)))))
X+ (or calc-graph-no-auto-view (sit-for 0)))
X+ )
X+ (setq calc-graph-no-auto-view nil)
X+
X+ (defun calc-gnuplot-check-for-errors ()
X+ (if (save-excursion
X+ (prog2
X+ (progn
X+ (set-buffer calc-gnuplot-buffer)
X+ (goto-char calc-gnuplot-last-error-pos))
X+ (re-search-forward "^[ \t]" nil t)
X+ (goto-char (point-max))
X+ (setq calc-gnuplot-last-error-pos (point-max))))
X+ (calc-graph-view-trail))
X+ )
X+
X+ (defun calc-gnuplot-command (&rest args)
X+ (calc-graph-init)
X+ (let ((cmd (concat (mapconcat 'identity args " ") "\n")))
X+ (accept-process-output)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-buffer)
X+ (calc-gnuplot-check-for-errors)
X+ (goto-char (point-max))
X+ (insert cmd)
X+ (set-marker (process-mark calc-gnuplot-process) (point))
X+ (process-send-string calc-gnuplot-process cmd)
X+ (if (get-buffer-window calc-gnuplot-buffer)
X+ (calc-graph-view-trail))
X+ (accept-process-output (and (not calc-graph-no-wait)
X+ calc-gnuplot-process))
X+ (calc-gnuplot-check-for-errors)
X+ (if (get-buffer-window calc-gnuplot-buffer)
X+ (calc-graph-view-trail))))
X+ )
X+ (setq calc-graph-no-wait nil)
X+
X+ (defun calc-graph-init-buffers ()
X+ (or (and calc-gnuplot-buffer
X+ (buffer-name calc-gnuplot-buffer))
X+ (setq calc-gnuplot-buffer (get-buffer-create "*Gnuplot Trail*")))
X+ (or (and calc-gnuplot-input
X+ (buffer-name calc-gnuplot-input))
X+ (setq calc-gnuplot-input (get-buffer-create "*Gnuplot Commands*")))
X+ )
X+
X+ (defun calc-graph-init ()
X+ (or (calc-gnuplot-alive)
X+ (progn
X+ (if calc-gnuplot-process
X+ (progn
X+ (delete-process calc-gnuplot-process)
X+ (setq calc-gnuplot-process nil)))
X+ (calc-graph-init-buffers)
X+ (save-excursion
X+ (set-buffer calc-gnuplot-buffer)
X+ (insert "\nStarting gnuplot...\n"))
X+ (setq calc-graph-last-device nil)
X+ (setq calc-graph-last-output nil)
X+ (condition-case err
X+ (let ((args (append (and calc-gnuplot-display
X+ (not (equal calc-gnuplot-display
X+ (getenv "DISPLAY")))
X+ (list "-display"
X+ calc-gnuplot-display))
X+ (and calc-gnuplot-geometry
X+ (list "-geometry"
X+ calc-gnuplot-geometry)))))
X+ (setq calc-gnuplot-process
X+ (apply 'start-process
X+ "gnuplot"
X+ calc-gnuplot-buffer
X+ calc-gnuplot-name
X+ args))
X+ (process-kill-without-query calc-gnuplot-process))
X+ (file-error
X+ (error "Sorry, can't find \"%s\" on your system."
X+ calc-gnuplot-name)))))
X+ (save-excursion
X+ (set-buffer calc-gnuplot-input)
X+ (if (= (buffer-size) 0)
X+ (insert "# Commands for running gnuplot\n\n\n")
X+ (or calc-graph-no-auto-view
X+ (eq (char-after (1- (point-max))) ?\n)
X+ (progn
X+ (goto-char (point-max))
X+ (insert "\n")))))
X+ )
X+
X+ ;;;; [calc-ext.el]
X+
X+ (defun calc-gnuplot-alive ()
X+ (and calc-gnuplot-process
X+ calc-gnuplot-buffer
X+ (buffer-name calc-gnuplot-buffer)
X+ calc-gnuplot-input
X+ (buffer-name calc-gnuplot-input)
X+ (memq (process-status calc-gnuplot-process) '(run stop)))
X+ )
X+
X+
X+
X+
X+
X ;;; Combinatorics
X
X (defun calc-k-prefix-help ()
X (interactive)
X (calc-do-prefix-help
X! '("GCD, LCM; Choose (binomial), Double-factorial"
X! "Random, random-Again, sHuffle"
X "Factors, Prime-test, Next-prime, Totient, Moebius"
X! "Bernoulli, Euler, Stirling"
X! "SHIFT + Extended-gcd"
X! "SHIFT + dists: Binomial, Chi-square, F, Normal"
X! "SHIFT + dists: Poisson, student's-T")
X "combinatorics" ?k)
X )
X
X***************
X*** 3197,3212 ****
X "Produce a random integer between 0 (inclusive) and N (exclusive).
X N is the numeric prefix argument, if any, otherwise it is taken from the stack.
X If N is real, produce a random real number in the specified range.
X! If N is zero, produce a Gaussian-distributed value with mean 0, variance 1."
X (interactive "P")
X (calc-slow-wrapper
X (if n
X (calc-enter-result 0 "rand" (list 'calcFunc-random
X! (setq calc-last-random-limit
X! (prefix-numeric-value n))))
X (calc-enter-result 1 "rand" (list 'calcFunc-random
X! (setq calc-last-random-limit
X! (calc-top-n 1))))))
X )
X
X (defun calc-rrandom ()
X--- 6634,6659 ----
X "Produce a random integer between 0 (inclusive) and N (exclusive).
X N is the numeric prefix argument, if any, otherwise it is taken from the stack.
X If N is real, produce a random real number in the specified range.
X! If N is 0.0, produce a Gaussian-distributed value with mean 0, std dev 1.
X! If N is M +/- S, produce a Gaussian-distributed value with mean M, std dev S.
X! If N is an interval form, produce a random number in the interval.
X! If N is a vector, pick an element of the vector at random.
X! If N is the integer 0, reuse the previous value of N."
X (interactive "P")
X (calc-slow-wrapper
X (if n
X (calc-enter-result 0 "rand" (list 'calcFunc-random
X! (calc-get-random-limit
X! (prefix-numeric-value n))))
X (calc-enter-result 1 "rand" (list 'calcFunc-random
X! (calc-get-random-limit
X! (calc-top-n 1))))))
X! )
X!
X! (defun calc-get-random-limit (val)
X! (if (eq val 0)
X! calc-last-random-limit
X! (setq calc-last-random-limit val))
X )
X
X (defun calc-rrandom ()
X***************
X*** 3217,3229 ****
X (calc-enter-result 0 "rand" (list 'calcFunc-random '(float 1 0))))
X )
X
X! (defun calc-random-again ()
X "Produce another random number in the same range as the last one generated."
X! (interactive)
X (calc-slow-wrapper
X! (calc-enter-result 0 "rand" (list 'calcFunc-random calc-last-random-limit)))
X )
X
X (defun calc-report-prime-test (res)
X (cond ((eq (car res) t)
X (calc-record-message "prim" "Prime (guaranteed)"))
X--- 6664,6694 ----
X (calc-enter-result 0 "rand" (list 'calcFunc-random '(float 1 0))))
X )
X
X! (defun calc-random-again (arg)
X "Produce another random number in the same range as the last one generated."
X! (interactive "p")
X (calc-slow-wrapper
X! (while (>= (setq arg (1- arg)) 0)
X! (calc-enter-result 0 "rand" (list 'calcFunc-random
X! calc-last-random-limit))))
X )
X
X+ (defun calc-shuffle (n)
X+ "Produce a random selection of N items from the set M without duplicates.
X+ M may take any of the argument formats supported by calc-random."
X+ (interactive "P")
X+ (calc-slow-wrapper
X+ (if n
X+ (calc-enter-result 1 "shuf" (list 'calcFunc-shuffle
X+ (prefix-numeric-value n)
X+ (calc-get-random-limit
X+ (calc-top-n 1))))
X+ (calc-enter-result 2 "shuf" (list 'calcFunc-shuffle
X+ (calc-top-n 1)
X+ (calc-get-random-limit
X+ (calc-top-n 2))))))
X+ )
X+
X (defun calc-report-prime-test (res)
X (cond ((eq (car res) t)
X (calc-record-message "prim" "Prime (guaranteed)"))
X***************
X*** 3321,3327 ****
X (interactive)
X (calc-do-prefix-help
X '("Deg, Rad, HMS; Frac; Polar; Algebraic; Symbolic"
X! "Working; Xtensions; M=save"
X "SHIFT + simplify: Off, Num, Default, Bin-clip, Alg, Units")
X "mode" ?m)
X )
X--- 6786,6793 ----
X (interactive)
X (calc-do-prefix-help
X '("Deg, Rad, HMS; Frac; Polar; Algebraic; Symbolic"
X! "Working; Xtensions; Mode-save"
X! "SHIFT + Shifted-prefixes"
X "SHIFT + simplify: Off, Num, Default, Bin-clip, Alg, Units")
X "mode" ?m)
X )
X***************
X*** 3371,3382 ****
X (save-buffer)))
X )
X
X! (defun calc-algebraic-mode ()
X "Turn Algebraic mode on or off.
X! In algebraic mode, numeric entry accepts whole expressions without needing \"'\"."
X! (interactive)
X (calc-wrapper
X! (setq calc-algebraic-mode (not calc-algebraic-mode)))
X )
X
X (defun calc-symbolic-mode ()
X--- 6837,6869 ----
X (save-buffer)))
X )
X
X! (defun calc-shift-prefix ()
X! "Turn shifted prefixes mode on or off.
X! In this mode, the prefix keys A, B, D, F, G, J, K, and M can be used shifted
X! as well as unshifted. The commands that are normally bound to those
X! shifted letters, e.g., D for reDo, now use doubled keystrokes: DD = reDo.
X! Note that V always has this property, and C, T, U, and Z never do."
X! (interactive)
X! (calc-wrapper
X! (setq calc-shift-prefix (not calc-shift-prefix))
X! (calc-init-prefixes)
X! (message (if calc-shift-prefix
X! "Prefix keys A, B, D, F, G, J, K, M, V are now case-insensitive"
X! "Prefix keys must be unshifted (except V, Z)")))
X! )
X!
X! (defun calc-algebraic-mode (flag)
X "Turn Algebraic mode on or off.
X! In algebraic mode, numeric entry accepts whole expressions without needing \"'\".
X! With a numeric prefix argument, sets algebraic mode for [ and ( keys only."
X! (interactive "P")
X (calc-wrapper
X! (if flag
X! (setq calc-incomplete-algebraic-mode
X! (not calc-incomplete-algebraic-mode)
X! calc-algebraic-mode nil)
X! (setq calc-incomplete-algebraic-mode nil
X! calc-algebraic-mode (not calc-algebraic-mode))))
X )
X
X (defun calc-symbolic-mode ()
X***************
X*** 3549,3555 ****
X (interactive)
X (calc-do-prefix-help
X '("Display; Fwd, Back; Next, Prev, Here, [, ]; Yank"
X! "Search, Reverse; In, Out; <, >; Kill; Marker")
X "trail" ?t)
X )
X
X--- 7036,7042 ----
X (interactive)
X (calc-do-prefix-help
X '("Display; Fwd, Back; Next, Prev, Here, [, ]; Yank"
X! "Search, Reverse; In, Out; <, >; Kill; Marker; . (abbrev)")
X "trail" ?t)
X )
X
X***************
X*** 3568,3574 ****
X (calc-select-buffer)
X (let ((win (get-buffer-window (current-buffer))))
X (if win
X! (select-window win)
X (calc)))
X )
X
X--- 7055,7063 ----
X (calc-select-buffer)
X (let ((win (get-buffer-window (current-buffer))))
X (if win
X! (progn
X! (select-window win)
X! (calc-align-stack-window))
X (calc)))
X )
X
X***************
X*** 3663,3669 ****
X (calc-with-trail-buffer
X (save-window-excursion
X (select-window (get-buffer-window (current-buffer)))
X! (isearch t nil))
X (calc-trail-here))
X )
X
X--- 7152,7159 ----
X (calc-with-trail-buffer
X (save-window-excursion
X (select-window (get-buffer-window (current-buffer)))
X! (let ((search-exit-char ?\r))
X! (isearch t nil)))
X (calc-trail-here))
X )
X
X***************
X*** 3673,3679 ****
X (calc-with-trail-buffer
X (save-window-excursion
X (select-window (get-buffer-window (current-buffer)))
X! (isearch nil nil))
X (calc-trail-here))
X )
X
X--- 7163,7170 ----
X (calc-with-trail-buffer
X (save-window-excursion
X (select-window (get-buffer-window (current-buffer)))
X! (let ((search-exit-char ?\r))
X! (isearch nil nil)))
X (calc-trail-here))
X )
X
X***************
X*** 3689,3701 ****
X (looking-at " ? ? ?[^ \n]* *$")
X (looking-at "..?.?$"))
X (error "Can't yank that line"))
X (forward-char 4)
X (search-forward " ")
X (let* ((next (save-excursion (forward-line 1) (point)))
X (str (buffer-substring (point) (1- next)))
X! (calc-language nil)
X! (math-expr-opers math-standard-opers)
X! (val (math-read-expr str)))
X (if (eq (car-safe val) 'error)
X (error "Can't yank that line: " (nth 2 val))
X val)))))
X--- 7180,7192 ----
X (looking-at " ? ? ?[^ \n]* *$")
X (looking-at "..?.?$"))
X (error "Can't yank that line"))
X+ (if (looking-at ".*, \\.\\.\\., ")
X+ (error "Can't yank (vector was abbreviated)"))
X (forward-char 4)
X (search-forward " ")
X (let* ((next (save-excursion (forward-line 1) (point)))
X (str (buffer-substring (point) (1- next)))
X! (val (math-read-plain-expr str)))
X (if (eq (car-safe val) 'error)
X (error "Can't yank that line: " (nth 2 val))
X val)))))
X***************
X*** 3937,3946 ****
X )
X
X (defun calc-view-units-table (n)
X! "Display a temporary buffer for displaying the Units Table."
X (interactive "P")
X (and n (setq math-units-table-buffer-valid nil))
X! (math-build-units-table-buffer nil)
X )
X
X (defun calc-enter-units-table (n)
X--- 7428,7448 ----
X )
X
X (defun calc-view-units-table (n)
X! "Display a temporary buffer for displaying the Units Table.
X! If the Units Table is already displayed in a window, hide it again."
X (interactive "P")
X (and n (setq math-units-table-buffer-valid nil))
X! (let ((win (get-buffer-window "*Units Table*")))
X! (if (and win
X! math-units-table
X! math-units-table-buffer-valid)
X! (progn
X! (bury-buffer (window-buffer win))
X! (let ((curwin (selected-window)))
X! (select-window win)
X! (switch-to-buffer nil)
X! (select-window curwin)))
X! (math-build-units-table-buffer nil)))
X )
X
X (defun calc-enter-units-table (n)
X***************
X*** 4075,4085 ****
X (interactive)
X (calc-do-prefix-help
X '("Pack, Unpack, Identity, Diagonal, indeX, Build"
X! "Row, Col, Length; rNorm"
X! "Tranpose, Arrange; Sort, Histogram"
X! "SHIFT + Det, Inv, LUD, Trace, conJtrn, Cross, cNorm"
X! "SHIFT + Reduce, Map, Apply"
X! "<, =, > (justification); , (commas); [, {, ( (brackets)")
X "vec/mat" ?v)
X )
X
X--- 7577,7589 ----
X (interactive)
X (calc-do-prefix-help
X '("Pack, Unpack, Identity, Diagonal, indeX, Build"
X! "Row, Column, Subvector; Length; Find; Mask, Expand"
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 )
X
X***************
X*** 4088,4094 ****
X Or concatenate a scalar value and a vector."
X (interactive "P")
X (calc-wrapper
X! (calc-binary-op "|" 'calcFunc-vconcat arg '(vec)))
X )
X
X ;;;; [calc-mode.el]
X--- 7592,7598 ----
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***************
X*** 4117,4122 ****
X--- 7621,7656 ----
X (calc-refresh))
X )
X
X+ (defun calc-full-vectors ()
X+ "Turn abbreviated display of long vectors on and off."
X+ (interactive)
X+ (calc-wrapper
X+ (setq calc-full-vectors (not calc-full-vectors))
X+ (calc-refresh)
X+ (message (if calc-full-vectors
X+ "Displaying long vectors in full."
X+ "Displaying long vectors in [a, b, c, ..., z] notation.")))
X+ )
X+
X+ (defun calc-full-trail-vectors ()
X+ "Turn abbreviated display of long vectors on and off in the Trail."
X+ (interactive)
X+ (calc-wrapper
X+ (setq calc-full-trail-vectors (not calc-full-trail-vectors))
X+ (calc-refresh)
X+ (message (if calc-full-trail-vectors
X+ "Recording long vectors in full."
X+ "Recording long vectors in [a, b, c, ..., z] notation.")))
X+ )
X+
X+ (defun calc-break-vectors ()
X+ "Turn multi-line display of plain vectors on and off."
X+ (interactive)
X+ (calc-wrapper
X+ (setq calc-break-vectors (not calc-break-vectors))
X+ (calc-refresh))
X+ )
X+
X (defun calc-vector-commas ()
X "Turn separating commas in vectors on and off."
X (interactive)
X***************
X*** 4250,4261 ****
X (prefix-numeric-value n))))
X )
X
X! (defun calc-index (n)
X "Generate a vector of the form [1, 2, ..., N]."
X! (interactive "NSize of vector = ")
X (calc-wrapper
X! (calc-enter-result 0 "indx" (list 'calcFunc-index
X! (prefix-numeric-value n))))
X )
X
X (defun calc-build-vector (n)
X--- 7784,7797 ----
X (prefix-numeric-value n))))
X )
X
X! (defun calc-index (n &optional stack)
X "Generate a vector of the form [1, 2, ..., N]."
X! (interactive "NSize of vector = \nP")
X (calc-wrapper
X! (if (consp stack)
X! (calc-enter-result 3 "indx" (cons 'calcFunc-index (calc-top-list-n 3)))
X! (calc-enter-result 0 "indx" (list 'calcFunc-index
X! (prefix-numeric-value n)))))
X )
X
X (defun calc-build-vector (n)
X***************
X*** 4267,4272 ****
X--- 7803,7831 ----
X (prefix-numeric-value n))))
X )
X
X+ (defun calc-cons (arg)
X+ "Insert the object in stack level 2 at front of vector at top of stack."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-binary-op "cons" 'calcFunc-cons arg))
X+ )
X+
X+
X+ (defun calc-head (arg)
X+ "Extract the first element of the vector on the top of the stack."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-unary-op "head" 'calcFunc-head arg))
X+ )
X+
X+
X+ (defun calc-tail (arg)
X+ "Extract all but the first element of the vector on the top of the stack."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-unary-op "tail" 'calcFunc-tail arg))
X+ )
X+
X (defun calc-vlength (arg)
X "Replace a vector with its length, in the form of an integer."
X (interactive "P")
X***************
X*** 4282,4290 ****
X (prefix-numeric-value n))))
X )
X
X (defun calc-sort ()
X "Sort the matrix at top of stack into increasing order.
X! With Inverse flag or a negative numeric prefix, sort into decreasing order."
X (interactive)
X (calc-slow-wrapper
X (if (calc-is-inverse)
X--- 7841,7905 ----
X (prefix-numeric-value n))))
X )
X
X+ (defun calc-vector-find (arg)
X+ "Search for a given element in a vector, return index of the element."
X+ (interactive "P")
X+ (calc-wrapper
X+ (let ((func (cons 'calcFunc-find (calc-top-list-n 2))))
X+ (calc-enter-result
X+ 2 "find"
X+ (if arg (append func (list (prefix-numeric-value arg))) func))))
X+ )
X+
X+ (defun calc-subvector ()
X+ "Extract a subvector of a vector: subvec(vec,start,end).
X+ If start is zero or negative, it is interpreted as length(vec) + start + 1.
X+ Same for end. If end is omitted in the algebraic form, it is taken as zero.
X+ Elements from start, inclusive, to end, exclusive, are taken."
X+ (interactive)
X+ (calc-wrapper
X+ (calc-enter-result 3 "svec" (cons 'calcFunc-subvec (calc-top-list-n 3))))
X+ )
X+
X+ (defun calc-reverse-vector (arg)
X+ "Reverse the order of elements in a vector."
X+ (interactive "P")
X+ (calc-wrapper
X+ (calc-unary-op "rev" 'calcFunc-rev arg))
X+ )
X+
X+ (defun calc-mask-vector (arg)
X+ "Compress a vector according to a mask vector.
X+ Vector is in top of stack, mask is in second-to-top.
X+ Both input vectors must have the same size. Elements of the vector
SHAR_EOF
echo "End of part 6, continue with part 7"
echo "7" > s2_seq_.tmp
exit 0
More information about the Comp.sources.misc
mailing list