/usr/share/maxima/5.32.1/src/pois3.lisp is in maxima-src 5.32.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The data in this file contains enhancments. ;;;;;
;;; ;;;;;
;;; Copyright (c) 1984,1987 by William Schelter,University of Texas ;;;;;
;;; All rights reserved ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (c) Copyright 1981 Massachusetts Institute of Technology ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :maxima)
(macsyma-module pois3)
;; GENERAL POISSON SERIES
(declare-top (special *argc *coef poisvals b* a* *a ss cc h* poishift
poistsm poists $poisz $pois1))
(defvar trim nil)
;;; THESE ARE THE ONLY COEFFICIENT DEPENDENT ROUTINES.
;;; POISCDECODE DECODES A COEFFICIENT
(defun poiscdecode (x) x)
;;; INTOPOISCO PUTS AN EXPRESSION INTO POISSON COEFFICIENT FORM
(defun intopoisco (x) (simplifya x nil))
;;; POISCO+ ADDS 2 COEFFICIENTS
(defun poisco+ (r s) (simplifya (list '(mplus) r s) nil))
;;; POISCO* MULTIPLIES 2 COEFFICIENTS
(defun poisco* (r s) (simplifya (list '(mtimes) r s) nil))
;;; HALVE DIVIDES A COEFFICIENT BY 2
(defun halve (r)
(simplifya (list '(mtimes) '((rat) 1 2) r) nil))
;;; POISSUBSTCO SUBSTITUTES AN EXPRESSION FOR A VARIABLE IN A COEFFICIENT.
(defun poissubstco (a b c)
(maxima-substitute a b c))
;;; THIS DIFFERENTIATES A COEFFICIENT
(defun poiscodif (h var)
($diff h var))
;;; THIS INTEGRATES A COEFFICIENT
(defun poiscointeg (h var)
(intopoisco($integrate (poiscdecode h) var)))
;;; TEST FOR ZERO
(defun poispzero (x) (zerop1 x))
(defun fumcheck (x)
(not (and (atom x) (integerp x) (< (abs x) poistsm))))
(defun checkencode(r)
(prog(q)
(setq q ($coeff r '$u))
(cond ((fumcheck q) (return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$u q)) nil))))
(setq q ($coeff r '$v))
(cond ((fumcheck q)(return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$v q)) nil))))
(setq q ($coeff r '$w))
(cond ((fumcheck q)(return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$w q)) nil))))
(setq q ($coeff r '$x))
(cond ((fumcheck q)(return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$x q)) nil))))
(setq q ($coeff r '$y))
(cond ((fumcheck q)(return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$y q)) nil))))
(setq q ($coeff r '$z))
(cond ((fumcheck q)(return nil))
(t (setq r (simplifya (list '(mplus) r (list '(mtimes) -1 '$z q)) nil))))
(cond ((equal r 0)(return t))
(t (return nil)))))
(defmfun $poissimp (x)
(if (mbagp x)
(cons (car x) (mapcar #'$poissimp (cdr x)))
($outofpois x)))
;;;********
;; ABOVE ASSUMES POISLIM(5) OR LESS ALSO REDEFINE ORDER< AND ORDER= TO BE < AND =
;;; THIS TELLS THE EVALUATOR TO KEEP OUT OF POISSON $SERIES.
(defprop mpois (lambda (x) x) mfexpr*)
(defmfun $poisplus (a b)
(setq a (intopois a) b (intopois b))
(list '(mpois simp) (poismerge22 (cadr a) (cadr b)) (poismerge22 (caddr a) (caddr b))))
(declare-top (special *b *fn))
(defmfun $poismap (p sinfn cosfn)
(prog (*b *fn)
(setq p (intopois p))
(setq *fn (list sinfn))
(return (list (car p)
(poismap (cadr p))
(prog2 (setq *fn (list cosfn)) (poismap (caddr p)))))))
(defun poismap (y)
(cond ((null y) nil)
(t (setq *b (meval (list *fn (poiscdecode (cadr y)) (poisdecodec (car y)))))
(tcons3(car y) (intopoisco *b) (poismap (cddr y))))))
(defun poismerge22 (r s)
(cond ((null r) s)
((null s) r)
((equal (car r) (car s))
(prog (tt)
(setq tt (poisco+ (cadr r) (cadr s)))
(return (cond ((poispzero tt) (poismerge22 (cddr r) (cddr s)))
(t (cons (car s) (cons tt (poismerge22 (cddr r) (cddr s)))))))))
((< (car r) (car s)) (cons (car r) (cons (cadr r) (poismerge22 (cddr r) s))))
(t (cons (car s) (cons (cadr s) (poismerge22 (cddr s) r))))))
(defun poiscosine (m)
(setq m (poisencode m))
(cond ((poisnegpred m) (setq m (poischangesign m))))
(list '(mpois simp) nil (list m 1)))
(defun poissine (m)
(setq m (poisencode m))
(cond ((poisnegpred m) (list '(mpois simp) (list (poischangesign m) -1) nil))
(t (list '(mpois simp) (list m 1) nil))))
(defmfun $intopois (x)
(let (*a)
(intopois x)))
(defun intopois (a)
(cond ((atom a)
(cond ((equal a 0) $poisz) (t (list '(mpois simp) nil (list poishift (intopoisco a))))))
((eq (caar a) 'mpois) a)
((eq (caar a) '%sin) (poissine (cadr a)))
((eq (caar a) '%cos) (poiscosine (cadr a)))
((and (eq (caar a) 'mexpt) (numberp (caddr a)) (> (caddr a) 0.))
($poisexpt (intopois (cadr a)) (caddr a)))
((eq (caar a) 'mplus)
(setq *a (intopois (cadr a)))
(mapc (function (lambda (z) (setq *a ($poisplus *a (intopois z))))) (cddr a))
*a)
((eq (caar a) 'mtimes)
(setq *a (intopois (cadr a)))
(mapc (function (lambda (z) (setq *a ($poistimes *a (intopois z))))) (cddr a))
*a)
((eq (caar a) 'mrat) (intopois (ratdisrep a)))
(t (list '(mpois simp) nil (list poishift (intopoisco a))))))
(defun tcons (r s)
(if (poispzero (car s))
(cdr s)
(cons r s)))
(defun poisnegpred ($n)
(prog ($r)
$loop (cond ((equal $n 0) (return nil))
(t nil))
(setq $r (- (rem $n poists) poistsm))
(cond ((> $r 0) (return nil))
((> 0 $r) (return t))
(t (setq $n (quotient $n poists))))
(go $loop)))
(defun poischangesign ($n)
(- (* poishift 2) $n))
(declare-top (special $u $v $w $x $y $z))
(defun poisencode (h*)
(unless (checkencode h*)
;; NOT CLEAR WHAT IS ILLEGAL HERE
(merror (intl:gettext "poissimp: illegal argument: ~M") h*))
(apply #'(lambda ($z $y $x $w $v $u)
(declare (special $u $v $w $x $y $z))
(setq h* (meval h*))
;; NOT CLEAR WHAT IS ILLEGAL HERE EITHER
(unless (integerp h*) (merror (intl:gettext "poisson: illegal trigonometric argument.")))
(+ poishift h*))
poisvals))
(let ((n 5))
(setq poists (expt 2 n)
poisvals (loop for i from 5 downto 0 collect (expt poists i))
poistsm (expt 2 (1- n))
poishift (loop for i from 0 to 5 sum (* poistsm (expt poists i)))
$poisz '((mpois simp) nil nil)
$pois1 (list '(mpois simp) nil (list poishift 1)))
n)
(defun poisdecodec (m)
(prog (arg h)
(setq h m)
(setq arg (list '(mtimes) (- (rem h poists) poistsm) '$u))
(setq h (quotient h poists))
(setq arg
(list '(mplus)
arg
(list '(mtimes) (- (rem h poists) poistsm) '$v)))
(setq h (quotient h poists))
(setq arg
(list '(mplus)
arg
(list '(mtimes) (- (rem h poists) poistsm) '$w)))
(setq h (quotient h poists))
(setq arg
(list '(mplus)
arg
(list '(mtimes) (- (rem h poists) poistsm) '$x)))
(setq h (quotient h poists))
(setq arg
(list '(mplus)
arg
(list '(mtimes) (- (rem h poists) poistsm) '$y)))
(setq h (quotient h poists))
(setq arg
(list '(mplus)
arg
(list '(mtimes) (- (rem h poists) poistsm) '$z)))
(return (simplifya arg nil))))
;;; THIS PROGRAM MULTIPLIES A POISSON SERIES P BY A NON-SERIES, C,
;;; WHICH IS FREE OF SINES AND COSINES .
(defmfun $poisctimes (c p)
(list '(mpois simp) (poisctimes1 (setq c (intopoisco c)) (cadr p)) (poisctimes1 c (caddr p))))
(defmfun $outofpois (p)
(prog (ans)
(cond ((or (atom p) (not (eq (caar p) 'mpois))) (setq p (intopois p))))
;; DO SINES
(do ((m
(cadr p)
(cddr m)))(
(null m))
(setq ans (cons (list '(mtimes)
(poiscdecode (cadr m))
(list '(%sin) (poisdecodec (car m))))
ans)))
;; DO COSINES
(do ((m
(caddr p)
(cddr m)))(
(null m))
(setq ans (cons (list '(mtimes)
(poiscdecode (cadr m))
(cond ((equal (car m) poishift) 1)
(t (list '(%cos) (poisdecodec (car m))))))
ans)))
(return (cond ((null ans) 0.) (t (simplifya (cons '(mplus) ans) nil))))))
(defmfun $printpois (p)
(prog nil
(setq p (intopois p))
;; DO SINES
(do ((m
(cadr p)
(cddr m)))(
(null m))
(displa (simplifya (list '(mtimes)
(poiscdecode (cadr m))
(list '(%sin) (poisdecodec (car m))))
t))
(terpri))
;; DO COSINES
(do ((m
(caddr p)
(cddr m)))(
(null m))
(displa (simplifya (list '(mtimes)
(poiscdecode (cadr m))
(cond ((equal (car m) poishift) 1.)
(t (list '(%cos) (poisdecodec (car m))))))
t))
(terpri))
(return '$done)))
;;; $POISDIFF DIFFERENTIATES A POISSON SERIES WRT X, Y, Z, U, V, W, OR A COEFF VAR.
(defmfun $poisdiff (p m)
(declare (special m))
(cond ((member m '($u $v $w $x $y $z) :test #'eq)
(list (car p) (cosdif (caddr p) m) (sindif (cadr p) m)))
(t (list (car p) (poisdif4(cadr p)) (poisdif4 (caddr p))))))
(defun poisdif4 (y)
(declare (special m))
(cond ((null y) nil)
(t (tcons3 (car y)(poiscodif (cadr y) m) (poisdif4 (cddr y))))))
;;; COSDIF DIFFERENTIATES COSINES TO GET SINES
(defun cosdif (h m)
(cond ((null h) nil)
(t (tcons (car h)
(cons (poisco* (intopoisco (- (poisxcoef (car h) m))) (cadr h))
(cosdif (cddr h) m))))))
(defun sindif (h m)
(cond ((null h) nil)
(t (tcons (car h)
(cons (poisco* (intopoisco (poisxcoef (car h) m)) (cadr h)) (sindif (cddr h) m))))))
(defun poisxcoef (h m)
(- (rem (quotient h
(expt poists
(cadr (member m '($u 0 $v 1 $w 2 $x 3 $y 4 $z 5) :test #'eq))))
poists)
poistsm))
;;; AVL BALANCED TREE SEARCH AND INSERTION.
;;; NODE LOOKS LIKE (KEY (LLINK . RLKINK) BALANCEFACTOR . RECORD)
;;; PROGRAM FOLLOWS ALGORITHM GIVEN IN KNUTH VOL. 3 455-57
(declare-top (special ans))
;; MACROS TO EXTRACT FIELDS FROM NODE
(defmacro key (&rest l) (cons 'car l))
(defmacro llink (&rest l) (cons 'caadr l))
(defmacro rlink (&rest l) (cons 'cdadr l))
(defmacro bp (&rest l) (cons 'caddr l))
(defmacro rec (&rest l) (cons 'cdddr l))
;; FOR ORDERING KEYS
(defmacro order< (&rest l) (cons '< l))
(defmacro order= (&rest l) (cons '= l))
;; MACROS TO SET FIELDS IN NODE
(defmacro setrlink (&rest l) (setq l (cons nil l))
(list 'rplacd (list 'cadr (cadr l)) (caddr l)))
(defmacro setllink (&rest l) (setq l (cons nil l))
(list 'rplaca (list 'cadr (cadr l)) (caddr l)))
(defmacro setbp (&rest l) (setq l (cons nil l))
(list 'rplaca (list 'cddr (cadr l)) (caddr l)))
(defmacro setrec (&rest l)(setq l (cons nil l))
(list 'rplacd (list 'cddr (cadr l)) (caddr l)))
(defun insert-it (pp newrec) (setrec pp (poisco+ (rec pp) newrec)))
(defun avlinsert (k newrec head)
(prog (qq tt ss pp rr)
(setq tt head)
(setq ss (setq pp (rlink head)))
a2 (cond ((order< k (key pp)) (go a3))
((order< (key pp) k) (go a4))
(t (insert-it pp newrec) (return head)))
a3 (setq qq (llink pp))
(cond ((null qq) (setllink pp (cons k (cons (cons nil nil) (cons 0. newrec)))) (go a6))
((order= 0. (bp qq)) nil)
(t (setq tt pp ss qq)))
(setq pp qq)
(go a2)
a4 (setq qq (rlink pp))
(cond ((null qq) (setrlink pp (cons k (cons (cons nil nil) (cons 0. newrec)))) (go a6))
((order= 0 (bp qq)) nil)
(t (setq tt pp ss qq)))
(setq pp qq)
(go a2)
a6 (cond ((order< k (key ss)) (setq rr (setq pp (llink ss)))) (t (setq rr (setq pp (rlink ss)))))
a6loop
(cond ((order< k (key pp)) (setbp pp -1) (setq pp (llink pp)))
((order< (key pp) k) (setbp pp 1) (setq pp (rlink pp)))
((order= k (key pp)) (go a7)))
(go a6loop)
a7 (cond ((order< k (key ss)) (go a7l)) (t (go a7r)))
a7l (cond ((order= 0. (bp ss)) (setbp ss -1) (setllink head (1+ (llink head))) (return head))
((order= (bp ss) 1) (setbp ss 0) (return head)))
(cond ((order= (bp rr) -1) nil) (t (go a9l)))
(setq pp rr)
(setllink ss (rlink rr))
(setrlink rr ss)
(setbp ss 0)
(setbp rr 0)
(go a10)
a9l (setq pp (rlink rr))
(setrlink rr (llink pp))
(setllink pp rr)
(setllink ss (rlink pp))
(setrlink pp ss)
(cond ((order= (bp pp) -1.) (setbp ss 1.) (setbp rr 0.))
((order= (bp pp) 0.) (setbp ss 0.) (setbp rr 0.))
((order= (bp pp) 1.) (setbp ss 0.) (setbp rr -1.)))
(setbp pp 0.)
(go a10)
a7r (cond ((order= 0. (bp ss)) (setbp ss 1.) (setllink head (1+ (llink head))) (return head))
((order= (bp ss) -1.) (setbp ss 0.) (return head)))
(cond ((order= (bp rr) 1.) nil) (t (go a9r)))
(setq pp rr)
(setrlink ss (llink rr))
(setllink rr ss)
(setbp ss 0.)
(setbp rr 0.)
(go a10)
a9r (setq pp (llink rr))
(setllink rr (rlink pp))
(setrlink pp rr)
(setrlink ss (llink pp))
(setllink pp ss)
(cond ((order= (bp pp) 1.) (setbp ss -1.) (setbp rr 0.))
((order= (bp pp) 0.) (setbp ss 0.) (setbp rr 0.))
((order= (bp pp) -1.) (setbp ss 0.) (setbp rr 1.)))
(setbp pp 0.)
a10 (cond ((eq ss (rlink tt)) (setrlink tt pp)) (t (setllink tt pp)))
(return head)))
(defun avlinit (key rec)
(cons 'top (cons (cons 0. (cons key (cons (cons nil nil) (cons 0. rec)))) (cons 0. nil))))
;; UNTREE CONVERTS THE TREE TO A LIST WHICH LOOKS LIKE ( SmALLEST-KEY RECORD NEXT-SMALLEST-KEY RECORD .... LARGEST-KEY
;;RECORD)
(defun untree (h) (prog (ans) (untree1 (rlink h)) (return ans)))
(defun untree1 (h)
(cond ((null h) ans)
((null (rlink h)) (setq ans (tcons3 (key h) (rec h) ans)) (untree1 (llink h)))
(t (setq ans (tcons3 (key h) (rec h) (untree1 (rlink h)))) (untree1 (llink h)))))
(defun tcons3 (r s tt) (cond ((poispzero s) tt) (t (cons r (cons s tt)))))
(defun poismerges (a ae l)
(cond ((equal poishift ae) l) ; SINE(0) IS 0
((poisnegpred ae) (poismerge (poisco* -1 a) (poischangesign ae) l))
(t (poismerge a ae l))))
(defun poismergec (a ae l)
(cond ((poisnegpred ae) (poismerge a (poischangesign ae) l)) (t (poismerge a ae l))))
(defun poismerge (a ae l) (cond ((poispzero a) nil) (t (merge11 a ae l))))
(defun poismerge2 (r s)
(cond ((null r) s)
((null s) r)
(t (prog (m n tt)
(setq m (setq n (cons 0. r)))
a (cond ((null r) (rplacd m s) (return (cdr n)))
((null s) (return (cdr n)))
((equal (car r) (car s))
(setq tt (poisco+ (cadr r) (cadr s)))
(cond ((poispzero tt) (rplacd m (cddr r)) (setq r (cddr r) s (cddr s)))
(t (rplaca (cdr r) tt) (setq s (cddr s) r (cddr r) m (cddr m)))))
((> (car r) (car s))
(rplacd m s)
(setq s (cddr s))
(rplacd (cddr m) r)
(setq m (cddr m)))
(t (setq r (cddr r)) (setq m (cddr m))))
(go a)))))
(defun merge11 (a ae l)
(poismerge2 (list ae a) l))
(defun poismergesx (a ae l)
(cond ((equal poishift ae) l) ; SINE(0) IS 0
((poisnegpred ae) (avlinsert (poischangesign ae) (poisco* -1 a) l))
(t (avlinsert ae a l))))
(defun poismergecx (a ae l)
(cond ((poisnegpred ae) (avlinsert (poischangesign ae) a l)) (t (avlinsert ae a l))))
(defun poisctimes1 (c h)
(cond ((null h) nil)
((and trim (trimf (car h))) (poisctimes1 c (cddr h)))
(t (tcons (car h) (cons (poisco* c (cadr h)) (poisctimes1 c (cddr h)))))))
(defun trimf (m)
(meval (list '($poistrim)
(poisxcoef m '$u)
(poisxcoef m '$v)
(poisxcoef m '$w)
(poisxcoef m '$x)
(poisxcoef m '$y)
(poisxcoef m '$z))))
(defmfun $poistimes (a b)
(prog (slc clc temp ae aa zero trim t1 t2 f1 f2)
(setq a (intopois a) b (intopois b))
(cond ((or (getl-lm-fcn-prop '$poistrim '(expr subr))
(mget '$poistrim 'mexpr))
(setq trim t)))
(cond ((nonperiod a) (return ($poisctimes (cadr (caddr a)) b)))
((nonperiod b) (return ($poisctimes (cadr (caddr b)) a))))
(setq slc (avlinit poishift (setq zero (intopoisco 0.))) clc (avlinit poishift zero))
;; PROCEED THROUGH ALL THE SINES IN ARGUMENT A
(do ((sla
(cadr a)
(cddr sla)))(
(null sla))
(setq aa (halve (cadr sla)) ae (car sla))
;; SINE(U)*SINE(V) ==> (-COSINE(U+V) + COSINE(U-V))/2
(do ((slb
(cadr b)
(cddr slb)))(
(null slb))
(setq t1 (+ ae poishift (- (car slb))) t2 (+ ae (- poishift) (car slb)))
(cond(trim(setq f1(trimf t1) f2 (trimf t2)))
(t (setq f1 nil f2 nil)))
(setq temp (poisco* aa (cadr slb)))
(cond ((poispzero temp) nil)
(t (or f1 (poismergecx temp t1 clc))
(or f2 (poismergecx (poisco* -1 temp) t2 clc)))))
;; SINE*COSINE ==> SINE + SINE
(do ((clb
(caddr b)
(cddr clb)))(
(null clb))
(setq t1 (+ ae poishift (- (car clb))) t2 (+ ae (- poishift) (car clb)))
(cond(trim(setq f1(trimf t1) f2 (trimf t2)))
(t (setq f1 nil f2 nil)))
(setq temp (poisco* aa (cadr clb)))
(cond ((poispzero temp) nil)
(t (or f1 (poismergesx temp t1 slc)) (or f2 (poismergesx temp t2 slc))))))
;; PROCEED THROUGH ALL THE COSINES IN ARGUMENT A
(do ((cla
(caddr a)
(cddr cla)))(
(null cla))
(setq aa (halve (cadr cla)) ae (car cla))
;; COSINE*SINE ==> SINE - SINE
(do ((slb
(cadr b)
(cddr slb)))(
(null slb))
(setq t1 (+ ae poishift (- (car slb)))
t2 (+ ae (- poishift) (car slb)))
(cond (trim (setq f1 (trimf t1) f2 (trimf t2)))
(t (setq f1 nil f2 nil)))
(cond (t (setq temp (poisco* aa (cadr slb)))
(cond ((poispzero temp) nil)
(t (or f1 (poismergesx (poisco* -1 temp) t1 slc))
(or f2 (poismergesx temp t2 slc)))))))
;; COSINE*COSINE ==> COSINE + COSINE
(do ((clb (caddr b) (cddr clb)))
((null clb))
(setq t1 (+ ae poishift (- (car clb)))
t2 (+ ae (- poishift) (car clb)))
(cond (trim (setq f1 (trimf t1) f2 (trimf t2)))
(t (setq f1 nil f2 nil)))
(cond
(t (setq temp (poisco* aa (cadr clb)))
(cond ((poispzero temp) nil)
(t (or f1 (poismergecx temp t1 clc))
(or f2 (poismergecx temp t2 clc))))))))
(return (list '(mpois simp) (untree slc) (untree clc)))))
(defmfun $poisexpt (p n)
(prog (u h)
(cond ((oddp n) (setq u p)) (t (setq u (setq h (intopois 1.)))))
a (setq n (ash n -1))
(cond ((zerop n) (return u)))
(setq p ($poistimes p p))
(cond ((oddp n) (setq u (cond ((equal u h) p) (t ($poistimes u p))))))
(go a)))
(defmfun $poissquare (a) ($poisexpt a 2))
;;; $POISINT INTEGRATES A POISSON SERIES WRT X,Y, Z, U, V, W. THE VARIABLE OF
;;; INTEGRATION MUST OCCUR ONLY IN THE ARGUMENTS OF SIN OR COS,
;;; OR ONLY IN THE COEFFICIENTS. POISCOINTEG IS CALLED TO INTEGRATE COEFFS.
;;; NON-PERIODIC TERMS ARE REMOVED.
(defmfun $poisint (p m)
(declare (special m))
(prog (b*)
(setq p (intopois p))
(cond ((member m '($u $v $w $x $y $z) :test #'eq)
(return (list (car p)
(cosint* (caddr p) m)
(sinint* (cadr p) m))))
(t (return (list (car p)
(poisint4 (cadr p))
(poisint4 (caddr p))))))))
(defun poisint4 (y)
(declare (special m))
(cond ((null y) nil)
(t (tcons3 (car y)(poiscointeg (cadr y) m) (poisint4 (cddr y))))))
;;;COSINT* INTEGRATES COSINES TO GET SINES
(defun cosint* (h m)
(cond ((null h) nil)
((equal 0 (setq b* (poisxcoef (car h) m))) (cosint* (cddr h) m))
(t (tcons (car h)
(cons (poisco* (intopoisco (list '(mexpt) b* -1)) (cadr h))
(cosint* (cddr h) m))))))
(defun sinint* (h m)
(cond ((null h) nil)
((equal 0 (setq b* (poisxcoef (car h) m))) (sinint* (cddr h) m))
(t (tcons (car h)
(cons (poisco* (intopoisco (list '(mexpt) (- (poisxcoef (car h) m)) -1))
(cadr h))
(sinint* (cddr h) m))))))
;;; $POISSUBST SUBSTITUTES AN EXPRESSION FOR A VARIABLE IN ARGUMENT OF TRIG FUNCTIONS OR
;;; COEFFICIENTS.
(defun poissubsta (a b* c)
(prog (ss cc)
(setq h* (- (poisencode (list '(mplus) a (list '(mtimes) -1 b*))) poishift))
(poissubst1s (cadr c))
(poissubst1c (caddr c))
(return (list (car c) ss cc))))
(defun poissubst1s (c)
(cond ((null c) nil)
(t (setq ss (poismerges (cadr c) (argsubst (car c)) ss))
(poissubst1s (cddr c)))))
(defun poissubst1c (c)
(cond ((null c) nil)
(t (setq cc (poismergec (cadr c) (argsubst (car c)) cc))
(poissubst1c (cddr c)))))
(defun argsubst (c)
(+ c (* h* (poisxcoef c b*))))
(defmfun $poissubst (aa bb cc &optional dd nn)
(if (and dd nn)
(fancypoissubst aa bb (intopois cc) (intopois dd) nn)
(let ((a* aa) (b* bb) (c (intopois cc)))
(if (member b* '($u $v $w $x $y $z) :test #'eq)
(poissubsta a* b* c)
(list (car c) (poissubstco1 (cadr c)) (poissubstco1 (caddr c)))))))
(declare-top (unspecial $u $v $w $x $y $z))
(defun poissubstco1 (c)
(if (null c)
nil
(tcons (car c) (cons (poissubstco a* b* (cadr c)) (poissubstco1 (cddr c))))))
(declare-top (special dc ds *ans))
(defun fancypoissubst (a b* c d n)
;;SUBSTITUTES A+D FOR B IN C, WHERE D IS EXPANDED IN POWERSERIES TO ORDER N
(prog (h* dc ds *ans)
(setq *ans (list '(mpois simp) nil nil) d (intopois d) dc (intopois 1) ds (intopois 0))
(when (equal n 0) (return ($poissubst a b* c)))
(fancypois1s d 1 1 n)
(setq h* (- (poisencode (list '(mplus) a (list '(mtimes) -1 b*))) poishift))
(fancypas (cadr c))
(fancypac (caddr c))
(return *ans)))
(defun fancypois1s (d dp n lim) ; DP IS LAST POWER: D^(N-1), LIM IS HIGHEST TO
(cond ((> n lim) nil) ;GO
(t (setq ds ($poisplus ds
($poisctimes (list '(rat)
(expt -1 (ash (1- n) -1))
(factorial n))
(setq dp ($poistimes dp d)))))
(fancypois1c d dp (1+ n) lim))))
(defun fancypois1c (d dp n lim) ; DP IS LAST POWER: D^(N-1), LIM IS HIGHEST TO
(cond ((> n lim) nil) ;GO
(t (setq dc
($poisplus dc
($poisctimes (list '(rat) (expt -1 (ash n -1)) (factorial n))
(setq dp ($poistimes dp d)))))
(fancypois1s d dp (1+ n) lim))))
;;; COS(R+K*B) ==> K*COS(R+K*A)*DC - K*SIN(R+K*A)*DS
;;; SIN(R+K*B) ==> K*COS(R+K*A)*DS + K*SIN(R+K*A)*DC
(defun fancypac (c)
(prog nil
(cond ((null c) (return nil)))
(setq *coef (poisxcoef (car c) b*))
(cond ((equal *coef 0)
(setq *ans ($poisplus *ans (list '(mpois simp) nil (list (car c) (cadr c)))))
(go end)))
(cond ((poispzero (setq *coef (poisco* (cadr c) (intopoisco *coef)))) (go end)))
(setq *argc (argsubst (car c)))
(setq *ans
($poisplus *ans
($poisplus ($poistimes (list '(mpois simp)
nil
(poismergec *coef *argc nil))
dc)
($poistimes (list '(mpois simp)
(poismerges (poisco* -1 *coef) *argc nil)
nil)
ds))))
end (fancypac (cddr c))))
(defun fancypas (c)
(prog nil
(cond ((null c) (return nil)))
(setq *coef (poisxcoef (car c) b*))
(cond ((equal *coef 0.)
(setq *ans ($poisplus *ans (list '(mpois simp) (list (car c) (cadr c)) nil)))
(go end)))
(cond ((poispzero (setq *coef (poisco* (cadr c) (intopoisco *coef)))) (go end)))
(setq *argc (argsubst (car c)))
(setq *ans ($poisplus *ans
($poisplus ($poistimes (list '(mpois simp)
nil
(poismergec *coef *argc nil))
ds)
($poistimes (list '(mpois simp)
(poismerges *coef *argc nil)
nil)
dc))))
end (fancypas (cddr c))))
|