annotate lisp/calc/calcalg2.el @ 58410:8d1aac87d0f4

(math-read-big-expr, math-read-big-bigp): Replace variable lines by math-read-big-lines. (math-read-big-expr): Replace variables the-baseline, the-h2 and err-msg by math-read-big-baseline, math-read-big-h2 and math-read-err-msg. (math-read-big-bigp): Replace variable h2 with math-rb-h2.
author Jay Belanger <jay.p.belanger@gmail.com>
date Mon, 22 Nov 2004 04:52:48 +0000
parents 7f5b01c17652
children 87c7dff39cb0 b637c617432f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1 ;;; calcalg2.el --- more algebraic functions for Calc
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
4
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
5 ;; Author: David Gillespie <daveg@synaptics.com>
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
6 ;; Maintainers: D. Goel <deego@gnufans.org>
49263
f4d68f97221e Add new maintainer (deego).
Deepak Goel <deego@gnufans.org>
parents: 43506
diff changeset
7 ;; Colin Walters <walters@debian.org>
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13 ;; accepts responsibility to anyone for the consequences of using it
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; or for whether it serves any particular purpose or works at all,
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16 ;; License for full details.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18 ;; Everyone is granted permission to copy, modify and redistribute
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; GNU Emacs, but only under the conditions described in the
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; GNU Emacs General Public License. A copy of this license is
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21 ;; supposed to have been given to you along with GNU Emacs so you
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22 ;; can know your rights and responsibilities. It should be in a
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23 ;; file named COPYING. Among other things, the copyright notice
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 ;; and this notice must be preserved on all copies.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
26 ;;; Commentary:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
28 ;;; Code:
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 ;; This file is autoloaded from calc-ext.el.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 (require 'calc-ext)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33 (require 'calc-macs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 (defun calc-Need-calc-alg-2 () nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
37
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
38 (defun calc-derivative (var num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
39 (interactive "sDifferentiate with respect to: \np")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
40 (calc-slow-wrapper
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
41 (when (< num 0)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
42 (error "Order of derivative must be positive"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
43 (let ((func (if (calc-is-hyperbolic) 'calcFunc-tderiv 'calcFunc-deriv))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
44 n expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
45 (if (or (equal var "") (equal var "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
46 (setq n 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
47 expr (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
48 var (calc-top-n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
49 (setq var (math-read-expr var))
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
50 (when (eq (car-safe var) 'error)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
51 (error "Bad format in expression: %s" (nth 1 var)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
52 (setq n 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
53 expr (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
54 (while (>= (setq num (1- num)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
55 (setq expr (list func expr var)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
56 (calc-enter-result n "derv" expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
57
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
58 (defun calc-integral (var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
59 (interactive "sIntegration variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
60 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
61 (if (or (equal var "") (equal var "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
62 (calc-enter-result 2 "intg" (list 'calcFunc-integ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
63 (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
64 (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
65 (let ((var (math-read-expr var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
66 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
67 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
68 (calc-enter-result 1 "intg" (list 'calcFunc-integ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
69 (calc-top-n 1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
70 var))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
71
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
72 (defun calc-num-integral (&optional varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
73 (interactive "sIntegration variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
74 (calc-tabular-command 'calcFunc-ninteg "Integration" "nint"
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
75 nil varname lowname highname))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
76
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
77 (defun calc-summation (arg &optional varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
78 (interactive "P\nsSummation variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
79 (calc-tabular-command 'calcFunc-sum "Summation" "sum"
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
80 arg varname lowname highname))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
81
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
82 (defun calc-alt-summation (arg &optional varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
83 (interactive "P\nsSummation variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
84 (calc-tabular-command 'calcFunc-asum "Summation" "asum"
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
85 arg varname lowname highname))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
86
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
87 (defun calc-product (arg &optional varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
88 (interactive "P\nsIndex variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
89 (calc-tabular-command 'calcFunc-prod "Index" "prod"
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
90 arg varname lowname highname))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
91
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
92 (defun calc-tabulate (arg &optional varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
93 (interactive "P\nsIndex variable: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
94 (calc-tabular-command 'calcFunc-table "Index" "tabl"
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
95 arg varname lowname highname))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
96
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
97 (defun calc-tabular-command (func prompt prefix arg varname lowname highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
99 (let (var (low nil) (high nil) (step nil) stepname stepnum (num 1) expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
100 (if (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
101 (setq stepnum 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
102 (setq stepnum 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
103 (if (or (equal varname "") (equal varname "$") (null varname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
104 (setq high (calc-top-n (+ stepnum 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
105 low (calc-top-n (+ stepnum 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
106 var (calc-top-n (+ stepnum 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
107 num (+ stepnum 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
108 (setq var (if (stringp varname) (math-read-expr varname) varname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
109 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
110 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
111 (or lowname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
112 (setq lowname (read-string (concat prompt " variable: " varname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113 ", from: "))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 (if (or (equal lowname "") (equal lowname "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115 (setq high (calc-top-n (+ stepnum 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 low (calc-top-n (+ stepnum 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 num (+ stepnum 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (setq low (if (stringp lowname) (math-read-expr lowname) lowname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (if (eq (car-safe low) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 (error "Bad format in expression: %s" (nth 1 low)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (or highname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 (setq highname (read-string (concat prompt " variable: " varname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 ", from: " lowname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 ", to: "))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 (if (or (equal highname "") (equal highname "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (setq high (calc-top-n (+ stepnum 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 num (+ stepnum 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (setq high (if (stringp highname) (math-read-expr highname)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 highname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (if (eq (car-safe high) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (error "Bad format in expression: %s" (nth 1 high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (if (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
133 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
134 (setq stepname (read-string (concat prompt " variable: "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 varname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 ", from: " lowname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 ", to: " highname
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 ", step: ")))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (if (or (equal stepname "") (equal stepname "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (setq step (calc-top-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 num 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (setq step (math-read-expr stepname))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (if (eq (car-safe step) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (error "Bad format in expression: %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145 (nth 1 step)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 (or step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 (if (consp arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 (setq step (calc-top-n 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 (if arg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (setq step (prefix-numeric-value arg)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (setq expr (calc-top-n num))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
152 (calc-enter-result num prefix (append (list func expr var low high)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
153 (and step (list step)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
155 (defun calc-solve-for (var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
156 (interactive "sVariable to solve for: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
157 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
158 (let ((func (if (calc-is-inverse)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
159 (if (calc-is-hyperbolic) 'calcFunc-ffinv 'calcFunc-finv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
160 (if (calc-is-hyperbolic) 'calcFunc-fsolve 'calcFunc-solve))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
161 (if (or (equal var "") (equal var "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
162 (calc-enter-result 2 "solv" (list func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
163 (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
164 (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
165 (let ((var (if (and (string-match ",\\|[^ ] +[^ ]" var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
166 (not (string-match "\\[" var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
167 (math-read-expr (concat "[" var "]"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
168 (math-read-expr var))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
169 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
170 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
171 (calc-enter-result 1 "solv" (list func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
172 (calc-top-n 1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
173 var)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
174
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
175 (defun calc-poly-roots (var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
176 (interactive "sVariable to solve for: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178 (if (or (equal var "") (equal var "$"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (calc-enter-result 2 "prts" (list 'calcFunc-roots
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 (calc-top-n 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 (calc-top-n 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182 (let ((var (if (and (string-match ",\\|[^ ] +[^ ]" var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183 (not (string-match "\\[" var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 (math-read-expr (concat "[" var "]"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 (math-read-expr var))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 (calc-enter-result 1 "prts" (list 'calcFunc-roots
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 (calc-top-n 1)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
190 var))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
191
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
192 (defun calc-taylor (var nterms)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
193 (interactive "sTaylor expansion variable: \nNNumber of terms: ")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
194 (calc-slow-wrapper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
195 (let ((var (math-read-expr var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
196 (if (eq (car-safe var) 'error)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
197 (error "Bad format in expression: %s" (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
198 (calc-enter-result 1 "tylr" (list 'calcFunc-taylor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
199 (calc-top-n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
200 var
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
201 (prefix-numeric-value nterms))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
202
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
203
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
204 ;; The following are global variables used by math-derivative and some
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
205 ;; related functions
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
206 (defvar math-deriv-var)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
207 (defvar math-deriv-total)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
208 (defvar math-deriv-symb)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
209
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
210 (defun math-derivative (expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
211 (cond ((equal expr math-deriv-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
212 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
213 ((or (Math-scalarp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
214 (eq (car expr) 'sdev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
215 (and (eq (car expr) 'var)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
216 (or (not math-deriv-total)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
217 (math-const-var expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
218 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
219 (math-setup-declarations)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
220 (memq 'const (nth 1 (or (assq (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
221 math-decls-cache)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
222 math-decls-all)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
223 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
224 ((eq (car expr) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
225 (math-add (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
226 (math-derivative (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
227 ((eq (car expr) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
228 (math-sub (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
229 (math-derivative (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
230 ((memq (car expr) '(calcFunc-eq calcFunc-neq calcFunc-lt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
231 calcFunc-gt calcFunc-leq calcFunc-geq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
232 (list (car expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
233 (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
234 (math-derivative (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
235 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
236 (math-neg (math-derivative (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
237 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
238 (math-add (math-mul (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
239 (math-derivative (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
240 (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
241 (math-derivative (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
242 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
243 (math-sub (math-div (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
244 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
245 (math-div (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
246 (math-derivative (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
247 (math-sqr (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
248 ((eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
249 (let ((du (math-derivative (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
250 (dv (math-derivative (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
251 (or (Math-zerop du)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
252 (setq du (math-mul (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
253 (math-mul (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
254 (list '^
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
255 (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
256 (math-add (nth 2 expr) -1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
257 du))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
258 (or (Math-zerop dv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
259 (setq dv (math-mul (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
260 (list 'calcFunc-ln (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
261 (math-mul expr dv))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
262 (math-add du dv)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
263 ((eq (car expr) '%)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
264 (math-derivative (nth 1 expr))) ; a reasonable definition
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
265 ((eq (car expr) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
266 (math-map-vec 'math-derivative expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
267 ((and (memq (car expr) '(calcFunc-conj calcFunc-re calcFunc-im))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
268 (= (length expr) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
269 (list (car expr) (math-derivative (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
270 ((and (memq (car expr) '(calcFunc-subscr calcFunc-mrow calcFunc-mcol))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
271 (= (length expr) 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
272 (let ((d (math-derivative (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
273 (if (math-numberp d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
274 0 ; assume x and x_1 are independent vars
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
275 (list (car expr) d (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
276 (t (or (and (symbolp (car expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
277 (if (= (length expr) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
278 (let ((handler (get (car expr) 'math-derivative)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
279 (and handler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
280 (let ((deriv (math-derivative (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
281 (if (Math-zerop deriv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
282 deriv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
283 (math-mul (funcall handler (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
284 deriv)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
285 (let ((handler (get (car expr) 'math-derivative-n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
286 (and handler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
287 (funcall handler expr)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
288 (and (not (eq math-deriv-symb 'pre-expand))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
289 (let ((exp (math-expand-formula expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
290 (and exp
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
291 (or (let ((math-deriv-symb 'pre-expand))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
292 (catch 'math-deriv (math-derivative expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
293 (math-derivative exp)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
294 (if (or (Math-objvecp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
295 (eq (car expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
296 (not (symbolp (car expr))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
297 (if math-deriv-symb
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
298 (throw 'math-deriv nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
299 (list (if math-deriv-total 'calcFunc-tderiv 'calcFunc-deriv)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
300 expr
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
301 math-deriv-var))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
302 (let ((accum 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
303 (arg expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
304 (n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
305 derv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
306 (while (setq arg (cdr arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
307 (or (Math-zerop (setq derv (math-derivative (car arg))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
308 (let ((func (intern (concat (symbol-name (car expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
309 "'"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
310 (if (> n 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
311 (int-to-string n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
312 ""))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
313 (prop (cond ((= (length expr) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
314 'math-derivative-1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
315 ((= (length expr) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
316 'math-derivative-2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
317 ((= (length expr) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
318 'math-derivative-3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
319 ((= (length expr) 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
320 'math-derivative-4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
321 ((= (length expr) 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
322 'math-derivative-5))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
323 (setq accum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
324 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
325 accum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
326 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
327 derv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
328 (let ((handler (get func prop)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
329 (or (and prop handler
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
330 (apply handler (cdr expr)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
331 (if (and math-deriv-symb
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
332 (not (get func
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
333 'calc-user-defn)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
334 (throw 'math-deriv nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
335 (cons func (cdr expr))))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
336 (setq n (1+ n)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
337 accum))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
338
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
339 (defun calcFunc-deriv (expr math-deriv-var &optional deriv-value math-deriv-symb)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
340 (let* ((math-deriv-total nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
341 (res (catch 'math-deriv (math-derivative expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
342 (or (eq (car-safe res) 'calcFunc-deriv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
343 (null res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
344 (setq res (math-normalize res)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
345 (and res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
346 (if deriv-value
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
347 (math-expr-subst res math-deriv-var deriv-value)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
348 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
349
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
350 (defun calcFunc-tderiv (expr math-deriv-var &optional deriv-value math-deriv-symb)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
351 (math-setup-declarations)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
352 (let* ((math-deriv-total t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
353 (res (catch 'math-deriv (math-derivative expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
354 (or (eq (car-safe res) 'calcFunc-tderiv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
355 (null res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
356 (setq res (math-normalize res)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
357 (and res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
358 (if deriv-value
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
359 (math-expr-subst res math-deriv-var deriv-value)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
360 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
361
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
362 (put 'calcFunc-inv\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
363 (function (lambda (u) (math-neg (math-div 1 (math-sqr u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
364
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
365 (put 'calcFunc-sqrt\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
366 (function (lambda (u) (math-div 1 (math-mul 2 (list 'calcFunc-sqrt u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
367
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
368 (put 'calcFunc-deg\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
369 (function (lambda (u) (math-div-float '(float 18 1) (math-pi)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
370
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
371 (put 'calcFunc-rad\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
372 (function (lambda (u) (math-pi-over-180))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
373
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
374 (put 'calcFunc-ln\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
375 (function (lambda (u) (math-div 1 u))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
376
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
377 (put 'calcFunc-log10\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
378 (function (lambda (u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
379 (math-div (math-div 1 (math-normalize '(calcFunc-ln 10)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
380 u))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
381
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
382 (put 'calcFunc-lnp1\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
383 (function (lambda (u) (math-div 1 (math-add u 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
384
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
385 (put 'calcFunc-log\' 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
386 (function (lambda (x b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
387 (and (not (Math-zerop b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
388 (let ((lnv (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
389 (list 'calcFunc-ln b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
390 (math-div 1 (math-mul lnv x)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
391
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
392 (put 'calcFunc-log\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
393 (function (lambda (x b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
394 (let ((lnv (list 'calcFunc-ln b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
395 (math-neg (math-div (list 'calcFunc-log x b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
396 (math-mul lnv b)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
397
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
398 (put 'calcFunc-exp\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
399 (function (lambda (u) (math-normalize (list 'calcFunc-exp u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
400
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
401 (put 'calcFunc-expm1\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
402 (function (lambda (u) (math-normalize (list 'calcFunc-expm1 u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
403
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
404 (put 'calcFunc-sin\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
405 (function (lambda (u) (math-to-radians-2 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
406 (list 'calcFunc-cos u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
407
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
408 (put 'calcFunc-cos\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
409 (function (lambda (u) (math-neg (math-to-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
410 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
411 (list 'calcFunc-sin u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
412
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
413 (put 'calcFunc-tan\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
414 (function (lambda (u) (math-to-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
415 (math-div 1 (math-sqr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
416 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
417 (list 'calcFunc-cos u))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
418
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
419 (put 'calcFunc-arcsin\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
420 (function (lambda (u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
421 (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
422 (math-div 1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
423 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
424 (math-sub 1 (math-sqr u)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
425
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
426 (put 'calcFunc-arccos\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
427 (function (lambda (u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
428 (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
429 (math-div -1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
430 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
431 (math-sub 1 (math-sqr u)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
432
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
433 (put 'calcFunc-arctan\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
434 (function (lambda (u) (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
435 (math-div 1 (math-add 1 (math-sqr u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
436
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
437 (put 'calcFunc-sinh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
438 (function (lambda (u) (math-normalize (list 'calcFunc-cosh u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
439
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
440 (put 'calcFunc-cosh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
441 (function (lambda (u) (math-normalize (list 'calcFunc-sinh u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
442
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
443 (put 'calcFunc-tanh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
444 (function (lambda (u) (math-div 1 (math-sqr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
445 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
446 (list 'calcFunc-cosh u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
447
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
448 (put 'calcFunc-arcsinh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
449 (function (lambda (u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
450 (math-div 1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
451 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
452 (math-add (math-sqr u) 1)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
453
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
454 (put 'calcFunc-arccosh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
455 (function (lambda (u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
456 (math-div 1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
457 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
458 (math-add (math-sqr u) -1)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
459
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
460 (put 'calcFunc-arctanh\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
461 (function (lambda (u) (math-div 1 (math-sub 1 (math-sqr u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
462
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
463 (put 'calcFunc-bern\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
464 (function (lambda (n x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
465 (math-mul n (list 'calcFunc-bern (math-add n -1) x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
466
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
467 (put 'calcFunc-euler\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
468 (function (lambda (n x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
469 (math-mul n (list 'calcFunc-euler (math-add n -1) x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
470
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
471 (put 'calcFunc-gammag\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
472 (function (lambda (a x) (math-deriv-gamma a x 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
473
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
474 (put 'calcFunc-gammaG\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
475 (function (lambda (a x) (math-deriv-gamma a x -1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
476
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
477 (put 'calcFunc-gammaP\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
478 (function (lambda (a x) (math-deriv-gamma a x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
479 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
480 1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
481 (list 'calcFunc-gamma
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
482 a)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
483
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
484 (put 'calcFunc-gammaQ\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
485 (function (lambda (a x) (math-deriv-gamma a x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
486 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
487 -1 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
488 (list 'calcFunc-gamma
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
489 a)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
490
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
491 (defun math-deriv-gamma (a x scale)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
492 (math-mul scale
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
493 (math-mul (math-pow x (math-add a -1))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
494 (list 'calcFunc-exp (math-neg x)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
495
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
496 (put 'calcFunc-betaB\' 'math-derivative-3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
497 (function (lambda (x a b) (math-deriv-beta x a b 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
498
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
499 (put 'calcFunc-betaI\' 'math-derivative-3
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
500 (function (lambda (x a b) (math-deriv-beta x a b
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
501 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
502 1 (list 'calcFunc-beta
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
503 a b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
504
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
505 (defun math-deriv-beta (x a b scale)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
506 (math-mul (math-mul (math-pow x (math-add a -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
507 (math-pow (math-sub 1 x) (math-add b -1)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
508 scale))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
509
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
510 (put 'calcFunc-erf\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
511 (function (lambda (x) (math-div 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
512 (math-mul (list 'calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
513 (math-sqr x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
514 (if calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
515 '(calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
516 (var pi var-pi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
517 (math-sqrt-pi)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
518
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
519 (put 'calcFunc-erfc\' 'math-derivative-1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
520 (function (lambda (x) (math-div -2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
521 (math-mul (list 'calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
522 (math-sqr x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
523 (if calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
524 '(calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
525 (var pi var-pi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
526 (math-sqrt-pi)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
527
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
528 (put 'calcFunc-besJ\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
529 (function (lambda (v z) (math-div (math-sub (list 'calcFunc-besJ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
530 (math-add v -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
531 z)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
532 (list 'calcFunc-besJ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
533 (math-add v 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
534 z))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
535 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
536
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
537 (put 'calcFunc-besY\'2 'math-derivative-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
538 (function (lambda (v z) (math-div (math-sub (list 'calcFunc-besY
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
539 (math-add v -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
540 z)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
541 (list 'calcFunc-besY
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
542 (math-add v 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
543 z))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
544 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
545
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
546 (put 'calcFunc-sum 'math-derivative-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
547 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
548 (lambda (expr)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
549 (if (math-expr-contains (cons 'vec (cdr (cdr expr))) math-deriv-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
550 (throw 'math-deriv nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
551 (cons 'calcFunc-sum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
552 (cons (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
553 (cdr (cdr expr))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
554
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
555 (put 'calcFunc-prod 'math-derivative-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
556 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
557 (lambda (expr)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
558 (if (math-expr-contains (cons 'vec (cdr (cdr expr))) math-deriv-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
559 (throw 'math-deriv nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
560 (math-mul expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
561 (cons 'calcFunc-sum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
562 (cons (math-div (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
563 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
564 (cdr (cdr expr)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
565
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
566 (put 'calcFunc-integ 'math-derivative-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
567 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
568 (lambda (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
569 (if (= (length expr) 3)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
570 (if (equal (nth 2 expr) math-deriv-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
571 (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
572 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
573 (list 'calcFunc-integ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
574 (math-derivative (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
575 (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
576 (if (= (length expr) 5)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
577 (let ((lower (math-expr-subst (nth 1 expr) (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
578 (nth 3 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
579 (upper (math-expr-subst (nth 1 expr) (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
580 (nth 4 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
581 (math-add (math-sub (math-mul upper
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
582 (math-derivative (nth 4 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
583 (math-mul lower
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
584 (math-derivative (nth 3 expr))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
585 (if (equal (nth 2 expr) math-deriv-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
586 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
587 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
588 (list 'calcFunc-integ
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
589 (math-derivative (nth 1 expr)) (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
590 (nth 3 expr) (nth 4 expr)))))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
591
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
592 (put 'calcFunc-if 'math-derivative-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
593 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
594 (lambda (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
595 (and (= (length expr) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
596 (list 'calcFunc-if (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
597 (math-derivative (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
598 (math-derivative (nth 3 expr)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
599
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
600 (put 'calcFunc-subscr 'math-derivative-n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
601 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
602 (lambda (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
603 (and (= (length expr) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
604 (list 'calcFunc-subscr (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
605 (math-derivative (nth 2 expr)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
606
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
607
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
608 (defvar math-integ-var '(var X ---))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
609 (defvar math-integ-var-2 '(var Y ---))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
610 (defvar math-integ-vars (list 'f math-integ-var math-integ-var-2))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
611 (defvar math-integ-var-list (list math-integ-var))
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
612 (defvar math-integ-var-list-list (list math-integ-var-list))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
613
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
614 ;; math-integ-depth is a local variable for math-try-integral, but is used
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
615 ;; by math-integral and math-tracing-integral
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
616 ;; which are called (directly or indirectly) by math-try-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
617 (defvar math-integ-depth)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
618 ;; math-integ-level is a local variable for math-try-integral, but is used
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
619 ;; by math-integral, math-do-integral, math-tracing-integral,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
620 ;; math-sub-integration, math-integrate-by-parts and
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
621 ;; math-integrate-by-substitution, which are called (directly or
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
622 ;; indirectly) by math-try-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
623 (defvar math-integ-level)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
624 ;; math-integral-limit is a local variable for calcFunc-integ, but is
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
625 ;; used by math-tracing-integral, math-sub-integration and
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
626 ;; math-try-integration.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
627 (defvar math-integral-limit)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
628
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
629 (defmacro math-tracing-integral (&rest parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
630 (list 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
631 'trace-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
632 (list 'save-excursion
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
633 '(set-buffer trace-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
634 '(goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
635 (list 'and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
636 '(bolp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
637 '(insert (make-string (- math-integral-limit
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
638 math-integ-level) 32)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
639 (format "%2d " math-integ-depth)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
640 (make-string math-integ-level 32)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
641 ;;(list 'condition-case 'err
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
642 (cons 'insert parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
643 ;; '(error (insert (prin1-to-string err))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
644 '(sit-for 0))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
645
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
646 ;;; The following wrapper caches results and avoids infinite recursion.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
647 ;;; Each cache entry is: ( A B ) Integral of A is B;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
648 ;;; ( A N ) Integral of A failed at level N;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
649 ;;; ( A busy ) Currently working on integral of A;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
650 ;;; ( A parts ) Currently working, integ-by-parts;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
651 ;;; ( A parts2 ) Currently working, integ-by-parts;
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
652 ;;; ( A cancelled ) Ignore this cache entry;
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
653 ;;; ( A [B] ) Same result as for math-cur-record = B.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
654
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
655 ;; math-cur-record is a local variable for math-try-integral, but is used
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
656 ;; by math-integral, math-replace-integral-parts and math-integrate-by-parts
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
657 ;; which are called (directly or indirectly) by math-try-integral, as well as
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
658 ;; by calc-dump-integral-cache
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
659 (defvar math-cur-record)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
660 ;; math-enable-subst and math-any-substs are local variables for
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
661 ;; calcFunc-integ, but are used by math-integral and math-try-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
662 (defvar math-enable-subst)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
663 (defvar math-any-substs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
664
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
665 ;; math-integ-msg is a local variable for math-try-integral, but is
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
666 ;; used (both locally and non-locally) by math-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
667 (defvar math-integ-msg)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
668
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
669 (defvar math-integral-cache nil)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
670 (defvar math-integral-cache-state nil)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
671
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
672 (defun math-integral (expr &optional simplify same-as-above)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
673 (let* ((simp math-cur-record)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
674 (math-cur-record (assoc expr math-integral-cache))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
675 (math-integ-depth (1+ math-integ-depth))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
676 (val 'cancelled))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
677 (math-tracing-integral "Integrating "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
678 (math-format-value expr 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
679 "...\n")
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
680 (and math-cur-record
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
681 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
682 (math-tracing-integral "Found "
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
683 (math-format-value (nth 1 math-cur-record) 1000))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
684 (and (consp (nth 1 math-cur-record))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
685 (math-replace-integral-parts math-cur-record))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
686 (math-tracing-integral " => "
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
687 (math-format-value (nth 1 math-cur-record) 1000)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
688 "\n")))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
689 (or (and math-cur-record
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
690 (not (eq (nth 1 math-cur-record) 'cancelled))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
691 (or (not (integerp (nth 1 math-cur-record)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
692 (>= (nth 1 math-cur-record) math-integ-level)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
693 (and (math-integral-contains-parts expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
694 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
695 (setq val nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
696 t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
697 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
698 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
699 (let (math-integ-msg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
700 (if (eq calc-display-working-message 'lots)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
701 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
702 (calc-set-command-flag 'clear-message)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
703 (setq math-integ-msg (format
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
704 "Working... Integrating %s"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
705 (math-format-flat-expr expr 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
706 (message math-integ-msg)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
707 (if math-cur-record
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
708 (setcar (cdr math-cur-record)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
709 (if same-as-above (vector simp) 'busy))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
710 (setq math-cur-record
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
711 (list expr (if same-as-above (vector simp) 'busy))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
712 math-integral-cache (cons math-cur-record
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
713 math-integral-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
714 (if (eq simplify 'yes)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
715 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
716 (math-tracing-integral "Simplifying...")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
717 (setq simp (math-simplify expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
718 (setq val (if (equal simp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
719 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
720 (math-tracing-integral " no change\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
721 (math-do-integral expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
722 (math-tracing-integral " simplified\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
723 (math-integral simp 'no t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
724 (or (setq val (math-do-integral expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
725 (eq simplify 'no)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
726 (let ((simp (math-simplify expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
727 (or (equal simp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
728 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
729 (math-tracing-integral "Trying again after "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
730 "simplification...\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
731 (setq val (math-integral simp 'no t))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
732 (if (eq calc-display-working-message 'lots)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
733 (message math-integ-msg)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
734 (setcar (cdr math-cur-record) (or val
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
735 (if (or math-enable-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
736 (not math-any-substs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
737 math-integ-level
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
738 'cancelled)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
739 (setq val math-cur-record)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
740 (while (vectorp (nth 1 val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
741 (setq val (aref (nth 1 val) 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
742 (setq val (if (memq (nth 1 val) '(parts parts2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
743 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
744 (setcar (cdr val) 'parts2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
745 (list 'var 'PARTS val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
746 (and (consp (nth 1 val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
747 (nth 1 val))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
748 (math-tracing-integral "Integral of "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
749 (math-format-value expr 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
750 " is "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
751 (math-format-value val 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
752 "\n")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
753 val))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
754
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
755 (defun math-integral-contains-parts (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
756 (if (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
757 (and (eq (car-safe expr) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
758 (eq (nth 1 expr) 'PARTS)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
759 (listp (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
760 (while (and (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
761 (not (math-integral-contains-parts (car expr)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
762 expr))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
763
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
764 (defun math-replace-integral-parts (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
765 (or (Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
766 (while (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
767 (and (consp (car expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
768 (if (eq (car (car expr)) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
769 (and (eq (nth 1 (car expr)) 'PARTS)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
770 (consp (nth 2 (car expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
771 (if (listp (nth 1 (nth 2 (car expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
772 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
773 (setcar expr (nth 1 (nth 2 (car expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
774 (math-replace-integral-parts (cons 'foo expr)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
775 (setcar (cdr math-cur-record) 'cancelled)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
776 (math-replace-integral-parts (car expr)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
777
58023
768b8e4f123b (math-linear-subst-tried): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
778 (defvar math-linear-subst-tried t
768b8e4f123b (math-linear-subst-tried): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
779 "Non-nil means that a linear substitution has been tried.")
768b8e4f123b (math-linear-subst-tried): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
780
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
781 ;; The variable math-has-rules is a local variable for math-try-integral,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
782 ;; but is used by math-do-integral, which is called (non-directly) by
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
783 ;; math-try-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
784 (defvar math-has-rules)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
785
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
786 ;; math-old-integ is a local variable for math-do-integral, but is
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
787 ;; used by math-sub-integration.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
788 (defvar math-old-integ)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
789
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
790 ;; The variables math-t1, math-t2 and math-t3 are local to
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
791 ;; math-do-integral, math-try-solve-for and math-decompose-poly, but
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
792 ;; are used by functions they call (directly or indirectly);
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
793 ;; math-do-integral calls math-do-integral-methods;
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
794 ;; math-try-solve-for calls math-try-solve-prod,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
795 ;; math-solve-find-root-term and math-solve-find-root-in-prod;
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
796 ;; math-decompose-poly calls math-solve-poly-funny-powers and
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
797 ;; math-solve-crunch-poly.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
798 (defvar math-t1)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
799 (defvar math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
800 (defvar math-t3)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
801
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
802 (defun math-do-integral (expr)
58023
768b8e4f123b (math-linear-subst-tried): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
803 (let ((math-linear-subst-tried nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
804 math-t1 math-t2)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
805 (or (cond ((not (math-expr-contains expr math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
806 (math-mul expr math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
807 ((equal expr math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
808 (math-div (math-sqr expr) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
809 ((eq (car expr) '+)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
810 (and (setq math-t1 (math-integral (nth 1 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
811 (setq math-t2 (math-integral (nth 2 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
812 (math-add math-t1 math-t2)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
813 ((eq (car expr) '-)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
814 (and (setq math-t1 (math-integral (nth 1 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
815 (setq math-t2 (math-integral (nth 2 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
816 (math-sub math-t1 math-t2)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
817 ((eq (car expr) 'neg)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
818 (and (setq math-t1 (math-integral (nth 1 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
819 (math-neg math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
820 ((eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
821 (cond ((not (math-expr-contains (nth 1 expr) math-integ-var))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
822 (and (setq math-t1 (math-integral (nth 2 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
823 (math-mul (nth 1 expr) math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
824 ((not (math-expr-contains (nth 2 expr) math-integ-var))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
825 (and (setq math-t1 (math-integral (nth 1 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
826 (math-mul math-t1 (nth 2 expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
827 ((memq (car-safe (nth 1 expr)) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
828 (math-integral (list (car (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
829 (math-mul (nth 1 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
830 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
831 (math-mul (nth 2 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
832 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
833 'yes t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
834 ((memq (car-safe (nth 2 expr)) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
835 (math-integral (list (car (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
836 (math-mul (nth 1 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
837 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
838 (math-mul (nth 2 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
839 (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
840 'yes t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
841 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
842 (cond ((and (not (math-expr-contains (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
843 math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
844 (not (math-equal-int (nth 1 expr) 1)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
845 (and (setq math-t1 (math-integral (math-div 1 (nth 2 expr))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
846 (math-mul (nth 1 expr) math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
847 ((not (math-expr-contains (nth 2 expr) math-integ-var))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
848 (and (setq math-t1 (math-integral (nth 1 expr)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
849 (math-div math-t1 (nth 2 expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
850 ((and (eq (car-safe (nth 1 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
851 (not (math-expr-contains (nth 1 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
852 math-integ-var)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
853 (and (setq math-t1 (math-integral
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
854 (math-div (nth 2 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
855 (nth 2 expr))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
856 (math-mul math-t1 (nth 1 (nth 1 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
857 ((and (eq (car-safe (nth 1 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
858 (not (math-expr-contains (nth 2 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
859 math-integ-var)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
860 (and (setq math-t1 (math-integral
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
861 (math-div (nth 1 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
862 (nth 2 expr))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
863 (math-mul math-t1 (nth 2 (nth 1 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
864 ((and (eq (car-safe (nth 2 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
865 (not (math-expr-contains (nth 1 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
866 math-integ-var)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
867 (and (setq math-t1 (math-integral
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
868 (math-div (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
869 (nth 2 (nth 2 expr)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
870 (math-div math-t1 (nth 1 (nth 2 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
871 ((and (eq (car-safe (nth 2 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
872 (not (math-expr-contains (nth 2 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
873 math-integ-var)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
874 (and (setq math-t1 (math-integral
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
875 (math-div (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
876 (nth 1 (nth 2 expr)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
877 (math-div math-t1 (nth 2 (nth 2 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
878 ((eq (car-safe (nth 2 expr)) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
879 (math-integral
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
880 (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
881 (list 'calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
882 (math-neg (nth 1 (nth 2 expr)))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
883 ((eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
884 (cond ((not (math-expr-contains (nth 1 expr) math-integ-var))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
885 (or (and (setq math-t1 (math-is-polynomial (nth 2 expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
886 math-integ-var 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
887 (math-div expr
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
888 (math-mul (nth 1 math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
889 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
890 (list 'calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
891 (nth 1 expr))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
892 (math-integral
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
893 (list 'calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
894 (math-mul (nth 2 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
895 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
896 (list 'calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
897 (nth 1 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
898 'yes t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
899 ((not (math-expr-contains (nth 2 expr) math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
900 (if (and (integerp (nth 2 expr)) (< (nth 2 expr) 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
901 (math-integral
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
902 (list '/ 1 (math-pow (nth 1 expr) (- (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
903 nil t)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
904 (or (and (setq math-t1 (math-is-polynomial (nth 1 expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
905 math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
906 1))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
907 (setq math-t2 (math-add (nth 2 expr) 1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
908 (math-div (math-pow (nth 1 expr) math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
909 (math-mul math-t2 (nth 1 math-t1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
910 (and (Math-negp (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
911 (math-integral
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
912 (math-div 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
913 (math-pow (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
914 (math-neg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
915 (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
916 nil t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
917 nil))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
918
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
919 ;; Integral of a polynomial.
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
920 (and (setq math-t1 (math-is-polynomial expr math-integ-var 20))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
921 (let ((accum 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
922 (n 1))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
923 (while math-t1
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
924 (if (setq accum (math-add accum
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
925 (math-div (math-mul (car math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
926 (math-pow
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
927 math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
928 n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
929 n))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
930 math-t1 (cdr math-t1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
931 (setq n (1+ n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
932 accum))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
933
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
934 ;; Try looking it up!
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
935 (cond ((= (length expr) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
936 (and (symbolp (car expr))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
937 (setq math-t1 (get (car expr) 'math-integral))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
938 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
939 (while (and math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
940 (not (setq math-t2 (funcall (car math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
941 (nth 1 expr)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
942 (setq math-t1 (cdr math-t1)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
943 (and math-t2 (math-normalize math-t2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
944 ((= (length expr) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
945 (and (symbolp (car expr))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
946 (setq math-t1 (get (car expr) 'math-integral-2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
947 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
948 (while (and math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
949 (not (setq math-t2 (funcall (car math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
950 (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
951 (nth 2 expr)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
952 (setq math-t1 (cdr math-t1)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
953 (and math-t2 (math-normalize math-t2))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
954
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
955 ;; Integral of a rational function.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
956 (and (math-ratpoly-p expr math-integ-var)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
957 (setq math-t1 (calcFunc-apart expr math-integ-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
958 (not (equal math-t1 expr))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
959 (math-integral math-t1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
960
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
961 ;; Try user-defined integration rules.
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
962 (and math-has-rules
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
963 (let ((math-old-integ (symbol-function 'calcFunc-integ))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
964 (input (list 'calcFunc-integtry expr math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
965 res part)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
966 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
967 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
968 (fset 'calcFunc-integ 'math-sub-integration)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
969 (setq res (math-rewrite input
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
970 '(var IntegRules var-IntegRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
971 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
972 (fset 'calcFunc-integ math-old-integ)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
973 (and (not (equal res input))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
974 (if (setq part (math-expr-calls
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
975 res '(calcFunc-integsubst)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
976 (and (memq (length part) '(3 4 5))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
977 (let ((parts (mapcar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
978 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
979 (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
980 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
981 x (nth 2 part)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
982 math-integ-var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
983 (cdr part))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
984 (math-integrate-by-substitution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
985 expr (car parts) t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
986 (or (nth 2 parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
987 (list 'calcFunc-integfailed
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
988 math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
989 (nth 3 parts))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
990 (if (not (math-expr-calls res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
991 '(calcFunc-integtry
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
992 calcFunc-integfailed)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
993 res))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
994 (fset 'calcFunc-integ math-old-integ))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
995
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
996 ;; See if the function is a symbolic derivative.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
997 (and (string-match "'" (symbol-name (car expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
998 (let ((name (symbol-name (car expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
999 (p expr) (n 0) (which nil) (bad nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1000 (while (setq n (1+ n) p (cdr p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1001 (if (equal (car p) math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1002 (if which (setq bad t) (setq which n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1003 (if (math-expr-contains (car p) math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1004 (setq bad t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1005 (and which (not bad)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1006 (let ((prime (if (= which 1) "'" (format "'%d" which))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1007 (and (string-match (concat prime "\\('['0-9]*\\|$\\)")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1008 name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1009 (cons (intern
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1010 (concat
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1011 (substring name 0 (match-beginning 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1012 (substring name (+ (match-beginning 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1013 (length prime)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1014 (cdr expr)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1015
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1016 ;; Try transformation methods (parts, substitutions).
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1017 (and (> math-integ-level 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1018 (math-do-integral-methods expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1019
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1020 ;; Try expanding the function's definition.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1021 (let ((res (math-expand-formula expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1022 (and res
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1023 (math-integral res))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1024
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1025 (defun math-sub-integration (expr &rest rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1026 (or (if (or (not rest)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1027 (and (< math-integ-level math-integral-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1028 (eq (car rest) math-integ-var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1029 (math-integral expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1030 (let ((res (apply math-old-integ expr rest)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1031 (and (or (= math-integ-level math-integral-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1032 (not (math-expr-calls res 'calcFunc-integ)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1033 res)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1034 (list 'calcFunc-integfailed expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1035
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1036 ;; math-so-far is a local variable for math-do-integral-methods, but
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1037 ;; is used by math-integ-try-linear-substitutions and
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1038 ;; math-integ-try-substitutions.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1039 (defvar math-so-far)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1040
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1041 ;; math-integ-expr is a local variable for math-do-integral-methods,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1042 ;; but is used by math-integ-try-linear-substitutions and
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1043 ;; math-integ-try-substitutions.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1044 (defvar math-integ-expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1045
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1046 (defun math-do-integral-methods (math-integ-expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1047 (let ((math-so-far math-integ-var-list-list)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1048 rat-in)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1049
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1050 ;; Integration by substitution, for various likely sub-expressions.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1051 ;; (In first pass, we look only for sub-exprs that are linear in X.)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1052 (or (math-integ-try-linear-substitutions math-integ-expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1053 (math-integ-try-substitutions math-integ-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1054
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1055 ;; If function has sines and cosines, try tan(x/2) substitution.
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1056 (and (let ((p (setq rat-in (math-expr-rational-in math-integ-expr))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1057 (while (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1058 (memq (car (car p)) '(calcFunc-sin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1059 calcFunc-cos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1060 calcFunc-tan))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1061 (equal (nth 1 (car p)) math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1062 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1063 (null p))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1064 (or (and (math-integ-parts-easy math-integ-expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1065 (math-integ-try-parts math-integ-expr t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1066 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1067 math-integ-expr (list 'calcFunc-tan (math-div math-integ-var 2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1068
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1069 ;; If function has sinh and cosh, try tanh(x/2) substitution.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1070 (and (let ((p rat-in))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1071 (while (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1072 (memq (car (car p)) '(calcFunc-sinh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1073 calcFunc-cosh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1074 calcFunc-tanh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1075 calcFunc-exp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1076 (equal (nth 1 (car p)) math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1077 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1078 (null p))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1079 (or (and (math-integ-parts-easy math-integ-expr)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1080 (math-integ-try-parts math-integ-expr t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1081 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1082 math-integ-expr (list 'calcFunc-tanh (math-div math-integ-var 2)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1083
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1084 ;; If function has square roots, try sin, tan, or sec substitution.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1085 (and (let ((p rat-in))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1086 (setq math-t1 nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1087 (while (and p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1088 (or (equal (car p) math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1089 (and (eq (car (car p)) 'calcFunc-sqrt)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1090 (setq math-t1 (math-is-polynomial
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1091 (nth 1 (setq math-t2 (car p)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1092 math-integ-var 2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1093 (setq p (cdr p)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1094 (and (null p) math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1095 (if (cdr (cdr math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1096 (if (math-guess-if-neg (nth 2 math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1097 (let* ((c (math-sqrt (math-neg (nth 2 math-t1))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1098 (d (math-div (nth 1 math-t1) (math-mul -2 c)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1099 (a (math-sqrt (math-add (car math-t1) (math-sqr d)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1100 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1101 math-integ-expr (list 'calcFunc-arcsin
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1102 (math-div-thru
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1103 (math-add (math-mul c math-integ-var) d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1104 a))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1105 (let* ((c (math-sqrt (nth 2 math-t1)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1106 (d (math-div (nth 1 math-t1) (math-mul 2 c)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1107 (aa (math-sub (car math-t1) (math-sqr d))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1108 (if (and nil (not (and (eq d 0) (eq c 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1109 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1110 math-integ-expr (math-add (math-mul c math-integ-var) d))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1111 (if (math-guess-if-neg aa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1112 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1113 math-integ-expr (list 'calcFunc-arccosh
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1114 (math-div-thru
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1115 (math-add (math-mul c math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1116 d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1117 (math-sqrt (math-neg aa)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1118 (math-integrate-by-good-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1119 math-integ-expr (list 'calcFunc-arcsinh
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1120 (math-div-thru
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1121 (math-add (math-mul c math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1122 d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1123 (math-sqrt aa))))))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1124 (math-integrate-by-good-substitution math-integ-expr math-t2)) )
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1125
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1126 ;; Try integration by parts.
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1127 (math-integ-try-parts math-integ-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1128
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1129 ;; Give up.
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1130 nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1131
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1132 (defun math-integ-parts-easy (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1133 (cond ((Math-primp expr) t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1134 ((memq (car expr) '(+ - *))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1135 (and (math-integ-parts-easy (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1136 (math-integ-parts-easy (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1137 ((eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1138 (and (math-integ-parts-easy (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1139 (math-atomic-factorp (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1140 ((eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1141 (and (natnump (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1142 (math-integ-parts-easy (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1143 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1144 (math-integ-parts-easy (nth 1 expr)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1145 (t t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1146
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1147 ;; math-prev-parts-v is local to calcFunc-integ (as well as
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1148 ;; math-integrate-by-parts), but is used by math-integ-try-parts.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1149 (defvar math-prev-parts-v)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1150
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1151 ;; math-good-parts is local to calcFunc-integ (as well as
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1152 ;; math-integ-try-parts), but is used by math-integrate-by-parts.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1153 (defvar math-good-parts)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1154
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1155
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1156 (defun math-integ-try-parts (expr &optional math-good-parts)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1157 ;; Integration by parts:
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1158 ;; integ(f(x) g(x),x) = f(x) h(x) - integ(h(x) f'(x),x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1159 ;; where h(x) = integ(g(x),x).
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1160 (or (let ((exp (calcFunc-expand expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1161 (and (not (equal exp expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1162 (math-integral exp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1163 (and (eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1164 (let ((first-bad (or (math-polynomial-p (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1165 math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1166 (equal (nth 2 expr) math-prev-parts-v))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1167 (or (and first-bad ; so try this one first
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1168 (math-integrate-by-parts (nth 1 expr) (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1169 (math-integrate-by-parts (nth 2 expr) (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1170 (and (not first-bad)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1171 (math-integrate-by-parts (nth 1 expr) (nth 2 expr))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1172 (and (eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1173 (math-expr-contains (nth 1 expr) math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1174 (let ((recip (math-div 1 (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1175 (or (math-integrate-by-parts (nth 1 expr) recip)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1176 (math-integrate-by-parts recip (nth 1 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1177 (and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1178 (math-integrate-by-parts (math-pow (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1179 (math-sub (nth 2 expr) 1))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1180 (nth 1 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1181
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1182 (defun math-integrate-by-parts (u vprime)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1183 (let ((math-integ-level (if (or math-good-parts
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1184 (math-polynomial-p u math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1185 math-integ-level
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1186 (1- math-integ-level)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1187 (math-doing-parts t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1188 v temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1189 (and (>= math-integ-level 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1190 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1191 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1192 (setcar (cdr math-cur-record) 'parts)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1193 (math-tracing-integral "Integrating by parts, u = "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1194 (math-format-value u 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1195 ", v' = "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1196 (math-format-value vprime 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1197 "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1198 (and (setq v (math-integral vprime))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1199 (setq temp (calcFunc-deriv u math-integ-var nil t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1200 (setq temp (let ((math-prev-parts-v v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1201 (math-integral (math-mul v temp) 'yes)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1202 (setq temp (math-sub (math-mul u v) temp))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1203 (if (eq (nth 1 math-cur-record) 'parts)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1204 (calcFunc-expand temp)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1205 (setq v (list 'var 'PARTS math-cur-record)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1206 temp (let (calc-next-why)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1207 (math-solve-for (math-sub v temp) 0 v nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1208 (and temp (not (integerp temp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1209 (math-simplify-extended temp)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1210 (setcar (cdr math-cur-record) 'busy)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1211
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1212 ;;; This tries two different formulations, hoping the algebraic simplifier
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1213 ;;; will be strong enough to handle at least one.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1214 (defun math-integrate-by-substitution (expr u &optional user uinv uinvprime)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1215 (and (> math-integ-level 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1216 (let ((math-integ-level (max (- math-integ-level 2) 0)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1217 (math-integrate-by-good-substitution expr u user uinv uinvprime))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1218
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1219 (defun math-integrate-by-good-substitution (expr u &optional user
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1220 uinv uinvprime)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1221 (let ((math-living-dangerously t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1222 deriv temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1223 (and (setq uinv (if uinv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1224 (math-expr-subst uinv math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1225 math-integ-var-2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1226 (let (calc-next-why)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1227 (math-solve-for u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1228 math-integ-var-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1229 math-integ-var nil))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1230 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1231 (math-tracing-integral "Integrating by substitution, u = "
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1232 (math-format-value u 1000)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1233 "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1234 (or (and (setq deriv (calcFunc-deriv u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1235 math-integ-var nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1236 (not user)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1237 (setq temp (math-integral (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1238 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1239 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1240 (math-div expr deriv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1241 u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1242 math-integ-var-2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1243 math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1244 uinv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1245 math-integ-var-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1246 math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1247 'yes)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1248 (and (setq deriv (or uinvprime
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1249 (calcFunc-deriv uinv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1250 math-integ-var-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1251 math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1252 (not user))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1253 (setq temp (math-integral (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1254 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1255 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1256 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1257 expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1258 u
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1259 math-integ-var-2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1260 math-integ-var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1261 uinv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1262 math-integ-var-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1263 math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1264 deriv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1265 'yes)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1266 (math-simplify-extended
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1267 (math-expr-subst temp math-integ-var u)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1268
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1269 ;;; Look for substitutions of the form u = a x + b.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1270 (defun math-integ-try-linear-substitutions (sub-expr)
58023
768b8e4f123b (math-linear-subst-tried): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 52401
diff changeset
1271 (setq math-linear-subst-tried t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1272 (and (not (Math-primp sub-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1273 (or (and (not (memq (car sub-expr) '(+ - * / neg)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1274 (not (and (eq (car sub-expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1275 (integerp (nth 2 sub-expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1276 (math-expr-contains sub-expr math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1277 (let ((res nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1278 (while (and (setq sub-expr (cdr sub-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1279 (or (not (math-linear-in (car sub-expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1280 math-integ-var))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1281 (assoc (car sub-expr) math-so-far)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1282 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1283 (setq math-so-far (cons (list (car sub-expr))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1284 math-so-far))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1285 (not (setq res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1286 (math-integrate-by-substitution
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1287 math-integ-expr (car sub-expr))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1288 res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1289 (let ((res nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1290 (while (and (setq sub-expr (cdr sub-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1291 (not (setq res (math-integ-try-linear-substitutions
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1292 (car sub-expr))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1293 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1294
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1295 ;;; Recursively try different substitutions based on various sub-expressions.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1296 (defun math-integ-try-substitutions (sub-expr &optional allow-rat)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1297 (and (not (Math-primp sub-expr))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1298 (not (assoc sub-expr math-so-far))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1299 (math-expr-contains sub-expr math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1300 (or (and (if (and (not (memq (car sub-expr) '(+ - * / neg)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1301 (not (and (eq (car sub-expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1302 (integerp (nth 2 sub-expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1303 (setq allow-rat t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1304 (prog1 allow-rat (setq allow-rat nil)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1305 (not (eq sub-expr math-integ-expr))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1306 (or (math-integrate-by-substitution math-integ-expr sub-expr)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1307 (and (eq (car sub-expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1308 (integerp (nth 2 sub-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1309 (< (nth 2 sub-expr) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1310 (math-integ-try-substitutions
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1311 (math-pow (nth 1 sub-expr) (- (nth 2 sub-expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1312 t))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1313 (let ((res nil))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1314 (setq math-so-far (cons (list sub-expr) math-so-far))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1315 (while (and (setq sub-expr (cdr sub-expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1316 (not (setq res (math-integ-try-substitutions
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1317 (car sub-expr) allow-rat)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1318 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1319
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1320 ;; The variable math-expr-parts is local to math-expr-rational-in,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1321 ;; but is used by math-expr-rational-in-rec
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1322
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1323 (defun math-expr-rational-in (expr)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1324 (let ((math-expr-parts nil))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1325 (math-expr-rational-in-rec expr)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1326 (mapcar 'car math-expr-parts)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1327
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1328 (defun math-expr-rational-in-rec (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1329 (cond ((Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1330 (and (equal expr math-integ-var)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1331 (not (assoc expr math-expr-parts))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1332 (setq math-expr-parts (cons (list expr) math-expr-parts))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1333 ((or (memq (car expr) '(+ - * / neg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1334 (and (eq (car expr) '^) (integerp (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1335 (math-expr-rational-in-rec (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1336 (and (nth 2 expr) (math-expr-rational-in-rec (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1337 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1338 (eq (math-quarter-integer (nth 2 expr)) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1339 (math-expr-rational-in-rec (list 'calcFunc-sqrt (nth 1 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1340 (t
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1341 (and (not (assoc expr math-expr-parts))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1342 (math-expr-contains expr math-integ-var)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1343 (setq math-expr-parts (cons (list expr) math-expr-parts))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1344
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1345 (defun math-expr-calls (expr funcs &optional arg-contains)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1346 (if (consp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1347 (if (or (memq (car expr) funcs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1348 (and (eq (car expr) '^) (eq (car funcs) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1349 (eq (math-quarter-integer (nth 2 expr)) 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1350 (and (or (not arg-contains)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1351 (math-expr-contains expr arg-contains))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1352 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1353 (and (not (Math-primp expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1354 (let ((res nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1355 (while (and (setq expr (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1356 (not (setq res (math-expr-calls
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1357 (car expr) funcs arg-contains)))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1358 res)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1359
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1360 (defun math-fix-const-terms (expr except-vars)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1361 (cond ((not (math-expr-depends expr except-vars)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1362 ((Math-primp expr) expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1363 ((eq (car expr) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1364 (math-add (math-fix-const-terms (nth 1 expr) except-vars)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1365 (math-fix-const-terms (nth 2 expr) except-vars)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1366 ((eq (car expr) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1367 (math-sub (math-fix-const-terms (nth 1 expr) except-vars)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1368 (math-fix-const-terms (nth 2 expr) except-vars)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1369 (t expr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1370
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1371 ;; Command for debugging the Calculator's symbolic integrator.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1372 (defun calc-dump-integral-cache (&optional arg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1373 (interactive "P")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1374 (let ((buf (current-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1375 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1376 (let ((p math-integral-cache)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1377 math-cur-record)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
1378 (display-buffer (get-buffer-create "*Integral Cache*"))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1379 (set-buffer (get-buffer "*Integral Cache*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1380 (erase-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1381 (while p
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1382 (setq math-cur-record (car p))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1383 (or arg (math-replace-integral-parts math-cur-record))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1384 (insert (math-format-flat-expr (car math-cur-record) 0)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1385 " --> "
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1386 (if (symbolp (nth 1 math-cur-record))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1387 (concat "(" (symbol-name (nth 1 math-cur-record)) ")")
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1388 (math-format-flat-expr (nth 1 math-cur-record) 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1389 "\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1390 (setq p (cdr p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1391 (goto-char (point-min)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1392 (set-buffer buf))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1393
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1394 ;; The variable math-max-integral-limit is local to calcFunc-integ,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1395 ;; but is used by math-try-integral.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1396 (defvar math-max-integral-limit)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1397
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1398 (defun math-try-integral (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1399 (let ((math-integ-level math-integral-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1400 (math-integ-depth 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1401 (math-integ-msg "Working...done")
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1402 (math-cur-record nil) ; a technicality
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1403 (math-integrating t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1404 (calc-prefer-frac t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1405 (calc-symbolic-mode t)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1406 (math-has-rules (calc-has-rules 'var-IntegRules)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1407 (or (math-integral expr 'yes)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1408 (and math-any-substs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1409 (setq math-enable-subst t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1410 (math-integral expr 'yes))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1411 (and (> math-max-integral-limit math-integral-limit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1412 (setq math-integral-limit math-max-integral-limit
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1413 math-integ-level math-integral-limit)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1414 (math-integral expr 'yes)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1415
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1416 (defvar var-IntegLimit nil)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1417
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1418 (defun calcFunc-integ (expr var &optional low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1419 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1420 ;; Do these even if the parts turn out not to be integrable.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1421 ((eq (car-safe expr) '+)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1422 (math-add (calcFunc-integ (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1423 (calcFunc-integ (nth 2 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1424 ((eq (car-safe expr) '-)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1425 (math-sub (calcFunc-integ (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1426 (calcFunc-integ (nth 2 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1427 ((eq (car-safe expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1428 (math-neg (calcFunc-integ (nth 1 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1429 ((and (eq (car-safe expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1430 (not (math-expr-contains (nth 1 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1431 (math-mul (nth 1 expr) (calcFunc-integ (nth 2 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1432 ((and (eq (car-safe expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1433 (not (math-expr-contains (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1434 (math-mul (calcFunc-integ (nth 1 expr) var low high) (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1435 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1436 (not (math-expr-contains (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1437 (not (math-equal-int (nth 1 expr) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1438 (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1439 (calcFunc-integ (math-div 1 (nth 2 expr)) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1440 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1441 (not (math-expr-contains (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1442 (math-div (calcFunc-integ (nth 1 expr) var low high) (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1443 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1444 (eq (car-safe (nth 1 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1445 (not (math-expr-contains (nth 1 (nth 1 expr)) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1446 (math-mul (nth 1 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1447 (calcFunc-integ (math-div (nth 2 (nth 1 expr)) (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1448 var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1449 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1450 (eq (car-safe (nth 1 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1451 (not (math-expr-contains (nth 2 (nth 1 expr)) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1452 (math-mul (nth 2 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1453 (calcFunc-integ (math-div (nth 1 (nth 1 expr)) (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1454 var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1455 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1456 (eq (car-safe (nth 2 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1457 (not (math-expr-contains (nth 1 (nth 2 expr)) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1458 (math-div (calcFunc-integ (math-div (nth 1 expr) (nth 2 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1459 var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1460 (nth 1 (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1461 ((and (eq (car-safe expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1462 (eq (car-safe (nth 2 expr)) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1463 (not (math-expr-contains (nth 2 (nth 2 expr)) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1464 (math-div (calcFunc-integ (math-div (nth 1 expr) (nth 1 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1465 var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1466 (nth 2 (nth 2 expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1467 ((eq (car-safe expr) 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1468 (cons 'vec (mapcar (function (lambda (x) (calcFunc-integ x var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1469 (cdr expr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1470 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1471 (let ((state (list calc-angle-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1472 ;;calc-symbolic-mode
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1473 ;;calc-prefer-frac
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1474 calc-internal-prec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1475 (calc-var-value 'var-IntegRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1476 (calc-var-value 'var-IntegSimpRules))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1477 (or (equal state math-integral-cache-state)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1478 (setq math-integral-cache-state state
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1479 math-integral-cache nil)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1480 (let* ((math-max-integral-limit (or (and (natnump var-IntegLimit)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1481 var-IntegLimit)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1482 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1483 (math-integral-limit 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1484 (sexpr (math-expr-subst expr var math-integ-var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1485 (trace-buffer (get-buffer "*Trace*"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1486 (calc-language (if (eq calc-language 'big) nil calc-language))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1487 (math-any-substs t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1488 (math-enable-subst nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1489 (math-prev-parts-v nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1490 (math-doing-parts nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1491 (math-good-parts nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1492 (res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1493 (if trace-buffer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1494 (let ((calcbuf (current-buffer))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1495 (calcwin (selected-window)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1496 (unwind-protect
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1497 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1498 (if (get-buffer-window trace-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1499 (select-window (get-buffer-window trace-buffer)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1500 (set-buffer trace-buffer)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1501 (goto-char (point-max))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1502 (or (assq 'scroll-stop (buffer-local-variables))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1503 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1504 (make-local-variable 'scroll-step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1505 (setq scroll-step 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1506 (insert "\n\n\n")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1507 (set-buffer calcbuf)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1508 (math-try-integral sexpr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1509 (select-window calcwin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1510 (set-buffer calcbuf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1511 (math-try-integral sexpr))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1512 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1513 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1514 (if (calc-has-rules 'var-IntegAfterRules)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1515 (setq res (math-rewrite res '(var IntegAfterRules
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1516 var-IntegAfterRules))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1517 (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1518 (if (and low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1519 (math-sub (math-expr-subst res math-integ-var high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1520 (math-expr-subst res math-integ-var low))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1521 (setq res (math-fix-const-terms res math-integ-vars))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1522 (if low
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1523 (math-expr-subst res math-integ-var low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1524 (math-expr-subst res math-integ-var var)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1525 (append (list 'calcFunc-integ expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1526 (and low (list low))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1527 (and high (list high))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1528
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1529
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1530 (math-defintegral calcFunc-inv
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1531 (math-integral (math-div 1 u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1532
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1533 (math-defintegral calcFunc-conj
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1534 (let ((int (math-integral u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1535 (and int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1536 (list 'calcFunc-conj int))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1537
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1538 (math-defintegral calcFunc-deg
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1539 (let ((int (math-integral u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1540 (and int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1541 (list 'calcFunc-deg int))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1542
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1543 (math-defintegral calcFunc-rad
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1544 (let ((int (math-integral u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1545 (and int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1546 (list 'calcFunc-rad int))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1547
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1548 (math-defintegral calcFunc-re
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1549 (let ((int (math-integral u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1550 (and int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1551 (list 'calcFunc-re int))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1552
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1553 (math-defintegral calcFunc-im
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1554 (let ((int (math-integral u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1555 (and int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1556 (list 'calcFunc-im int))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1557
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1558 (math-defintegral calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1559 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1560 (math-mul '(frac 2 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1561 (list 'calcFunc-sqrt (math-pow u 3)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1562
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1563 (math-defintegral calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1564 (or (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1565 (list 'calcFunc-exp u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1566 (let ((p (math-is-polynomial u math-integ-var 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1567 (and (nth 2 p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1568 (let ((sqa (math-sqrt (math-neg (nth 2 p)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1569 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1570 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1571 (math-mul (math-div (list 'calcFunc-sqrt '(var pi var-pi))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1572 sqa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1573 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1574 (list 'calcFunc-exp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1575 (math-div (math-sub (math-mul (car p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1576 (nth 2 p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1577 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1578 (math-sqr (nth 1 p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1579 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1580 (nth 2 p)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1581 (list 'calcFunc-erf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1582 (math-sub (math-mul sqa math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1583 (math-div (nth 1 p) (math-mul 2 sqa)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1584 2))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1585
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1586 (math-defintegral calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1587 (or (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1588 (math-sub (math-mul u (list 'calcFunc-ln u)) u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1589 (and (eq (car u) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1590 (math-integral (math-add (list 'calcFunc-ln (nth 1 u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1591 (list 'calcFunc-ln (nth 2 u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1592 (and (eq (car u) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1593 (math-integral (math-sub (list 'calcFunc-ln (nth 1 u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1594 (list 'calcFunc-ln (nth 2 u)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1595 (and (eq (car u) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1596 (math-integral (math-mul (nth 2 u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1597 (list 'calcFunc-ln (nth 1 u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1598
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1599 (math-defintegral calcFunc-log10
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1600 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1601 (math-sub (math-mul u (list 'calcFunc-ln u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1602 (math-div u (list 'calcFunc-ln 10)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1603
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1604 (math-defintegral-2 calcFunc-log
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1605 (math-integral (math-div (list 'calcFunc-ln u)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1606 (list 'calcFunc-ln v))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1607
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1608 (math-defintegral calcFunc-sin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1609 (or (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1610 (math-neg (math-from-radians-2 (list 'calcFunc-cos u))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1611 (and (nth 2 (math-is-polynomial u math-integ-var 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1612 (math-integral (math-to-exponentials (list 'calcFunc-sin u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1613
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1614 (math-defintegral calcFunc-cos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1615 (or (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1616 (math-from-radians-2 (list 'calcFunc-sin u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1617 (and (nth 2 (math-is-polynomial u math-integ-var 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1618 (math-integral (math-to-exponentials (list 'calcFunc-cos u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1619
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1620 (math-defintegral calcFunc-tan
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1621 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1622 (math-neg (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1623 (list 'calcFunc-ln (list 'calcFunc-cos u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1624
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1625 (math-defintegral calcFunc-arcsin
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1626 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1627 (math-add (math-mul u (list 'calcFunc-arcsin u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1628 (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1629 (list 'calcFunc-sqrt (math-sub 1 (math-sqr u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1630
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1631 (math-defintegral calcFunc-arccos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1632 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1633 (math-sub (math-mul u (list 'calcFunc-arccos u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1634 (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1635 (list 'calcFunc-sqrt (math-sub 1 (math-sqr u)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1636
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1637 (math-defintegral calcFunc-arctan
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1638 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1639 (math-sub (math-mul u (list 'calcFunc-arctan u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1640 (math-from-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1641 (math-div (list 'calcFunc-ln (math-add 1 (math-sqr u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1642 2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1643
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1644 (math-defintegral calcFunc-sinh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1645 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1646 (list 'calcFunc-cosh u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1647
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1648 (math-defintegral calcFunc-cosh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1649 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1650 (list 'calcFunc-sinh u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1651
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1652 (math-defintegral calcFunc-tanh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1653 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1654 (list 'calcFunc-ln (list 'calcFunc-cosh u))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1655
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1656 (math-defintegral calcFunc-arcsinh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1657 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1658 (math-sub (math-mul u (list 'calcFunc-arcsinh u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1659 (list 'calcFunc-sqrt (math-add (math-sqr u) 1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1660
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1661 (math-defintegral calcFunc-arccosh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1662 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1663 (math-sub (math-mul u (list 'calcFunc-arccosh u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1664 (list 'calcFunc-sqrt (math-sub 1 (math-sqr u))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1665
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1666 (math-defintegral calcFunc-arctanh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1667 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1668 (math-sub (math-mul u (list 'calcFunc-arctan u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1669 (math-div (list 'calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1670 (math-add 1 (math-sqr u)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1671 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1672
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1673 ;;; (Ax + B) / (ax^2 + bx + c)^n forms.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1674 (math-defintegral-2 /
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1675 (math-integral-rational-funcs u v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1676
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1677 (defun math-integral-rational-funcs (u v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1678 (let ((pu (math-is-polynomial u math-integ-var 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1679 (vpow 1) pv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1680 (and pu
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1681 (catch 'int-rat
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1682 (if (and (eq (car-safe v) '^) (natnump (nth 2 v)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1683 (setq vpow (nth 2 v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1684 v (nth 1 v)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1685 (and (setq pv (math-is-polynomial v math-integ-var 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1686 (let ((int (math-mul-thru
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1687 (car pu)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1688 (math-integral-q02 (car pv) (nth 1 pv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1689 (nth 2 pv) v vpow))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1690 (if (cdr pu)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1691 (setq int (math-add int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1692 (math-mul-thru
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1693 (nth 1 pu)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1694 (math-integral-q12
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1695 (car pv) (nth 1 pv)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1696 (nth 2 pv) v vpow)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1697 int))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1698
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1699 (defun math-integral-q12 (a b c v vpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1700 (let (q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1701 (cond ((not c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1702 (cond ((= vpow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1703 (math-sub (math-div math-integ-var b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1704 (math-mul (math-div a (math-sqr b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1705 (list 'calcFunc-ln v))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1706 ((= vpow 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1707 (math-div (math-add (list 'calcFunc-ln v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1708 (math-div a v))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1709 (math-sqr b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1710 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1711 (let ((nm1 (math-sub vpow 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1712 (nm2 (math-sub vpow 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1713 (math-div (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1714 (math-div a (math-mul nm1 (math-pow v nm1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1715 (math-div 1 (math-mul nm2 (math-pow v nm2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1716 (math-sqr b))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1717 ((math-zerop
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1718 (setq q (math-sub (math-mul 4 (math-mul a c)) (math-sqr b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1719 (let ((part (math-div b (math-mul 2 c))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1720 (math-mul-thru (math-pow c vpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1721 (math-integral-q12 part 1 nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1722 (math-add math-integ-var part)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1723 (* vpow 2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1724 ((= vpow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1725 (and (math-ratp q) (math-negp q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1726 (let ((calc-symbolic-mode t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1727 (math-ratp (math-sqrt (math-neg q))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1728 (throw 'int-rat nil)) ; should have used calcFunc-apart first
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1729 (math-sub (math-div (list 'calcFunc-ln v) (math-mul 2 c))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1730 (math-mul-thru (math-div b (math-mul 2 c))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1731 (math-integral-q02 a b c v 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1732 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1733 (let ((n (1- vpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1734 (math-sub (math-neg (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1735 (math-add (math-mul b math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1736 (math-mul 2 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1737 (math-mul n (math-mul q (math-pow v n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1738 (math-mul-thru (math-div (math-mul b (1- (* 2 n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1739 (math-mul n q))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1740 (math-integral-q02 a b c v n))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1741
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1742 (defun math-integral-q02 (a b c v vpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1743 (let (q rq part)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1744 (cond ((not c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1745 (cond ((= vpow 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1746 (math-div (list 'calcFunc-ln v) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1747 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1748 (math-div (math-pow v (- 1 vpow))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1749 (math-mul (- 1 vpow) b)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1750 ((math-zerop
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1751 (setq q (math-sub (math-mul 4 (math-mul a c)) (math-sqr b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1752 (let ((part (math-div b (math-mul 2 c))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1753 (math-mul-thru (math-pow c vpow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1754 (math-integral-q02 part 1 nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1755 (math-add math-integ-var part)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1756 (* vpow 2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1757 ((progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1758 (setq part (math-add (math-mul 2 (math-mul c math-integ-var)) b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1759 (> vpow 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1760 (let ((n (1- vpow)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1761 (math-add (math-div part (math-mul n (math-mul q (math-pow v n))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1762 (math-mul-thru (math-div (math-mul (- (* 4 n) 2) c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1763 (math-mul n q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1764 (math-integral-q02 a b c v n)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1765 ((math-guess-if-neg q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1766 (setq rq (list 'calcFunc-sqrt (math-neg q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1767 ;;(math-div-thru (list 'calcFunc-ln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1768 ;; (math-div (math-sub part rq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1769 ;; (math-add part rq)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1770 ;; rq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1771 (math-div (math-mul -2 (list 'calcFunc-arctanh
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1772 (math-div part rq)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1773 rq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1774 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1775 (setq rq (list 'calcFunc-sqrt q))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1776 (math-div (math-mul 2 (math-to-radians-2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1777 (list 'calcFunc-arctan
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1778 (math-div part rq))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1779 rq)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1780
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1781
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1782 (math-defintegral calcFunc-erf
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1783 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1784 (math-add (math-mul u (list 'calcFunc-erf u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1785 (math-div 1 (math-mul (list 'calcFunc-exp (math-sqr u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1786 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1787 '(var pi var-pi)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1788
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1789 (math-defintegral calcFunc-erfc
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1790 (and (equal u math-integ-var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1791 (math-sub (math-mul u (list 'calcFunc-erfc u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1792 (math-div 1 (math-mul (list 'calcFunc-exp (math-sqr u))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1793 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1794 '(var pi var-pi)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1795
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1796
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1797
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1798
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1799 (defvar math-tabulate-initial nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1800 (defvar math-tabulate-function nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1801
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1802 ;; The variables calc-low and calc-high are local to calcFunc-table,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1803 ;; but are used by math-scan-for-limits.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1804 (defvar calc-low)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1805 (defvar calc-high)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1806
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1807 (defun calcFunc-table (expr var &optional calc-low calc-high step)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1808 (or calc-low
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1809 (setq calc-low '(neg (var inf var-inf)) calc-high '(var inf var-inf)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1810 (or calc-high (setq calc-high calc-low calc-low 1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1811 (and (or (math-infinitep calc-low) (math-infinitep calc-high))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1812 (not step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1813 (math-scan-for-limits expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1814 (and step (math-zerop step) (math-reject-arg step 'nonzerop))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1815 (let ((known (+ (if (Math-objectp calc-low) 1 0)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1816 (if (Math-objectp calc-high) 1 0)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1817 (if (or (null step) (Math-objectp step)) 1 0)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1818 (count '(var inf var-inf))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1819 vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1820 (or (= known 2) ; handy optimization
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1821 (equal calc-high '(var inf var-inf))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1822 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1823 (setq count (math-div (math-sub calc-high calc-low) (or step 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1824 (or (Math-objectp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1825 (setq count (math-simplify count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1826 (if (Math-messy-integerp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1827 (setq count (math-trunc count)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1828 (if (Math-negp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1829 (setq count -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1830 (if (integerp count)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1831 (let ((var-DUMMY nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1832 (vec math-tabulate-initial)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1833 (math-working-step-2 (1+ count))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1834 (math-working-step 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1835 (setq expr (math-evaluate-expr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1836 (math-expr-subst expr var '(var DUMMY var-DUMMY))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1837 (while (>= count 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1838 (setq math-working-step (1+ math-working-step)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1839 var-DUMMY calc-low
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1840 vec (cond ((eq math-tabulate-function 'calcFunc-sum)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1841 (math-add vec (math-evaluate-expr expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1842 ((eq math-tabulate-function 'calcFunc-prod)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1843 (math-mul vec (math-evaluate-expr expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1844 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1845 (cons (math-evaluate-expr expr) vec)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1846 calc-low (math-add calc-low (or step 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1847 count (1- count)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1848 (if math-tabulate-function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1849 vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1850 (cons 'vec (nreverse vec))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1851 (if (Math-integerp count)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1852 (calc-record-why 'fixnump calc-high)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1853 (if (Math-num-integerp calc-low)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1854 (if (Math-num-integerp calc-high)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1855 (calc-record-why 'integerp step)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1856 (calc-record-why 'integerp calc-high))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1857 (calc-record-why 'integerp calc-low)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1858 (append (list (or math-tabulate-function 'calcFunc-table)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1859 expr var)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1860 (and (not (and (equal calc-low '(neg (var inf var-inf)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1861 (equal calc-high '(var inf var-inf))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1862 (list calc-low calc-high))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1863 (and step (list step))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1864
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1865 (defun math-scan-for-limits (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1866 (cond ((Math-primp x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1867 ((and (eq (car x) 'calcFunc-subscr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1868 (Math-vectorp (nth 1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1869 (math-expr-contains (nth 2 x) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1870 (let* ((calc-next-why nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1871 (low-val (math-solve-for (nth 2 x) 1 var nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1872 (high-val (math-solve-for (nth 2 x) (1- (length (nth 1 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1873 var nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1874 temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1875 (and low-val (math-realp low-val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1876 high-val (math-realp high-val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1877 (and (Math-lessp high-val low-val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1878 (setq temp low-val low-val high-val high-val temp))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1879 (setq calc-low (math-max calc-low (math-ceiling low-val))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
1880 calc-high (math-min calc-high (math-floor high-val)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1881 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1882 (while (setq x (cdr x))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1883 (math-scan-for-limits (car x))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1884
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1885
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
1886 (defvar math-disable-sums nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1887 (defun calcFunc-sum (expr var &optional low high step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1888 (if math-disable-sums (math-reject-arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1889 (let* ((res (let* ((calc-internal-prec (+ calc-internal-prec 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1890 (math-sum-rec expr var low high step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1891 (math-disable-sums t))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1892 (math-normalize res)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1893
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1894 (defun math-sum-rec (expr var &optional low high step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1895 (or low (setq low '(neg (var inf var-inf)) high '(var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1896 (and low (not high) (setq high low low 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1897 (let (t1 t2 val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1898 (setq val
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1899 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1900 ((not (math-expr-contains expr var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1901 (math-mul expr (math-add (math-div (math-sub high low) (or step 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1902 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1903 ((and step (not (math-equal-int step 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1904 (if (math-negp step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1905 (math-sum-rec expr var high low (math-neg step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1906 (let ((lo (math-simplify (math-div low step))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1907 (if (math-known-num-integerp lo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1908 (math-sum-rec (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1909 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1910 (math-mul step var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1911 var lo (math-simplify (math-div high step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1912 (math-sum-rec (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1913 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1914 (math-add (math-mul step var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1915 low)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1916 var 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1917 (math-simplify (math-div (math-sub high low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1918 step)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1919 ((memq (setq t1 (math-compare low high)) '(0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1920 (if (eq t1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1921 (math-expr-subst expr var low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1922 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1923 ((setq t1 (math-is-polynomial expr var 20))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1924 (let ((poly nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1925 (n 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1926 (while t1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1927 (setq poly (math-poly-mix poly 1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1928 (math-sum-integer-power n) (car t1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1929 n (1+ n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1930 t1 (cdr t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1931 (setq n (math-build-polynomial-expr poly high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1932 (if (memq low '(0 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1933 n
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1934 (math-sub n (math-build-polynomial-expr poly
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1935 (math-sub low 1))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1936 ((and (memq (car expr) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1937 (setq t1 (math-sum-rec (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1938 t2 (math-sum-rec (nth 2 expr) var low high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1939 (not (and (math-expr-calls t1 '(calcFunc-sum))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1940 (math-expr-calls t2 '(calcFunc-sum)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1941 (list (car expr) t1 t2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1942 ((and (eq (car expr) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1943 (setq t1 (math-sum-const-factors expr var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1944 (math-mul (car t1) (math-sum-rec (cdr t1) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1945 ((and (eq (car expr) '*) (memq (car-safe (nth 1 expr)) '(+ -)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1946 (math-sum-rec (math-add-or-sub (math-mul (nth 1 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1947 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1948 (math-mul (nth 2 (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1949 (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1950 nil (eq (car (nth 1 expr)) '-))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1951 var low high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1952 ((and (eq (car expr) '*) (memq (car-safe (nth 2 expr)) '(+ -)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1953 (math-sum-rec (math-add-or-sub (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1954 (nth 1 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1955 (math-mul (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1956 (nth 2 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1957 nil (eq (car (nth 2 expr)) '-))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1958 var low high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1959 ((and (eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1960 (not (math-primp (nth 1 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1961 (setq t1 (math-sum-const-factors (nth 1 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1962 (math-mul (car t1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1963 (math-sum-rec (math-div (cdr t1) (nth 2 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1964 var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1965 ((and (eq (car expr) '/)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1966 (setq t1 (math-sum-const-factors (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1967 (math-div (math-sum-rec (math-div (nth 1 expr) (cdr t1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1968 var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1969 (car t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1970 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1971 (math-neg (math-sum-rec (nth 1 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1972 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1973 (not (math-expr-contains (nth 1 expr) var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1974 (setq t1 (math-is-polynomial (nth 2 expr) var 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1975 (let ((x (math-pow (nth 1 expr) (nth 1 t1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1976 (math-div (math-mul (math-sub (math-pow x (math-add 1 high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1977 (math-pow x low))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1978 (math-pow (nth 1 expr) (car t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1979 (math-sub x 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1980 ((and (setq t1 (math-to-exponentials expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1981 (setq t1 (math-sum-rec t1 var low high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1982 (not (math-expr-calls t1 '(calcFunc-sum))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1983 (math-to-exps t1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1984 ((memq (car expr) '(calcFunc-ln calcFunc-log10))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1985 (list (car expr) (calcFunc-prod (nth 1 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1986 ((and (eq (car expr) 'calcFunc-log)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1987 (= (length expr) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1988 (not (math-expr-contains (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1989 (list 'calcFunc-log
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1990 (calcFunc-prod (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1991 (nth 2 expr)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1992 (if (equal val '(var nan var-nan)) (setq val nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1993 (or val
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1994 (let* ((math-tabulate-initial 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1995 (math-tabulate-function 'calcFunc-sum))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
1996 (calcFunc-table expr var low high)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1997
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1998 (defun calcFunc-asum (expr var low &optional high step no-mul-flag)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1999 (or high (setq high low low 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2000 (if (and step (not (math-equal-int step 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2001 (if (math-negp step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2002 (math-mul (math-pow -1 low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2003 (calcFunc-asum expr var high low (math-neg step) t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2004 (let ((lo (math-simplify (math-div low step))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2005 (if (math-num-integerp lo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2006 (calcFunc-asum (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2007 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2008 (math-mul step var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2009 var lo (math-simplify (math-div high step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2010 (calcFunc-asum (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2011 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2012 (math-add (math-mul step var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2013 low)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2014 var 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2015 (math-simplify (math-div (math-sub high low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2016 step))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2017 (math-mul (if no-mul-flag 1 (math-pow -1 low))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2018 (calcFunc-sum (math-mul (math-pow -1 var) expr) var low high))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2019
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2020 (defun math-sum-const-factors (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2021 (let ((const nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2022 (not-const nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2023 (p expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2024 (while (eq (car-safe p) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2025 (if (math-expr-contains (nth 1 p) var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2026 (setq not-const (cons (nth 1 p) not-const))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2027 (setq const (cons (nth 1 p) const)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2028 (setq p (nth 2 p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2029 (if (math-expr-contains p var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2030 (setq not-const (cons p not-const))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2031 (setq const (cons p const)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2032 (and const
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2033 (cons (let ((temp (car const)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2034 (while (setq const (cdr const))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2035 (setq temp (list '* (car const) temp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2036 temp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2037 (let ((temp (or (car not-const) 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2038 (while (setq not-const (cdr not-const))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2039 (setq temp (list '* (car not-const) temp)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2040 temp)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2041
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2042 (defvar math-sum-int-pow-cache (list '(0 1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2043 ;; Following is from CRC Math Tables, 27th ed, pp. 52-53.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2044 (defun math-sum-integer-power (pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2045 (let ((calc-prefer-frac t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2046 (n (length math-sum-int-pow-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2047 (while (<= n pow)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2048 (let* ((new (list 0 0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2049 (lin new)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2050 (pp (cdr (nth (1- n) math-sum-int-pow-cache)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2051 (p 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2052 (sum 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2053 q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2054 (while pp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2055 (setq q (math-div (car pp) p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2056 new (cons (math-mul q n) new)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2057 sum (math-add sum q)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2058 p (1+ p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2059 pp (cdr pp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2060 (setcar lin (math-sub 1 (math-mul n sum)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2061 (setq math-sum-int-pow-cache
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2062 (nconc math-sum-int-pow-cache (list (nreverse new)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2063 n (1+ n))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2064 (nth pow math-sum-int-pow-cache)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2065
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2066 (defun math-to-exponentials (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2067 (and (consp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2068 (= (length expr) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2069 (let ((x (nth 1 expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2070 (pi (if calc-symbolic-mode '(var pi var-pi) (math-pi)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2071 (i (if calc-symbolic-mode '(var i var-i) '(cplx 0 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2072 (cond ((eq (car expr) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2073 (list '^ '(var e var-e) x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2074 ((eq (car expr) 'calcFunc-sin)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2075 (or (eq calc-angle-mode 'rad)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2076 (setq x (list '/ (list '* x pi) 180)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2077 (list '/ (list '-
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2078 (list '^ '(var e var-e) (list '* x i))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2079 (list '^ '(var e var-e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2080 (list 'neg (list '* x i))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2081 (list '* 2 i)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2082 ((eq (car expr) 'calcFunc-cos)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2083 (or (eq calc-angle-mode 'rad)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2084 (setq x (list '/ (list '* x pi) 180)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2085 (list '/ (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2086 (list '^ '(var e var-e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2087 (list '* x i))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2088 (list '^ '(var e var-e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2089 (list 'neg (list '* x i))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2090 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2091 ((eq (car expr) 'calcFunc-sinh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2092 (list '/ (list '-
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2093 (list '^ '(var e var-e) x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2094 (list '^ '(var e var-e) (list 'neg x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2095 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2096 ((eq (car expr) 'calcFunc-cosh)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2097 (list '/ (list '+
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2098 (list '^ '(var e var-e) x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2099 (list '^ '(var e var-e) (list 'neg x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2100 2))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2101 (t nil)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2102
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2103 (defun math-to-exps (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2104 (cond (calc-symbolic-mode expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2105 ((Math-primp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2106 (if (equal expr '(var e var-e)) (math-e) expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2107 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2108 (equal (nth 1 expr) '(var e var-e)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2109 (list 'calcFunc-exp (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2110 (t
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2111 (cons (car expr) (mapcar 'math-to-exps (cdr expr))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2112
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2113
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2114 (defvar math-disable-prods nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2115 (defun calcFunc-prod (expr var &optional low high step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2116 (if math-disable-prods (math-reject-arg))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2117 (let* ((res (let* ((calc-internal-prec (+ calc-internal-prec 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2118 (math-prod-rec expr var low high step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2119 (math-disable-prods t))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2120 (math-normalize res)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2121
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2122 (defun math-prod-rec (expr var &optional low high step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2123 (or low (setq low '(neg (var inf var-inf)) high '(var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2124 (and low (not high) (setq high '(var inf var-inf)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2125 (let (t1 t2 t3 val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2126 (setq val
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2127 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2128 ((not (math-expr-contains expr var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2129 (math-pow expr (math-add (math-div (math-sub high low) (or step 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2130 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2131 ((and step (not (math-equal-int step 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2132 (if (math-negp step)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2133 (math-prod-rec expr var high low (math-neg step))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2134 (let ((lo (math-simplify (math-div low step))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2135 (if (math-known-num-integerp lo)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2136 (math-prod-rec (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2137 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2138 (math-mul step var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2139 var lo (math-simplify (math-div high step)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2140 (math-prod-rec (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2141 (math-expr-subst expr var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2142 (math-add (math-mul step
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2143 var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2144 low)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2145 var 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2146 (math-simplify (math-div (math-sub high low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2147 step)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2148 ((and (memq (car expr) '(* /))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2149 (setq t1 (math-prod-rec (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2150 t2 (math-prod-rec (nth 2 expr) var low high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2151 (not (and (math-expr-calls t1 '(calcFunc-prod))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2152 (math-expr-calls t2 '(calcFunc-prod)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2153 (list (car expr) t1 t2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2154 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2155 (not (math-expr-contains (nth 2 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2156 (math-pow (math-prod-rec (nth 1 expr) var low high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2157 (nth 2 expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2158 ((and (eq (car expr) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2159 (not (math-expr-contains (nth 1 expr) var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2160 (math-pow (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2161 (calcFunc-sum (nth 2 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2162 ((eq (car expr) 'sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2163 (math-normalize (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2164 (list 'calcFunc-prod (nth 1 expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2165 var low high))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2166 ((eq (car expr) 'neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2167 (math-mul (math-pow -1 (math-add (math-sub high low) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2168 (math-prod-rec (nth 1 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2169 ((eq (car expr) 'calcFunc-exp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2170 (list 'calcFunc-exp (calcFunc-sum (nth 1 expr) var low high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2171 ((and (setq t1 (math-is-polynomial expr var 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2172 (setq t2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2173 (cond
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2174 ((or (and (math-equal-int (nth 1 t1) 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2175 (setq low (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2176 (math-add low (car t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2177 high (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2178 (math-add high (car t1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2179 (and (math-equal-int (nth 1 t1) -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2180 (setq t2 low
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2181 low (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2182 (math-sub (car t1) high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2183 high (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2184 (math-sub (car t1) t2)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2185 (if (or (math-zerop low) (math-zerop high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2186 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2187 (if (and (or (math-negp low) (math-negp high))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2188 (or (math-num-integerp low)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2189 (math-num-integerp high)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2190 (if (math-posp high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2191 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2192 (math-mul (math-pow -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2193 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2194 (math-add low high) 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2195 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2196 (list 'calcFunc-fact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2197 (math-neg low))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2198 (list 'calcFunc-fact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2199 (math-sub -1 high)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2200 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2201 (list 'calcFunc-fact high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2202 (list 'calcFunc-fact (math-sub low 1))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2203 ((and (or (and (math-equal-int (nth 1 t1) 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2204 (setq t2 (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2205 (math-add (math-mul low 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2206 (car t1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2207 t3 (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2208 (math-add (math-mul high 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2209 (car t1)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2210 (and (math-equal-int (nth 1 t1) -2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2211 (setq t2 (math-simplify
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2212 (math-sub (car t1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2213 (math-mul high 2)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
2214 t3 (math-simplify
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2215 (math-sub (car t1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2216 (math-mul low
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2217 2))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2218 (or (math-integerp t2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2219 (and (math-messy-integerp t2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2220 (setq t2 (math-trunc t2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2221 (math-integerp t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2222 (and (math-messy-integerp t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2223 (setq t3 (math-trunc t3)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2224 (if (or (math-zerop t2) (math-zerop t3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2225 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2226 (if (or (math-evenp t2) (math-evenp t3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2227 (if (or (math-negp t2) (math-negp t3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2228 (if (math-posp high)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2229 0
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2230 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2231 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2232 (math-neg t2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2233 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2234 (math-sub -2 t3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2235 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2236 (list 'calcFunc-dfact t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2237 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2238 (math-sub t2 2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2239 (if (math-negp t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2240 (list '*
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2241 (list '^ -1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2242 (list '/ (list '- (list '- t2 t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2243 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2244 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2245 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2246 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2247 (math-neg t2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2248 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2249 (math-sub -2 t3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2250 (if (math-posp t2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2251 (list '/
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2252 (list 'calcFunc-dfact t3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2253 (list 'calcFunc-dfact
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2254 (math-sub t2 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2255 nil))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2256 t2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2257 (if (equal val '(var nan var-nan)) (setq val nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2258 (or val
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2259 (let* ((math-tabulate-initial 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2260 (math-tabulate-function 'calcFunc-prod))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2261 (calcFunc-table expr var low high)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2262
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2263
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2264
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2265
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2266 (defvar math-solve-ranges nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2267 (defvar math-solve-sign)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2268 ;;; Attempt to reduce math-solve-lhs = math-solve-rhs to
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2269 ;;; math-solve-var = math-solve-rhs', where math-solve-var appears
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2270 ;;; in math-solve-lhs but not in math-solve-rhs or math-solve-rhs';
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2271 ;;; return math-solve-rhs'.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2272 ;;; Uses global values: math-solve-var, math-solve-full.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2273 (defvar math-solve-var)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2274 (defvar math-solve-full)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2275
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2276 ;; The variables math-solve-lhs, math-solve-rhs and math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2277 ;; are local to math-try-solve-for, but are used by math-try-solve-prod.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2278 ;; (math-solve-lhs and math-solve-rhs are is also local to
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2279 ;; math-decompose-poly, but used by math-solve-poly-funny-powers.)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2280 (defvar math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2281 (defvar math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2282
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2283 (defun math-try-solve-for
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2284 (math-solve-lhs math-solve-rhs &optional math-try-solve-sign no-poly)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2285 (let (math-t1 math-t2 math-t3)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2286 (cond ((equal math-solve-lhs math-solve-var)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2287 (setq math-solve-sign math-try-solve-sign)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2288 (if (eq math-solve-full 'all)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2289 (let ((vec (list 'vec (math-evaluate-expr math-solve-rhs)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2290 newvec var p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2291 (while math-solve-ranges
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2292 (setq p (car math-solve-ranges)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2293 var (car p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2294 newvec (list 'vec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2295 (while (setq p (cdr p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2296 (setq newvec (nconc newvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2297 (cdr (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2298 vec var (car p))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2299 (setq vec newvec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2300 math-solve-ranges (cdr math-solve-ranges)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2301 (math-normalize vec))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2302 math-solve-rhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2303 ((Math-primp math-solve-lhs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2304 nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2305 ((and (eq (car math-solve-lhs) '-)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2306 (eq (car-safe (nth 1 math-solve-lhs)) (car-safe (nth 2 math-solve-lhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2307 (Math-zerop math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2308 (= (length (nth 1 math-solve-lhs)) 2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2309 (= (length (nth 2 math-solve-lhs)) 2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2310 (setq math-t1 (get (car (nth 1 math-solve-lhs)) 'math-inverse))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2311 (setq math-t2 (funcall math-t1 '(var SOLVEDUM SOLVEDUM)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2312 (eq (math-expr-contains-count math-t2 '(var SOLVEDUM SOLVEDUM)) 1)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2313 (setq math-t3 (math-solve-above-dummy math-t2))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2314 (setq math-t1 (math-try-solve-for
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2315 (math-sub (nth 1 (nth 1 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2316 (math-expr-subst
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2317 math-t2 math-t3
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2318 (nth 1 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2319 0)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2320 math-t1)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2321 ((eq (car math-solve-lhs) 'neg)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2322 (math-try-solve-for (nth 1 math-solve-lhs) (math-neg math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2323 (and math-try-solve-sign (- math-try-solve-sign))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2324 ((and (not (eq math-solve-full 't)) (math-try-solve-prod)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2325 ((and (not no-poly)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2326 (setq math-t2
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2327 (math-decompose-poly math-solve-lhs
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2328 math-solve-var 15 math-solve-rhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2329 (setq math-t1 (cdr (nth 1 math-t2))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2330 math-t1 (let ((math-solve-ranges math-solve-ranges))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2331 (cond ((= (length math-t1) 5)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2332 (apply 'math-solve-quartic (car math-t2) math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2333 ((= (length math-t1) 4)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2334 (apply 'math-solve-cubic (car math-t2) math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2335 ((= (length math-t1) 3)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2336 (apply 'math-solve-quadratic (car math-t2) math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2337 ((= (length math-t1) 2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2338 (apply 'math-solve-linear
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2339 (car math-t2) math-try-solve-sign math-t1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2340 (math-solve-full
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2341 (math-poly-all-roots (car math-t2) math-t1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2342 (calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2343 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2344 (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2345 (car math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2346 (math-poly-any-root (reverse math-t1) 0 t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2347 nil t)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2348 (if math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2349 (if (eq (nth 2 math-t2) 1)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2350 math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2351 (math-solve-prod math-t1 (math-try-solve-for (nth 2 math-t2) 0 nil t)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2352 (calc-record-why "*Unable to find a symbolic solution")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2353 nil))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2354 ((and (math-solve-find-root-term math-solve-lhs nil)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2355 (eq (math-expr-contains-count math-solve-lhs math-t1) 1)) ; just in case
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2356 (math-try-solve-for (math-simplify
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2357 (math-sub (if (or math-t3 (math-evenp math-t2))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2358 (math-pow math-t1 math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2359 (math-neg (math-pow math-t1 math-t2)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2360 (math-expand-power
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2361 (math-sub (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2362 (math-expr-subst
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2363 math-solve-lhs math-t1 0))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2364 math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2365 math-t2 math-solve-var)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2366 0))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2367 ((eq (car math-solve-lhs) '+)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2368 (cond ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2369 (math-try-solve-for (nth 2 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2370 (math-sub math-solve-rhs (nth 1 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2371 math-try-solve-sign))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2372 ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2373 (math-try-solve-for (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2374 (math-sub math-solve-rhs (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2375 math-try-solve-sign))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2376 ((eq (car math-solve-lhs) 'calcFunc-eq)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2377 (math-try-solve-for (math-sub (nth 1 math-solve-lhs) (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2378 math-solve-rhs math-try-solve-sign no-poly))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2379 ((eq (car math-solve-lhs) '-)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2380 (cond ((or (and (eq (car-safe (nth 1 math-solve-lhs)) 'calcFunc-sin)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2381 (eq (car-safe (nth 2 math-solve-lhs)) 'calcFunc-cos))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2382 (and (eq (car-safe (nth 1 math-solve-lhs)) 'calcFunc-cos)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2383 (eq (car-safe (nth 2 math-solve-lhs)) 'calcFunc-sin)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2384 (math-try-solve-for (math-sub (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2385 (list (car (nth 1 math-solve-lhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2386 (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2387 (math-quarter-circle t)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2388 (nth 1 (nth 2 math-solve-lhs)))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2389 math-solve-rhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2390 ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2391 (math-try-solve-for (nth 2 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2392 (math-sub (nth 1 math-solve-lhs) math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2393 (and math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2394 (- math-try-solve-sign))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2395 ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2396 (math-try-solve-for (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2397 (math-add math-solve-rhs (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2398 math-try-solve-sign))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2399 ((and (eq math-solve-full 't) (math-try-solve-prod)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2400 ((and (eq (car math-solve-lhs) '%)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2401 (not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2402 (math-try-solve-for (nth 1 math-solve-lhs) (math-add math-solve-rhs
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2403 (math-solve-get-int
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2404 (nth 2 math-solve-lhs)))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2405 ((eq (car math-solve-lhs) 'calcFunc-log)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2406 (cond ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2407 (math-try-solve-for (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2408 (math-pow (nth 2 math-solve-lhs) math-solve-rhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2409 ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2410 (math-try-solve-for (nth 2 math-solve-lhs) (math-pow
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2411 (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2412 (math-div 1 math-solve-rhs))))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2413 ((and (= (length math-solve-lhs) 2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2414 (symbolp (car math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2415 (setq math-t1 (get (car math-solve-lhs) 'math-inverse))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2416 (setq math-t2 (funcall math-t1 math-solve-rhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2417 (setq math-t1 (get (car math-solve-lhs) 'math-inverse-sign))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2418 (math-try-solve-for (nth 1 math-solve-lhs) (math-normalize math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2419 (and math-try-solve-sign math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2420 (if (integerp math-t1)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2421 (* math-t1 math-try-solve-sign)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2422 (funcall math-t1 math-solve-lhs
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2423 math-try-solve-sign)))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2424 ((and (symbolp (car math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2425 (setq math-t1 (get (car math-solve-lhs) 'math-inverse-n))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2426 (setq math-t2 (funcall math-t1 math-solve-lhs math-solve-rhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2427 math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2428 ((setq math-t1 (math-expand-formula math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2429 (math-try-solve-for math-t1 math-solve-rhs math-try-solve-sign))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2430 (t
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2431 (calc-record-why "*No inverse known" math-solve-lhs)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2432 nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2433
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2434
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2435 (defun math-try-solve-prod ()
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2436 (cond ((eq (car math-solve-lhs) '*)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2437 (cond ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2438 (math-try-solve-for (nth 2 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2439 (math-div math-solve-rhs (nth 1 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2440 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2441 (nth 1 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2442 ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2443 (math-try-solve-for (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2444 (math-div math-solve-rhs (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2445 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2446 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2447 ((Math-zerop math-solve-rhs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2448 (math-solve-prod (let ((math-solve-ranges math-solve-ranges))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2449 (math-try-solve-for (nth 2 math-solve-lhs) 0))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2450 (math-try-solve-for (nth 1 math-solve-lhs) 0)))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2451 ((eq (car math-solve-lhs) '/)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2452 (cond ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2453 (math-try-solve-for (nth 2 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2454 (math-div (nth 1 math-solve-lhs) math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2455 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2456 (nth 1 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2457 ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2458 (math-try-solve-for (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2459 (math-mul math-solve-rhs (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2460 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2461 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2462 ((setq math-t1 (math-try-solve-for (math-sub (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2463 (math-mul (nth 2 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2464 math-solve-rhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2465 0))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2466 math-t1)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2467 ((eq (car math-solve-lhs) '^)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2468 (cond ((not (math-expr-contains (nth 1 math-solve-lhs) math-solve-var))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2469 (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2470 (nth 2 math-solve-lhs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2471 (math-add (math-normalize
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2472 (list 'calcFunc-log math-solve-rhs (nth 1 math-solve-lhs)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2473 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2474 (math-mul 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2475 (math-mul '(var pi var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2476 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2477 '(var i var-i))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2478 (math-normalize
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2479 (list 'calcFunc-ln (nth 1 math-solve-lhs)))))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2480 ((not (math-expr-contains (nth 2 math-solve-lhs) math-solve-var))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2481 (cond ((and (integerp (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2482 (>= (nth 2 math-solve-lhs) 2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2483 (setq math-t1 (math-integer-log2 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2484 (setq math-t2 math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2485 (if (and (eq math-solve-full t)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2486 (math-known-realp (nth 1 math-solve-lhs)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2487 (progn
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2488 (while (>= (setq math-t1 (1- math-t1)) 0)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2489 (setq math-t2 (list 'calcFunc-sqrt math-t2)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2490 (setq math-t2 (math-solve-get-sign math-t2)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2491 (while (>= (setq math-t1 (1- math-t1)) 0)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2492 (setq math-t2 (math-solve-get-sign
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2493 (math-normalize
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2494 (list 'calcFunc-sqrt math-t2))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2495 (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2496 (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2497 (math-normalize math-t2)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2498 ((math-looks-negp (nth 2 math-solve-lhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2499 (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2500 (list '^ (nth 1 math-solve-lhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2501 (math-neg (nth 2 math-solve-lhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2502 (math-div 1 math-solve-rhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2503 ((and (eq math-solve-full t)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2504 (Math-integerp (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2505 (math-known-realp (nth 1 math-solve-lhs)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2506 (setq math-t1 (math-normalize
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2507 (list 'calcFunc-nroot math-solve-rhs
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2508 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2509 (if (math-evenp (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2510 (setq math-t1 (math-solve-get-sign math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2511 (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2512 (nth 1 math-solve-lhs) math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2513 (and math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2514 (math-oddp (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2515 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2516 (nth 2 math-solve-lhs)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2517 (t (math-try-solve-for
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2518 (nth 1 math-solve-lhs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2519 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2520 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2521 (list 'calcFunc-exp
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2522 (if (Math-realp (nth 2 math-solve-lhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2523 (math-div (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2524 '(var pi var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2525 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2526 '(var i var-i)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2527 (and (integerp (nth 2 math-solve-lhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2528 (math-abs
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2529 (nth 2 math-solve-lhs)))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2530 (math-div (nth 2 math-solve-lhs) 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2531 (math-div (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2532 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2533 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2534 '(var pi var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2535 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2536 '(var i var-i)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2537 (and (integerp (nth 2 math-solve-lhs))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2538 (math-abs
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2539 (nth 2 math-solve-lhs))))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2540 (nth 2 math-solve-lhs)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2541 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2542 (list 'calcFunc-nroot
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2543 math-solve-rhs
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2544 (nth 2 math-solve-lhs))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2545 (and math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2546 (math-oddp (nth 2 math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2547 (math-solve-sign math-try-solve-sign
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2548 (nth 2 math-solve-lhs)))))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2549 (t nil)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2550
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2551 (defun math-solve-prod (lsoln rsoln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2552 (cond ((null lsoln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2553 rsoln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2554 ((null rsoln)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2555 lsoln)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2556 ((eq math-solve-full 'all)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2557 (cons 'vec (append (cdr lsoln) (cdr rsoln))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2558 (math-solve-full
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2559 (list 'calcFunc-if
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2560 (list 'calcFunc-gt (math-solve-get-sign 1) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2561 lsoln
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2562 rsoln))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2563 (t lsoln)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2564
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2565 ;;; This deals with negative, fractional, and symbolic powers of "x".
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2566 ;; The variable math-solve-b is local to math-decompose-poly,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2567 ;; but is used by math-solve-poly-funny-powers.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2568
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2569 (defun math-solve-poly-funny-powers (sub-rhs) ; uses "t1", "t2"
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2570 (setq math-t1 math-solve-lhs)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2571 (let ((pp math-poly-neg-powers)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2572 fac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2573 (while pp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2574 (setq fac (math-pow (car pp) (or math-poly-mult-powers 1))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2575 math-t1 (math-mul math-t1 fac)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2576 math-solve-rhs (math-mul math-solve-rhs fac)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2577 pp (cdr pp))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2578 (if sub-rhs (setq math-t1 (math-sub math-t1 math-solve-rhs)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2579 (let ((math-poly-neg-powers nil))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2580 (setq math-t2 (math-mul (or math-poly-mult-powers 1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2581 (let ((calc-prefer-frac t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2582 (math-div 1 math-poly-frac-powers)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2583 math-t1 (math-is-polynomial
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2584 (math-simplify (calcFunc-expand math-t1)) math-solve-b 50))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2585
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2586 ;;; This converts "a x^8 + b x^5 + c x^2" to "(a (x^3)^2 + b (x^3) + c) * x^2".
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2587 (defun math-solve-crunch-poly (max-degree) ; uses "t1", "t3"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2588 (let ((count 0))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2589 (while (and math-t1 (Math-zerop (car math-t1)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2590 (setq math-t1 (cdr math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2591 count (1+ count)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2592 (and math-t1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2593 (let* ((degree (1- (length math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2594 (scale degree))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2595 (while (and (> scale 1) (= (car math-t3) 1))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2596 (and (= (% degree scale) 0)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2597 (let ((p math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2598 (n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2599 (new-t1 nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2600 (okay t))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2601 (while (and p okay)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2602 (if (= (% n scale) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2603 (setq new-t1 (nconc new-t1 (list (car p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2604 (or (Math-zerop (car p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2605 (setq okay nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2606 (setq p (cdr p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2607 n (1+ n)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2608 (if okay
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2609 (setq math-t3 (cons scale (cdr math-t3))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2610 math-t1 new-t1))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2611 (setq scale (1- scale)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2612 (setq math-t3 (list (math-mul (car math-t3) math-t2)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2613 (math-mul count math-t2)))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2614 (<= (1- (length math-t1)) max-degree)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2615
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2616 (defun calcFunc-poly (expr var &optional degree)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2617 (if degree
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2618 (or (natnump degree) (math-reject-arg degree 'fixnatnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2619 (setq degree 50))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2620 (let ((p (math-is-polynomial expr var degree 'gen)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2621 (if p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2622 (if (equal p '(0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2623 (list 'vec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2624 (cons 'vec p))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2625 (math-reject-arg expr "Expected a polynomial"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2626
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2627 (defun calcFunc-gpoly (expr var &optional degree)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2628 (if degree
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2629 (or (natnump degree) (math-reject-arg degree 'fixnatnump))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2630 (setq degree 50))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2631 (let* ((math-poly-base-variable var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2632 (d (math-decompose-poly expr var degree nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2633 (if d
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2634 (cons 'vec d)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2635 (math-reject-arg expr "Expected a polynomial"))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2636
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2637 (defun math-decompose-poly (math-solve-lhs math-solve-var degree sub-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2638 (let ((math-solve-rhs (or sub-rhs 1))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2639 math-t1 math-t2 math-t3)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2640 (setq math-t2 (math-polynomial-base
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2641 math-solve-lhs
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2642 (function
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2643 (lambda (math-solve-b)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2644 (let ((math-poly-neg-powers '(1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2645 (math-poly-mult-powers nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2646 (math-poly-frac-powers 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2647 (math-poly-exp-base t))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2648 (and (not (equal math-solve-b math-solve-lhs))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2649 (or (not (memq (car-safe math-solve-b) '(+ -))) sub-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2650 (setq math-t3 '(1 0) math-t2 1
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2651 math-t1 (math-is-polynomial math-solve-lhs
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2652 math-solve-b 50))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2653 (if (and (equal math-poly-neg-powers '(1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2654 (memq math-poly-mult-powers '(nil 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2655 (eq math-poly-frac-powers 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2656 sub-rhs)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2657 (setq math-t1 (cons (math-sub (car math-t1) math-solve-rhs)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2658 (cdr math-t1)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2659 (math-solve-poly-funny-powers sub-rhs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2660 (math-solve-crunch-poly degree)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2661 (or (math-expr-contains math-solve-b math-solve-var)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2662 (math-expr-contains (car math-t3) math-solve-var))))))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2663 (if math-t2
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2664 (list (math-pow math-t2 (car math-t3))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2665 (cons 'vec math-t1)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2666 (if sub-rhs
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2667 (math-pow math-t2 (nth 1 math-t3))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2668 (math-div (math-pow math-t2 (nth 1 math-t3)) math-solve-rhs))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2669
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2670 (defun math-solve-linear (var sign b a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2671 (math-try-solve-for var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2672 (math-div (math-neg b) a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2673 (math-solve-sign sign a)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2674 t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2675
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2676 (defun math-solve-quadratic (var c b a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2677 (math-try-solve-for
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2678 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2679 (if (math-looks-evenp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2680 (let ((halfb (math-div b 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2681 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2682 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2683 (math-neg halfb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2684 (math-solve-get-sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2685 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2686 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2687 (math-add (math-sqr halfb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2688 (math-mul (math-neg c) a))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2689 a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2690 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2691 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2692 (math-neg b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2693 (math-solve-get-sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2694 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2695 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2696 (math-add (math-sqr b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2697 (math-mul 4 (math-mul (math-neg c) a)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2698 (math-mul 2 a)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2699 nil t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2700
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2701 (defun math-solve-cubic (var d c b a)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2702 (let* ((p (math-div b a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2703 (q (math-div c a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2704 (r (math-div d a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2705 (psqr (math-sqr p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2706 (aa (math-sub q (math-div psqr 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2707 (bb (math-add r
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2708 (math-div (math-sub (math-mul 2 (math-mul psqr p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2709 (math-mul 9 (math-mul p q)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2710 27)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2711 m)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2712 (if (Math-zerop aa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2713 (math-try-solve-for (math-pow (math-add var (math-div p 3)) 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2714 (math-neg bb) nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2715 (if (Math-zerop bb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2716 (math-try-solve-for
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2717 (math-mul (math-add var (math-div p 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2718 (math-add (math-sqr (math-add var (math-div p 3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2719 aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2720 0 nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2721 (setq m (math-mul 2 (list 'calcFunc-sqrt (math-div aa -3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2722 (math-try-solve-for
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2723 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2724 (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2725 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2726 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2727 m
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2728 (list 'calcFunc-cos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2729 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2730 (math-sub (list 'calcFunc-arccos
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2731 (math-div (math-mul 3 bb)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2732 (math-mul aa m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2733 (math-mul 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2734 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2735 (math-add 1 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2736 1 3))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2737 (math-half-circle
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2738 calc-symbolic-mode))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2739 3))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2740 (math-div p 3))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2741 nil t)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2742
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2743 (defun math-solve-quartic (var d c b a aa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2744 (setq a (math-div a aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2745 (setq b (math-div b aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2746 (setq c (math-div c aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2747 (setq d (math-div d aa))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2748 (math-try-solve-for
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2749 var
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2750 (let* ((asqr (math-sqr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2751 (asqr4 (math-div asqr 4))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2752 (y (let ((math-solve-full nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2753 calc-next-why)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2754 (math-solve-cubic math-solve-var
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2755 (math-sub (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2756 (math-mul 4 (math-mul b d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2757 (math-mul asqr d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2758 (math-sqr c))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2759 (math-sub (math-mul a c)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2760 (math-mul 4 d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2761 (math-neg b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2762 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2763 (rsqr (math-add (math-sub asqr4 b) y))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2764 (r (list 'calcFunc-sqrt rsqr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2765 (sign1 (math-solve-get-sign 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2766 (de (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2767 (math-add
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2768 (math-sub (math-mul 3 asqr4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2769 (math-mul 2 b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2770 (if (Math-zerop rsqr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2771 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2772 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2773 (math-mul sign1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2774 (list 'calcFunc-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2775 (math-sub (math-sqr y)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2776 (math-mul 4 d)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2777 (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2778 (math-mul sign1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2779 (math-div
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2780 (math-sub (math-sub
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2781 (math-mul 4 (math-mul a b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2782 (math-mul 8 c))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2783 (math-mul asqr a))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2784 (math-mul 4 r)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2785 rsqr))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2786 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2787 (math-sub (math-add (math-mul sign1 (math-div r 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2788 (math-solve-get-sign (math-div de 2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2789 (math-div a 4))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2790 nil t))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2791
41271
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2792 (defvar math-symbolic-solve nil)
fcd507927105 Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents: 41047
diff changeset
2793 (defvar math-int-coefs nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2794
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2795 ;; The variable math-int-threshold is local to math-poly-all-roots,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2796 ;; but is used by math-poly-newton-root.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2797 (defvar math-int-threshold)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2798 ;; The variables math-int-scale, math-int-factors and math-double-roots
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2799 ;; are local to math-poly-all-roots, but are used by math-poly-integer-root.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2800 (defvar math-int-scale)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2801
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2802 (defun math-poly-all-roots (var p &optional math-factoring)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2803 (catch 'ouch
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2804 (let* ((math-symbolic-solve calc-symbolic-mode)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2805 (roots nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2806 (deg (1- (length p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2807 (orig-p (reverse p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2808 (math-int-coefs nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2809 (math-int-scale nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2810 (math-double-roots nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2811 (math-int-factors nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2812 (math-int-threshold nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2813 (pp p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2814 ;; If rational coefficients, look for exact rational factors.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2815 (while (and pp (Math-ratp (car pp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2816 (setq pp (cdr pp)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2817 (if pp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2818 (if (or math-factoring math-symbolic-solve)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2819 (throw 'ouch nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2820 (let ((lead (car orig-p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2821 (calc-prefer-frac t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2822 (scale (apply 'math-lcm-denoms p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2823 (setq math-int-scale (math-abs (math-mul scale lead))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2824 math-int-threshold (math-div '(float 5 -2) math-int-scale)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2825 math-int-coefs (cdr (math-div (cons 'vec orig-p) lead)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2826 (if (> deg 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2827 (let ((calc-prefer-frac nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2828 (calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2829 (pp p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2830 (def-p (copy-sequence orig-p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2831 (while pp
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2832 (if (Math-numberp (car pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2833 (setq pp (cdr pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2834 (throw 'ouch nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2835 (while (> deg (if math-symbolic-solve 2 4))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2836 (let* ((x (math-poly-any-root def-p '(float 0 0) nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2837 b c pp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2838 (if (and (eq (car-safe x) 'cplx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2839 (math-nearly-zerop (nth 2 x) (nth 1 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2840 (setq x (calcFunc-re x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2841 (or math-factoring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2842 (setq roots (cons x roots)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2843 (or (math-numberp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2844 (setq x (math-evaluate-expr x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2845 (setq pp def-p
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2846 b (car def-p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2847 (while (setq pp (cdr pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2848 (setq c (car pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2849 (setcar pp b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2850 (setq b (math-add (math-mul x b) c)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2851 (setq def-p (cdr def-p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2852 deg (1- deg))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2853 (setq p (reverse def-p))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2854 (if (> deg 1)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2855 (let ((math-solve-var '(var DUMMY var-DUMMY))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2856 (math-solve-sign nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2857 (math-solve-ranges nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2858 (math-solve-full 'all))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2859 (if (= (length p) (length math-int-coefs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2860 (setq p (reverse math-int-coefs)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2861 (setq roots (append (cdr (apply (cond ((= deg 2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2862 'math-solve-quadratic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2863 ((= deg 3)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2864 'math-solve-cubic)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2865 (t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2866 'math-solve-quartic))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2867 math-solve-var p))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2868 roots)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2869 (if (> deg 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2870 (setq roots (cons (math-div (math-neg (car p)) (nth 1 p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2871 roots))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2872 (if math-factoring
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2873 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2874 (while roots
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2875 (math-poly-integer-root (car roots))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2876 (setq roots (cdr roots)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2877 (list math-int-factors (nreverse math-int-coefs) math-int-scale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2878 (let ((vec nil) res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2879 (while roots
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2880 (let ((root (car roots))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2881 (math-solve-full (and math-solve-full 'all)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2882 (if (math-floatp root)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2883 (setq root (math-poly-any-root orig-p root t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2884 (setq vec (append vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2885 (cdr (or (math-try-solve-for var root nil t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2886 (throw 'ouch nil))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2887 (setq roots (cdr roots)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2888 (setq vec (cons 'vec (nreverse vec)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2889 (if math-symbolic-solve
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2890 (setq vec (math-normalize vec)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
2891 (if (eq math-solve-full t)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2892 (list 'calcFunc-subscr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2893 vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2894 (math-solve-get-int 1 (1- (length orig-p)) 1))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2895 vec))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2896
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2897 (defun math-lcm-denoms (&rest fracs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2898 (let ((den 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2899 (while fracs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2900 (if (eq (car-safe (car fracs)) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2901 (setq den (calcFunc-lcm den (nth 2 (car fracs)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2902 (setq fracs (cdr fracs)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2903 den))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2904
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2905 (defun math-poly-any-root (p x polish) ; p is a reverse poly coeff list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2906 (let* ((newt (if (math-zerop x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2907 (math-poly-newton-root
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2908 p '(cplx (float 123 -6) (float 1 -4)) 4)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2909 (math-poly-newton-root p x 4)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2910 (res (if (math-zerop (cdr newt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2911 (car newt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2912 (if (and (math-lessp (cdr newt) '(float 1 -3)) (not polish))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2913 (setq newt (math-poly-newton-root p (car newt) 30)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2914 (if (math-zerop (cdr newt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2915 (car newt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2916 (math-poly-laguerre-root p x polish)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2917 (and math-symbolic-solve (math-floatp res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2918 (throw 'ouch nil))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2919 res))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2920
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2921 (defun math-poly-newton-root (p x iters)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2922 (let* ((calc-prefer-frac nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2923 (calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2924 (try-integer math-int-coefs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2925 (dx x) b d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2926 (while (and (> (setq iters (1- iters)) 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2927 (let ((pp p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2928 (math-working "newton" x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2929 (setq b (car p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2930 d 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2931 (while (setq pp (cdr pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2932 (setq d (math-add (math-mul x d) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2933 b (math-add (math-mul x b) (car pp))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2934 (not (math-zerop d)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2935 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2936 (setq dx (math-div b d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2937 x (math-sub x dx))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2938 (if try-integer
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2939 (let ((adx (math-abs-approx dx)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2940 (and (math-lessp adx math-int-threshold)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2941 (let ((iroot (math-poly-integer-root x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2942 (if iroot
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2943 (setq x iroot dx 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2944 (setq try-integer nil))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2945 (or (not (or (eq dx 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2946 (math-nearly-zerop dx (math-abs-approx x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2947 (progn (setq dx 0) nil)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2948 (cons x (if (math-zerop x)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
2949 1 (math-div (math-abs-approx dx) (math-abs-approx x))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2950
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2951 (defun math-poly-integer-root (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2952 (and (math-lessp (calcFunc-xpon (math-abs-approx x)) calc-internal-prec)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2953 math-int-coefs
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2954 (let* ((calc-prefer-frac t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2955 (xre (calcFunc-re x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2956 (xim (calcFunc-im x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2957 (xresq (math-sqr xre))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2958 (ximsq (math-sqr xim)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2959 (if (math-lessp ximsq (calcFunc-scf xresq -1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2960 ;; Look for linear factor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2961 (let* ((rnd (math-div (math-round (math-mul xre math-int-scale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2962 math-int-scale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2963 (icp math-int-coefs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2964 (rem (car icp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2965 (newcoef nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2966 (while (setq icp (cdr icp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2967 (setq newcoef (cons rem newcoef)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2968 rem (math-add (car icp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2969 (math-mul rem rnd))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2970 (and (math-zerop rem)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2971 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2972 (setq math-int-coefs (nreverse newcoef)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2973 math-int-factors (cons (list (math-neg rnd))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2974 math-int-factors))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2975 rnd)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2976 ;; Look for irreducible quadratic factor
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2977 (let* ((rnd1 (math-div (math-round
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2978 (math-mul xre (math-mul -2 math-int-scale)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2979 math-int-scale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2980 (sqscale (math-sqr math-int-scale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2981 (rnd0 (math-div (math-round (math-mul (math-add xresq ximsq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2982 sqscale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2983 sqscale))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2984 (rem1 (car math-int-coefs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2985 (icp (cdr math-int-coefs))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2986 (rem0 (car icp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2987 (newcoef nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2988 (found (assoc (list rnd0 rnd1 (math-posp xim))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2989 math-double-roots))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2990 this)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2991 (if found
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2992 (setq math-double-roots (delq found math-double-roots)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2993 rem0 0 rem1 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2994 (while (setq icp (cdr icp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2995 (setq this rem1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2996 newcoef (cons rem1 newcoef)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2997 rem1 (math-sub rem0 (math-mul this rnd1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2998 rem0 (math-sub (car icp) (math-mul this rnd0)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2999 (and (math-zerop rem0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3000 (math-zerop rem1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3001 (let ((aa (math-div rnd1 -2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3002 (or found (setq math-int-coefs (reverse newcoef)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3003 math-double-roots (cons (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3004 (list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3005 rnd0 rnd1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3006 (math-negp xim)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3007 math-double-roots)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3008 math-int-factors (cons (cons rnd0 rnd1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3009 math-int-factors)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3010 (math-add aa
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3011 (let ((calc-symbolic-mode math-symbolic-solve))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3012 (math-mul (math-sqrt (math-sub (math-sqr aa)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3013 rnd0))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3014 (if (math-negp xim) -1 1)))))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3015
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3016 ;;; The following routine is from Numerical Recipes, section 9.5.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3017 (defun math-poly-laguerre-root (p x polish)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3018 (let* ((calc-prefer-frac nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3019 (calc-symbolic-mode nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3020 (iters 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3021 (m (1- (length p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3022 (try-newt (not polish))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3023 (tried-newt nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3024 b d f x1 dx dxold)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3025 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3026 (and (or (< (setq iters (1+ iters)) 50)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3027 (math-reject-arg x "*Laguerre's method failed to converge"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3028 (let ((err (math-abs-approx (car p)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3029 (abx (math-abs-approx x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3030 (pp p))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3031 (setq b (car p)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3032 d 0 f 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3033 (while (setq pp (cdr pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3034 (setq f (math-add (math-mul x f) d)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3035 d (math-add (math-mul x d) b)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3036 b (math-add (math-mul x b) (car pp))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3037 err (math-add (math-abs-approx b) (math-mul abx err))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3038 (math-lessp (calcFunc-scf err (- -2 calc-internal-prec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3039 (math-abs-approx b)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3040 (or (not (math-zerop d))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3041 (not (math-zerop f))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3042 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3043 (setq x (math-pow (math-neg b) (list 'frac 1 m)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3044 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3045 (let* ((g (math-div d b))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3046 (g2 (math-sqr g))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3047 (h (math-sub g2 (math-mul 2 (math-div f b))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3048 (sq (math-sqrt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3049 (math-mul (1- m) (math-sub (math-mul m h) g2))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3050 (gp (math-add g sq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3051 (gm (math-sub g sq)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3052 (if (math-lessp (calcFunc-abssqr gp) (calcFunc-abssqr gm))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3053 (setq gp gm))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3054 (setq dx (math-div m gp)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3055 x1 (math-sub x dx))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3056 (if (and try-newt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3057 (math-lessp (math-abs-approx dx)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3058 (calcFunc-scf (math-abs-approx x) -3)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3059 (let ((newt (math-poly-newton-root p x1 7)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3060 (setq tried-newt t
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3061 try-newt nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3062 (if (math-zerop (cdr newt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3063 (setq x (car newt) x1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3064 (if (math-lessp (cdr newt) '(float 1 -6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3065 (let ((newt2 (math-poly-newton-root
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3066 p (car newt) 20)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3067 (if (math-zerop (cdr newt2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3068 (setq x (car newt2) x1 x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3069 (setq x (car newt))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3070 (not (or (eq x x1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3071 (math-nearly-equal x x1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3072 (let ((cdx (math-abs-approx dx)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3073 (setq x x1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3074 tried-newt nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3075 (prog1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3076 (or (<= iters 6)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3077 (math-lessp cdx dxold)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3078 (progn
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3079 (if polish
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3080 (let ((digs (calcFunc-xpon
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3081 (math-div (math-abs-approx x) cdx))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3082 (calc-record-why
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3083 "*Could not attain full precision")
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3084 (if (natnump digs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3085 (let ((calc-internal-prec (max 3 digs)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3086 (setq x (math-normalize x))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3087 nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3088 (setq dxold cdx)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3089 (or polish
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3090 (math-lessp (calcFunc-scf (math-abs-approx x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3091 (- calc-internal-prec))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3092 dxold))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3093 (or (and (math-floatp x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3094 (math-poly-integer-root x))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3095 x)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3096
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3097 (defun math-solve-above-dummy (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3098 (and (not (Math-primp x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3099 (if (and (equal (nth 1 x) '(var SOLVEDUM SOLVEDUM))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3100 (= (length x) 2))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3101 x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3102 (let ((res nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3103 (while (and (setq x (cdr x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3104 (not (setq res (math-solve-above-dummy (car x))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3105 res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3106
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3107 (defun math-solve-find-root-term (x neg) ; sets "t2", "t3"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3108 (if (math-solve-find-root-in-prod x)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3109 (setq math-t3 neg
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3110 math-t1 x)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3111 (and (memq (car-safe x) '(+ -))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3112 (or (math-solve-find-root-term (nth 1 x) neg)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3113 (math-solve-find-root-term (nth 2 x)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3114 (if (eq (car x) '-) (not neg) neg))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3115
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3116 (defun math-solve-find-root-in-prod (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3117 (and (consp x)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3118 (math-expr-contains x math-solve-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3119 (or (and (eq (car x) 'calcFunc-sqrt)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3120 (setq math-t2 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3121 (and (eq (car x) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3122 (or (and (memq (math-quarter-integer (nth 2 x)) '(1 2 3))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3123 (setq math-t2 2))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3124 (and (eq (car-safe (nth 2 x)) 'frac)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3125 (eq (nth 2 (nth 2 x)) 3)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3126 (setq math-t2 3))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3127 (and (memq (car x) '(* /))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3128 (or (and (not (math-expr-contains (nth 1 x) math-solve-var))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3129 (math-solve-find-root-in-prod (nth 2 x)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3130 (and (not (math-expr-contains (nth 2 x) math-solve-var))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3131 (math-solve-find-root-in-prod (nth 1 x))))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3132
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3133 ;; The variable math-solve-vars is local to math-solve-system,
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3134 ;; but is used by math-solve-system-rec.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3135 (defvar math-solve-vars)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3136
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3137 ;; The variable math-solve-simplifying is local to math-solve-system
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3138 ;; and math-solve-system-rec, but is used by math-solve-system-subst.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3139
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3140 (defun math-solve-system (exprs math-solve-vars math-solve-full)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3141 (setq exprs (mapcar 'list (if (Math-vectorp exprs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3142 (cdr exprs)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3143 (list exprs)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3144 math-solve-vars (if (Math-vectorp math-solve-vars)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3145 (cdr math-solve-vars)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3146 (list math-solve-vars)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3147 (or (let ((math-solve-simplifying nil))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3148 (math-solve-system-rec exprs math-solve-vars nil))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3149 (let ((math-solve-simplifying t))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3150 (math-solve-system-rec exprs math-solve-vars nil))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3151
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3152 ;;; The following backtracking solver works by choosing a variable
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3153 ;;; and equation, and trying to solve the equation for the variable.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3154 ;;; If it succeeds it calls itself recursively with that variable and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3155 ;;; equation removed from their respective lists, and with the solution
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3156 ;;; added to solns as well as being substituted into all existing
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3157 ;;; equations. The algorithm terminates when any solution path
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3158 ;;; manages to remove all the variables from var-list.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3159
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3160 ;;; To support calcFunc-roots, entries in eqn-list and solns are
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3161 ;;; actually lists of equations.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3162
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3163 ;; The variables math-solve-system-res and math-solve-system-vv are
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3164 ;; local to math-solve-system-rec, but are used by math-solve-system-subst.
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3165 (defvar math-solve-system-vv)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3166 (defvar math-solve-system-res)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3167
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3168
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3169 (defun math-solve-system-rec (eqn-list var-list solns)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3170 (if var-list
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3171 (let ((v var-list)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3172 (math-solve-system-res nil))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3173
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3174 ;; Try each variable in turn.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3175 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3176 (and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3177 v
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3178 (let* ((math-solve-system-vv (car v))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3179 (e eqn-list)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3180 (elim (eq (car-safe math-solve-system-vv) 'calcFunc-elim)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3181 (if elim
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3182 (setq math-solve-system-vv (nth 1 math-solve-system-vv)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3183
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3184 ;; Try each equation in turn.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3185 (while
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3186 (and
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3187 e
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3188 (let ((e2 (car e))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3189 (eprev nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3190 res2)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3191 (setq math-solve-system-res nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3192
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3193 ;; Try to solve for math-solve-system-vv the list of equations e2.
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3194 (while (and e2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3195 (setq res2 (or (and (eq (car e2) eprev)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3196 res2)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3197 (math-solve-for (car e2) 0
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3198 math-solve-system-vv
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3199 math-solve-full))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3200 (setq eprev (car e2)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3201 math-solve-system-res (cons (if (eq math-solve-full 'all)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3202 (cdr res2)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3203 (list res2))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3204 math-solve-system-res)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3205 e2 (cdr e2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3206 (if e2
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3207 (setq math-solve-system-res nil)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3208
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3209 ;; Found a solution. Now try other variables.
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3210 (setq math-solve-system-res (nreverse math-solve-system-res)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3211 math-solve-system-res (math-solve-system-rec
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3212 (mapcar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3213 'math-solve-system-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3214 (delq (car e)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3215 (copy-sequence eqn-list)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3216 (delq (car v) (copy-sequence var-list))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3217 (let ((math-solve-simplifying nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3218 (s (mapcar
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3219 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3220 (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3221 (cons
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3222 (car x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3223 (math-solve-system-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3224 (cdr x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3225 solns)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3226 (if elim
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3227 s
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3228 (cons (cons
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3229 math-solve-system-vv
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3230 (apply 'append math-solve-system-res))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3231 s)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3232 (not math-solve-system-res))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3233 (setq e (cdr e)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3234 (not math-solve-system-res)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3235 (setq v (cdr v)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3236 math-solve-system-res)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3237
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3238 ;; Eliminated all variables, so now put solution into the proper format.
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3239 (setq solns (sort solns
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3240 (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3241 (lambda (x y)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3242 (not (memq (car x) (memq (car y) math-solve-vars)))))))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3243 (if (eq math-solve-full 'all)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3244 (math-transpose
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3245 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3246 (cons 'vec
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3247 (if solns
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3248 (mapcar (function (lambda (x) (cons 'vec (cdr x)))) solns)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3249 (mapcar (function (lambda (x) (cons 'vec x))) eqn-list)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3250 (math-normalize
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49263
diff changeset
3251 (cons 'vec
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3252 (if solns
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3253 (mapcar (function (lambda (x) (cons 'calcFunc-eq x))) solns)
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3254 (mapcar 'car eqn-list)))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3255
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3256 (defun math-solve-system-subst (x) ; uses "res" and "v"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3257 (let ((accum nil)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3258 (res2 math-solve-system-res))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3259 (while x
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3260 (setq accum (nconc accum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3261 (mapcar (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3262 (lambda (r)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3263 (if math-solve-simplifying
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3264 (math-simplify
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3265 (math-expr-subst
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3266 (car x) math-solve-system-vv r))
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3267 (math-expr-subst
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3268 (car x) math-solve-system-vv r))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3269 (car res2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3270 x (cdr x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3271 res2 (cdr res2)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3272 accum))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3273
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3274
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3275 ;; calc-command-flags is declared in calc.el
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3276 (defvar calc-command-flags)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3277
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3278 (defun math-get-from-counter (name)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3279 (let ((ctr (assq name calc-command-flags)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3280 (if ctr
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3281 (setcdr ctr (1+ (cdr ctr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3282 (setq ctr (cons name 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3283 calc-command-flags (cons ctr calc-command-flags)))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3284 (cdr ctr)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3285
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3286 (defvar var-GenCount)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3287
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3288 (defun math-solve-get-sign (val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3289 (setq val (math-simplify val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3290 (if (and (eq (car-safe val) '*)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3291 (Math-numberp (nth 1 val)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3292 (list '* (nth 1 val) (math-solve-get-sign (nth 2 val)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3293 (and (eq (car-safe val) 'calcFunc-sqrt)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3294 (eq (car-safe (nth 1 val)) '^)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3295 (setq val (math-normalize (list '^
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3296 (nth 1 (nth 1 val))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3297 (math-div (nth 2 (nth 1 val)) 2)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3298 (if math-solve-full
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3299 (if (and (calc-var-value 'var-GenCount)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3300 (Math-natnump var-GenCount)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3301 (not (eq math-solve-full 'all)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3302 (prog1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3303 (math-mul (list 'calcFunc-as var-GenCount) val)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3304 (setq var-GenCount (math-add var-GenCount 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3305 (calc-refresh-evaltos 'var-GenCount))
43506
43be8de143a2 (math-solve-get-sign): Convert integer to string.
Colin Walters <walters@gnu.org>
parents: 43404
diff changeset
3306 (let* ((var (concat "s" (int-to-string (math-get-from-counter 'solve-sign))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3307 (var2 (list 'var (intern var) (intern (concat "var-" var)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3308 (if (eq math-solve-full 'all)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3309 (setq math-solve-ranges (cons (list var2 1 -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3310 math-solve-ranges)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3311 (math-mul var2 val)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3312 (calc-record-why "*Choosing positive solution")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3313 val)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3314
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3315 (defun math-solve-get-int (val &optional range first)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3316 (if math-solve-full
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3317 (if (and (calc-var-value 'var-GenCount)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3318 (Math-natnump var-GenCount)
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3319 (not (eq math-solve-full 'all)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3320 (prog1
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3321 (math-mul val (list 'calcFunc-an var-GenCount))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3322 (setq var-GenCount (math-add var-GenCount 1))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3323 (calc-refresh-evaltos 'var-GenCount))
43404
36c14bc6e7fb (math-solve-get-int): Convert return value from
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
3324 (let* ((var (concat "n" (int-to-string
36c14bc6e7fb (math-solve-get-int): Convert return value from
Colin Walters <walters@gnu.org>
parents: 41271
diff changeset
3325 (math-get-from-counter 'solve-int))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3326 (var2 (list 'var (intern var) (intern (concat "var-" var)))))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3327 (if (and range (eq math-solve-full 'all))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3328 (setq math-solve-ranges (cons (cons var2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3329 (cdr (calcFunc-index
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3330 range (or first 0))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3331 math-solve-ranges)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3332 (math-mul val var2)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3333 (calc-record-why "*Choosing 0 for arbitrary integer in solution")
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3334 0))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3335
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3336 (defun math-solve-sign (sign expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3337 (and sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3338 (let ((s1 (math-possible-signs expr)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3339 (cond ((memq s1 '(4 6))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3340 sign)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3341 ((memq s1 '(1 3))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3342 (- sign))))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3343
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3344 (defun math-looks-evenp (expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3345 (if (Math-integerp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3346 (math-evenp expr)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3347 (if (memq (car expr) '(* /))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3348 (math-looks-evenp (nth 1 expr)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3349
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3350 (defun math-solve-for (lhs rhs math-solve-var math-solve-full &optional sign)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3351 (if (math-expr-contains rhs math-solve-var)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3352 (math-solve-for (math-sub lhs rhs) 0 math-solve-var math-solve-full)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3353 (and (math-expr-contains lhs math-solve-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3354 (math-with-extra-prec 1
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3355 (let* ((math-poly-base-variable math-solve-var)
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3356 (res (math-try-solve-for lhs rhs sign)))
58229
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3357 (if (and (eq math-solve-full 'all)
7f5b01c17652 (math-integrate-by-parts): Removed unused variable var-thing.
Jay Belanger <jay.p.belanger@gmail.com>
parents: 58027
diff changeset
3358 (math-known-realp math-solve-var))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3359 (let ((old-len (length res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3360 new-len)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3361 (setq res (delq nil
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3362 (mapcar (function
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3363 (lambda (x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3364 (and (not (memq (car-safe x)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3365 '(cplx polar)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3366 x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3367 res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3368 new-len (length res))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3369 (if (< new-len old-len)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3370 (calc-record-why (if (= new-len 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3371 "*All solutions were complex"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3372 (format
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3373 "*Omitted %d complex solutions"
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3374 (- old-len new-len)))))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3375 res)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3376
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3377 (defun math-solve-eqn (expr var full)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3378 (if (memq (car-safe expr) '(calcFunc-neq calcFunc-lt calcFunc-gt
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3379 calcFunc-leq calcFunc-geq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3380 (let ((res (math-solve-for (cons '- (cdr expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3381 0 var full
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3382 (if (eq (car expr) 'calcFunc-neq) nil 1))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3383 (and res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3384 (if (eq math-solve-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3385 (list (car expr) var res)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3386 (if (eq math-solve-sign -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3387 (list (car expr) res var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3388 (or (eq (car expr) 'calcFunc-neq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3389 (calc-record-why
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3390 "*Can't determine direction of inequality"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3391 (and (memq (car expr) '(calcFunc-neq calcFunc-lt calcFunc-gt))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3392 (list 'calcFunc-neq var res))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3393 (let ((res (math-solve-for expr 0 var full)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3394 (and res
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3395 (list 'calcFunc-eq var res)))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3396
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3397 (defun math-reject-solution (expr var func)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3398 (if (math-expr-contains expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3399 (or (equal (car calc-next-why) '(* "Unable to find a symbolic solution"))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3400 (calc-record-why "*Unable to find a solution")))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3401 (list func expr var))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3402
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3403 (defun calcFunc-solve (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3404 (or (if (or (Math-vectorp expr) (Math-vectorp var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3405 (math-solve-system expr var nil)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3406 (math-solve-eqn expr var nil))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3407 (math-reject-solution expr var 'calcFunc-solve)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3408
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3409 (defun calcFunc-fsolve (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3410 (or (if (or (Math-vectorp expr) (Math-vectorp var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3411 (math-solve-system expr var t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3412 (math-solve-eqn expr var t))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3413 (math-reject-solution expr var 'calcFunc-fsolve)))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3414
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3415 (defun calcFunc-roots (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3416 (let ((math-solve-ranges nil))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3417 (or (if (or (Math-vectorp expr) (Math-vectorp var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3418 (math-solve-system expr var 'all)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3419 (math-solve-for expr 0 var 'all))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3420 (math-reject-solution expr var 'calcFunc-roots))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3421
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3422 (defun calcFunc-finv (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3423 (let ((res (math-solve-for expr math-integ-var var nil)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3424 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3425 (math-normalize (math-expr-subst res math-integ-var var))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3426 (math-reject-solution expr var 'calcFunc-finv))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3427
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3428 (defun calcFunc-ffinv (expr var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3429 (let ((res (math-solve-for expr math-integ-var var t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3430 (if res
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3431 (math-normalize (math-expr-subst res math-integ-var var))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3432 (math-reject-solution expr var 'calcFunc-finv))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3433
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3434
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3435 (put 'calcFunc-inv 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3436 (function (lambda (x) (math-div 1 x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3437 (put 'calcFunc-inv 'math-inverse-sign -1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3438
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3439 (put 'calcFunc-sqrt 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3440 (function (lambda (x) (math-sqr x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3441
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3442 (put 'calcFunc-conj 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3443 (function (lambda (x) (list 'calcFunc-conj x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3444
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3445 (put 'calcFunc-abs 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3446 (function (lambda (x) (math-solve-get-sign x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3447
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3448 (put 'calcFunc-deg 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3449 (function (lambda (x) (list 'calcFunc-rad x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3450 (put 'calcFunc-deg 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3451
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3452 (put 'calcFunc-rad 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3453 (function (lambda (x) (list 'calcFunc-deg x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3454 (put 'calcFunc-rad 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3455
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3456 (put 'calcFunc-ln 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3457 (function (lambda (x) (list 'calcFunc-exp x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3458 (put 'calcFunc-ln 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3459
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3460 (put 'calcFunc-log10 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3461 (function (lambda (x) (list 'calcFunc-exp10 x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3462 (put 'calcFunc-log10 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3463
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3464 (put 'calcFunc-lnp1 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3465 (function (lambda (x) (list 'calcFunc-expm1 x))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3466 (put 'calcFunc-lnp1 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3467
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3468 (put 'calcFunc-exp 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3469 (function (lambda (x) (math-add (math-normalize (list 'calcFunc-ln x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3470 (math-mul 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3471 (math-mul '(var pi var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3472 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3473 '(var i var-i))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3474 (put 'calcFunc-exp 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3475
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3476 (put 'calcFunc-expm1 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3477 (function (lambda (x) (math-add (math-normalize (list 'calcFunc-lnp1 x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3478 (math-mul 2
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3479 (math-mul '(var pi var-pi)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3480 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3481 '(var i var-i))))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3482 (put 'calcFunc-expm1 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3483
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3484 (put 'calcFunc-sin 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3485 (function (lambda (x) (let ((n (math-solve-get-int 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3486 (math-add (math-mul (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3487 (list 'calcFunc-arcsin x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3488 (math-pow -1 n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3489 (math-mul (math-half-circle t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3490 n))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3491
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3492 (put 'calcFunc-cos 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3493 (function (lambda (x) (math-add (math-solve-get-sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3494 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3495 (list 'calcFunc-arccos x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3496 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3497 (math-full-circle t))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3498
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3499 (put 'calcFunc-tan 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3500 (function (lambda (x) (math-add (math-normalize (list 'calcFunc-arctan x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3501 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3502 (math-half-circle t))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3503
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3504 (put 'calcFunc-arcsin 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3505 (function (lambda (x) (math-normalize (list 'calcFunc-sin x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3506
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3507 (put 'calcFunc-arccos 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3508 (function (lambda (x) (math-normalize (list 'calcFunc-cos x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3509
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3510 (put 'calcFunc-arctan 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3511 (function (lambda (x) (math-normalize (list 'calcFunc-tan x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3512
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3513 (put 'calcFunc-sinh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3514 (function (lambda (x) (let ((n (math-solve-get-int 1)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3515 (math-add (math-mul (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3516 (list 'calcFunc-arcsinh x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3517 (math-pow -1 n))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3518 (math-mul (math-half-circle t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3519 (math-mul
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3520 '(var i var-i)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3521 n)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3522 (put 'calcFunc-sinh 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3523
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3524 (put 'calcFunc-cosh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3525 (function (lambda (x) (math-add (math-solve-get-sign
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3526 (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3527 (list 'calcFunc-arccosh x)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3528 (math-mul (math-full-circle t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3529 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3530 '(var i var-i)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3531
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3532 (put 'calcFunc-tanh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3533 (function (lambda (x) (math-add (math-normalize
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3534 (list 'calcFunc-arctanh x))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3535 (math-mul (math-half-circle t)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3536 (math-solve-get-int
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3537 '(var i var-i)))))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3538 (put 'calcFunc-tanh 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3539
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3540 (put 'calcFunc-arcsinh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3541 (function (lambda (x) (math-normalize (list 'calcFunc-sinh x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3542 (put 'calcFunc-arcsinh 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3543
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3544 (put 'calcFunc-arccosh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3545 (function (lambda (x) (math-normalize (list 'calcFunc-cosh x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3546
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3547 (put 'calcFunc-arctanh 'math-inverse
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3548 (function (lambda (x) (math-normalize (list 'calcFunc-tanh x)))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3549 (put 'calcFunc-arctanh 'math-inverse-sign 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3550
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3551
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3552
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3553 (defun calcFunc-taylor (expr var num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3554 (let ((x0 0) (v var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3555 (if (memq (car-safe var) '(+ - calcFunc-eq))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3556 (setq x0 (if (eq (car var) '+) (math-neg (nth 2 var)) (nth 2 var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3557 v (nth 1 var)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3558 (or (and (eq (car-safe v) 'var)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3559 (math-expr-contains expr v)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3560 (natnump num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3561 (let ((accum (math-expr-subst expr v x0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3562 (var2 (if (eq (car var) 'calcFunc-eq)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3563 (cons '- (cdr var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3564 var))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3565 (n 0)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3566 (nfac 1)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3567 (fprime expr))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3568 (while (and (<= (setq n (1+ n)) num)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3569 (setq fprime (calcFunc-deriv fprime v nil t)))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3570 (setq fprime (math-simplify fprime)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3571 nfac (math-mul nfac n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3572 accum (math-add accum
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3573 (math-div (math-mul (math-pow var2 n)
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3574 (math-expr-subst
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3575 fprime v x0))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3576 nfac))))
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3577 (and fprime
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3578 (math-normalize accum))))
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3579 (list 'calcFunc-taylor expr var num))))
40785
2fb9d407ae73 Initial import of Calc 2.02f.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3580
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
3581 ;;; arch-tag: f2932ec8-dd63-418b-a542-11a644b9d4c4
41047
73f364fd8aaa Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents: 40785
diff changeset
3582 ;;; calcalg2.el ends here