1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;; The data in this file contains enhancments. ;;;;;
5 ;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
6 ;;; All rights reserved ;;;;;
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;;; (c) Copyright 1981 Massachusetts Institute of Technology ;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (macsyma-module laplac
)
15 (declare-top (special var $savefactors
16 checkfactors $ratfac $keepfloat
*nounl
* *nounsflag
*
19 ;;; The properties NOUN and VERB give correct linear display
21 (defprop $laplace %laplace verb
)
22 (defprop %laplace $laplace noun
)
24 (defprop $ilt %ilt verb
)
25 (defprop %ilt $ilt noun
)
27 (defun exponentiate (pow)
28 ;;;COMPUTES %E**Z WHERE Z IS AN ARBITRARY EXPRESSION TAKING SOME OF THE WORK AWAY FROM SIMPEXPT
29 (cond ((zerop1 pow
) 1)
31 (t (power '$%e pow
))))
33 (defun fixuprest (rest)
34 ;;;REST IS A PRODUCT WITHOUT THE MTIMES.FIXUPREST PUTS BACK THE MTIMES
36 ((cdr rest
) (cons '(mtimes) rest
))
39 (defun isquadraticp (e x
)
40 (let ((b (sdiff e x
)))
41 (cond ((zerop1 b
) (list 0 0 e
))
42 ((freeof x b
) (list 0 b
(maxima-substitute 0 x e
)))
43 ((setq b
(islinear b x
))
44 (list (div* (car b
) 2) (cdr b
) (maxima-substitute 0 x e
))))))
46 ;;;INITIALIZES SOME GLOBAL VARIABLES THEN CALLS THE DISPATCHING FUNCTION
48 (defmfun $laplace
(fun var parm
)
49 (setq fun
(mratcheck fun
))
50 (cond ((or *nounsflag
* (member '%laplace
*nounl
* :test
#'eq
))
51 (setq fun
(remlaplace fun
))))
54 ;;;LAMBDA BINDS SOME SPECIAL VARIABLES TO NIL AND DISPATCHES
59 (cons (delete 'laplace
(append (car e
) nil
) :count
1 :test
#'eq
)
60 (mapcar #'remlaplace
(cdr e
)))))
62 (defun laplace (fun parm
&optional
(dvar nil
))
64 ;;; Handles easy cases and calls appropriate function on others.
65 (cond ((mbagp fun
) (cons (car fun
) (mapcar #'(lambda (e) (laplace e parm
)) (cdr fun
))))
68 (cond ((zerop1 parm
) (simplify (list '($delta
) 0)))
70 ((alike1 fun var
) (power parm -
2))
71 ((or (atom fun
) (freeof var fun
))
72 (cond ((zerop1 parm
) (mul2 fun
(simplify (list '($delta
) 0))))
73 (t (mul2 fun
(power parm -
1)))))
75 (let ((op (caar fun
)))
76 (let ((result ; We store the result of laplace for further work.
80 (laptimes (cdr fun
) parm
))
82 (lapexpt fun nil parm
))
84 (lapsin fun nil nil parm
))
86 (lapsin fun nil t parm
))
88 (lapsinh fun nil nil parm
))
90 (lapsinh fun nil t parm
))
96 (lapint fun parm dvar
))
99 (laplace (cadr fun
) parm
)
105 ((and (eq op
'%ilt
)(eq (cadddr fun
) var
))
106 (cond ((eq parm
(caddr fun
))(cadr fun
))
107 (t (subst parm
(caddr fun
)(cadr fun
)))))
109 (lapdelta fun nil parm
))
110 ((member op
'(%hstep $unit_step
))
111 (laphstep fun nil parm
))
112 ((setq op
($get op
'$laplace
))
113 (mcall op fun var parm
))
114 (t (lapdefint fun parm
)))))
115 (when (isinop result
'%integrate
)
116 ;; Laplace has not found a result but returns a definit
117 ;; integral. This integral can contain internal integration
118 ;; variables. Replace such a result with the noun form.
119 (setq result
(list '(%laplace
) fun var parm
)))
120 ;; Check if we have a result, when not call $specint.
121 (check-call-to-$specint result fun parm
)))))))
123 ;;; Check if laplace has found a result, when not try $specint.
125 (defun check-call-to-$specint
(result fun parm
)
127 ((or (isinop result
'%laplace
)
128 (isinop result
'%limit
) ; Try $specint for incomplete results
129 (isinop result
'%at
)) ; which contain %limit or %at too.
130 ;; laplace returns a noun form or a result which contains %limit or %at.
131 ;; We pass the function to $specint to look for more results.
133 ;; laplace assumes the parameter s to be positive and does a
134 ;; declaration before an integration is done. Therefore we declare
135 ;; the parameter of the Laplace transform to be positive before
136 ;; we call $specint too.
137 (with-new-context (context)
138 (meval `(($assume
) ,@(list (list '(mgreaterp) parm
0))))
139 (setq res
($specint
(mul fun
(power '$%e
(mul -
1 var parm
))) var
)))
140 (if (or (isinop res
'%specint
) ; Both symobls are possible, that is
141 (isinop res
'$specint
)) ; not consistent! Check it! 02/2009
142 ;; $specint has not found a result.
144 ;; $specint has found a result
148 (defun laplus (fun parm
)
149 (simplus (cons '(mplus) (mapcar #'(lambda (e) (laplace e parm
)) (cdr fun
))) 1 t
))
151 (defun laptimes (fun parm
)
152 ;;;EXPECTS A LIST (PERHAPS EMPTY) OF FUNCTIONS MULTIPLIED TOGETHER WITHOUT THE MTIMES
153 ;;;SEES IF IT CAN APPLY THE FIRST AS A TRANSFORMATION ON THE REST OF THE FUNCTIONS
154 (cond ((null fun
) (list '(mexpt) parm -
1.
))
155 ((null (cdr fun
)) (laplace (car fun
) parm
))
156 ((freeof var
(car fun
))
157 (simptimes (list '(mtimes)
159 (laptimes (cdr fun
) parm
))
163 (simptimes (list '(mtimes) -
1 (sdiff (laptimes (cdr fun
) parm
) parm
))
167 (let ((op (caaar fun
)))
168 (cond ((eq op
'mexpt
)
169 (lapexpt (car fun
) (cdr fun
) parm
))
171 (laplus ($multthru
(fixuprest (cdr fun
)) (car fun
)) parm
))
173 (lapsin (car fun
) (cdr fun
) nil parm
))
175 (lapsin (car fun
) (cdr fun
) t parm
))
177 (lapsinh (car fun
) (cdr fun
) nil parm
))
179 (lapsinh (car fun
) (cdr fun
) t parm
))
181 (lapdelta (car fun
) (cdr fun
) parm
))
182 ((member op
'(%hstep $unit_step
))
183 (laphstep (car fun
) (cdr fun
) parm
))
185 (lapshift (car fun
) (cdr fun
) parm
)))))))
187 (defun lapexpt (fun rest parm
)
188 ;;;HANDLES %E**(A*T+B)*REST(T), %E**(A*T**2+B*T+C),
189 ;;; 1/SQRT(A*T+B), OR T**K*REST(T)
190 (prog (ab base-of-fun power result
)
191 (setq base-of-fun
(cadr fun
) power
(caddr fun
))
194 (freeof var base-of-fun
)
198 (cond ((eq base-of-fun
'$%e
) power
)
199 (t (simptimes (list '(mtimes)
206 (cond ((equal (car ab
) 0) (go %e-case-lin
))
207 ((null rest
) (go %e-case-quad
))
209 ((and (eq base-of-fun var
) (freeof var power
))
211 ((and (alike1 '((rat) -
1 2) power
) (null rest
)
212 (setq ab
(islinear base-of-fun var
)))
213 (setq result
(div* (cdr ab
) (car ab
)))
222 (exponentiate (list '(mtimes) result parm
))
238 (rest (sratsimp ($at
(laptimes rest parm
)
248 (afixsign (cadr ab
) nil
))
250 (return (simptimes (list '(mtimes)
251 (exponentiate (caddr ab
))
256 (setq result
(afixsign (car ab
) nil
))
265 (exponentiate (div* (list '(mexpt) parm
2)
266 (list '(mtimes) 4 result
)))
279 (and (null (equal (cadr ab
) 0))
281 (maxima-substitute (list '(mplus)
288 (return (simptimes (list '(mtimes)
289 (exponentiate (caddr ab
))
292 (cond ((or (null rest
) (freeof var
(fixuprest rest
)))
294 (cond ((posint power
)
295 (return (afixsign (apply '$diff
296 (list (laptimes rest parm
)
301 (return (mydefint (hackit power rest parm
)
302 (createname parm
(- power
))
307 (simplus (list '(mplus) 1 power
) 1 t
))
308 (or (eq (asksign ($realpart power
)) '$positive
) (go noluck
))
309 (setq result
(list (list '(%gamma
) power
)
312 (afixsign power nil
))))
313 (and rest
(setq result
(nconc result rest
)))
314 (return (simptimes (cons '(mtimes) result
) 1 nil
))
319 (member (caar base-of-fun
)
320 '(mplus %sin %cos %sinh %cosh
) :test
#'eq
))
321 (laptimes (cons base-of-fun
322 (cons (cond ((= power
2) base-of-fun
)
327 (t (lapshift fun rest parm
))))))
329 ;;;INTEGRAL FROM A TO INFINITY OF F(X)
330 (defun mydefint (f x a parm
)
331 (let ((tryint (and (not ($unknown f
))
332 ;; We don't want any errors thrown by $defint to propagate,
333 ;; so we set errset, errcatch, $errormsg and *mdebug*. If
334 ;; $defint throws a error, then no error message is printed
335 ;; and errset simply returns nil below.
336 (with-new-context (context)
337 (meval `(($assume
) ,@(list (list '(mgreaterp) parm
0))))
338 (meval `(($assume
) ,@(list (list '(mgreaterp) x
0))))
339 (meval `(($assume
) ,@(list (list '(mgreaterp) a
0))))
344 (errset ($defint f x a
'$inf
)))))))
347 (list '(%integrate
) f x a
'$inf
))))
349 ;;;CREATES UNIQUE NAMES FOR VARIABLE OF INTEGRATION
350 (defun createname (head tail
)
351 (intern (format nil
"~S~S" head tail
)))
353 ;;;REDUCES LAPLACE(F(T)/T**N,T,S) CASE TO LAPLACE(F(T)/T**(N-1),T,S) CASE
354 (defun hackit (exponent rest parm
)
355 (cond ((equal exponent -
1)
356 (let ((parm (createname parm
1)))
357 (laptimes rest parm
)))
358 (t (mydefint (hackit (1+ exponent
) rest parm
)
359 (createname parm
(- -
1 exponent
))
360 (createname parm
(- exponent
)) parm
))))
362 (defun afixsign (funct signswitch
)
363 ;;;MULTIPLIES FUNCT BY -1 IF SIGNSWITCH IS NIL
364 (cond (signswitch funct
)
365 (t (simptimes (list '(mtimes) -
1 funct
) 1 t
))))
367 (defun lapshift (fun rest parm
)
368 (cond ((atom fun
) (merror "LAPSHIFT: expected a cons, not ~M" fun
))
369 ((or (member 'laplace
(car fun
) :test
#'eq
) (null rest
))
370 (lapdefint (cond (rest (simptimes (cons '(mtimes)
371 (cons fun rest
)) 1 t
))
373 (t (laptimes (append rest
374 (ncons (cons (append (car fun
)
376 (cdr fun
)))) parm
))))
378 ;;;COMPUTES %E**(W*B*%I)*F(S-W*A*%I) WHERE W=-1 IF SIGN IS T ELSE W=1
379 (defun mostpart (f parm sign a b
)
380 (let ((substinfun ($at f
383 (list '(mplus) parm
(afixsign (list '(mtimes) a
'$%i
) sign
))))))
387 (exponentiate (afixsign (list '(mtimes) b
'$%i
) (null sign
)))
390 ;;;IF WHICHSIGN IS NIL THEN SIN TRANSFORM ELSE COS TRANSFORM
391 (defun compose (fun parm whichsign a b
)
392 (let ((result (list '((rat) 1 2)
394 (mostpart fun parm t a b
)
395 (afixsign (mostpart fun parm nil a b
)
397 (sratsimp (simptimes (cons '(mtimes)
403 ;;;FUN IS OF THE FORM SIN(A*T+B)*REST(T) OR COS
404 (defun lapsin (fun rest trigswitch parm
)
405 (let ((ab (islinear (cadr fun
) var
)))
408 (compose (laptimes rest parm
)
416 (cond ((zerop1 (cdr ab
))
417 (if trigswitch parm
(car ab
)))
423 (list '(%cos
) (cdr ab
)))
427 (list '(%sin
) (cdr ab
)))))
432 (list '(%sin
) (cdr ab
)))
435 (list '(%cos
) (cdr ab
))))))))
438 (list '(mexpt) parm
2)
439 (list '(mexpt) (car ab
) 2))
443 (lapshift fun rest parm
)))))
445 ;;;FUN IS OF THE FORM SINH(A*T+B)*REST(T) OR IS COSH
446 (defun lapsinh (fun rest switch parm
)
447 (cond ((islinear (cadr fun
) var
)
452 (nconc (list '(mtimes)
458 (afixsign (nconc (list '(mtimes)
468 (t (lapshift fun rest parm
))))
470 ;;;FUN IS OF THE FORM LOG(A*T)
471 (defun laplog (fun parm
)
472 (let ((ab (islinear (cadr fun
) var
)))
473 (cond ((and ab
(zerop1 (cdr ab
)))
474 (simptimes (list '(mtimes)
476 (subfunmake '$psi
'(0) (ncons 1))
477 (list '(%log
) (car ab
))
478 (list '(mtimes) -
1 (list '(%log
) parm
)))
479 (list '(mexpt) parm -
1))
482 (lapdefint fun parm
)))))
484 (defun raiseup (fbase exponent
)
485 (if (equal exponent
1)
487 (list '(mexpt) fbase exponent
)))
489 ;;TAKES TRANSFORM OF HSTEP(A*T+B)*F(T)
490 (defun laphstep (fun rest parm
)
491 (let ((ab (islinear (cadr fun
) var
)))
497 ($positive
(if (eq (asksign offset
) '$negative
)
498 (mul (exponentiate (mul offset parm
))
499 (laplace (maxima-substitute
501 (fixuprest rest
)) parm
))
502 (laptimes rest parm
)))
503 ($negative
(if (eq (asksign offset
) '$negative
)
504 (sub (laptimes rest parm
)
505 (mul (exponentiate (mul offset parm
))
506 (laplace (maxima-substitute
508 (fixuprest rest
)) parm
)))
510 (t (mul fun
(laptimes rest parm
)))))
511 (lapshift fun rest parm
))))
513 ;;TAKES TRANSFORM OF DELTA(A*T+B)*F(T)
514 (defun lapdelta (fun rest parm
)
515 (let ((ab (islinear (cadr fun
) var
))
519 (setq recipa
(power (car ab
) -
1) ab
(div (cdr ab
) (car ab
)))
520 (setq sign
(asksign ab
) recipa
(simplifya (list '(mabs) recipa
) nil
))
521 (simplifya (cond ((eq sign
'$positive
)
525 (maxima-substitute 0 var
(fixuprest rest
))
529 (maxima-substitute (neg ab
) var
(fixuprest rest
))
530 (list '(mexpt) '$%e
(cons '(mtimes) (cons parm
(ncons ab
))))
534 (lapshift fun rest parm
)))))
536 (defun laperf (fun parm
)
537 (let ((ab (islinear (cadr fun
) var
)))
538 (cond ((and ab
(equal (cdr ab
) 0))
539 (simptimes (list '(mtimes)
540 (div* (exponentiate (div* (list '(mexpt) parm
2)
543 (list '(mexpt) (car ab
) 2))))
549 (list '(%erf
) (div* parm
(list '(mtimes) 2 (car ab
)))))))
553 (lapdefint fun parm
)))))
555 (defun lapdefint (fun parm
)
557 (and ($unknown fun
)(go skip
))
558 (setq mult
(simptimes (list '(mtimes) (exponentiate
559 (list '(mtimes) -
1 var parm
)) fun
) 1 nil
))
560 (with-new-context (context)
561 (meval `(($assume
) ,@(list (list '(mgreaterp) parm
0))))
563 ;; We don't want any errors thrown by $defint to propagate,
564 ;; so we set errset, errcatch, $errormsg and *mdebug*. If
565 ;; $defint throws a error, then no error message is printed
566 ;; and errset simply returns nil below.
571 (errset ($defint mult var
0 '$inf
)))))
572 (and tryint
(not (eq (and (listp (car tryint
))
575 (return (car tryint
)))
576 skip
(return (list '(%laplace
) fun var parm
))))
579 (defun lapdiff (fun parm
)
580 ;;;FUN IS OF THE FORM DIFF(F(T),T,N) WHERE N IS A POSITIVE INTEGER
581 (prog (difflist degree frontend resultlist newdlist order arg2
)
582 (setq newdlist
(setq difflist
(copy-tree (cddr fun
))))
583 (setq arg2
(list '(mequal) var
0))
584 a
(cond ((null difflist
)
585 (return (cons '(%derivative
)
586 (cons (list '(%laplace
)
591 ((eq (car difflist
) var
)
592 (setq degree
(cadr difflist
)
593 difflist
(cddr difflist
))
595 (setq difflist
(cdr (setq frontend
(cdr difflist
))))
597 out
(cond ((null (posint degree
))
598 (return (list '(%laplace
) fun var parm
))))
599 (cond (frontend (rplacd frontend difflist
))
600 (t (setq newdlist difflist
)))
601 (cond (newdlist (setq fun
(cons '(%derivative
)
604 (t (setq fun
(cadr fun
))))
608 (cons (list '(mtimes)
609 (raiseup parm degree
)
610 ($at
($diff fun var order
) arg2
))
613 (and (> degree
0) (go loop
))
614 (setq resultlist
(cond ((cdr resultlist
)
617 (t (car resultlist
))))
618 (return (simplus (list '(mplus)
627 ;;;FUN IS OF THE FORM INTEGRATE(F(X)*G(T)*H(T-X),X,0,T)
628 (defun lapint (fun parm dvar
)
629 (prog (newfun parm-list f var-list var-parm-list
)
630 (and dvar
(go convolution
))
631 (setq dvar
(cadr (setq newfun
(cdr fun
))))
633 (zerop1 (caddr newfun
))
634 (eq (cadddr newfun
) var
)
635 (go convolutiontest
))
637 (setq newfun
(cdr fun
))
639 (cond ((and (freeof var
(caddr newfun
))
640 (freeof var
(cadddr newfun
)))
641 (return (list '(%integrate
)
642 (laplace (car newfun
) parm dvar
)
647 (t (return (list '(%integrate
)
648 (laplace (car newfun
) parm dvar
)
651 (return (list '(%laplace
) fun var parm
))
653 (setq newfun
($factor
(car newfun
)))
654 (cond ((eq (caar newfun
) 'mtimes
)
655 (setq f
(cadr newfun
) newfun
(cddr newfun
)))
656 (t (setq f newfun newfun nil
)))
658 (cond ((freeof dvar f
)
659 (setq parm-list
(cons f parm-list
)))
660 ((freeof var f
) (setq var-list
(cons f var-list
)))
662 (sratsimp (maxima-substitute (list '(mplus)
667 (setq var-parm-list
(cons f var-parm-list
)))
669 (cond (newfun (setq f
(car newfun
) newfun
(cdr newfun
))
678 (ncons (list '(%integrate
)
690 (laplace ($expand
(maxima-substitute var
692 (fixuprest var-list
))) parm dvar
)
694 ($expand
(maxima-substitute 0 dvar
(fixuprest var-parm-list
))) parm dvar
))
698 (declare-top (special varlist ratform ils ilt
))
700 (defmfun $ilt
(exp ils ilt
)
701 ;;;EXP IS F(S)/G(S) WHERE F AND G ARE POLYNOMIALS IN S AND DEGR(F) < DEGR(G)
702 (let (varlist ($savefactors t
) checkfactors $ratfac $keepfloat
)
703 ;;; MAKES ILS THE MAIN VARIABLE
704 (setq varlist
(list ils
))
706 (orderpointer varlist
)
707 (setq var
(caadr (ratrep* ils
)))
708 (cond ((and (null (atom exp
))
709 (eq (caar exp
) 'mequal
))
711 ($ilt
(cadr exp
) ils ilt
)
712 ($ilt
(caddr exp
) ils ilt
)))
715 (list '(mtimes) exp
(list '($delta
) ilt
)))
718 (defun maxima-rationalp (le v
)
720 ((and (null (atom (car le
))) (null (freeof v
(car le
))))
722 (t (maxima-rationalp (cdr le
) v
))))
724 ;;;THIS FUNCTION DOES THE PARTIAL FRACTION DECOMPOSITION
726 (prog (wholepart frpart num denom y content real factor
727 apart bpart parnumer ratarg ratform
)
729 (return (simplus (cons '(mplus)
730 (mapcar #'(lambda (f) ($ilt f ils ilt
)) (cdr exp
))) 1 t
)))
731 (and (null (atom exp
))
732 (eq (caar exp
) '%laplace
)
733 (eq (cadddr exp
) ils
)
734 (return (cond ((eq (caddr exp
) ilt
) (cadr exp
))
738 (setq ratarg
(ratrep* exp
))
739 (or (maxima-rationalp varlist ils
)
740 (return (list '(%ilt
) exp ils ilt
)))
741 (setq ratform
(car ratarg
))
742 (setq denom
(ratdenominator (cdr ratarg
)))
743 (setq frpart
(pdivide (ratnumerator (cdr ratarg
)) denom
))
744 (setq wholepart
(car frpart
))
745 (setq frpart
(ratqu (cadr frpart
) denom
))
746 (cond ((not (zerop1 (car wholepart
)))
747 (return (list '(%ilt
) exp ils ilt
)))
748 ((zerop1 (car frpart
)) (return 0)))
749 (setq num
(car frpart
) denom
(cdr frpart
))
750 (setq y
(oldcontent denom
))
751 (setq content
(car y
))
753 (setq factor
(pfactor real
))
754 loop
(cond ((null (cddr factor
))
759 (setq apart
(pexpt (car factor
) (cadr factor
)))
760 (setq bpart
(car (ratqu real apart
)))
761 (setq y
(bprog apart bpart
))
763 (cdr (ratdivide (ratti (ratnumerator num
)
766 (ratti (ratdenominator num
)
767 (ratti content apart t
)
771 (cons (ilt1 (ratqu (ratnumerator frpart
)
772 (ratti (ratdenominator frpart
)
773 (ratti (ratdenominator num
)
780 (setq factor
(cddr factor
))
782 (return (simplus (cons '(mplus) parnumer
) 1 t
))))
783 (setq num
(cdr (ratdivide (ratti num
(car y
) t
)
784 (ratti content bpart t
))))
788 (declare-top (special q z
))
792 (cond ((onep1 k
) (ilt3 p
))
793 (t (setq z
(bprog q
(pderivative q var
)))
797 ;;;INVERTS P(S)/Q(S)**K WHERE Q(S) IS IRREDUCIBLE
798 ;;;DOESN'T CALL ILT3 IF Q(S) IS LINEAR
801 (and (onep1 k
) (return (ilt3 p
)))
803 (setq a
(ratti p
(car z
) t
))
804 (setq b
(ratti p
(cdr z
) t
))
807 ((or (null (equal (pdegree q var
) 1))
808 (> (pdegree (car p
) var
) 0))
814 (cdr (ratdivide (ratplus a
(ratqu (ratderivative b var
) k
)) y
))
816 ($multthru
(simptimes (list '(mtimes)
819 (ilt2 (cdr (ratdivide b y
)) k
))
824 (setq a
(disrep (polcoef q
1))
825 b
(disrep (polcoef q
0)))
827 (simptimes (list '(mtimes)
830 (simpexpt (list '(mexpt)
836 (list '(mexpt) a -
1)))
848 ;;(DEFUN COEF MACRO (POL) (SUBST (CADR POL) (QUOTE DEG)
849 ;; '(DISREP (RATQU (POLCOEF (CAR P) DEG) (CDR P)))))
852 `(disrep (ratqu (polcoef (car p
) ,pol
) (cdr p
))))
854 (defun lapsum (&rest args
)
855 (cons '(mplus) args
))
857 (defun lapprod (&rest args
)
858 (cons '(mtimes) args
))
860 (defun expo (&rest args
)
861 (cons '(mexpt) args
))
863 ;;;INVERTS P(S)/Q(S) WHERE Q(S) IS IRREDUCIBLE
865 (prog (discrim sign a c d e b1 b0 r term1 term2 degr
)
866 (setq e
(disrep (polcoef q
0))
867 d
(disrep (polcoef q
1))
868 degr
(pdegree q var
))
874 (expo '$%e
(lapprod -
1 ilt e
(expo d -
1))))
877 (setq c
(disrep (polcoef q
2)))
878 (and (equal degr
2) (go quadratic
))
879 (and (equal degr
3) (zerop1 c
) (zerop1 d
)
881 (return (list '(%ilt
) (div* (disrep p
)(disrep q
)) ils ilt
))
882 cubic
(setq a
(disrep (polcoef q
3))
883 r
(simpnrt (div* e a
) 3))
884 (setq d
(div* (disrep p
)(lapprod a
(lapsum
885 (expo ils
3)(expo '%r
3)))))
886 (return (ilt0 (maxima-substitute r
'%r
($partfrac d ils
))))
887 quadratic
(setq b0
(coef 0) b1
(coef 1))
895 (setq sign
(cond ((free discrim
'$%i
) (asksign discrim
)) (t '$positive
))
898 (setq degr
(expo '$%e
(lapprod ilt d
(power c -
1) '((rat) -
1 2))))
899 (cond ((eq sign
'$zero
)
900 (return (simptimes (lapprod degr
(lapsum (div* b1 c
)
902 (div* (lapsum (lapprod 2 b0 c
) (lapprod -
1 b1 d
))
903 (lapprod 2 c c
)) ilt
))) 1 nil
))
904 ) ((eq sign
'$negative
)
907 discrim
(simptimes (lapprod -
1 discrim
) 1 t
))))
908 (setq discrim
(simpnrt discrim
2))
918 (setq c
(power c -
1))
919 (setq discrim
(simptimes (lapprod
930 (lapprod b1
(list term1 discrim
))
931 (lapprod sign
(list term2 discrim
))))
935 (declare-top (unspecial ils ilt
*nounl
* q ratform var