Add xref for ctranspose.
[maxima.git] / src / tlimit.lisp
blobd628942a934cce42090699b73cac574012d27d03
1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
4 ;;; ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; (c) Copyright 1980 Massachusetts Institute of Technology ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 (in-package :maxima)
13 (declare-top (special taylored))
15 (macsyma-module tlimit)
17 (load-macsyma-macros rzmac)
19 ;; TOP LEVEL FUNCTION(S): $TLIMIT $TLDEFINT
21 (defmfun $tlimit (&rest args)
22 (let ((limit-using-taylor t))
23 (declare (special limit-using-taylor))
24 (apply #'$limit args)))
26 (defmfun $tldefint (exp var ll ul)
27 (let ((limit-using-taylor t))
28 (declare (special limit-using-taylor))
29 ($ldefint exp var ll ul)))
31 ;; Taylor cannot handle conjugate, ceiling, floor, unit_step, or signum
32 ;; expressions, so let's tell tlimit to *not* try. We also disallow
33 ;; expressions containing $ind.
34 (defun tlimp (e x)
35 (or (and ($mapatom e) (not (eq e '$ind)) (not (eq e '$und)))
36 (and (consp e)
37 (consp (car e))
38 (or
39 (known-ps (caar e))
40 (and (eq (caar e) 'mqapply) (known-ps (subfunname e)))
41 (member (caar e) (list 'mplus 'mtimes 'mexpt '%log))
42 (get (caar e) 'grad)
43 ($freeof x e))
44 (every #'(lambda (q) (tlimp q x)) (cdr e)))))
46 ;; Dispatch Taylor, but recurse on the order until either the recursion
47 ;; depth is 15 or the Taylor polynomial is nonzero. When Taylor
48 ;; fails to find a nonzero Taylor polynomial or the recursion depth is
49 ;; too great, return nil.
51 ;; This recursion on the order attempts to handle limits such as
52 ;; tlimit(2^n/n^5, n, inf) correctly.
54 ;; We set up a reasonable environment for calling taylor. When $taylor_logexpand
55 ;; is true, taylor does some principal branch violating transformations, so we set
56 ;; it to nil.
58 ;; I know of no compelling reason for defaulting the taylor order to
59 ;; lhospitallim, but this is documented in the user documentation).
61 (defun tlimit-taylor (e x pt n &optional (d 0))
62 (let ((ee 0)
63 (silent-taylor-flag t)
64 ($taylordepth 8)
65 ($radexpand nil)
66 ($logexpand nil)
67 ($taylor_logexpand nil)
68 ($taylor_simplifier #'(lambda (q) (sratsimp (extra-simp q)))))
69 (setq e (partial-logarc e (list '%atan)))
70 (setq ee (catch 'taylor-catch (let (($logexpand t)) (ratdisrep ($taylor e x pt n)))))
71 (cond ((and ee (not (alike1 ee 0))) ee)
72 ;; When taylor returns zero and the depth d is less than 16,
73 ;; declare a do-over; otherwise return nil.
74 ((and ee (< d 16))
75 (tlimit-taylor e x pt (* 4 (max 1 n)) (+ d 1)))
76 (t nil))))
78 ;; Previously when the taylor series failed, there was code for deciding
79 ;; whether to call limit1 or simplimit. The choice depended on the last
80 ;; argument to taylim (previously named *i*) and the main operator of the
81 ;; expression. This code dispenses with this logic and dispatches limit1
82 ;; when Maxima is unable to find the taylor polynomial. This change orphans
83 ;; the last argument of taylim.
84 (defun taylim (e var val flag)
85 (declare (ignore flag))
86 (let ((et nil))
87 (when (tlimp e var)
88 (setq e (stirling0 e))
89 (setq et (tlimit-taylor e var (ridofab val) $lhospitallim 0)))
90 (if et (let ((taylored t)) (limit et var val 'think)) (limit1 e var val))))