Commit 3132f345 authored by Colin Walters's avatar Colin Walters
Browse files

Change all toplevel `setq' forms to `defvar' forms, and move them

before their first use.  Use `when', `unless'.  Remove trailing
periods from error forms.  Add description and headers suggested by
Emacs Lisp coding conventions.
parent f269b73e
2001-11-19 Colin Walters <walters@verbum.org>
* calc/calc-macs.el (calc-wrapper, calc-slow-wrapper)
(math-showing-full-precision, math-with-extra-prec, math-working)
(calc-with-default-simplification)
(calc-with-trail-buffer): Use backtick.
(Math-zerop, Math-integer-negp, Math-integer-posp, Math-negp)
(Math-looks-negp, Math-posp, Math-integerp, Math-natnump)
(Math-ratp, Math-realp, Math-anglep, Math-numberp, Math-scalarp)
(Math-vectorp, Math-messy-integerp, Math-objectp, Math-objvecp)
(Math-integer-neg, Math-equal, Math-lessp, Math-primp)
(Math-num-integerp, Math-bignum-test, Math-equal-int)
(Math-natnum-lessp, math-format-radix-digit): Change to `defsubst'.
(calc-record-compilation-date-macro): Deleted. Callers updated.
(math-format-radix-digit): Move to calc-bin.el.
* calc/calc.el (calc-record-compilation-date): Remove.
(calc-bug-address): Update.
(calc-settings-file): Use `user-init-file'.
* calc/calc-mode.el (calc-settings-file-name, calc-save-modes):
Handle null `calc-settings-file'.
* calc/calc-frac.el (calc-over-notation): Use `completing-read'.
* calc/calc-keypd.el (calc-keypad-mode): New.
(calc-do-keypad): Use it.
(calc-keypad-map): Move into `calc-keypad-mode'.
* calc-math.el (calcFunc-sqrt, calcFunc-hypot): Add missing quote
to defalias argument.
* calc-misc.el (math-fixnump, math-fixnatnump, calcFunc-trunc)
(calcFunc-floor): Ditto.
* calc-units.el (calcFunc-usimplify): Ditto.
* calc-aent.el, calc-ext.el, calc-incom.el, calc-misc.el
* calc-sel.el, calc-vec.el, calc-alg.el, calc-fin.el
* calc-keypd.el, calc-mode.el, calc-stat.el, calc-yank.el
* calc-arith.el, calc-forms.el, calc-lang.el, calc-mtx.el
* calc-store.el, calc.el, calc-bin.el, calc-frac.el, calc-macs.el
* calc-poly.el, calc-stuff.el, calcalg2.el, calc-comb.el
* calc-funcs.el, calc-maint.el, calc-prog.el, calc-trail.el
* calcalg3.el, calc-cplx.el, calc-graph.el, calc-map.el
* calc-rewr.el, calc-undo.el, calccomp.el, calc-embed.el
* calc-help.el, calc-math.el, calc-rules.el, calc-units.el
* calcsel2.el: Change all toplevel `setq' forms to `defvar' forms,
and move them before their first use. Use `when', `unless'.
Remove trailing periods from error forms. Add description and
headers suggested by Emacs Lisp coding conventions.
2001-11-19 Stefan Monnier <monnier@cs.yale.edu> 2001-11-19 Stefan Monnier <monnier@cs.yale.edu>
   
* newcomment.el (comment-indent): * newcomment.el (comment-indent):
......
;; Calculator for GNU Emacs, part I [calc-aent.el] ;;; calc-aent.el --- algebraic entry functions for Calc
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; Author: Dave Gillespie <daveg@synaptics.com>
;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -19,7 +22,9 @@ ...@@ -19,7 +22,9 @@
;; file named COPYING. Among other things, the copyright notice ;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies. ;; and this notice must be preserved on all copies.
;;; Commentary:
;;; Code:
;; This file is autoloaded from calc.el. ;; This file is autoloaded from calc.el.
(require 'calc) (require 'calc)
...@@ -55,15 +60,14 @@ ...@@ -55,15 +60,14 @@
(calc-extensions) (calc-extensions)
(math-evaluate-expr x)))) (math-evaluate-expr x))))
entry))) entry)))
(if (and (= (length alg-exp) 1) (when (and (= (length alg-exp) 1)
(eq (car-safe (car alg-exp)) 'calcFunc-assign) (eq (car-safe (car alg-exp)) 'calcFunc-assign)
(= (length (car alg-exp)) 3) (= (length (car alg-exp)) 3)
(eq (car-safe (nth 1 (car alg-exp))) 'var)) (eq (car-safe (nth 1 (car alg-exp))) 'var))
(progn (calc-extensions)
(calc-extensions) (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
(set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp))) (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
(calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp)))) (setq alg-exp (list (nth 2 (car alg-exp)))))
(setq alg-exp (list (nth 2 (car alg-exp))))))
(setq calc-quick-prev-results alg-exp (setq calc-quick-prev-results alg-exp
buf (mapconcat (function (lambda (x) buf (mapconcat (function (lambda (x)
(math-format-value x 1000))) (math-format-value x 1000)))
...@@ -97,8 +101,8 @@ ...@@ -97,8 +101,8 @@
(if (eq last-command-char 10) (if (eq last-command-char 10)
(insert shortbuf) (insert shortbuf)
(setq kill-ring (cons shortbuf kill-ring)) (setq kill-ring (cons shortbuf kill-ring))
(if (> (length kill-ring) kill-ring-max) (when (> (length kill-ring) kill-ring-max)
(setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
(setq kill-ring-yank-pointer kill-ring))))) (setq kill-ring-yank-pointer kill-ring)))))
(defun calc-do-calc-eval (str separator args) (defun calc-do-calc-eval (str separator args)
...@@ -294,8 +298,7 @@ ...@@ -294,8 +298,7 @@
(let* ((calc-buffer (current-buffer)) (let* ((calc-buffer (current-buffer))
(blink-paren-function 'calcAlg-blink-matching-open) (blink-paren-function 'calcAlg-blink-matching-open)
(alg-exp 'error)) (alg-exp 'error))
(if (boundp 'calc-alg-ent-map) (unless (boundp 'calc-alg-ent-map)
()
(setq calc-alg-ent-map (copy-keymap minibuffer-local-map)) (setq calc-alg-ent-map (copy-keymap minibuffer-local-map))
(define-key calc-alg-ent-map "'" 'calcAlg-previous) (define-key calc-alg-ent-map "'" 'calcAlg-previous)
(define-key calc-alg-ent-map "`" 'calcAlg-edit) (define-key calc-alg-ent-map "`" 'calcAlg-edit)
...@@ -307,8 +310,8 @@ ...@@ -307,8 +310,8 @@
(while (< i 127) (while (< i 127)
(aset calc-alg-ent-esc-map i 'calcAlg-escape) (aset calc-alg-ent-esc-map i 'calcAlg-escape)
(setq i (1+ i)))))) (setq i (1+ i))))))
(or calc-emacs-type-19 (unless calc-emacs-type-19
(define-key calc-alg-ent-map "\e" nil)) (define-key calc-alg-ent-map "\e" nil))
(if (eq calc-algebraic-mode 'total) (if (eq calc-algebraic-mode 'total)
(define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map) (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
(define-key calc-alg-ent-map "\ep" 'calcAlg-plus-minus) (define-key calc-alg-ent-map "\ep" 'calcAlg-plus-minus)
...@@ -320,9 +323,9 @@ ...@@ -320,9 +323,9 @@
(let ((buf (read-from-minibuffer (or prompt "Algebraic: ") (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
(or initial "") (or initial "")
calc-alg-ent-map nil))) calc-alg-ent-map nil)))
(if (eq alg-exp 'error) (when (eq alg-exp 'error)
(if (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error) (when (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error)
(setq alg-exp nil))) (setq alg-exp nil)))
(setq calc-aborted-prefix "alg'") (setq calc-aborted-prefix "alg'")
(or no-normalize (or no-normalize
(and alg-exp (setq alg-exp (mapcar 'calc-normalize alg-exp)))) (and alg-exp (setq alg-exp (mapcar 'calc-normalize alg-exp))))
...@@ -368,6 +371,7 @@ ...@@ -368,6 +371,7 @@
(use-local-map calc-mode-map)) (use-local-map calc-mode-map))
(calcAlg-enter)) (calcAlg-enter))
(defvar calc-plain-entry nil)
(defun calcAlg-edit () (defun calcAlg-edit ()
(interactive) (interactive)
(if (or (not calc-plain-entry) (if (or (not calc-plain-entry)
...@@ -377,7 +381,6 @@ ...@@ -377,7 +381,6 @@
(setq alg-exp (minibuffer-contents)) (setq alg-exp (minibuffer-contents))
(and (> (length alg-exp) 0) (setq calc-previous-alg-entry alg-exp)) (and (> (length alg-exp) 0) (setq calc-previous-alg-entry alg-exp))
(exit-minibuffer))) (exit-minibuffer)))
(setq calc-plain-entry nil)
(defun calcAlg-enter () (defun calcAlg-enter ()
(interactive) (interactive)
...@@ -482,11 +485,11 @@ ...@@ -482,11 +485,11 @@
(setq last rest))) (setq last rest)))
val)) val))
(setq calc-user-parse-table nil) (defvar calc-user-parse-table nil)
(setq calc-last-main-parse-table nil) (defvar calc-last-main-parse-table nil)
(setq calc-last-lang-parse-table nil) (defvar calc-last-lang-parse-table nil)
(setq calc-user-tokens nil) (defvar calc-user-tokens nil)
(setq calc-user-token-chars nil) (defvar calc-user-token-chars nil)
(defun math-build-parse-table () (defun math-build-parse-table ()
(let ((mtab (cdr (assq nil calc-user-parse-tables))) (let ((mtab (cdr (assq nil calc-user-parse-tables)))
......
;; Calculator for GNU Emacs, part II [calc-alg.el] ;;; calc-alg.el --- algebraic functions for Calc
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -19,7 +22,9 @@ ...@@ -19,7 +22,9 @@
;; file named COPYING. Among other things, the copyright notice ;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies. ;; and this notice must be preserved on all copies.
;;; Commentary:
;;; Code:
;; This file is autoloaded from calc-ext.el. ;; This file is autoloaded from calc-ext.el.
(require 'calc-ext) (require 'calc-ext)
...@@ -28,7 +33,6 @@ ...@@ -28,7 +33,6 @@
(defun calc-Need-calc-alg () nil) (defun calc-Need-calc-alg () nil)
;;; Algebra commands. ;;; Algebra commands.
(defun calc-alg-evaluate (arg) (defun calc-alg-evaluate (arg)
...@@ -169,7 +173,7 @@ ...@@ -169,7 +173,7 @@
(if (eq (car-safe old) 'error) (if (eq (car-safe old) 'error)
(error "Bad format in expression: %s" (nth 1 old))) (error "Bad format in expression: %s" (nth 1 old)))
(or (math-expr-contains expr old) (or (math-expr-contains expr old)
(error "No occurrences found."))) (error "No occurrences found")))
(calc-enter-result num "sbst" (math-expr-subst expr old new))))) (calc-enter-result num "sbst" (math-expr-subst expr old new)))))
......
;; Calculator for GNU Emacs, part II [calc-arith.el] ;;; calc-arith.el --- arithmetic functions for Calc
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -19,7 +22,9 @@ ...@@ -19,7 +22,9 @@
;; file named COPYING. Among other things, the copyright notice ;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies. ;; and this notice must be preserved on all copies.
;;; Commentary:
;;; Code:
;; This file is autoloaded from calc-ext.el. ;; This file is autoloaded from calc-ext.el.
(require 'calc-ext) (require 'calc-ext)
...@@ -148,9 +153,9 @@ ...@@ -148,9 +153,9 @@
;;;; Declarations. ;;;; Declarations.
(setq math-decls-cache-tag nil) (defvar math-decls-cache-tag nil)
(setq math-decls-cache nil) (defvar math-decls-cache nil)
(setq math-decls-all nil) (defvar math-decls-all nil)
;;; Math-decls-cache is an a-list where each entry is a list of the form: ;;; Math-decls-cache is an a-list where each entry is a list of the form:
;;; (VAR TYPES RANGE) ;;; (VAR TYPES RANGE)
...@@ -880,7 +885,7 @@ ...@@ -880,7 +885,7 @@
;;;; Arithmetic. ;;;; Arithmetic.
(defun calcFunc-neg (a) (defsubst calcFunc-neg (a)
(math-normalize (list 'neg a))) (math-normalize (list 'neg a)))
(defun math-neg-fancy (a) (defun math-neg-fancy (a)
...@@ -2351,7 +2356,7 @@ ...@@ -2351,7 +2356,7 @@
a a
(math-float (math-ceiling a prec)))) (math-float (math-ceiling a prec))))
(setq math-rounding-mode nil) (defvar math-rounding-mode nil)
;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public] ;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public]
(defun math-round (a &optional prec) (defun math-round (a &optional prec)
...@@ -2620,6 +2625,8 @@ ...@@ -2620,6 +2625,8 @@
(math-normalize (list '+ a b)) (math-normalize (list '+ a b))
(math-add a b))) (math-add a b)))
(defvar math-combine-prod-e '(var e var-e))
;;; The following is expanded out four ways for speed. ;;; The following is expanded out four ways for speed.
(defun math-combine-prod (a b inva invb scalar-okay) (defun math-combine-prod (a b inva invb scalar-okay)
(cond (cond
...@@ -2734,7 +2741,6 @@ ...@@ -2734,7 +2741,6 @@
(condition-case err (condition-case err
(math-pow a apow) (math-pow a apow)
(inexact-result (list '^ a apow))))))))))) (inexact-result (list '^ a apow)))))))))))
(setq math-combine-prod-e '(var e var-e))
(defun math-mul-or-div (a b ainv binv) (defun math-mul-or-div (a b ainv binv)
(if (or (Math-vectorp a) (Math-vectorp b)) (if (or (Math-vectorp a) (Math-vectorp b))
......
;; Calculator for GNU Emacs, part II [calc-bin.el] ;;; calc-bin.el --- binary functions for Calc
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -19,7 +22,9 @@ ...@@ -19,7 +22,9 @@
;; file named COPYING. Among other things, the copyright notice ;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies. ;; and this notice must be preserved on all copies.
;;; Commentary:
;;; Code:
;; This file is autoloaded from calc-ext.el. ;; This file is autoloaded from calc-ext.el.
(require 'calc-ext) (require 'calc-ext)
...@@ -143,8 +148,8 @@ ...@@ -143,8 +148,8 @@
(list n (math-power-of-2 (math-abs n))) (list n (math-power-of-2 (math-abs n)))
calc-leading-zeros))) calc-leading-zeros)))
(if (< n 0) (if (< n 0)
(message "Binary word size is %d bits (2's complement)." (- n)) (message "Binary word size is %d bits (2's complement)" (- n))
(message "Binary word size is %d bits." n)))) (message "Binary word size is %d bits" n))))
...@@ -161,7 +166,7 @@ ...@@ -161,7 +166,7 @@
;; also change global value so minibuffer sees it ;; also change global value so minibuffer sees it
(setq-default calc-number-radix calc-number-radix)) (setq-default calc-number-radix calc-number-radix))
(setq n calc-number-radix)) (setq n calc-number-radix))
(message "Number radix is %d." n))) (message "Number radix is %d" n)))
(defun calc-decimal-radix () (defun calc-decimal-radix ()
(interactive) (interactive)
...@@ -183,12 +188,12 @@ ...@@ -183,12 +188,12 @@
(interactive "P") (interactive "P")
(calc-wrapper (calc-wrapper
(if (calc-change-mode 'calc-leading-zeros n t t) (if (calc-change-mode 'calc-leading-zeros n t t)
(message "Zero-padding integers to %d digits (assuming radix %d)." (message "Zero-padding integers to %d digits (assuming radix %d)"
(let* ((calc-internal-prec 6)) (let* ((calc-internal-prec 6))
(math-compute-max-digits (math-abs calc-word-size) (math-compute-max-digits (math-abs calc-word-size)
calc-number-radix)) calc-number-radix))
calc-number-radix) calc-number-radix)
(message "Omitting leading zeros on integers.")))) (message "Omitting leading zeros on integers"))))
(defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024)) (defvar math-power-of-2-cache (list 1 2 4 8 16 32 64 128 256 512 1024))
...@@ -562,6 +567,9 @@ ...@@ -562,6 +567,9 @@
"K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T"
"U" "V" "W" "X" "Y" "Z"]) "U" "V" "W" "X" "Y" "Z"])
(defsubst math-format-radix-digit (a) ; [X D]
(aref math-radix-digits a))
(defun math-format-radix (a) ; [X S] (defun math-format-radix (a) ; [X S]
(if (< a calc-number-radix) (if (< a calc-number-radix)
(if (< a 0) (if (< a 0)
...@@ -750,6 +758,8 @@ ...@@ -750,6 +758,8 @@
(format "%se%s" str estr))))))) (format "%se%s" str estr)))))))
str)) str))
(defvar math-radix-digits-cache nil)
(defun math-convert-radix-digits (n &optional to-dec) (defun math-convert-radix-digits (n &optional to-dec)
(let ((key (cons n (cons to-dec calc-number-radix)))) (let ((key (cons n (cons to-dec calc-number-radix))))
(or (cdr (assoc key math-radix-digits-cache)) (or (cdr (assoc key math-radix-digits-cache))
...@@ -762,7 +772,7 @@ ...@@ -762,7 +772,7 @@
(math-div n log)))) (math-div n log))))
math-radix-digits-cache)))))))) math-radix-digits-cache))))))))
(setq math-radix-digits-cache nil) (defvar math-radix-float-cache-tag nil)
(defun math-radix-float-power (n) (defun math-radix-float-power (n)
(if (eq n 0) (if (eq n 0)
...@@ -792,6 +802,5 @@ ...@@ -792,6 +802,5 @@
calc-number-radix)))))) calc-number-radix))))))
math-radix-float-cache)))))))) math-radix-float-cache))))))))
(setq math-radix-float-cache-tag nil)
;;; calc-bin.el ends here ;;; calc-bin.el ends here
;; Calculator for GNU Emacs, part II [calc-comb.el] ;;; calc-comb.el --- combinatoric functions for Calc
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
;; Written by Dave Gillespie, daveg@synaptics.com.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Colin Walters <walters@debian.org>
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -19,7 +22,9 @@ ...@@ -19,7 +22,9 @@
;; file named COPYING. Among other things, the copyright notice ;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies. ;; and this notice must be preserved on all copies.
;;; Commentary:
;;; Code:
;; This file is autoloaded from calc-ext.el. ;; This file is autoloaded from calc-ext.el.
(require 'calc-ext) (require 'calc-ext)
...@@ -28,6 +33,53 @@ ...@@ -28,6 +33,53 @@
(defun calc-Need-calc-comb () nil) (defun calc-Need-calc-comb () nil)
(defconst math-primes-table
[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89
97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181
191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277
281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383
389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487
491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601
607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709
719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827
829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947
953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049
1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151
1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249
1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361
1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459
1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559
1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657
1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759
1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877
1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997
1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089
2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213
2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311
2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411
2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543
2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663
2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741
2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851
2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969
2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089
3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221
3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331
3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461
3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557
3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671
3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779
3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907
3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013
4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129
4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243
4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363
4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493
4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621
4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729
4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871
4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973
4987 4993 4999 5003])
;;; Combinatorics ;;; Combinatorics
...@@ -430,6 +482,7 @@ ...@@ -430,6 +482,7 @@
(defun calcFunc-stir2 (n m) (defun calcFunc-stir2 (n m)
(math-stirling-number n m 0)) (math-stirling-number n m 0))
(defvar math-stirling-cache (vector [[1]] [[1]]))
(defun math-stirling-number (n m k) (defun math-stirling-number (n m k)
(or (math-num-natnump n) (math-reject-arg n 'natnump)) (or (math-num-natnump n) (math-reject-arg n 'natnump))
(or (math-num-natnump m) (math-reject-arg m 'natnump)) (or (math-num-natnump m) (math-reject-arg m 'natnump))
...@@ -452,7 +505,6 @@ ...@@ -452,7 +505,6 @@
(if (= k 1) (if (= k 1)
(math-stirling-1 n m) (math-stirling-1 n m)
(math-stirling-2 n m))))) (math-stirling-2 n m)))))
(setq math-stirling-cache (vector [[1]] [[1]]))
(defun math-stirling-1 (n m) (defun math-stirling-1 (n m)
(or (aref (aref cache n) m) (or (aref (aref cache n) m)
...@@ -466,6 +518,11 @@ ...@@ -466,6 +518,11 @@
(math-add (math-stirling-2 (1- n) (1- m)) (math-add (math-stirling-2 (1- n) (1- m))
(math-mul m (math-stirling-2 (1- n) m))))))