home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-29 | 55.2 KB | 1,739 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i055: gnucalc - GNU Emacs Calculator, v2.00, Part07/56
- Message-ID: <1991Oct29.225818.19922@sparky.imd.sterling.com>
- X-Md4-Signature: 1eb577a4cebff995a6246c32fe6931f2
- Date: Tue, 29 Oct 1991 22:58:18 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 55
- Archive-name: gnucalc/part07
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # this is Part.07 (part 7 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc-alg-3.el continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 7; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc-alg-3.el'
- else
- echo 'x - continuing file calc-alg-3.el'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc-alg-3.el' &&
- X (math-float tlo) (math-float hi) 'inf))
- X hi tlo)))
- X (or (math-equal lo hi)
- X (setq sum (math-add sum
- X (math-ninteg-romberg
- X 'math-ninteg-midpoint expr
- X (math-float lo) (math-float hi) nil))))
- X sum))
- )
- X
- X
- ;;; Open Romberg method; "qromo" in section 4.4.
- (defun math-ninteg-romberg (func expr lo hi mode)
- X (let ((curh '(float 1 0))
- X (h nil)
- X (s nil)
- X (j 0)
- X (ss nil)
- X (prec calc-internal-prec)
- X (integ-temp nil))
- X (math-with-extra-prec 2
- X ;; Limit on "j" loop must be 14 or less to keep "it" from overflowing.
- X (or (while (and (null ss) (<= (setq j (1+ j)) 8))
- X (setq s (nconc s (list (funcall func expr lo hi mode)))
- X h (nconc h (list curh)))
- X (if (>= j 3)
- X (let ((res (math-poly-interp h s '(float 0 0) nil)))
- X (if (math-lessp (math-abs (nth 1 res))
- X (calcFunc-scf (math-abs (car res))
- X (- prec)))
- X (setq math-ninteg-convergence j
- X ss (car res)))))
- X (if (>= j 5)
- X (setq s (cdr s)
- X h (cdr h)))
- X (setq curh (math-div-float curh '(float 9 0))))
- X ss
- X (math-reject-arg nil (format "*Integral failed to converge")))))
- )
- X
- X
- (defun math-ninteg-evaluate (expr x mode)
- X (if (eq mode 'inf)
- X (setq x (math-div '(float 1 0) x)))
- X (let* ((var-DUMMY x)
- X (res (math-evaluate-expr expr)))
- X (or (Math-numberp res)
- X (math-reject-arg res "*Integrand does not evaluate to a number"))
- X (if (eq mode 'inf)
- X (setq res (math-mul res (math-sqr x))))
- X res)
- )
- X
- X
- (defun math-ninteg-midpoint (expr lo hi mode) ; uses "integ-temp"
- X (if (eq mode 'inf)
- X (let ((math-infinite-mode t) temp)
- X (setq temp (math-div 1 lo)
- X lo (math-div 1 hi)
- X hi temp)))
- X (if integ-temp
- X (let* ((it3 (* 3 (car integ-temp)))
- X (math-working-step-2 (* 2 (car integ-temp)))
- X (math-working-step 0)
- X (range (math-sub hi lo))
- X (del (math-div range (math-float it3)))
- X (del2 (math-add del del))
- X (del3 (math-add del del2))
- X (x (math-add lo (math-mul '(float 5 -1) del)))
- X (sum '(float 0 0))
- X (j 0) temp)
- X (while (<= (setq j (1+ j)) (car integ-temp))
- X (setq math-working-step (1+ math-working-step)
- X temp (math-ninteg-evaluate expr x mode)
- X math-working-step (1+ math-working-step)
- X sum (math-add sum (math-add temp (math-ninteg-evaluate
- X expr (math-add x del2)
- X mode)))
- X x (math-add x del3)))
- X (setq integ-temp (list it3
- X (math-add (math-div (nth 1 integ-temp)
- X '(float 3 0))
- X (math-mul sum del)))))
- X (setq integ-temp (list 1 (math-mul
- X (math-sub hi lo)
- X (math-ninteg-evaluate
- X expr
- X (math-mul (math-add lo hi) '(float 5 -1))
- X mode)))))
- X (nth 1 integ-temp)
- )
- X
- X
- X
- X
- X
- ;;; The following algorithms come from Numerical Recipes, chapter 14.
- X
- (setq math-dummy-vars [(var DUMMY var-DUMMY)])
- (setq math-dummy-counter 0)
- X
- (defun math-dummy-variable ()
- X (if (= math-dummy-counter (length math-dummy-vars))
- X (let ((symb (intern (format "math-dummy-%d" math-dummy-counter))))
- X (setq math-dummy-vars (vconcat math-dummy-vars
- X (vector (list 'var symb symb))))))
- X (set (nth 2 (aref math-dummy-vars math-dummy-counter)) nil)
- X (prog1
- X (aref math-dummy-vars math-dummy-counter)
- X (setq math-dummy-counter (1+ math-dummy-counter)))
- )
- X
- X
- X
- (defun calcFunc-fit (expr vars &optional coefs data)
- X (let ((math-in-fit 10))
- X (math-with-extra-prec 2
- X (math-general-fit expr vars coefs data nil)))
- )
- X
- (defun calcFunc-efit (expr vars &optional coefs data)
- X (let ((math-in-fit 10))
- X (math-with-extra-prec 2
- X (math-general-fit expr vars coefs data 'sdev)))
- )
- X
- (defun calcFunc-xfit (expr vars &optional coefs data)
- X (let ((math-in-fit 10))
- X (math-with-extra-prec 2
- X (math-general-fit expr vars coefs data 'full)))
- )
- X
- (defun math-general-fit (expr vars coefs data mode)
- X (let ((calc-simplify-mode nil)
- X (math-dummy-counter math-dummy-counter)
- X (math-in-fit 1)
- X (extended (eq mode 'full))
- X (first-coef math-dummy-counter)
- X first-var
- X (plain-expr expr)
- X orig-expr
- X have-sdevs need-chisq chisq
- X (x-funcs nil)
- X (y-filter nil)
- X y-dummy
- X (coef-filters nil)
- X new-coefs
- X (xy-values nil)
- X (weights nil)
- X (var-YVAL nil) (var-YVALX nil)
- X covar beta
- X n nn m mm v dummy p)
- X
- X ;; Validate and parse arguments.
- X (or data
- X (if coefs
- X (setq data coefs
- X coefs nil)
- X (if (math-vectorp expr)
- X (if (memq (length expr) '(3 4))
- X (setq data vars
- X vars (nth 2 expr)
- X coefs (nth 3 expr)
- X expr (nth 1 expr))
- X (math-dimension-error))
- X (setq data vars
- X vars nil
- X coefs nil))))
- X (or (math-matrixp data) (math-reject-arg data 'matrixp))
- X (setq v (1- (length data))
- X n (1- (length (nth 1 data))))
- X (or (math-vectorp vars) (null vars)
- X (setq vars (list 'vec vars)))
- X (or (math-vectorp coefs) (null coefs)
- X (setq coefs (list 'vec coefs)))
- X (or coefs
- X (setq coefs (cons 'vec (math-all-vars-but expr vars))))
- X (or vars
- X (if (<= (1- (length coefs)) v)
- X (math-reject-arg coefs "*Not enough variables in model")
- X (setq coefs (copy-sequence coefs))
- X (let ((p (nthcdr (- (length coefs) v
- X (if (eq (car-safe expr) 'calcFunc-eq) 1 0))
- X coefs)))
- X (setq vars (cons 'vec (cdr p)))
- X (setcdr p nil))))
- X (or (= (1- (length vars)) v)
- X (= (length vars) v)
- X (math-reject-arg vars "*Number of variables does not match data"))
- X (setq m (1- (length coefs)))
- X (if (< m 1)
- X (math-reject-arg coefs "*Need at least one parameter"))
- X
- X ;; Rewrite expr in terms of fitparam and fitvar, make into an equation.
- X (setq p coefs)
- X (while (setq p (cdr p))
- X (or (eq (car-safe (car p)) 'var)
- X (math-reject-arg (car p) "*Expected a variable"))
- X (setq dummy (math-dummy-variable)
- X expr (math-expr-subst expr (car p)
- X (list 'calcFunc-fitparam
- X (- math-dummy-counter first-coef)))))
- X (setq first-var math-dummy-counter
- X p vars)
- X (while (setq p (cdr p))
- X (or (eq (car-safe (car p)) 'var)
- X (math-reject-arg (car p) "*Expected a variable"))
- X (setq dummy (math-dummy-variable)
- X expr (math-expr-subst expr (car p)
- X (list 'calcFunc-fitvar
- X (- math-dummy-counter first-var)))))
- X (if (< math-dummy-counter (+ first-var v))
- X (setq dummy (math-dummy-variable))) ; dependent variable may be unnamed
- X (setq y-dummy dummy
- X orig-expr expr)
- X (or (eq (car-safe expr) 'calcFunc-eq)
- X (setq expr (list 'calcFunc-eq (list 'calcFunc-fitvar v) expr)))
- X
- X (let ((calc-symbolic-mode nil))
- X
- X ;; Apply rewrites to put expr into a linear-like form.
- X (setq expr (math-evaluate-expr expr)
- X expr (math-rewrite (list 'calcFunc-fitmodel expr)
- X '(var FitRules var-FitRules))
- X math-in-fit 2
- X expr (math-evaluate-expr expr))
- X (or (and (eq (car-safe expr) 'calcFunc-fitsystem)
- X (= (length expr) 4)
- X (math-vectorp (nth 2 expr))
- X (math-vectorp (nth 3 expr))
- X (> (length (nth 2 expr)) 1)
- X (= (length (nth 3 expr)) (1+ m)))
- X (math-reject-arg plain-expr "*Model expression is too complex"))
- X (setq y-filter (nth 1 expr)
- X x-funcs (vconcat (cdr (nth 2 expr)))
- X coef-filters (nth 3 expr)
- X mm (length x-funcs))
- X (if (equal y-filter y-dummy)
- X (setq y-filter nil))
- X
- X ;; Build the (square) system of linear equations to be solved.
- X (setq beta (cons 'vec (make-list mm 0))
- X covar (cons 'vec (mapcar 'copy-sequence (make-list mm beta))))
- X (let* ((ptrs (vconcat (cdr data)))
- X (isigsq 1)
- X (xvals (make-vector mm 0))
- X (i 0)
- X j k xval yval sigmasqr wt covj covjk covk betaj lud)
- X (while (<= (setq i (1+ i)) n)
- X
- X ;; Assign various independent variables for this data point.
- X (setq j 0
- X sigmasqr nil)
- X (while (< j v)
- X (aset ptrs j (cdr (aref ptrs j)))
- X (setq xval (car (aref ptrs j)))
- X (if (= j (1- v))
- X (if sigmasqr
- X (progn
- X (if (eq (car-safe xval) 'sdev)
- X (setq sigmasqr (math-add (math-sqr (nth 2 xval))
- X sigmasqr)
- X xval (nth 1 xval)))
- X (if y-filter
- X (setq xval (math-make-sdev xval
- X (math-sqrt sigmasqr))))))
- X (if (eq (car-safe xval) 'sdev)
- X (setq sigmasqr (math-add (math-sqr (nth 2 xval))
- X (or sigmasqr 0))
- X xval (nth 1 xval))))
- X (set (nth 2 (aref math-dummy-vars (+ first-var j))) xval)
- X (setq j (1+ j)))
- X
- X ;; Compute Y value for this data point.
- X (if y-filter
- X (setq yval (math-evaluate-expr y-filter))
- X (setq yval (symbol-value (nth 2 y-dummy))))
- X (if (eq (car-safe yval) 'sdev)
- X (setq sigmasqr (math-sqr (nth 2 yval))
- X yval (nth 1 yval)))
- X (if (= i 1)
- X (setq have-sdevs sigmasqr
- X need-chisq (or extended
- X (and (eq mode 'sdev) (not have-sdevs)))))
- X (if have-sdevs
- X (if sigmasqr
- X (progn
- X (setq isigsq (math-div 1 sigmasqr))
- X (if need-chisq
- X (setq weights (cons isigsq weights))))
- X (math-reject-arg yval "*Mixed error forms and plain numbers"))
- X (if sigmasqr
- X (math-reject-arg yval "*Mixed error forms and plain numbers")))
- X
- X ;; Compute X values for this data point and update covar and beta.
- X (if (eq (car-safe xval) 'sdev)
- X (set (nth 2 y-dummy) (nth 1 xval)))
- X (setq j 0
- X covj covar
- X betaj beta)
- X (while (< j mm)
- X (setq wt (math-evaluate-expr (aref x-funcs j)))
- X (aset xvals j wt)
- X (setq wt (math-mul wt isigsq)
- X betaj (cdr betaj)
- X covjk (car (setq covj (cdr covj)))
- X k 0)
- X (while (<= k j)
- X (setq covjk (cdr covjk))
- X (setcar covjk (math-add (car covjk)
- X (math-mul wt (aref xvals k))))
- X (setq k (1+ k)))
- X (setcar betaj (math-add (car betaj) (math-mul wt yval)))
- X (setq j (1+ j)))
- X (if need-chisq
- X (setq xy-values (cons (append xvals (list yval)) xy-values))))
- X
- X ;; Fill in symmetric half of covar matrix.
- X (setq j 0
- X covj covar)
- X (while (< j (1- mm))
- X (setq k j
- X j (1+ j)
- X covjk (nthcdr j (car (setq covj (cdr covj))))
- X covk (nthcdr j covar))
- X (while (< (setq k (1+ k)) mm)
- X (setq covjk (cdr covjk)
- X covk (cdr covk))
- X (setcar covjk (nth j (car covk))))))
- X
- X ;; Solve the linear system.
- X (if mode
- X (progn
- X (setq covar (math-matrix-inv-raw covar))
- X (if covar
- X (setq beta (math-mul covar beta))
- X (if (math-zerop (math-abs beta))
- X (setq covar (calcFunc-diag 0 (1- (length beta))))
- X (math-reject-arg orig-expr "*Singular matrix")))
- X (or (math-vectorp covar)
- X (setq covar (list 'vec (list 'vec covar)))))
- X (setq beta (math-div beta covar)))
- X
- X ;; Compute chi-square statistic if necessary.
- X (if need-chisq
- X (let (bp xp sum)
- X (setq chisq 0)
- X (while xy-values
- X (setq bp beta
- X xp (car xy-values)
- X sum 0)
- X (while (setq bp (cdr bp))
- X (setq sum (math-add sum (math-mul (car bp) (car xp)))
- X xp (cdr xp)))
- X (setq sum (math-sqr (math-sub (car xp) sum)))
- X (if weights (setq sum (math-mul sum (car weights))))
- X (setq chisq (math-add chisq sum)
- X weights (cdr weights)
- X xy-values (cdr xy-values)))))
- X
- X ;; Convert coefficients back into original terms.
- X (setq new-coefs (copy-sequence beta))
- X (let* ((bp new-coefs)
- X (cp covar)
- X (sigdat 1)
- X (math-in-fit 3)
- X (j 0))
- X (and mode (not have-sdevs)
- X (setq sigdat (if (<= n mm)
- X 0
- X (math-div chisq (- n mm)))))
- X (if mode
- X (while (setq bp (cdr bp))
- X (setcar bp (math-make-sdev
- X (car bp)
- X (math-sqrt (math-mul (nth (setq j (1+ j))
- X (car (setq cp (cdr cp))))
- X sigdat))))))
- X (setq new-coefs (math-evaluate-expr coef-filters))
- X (if calc-fit-to-trail
- X (let ((bp new-coefs)
- X (cp coefs)
- X (vec nil))
- X (while (setq bp (cdr bp) cp (cdr cp))
- X (setq vec (cons (list 'calcFunc-eq (car cp) (car bp)) vec)))
- X (setq calc-fit-to-trail (cons 'vec (nreverse vec)))))))
- X
- X ;; Substitute best-fit coefficients back into original formula.
- X (setq expr (math-multi-subst
- X orig-expr
- X (let ((n v)
- X (vec nil))
- X (while (>= n 1)
- X (setq vec (cons (list 'calcFunc-fitvar n) vec)
- X n (1- n)))
- X (setq n m)
- X (while (>= n 1)
- X (setq vec (cons (list 'calcFunc-fitparam n) vec)
- X n (1- n)))
- X vec)
- X (append (cdr new-coefs) (cdr vars))))
- X
- X ;; Package the result.
- X (math-normalize
- X (if extended
- X (list 'vec expr beta covar
- X (let ((p coef-filters)
- X (n 0))
- X (while (and (setq n (1+ n) p (cdr p))
- X (eq (car-safe (car p)) 'calcFunc-fitdummy)
- X (eq (nth 1 (car p)) n)))
- X (if p
- X coef-filters
- X (list 'vec)))
- X chisq
- X (if (and have-sdevs (> n mm))
- X (list 'calcFunc-utpc chisq (- n mm))
- X '(var nan var-nan)))
- X expr)))
- )
- X
- (setq math-in-fit 0)
- (setq calc-fit-to-trail nil)
- X
- (defun calcFunc-fitvar (x)
- X (if (>= math-in-fit 2)
- X (progn
- X (setq x (aref math-dummy-vars (+ first-var x -1)))
- X (or (calc-var-value (nth 2 x)) x))
- X (math-reject-arg x))
- )
- X
- (defun calcFunc-fitparam (x)
- X (if (>= math-in-fit 2)
- X (progn
- X (setq x (aref math-dummy-vars (+ first-coef x -1)))
- X (or (calc-var-value (nth 2 x)) x))
- X (math-reject-arg x))
- )
- X
- (defun calcFunc-fitdummy (x)
- X (if (= math-in-fit 3)
- X (nth x new-coefs)
- X (math-reject-arg x))
- )
- X
- (defun calcFunc-hasfitvars (expr)
- X (if (Math-primp expr)
- X 0
- X (if (eq (car expr) 'calcFunc-fitvar)
- X (nth 1 expr)
- X (apply 'max (mapcar 'calcFunc-hasfitvars (cdr expr)))))
- )
- X
- (defun calcFunc-hasfitparams (expr)
- X (if (Math-primp expr)
- X 0
- X (if (eq (car expr) 'calcFunc-fitparam)
- X (nth 1 expr)
- X (apply 'max (mapcar 'calcFunc-hasfitparams (cdr expr)))))
- )
- X
- X
- (defun math-all-vars-but (expr but)
- X (let* ((vars (math-all-vars-in expr))
- X (p but))
- X (while p
- X (setq vars (delq (assoc (car-safe p) vars) vars)
- X p (cdr p)))
- X (sort (mapcar 'car vars)
- X (function (lambda (x y) (string< (nth 1 x) (nth 1 y))))))
- )
- X
- (defun math-all-vars-in (expr)
- X (let ((vars nil)
- X found)
- X (math-all-vars-rec expr)
- X vars)
- )
- X
- (defun math-all-vars-rec (expr)
- X (if (Math-primp expr)
- X (if (eq (car-safe expr) 'var)
- X (or (math-const-var expr)
- X (if (setq found (assoc expr vars))
- X (setcdr found (1+ (cdr found)))
- X (setq vars (cons (cons expr 1) vars)))))
- X (while (setq expr (cdr expr))
- X (math-all-vars-rec (car expr))))
- )
- X
- X
- X
- X
- SHAR_EOF
- echo 'File calc-alg-3.el is complete' &&
- chmod 0644 calc-alg-3.el ||
- echo 'restore of calc-alg-3.el failed'
- Wc_c="`wc -c < 'calc-alg-3.el'`"
- test 56657 -eq "$Wc_c" ||
- echo 'calc-alg-3.el: original size 56657, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= calc-alg.el ==============
- if test -f 'calc-alg.el' -a X"$1" != X"-c"; then
- echo 'x - skipping calc-alg.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting calc-alg.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'calc-alg.el' &&
- ;; Calculator for GNU Emacs, part II [calc-alg.el]
- ;; Copyright (C) 1990, 1991 Free Software Foundation, Inc.
- ;; Written by Dave Gillespie, daveg@csvax.cs.caltech.edu.
- X
- ;; This file is part of GNU Emacs.
- X
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY. No author or distributor
- ;; accepts responsibility to anyone for the consequences of using it
- ;; or for whether it serves any particular purpose or works at all,
- ;; unless he says so in writing. Refer to the GNU Emacs General Public
- ;; License for full details.
- X
- ;; Everyone is granted permission to copy, modify and redistribute
- ;; GNU Emacs, but only under the conditions described in the
- ;; GNU Emacs General Public License. A copy of this license is
- ;; supposed to have been given to you along with GNU Emacs so you
- ;; can know your rights and responsibilities. It should be in a
- ;; file named COPYING. Among other things, the copyright notice
- ;; and this notice must be preserved on all copies.
- X
- X
- X
- ;; This file is autoloaded from calc-ext.el.
- (require 'calc-ext)
- X
- (require 'calc-macs)
- X
- (defun calc-Need-calc-alg () nil)
- X
- X
- ;;; Algebra commands.
- X
- (defun calc-alg-evaluate (arg)
- 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
- (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
- (defun calc-simplify ()
- X (interactive)
- X (calc-slow-wrapper
- X (calc-with-default-simplification
- X (calc-enter-result 1 "simp" (math-simplify (calc-top-n 1)))))
- )
- X
- (defun calc-simplify-extended ()
- X (interactive)
- X (calc-slow-wrapper
- X (calc-with-default-simplification
- X (calc-enter-result 1 "esmp" (math-simplify-extended (calc-top-n 1)))))
- )
- X
- (defun calc-expand-formula (arg)
- 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 "expf"
- X (if (> arg 0)
- X (let ((math-expand-formulas t))
- X (calc-top-n 1))
- X (let ((top (calc-top-n 1)))
- X (or (math-expand-formula top)
- X top)))))))
- )
- X
- (defun calc-factor (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-unary-op "fctr" (if (calc-is-hyperbolic)
- X 'calcFunc-factors 'calcFunc-factor)
- X arg))
- )
- X
- (defun calc-expand (n)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-enter-result 1 "expa"
- X (append (list 'calcFunc-expand
- X (calc-top-n 1))
- X (and n (list (prefix-numeric-value n))))))
- )
- X
- (defun calc-collect (&optional var)
- X (interactive "sCollect terms involving: ")
- X (calc-slow-wrapper
- X (if (or (equal var "") (equal var "$") (null var))
- X (calc-enter-result 2 "clct" (cons 'calcFunc-collect
- X (calc-top-list-n 2)))
- 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 "clct" (list 'calcFunc-collect
- X (calc-top-n 1)
- X var)))))
- )
- X
- (defun calc-apart (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-unary-op "aprt" 'calcFunc-apart arg))
- )
- X
- (defun calc-normalize-rat (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-unary-op "nrat" 'calcFunc-nrat arg))
- )
- X
- (defun calc-poly-gcd (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-binary-op "pgcd" 'calcFunc-pgcd arg))
- )
- X
- (defun calc-poly-div (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (setq calc-poly-div-remainder nil)
- X (calc-binary-op "pdiv" 'calcFunc-pdiv arg)
- X (if (and calc-poly-div-remainder (null arg))
- X (progn
- X (calc-clear-command-flag 'clear-message)
- X (calc-record calc-poly-div-remainder "prem")
- X (if (not (Math-zerop calc-poly-div-remainder))
- X (message "(Remainder was %s)"
- X (math-format-flat-expr calc-poly-div-remainder 0))
- X (message "(No remainder)")))))
- )
- X
- (defun calc-poly-rem (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (calc-binary-op "prem" 'calcFunc-prem arg))
- )
- X
- (defun calc-poly-div-rem (arg)
- X (interactive "P")
- X (calc-slow-wrapper
- X (if (calc-is-hyperbolic)
- X (calc-binary-op "pdvr" 'calcFunc-pdivide arg)
- X (calc-binary-op "pdvr" 'calcFunc-pdivrem arg)))
- )
- X
- (defun calc-substitute (&optional oldname newname)
- X (interactive "sSubstitute old: ")
- X (calc-slow-wrapper
- X (let (old new (num 1) expr)
- X (if (or (equal oldname "") (equal oldname "$") (null oldname))
- X (setq new (calc-top-n 1)
- X old (calc-top-n 2)
- X expr (calc-top-n 3)
- X num 3)
- X (or newname
- X (setq unread-command-char ?\C-a
- X newname (read-string (concat "Substitute old: "
- X oldname
- X ", new: ")
- X oldname)))
- X (if (or (equal newname "") (equal newname "$") (null newname))
- X (setq new (calc-top-n 1)
- X expr (calc-top-n 2)
- X num 2)
- X (setq new (if (stringp newname) (math-read-expr newname) newname))
- X (if (eq (car-safe new) 'error)
- X (error "Bad format in expression: %s" (nth 1 new)))
- X (setq expr (calc-top-n 1)))
- X (setq old (if (stringp oldname) (math-read-expr oldname) oldname))
- X (if (eq (car-safe old) 'error)
- X (error "Bad format in expression: %s" (nth 1 old)))
- X (or (math-expr-contains expr old)
- X (error "No occurrences found.")))
- X (calc-enter-result num "sbst" (math-expr-subst expr old new))))
- )
- X
- X
- (defun calc-has-rules (name)
- X (setq name (calc-var-value name))
- X (and (consp name)
- X (memq (car name) '(vec calcFunc-assign calcFunc-condition))
- X (cdr name))
- )
- X
- (defun math-recompile-eval-rules ()
- X (setq math-eval-rules-cache (and (calc-has-rules 'var-EvalRules)
- X (math-compile-rewrites
- X '(var EvalRules var-EvalRules)))
- X math-eval-rules-cache-other (assq nil math-eval-rules-cache)
- X math-eval-rules-cache-tag (calc-var-value 'var-EvalRules))
- )
- X
- X
- ;;; Try to expand a formula according to its definition.
- (defun math-expand-formula (expr)
- X (and (consp expr)
- X (symbolp (car expr))
- X (or (get (car expr) 'calc-user-defn)
- X (get (car expr) 'math-expandable))
- X (let ((res (let ((math-expand-formulas t))
- X (apply (car expr) (cdr expr)))))
- X (and (not (eq (car-safe res) (car expr)))
- X res)))
- )
- X
- X
- X
- X
- ;;; True if A comes before B in a canonical ordering of expressions. [P X X]
- (defun math-beforep (a b) ; [Public]
- X (cond ((and (Math-realp a) (Math-realp b))
- X (let ((comp (math-compare a b)))
- X (or (eq comp -1)
- X (and (eq comp 0)
- X (not (equal a b))
- X (> (length (memq (car-safe a)
- X '(bigneg nil bigpos frac float)))
- X (length (memq (car-safe b)
- X '(bigneg nil bigpos frac float))))))))
- X ((equal b '(neg (var inf var-inf))) nil)
- X ((equal a '(neg (var inf var-inf))) t)
- X ((equal a '(var inf var-inf)) nil)
- X ((equal b '(var inf var-inf)) t)
- X ((Math-realp a)
- X (if (and (eq (car-safe b) 'intv) (math-intv-constp b))
- X (if (or (math-beforep a (nth 2 b)) (Math-equal a (nth 2 b)))
- X t
- X nil)
- X t))
- X ((Math-realp b)
- X (if (and (eq (car-safe a) 'intv) (math-intv-constp a))
- X (if (math-beforep (nth 2 a) b)
- X t
- X nil)
- X nil))
- X ((and (eq (car a) 'intv) (eq (car b) 'intv)
- X (math-intv-constp a) (math-intv-constp b))
- X (let ((comp (math-compare (nth 2 a) (nth 2 b))))
- X (cond ((eq comp -1) t)
- X ((eq comp 1) nil)
- X ((and (memq (nth 1 a) '(2 3)) (memq (nth 1 b) '(0 1))) t)
- X ((and (memq (nth 1 a) '(0 1)) (memq (nth 1 b) '(2 3))) nil)
- X ((eq (setq comp (math-compare (nth 3 a) (nth 3 b))) -1) t)
- X ((eq comp 1) nil)
- X ((and (memq (nth 1 a) '(0 2)) (memq (nth 1 b) '(1 3))) t)
- X (t nil))))
- X ((not (eq (not (Math-objectp a)) (not (Math-objectp b))))
- X (Math-objectp a))
- X ((eq (car a) 'var)
- X (if (eq (car b) 'var)
- X (string-lessp (symbol-name (nth 1 a)) (symbol-name (nth 1 b)))
- X (not (Math-numberp b))))
- X ((eq (car b) 'var) (Math-numberp a))
- X ((eq (car a) (car b))
- X (while (and (setq a (cdr a) b (cdr b)) a
- X (equal (car a) (car b))))
- X (and b
- X (or (null a)
- X (math-beforep (car a) (car b)))))
- X (t (string-lessp (symbol-name (car a)) (symbol-name (car b)))))
- )
- X
- X
- (defun math-simplify-extended (a)
- X (let ((math-living-dangerously t))
- X (math-simplify a))
- )
- (fset 'calcFunc-esimplify (symbol-function 'math-simplify-extended))
- X
- (defun math-simplify (top-expr)
- X (let ((math-simplifying t)
- X (top-only (consp calc-simplify-mode))
- X (simp-rules (append (and (calc-has-rules 'var-AlgSimpRules)
- X '((var AlgSimpRules var-AlgSimpRules)))
- X (and math-living-dangerously
- X (calc-has-rules 'var-ExtSimpRules)
- X '((var ExtSimpRules var-ExtSimpRules)))
- X (and math-simplifying-units
- X (calc-has-rules 'var-UnitSimpRules)
- X '((var UnitSimpRules var-UnitSimpRules)))
- X (and math-integrating
- X (calc-has-rules 'var-IntegSimpRules)
- X '((var IntegSimpRules var-IntegSimpRules)))))
- X res)
- X (if top-only
- X (let ((r simp-rules))
- X (setq res (math-simplify-step (math-normalize top-expr))
- X calc-simplify-mode '(nil)
- X top-expr (math-normalize res))
- X (while r
- X (setq top-expr (math-rewrite top-expr (car r)
- X '(neg (var inf var-inf)))
- X r (cdr r))))
- X (calc-with-default-simplification
- X (while (let ((r simp-rules))
- X (setq res (math-normalize top-expr))
- X (while r
- X (setq res (math-rewrite res (car r))
- X r (cdr r)))
- X (not (equal top-expr (setq res (math-simplify-step res)))))
- X (setq top-expr res)))))
- X top-expr
- )
- (fset 'calcFunc-simplify (symbol-function 'math-simplify))
- X
- ;;; The following has a "bug" in that if any recursive simplifications
- ;;; occur only the first handler will be tried; this doesn't really
- ;;; matter, since math-simplify-step is iterated to a fixed point anyway.
- (defun math-simplify-step (a)
- X (if (Math-primp a)
- X a
- X (let ((aa (if (or top-only
- X (memq (car a) '(calcFunc-quote calcFunc-condition
- X calcFunc-evalto)))
- X a
- X (cons (car a) (mapcar 'math-simplify-step (cdr a))))))
- X (and (symbolp (car aa))
- X (let ((handler (get (car aa) 'math-simplify)))
- X (and handler
- X (while (and handler
- X (equal (setq aa (or (funcall (car handler) aa)
- X aa))
- X a))
- X (setq handler (cdr handler))))))
- X aa))
- )
- X
- X
- (defun math-need-std-simps ()
- X ;; Placeholder, to synchronize autoloading.
- )
- X
- (math-defsimplify (+ -)
- X (math-simplify-plus))
- X
- (defun math-simplify-plus ()
- X (cond ((and (memq (car-safe (nth 1 expr)) '(+ -))
- X (Math-numberp (nth 2 (nth 1 expr)))
- X (not (Math-numberp (nth 2 expr))))
- X (let ((x (nth 2 expr))
- X (op (car expr)))
- X (setcar (cdr (cdr expr)) (nth 2 (nth 1 expr)))
- X (setcar expr (car (nth 1 expr)))
- X (setcar (cdr (cdr (nth 1 expr))) x)
- X (setcar (nth 1 expr) op)))
- X ((and (eq (car expr) '+)
- X (Math-numberp (nth 1 expr))
- X (not (Math-numberp (nth 2 expr))))
- X (let ((x (nth 2 expr)))
- X (setcar (cdr (cdr expr)) (nth 1 expr))
- X (setcar (cdr expr) x))))
- X (let ((aa expr)
- X aaa temp)
- X (while (memq (car-safe (setq aaa (nth 1 aa))) '(+ -))
- X (if (setq temp (math-combine-sum (nth 2 aaa) (nth 2 expr)
- X (eq (car aaa) '-) (eq (car expr) '-) t))
- X (progn
- X (setcar (cdr (cdr expr)) temp)
- X (setcar expr '+)
- X (setcar (cdr (cdr aaa)) 0)))
- X (setq aa (nth 1 aa)))
- X (if (setq temp (math-combine-sum aaa (nth 2 expr)
- X nil (eq (car expr) '-) t))
- X (progn
- X (setcar (cdr (cdr expr)) temp)
- X (setcar expr '+)
- X (setcar (cdr aa) 0)))
- X expr)
- )
- X
- (math-defsimplify *
- X (math-simplify-times))
- X
- (defun math-simplify-times ()
- X (if (eq (car-safe (nth 2 expr)) '*)
- X (and (math-beforep (nth 1 (nth 2 expr)) (nth 1 expr))
- X (or (math-known-scalarp (nth 1 expr) t)
- X (math-known-scalarp (nth 1 (nth 2 expr)) t))
- X (let ((x (nth 1 expr)))
- X (setcar (cdr expr) (nth 1 (nth 2 expr)))
- X (setcar (cdr (nth 2 expr)) x)))
- X (and (math-beforep (nth 2 expr) (nth 1 expr))
- X (or (math-known-scalarp (nth 1 expr) t)
- X (math-known-scalarp (nth 2 expr) t))
- X (let ((x (nth 2 expr)))
- X (setcar (cdr (cdr expr)) (nth 1 expr))
- X (setcar (cdr expr) x))))
- X (let ((aa expr)
- X aaa temp
- X (safe t) (scalar (math-known-scalarp (nth 1 expr))))
- X (if (and (Math-ratp (nth 1 expr))
- X (setq temp (math-common-constant-factor (nth 2 expr))))
- X (progn
- X (setcar (cdr (cdr expr))
- X (math-cancel-common-factor (nth 2 expr) temp))
- X (setcar (cdr expr) (math-mul (nth 1 expr) temp))))
- X (while (and (eq (car-safe (setq aaa (nth 2 aa))) '*)
- X safe)
- X (if (setq temp (math-combine-prod (nth 1 expr) (nth 1 aaa) nil nil t))
- X (progn
- X (setcar (cdr expr) temp)
- X (setcar (cdr aaa) 1)))
- X (setq safe (or scalar (math-known-scalarp (nth 1 aaa) t))
- X aa (nth 2 aa)))
- X (if (and (setq temp (math-combine-prod aaa (nth 1 expr) nil nil t))
- X safe)
- X (progn
- X (setcar (cdr expr) temp)
- X (setcar (cdr (cdr aa)) 1)))
- X (if (and (eq (car-safe (nth 1 expr)) 'frac)
- X (memq (nth 1 (nth 1 expr)) '(1 -1)))
- X (math-div (math-mul (nth 2 expr) (nth 1 (nth 1 expr)))
- X (nth 2 (nth 1 expr)))
- X expr))
- )
- X
- (math-defsimplify /
- X (math-simplify-divide))
- X
- (defun math-simplify-divide ()
- X (let ((np (cdr expr))
- X (nover nil)
- X (nn (and (or (eq (car expr) '/) (not (Math-realp (nth 2 expr))))
- X (math-common-constant-factor (nth 2 expr))))
- X n op)
- X (if nn
- X (progn
- X (setq n (and (or (eq (car expr) '/) (not (Math-realp (nth 1 expr))))
- X (math-common-constant-factor (nth 1 expr))))
- X (if (and (eq (car-safe nn) 'frac) (eq (nth 1 nn) 1) (not n))
- X (progn
- X (setcar (cdr expr) (math-mul (nth 2 nn) (nth 1 expr)))
- X (setcar (cdr (cdr expr))
- X (math-cancel-common-factor (nth 2 expr) nn))
- X (if (and (math-negp nn)
- X (setq op (assq (car expr) calc-tweak-eqn-table)))
- X (setcar expr (nth 1 op))))
- X (if (and n (not (eq (setq n (math-frac-gcd n nn)) 1)))
- X (progn
- X (setcar (cdr expr)
- X (math-cancel-common-factor (nth 1 expr) n))
- X (setcar (cdr (cdr expr))
- X (math-cancel-common-factor (nth 2 expr) n))
- X (if (and (math-negp n)
- X (setq op (assq (car expr) calc-tweak-eqn-table)))
- X (setcar expr (nth 1 op))))))))
- X (if (and (eq (car-safe (car np)) '/)
- X (math-known-scalarp (nth 2 expr) t))
- X (progn
- X (setq np (cdr (nth 1 expr)))
- X (while (eq (car-safe (setq n (car np))) '*)
- X (and (math-known-scalarp (nth 2 n) t)
- X (math-simplify-divisor (cdr n) (cdr (cdr expr)) nil t))
- X (setq np (cdr (cdr n))))
- X (math-simplify-divisor np (cdr (cdr expr)) nil t)
- X (setq nover t
- X np (cdr (cdr (nth 1 expr))))))
- X (while (eq (car-safe (setq n (car np))) '*)
- X (and (math-known-scalarp (nth 2 n) t)
- X (math-simplify-divisor (cdr n) (cdr (cdr expr)) nover t))
- X (setq np (cdr (cdr n))))
- X (math-simplify-divisor np (cdr (cdr expr)) nover t)
- X expr)
- )
- X
- (defun math-simplify-divisor (np dp nover dover)
- X (cond ((eq (car-safe (car dp)) '/)
- X (math-simplify-divisor np (cdr (car dp)) nover dover)
- X (and (math-known-scalarp (nth 1 (car dp)) t)
- X (math-simplify-divisor np (cdr (cdr (car dp)))
- X nover (not dover))))
- X ((or (or (eq (car expr) '/)
- X (let ((signs (math-possible-signs (car np))))
- X (or (memq signs '(1 4))
- X (and (memq (car expr) '(calcFunc-eq calcFunc-neq))
- X (eq signs 5))
- X math-living-dangerously)))
- X (math-numberp (car np)))
- X (let ((n (car np))
- X d dd temp op
- X (safe t) (scalar (math-known-scalarp n)))
- X (while (and (eq (car-safe (setq d (car dp))) '*)
- X safe)
- X (math-simplify-one-divisor np (cdr d))
- X (setq safe (or scalar (math-known-scalarp (nth 1 d) t))
- X dp (cdr (cdr d))))
- X (if safe
- X (math-simplify-one-divisor np dp)))))
- )
- X
- (defun math-simplify-one-divisor (np dp)
- X (if (setq temp (math-combine-prod (car np) (car dp) nover dover t))
- X (progn
- X (and (not (memq (car expr) '(/ calcFunc-eq calcFunc-neq)))
- X (math-known-negp (car dp))
- X (setq op (assq (car expr) calc-tweak-eqn-table))
- X (setcar expr (nth 1 op)))
- X (setcar np (if nover (math-div 1 temp) temp))
- X (setcar dp 1))
- X (and dover (not nover) (eq (car expr) '/)
- X (eq (car-safe (car dp)) 'calcFunc-sqrt)
- X (Math-integerp (nth 1 (car dp)))
- X (progn
- X (setcar np (math-mul (car np)
- X (list 'calcFunc-sqrt (nth 1 (car dp)))))
- X (setcar dp (nth 1 (car dp))))))
- )
- X
- (defun math-common-constant-factor (expr)
- X (if (Math-realp expr)
- X (if (Math-ratp expr)
- X (and (not (memq expr '(0 1 -1)))
- X (math-abs expr))
- X (if (math-ratp (setq expr (math-to-simple-fraction expr)))
- X (math-common-constant-factor expr)))
- X (if (memq (car expr) '(+ - cplx sdev))
- X (let ((f1 (math-common-constant-factor (nth 1 expr)))
- X (f2 (math-common-constant-factor (nth 2 expr))))
- X (and f1 f2
- X (not (eq (setq f1 (math-frac-gcd f1 f2)) 1))
- X f1))
- X (if (memq (car expr) '(* polar))
- X (math-common-constant-factor (nth 1 expr))
- X (if (eq (car expr) '/)
- X (or (math-common-constant-factor (nth 1 expr))
- X (and (Math-integerp (nth 2 expr))
- X (list 'frac 1 (math-abs (nth 2 expr)))))))))
- )
- X
- (defun math-cancel-common-factor (expr val)
- X (if (memq (car-safe expr) '(+ - cplx sdev))
- X (progn
- X (setcar (cdr expr) (math-cancel-common-factor (nth 1 expr) val))
- X (setcar (cdr (cdr expr)) (math-cancel-common-factor (nth 2 expr) val))
- X expr)
- X (if (eq (car-safe expr) '*)
- X (math-mul (math-cancel-common-factor (nth 1 expr) val) (nth 2 expr))
- X (math-div expr val)))
- )
- X
- (defun math-frac-gcd (a b)
- X (if (Math-zerop a)
- X b
- X (if (Math-zerop b)
- X a
- X (if (and (Math-integerp a)
- X (Math-integerp b))
- X (math-gcd a b)
- X (and (Math-integerp a) (setq a (list 'frac a 1)))
- X (and (Math-integerp b) (setq b (list 'frac b 1)))
- X (math-make-frac (math-gcd (nth 1 a) (nth 1 b))
- X (math-gcd (nth 2 a) (nth 2 b))))))
- )
- X
- (math-defsimplify %
- X (math-simplify-mod))
- X
- (defun math-simplify-mod ()
- X (and (Math-realp (nth 2 expr))
- X (Math-posp (nth 2 expr))
- X (let ((lin (math-is-linear (nth 1 expr)))
- X t1 t2 t3)
- X (or (and lin
- X (or (math-negp (car lin))
- X (not (Math-lessp (car lin) (nth 2 expr))))
- X (list '%
- X (list '+
- X (math-mul (nth 1 lin) (nth 2 lin))
- X (math-mod (car lin) (nth 2 expr)))
- X (nth 2 expr)))
- X (and lin
- X (not (math-equal-int (nth 1 lin) 1))
- X (math-num-integerp (nth 1 lin))
- X (math-num-integerp (nth 2 expr))
- X (setq t1 (calcFunc-gcd (nth 1 lin) (nth 2 expr)))
- X (not (math-equal-int t1 1))
- X (list '*
- X t1
- X (list '%
- X (list '+
- X (math-mul (math-div (nth 1 lin) t1)
- X (nth 2 lin))
- X (let ((calc-prefer-frac t))
- X (math-div (car lin) t1)))
- X (math-div (nth 2 expr) t1))))
- X (and (math-equal-int (nth 2 expr) 1)
- X (math-known-integerp (if lin
- X (math-mul (nth 1 lin) (nth 2 lin))
- X (nth 1 expr)))
- X (if lin (math-mod (car lin) 1) 0)))))
- )
- X
- (math-defsimplify (calcFunc-eq calcFunc-neq calcFunc-lt
- X calcFunc-gt calcFunc-leq calcFunc-geq)
- X (if (= (length expr) 3)
- X (math-simplify-ineq)))
- X
- (defun math-simplify-ineq ()
- X (let ((np (cdr expr))
- X n)
- X (while (memq (car-safe (setq n (car np))) '(+ -))
- X (math-simplify-add-term (cdr (cdr n)) (cdr (cdr expr))
- X (eq (car n) '-) nil)
- X (setq np (cdr n)))
- X (math-simplify-add-term np (cdr (cdr expr)) nil (eq np (cdr expr)))
- X (math-simplify-divide)
- X (let ((signs (math-possible-signs (cons '- (cdr expr)))))
- X (or (cond ((eq (car expr) 'calcFunc-eq)
- X (or (and (eq signs 2) 1)
- X (and (memq signs '(1 4 5)) 0)))
- X ((eq (car expr) 'calcFunc-neq)
- X (or (and (eq signs 2) 0)
- X (and (memq signs '(1 4 5)) 1)))
- X ((eq (car expr) 'calcFunc-lt)
- X (or (and (eq signs 1) 1)
- X (and (memq signs '(2 4 6)) 0)))
- X ((eq (car expr) 'calcFunc-gt)
- X (or (and (eq signs 4) 1)
- X (and (memq signs '(1 2 3)) 0)))
- X ((eq (car expr) 'calcFunc-leq)
- X (or (and (eq signs 4) 0)
- X (and (memq signs '(1 2 3)) 1)))
- X ((eq (car expr) 'calcFunc-geq)
- X (or (and (eq signs 1) 0)
- X (and (memq signs '(2 4 6)) 1))))
- X expr)))
- )
- X
- (defun math-simplify-add-term (np dp minus lplain)
- X (or (math-vectorp (car np))
- X (let ((rplain t)
- X n d dd temp)
- X (while (memq (car-safe (setq n (car np) d (car dp))) '(+ -))
- X (setq rplain nil)
- X (if (setq temp (math-combine-sum n (nth 2 d)
- X minus (eq (car d) '+) t))
- X (if (or lplain (eq (math-looks-negp temp) minus))
- X (progn
- X (setcar np (setq n (if minus (math-neg temp) temp)))
- X (setcar (cdr (cdr d)) 0))
- X (progn
- X (setcar np 0)
- X (setcar (cdr (cdr d)) (setq n (if (eq (car d) '+)
- X (math-neg temp)
- X temp))))))
- X (setq dp (cdr d)))
- X (if (setq temp (math-combine-sum n d minus t t))
- X (if (or lplain
- X (and (not rplain)
- X (eq (math-looks-negp temp) minus)))
- X (progn
- X (setcar np (setq n (if minus (math-neg temp) temp)))
- X (setcar dp 0))
- X (progn
- X (setcar np 0)
- X (setcar dp (setq n (math-neg temp))))))))
- )
- X
- (math-defsimplify calcFunc-sin
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-sin (math-neg (nth 1 expr)))))
- X (and (eq calc-angle-mode 'rad)
- X (let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
- X (and n
- X (math-known-sin (car n) (nth 1 n) 120 0))))
- X (and (eq calc-angle-mode 'deg)
- X (let ((n (math-integer-plus (nth 1 expr))))
- X (and n
- X (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
- X (list 'calcFunc-sqrt (math-sub 1 (math-sqr (nth 1 (nth 1 expr))))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
- X (math-div (nth 1 (nth 1 expr))
- X (list 'calcFunc-sqrt
- X (math-add 1 (math-sqr (nth 1 (nth 1 expr)))))))
- X (let ((m (math-should-expand-trig (nth 1 expr))))
- X (and m (integerp (car m))
- X (let ((n (car m)) (a (nth 1 m)))
- X (list '+
- X (list '* (list 'calcFunc-sin (list '* (1- n) a))
- X (list 'calcFunc-cos a))
- X (list '* (list 'calcFunc-cos (list '* (1- n) a))
- X (list 'calcFunc-sin a)))))))
- )
- X
- (math-defsimplify calcFunc-cos
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (list 'calcFunc-cos (math-neg (nth 1 expr))))
- X (and (eq calc-angle-mode 'rad)
- X (let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
- X (and n
- X (math-known-sin (car n) (nth 1 n) 120 300))))
- X (and (eq calc-angle-mode 'deg)
- X (let ((n (math-integer-plus (nth 1 expr))))
- X (and n
- X (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
- X (list 'calcFunc-sqrt (math-sub 1 (math-sqr (nth 1 (nth 1 expr))))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
- X (math-div 1
- X (list 'calcFunc-sqrt
- X (math-add 1 (math-sqr (nth 1 (nth 1 expr)))))))
- X (let ((m (math-should-expand-trig (nth 1 expr))))
- X (and m (integerp (car m))
- X (let ((n (car m)) (a (nth 1 m)))
- X (list '-
- X (list '* (list 'calcFunc-cos (list '* (1- n) a))
- X (list 'calcFunc-cos a))
- X (list '* (list 'calcFunc-sin (list '* (1- n) a))
- X (list 'calcFunc-sin a)))))))
- )
- X
- (defun math-should-expand-trig (x &optional hyperbolic)
- X (let ((m (math-is-multiple x)))
- X (and math-living-dangerously
- X m (or (and (integerp (car m)) (> (car m) 1))
- X (equal (car m) '(frac 1 2)))
- X (or math-integrating
- X (memq (car-safe (nth 1 m))
- X (if hyperbolic
- X '(calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh)
- X '(calcFunc-arcsin calcFunc-arccos calcFunc-arctan)))
- X (and (eq (car-safe (nth 1 m)) 'calcFunc-ln)
- X (eq hyperbolic 'exp)))
- X m))
- )
- X
- (defun math-known-sin (plus n mul off)
- X (setq n (math-mul n mul))
- X (and (math-num-integerp n)
- X (setq n (math-mod (math-add (math-trunc n) off) 240))
- X (if (>= n 120)
- X (and (setq n (math-known-sin plus (- n 120) 1 0))
- X (math-neg n))
- X (if (> n 60)
- X (setq n (- 120 n)))
- X (if (math-zerop plus)
- X (and (or calc-symbolic-mode
- X (memq n '(0 20 60)))
- X (cdr (assq n
- X '( (0 . 0)
- X (10 . (/ (calcFunc-sqrt
- X (- 2 (calcFunc-sqrt 3))) 2))
- X (12 . (/ (- (calcFunc-sqrt 5) 1) 4))
- X (15 . (/ (calcFunc-sqrt
- X (- 2 (calcFunc-sqrt 2))) 2))
- X (20 . (/ 1 2))
- X (24 . (* (^ (/ 1 2) (/ 3 2))
- X (calcFunc-sqrt
- X (- 5 (calcFunc-sqrt 5)))))
- X (30 . (/ (calcFunc-sqrt 2) 2))
- X (36 . (/ (+ (calcFunc-sqrt 5) 1) 4))
- X (40 . (/ (calcFunc-sqrt 3) 2))
- X (45 . (/ (calcFunc-sqrt
- X (+ 2 (calcFunc-sqrt 2))) 2))
- X (48 . (* (^ (/ 1 2) (/ 3 2))
- X (calcFunc-sqrt
- X (+ 5 (calcFunc-sqrt 5)))))
- X (50 . (/ (calcFunc-sqrt
- X (+ 2 (calcFunc-sqrt 3))) 2))
- X (60 . 1)))))
- X (cond ((eq n 0) (math-normalize (list 'calcFunc-sin plus)))
- X ((eq n 60) (math-normalize (list 'calcFunc-cos plus)))
- X (t nil)))))
- )
- X
- (math-defsimplify calcFunc-tan
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctan)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-tan (math-neg (nth 1 expr)))))
- X (and (eq calc-angle-mode 'rad)
- X (let ((n (math-linear-in (nth 1 expr) '(var pi var-pi))))
- X (and n
- X (math-known-tan (car n) (nth 1 n) 120))))
- X (and (eq calc-angle-mode 'deg)
- X (let ((n (math-integer-plus (nth 1 expr))))
- X (and n
- X (math-known-tan (car n) (nth 1 n) '(frac 2 3)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsin)
- X (math-div (nth 1 (nth 1 expr))
- X (list 'calcFunc-sqrt
- X (math-sub 1 (math-sqr (nth 1 (nth 1 expr)))))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccos)
- X (math-div (list 'calcFunc-sqrt
- X (math-sub 1 (math-sqr (nth 1 (nth 1 expr)))))
- X (nth 1 (nth 1 expr))))
- X (let ((m (math-should-expand-trig (nth 1 expr))))
- X (and m
- X (if (equal (car m) '(frac 1 2))
- X (math-div (math-sub 1 (list 'calcFunc-cos (nth 1 m)))
- X (list 'calcFunc-sin (nth 1 m)))
- X (math-div (list 'calcFunc-sin (nth 1 expr))
- X (list 'calcFunc-cos (nth 1 expr)))))))
- )
- X
- (defun math-known-tan (plus n mul)
- X (setq n (math-mul n mul))
- X (and (math-num-integerp n)
- X (setq n (math-mod (math-trunc n) 120))
- X (if (> n 60)
- X (and (setq n (math-known-tan plus (- 120 n) 1))
- X (math-neg n))
- X (if (math-zerop plus)
- X (and (or calc-symbolic-mode
- X (memq n '(0 30 60)))
- X (cdr (assq n '( (0 . 0)
- X (10 . (- 2 (calcFunc-sqrt 3)))
- X (12 . (calcFunc-sqrt
- X (- 1 (* (/ 2 5) (calcFunc-sqrt 5)))))
- X (15 . (- (calcFunc-sqrt 2) 1))
- X (20 . (/ (calcFunc-sqrt 3) 3))
- X (24 . (calcFunc-sqrt
- X (- 5 (* 2 (calcFunc-sqrt 5)))))
- X (30 . 1)
- X (36 . (calcFunc-sqrt
- X (+ 1 (* (/ 2 5) (calcFunc-sqrt 5)))))
- X (40 . (calcFunc-sqrt 3))
- X (45 . (+ (calcFunc-sqrt 2) 1))
- X (48 . (calcFunc-sqrt
- X (+ 5 (* 2 (calcFunc-sqrt 5)))))
- X (50 . (+ 2 (calcFunc-sqrt 3)))
- X (60 . (var uinf var-uinf))))))
- X (cond ((eq n 0) (math-normalize (list 'calcFunc-tan plus)))
- X ((eq n 60) (math-normalize (list '/ -1
- X (list 'calcFunc-tan plus))))
- X (t nil)))))
- )
- X
- (math-defsimplify calcFunc-sinh
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsinh)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-sinh (math-neg (nth 1 expr)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccosh)
- X math-living-dangerously
- X (list 'calcFunc-sqrt (math-sub (math-sqr (nth 1 (nth 1 expr))) 1)))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctanh)
- X math-living-dangerously
- X (math-div (nth 1 (nth 1 expr))
- X (list 'calcFunc-sqrt
- X (math-sub 1 (math-sqr (nth 1 (nth 1 expr)))))))
- X (let ((m (math-should-expand-trig (nth 1 expr) t)))
- X (and m (integerp (car m))
- X (let ((n (car m)) (a (nth 1 m)))
- X (if (> n 1)
- X (list '+
- X (list '* (list 'calcFunc-sinh (list '* (1- n) a))
- X (list 'calcFunc-cosh a))
- X (list '* (list 'calcFunc-cosh (list '* (1- n) a))
- X (list 'calcFunc-sinh a))))))))
- )
- X
- (math-defsimplify calcFunc-cosh
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccosh)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (list 'calcFunc-cosh (math-neg (nth 1 expr))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsinh)
- X math-living-dangerously
- X (list 'calcFunc-sqrt (math-add (math-sqr (nth 1 (nth 1 expr))) 1)))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctanh)
- X math-living-dangerously
- X (math-div 1
- X (list 'calcFunc-sqrt
- X (math-sub 1 (math-sqr (nth 1 (nth 1 expr)))))))
- X (let ((m (math-should-expand-trig (nth 1 expr) t)))
- X (and m (integerp (car m))
- X (let ((n (car m)) (a (nth 1 m)))
- X (if (> n 1)
- X (list '+
- X (list '* (list 'calcFunc-cosh (list '* (1- n) a))
- X (list 'calcFunc-cosh a))
- X (list '* (list 'calcFunc-sinh (list '* (1- n) a))
- X (list 'calcFunc-sinh a))))))))
- )
- X
- (math-defsimplify calcFunc-tanh
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-arctanh)
- X (nth 1 (nth 1 expr)))
- X (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-tanh (math-neg (nth 1 expr)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arcsinh)
- X math-living-dangerously
- X (math-div (nth 1 (nth 1 expr))
- X (list 'calcFunc-sqrt
- X (math-add (math-sqr (nth 1 (nth 1 expr))) 1))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-arccosh)
- X math-living-dangerously
- X (math-div (list 'calcFunc-sqrt
- X (math-sub (math-sqr (nth 1 (nth 1 expr))) 1))
- X (nth 1 (nth 1 expr))))
- X (let ((m (math-should-expand-trig (nth 1 expr) t)))
- X (and m
- X (if (equal (car m) '(frac 1 2))
- X (math-div (math-sub (list 'calcFunc-cosh (nth 1 m)) 1)
- X (list 'calcFunc-sinh (nth 1 m)))
- X (math-div (list 'calcFunc-sinh (nth 1 expr))
- X (list 'calcFunc-cosh (nth 1 expr)))))))
- )
- X
- (math-defsimplify calcFunc-arcsin
- X (or (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-arcsin (math-neg (nth 1 expr)))))
- X (and (eq (nth 1 expr) 1)
- X (math-quarter-circle t))
- X (and (equal (nth 1 expr) '(frac 1 2))
- X (math-div (math-half-circle t) 6))
- X (and math-living-dangerously
- X (eq (car-safe (nth 1 expr)) 'calcFunc-sin)
- X (nth 1 (nth 1 expr)))
- X (and math-living-dangerously
- X (eq (car-safe (nth 1 expr)) 'calcFunc-cos)
- X (math-sub (math-quarter-circle t)
- X (nth 1 (nth 1 expr)))))
- )
- X
- (math-defsimplify calcFunc-arccos
- X (or (and (eq (nth 1 expr) 0)
- X (math-quarter-circle t))
- X (and (eq (nth 1 expr) -1)
- X (math-half-circle t))
- X (and (equal (nth 1 expr) '(frac 1 2))
- X (math-div (math-half-circle t) 3))
- X (and (equal (nth 1 expr) '(frac -1 2))
- X (math-div (math-mul (math-half-circle t) 2) 3))
- X (and math-living-dangerously
- X (eq (car-safe (nth 1 expr)) 'calcFunc-cos)
- X (nth 1 (nth 1 expr)))
- X (and math-living-dangerously
- X (eq (car-safe (nth 1 expr)) 'calcFunc-sin)
- X (math-sub (math-quarter-circle t)
- X (nth 1 (nth 1 expr)))))
- )
- X
- (math-defsimplify calcFunc-arctan
- X (or (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-arctan (math-neg (nth 1 expr)))))
- X (and (eq (nth 1 expr) 1)
- X (math-div (math-half-circle t) 4))
- X (and math-living-dangerously
- X (eq (car-safe (nth 1 expr)) 'calcFunc-tan)
- X (nth 1 (nth 1 expr))))
- )
- X
- (math-defsimplify calcFunc-arcsinh
- X (or (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-arcsinh (math-neg (nth 1 expr)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-sinh)
- X (or math-living-dangerously
- X (math-known-realp (nth 1 (nth 1 expr))))
- X (nth 1 (nth 1 expr))))
- )
- X
- (math-defsimplify calcFunc-arccosh
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-cosh)
- X (or math-living-dangerously
- X (math-known-realp (nth 1 (nth 1 expr))))
- X (nth 1 (nth 1 expr)))
- )
- X
- (math-defsimplify calcFunc-arctanh
- X (or (and (math-looks-negp (nth 1 expr))
- X (math-neg (list 'calcFunc-arctanh (math-neg (nth 1 expr)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-tanh)
- X (or math-living-dangerously
- X (math-known-realp (nth 1 (nth 1 expr))))
- X (nth 1 (nth 1 expr))))
- )
- X
- (math-defsimplify calcFunc-sqrt
- X (math-simplify-sqrt)
- )
- X
- (defun math-simplify-sqrt ()
- X (or (and (eq (car-safe (nth 1 expr)) 'frac)
- X (math-div (list 'calcFunc-sqrt (math-mul (nth 1 (nth 1 expr))
- X (nth 2 (nth 1 expr))))
- X (nth 2 (nth 1 expr))))
- X (let ((fac (if (math-objectp (nth 1 expr))
- X (math-squared-factor (nth 1 expr))
- X (math-common-constant-factor (nth 1 expr)))))
- X (and fac (not (eq fac 1))
- X (math-mul (math-normalize (list 'calcFunc-sqrt fac))
- X (math-normalize
- X (list 'calcFunc-sqrt
- X (math-cancel-common-factor (nth 1 expr) fac))))))
- X (and math-living-dangerously
- X (or (and (eq (car-safe (nth 1 expr)) '-)
- X (math-equal-int (nth 1 (nth 1 expr)) 1)
- X (eq (car-safe (nth 2 (nth 1 expr))) '^)
- X (math-equal-int (nth 2 (nth 2 (nth 1 expr))) 2)
- X (or (and (eq (car-safe (nth 1 (nth 2 (nth 1 expr))))
- X 'calcFunc-sin)
- X (list 'calcFunc-cos
- X (nth 1 (nth 1 (nth 2 (nth 1 expr))))))
- X (and (eq (car-safe (nth 1 (nth 2 (nth 1 expr))))
- X 'calcFunc-cos)
- X (list 'calcFunc-sin
- X (nth 1 (nth 1 (nth 2 (nth 1 expr))))))))
- X (and (eq (car-safe (nth 1 expr)) '-)
- X (math-equal-int (nth 2 (nth 1 expr)) 1)
- X (eq (car-safe (nth 1 (nth 1 expr))) '^)
- X (math-equal-int (nth 2 (nth 1 (nth 1 expr))) 2)
- X (and (eq (car-safe (nth 1 (nth 1 (nth 1 expr))))
- X 'calcFunc-cosh)
- X (list 'calcFunc-sinh
- X (nth 1 (nth 1 (nth 1 (nth 1 expr)))))))
- X (and (eq (car-safe (nth 1 expr)) '+)
- X (let ((a (nth 1 (nth 1 expr)))
- X (b (nth 2 (nth 1 expr))))
- X (and (or (and (math-equal-int a 1)
- X (setq a b b (nth 1 (nth 1 expr))))
- X (math-equal-int b 1))
- X (eq (car-safe a) '^)
- X (math-equal-int (nth 2 a) 2)
- X (or (and (eq (car-safe (nth 1 a)) 'calcFunc-sinh)
- X (list 'calcFunc-cosh (nth 1 (nth 1 a))))
- X (and (eq (car-safe (nth 1 a)) 'calcFunc-tan)
- X (list '/ 1 (list 'calcFunc-cos
- X (nth 1 (nth 1 a)))))))))
- X (and (eq (car-safe (nth 1 expr)) '^)
- X (list '^
- X (nth 1 (nth 1 expr))
- X (math-div (nth 2 (nth 1 expr)) 2)))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-sqrt)
- X (list '^ (nth 1 (nth 1 expr)) (math-div 1 4)))
- X (and (memq (car-safe (nth 1 expr)) '(* /))
- X (list (car (nth 1 expr))
- X (list 'calcFunc-sqrt (nth 1 (nth 1 expr)))
- X (list 'calcFunc-sqrt (nth 2 (nth 1 expr)))))
- X (and (memq (car-safe (nth 1 expr)) '(+ -))
- X (not (math-any-floats (nth 1 expr)))
- X (let ((f (calcFunc-factors (calcFunc-expand
- X (nth 1 expr)))))
- X (and (math-vectorp f)
- X (or (> (length f) 2)
- X (> (nth 2 (nth 1 f)) 1))
- X (let ((out 1) (rest 1) (sums 1) fac pow)
- X (while (setq f (cdr f))
- X (setq fac (nth 1 (car f))
- X pow (nth 2 (car f)))
- X (if (> pow 1)
- X (setq out (math-mul out (math-pow
- X fac (/ pow 2)))
- X pow (% pow 2)))
- X (if (> pow 0)
- X (if (memq (car-safe fac) '(+ -))
- X (setq sums (math-mul-thru sums fac))
- X (setq rest (math-mul rest fac)))))
- X (and (not (and (eq out 1) (memq rest '(1 -1))))
- X (math-mul
- X out
- X (list 'calcFunc-sqrt
- X (math-mul sums rest)))))))))))
- )
- X
- ;;; Rather than factoring x into primes, just check for the first ten primes.
- (defun math-squared-factor (x)
- X (if (Math-integerp x)
- X (let ((prsqr '(4 9 25 49 121 169 289 361 529 841))
- X (fac 1)
- X res)
- X (while prsqr
- X (if (eq (cdr (setq res (math-idivmod x (car prsqr)))) 0)
- X (setq x (car res)
- X fac (math-mul fac (car prsqr)))
- X (setq prsqr (cdr prsqr))))
- X fac))
- )
- X
- (math-defsimplify calcFunc-exp
- X (math-simplify-exp (nth 1 expr))
- )
- X
- (defun math-simplify-exp (x)
- X (or (and (eq (car-safe x) 'calcFunc-ln)
- X (nth 1 x))
- X (and math-living-dangerously
- X (or (and (eq (car-safe x) 'calcFunc-arcsinh)
- X (math-add (nth 1 x)
- X (list 'calcFunc-sqrt
- X (math-add (math-sqr (nth 1 x)) 1))))
- X (and (eq (car-safe x) 'calcFunc-arccosh)
- X (math-add (nth 1 x)
- X (list 'calcFunc-sqrt
- X (math-sub (math-sqr (nth 1 x)) 1))))
- X (and (eq (car-safe x) 'calcFunc-arctanh)
- X (math-div (list 'calcFunc-sqrt (math-add 1 (nth 1 x)))
- X (list 'calcFunc-sqrt (math-sub 1 (nth 1 x)))))
- X (let ((m (math-should-expand-trig x 'exp)))
- X (and m (integerp (car m))
- X (list '^ (list 'calcFunc-exp (nth 1 m)) (car m))))))
- X (and calc-symbolic-mode
- X (math-known-imagp x)
- X (let* ((ip (calcFunc-im x))
- X (n (math-linear-in ip '(var pi var-pi)))
- X s c)
- X (and n
- X (setq s (math-known-sin (car n) (nth 1 n) 120 0))
- X (setq c (math-known-sin (car n) (nth 1 n) 120 300))
- X (list '+ c (list '* s '(var i var-i)))))))
- )
- X
- (math-defsimplify calcFunc-ln
- X (or (and (eq (car-safe (nth 1 expr)) 'calcFunc-exp)
- X (or math-living-dangerously
- X (math-known-realp (nth 1 (nth 1 expr))))
- X (nth 1 (nth 1 expr)))
- X (and (eq (car-safe (nth 1 expr)) '^)
- X (equal (nth 1 (nth 1 expr)) '(var e var-e))
- X (or math-living-dangerously
- X (math-known-realp (nth 2 (nth 1 expr))))
- X (nth 2 (nth 1 expr)))
- X (and calc-symbolic-mode
- X (math-known-negp (nth 1 expr))
- X (math-add (list 'calcFunc-ln (math-neg (nth 1 expr)))
- X '(var pi var-pi)))
- X (and calc-symbolic-mode
- X (math-known-imagp (nth 1 expr))
- X (let* ((ip (calcFunc-im (nth 1 expr)))
- X (ips (math-possible-signs ip)))
- X (or (and (memq ips '(4 6))
- X (math-add (list 'calcFunc-ln ip)
- X '(/ (* (var pi var-pi) (var i var-i)) 2)))
- X (and (memq ips '(1 3))
- X (math-sub (list 'calcFunc-ln (math-neg ip))
- X '(/ (* (var pi var-pi) (var i var-i)) 2)))))))
- )
- X
- (math-defsimplify ^
- X (math-simplify-pow))
- X
- (defun math-simplify-pow ()
- X (or (and math-living-dangerously
- X (or (and (eq (car-safe (nth 1 expr)) '^)
- X (list '^
- X (nth 1 (nth 1 expr))
- X (math-mul (nth 2 expr) (nth 2 (nth 1 expr)))))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-sqrt)
- X (list '^
- X (nth 1 (nth 1 expr))
- X (math-div (nth 2 expr) 2)))
- X (and (memq (car-safe (nth 1 expr)) '(* /))
- X (list (car (nth 1 expr))
- X (list '^ (nth 1 (nth 1 expr)) (nth 2 expr))
- X (list '^ (nth 2 (nth 1 expr)) (nth 2 expr))))))
- X (and (math-equal-int (nth 1 expr) 10)
- X (eq (car-safe (nth 2 expr)) 'calcFunc-log10)
- X (nth 1 (nth 2 expr)))
- X (and (equal (nth 1 expr) '(var e var-e))
- X (math-simplify-exp (nth 2 expr)))
- X (and (eq (car-safe (nth 1 expr)) 'calcFunc-exp)
- X (not math-integrating)
- X (list 'calcFunc-exp (math-mul (nth 1 (nth 1 expr)) (nth 2 expr))))
- X (and (equal (nth 1 expr) '(var i var-i))
- X (math-imaginary-i)
- X (math-num-integerp (nth 2 expr))
- X (let ((x (math-mod (math-trunc (nth 2 expr)) 4)))
- X (cond ((eq x 0) 1)
- SHAR_EOF
- true || echo 'restore of calc-alg.el failed'
- fi
- echo 'End of part 7'
- echo 'File calc-alg.el is continued in part 8'
- echo 8 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-