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 1982 Massachusetts Institute of Technology ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (macsyma-module ratout
)
15 ;; THIS IS THE OUT-OF-CORE SEGMENT OF THE RATIONAL FUNCTION PACKAGE.
17 (declare-top (special $algebraic varlist ss
*y
* f $factorflag modulus
18 genvar
*alpha
*x
* *p
*max
*var
*res
*chk
*l
19 $ratfac u
* $ratwtlvl
*ratweights $ratweights
))
21 (declare-top (special xv bigf1 bigf2
24 ;; NEWGCD (X,Y) RETURNS A LIST OF THREE ITEMS,
25 ;; (GCD, X/GCD, Y/GCD)
27 (defun newgcd (x y modulus
)
29 (let ((a (cond ((pcoefp x
)
31 ((pcoefp y
) (cgcd x y
))
32 (t (pcontent1 (cdr y
) x
))))
33 ((pcoefp y
) (cond ((zerop y
) x
) (t (pcontent1 (cdr x
) y
))))
34 ((pointergp (p-var x
) (p-var y
)) (oldcontent1 (cdr x
) y
))
35 ((pointergp (p-var y
) (p-var x
)) (oldcontent1 (cdr y
) x
))
37 (cond (a (list a
(pquotient x a
) (pquotient y a
)))
38 (modulus (pgcdp x y modulus
))
41 ;;;*** PMODCONTENT COMPUTES CONTENT OF
43 ;; Z [X ] [X , X , ..., X ]
46 ;; PMODCONTENT OF 3*A*X IS A, IF MAINVAR IS X (=X )
49 (defun pmodcontent (p)
50 (prog (*var
*chk
*res
*max gcd
)
53 (setq *var
(pnext (cdr p
) nil
))
54 (cond ((pointergp xv
*chk
) (go ret1
))
55 ((null *var
) (return (list p
1))))
59 a2
(cond ((pcoefp *res
) (cond ((pzerop *res
) nil
)(t(go ret1
))))
60 ((not (eq (car *res
) *chk
)) (go ret1
))
61 ((not (univar (cdr *res
)))
62 (setq *res
(car (pmodcontent *res
)))
64 (gcd (setq gcd
(pgcdu gcd
*res
)))
66 (cond ((pcoefp gcd
) (go ret1
))
67 ((minusp (setq *max
(1- *max
)))
68 (return (list gcd
(pquotient p gcd
)))))
70 ret1
(return (list 1 p
))))
72 (defun pgathercoef (p *chk
*res
)
73 (if (not (eq (car p
) *chk
)) 1 (pgath2 (cdr p
) nil
)))
77 (cond ((null p
) (return *max
))
78 ((pcoefp (cadr p
)) nil
)
79 ((eq (caadr p
) *var
) (setq *max
(max *max
(cadadr p
)))))
80 (return (pgath1 (cddr p
)))))
82 (defun pgath2 (p vmax
)
84 (cond ((null p
) (return *res
))
85 ((pcoefp (cadr p
)) nil
)
86 ((vgreat (setq v2
(pdegreer (cadr p
))) vmax
)
87 (setq *res
(psimp *chk
88 (list (car p
) (leadcoefficient (cadr p
)))))
94 (list (car p
) (leadcoefficient (cadr p
))))))))
95 (return (pgath2 (cddr p
) vmax
))))
99 (cond ((null p
) (return *res
))
101 (cond ((equal *max
0) (setq zz
(cadr p
)) (go add
)) (t (go ret
))))
102 ((eq (caadr p
) *var
) (setq zz
(ptterm (cdadr p
) *max
)) (go add
)))
103 (cond ((equal *max
0) (setq zz
(cadr p
))) (t (go ret
)))
104 add
(cond ((equal zz
0) (go ret
)))
105 (setq *res
(pplus *res
(psimp *chk
(list (car p
) zz
))))
106 ret
(return (pgath3 (cddr p
)))))
110 (cond ((null *l
) nil
)
111 (t (car (sort *l
#'pointergp
)))))
115 (cond ((null x
) (return *l
))
116 ((or (pcoefp (cadr x
)) (member (caadr x
) *l
:test
#'eq
)) nil
)
117 (t (setq *l
(cons (caadr x
) *l
))))
118 (return (pnext1 (cddr x
)))))
123 ((pointergp (car x
)(car y
))t
)
124 ((not (eq (car x
)(car y
)))nil
)
125 ((> (cadr x
)(cadr y
)) t
)
126 ((equal (cadr x
)(cadr y
))(vgreat (cddr x
)(cddr y
)))
130 (if (pcoefp x
) () (cons (car x
) (cons (cadr x
) (pdegreer (caddr x
))))))
132 ;;*** PGCDP CORRESPONDS TO BROWN'S ALGORITHM P
134 (defun pgcdp (bigf1 bigf2 modulus
)
136 h1tilde h2tilde gstar h1star
138 gbar nubar nu1bar nu2bar
139 gtilde f1tilde f2tilde biggtilde
141 (set-modulus modulus
)
142 (cond ((and (univar (cdr bigf1
)) (univar (cdr bigf2
)))
143 (setq q
(pgcdu bigf1 bigf2
))
144 (return (list q
(pquotient bigf1 q
) (pquotient bigf2 q
)))))
145 (setq xv
(car bigf1
))
146 (setq bigf1
(pmodcontent bigf1
))
147 (setq bigf2
(pmodcontent bigf2
))
148 (setq c
(pgcdu (setq c1
(car bigf1
)) (setq c2
(car bigf2
))))
149 (setq bigf1
(cadr bigf1
))
150 (setq bigf2
(cadr bigf2
))
152 (setq e
(pdegreer bigf2
))
153 (setq degree
(pdegreer bigf1
))
154 (cond ((vgreat e degree
) (setq e degree
)))
155 (setq b
(ash modulus -
1))
157 (pgcdu (setq f1
(pgathercoef bigf1 xv
0))
159 (pgathercoef bigf2 xv
0))))
160 (cond ((equal 0 f1f2
) (go step15a
)))
161 (setq nubar
(pdegree gbar xv
))
162 (setq nu1bar
(+ nubar
(pdegree bigf1 xv
)))
163 (setq nu2bar
(+ nubar
(pdegree bigf2 xv
)))
164 (setq f1f2
(ptimes f1 f1f2
))
165 (setq nubar
(max nu1bar nu2bar
))
166 step6
(setq b
(cplus b
1))
167 (cond ((equal (pcsubst f1f2 b xv
) 0) (go step6
)))
169 (setq gtilde
(pcsubst gbar b xv
))
170 (setq f1tilde
(pcsubst bigf1 b xv
))
171 (setq f2tilde
(pcsubst bigf2 b xv
))
174 (car (setq h2tilde
(newgcd f1tilde f2tilde modulus
)))))
175 (cond ((pcoefp biggtilde
) (go step15a
)))
176 (setq h1tilde
(cadr h2tilde
))
177 (setq h2tilde
(caddr h2tilde
))
178 (setq degree
(pdegreer biggtilde
))
179 (cond ((vgreat degree e
) (go step6
))
180 ((vgreat e degree
) (setq n
0) (setq e degree
)))
182 (cond ((equal n
1) (setq q
(list xv
1 1 0 (cminus b
)))
183 (setq gstar biggtilde
)
184 (setq h1star h1tilde
)
185 (setq h2star h2tilde
))
186 (t (setq gstar
(lagrange33 gstar biggtilde q b
))
187 (setq h1star
(lagrange33 h1star h1tilde q b
))
188 (setq h2star
(lagrange33 h2star h2tilde q b
))
189 (setq q
(ptimes q
(list xv
1 1 0 (cminus b
))))))
191 (cond ((not (> n nubar
)) (go step6
)))
193 (cond ((or (not (= nu1bar
(+ (setq degree
(pdegree gstar xv
))
194 (pdegree h1star xv
))))
195 (not (= nu2bar
(+ degree
(pdegree h2star xv
)))))
198 (setq gstar
(cadr (pmodcontent gstar
)))
200 (setq q
(pgathercoef gstar xv
0))
201 (return (monicgcd (ptimeschk c gstar
)
202 (ptimeschk (pquotient c1 c
) (pquotientchk h1star q
))
203 (ptimeschk (pquotient c2 c
) (pquotientchk h2star q
))
204 (leadcoefficient gstar
)))
207 (ptimeschk (pquotient c1 c
) bigf1
)
208 (ptimeschk (pquotient c2 c
) bigf2
))) ))
211 (defun monicgcd (gcd x y lcf
)
212 (cond ((equal lcf
1) (list gcd x y
))
213 (t (list (ptimes (crecip lcf
) gcd
)
217 ;;*** PGCDM CORRESPONDS TO BROWN'S ALGORITHM M
222 (prog (c c1 c2 f1 f2 n
224 gtilde h1tilde h2tilde
226 biggtilde q h1star h2star
229 (setq xv
(car bigf1
))
231 (setq f1
(pcontent bigf1
))
232 (setq f2
(pcontent bigf2
))
233 (setq c
(cgcd (setq c1
(car f1
)) (setq c2
(car f2
))))
234 (setq bigf1
(cadr f1
))
235 (setq bigf2
(cadr f2
))
237 (setq f1
(leadcoefficient bigf1
))
238 (setq f2
(leadcoefficient bigf2
))
239 (setq gbar
(cgcd f1 f2
))
242 (setq degree
(pdegreer bigf1
))
243 (setq e
(pdegreer bigf2
))
244 (cond ((vgreat e degree
) (setq e degree
)))
247 (* 2 gbar
(max (maxcoefficient bigf1
)
248 (maxcoefficient bigf2
))))
250 step6
(setq p
(newprime p
))
252 (cond ((or (zerop (rem f1 p
)) (zerop (rem f2 p
)))
256 (setq gtilde
(pmod gbar
))
261 (newgcd (pmod bigf1
) (pmod bigf2
)
263 (cond ((pcoefp biggtilde
) (setq modulus nil
)
268 (cond ((null (cdr h2tilde
))
269 (setq h1tilde
(pquotient (pmod bigf1
) (car h2tilde
)))
270 (setq h2tilde
(pquotient (pmod bigf2
) (car h2tilde
))))
271 (t (setq h1tilde
(cadr h2tilde
))
272 (setq h2tilde
(caddr h2tilde
))))
273 (setq degree
(pdegreer biggtilde
))
274 (cond ((vgreat degree e
) (go step6
))
275 ((vgreat e degree
) (setq n
0) (setq e degree
)))
279 (cond ((equal n
1) (setq q p
)
280 (setq gstar biggtilde
)
281 (setq h1star h1tilde
)
282 (setq h2star h2tilde
))
283 (t (setq gstar
(lagrange3 gstar biggtilde p q
))
284 (setq h1star
(lagrange3 h1star h1tilde p q
))
285 (setq h2star
(lagrange3 h2star h2tilde p q
))
288 (cond ((> mubar q
) (go step6
)))
289 (cond ((> (* 2 (max (* (setq gtilde
(norm gstar
)) (maxcoefficient h1star
))
290 (* gtilde
(maxcoefficient h2star
))))
294 (setq gstar
(cadr (pcontent gstar
)))
296 (setq q
(leadcoefficient gstar
))
297 (return (list (ptimeschk c gstar
)
298 (ptimeschk (cquotient c1 c
) (pquotientchk h1star q
))
299 (ptimeschk (cquotient c2 c
) (pquotientchk h2star q
))))))
301 ;; THE FUNCTIONS ON THIS PAGE ARE USED BY KRONECKER FACTORING
304 (prog (maxexp i l
*p factors factor
)
305 (setq maxexp
(quotient (cadr p
) 2))
307 a
(when (> i maxexp
) (return (cons p factors
)))
308 (setq l
(p1 (reverse (let ((p p
) (i i
) ($factorflag t
))
310 b
(when (null l
) (go d
))
314 (setq factor
(errset (pinterpolate *l
*p
))))
318 (setq factor
(car factor
)))
319 (when (or (pcoefp factor
)
320 (not (equal (car p
) (car factor
)))
321 (not (pzerop (prem p factor
))))
323 (cond (modulus (pmonicize (cdr factor
)))
324 ((pminusp factor
) (setq factor
(pminus factor
))))
325 (setq p
(pquotient p factor
))
326 (setq maxexp
(quotient (cadr p
) 2))
327 (setq factors
(cons factor factors
))
332 (defun pfactor2 (p i
)
334 (t (cons (pfactor (pcsubst p i
(car p
)))
335 (pfactor2 p
(1- i
))))))
337 (defun rpowerset (x n
)
338 (cond ((null x
) (quote (1 nil
)))
339 ((equal x
1) (quote (1)))
340 (t (cons 1 (ptts1 x n x
)))))
343 (defun allprods (x y
)
346 (t (nconc (ap1 (car x
) y
) (allprods (cdr x
) y
)))))
352 (return (mapcar #'(lambda (*y
*) (cons *y
* nil
)) f
)))
353 ((null r
) (return nil
))
355 (mapc #'(lambda (*y
*)
358 (mapcar #'(lambda (z) (cons z
*y
*))
360 (al1 (car r
) (cdr r
) (1- len
)))
366 (t (cons (ptimes x
(car l
)) (ap1 x
(cdr l
))))))
369 (cond ((equal n
1) (list y
))
370 (t (cons y
(ptts1 x
(1- n
) (ptimes x y
))))))
374 (setq a
(mapcar #'p11 l
))
375 (return (cond ((null l
) nil
)
381 (cond ((null (cddr ele
)) (rpowerset (car ele
) (cadr ele
)))
382 (t (allprods (rpowerset (car ele
) (cadr ele
))
385 (defun pinterpolate (l var
)
386 (psimp var
(pinterpolate1 (pinterpolate2 l
1)
389 (defun pinterpolate1 (x n
)
390 (pinterpolate4 (pinterpolate5 (reverse x
) 1 n n
) (1+ n
)))
392 (defun pinterpolate2 (x n
)
393 (cond ((null (cdr x
)) x
)
395 (pinterpolate2 (pinterpolate3 x n
) (1+ n
))))))
397 (defun pinterpolate3 (x n
)
398 (cond ((null (cdr x
)) nil
)
399 (t (cons (pquotient (pdifference (cadr x
) (car x
)) n
)
400 (pinterpolate3 (cdr x
) n
)))))
402 (defun pinterpolate4 (x n
)
404 ((pzerop (car x
)) (pinterpolate4 (cdr x
) (1- n
)))
405 (t (cons n
(cons (car x
)
406 (pinterpolate4 (cdr x
) (1- n
)))))))
408 (defun pinterpolate5 (x i j n
)
410 (t (pinterpolate5 (cons (car x
) (pinterpolate6 x i j
))
415 (defun pinterpolate6 (x i j
)
416 (cond ((zerop i
) (cdr x
))
417 (t (cons (pdifference (cadr x
) (pctimes j
(car x
)))
418 (pinterpolate6 (cdr x
) (1- i
) j
)))))
420 ;; THE N**(1.585) MULTIPLICATION SCHEME
421 ;;FOLLOWS. IT SHOULD BE USED ONLY WHEN BOTH INPUTS ARE MULTIVARIATE,
422 ;;DENSE, AND OF NEARLY THE SAME SIZE. OR ABSOLUTELY TREMENDOUS.
423 ;;(THE CLASSICAL MULTIPLICATION SCHEME IS N**2 WHERE N IS SIZE OF
424 ;;POLYNOMIAL (OR N*M FOR DIFFERENT SIZES). FOR THIS
425 ;;CASE, N IS APPX. THE SIZE OF LARGER.
427 (defmfun $fasttimes
(x y
)
428 (cond ((and (not (atom x
)) (not (atom y
))
429 (equal (car x
) (car y
)) (equal (caar x
) 'mrat
)
430 (equal (cddr x
) 1) (equal (cddr y
) 1))
431 (cons (car x
)(cons (fptimes (cadr x
)(cadr y
))1)))
432 (t (merror (intl:gettext
"fasttimes: arguments must be CRE polynomials with same variables.")))))
435 (cond ((or (pzerop x
) (pzerop y
)) (pzero))
436 ((pcoefp x
) (pctimes x y
))
437 ((pcoefp y
) (pctimes y x
))
438 ((eq (car x
) (car y
))
439 (cond((or(univar(cdr x
))(univar(cdr y
)))
440 (cons (car x
) (ptimes1 (cdr x
) (cdr y
))))
441 (t(cons (car x
) (fptimes1 (cdr x
)(cdr y
))))))
442 ((pointergp (car x
) (car y
))
443 (cons (car x
) (pctimes1 y
(cdr x
))))
444 (t (cons (car y
) (pctimes1 x
(cdr y
))))))
446 (defun fptimes1 (f g
)
448 (cond ((or (null f
) (null g
)) (return nil
))
450 (return (lsft (pctimes1 (cadr f
) g
) (car f
))))
452 (return (lsft (pctimes1 (cadr g
) f
) (car g
)))))
453 (setq d
(ash (1+ (max (car f
) (car g
))) -
1))
454 (setq f
(halfsplit f d
) g
(halfsplit g d
))
455 (setq a
(fptimes1 (car f
) (car g
)))
457 (fptimes1 (ptptplus (car f
) (cdr f
)) (ptptplus (car g
) (cdr g
))))
458 (setq c
(fptimes1 (cdr f
) (cdr g
)))
459 (setq b
(ptptdiffer (ptptdiffer b a
) c
))
460 (return (ptptplus (lsft a
(ash d
1)) (ptptplus (lsft b d
) c
)))))
462 (defun halfsplit (p d
)
463 (do ((a) (p p
(cddr p
)))
464 ((or (null p
) (< (car p
) d
)) (cons (nreverse a
) p
))
465 (setq a
(cons (cadr p
) (cons (- (car p
) d
) a
)))))
468 (do ((q p
(cddr (rplaca q
(+ (car q
) n
)))))
472 (declare-top (special wtsofar xweight $ratwtlvl v
*x
*))
474 ;;; TO TRUNCATE ON E, DO RATWEIGHT(E,1);
475 ;;;THEN DO RATWTLVL:N. ALL POWERS >N GO TO 0.
477 (defmfun $ratweight
(&rest args
)
478 (when (oddp (length args
))
479 (merror (intl:gettext
"ratweight: number of arguments must be a multiple of 2.")))
480 (do ((l args
(cddr l
)))
482 (rplacd (or (assoc (first l
) *ratweights
:test
#'equal
)
483 (car (push (list (first l
)) *ratweights
)))
485 (setq $ratweights
(cons '(mlist simp
) (dot2l *ratweights
)))
488 (cons '(mlist) args
)))
491 (or (get x
'$ratweight
) 0))
493 (defun wtptimes (x y wtsofar
)
494 (cond ((or (pzerop x
) (pzerop y
) (> wtsofar $ratwtlvl
))
496 ((pcoefp x
) (wtpctimes x y
))
497 ((pcoefp y
) (wtpctimes y x
))
498 ((eq (car x
) (car y
))
504 ((pointergp (car x
) (car y
))
506 (wtpctimes1 y
(cdr x
) (pweight (car x
)))))
508 (wtpctimes1 x
(cdr y
) (pweight (car y
)))))))
510 (defun wtptimes1 (*x
* y xweight
)
512 (declare (special v
))
513 (setq v
(setq u
* (wtptimes2 y
)))
514 a
(setq *x
* (cddr *x
*))
515 (cond ((null *x
*) (return u
*)))
523 (let ((ii (+ (* xweight
(+ (car *x
*) (car y
))) wtsofar
)))
526 (pcoefadd (+ (car *x
*) (car y
))
527 (wtptimes (cadr *x
*) (cadr y
) ii
)
528 (wtptimes2 (cddr y
)))))))
532 (declare (special v
))
533 a1
(cond ((null y
) (return nil
)))
534 (setq e
(+ (car *x
*) (car y
)))
535 (setq c
(wtptimes (cadr y
) (cadr *x
*) (+ wtsofar
(* xweight e
))))
536 (cond ((pzerop c
) (setq y
(cddr y
)) (go a1
))
537 ((or (null v
) (> e
(car v
))) (setq u
* (setq v
(ptptplus u
* (list e c
)))) (setq y
(cddr y
)) (go a1
))
539 (setq c
(pplus c
(cadr v
)))
540 (cond ((pzerop c
) (setq u
* (setq v
(ptptdiffer u
* (list (car v
) (cadr v
)))))) (t (rplaca (cdr v
) c
)))
543 a
(cond ((and (cddr v
) (> (caddr v
) e
)) (setq v
(cddr v
)) (go a
)))
545 b
(cond ((or (null (cdr u
)) (< (cadr u
) e
)) (rplacd u
(cons e
(cons c
(cdr u
)))) (go e
)))
546 (cond ((pzerop (setq c
(pplus (caddr u
) c
))) (rplacd u
(cdddr u
)) (go d
)) (t (rplaca (cddr u
) c
)))
549 (cond ((null y
) (return nil
))
551 (setq c
(wtptimes (cadr *x
*) (cadr y
)
552 (+ wtsofar
(* xweight
553 (setq e
(+ (car *x
*) (car y
))))))))
555 c
(cond ((and (cdr u
) (> (cadr u
) e
)) (setq u
(cddr u
)) (go c
)))
559 (defun wtpctimes (c p
)
560 (cond ((pcoefp p
) (ctimes c p
))
561 (t (psimp (car p
) (wtpctimes1 c
(cdr p
) (pweight (car p
)))))))
563 (defun wtpctimes1 (c x xwt
)
567 (t (setq cc
(wtptimes c
569 (+ wtsofar
(* xwt
(car x
)))))
570 (cond ((pzerop cc
) (wtpctimes1 c
(cddr x
) xwt
))
581 (let ((xn2 (wtpexpt x
(/ n
2))))
582 (wtptimes xn2 xn2
0)))
583 (t (wtptimes x
(wtpexpt x
(1- n
)) 0))))
585 (defmfun $horner
(e &rest l
)
587 (varlist (cdr $ratvars
))
590 (arg1 (taychk2rat e
)))
593 (mapcar #'(lambda (u) (apply '$horner
(cons u l
))) (cdr arg1
))))
595 (setq x
(apply #'$rat
(cons arg1 l
)))
596 (mapc #'(lambda (y z
) (putprop y z
'disrep
)) (cadddr (car x
)) (caddar x
))
597 (div* (hornrep (cadr x
)) (hornrep (cddr x
)))))))
602 (horn+ (cdr p
) (get (car p
) 'disrep
))))
606 (setq ans
(hornrep (cadr l
)))
607 a
(setq last
(car l
) l
(cddr l
))
609 (return (cond ((equal last
0) ans
)
611 (list '(mexpt) var last
) ans
)))))
612 (t (setq ans
(list '(mplus)
615 (list '(mexpt) var
(- last
(car l
)))
619 (declare-top (special y genvar $savefactors checkfactors
620 exp var x $factorflag $ratfac
622 wholepart parnumer varlist n
))
624 (defmfun $partfrac
(exp var
)
626 (cons (car exp
) (mapcar #'(lambda (u) ($partfrac u var
)) (cdr exp
))))
627 ((and (atom var
) (not (among var exp
))) exp
)
628 (t (let (($savefactors t
) (checkfactors ()) (varlist (list var
))
629 $ratfac $algebraic $keepfloat ratform genvar
)
630 (desetq (ratform . exp
) (taychk2rat exp
))
631 (setq var
(caadr (ratf var
)))
632 (setq exp
(partfrac exp var
))
633 (setq exp
(cons (car exp
) ;FULL DECOMP?
634 (mapcan #'partfraca
(cdr exp
))))
635 (add2* (disrep (car exp
))
637 (mapcar #'(lambda (l)
638 (destructuring-let (((coef poly exp
) l
))
646 (defun partfraca (llist)
647 (destructuring-let (((coef poly exp
) llist
))
648 (do ((nc (ratdivide coef poly
) (ratdivide (car nc
) poly
))
651 ((rzerop (car nc
)) (cons (list (cdr nc
) poly n
) ans
))
652 (push (list (cdr nc
) poly n
) ans
))))
654 (defun partfrac (rat var
)
655 (destructuring-let* (((wholepart frpart
) (pdivide (car rat
) (cdr rat
)))
656 ((num . denom
) (ratqu frpart
(cdr rat
))))
658 ((pzerop num
) (cons wholepart nil
))
659 ((or (pcoefp denom
) (pointergp var
(car denom
))) (cons rat nil
))
660 (t (destructuring-let (((content bpart
) (oldcontent denom
)))
661 (let (apart y parnumer
)
663 for
(factor multiplicity
)
664 on
(pfactor bpart
) by
#'cddr
665 unless
(zerop (pdegree factor var
))
667 (setq apart
(pexpt factor multiplicity
)
668 bpart
(pquotient bpart apart
)
669 y
(bprog apart bpart
)
670 frpart
(cdr (ratdivide (ratti num
(cdr y
) t
)
672 (push (list (ratqu frpart content
) factor multiplicity
)
674 (desetq (num . content
)
675 (cdr (ratdivide (ratqu (ratti num
(car y
) t
)
678 (cons wholepart parnumer
)))))))
680 (declare-top (unspecial exp f n ss v var xv y
*chk
*l
*max
*p
683 ;; $RATDIFF TAKES DERIVATIVES FAST. IT ASSUMES THAT THE
684 ;; ONLY ENTITY WHICH DEPENDS ON X IS X ITSELF.
685 ;; THAT IS, DEPENDENCIES DECLARED EXPLICITLY OR IMPLICITLY ARE
686 ;; TOTALLY IGNORED. RATDIFF(F(X),X) IS 0. RATDIFF(Y,X) IS 0.
687 ;; ANY OTHER USAGE MUST GO THROUGH $DIFF.
688 ;; FURTHERMORE, X IS ASSUMED TO BE AN ATOM OR A SINGLE ITEM ON
689 ;; VARLIST. E.G. X MIGHT BE SIN(U), BUT NOT 2*SIN(U).
691 (declare-top (special varlist genvar x
))
693 (defmfun $ratdiff
(p x
)
695 (setq p
(minimize-varlist
696 (if (member 'trunc
(cdar p
) :test
#'eq
) ($taytorat p
) p
))))
697 (let ((formflag ($ratp p
)) (varlist) (genvar))
698 (newvar x
) (newvar p
)
699 (or (every #'(lambda (exp)
700 (or (alike1 x exp
) (free exp x
)))
702 (merror (intl:gettext
"ratdiff: first argument must be a polynomial in ~M; found: ~M") x p
))
704 (setq x
(caadr (ratf x
)))
705 (setq p
(cons (car p
) (ratderivative (cdr p
) x
)))
706 (if formflag p
($ratdisrep p
))))
708 (declare-top (unspecial x
))
710 (declare-top (special $pfeformat varlist $factorflag m v dosimp
))
713 (prog (listov $pfeformat varlist $factorflag
)
716 (setq listov varlist
)
717 (mapc #'(lambda (r) (setq m
(pfet1 m r
)))
719 (setq m
(simplify m
))
720 (setq m
(cond ((atom m
) m
)
721 ((eq (caar m
) 'mplus
)
723 (mapcar #'$ratexpand
(cdr m
))))
725 (return (cond ((atom m
) m
)
726 ((eq (caar m
) 'mplus
)
728 (mapcar #'sssqfr
(cdr m
))))
732 (let ((dosimp t
)) (simplify ($sqfr x
))))
736 ((eq (caar m
) 'mplus
)
738 (mapcar #'(lambda (s) ($partfrac s v
))
740 (t ($partfrac m v
))))
742 (declare-top (unspecial m v
))