1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancements. ;;;;;
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 (declare-top (special tlist
))
17 (load-macsyma-macros rzmac mhayat ratmac
)
19 (defmacro red
(p) `(cdr ,p
))
21 (defmacro p0?
(p) `(null ,p
))
23 (defmacro e0?
(expon) `(zerop (car ,expon
)))
25 (defmacro epos?
(expon) `(signp g
(car ,expon
)))
27 (defmacro eneg?
(expon) `(signp l
(car ,expon
)))
29 (defmacro num
(r) `(car ,r
))
31 (defmacro denom
(r) `(cdr ,r
))
33 (defmacro eneg
(exp) `(cons (- (car ,exp
)) (cdr ,exp
)))
35 (defmacro pade-lexp
(poly) `(cond ((p0?
,poly
) (ezero))
38 (defun eshift (poly expon
)
39 (mapcar #'(lambda (tm) (term (e+ (e tm
) expon
)
43 (defmacro psmake
(p tpf
)
44 `(make-ps (gvar-o ,tpf
) (poly-data ,tpf
) (reverse ,p
)))
46 (defmfun $pade
(taylor-form n-bound d-bound
)
47 (cond ((not (and ($ratp taylor-form
) (member 'trunc
(car taylor-form
) :test
#'eq
)))
48 (merror (intl:gettext
"pade: first argument must be a Taylor series; found: ~M") taylor-form
)))
49 (destructuring-let (((nil nil varlist genvar tlist
) (car taylor-form
)))
50 (if (psp (cdr taylor-form
))
52 (pade (cdr taylor-form
)
53 (cons (car (tay-order n-bound
))
54 (car (tay-order d-bound
)))
55 (orig-trunc (car (mrat-tlist taylor-form
)))))
56 (list '(mlist) (srdis (cdr taylor-form
))))))
58 (defun pade (tpf bounds trunc
)
59 (let ((ord (le (terms tpf
))) (poly (terms tpf
)))
60 (setq trunc
(e+ trunc
(egcd trunc
(psexpon-gcd poly
))))
62 (setq poly
(eshift poly
(eneg ord
)))
63 (setq trunc
(e- trunc ord
))
64 (cond ((epos? ord
) (rplaca bounds
65 (e- (car bounds
) ord
)))
66 (t (rplacd bounds
(e+ (cdr bounds
) ord
)))))
67 (let ((r1 (cons (list (term trunc
(rcone))) nil
))
68 (r2 (pade-monize (reverse poly
) (list (term (ezero) (rcone))))))
69 (do ((ans (cond ((or (e> (le (last poly
)) (num bounds
))
70 (eneg?
(denom bounds
))) nil
)
72 (cond ((or (e> (le (num r2
)) (num bounds
))
73 (e> (le (denom r2
)) (denom bounds
)))
75 ((epos?
(le (last (num r2
))))
76 ans
) ;not a true approximate
78 ((or (e0?
(pade-lexp (num r2
)))
79 (e>= (pade-lexp (denom r2
)) (denom bounds
)))
80 (mapcar #'(lambda (r) ($ratsimp
81 (m// (srdis (psmake (eshift (num r
) ord
) tpf
))
82 (srdis (psmake (denom r
) tpf
)))))
84 (setq r1
(pade1 r1 r2
))
88 (do ((quoterm) (lcoef (lc (num r2
))) (expon (le (num r2
)))
89 (p2 (red (num r2
))) (q2 (denom r2
)) (p1 (num r1
)) (q1 (denom r1
)))
90 ((or (p0? p1
) (e> expon
(le p1
)))
92 (setq quoterm
(term (e- (le p1
) expon
)
93 (rcminus (rcquo (lc p1
) lcoef
))))
94 (setq p1
(upoly+ (red p1
)
96 (setq q1
(upoly+ q1
(term* quoterm q2
)))))
99 (let ((p1 nil
) (coef (c term
)) (expon (e term
)) coef1
)
100 (mapc #'(lambda (term1)
101 (setq coef1
(rctimes coef
(c term1
)))
102 (if (not (rczerop coef1
))
103 (push (term (e+ expon
(e term1
))
109 (defun pade-monize (num den
) ;monicize numerator
110 (let ((mult (term (ezero) (rcinv (lc num
)))))
111 (cons (term* mult num
) (term* mult den
))))
113 (defun upoly+ (p1 p2
)
116 (cond ((p0? p1
) (return (nreconc p p2
)))
117 ((p0? p2
) (return (nreconc p p1
)))
118 ((e> (le p2
) (le p1
)) (push (pop p2
) p
))
119 ((e> (le p1
) (le p2
)) (push (pop p1
) p
))
121 (setq c
(rcplus (lc p1
) (lc p2
)))
122 (if (not (rczerop c
))
123 (push (term (le p1
) c
) p
))
124 (setq p1
(red p1
) p2
(red p2
))))))
127 (declare-top(unspecial tlist
))