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 pois3
)
15 ;; GENERAL POISSON SERIES
17 (declare-top (special *argc
*coef poisvals b
* a
* *a ss cc h
* poishift
18 poistsm poists $poisz $pois1
))
22 ;;; THESE ARE THE ONLY COEFFICIENT DEPENDENT ROUTINES.
24 ;;; POISCDECODE DECODES A COEFFICIENT
25 (defun poiscdecode (x) x
)
27 ;;; INTOPOISCO PUTS AN EXPRESSION INTO POISSON COEFFICIENT FORM
28 (defun intopoisco (x) (simplifya x nil
))
30 ;;; POISCO+ ADDS 2 COEFFICIENTS
31 (defun poisco+ (r s
) (simplifya (list '(mplus) r s
) nil
))
33 ;;; POISCO* MULTIPLIES 2 COEFFICIENTS
34 (defun poisco* (r s
) (simplifya (list '(mtimes) r s
) nil
))
36 ;;; HALVE DIVIDES A COEFFICIENT BY 2
38 (simplifya (list '(mtimes) '((rat) 1 2) r
) nil
))
40 ;;; POISSUBSTCO SUBSTITUTES AN EXPRESSION FOR A VARIABLE IN A COEFFICIENT.
41 (defun poissubstco (a b c
)
42 (maxima-substitute a b c
))
44 ;;; THIS DIFFERENTIATES A COEFFICIENT
45 (defun poiscodif (h var
)
48 ;;; THIS INTEGRATES A COEFFICIENT
49 (defun poiscointeg (h var
)
50 (intopoisco($integrate
(poiscdecode h
) var
)))
53 (defun poispzero (x) (zerop1 x
))
56 (not (and (atom x
) (integerp x
) (< (abs x
) poistsm
))))
60 (setq q
($coeff r
'$u
))
61 (cond ((fumcheck q
) (return nil
))
62 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$u q
)) nil
))))
63 (setq q
($coeff r
'$v
))
64 (cond ((fumcheck q
)(return nil
))
65 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$v q
)) nil
))))
66 (setq q
($coeff r
'$w
))
67 (cond ((fumcheck q
)(return nil
))
68 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$w q
)) nil
))))
69 (setq q
($coeff r
'$x
))
70 (cond ((fumcheck q
)(return nil
))
71 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$x q
)) nil
))))
72 (setq q
($coeff r
'$y
))
73 (cond ((fumcheck q
)(return nil
))
74 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$y q
)) nil
))))
75 (setq q
($coeff r
'$z
))
76 (cond ((fumcheck q
)(return nil
))
77 (t (setq r
(simplifya (list '(mplus) r
(list '(mtimes) -
1 '$z q
)) nil
))))
78 (cond ((equal r
0)(return t
))
81 (defmfun $poissimp
(x)
83 (cons (car x
) (mapcar #'$poissimp
(cdr x
)))
88 ;; ABOVE ASSUMES POISLIM(5) OR LESS ALSO REDEFINE ORDER< AND ORDER= TO BE < AND =
90 ;;; THIS TELLS THE EVALUATOR TO KEEP OUT OF POISSON $SERIES.
92 (defprop mpois
(lambda (x) x
) mfexpr
*)
94 (defmfun $poisplus
(a b
)
95 (setq a
(intopois a
) b
(intopois b
))
96 (list '(mpois simp
) (poismerge22 (cadr a
) (cadr b
)) (poismerge22 (caddr a
) (caddr b
))))
98 (declare-top (special *b
*fn
))
100 (defmfun $poismap
(p sinfn cosfn
)
102 (setq p
(intopois p
))
103 (setq *fn
(list sinfn
))
104 (return (list (car p
)
106 (prog2 (setq *fn
(list cosfn
)) (poismap (caddr p
)))))))
110 (t (setq *b
(meval (list *fn
(poiscdecode (cadr y
)) (poisdecodec (car y
)))))
111 (tcons3(car y
) (intopoisco *b
) (poismap (cddr y
))))))
113 (defun poismerge22 (r s
)
116 ((equal (car r
) (car s
))
118 (setq tt
(poisco+ (cadr r
) (cadr s
)))
119 (return (cond ((poispzero tt
) (poismerge22 (cddr r
) (cddr s
)))
120 (t (cons (car s
) (cons tt
(poismerge22 (cddr r
) (cddr s
)))))))))
121 ((< (car r
) (car s
)) (cons (car r
) (cons (cadr r
) (poismerge22 (cddr r
) s
))))
122 (t (cons (car s
) (cons (cadr s
) (poismerge22 (cddr s
) r
))))))
124 (defun poiscosine (m)
125 (setq m
(poisencode m
))
126 (cond ((poisnegpred m
) (setq m
(poischangesign m
))))
127 (list '(mpois simp
) nil
(list m
1)))
130 (setq m
(poisencode m
))
131 (cond ((poisnegpred m
) (list '(mpois simp
) (list (poischangesign m
) -
1) nil
))
132 (t (list '(mpois simp
) (list m
1) nil
))))
134 (defmfun $intopois
(x)
140 (cond ((equal a
0) $poisz
) (t (list '(mpois simp
) nil
(list poishift
(intopoisco a
))))))
141 ((eq (caar a
) 'mpois
) a
)
142 ((eq (caar a
) '%sin
) (poissine (cadr a
)))
143 ((eq (caar a
) '%cos
) (poiscosine (cadr a
)))
144 ((and (eq (caar a
) 'mexpt
) (numberp (caddr a
)) (> (caddr a
) 0.
))
145 ($poisexpt
(intopois (cadr a
)) (caddr a
)))
146 ((eq (caar a
) 'mplus
)
147 (setq *a
(intopois (cadr a
)))
148 (mapc (function (lambda (z) (setq *a
($poisplus
*a
(intopois z
))))) (cddr a
))
150 ((eq (caar a
) 'mtimes
)
151 (setq *a
(intopois (cadr a
)))
152 (mapc (function (lambda (z) (setq *a
($poistimes
*a
(intopois z
))))) (cddr a
))
154 ((eq (caar a
) 'mrat
) (intopois (ratdisrep a
)))
155 (t (list '(mpois simp
) nil
(list poishift
(intopoisco a
))))))
158 (if (poispzero (car s
))
162 (defun poisnegpred ($n
)
164 $loop
(cond ((equal $n
0) (return nil
))
166 (setq $r
(- (rem $n poists
) poistsm
))
167 (cond ((> $r
0) (return nil
))
168 ((> 0 $r
) (return t
))
169 (t (setq $n
(quotient $n poists
))))
172 (defun poischangesign ($n
)
173 (- (* poishift
2) $n
))
175 (declare-top (special $u $v $w $x $y $z
))
177 (defun poisencode (h*)
178 (unless (checkencode h
*)
179 ;; NOT CLEAR WHAT IS ILLEGAL HERE
180 (merror (intl:gettext
"poissimp: illegal argument: ~M") h
*))
181 (apply #'(lambda ($z $y $x $w $v $u
)
182 (declare (special $u $v $w $x $y $z
))
184 ;; NOT CLEAR WHAT IS ILLEGAL HERE EITHER
185 (unless (integerp h
*) (merror (intl:gettext
"poisson: illegal trigonometric argument.")))
190 (setq poists
(expt 2 n
)
191 poisvals
(loop for i from
5 downto
0 collect
(expt poists i
))
192 poistsm
(expt 2 (1- n
))
193 poishift
(loop for i from
0 to
5 sum
(* poistsm
(expt poists i
)))
194 $poisz
'((mpois simp
) nil nil
)
195 $pois1
(list '(mpois simp
) nil
(list poishift
1)))
198 (defun poisdecodec (m)
201 (setq arg
(list '(mtimes) (- (rem h poists
) poistsm
) '$u
))
202 (setq h
(quotient h poists
))
206 (list '(mtimes) (- (rem h poists
) poistsm
) '$v
)))
207 (setq h
(quotient h poists
))
211 (list '(mtimes) (- (rem h poists
) poistsm
) '$w
)))
212 (setq h
(quotient h poists
))
216 (list '(mtimes) (- (rem h poists
) poistsm
) '$x
)))
217 (setq h
(quotient h poists
))
221 (list '(mtimes) (- (rem h poists
) poistsm
) '$y
)))
222 (setq h
(quotient h poists
))
226 (list '(mtimes) (- (rem h poists
) poistsm
) '$z
)))
227 (return (simplifya arg nil
))))
230 ;;; THIS PROGRAM MULTIPLIES A POISSON SERIES P BY A NON-SERIES, C,
231 ;;; WHICH IS FREE OF SINES AND COSINES .
233 (defmfun $poisctimes
(c p
)
234 (list '(mpois simp
) (poisctimes1 (setq c
(intopoisco c
)) (cadr p
)) (poisctimes1 c
(caddr p
))))
236 (defmfun $outofpois
(p)
238 (cond ((or (atom p
) (not (eq (caar p
) 'mpois
))) (setq p
(intopois p
))))
245 (setq ans
(cons (list '(mtimes)
246 (poiscdecode (cadr m
))
247 (list '(%sin
) (poisdecodec (car m
))))
255 (setq ans
(cons (list '(mtimes)
256 (poiscdecode (cadr m
))
257 (cond ((equal (car m
) poishift
) 1)
258 (t (list '(%cos
) (poisdecodec (car m
))))))
260 (return (cond ((null ans
) 0.
) (t (simplifya (cons '(mplus) ans
) nil
))))))
262 (defmfun $printpois
(p)
264 (setq p
(intopois p
))
271 (displa (simplifya (list '(mtimes)
272 (poiscdecode (cadr m
))
273 (list '(%sin
) (poisdecodec (car m
))))
282 (displa (simplifya (list '(mtimes)
283 (poiscdecode (cadr m
))
284 (cond ((equal (car m
) poishift
) 1.
)
285 (t (list '(%cos
) (poisdecodec (car m
))))))
291 ;;; $POISDIFF DIFFERENTIATES A POISSON SERIES WRT X, Y, Z, U, V, W, OR A COEFF VAR.
294 (defmfun $poisdiff
(p m
)
295 (declare (special m
))
296 (cond ((member m
'($u $v $w $x $y $z
) :test
#'eq
)
297 (list (car p
) (cosdif (caddr p
) m
) (sindif (cadr p
) m
)))
298 (t (list (car p
) (poisdif4(cadr p
)) (poisdif4 (caddr p
))))))
302 (declare (special m
))
304 (t (tcons3 (car y
)(poiscodif (cadr y
) m
) (poisdif4 (cddr y
))))))
307 ;;; COSDIF DIFFERENTIATES COSINES TO GET SINES
312 (cons (poisco* (intopoisco (- (poisxcoef (car h
) m
))) (cadr h
))
313 (cosdif (cddr h
) m
))))))
318 (cons (poisco* (intopoisco (poisxcoef (car h
) m
)) (cadr h
)) (sindif (cddr h
) m
))))))
320 (defun poisxcoef (h m
)
323 (cadr (member m
'($u
0 $v
1 $w
2 $x
3 $y
4 $z
5) :test
#'eq
))))
328 ;;; AVL BALANCED TREE SEARCH AND INSERTION.
329 ;;; NODE LOOKS LIKE (KEY (LLINK . RLKINK) BALANCEFACTOR . RECORD)
330 ;;; PROGRAM FOLLOWS ALGORITHM GIVEN IN KNUTH VOL. 3 455-57
332 (declare-top (special ans
))
335 ;; MACROS TO EXTRACT FIELDS FROM NODE
337 (defmacro key
(&rest l
) (cons 'car l
))
339 (defmacro llink
(&rest l
) (cons 'caadr l
))
341 (defmacro rlink
(&rest l
) (cons 'cdadr l
))
343 (defmacro bp
(&rest l
) (cons 'caddr l
))
345 (defmacro rec
(&rest l
) (cons 'cdddr l
))
350 (defmacro order
< (&rest l
) (cons '< l
))
351 (defmacro order
= (&rest l
) (cons '= l
))
353 ;; MACROS TO SET FIELDS IN NODE
355 (defmacro setrlink
(&rest l
) (setq l
(cons nil l
))
356 (list 'rplacd
(list 'cadr
(cadr l
)) (caddr l
)))
358 (defmacro setllink
(&rest l
) (setq l
(cons nil l
))
359 (list 'rplaca
(list 'cadr
(cadr l
)) (caddr l
)))
361 (defmacro setbp
(&rest l
) (setq l
(cons nil l
))
362 (list 'rplaca
(list 'cddr
(cadr l
)) (caddr l
)))
364 (defmacro setrec
(&rest l
)(setq l
(cons nil l
))
365 (list 'rplacd
(list 'cddr
(cadr l
)) (caddr l
)))
368 (defun insert-it (pp newrec
) (setrec pp
(poisco+ (rec pp
) newrec
)))
370 (defun avlinsert (k newrec head
)
371 (prog (qq tt ss pp rr
)
373 (setq ss
(setq pp
(rlink head
)))
374 a2
(cond ((order< k
(key pp
)) (go a3
))
375 ((order< (key pp
) k
) (go a4
))
376 (t (insert-it pp newrec
) (return head
)))
377 a3
(setq qq
(llink pp
))
378 (cond ((null qq
) (setllink pp
(cons k
(cons (cons nil nil
) (cons 0. newrec
)))) (go a6
))
379 ((order= 0.
(bp qq
)) nil
)
380 (t (setq tt pp ss qq
)))
383 a4
(setq qq
(rlink pp
))
384 (cond ((null qq
) (setrlink pp
(cons k
(cons (cons nil nil
) (cons 0. newrec
)))) (go a6
))
385 ((order= 0 (bp qq
)) nil
)
386 (t (setq tt pp ss qq
)))
389 a6
(cond ((order< k
(key ss
)) (setq rr
(setq pp
(llink ss
)))) (t (setq rr
(setq pp
(rlink ss
)))))
391 (cond ((order< k
(key pp
)) (setbp pp -
1) (setq pp
(llink pp
)))
392 ((order< (key pp
) k
) (setbp pp
1) (setq pp
(rlink pp
)))
393 ((order= k
(key pp
)) (go a7
)))
395 a7
(cond ((order< k
(key ss
)) (go a7l
)) (t (go a7r
)))
396 a7l
(cond ((order= 0.
(bp ss
)) (setbp ss -
1) (setllink head
(1+ (llink head
))) (return head
))
397 ((order= (bp ss
) 1) (setbp ss
0) (return head
)))
398 (cond ((order= (bp rr
) -
1) nil
) (t (go a9l
)))
400 (setllink ss
(rlink rr
))
405 a9l
(setq pp
(rlink rr
))
406 (setrlink rr
(llink pp
))
408 (setllink ss
(rlink pp
))
410 (cond ((order= (bp pp
) -
1.
) (setbp ss
1.
) (setbp rr
0.
))
411 ((order= (bp pp
) 0.
) (setbp ss
0.
) (setbp rr
0.
))
412 ((order= (bp pp
) 1.
) (setbp ss
0.
) (setbp rr -
1.
)))
415 a7r
(cond ((order= 0.
(bp ss
)) (setbp ss
1.
) (setllink head
(1+ (llink head
))) (return head
))
416 ((order= (bp ss
) -
1.
) (setbp ss
0.
) (return head
)))
417 (cond ((order= (bp rr
) 1.
) nil
) (t (go a9r
)))
419 (setrlink ss
(llink rr
))
424 a9r
(setq pp
(llink rr
))
425 (setllink rr
(rlink pp
))
427 (setrlink ss
(llink pp
))
429 (cond ((order= (bp pp
) 1.
) (setbp ss -
1.
) (setbp rr
0.
))
430 ((order= (bp pp
) 0.
) (setbp ss
0.
) (setbp rr
0.
))
431 ((order= (bp pp
) -
1.
) (setbp ss
0.
) (setbp rr
1.
)))
433 a10
(cond ((eq ss
(rlink tt
)) (setrlink tt pp
)) (t (setllink tt pp
)))
436 (defun avlinit (key rec
)
437 (cons 'top
(cons (cons 0.
(cons key
(cons (cons nil nil
) (cons 0. rec
)))) (cons 0. nil
))))
440 ;; UNTREE CONVERTS THE TREE TO A LIST WHICH LOOKS LIKE ( SmALLEST-KEY RECORD NEXT-SMALLEST-KEY RECORD .... LARGEST-KEY
443 (defun untree (h) (prog (ans) (untree1 (rlink h
)) (return ans
)))
447 ((null (rlink h
)) (setq ans
(tcons3 (key h
) (rec h
) ans
)) (untree1 (llink h
)))
448 (t (setq ans
(tcons3 (key h
) (rec h
) (untree1 (rlink h
)))) (untree1 (llink h
)))))
450 (defun tcons3 (r s tt
) (cond ((poispzero s
) tt
) (t (cons r
(cons s tt
)))))
453 (defun poismerges (a ae l
)
454 (cond ((equal poishift ae
) l
) ; SINE(0) IS 0
455 ((poisnegpred ae
) (poismerge (poisco* -
1 a
) (poischangesign ae
) l
))
456 (t (poismerge a ae l
))))
458 (defun poismergec (a ae l
)
459 (cond ((poisnegpred ae
) (poismerge a
(poischangesign ae
) l
)) (t (poismerge a ae l
))))
461 (defun poismerge (a ae l
) (cond ((poispzero a
) nil
) (t (merge11 a ae l
))))
463 (defun poismerge2 (r s
)
467 (setq m
(setq n
(cons 0. r
)))
468 a
(cond ((null r
) (rplacd m s
) (return (cdr n
)))
469 ((null s
) (return (cdr n
)))
470 ((equal (car r
) (car s
))
471 (setq tt
(poisco+ (cadr r
) (cadr s
)))
472 (cond ((poispzero tt
) (rplacd m
(cddr r
)) (setq r
(cddr r
) s
(cddr s
)))
473 (t (rplaca (cdr r
) tt
) (setq s
(cddr s
) r
(cddr r
) m
(cddr m
)))))
479 (t (setq r
(cddr r
)) (setq m
(cddr m
))))
482 (defun merge11 (a ae l
)
483 (poismerge2 (list ae a
) l
))
485 (defun poismergesx (a ae l
)
486 (cond ((equal poishift ae
) l
) ; SINE(0) IS 0
487 ((poisnegpred ae
) (avlinsert (poischangesign ae
) (poisco* -
1 a
) l
))
488 (t (avlinsert ae a l
))))
490 (defun poismergecx (a ae l
)
491 (cond ((poisnegpred ae
) (avlinsert (poischangesign ae
) a l
)) (t (avlinsert ae a l
))))
493 (defun poisctimes1 (c h
)
495 ((and trim
(trimf (car h
))) (poisctimes1 c
(cddr h
)))
496 (t (tcons (car h
) (cons (poisco* c
(cadr h
)) (poisctimes1 c
(cddr h
)))))))
499 (meval (list '($poistrim
)
507 (defmfun $poistimes
(a b
)
508 (prog (slc clc temp ae aa zero trim t1 t2 f1 f2
)
509 (setq a
(intopois a
) b
(intopois b
))
510 (cond ((or (getl-lm-fcn-prop '$poistrim
'(expr subr
))
511 (mget '$poistrim
'mexpr
))
513 (cond ((nonperiod a
) (return ($poisctimes
(cadr (caddr a
)) b
)))
514 ((nonperiod b
) (return ($poisctimes
(cadr (caddr b
)) a
))))
515 (setq slc
(avlinit poishift
(setq zero
(intopoisco 0.
))) clc
(avlinit poishift zero
))
516 ;; PROCEED THROUGH ALL THE SINES IN ARGUMENT A
521 (setq aa
(halve (cadr sla
)) ae
(car sla
))
522 ;; SINE(U)*SINE(V) ==> (-COSINE(U+V) + COSINE(U-V))/2
527 (setq t1
(+ ae poishift
(- (car slb
))) t2
(+ ae
(- poishift
) (car slb
)))
528 (cond(trim(setq f1
(trimf t1
) f2
(trimf t2
)))
529 (t (setq f1 nil f2 nil
)))
530 (setq temp
(poisco* aa
(cadr slb
)))
531 (cond ((poispzero temp
) nil
)
532 (t (or f1
(poismergecx temp t1 clc
))
533 (or f2
(poismergecx (poisco* -
1 temp
) t2 clc
)))))
534 ;; SINE*COSINE ==> SINE + SINE
539 (setq t1
(+ ae poishift
(- (car clb
))) t2
(+ ae
(- poishift
) (car clb
)))
540 (cond(trim(setq f1
(trimf t1
) f2
(trimf t2
)))
541 (t (setq f1 nil f2 nil
)))
542 (setq temp
(poisco* aa
(cadr clb
)))
543 (cond ((poispzero temp
) nil
)
544 (t (or f1
(poismergesx temp t1 slc
)) (or f2
(poismergesx temp t2 slc
))))))
545 ;; PROCEED THROUGH ALL THE COSINES IN ARGUMENT A
550 (setq aa
(halve (cadr cla
)) ae
(car cla
))
551 ;; COSINE*SINE ==> SINE - SINE
556 (setq t1
(+ ae poishift
(- (car slb
)))
557 t2
(+ ae
(- poishift
) (car slb
)))
558 (cond (trim (setq f1
(trimf t1
) f2
(trimf t2
)))
559 (t (setq f1 nil f2 nil
)))
560 (cond (t (setq temp
(poisco* aa
(cadr slb
)))
561 (cond ((poispzero temp
) nil
)
562 (t (or f1
(poismergesx (poisco* -
1 temp
) t1 slc
))
563 (or f2
(poismergesx temp t2 slc
)))))))
564 ;; COSINE*COSINE ==> COSINE + COSINE
565 (do ((clb (caddr b
) (cddr clb
)))
567 (setq t1
(+ ae poishift
(- (car clb
)))
568 t2
(+ ae
(- poishift
) (car clb
)))
569 (cond (trim (setq f1
(trimf t1
) f2
(trimf t2
)))
570 (t (setq f1 nil f2 nil
)))
572 (t (setq temp
(poisco* aa
(cadr clb
)))
573 (cond ((poispzero temp
) nil
)
574 (t (or f1
(poismergecx temp t1 clc
))
575 (or f2
(poismergecx temp t2 clc
))))))))
576 (return (list '(mpois simp
) (untree slc
) (untree clc
)))))
578 (defmfun $poisexpt
(p n
)
580 (cond ((oddp n
) (setq u p
)) (t (setq u
(setq h
(intopois 1.
)))))
581 a
(setq n
(ash n -
1))
582 (cond ((zerop n
) (return u
)))
583 (setq p
($poistimes p p
))
584 (cond ((oddp n
) (setq u
(cond ((equal u h
) p
) (t ($poistimes u p
))))))
587 (defmfun $poissquare
(a) ($poisexpt a
2))
589 ;;; $POISINT INTEGRATES A POISSON SERIES WRT X,Y, Z, U, V, W. THE VARIABLE OF
590 ;;; INTEGRATION MUST OCCUR ONLY IN THE ARGUMENTS OF SIN OR COS,
591 ;;; OR ONLY IN THE COEFFICIENTS. POISCOINTEG IS CALLED TO INTEGRATE COEFFS.
593 ;;; NON-PERIODIC TERMS ARE REMOVED.
595 (defmfun $poisint
(p m
)
596 (declare (special m
))
598 (setq p
(intopois p
))
599 (cond ((member m
'($u $v $w $x $y $z
) :test
#'eq
)
600 (return (list (car p
)
601 (cosint* (caddr p
) m
)
602 (sinint* (cadr p
) m
))))
603 (t (return (list (car p
)
605 (poisint4 (caddr p
))))))))
608 (declare (special m
))
610 (t (tcons3 (car y
)(poiscointeg (cadr y
) m
) (poisint4 (cddr y
))))))
612 ;;;COSINT* INTEGRATES COSINES TO GET SINES
616 ((equal 0 (setq b
* (poisxcoef (car h
) m
))) (cosint* (cddr h
) m
))
618 (cons (poisco* (intopoisco (list '(mexpt) b
* -
1)) (cadr h
))
619 (cosint* (cddr h
) m
))))))
623 ((equal 0 (setq b
* (poisxcoef (car h
) m
))) (sinint* (cddr h
) m
))
625 (cons (poisco* (intopoisco (list '(mexpt) (- (poisxcoef (car h
) m
)) -
1))
627 (sinint* (cddr h
) m
))))))
630 ;;; $POISSUBST SUBSTITUTES AN EXPRESSION FOR A VARIABLE IN ARGUMENT OF TRIG FUNCTIONS OR
633 (defun poissubsta (a b
* c
)
635 (setq h
* (- (poisencode (list '(mplus) a
(list '(mtimes) -
1 b
*))) poishift
))
636 (poissubst1s (cadr c
))
637 (poissubst1c (caddr c
))
638 (return (list (car c
) ss cc
))))
640 (defun poissubst1s (c)
642 (t (setq ss
(poismerges (cadr c
) (argsubst (car c
)) ss
))
643 (poissubst1s (cddr c
)))))
645 (defun poissubst1c (c)
647 (t (setq cc
(poismergec (cadr c
) (argsubst (car c
)) cc
))
648 (poissubst1c (cddr c
)))))
651 (+ c
(* h
* (poisxcoef c b
*))))
653 (defmfun $poissubst
(aa bb cc
&optional dd nn
)
655 (fancypoissubst aa bb
(intopois cc
) (intopois dd
) nn
)
656 (let ((a* aa
) (b* bb
) (c (intopois cc
)))
657 (if (member b
* '($u $v $w $x $y $z
) :test
#'eq
)
659 (list (car c
) (poissubstco1 (cadr c
)) (poissubstco1 (caddr c
)))))))
661 (declare-top (unspecial $u $v $w $x $y $z
))
663 (defun poissubstco1 (c)
666 (tcons (car c
) (cons (poissubstco a
* b
* (cadr c
)) (poissubstco1 (cddr c
))))))
668 (declare-top (special dc ds
*ans
))
670 (defun fancypoissubst (a b
* c d n
)
671 ;;SUBSTITUTES A+D FOR B IN C, WHERE D IS EXPANDED IN POWERSERIES TO ORDER N
672 (prog (h* dc ds
*ans
)
673 (setq *ans
(list '(mpois simp
) nil nil
) d
(intopois d
) dc
(intopois 1) ds
(intopois 0))
674 (when (equal n
0) (return ($poissubst a b
* c
)))
675 (fancypois1s d
1 1 n
)
676 (setq h
* (- (poisencode (list '(mplus) a
(list '(mtimes) -
1 b
*))) poishift
))
681 (defun fancypois1s (d dp n lim
) ; DP IS LAST POWER: D^(N-1), LIM IS HIGHEST TO
682 (cond ((> n lim
) nil
) ;GO
683 (t (setq ds
($poisplus ds
684 ($poisctimes
(list '(rat)
685 (expt -
1 (ash (1- n
) -
1))
687 (setq dp
($poistimes dp d
)))))
688 (fancypois1c d dp
(1+ n
) lim
))))
690 (defun fancypois1c (d dp n lim
) ; DP IS LAST POWER: D^(N-1), LIM IS HIGHEST TO
691 (cond ((> n lim
) nil
) ;GO
694 ($poisctimes
(list '(rat) (expt -
1 (ash n -
1)) (factorial n
))
695 (setq dp
($poistimes dp d
)))))
696 (fancypois1s d dp
(1+ n
) lim
))))
698 ;;; COS(R+K*B) ==> K*COS(R+K*A)*DC - K*SIN(R+K*A)*DS
699 ;;; SIN(R+K*B) ==> K*COS(R+K*A)*DS + K*SIN(R+K*A)*DC
703 (cond ((null c
) (return nil
)))
704 (setq *coef
(poisxcoef (car c
) b
*))
705 (cond ((equal *coef
0)
706 (setq *ans
($poisplus
*ans
(list '(mpois simp
) nil
(list (car c
) (cadr c
)))))
708 (cond ((poispzero (setq *coef
(poisco* (cadr c
) (intopoisco *coef
)))) (go end
)))
709 (setq *argc
(argsubst (car c
)))
712 ($poisplus
($poistimes
(list '(mpois simp
)
714 (poismergec *coef
*argc nil
))
716 ($poistimes
(list '(mpois simp
)
717 (poismerges (poisco* -
1 *coef
) *argc nil
)
720 end
(fancypac (cddr c
))))
724 (cond ((null c
) (return nil
)))
725 (setq *coef
(poisxcoef (car c
) b
*))
726 (cond ((equal *coef
0.
)
727 (setq *ans
($poisplus
*ans
(list '(mpois simp
) (list (car c
) (cadr c
)) nil
)))
729 (cond ((poispzero (setq *coef
(poisco* (cadr c
) (intopoisco *coef
)))) (go end
)))
730 (setq *argc
(argsubst (car c
)))
731 (setq *ans
($poisplus
*ans
732 ($poisplus
($poistimes
(list '(mpois simp
)
734 (poismergec *coef
*argc nil
))
736 ($poistimes
(list '(mpois simp
)
737 (poismerges *coef
*argc nil
)
740 end
(fancypas (cddr c
))))