comparison lisp/calc/calcalg2.el @ 58023:768b8e4f123b

(math-linear-subst-tried): New variable. (math-do-integral): Set `math-linear-subst-tried' to nil. (math-do-integral-methods): Use `math-linear-subst-tried' to determine what type of substitution to try. (math-integ-try-linear-substituion): Set `math-linear-subst-tried' to t.
author Jay Belanger <jay.p.belanger@gmail.com>
date Sun, 07 Nov 2004 23:33:29 +0000
parents 695cf19ef79e
children 771eb065ad11
comparison
equal deleted inserted replaced
58022:4f686c82cfc9 58023:768b8e4f123b
736 (setcar expr (nth 1 (nth 2 (car expr)))) 736 (setcar expr (nth 1 (nth 2 (car expr))))
737 (math-replace-integral-parts (cons 'foo expr))) 737 (math-replace-integral-parts (cons 'foo expr)))
738 (setcar (cdr cur-record) 'cancelled))) 738 (setcar (cdr cur-record) 'cancelled)))
739 (math-replace-integral-parts (car expr))))))) 739 (math-replace-integral-parts (car expr)))))))
740 740
741 (defvar math-linear-subst-tried t
742 "Non-nil means that a linear substitution has been tried.")
743
741 (defun math-do-integral (expr) 744 (defun math-do-integral (expr)
742 (let (t1 t2) 745 (let ((math-linear-subst-tried nil)
746 t1 t2)
743 (or (cond ((not (math-expr-contains expr math-integ-var)) 747 (or (cond ((not (math-expr-contains expr math-integ-var))
744 (math-mul expr math-integ-var)) 748 (math-mul expr math-integ-var))
745 ((equal expr math-integ-var) 749 ((equal expr math-integ-var)
746 (math-div (math-sqr expr) 2)) 750 (math-div (math-sqr expr) 2))
747 ((eq (car expr) '+) 751 ((eq (car expr) '+)
975 (let ((so-far math-integ-var-list-list) 979 (let ((so-far math-integ-var-list-list)
976 rat-in) 980 rat-in)
977 981
978 ;; Integration by substitution, for various likely sub-expressions. 982 ;; Integration by substitution, for various likely sub-expressions.
979 ;; (In first pass, we look only for sub-exprs that are linear in X.) 983 ;; (In first pass, we look only for sub-exprs that are linear in X.)
980 (or (if math-enable-subst 984 (or (if math-linear-subst-tried
981 (math-integ-try-substitutions expr) 985 (math-integ-try-substitutions expr)
982 (math-integ-try-linear-substitutions expr)) 986 (math-integ-try-linear-substitutions expr))
983 987
984 ;; If function has sines and cosines, try tan(x/2) substitution. 988 ;; If function has sines and cosines, try tan(x/2) substitution.
985 (and (let ((p (setq rat-in (math-expr-rational-in expr)))) 989 (and (let ((p (setq rat-in (math-expr-rational-in expr))))
1187 (math-simplify-extended 1191 (math-simplify-extended
1188 (math-expr-subst temp math-integ-var u))))) 1192 (math-expr-subst temp math-integ-var u)))))
1189 1193
1190 ;;; Look for substitutions of the form u = a x + b. 1194 ;;; Look for substitutions of the form u = a x + b.
1191 (defun math-integ-try-linear-substitutions (sub-expr) 1195 (defun math-integ-try-linear-substitutions (sub-expr)
1196 (setq math-linear-subst-tried t)
1192 (and (not (Math-primp sub-expr)) 1197 (and (not (Math-primp sub-expr))
1193 (or (and (not (memq (car sub-expr) '(+ - * / neg))) 1198 (or (and (not (memq (car sub-expr) '(+ - * / neg)))
1194 (not (and (eq (car sub-expr) '^) 1199 (not (and (eq (car sub-expr) '^)
1195 (integerp (nth 2 sub-expr)))) 1200 (integerp (nth 2 sub-expr))))
1196 (math-expr-contains sub-expr math-integ-var) 1201 (math-expr-contains sub-expr math-integ-var)