home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / src / algsys.lisp < prev    next >
Encoding:
Text File  |  2003-02-09  |  17.0 KB  |  545 lines

  1. ;;; -*-  Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;     The data in this file contains enhancments.                    ;;;;;
  4. ;;;                                                                    ;;;;;
  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. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. (in-package "MAXIMA")
  12. (macsyma-module algsys)
  13. (load-macsyma-macros ratmac)
  14.  
  15. (eval-when (eval compile)
  16.   #+PDP10
  17.   ;; this file contains macysma variable binding calls which
  18.   ;; have been observed to need unwind-protect even on the PDP10,
  19.   ;; since the ERRLIST mechanism can't hack catch and *throw.
  20.   ;; In general unwind-protect is needed, but the bugs caused by not using
  21.   ;; it are rare, and it is not deemed worth using UNWIND-PROTECT in
  22.   ;; general.
  23.   (setq MBINDING-USAGE 'unwind-protect))
  24.  
  25. ;This is the algsys package.
  26.  
  27. ;It solves systems of polynomial equations by straight-forward
  28. ;resultant hackery.  Other possible methods seem worse:
  29. ;the Buchberger-Spear canonical ideal basis algorithm is slow,
  30. ;and the "resolvent" method (see van der Waerden, section 79)
  31. ;blows up in time and space.  The "resultant"
  32. ;method (see the following sections of van der Waerden and
  33. ;Macaulay's book - Algebraic Theory of Modular Systems) looks
  34. ;good, but it requires the evaluation of large determinants.
  35. ;Unless some hack (such as prs's for evaluating resultants of
  36. ;two polynomials) is developed for multi-polynomial resultants,
  37. ;this method will remain impractical.
  38.  
  39. ;Some other possible ideas:  Keeping the total number of equations constant,
  40. ;in an effort to reduce extraneous solutions, or Reducing to a linear 
  41. ;equation before taking resultants.
  42.  
  43. (declare-top(special $algdelta $ratepsilon $algepsilon $keepfloat
  44.           varlist genvar *roots *failures $ratprint $numer $ratfac
  45.           $rnum $solvefactors $dispflag $breakup $rootsquad
  46.           *tvarxlist* errorsw $programmode *ivar* errset $polyfactor
  47.           bindlist loclist $float $infeval)
  48.      (*lexpr $ratsimp)
  49.      (genprefix alg))
  50.  
  51. ;;note if  $algepsilon is too large you may lose some roots.
  52. #+cl
  53. (defmvar $algdelta 1.0e-4 )
  54.  
  55.  
  56. (defmvar $%rnum_list '((mlist))
  57.      "Upon exit from ALGSYS this is bound to a list of the %RNUMS
  58.      which where introduced into the expression. Useful for mapping
  59.      over and using as an argument to SUBST.")
  60.  
  61. (defmvar $realonly nil "If t only real solutions are returned.")
  62.  
  63. (defmvar realonlyratnum nil
  64.  "A REALROOTS hack for RWG.  Causes ALGSYS to retain rational numbers 
  65.   returned by REALROOTS when REALONLY is TRUE."
  66.  in-core)
  67.  
  68. (defmvar $algexact nil "If t ALGSYS always calls SOLVE to try to MAXIMA-FIND exact
  69.                         solutions.") 
  70.  
  71. (defmvar algnotexact nil
  72.  "A hack for RWG for univariate polys.  Causes SOLVE not to get called
  73.   so that sqrts and cube roots will not be generated."
  74.  in-core)
  75.  
  76. (defmacro merrset (l)
  77.   #-NIL `(let ((errset 'errbreak1) (unbind (cons bindlist loclist)) val)
  78.        (setq val (errset ,l nil))
  79.        (cond ((null val) (errlfun1 unbind)))
  80.        val)
  81.   ;I guess be a bit dirty now...
  82.   #+NIL (let ((name (gentemp)))
  83.       `(let ((unbind (cons bindlist loclist)))
  84.          (let ((val (block ,name
  85.               (catch 'si:errset-catch
  86.                 (let ((si:errset-status t)
  87.                   (si:errset-print-message t))
  88.                   (return-from ,name (list ,l))))
  89.               (errbreak1 nil)
  90.               nil)))
  91.            (unless val (errlfun1 unbind))
  92.            val))))
  93.  
  94. ;; Make sure that $SOLVE is in core.  Only needed for small address
  95. ;; space systems.
  96.  
  97. #+PDP10
  98. (find-function '$solve)
  99.  
  100. (defmfun $algsys (lhslist varxlist &aux varlist genvar)
  101. ;  (declare (special varxlist)) ;;??
  102.   (setq $%rnum_list (list '(mlist)))
  103.   (cond ((not ($listp lhslist))
  104.      (merror  "Wrong type arg to ALGSYS:~%~M" lhslist))
  105.     ((not ($listp varxlist))
  106.      (merror "Wrong type arg to ALGSYS:~%~M" varxlist)))
  107.   ((lambda (tlhslist *tvarxlist* solnlist $ratprint $ratepsilon
  108.              $keepfloat varlist genvar $ratfac $breakup
  109.              $solvefactors *roots *failures *ivar* $polyfactor 
  110.              varxl $infeval $numer $float numerflg)
  111.      (dolist (var (cdr ($listofvars (list '(mlist simp) lhslist varxlist))))
  112.          (if (and (symbolp var) (not (constant var)))
  113.          (setq varxl (cons var varxl))))
  114.      (orderpointer varlist)
  115.      (setq tlhslist
  116.        (mapcar (function (lambda (q) (cadr (ratf (meqhk q)))))
  117.            (cdr lhslist)))
  118.      (setq *ivar* (caadr (ratf '$%I)))
  119.      (setq *tvarxlist*
  120.        (mapcar #'(lambda (q)
  121.                (cond ((mnump q)
  122.                   (merror "Unacceptable variable to ALGSYS:~%~M"
  123.                       q))
  124.                  (t (caadr (ratf q)))))
  125.            (cdr varxlist)))
  126.      (putorder *tvarxlist*)
  127.      (mbinding (varxl varxl)
  128.            (setq solnlist
  129.              (mapcar #'(lambda (q)
  130.                  (addmlist
  131.                   (bbsorteqns
  132.                    (addparam (roundroots1 q) varxlist))))
  133.                  (algsys tlhslist))))
  134.      (remorder *tvarxlist*)
  135.      (setq solnlist (addmlist solnlist))
  136.      (if numerflg (let (($numer t) ($float t)) (ssimplifya solnlist))
  137.           solnlist))
  138.    nil nil nil nil 1.0e-7
  139.    nil (reverse (cdr varxlist)) nil nil nil
  140.    nil nil nil nil nil nil nil nil nil $numer))
  141.  
  142. (defun condensesolnl (tempsolnl)
  143.    (let (solnl)
  144.     (MAPL #'(lambda (q) (or (subsetl (cdr q) (car q))
  145.                    (setq solnl (cons (car q) solnl))))
  146.          (sort tempsolnl (function (lambda (a b) (> (length a)
  147.                             (length b))))))
  148.     solnl))
  149.  
  150. (defun subsetl (l1 s2)
  151.        (or (equal s2 (list nil))
  152.        (do ((l l1 (cdr l)))
  153.            ((null l) nil)
  154.            (cond ((m-subset (car l) s2) (return t))))))
  155.  
  156. (defun m-subset (s1 s2)
  157.        (do ((s s1 (cdr s)))
  158.        ((null s) t)
  159.        (cond ((not (memalike (car s) s2)) (return nil)))))
  160.  
  161. (defun algsys (tlhslist &aux answ)
  162.    (setq answ    (condensesolnl (apply (function append)
  163.                  (mapcar (function algsys0)
  164.                      (distrep (mapcar (function lofactors)
  165.                               tlhslist))))))
  166. ;     (displa  (cons '(mlist)  (sloop for v in answ collecting
  167. ;                  (cons '(mlist) v))))
  168.    answ)
  169.  
  170. (defun algsys0 (tlhslist)
  171.        (cond ((null tlhslist) (list nil))
  172.          ((equal tlhslist (list nil)) nil)
  173.          (t (algsys1 tlhslist))))
  174.  
  175. (defun algsys1 (tlhslist &aux answ)
  176.        ((lambda (resulteq vartorid nlhslist)
  177.         (setq vartorid (cdr resulteq)
  178.               resulteq (car resulteq)
  179.               nlhslist (mapcar (function (lambda (q)
  180.                       (cond ((among vartorid q)
  181.                          (presultant q resulteq
  182.                                  vartorid))
  183.                         (t q))))
  184.                        (delet resulteq tlhslist)))
  185.         (setq answ (bakalevel (algsys nlhslist) tlhslist vartorid))
  186.         
  187.         answ)
  188.     (findleastvar tlhslist) nil nil))
  189.        
  190.  
  191.  
  192.  
  193.  
  194. (defun addmlist (l) (cons '(MLIST) l))
  195.  
  196. (defmacro what-the-$ev (&rest l)
  197.       ;; macro for calling $EV when you are not really
  198.       ;; sure why you are calling it, but you want the
  199.       ;; features of multiple evaluations and unpredictabiltiy
  200.       ;; anyway.
  201.       `(meval (list '($ev) ,@l)))
  202.  
  203. (defun rootsp (asolnset eqn)    ;eqn is ((MLIST) eq deriv) 
  204.        (let (rr ($keepfloat t) ($numer t) ($float t)) 
  205.         (setq rr (what-the-$EV eqn asolnset))  ; ratsimp?
  206.         (cond ((and (complexnump (cadr rr)) (complexnump (caddr rr)))
  207.            (lessp (cabs (cadr rr))
  208.               (times $algdelta (max 1 (cabs (caddr rr))))))
  209.           (t nil)))) 
  210.  
  211. (defun round1 (a) 
  212.        (cond ((floatp a)
  213.           (setq a (MAXIMA-RATIONALIZE a))
  214.           (fpcofrat1 (car a) (cdr a)))
  215.          (t a))) 
  216.  
  217. (defun roundrhs (eqn)
  218.     (list (car eqn) (cadr eqn) (round1 (caddr eqn))))
  219.  
  220. (defun roundroots1 (lsoln) (mapcar (function roundrhs) lsoln))
  221.  
  222. (defun bbsorteqns (l) (sort (copy-top-level l) 'ORDERLESSP))
  223.  
  224. (defun putorder (tempvarl) 
  225.      (do ((n 1 (f1+ n))
  226.       (tempvarl tempvarl (cdr tempvarl)))
  227.      ((null tempvarl) nil)
  228.      (putprop (car tempvarl) n 'VARORDER)))
  229.  
  230. (defun remorder (gvarl)
  231.        (mapc (function (lambda (x) (remprop x 'VARORDER))) gvarl))
  232.  
  233.  
  234. (defun orderlessp (eqn1 eqn2) 
  235.     (< (get (caadr (ratf (cadr eqn1))) 'VARORDER)
  236.        (get (caadr (ratf (cadr eqn2))) 'VARORDER)))
  237.  
  238. (defun addparam (asolnsetl varxlist)
  239.     (cond ((= (length asolnsetl) (length *tvarxlist*))
  240.        asolnsetl)
  241.       (t
  242.        (do ((tvarxl (cdr varxlist) (cdr tvarxl))
  243.         (defvar (mapcar #'cadr asolnsetl))
  244.         (var) (param))
  245.            ((null tvarxl) asolnsetl)
  246.            (setq var (car tvarxl))
  247.            (cond ((memalike var defvar) nil)
  248.              (t (setq param (make-param)
  249.                   asolnsetl (cons (list '(MEQUAL) var param)
  250.                           (cdr (MAXIMA-SUBSTITUTE
  251.                             param var
  252.                             (addmlist asolnsetl)))))))))))
  253.  
  254. (declare-top(special *vardegs*))
  255.  
  256. (defun findleastvar (lhsl)
  257.     (do ((tlhsl lhsl (cdr tlhsl))
  258.      (teq) (*vardegs*) (tdeg)
  259.      ;; Largest possible fixnum.  The actual degree of any polynomial
  260.      ;; is supposed to be less than this number.
  261.      (leastdeg  most-positive-fixnum)
  262.      (leasteq) (leastvar))
  263.     ((null tlhsl) (cons leasteq leastvar))
  264.     (declare (special *vardegs*))
  265.     (setq teq (car tlhsl))
  266.     (setq *vardegs* (getvardegs teq))
  267.     (setq tdeg (killvardegsc teq))
  268.     (mapc (function (lambda (q) (cond ((not (> (cdr q) leastdeg))
  269.                        (setq leastdeg (cdr q)
  270.                          leasteq teq
  271.                          leastvar (car q))))))
  272.           *vardegs*)
  273.     (cond ((< tdeg leastdeg) (setq leastdeg tdeg
  274.                        leasteq teq
  275.                        leastvar (car teq))))))
  276.  
  277. (defun killvardegsc (poly)
  278.        (cond ((pconstp poly) 0)
  279.          (t (do ((poly (cdr poly) (cddr poly))
  280.              (tdeg 0 (max tdeg (f+ (car  poly)
  281.             (cond ((= (car poly) 0)
  282.                    (killvardegsc (cadr poly)))
  283.                   (t (killvardegsn (cadr poly))))))))
  284.             ((null poly) tdeg)))))
  285.  
  286. (defun killvardegsn (poly)
  287.        (declare (special *vardegs*))
  288.        (cond ((pconstp poly) 0)
  289.          (t ((lambda (x) (and x
  290.                   (not (> (cdr x) (cadr poly)))
  291.                   (setq *vardegs* (zl-DELETE x *vardegs*))))
  292.          (assq (car poly) *vardegs*))
  293.         (do ((poly (cdr poly) (cddr poly))
  294.              (tdeg 0 (max tdeg (f+ (car poly)
  295.                       (killvardegsn (cadr poly))))))
  296.             ((null poly) tdeg)))))
  297.  
  298. (defun getvardegs (poly)
  299.        (cond ((pconstp poly) nil)
  300.          ((pconstp (caddr poly))
  301.           (cons (cons (car poly) (cadr poly))
  302.             (getvardegs (pterm (cdr poly) 0))))
  303.          (t (getvardegs (pterm (cdr poly) 0)))))
  304.  
  305. (declare-top(unspecial *vardegs*))
  306.  
  307. (defun pconstp (poly)
  308.        (or (atom poly) (not (memq (car poly) *tvarxlist*))))
  309.  
  310. (defun pfreeofmainvarsp (poly)
  311.        (cond ((atom poly) poly)
  312.          ((null (memq (car poly) *tvarxlist*))
  313.           ($radcan (pdis poly)))
  314.          (t poly)))
  315.  
  316. (defun lofactors (poly)
  317.        (setq poly (pfreeofmainvarsp poly))
  318.        (cond ((pzerop poly) ;(signp e poly)
  319.           (list 0))
  320.          ((or (atom poly) (not (atom (car poly))))  nil)
  321.          (t (do ((tfactors (pfactor poly) (cddr tfactors))
  322.              (lfactors))
  323.             ((null tfactors) lfactors)
  324.             (setq poly (pfreeofmainvarsp (car tfactors)))
  325.             (cond ((pzerop poly);(signp e poly)
  326.                (return (list 0)))
  327.               ((and (not (atom poly)) (atom (car poly)))
  328.                (setq lfactors (cons (pabs poly) lfactors))))))))
  329.  
  330. (defun combiney (listofl)
  331.        (cond ((memq nil listofl) nil)
  332.          (t (combiney1 (zl-DELETE '(0) listofl)))))
  333.  
  334. (defun combiney1 (listofl)
  335.        (cond ((null listofl) (list nil))
  336.          (t (mapcan #'(lambda (r)
  337.                   (cond ((intersect (car listofl) r) (list r))
  338.                     (t (mapcar #'(lambda (q) (cons q r))
  339.                            (car listofl)))))
  340.             (combiney1 (cdr listofl))))))
  341.  
  342. (defun midpnt (l) (rhalf (rplus* (car l) (cadr l)))) 
  343.  
  344. (defun rflot (l) 
  345.  (let ((rr (midpnt l)))
  346.       (if realonlyratnum (list '(rat) (car rr) (cdr rr))
  347.              (quotient (plus 0.0 (car rr)) (cdr rr)))))
  348.  
  349. (defun memberroot (a x eps)
  350.        (cond ((null x) nil)
  351.          ((lessp (abs (difference a (car x)))
  352.              (quotient (plus 0.0 (car eps)) (cdr eps)))
  353.           t)
  354.          (t (memberroot a (cdr x) eps))))
  355.  
  356. (defun commonroots (eps solnl1 solnl2) 
  357.        (cond ((null solnl1) nil)
  358.          ((memberroot (car solnl1) solnl2 eps)
  359.           (cons (car solnl1) (commonroots eps (cdr solnl1) solnl2)))
  360.          (t (commonroots eps (cdr solnl1) solnl2)))) 
  361.  
  362. (defun deletmult (l) 
  363.        (and l (cons (car l) (deletmult (cddr l)))))
  364.  
  365. (defun punivarp (poly)
  366.        (do ((l (cdr poly) (cddr l)))
  367.        ((null l) t)
  368.        (or (numberp (cadr l))
  369.            (and (eq (caadr l) *ivar*)
  370.             (punivarp (cadr l)))
  371.            (return nil))))
  372.  
  373. (defun realonly (rootsl) 
  374.        (cond ((null rootsl) nil)
  375.          ((freeof '$%I (car rootsl))
  376.           (nconc (list (car rootsl)) (realonly (cdr rootsl))))
  377.          (t (realonly (cdr rootsl))))) 
  378.  
  379.  
  380. (defun presultant (p1 p2 var) 
  381.        (cadr (ratf ($resultant (pdis p1) (pdis p2) (pdis (list var 1. 1.)))))) 
  382.  
  383. (defun ptimeftrs (l) 
  384.        (prog (ll) 
  385.          (setq ll (cddr l))
  386.          (cond ((null ll) (return (car l)))
  387.            (t (return (ptimes (car l) (ptimeftrs ll))))))) 
  388.  
  389. (defun ebaksubst (solnl lhsl)
  390.        (mapcar #'(lambda (q) (cadr (ratf (what-the-$EV (pdis q)
  391.                                (cons '(MLIST) solnl)
  392.                                '$radcan))))
  393.            lhsl))
  394.  
  395. (defun baksubst (solnl lhsl)
  396.        (setq lhsl (delq 'T (mapcar #'(lambda (q)
  397.                          (car (merrset (baksubst1 solnl q))))
  398.                    lhsl)))        ;catches arith. ovfl
  399.        (cond ((memq nil lhsl) (list nil))
  400.          (t lhsl)))
  401.  
  402. (defun baksubst1 (solnl poly)
  403.        (let* (($keepfloat (not $realonly))        ;sturm1 needs poly with
  404.           (poly1                    ;integer coefs
  405.            (cdr
  406.         (ratf (what-the-$EV (pdis poly)
  407.                     (cons '(MLIST) solnl)
  408.                     '$NUMER)))))
  409.          (cond ((and (complexnump (pdis (car poly1)))
  410.              (numberp (cdr poly1)))
  411.             (rootsp (cons '(MLIST) solnl)
  412.                 (list '(MLIST) (pdis poly) (tayapprox poly))))
  413.            (t (car poly1)))))
  414.  
  415. (defun complexnump (p)
  416.        ((lambda (p)
  417.         (or (numberp p) (eq (pdis (pget (car p))) '$%i)))
  418.     (cadr (ratf ($ratsimp p)))))
  419.  
  420. (defun bakalevel (solnl lhsl var)
  421.   ;(apply #'append (mapcar #'(lambda (q) (bakalevel1 q lhsl var)) solnl))
  422.   (sloop for q in solnl append (bakalevel1 q lhsl var))
  423.   )
  424.  
  425. (defun bakalevel1 (solnl lhsl var) 
  426.        (cond ((exactonly solnl)
  427.           (cond (solnl (mergesoln solnl (algsys (ebaksubst solnl lhsl))))
  428.             ((cdr lhsl)
  429.              (bakalevel (callsolve (setq solnl (findleastvar lhsl)))
  430.                 (zl-REMOVE (car solnl) lhsl) var))
  431.             (t (callsolve (cons (car lhsl) var)))))
  432.          (t (mergesoln solnl (apprsys (baksubst solnl lhsl))))))
  433.  
  434. (defun exactonly (solnl)
  435.   (cond ((atom solnl)
  436.      (and (not (floatp solnl))
  437.           (or (null realonlyratnum) (not (eq solnl 'rat)))))
  438.     (t (and (exactonly (car solnl)) (exactonly (cdr solnl))))))
  439.  
  440. (defun mergesoln (asoln solnl)
  441.   (let ((errorsw t) s (unbind (cons bindlist loclist)))
  442.        (mapcan
  443.     #'(lambda (q)
  444.          (setq s (catch 'errorsw
  445.                  (append
  446.                   (mapcar #'(lambda (r)
  447.                         (what-the-$EV r
  448.                                   (cons '(MLIST) q))
  449.                       )
  450.                       asoln)
  451.                   q)))
  452.          (cond ((eq s t) (errlfun1 unbind) nil)
  453.            (t (list s))))
  454.     solnl)))
  455.  
  456. (defun callsolve (pv)
  457.        ((lambda (poly var varlist genvar *roots *failures $programmode)
  458.         (cond ((or $algexact (not (punivarp  poly))
  459.                (biquadraticp poly))
  460.                (solve (pdis poly) (pdis (list var 1 1)) 1)
  461.                (cond ((null (or *roots *failures))
  462.                   (list nil))
  463.                  (t
  464.                   (append (mapcan (function (lambda (q)
  465.  
  466.                   (callapprs (cadr (ratf (meqhk q))))))
  467.  
  468.                           (deletmult *failures))
  469.                       (mapcar (function list)
  470.                           (cond ($realonly
  471.                              (realonly (deletmult *roots)))
  472.                             (t (deletmult *roots))))))))
  473.          (t (callapprs poly))))
  474.     (car pv) (cdr pv) varlist genvar nil nil t))
  475.  
  476. (defun biquadraticp (poly)
  477.   (or (atom poly)
  478.       (if algnotexact
  479.       (< (cadr poly) 2)
  480.       (or (< (cadr poly) 3)
  481.           (and (= (cadr poly) 4) (biquadp1 (cdddr poly)))))))
  482.  
  483. (defun biquadp1 (l)
  484.        (or (null l)
  485.        (and (or (= (car l) 2) (= (car l) 0))
  486.         (biquadp1 (cddr l)))))
  487.        
  488. (defun callapprs (poly)
  489.        (or (punivarp poly)
  490.        (merror "ALGSYS cannot solve - system too complicated."))
  491.        (let ($rootsquad $dispflag)
  492.         (cond ($realonly
  493.            (mapcar (function (lambda (q)
  494.                          (list (list '(MEQUAL)
  495.                            (pdis (list (car poly) 1 1))
  496.                            (rflot q)))))
  497.                    (sturm1 poly (cons 1 $algepsilon))))
  498.           (t (mapcar #'list
  499.                  (let (($programmode t) l)
  500.                   (setq l (cdr ($allroots (pdis poly))))
  501.                   (cond ((not (eq (caaar l) 'mequal)) (cdr l))
  502.                     (t l))))))))
  503.  
  504. (defun apprsys (lhsl)
  505.        (cond ((null lhsl) (list nil))
  506.          (t
  507.           (do ((tlhsl lhsl (cdr tlhsl))) (nil)
  508.           (cond ((null tlhsl)
  509.              (merror
  510.               "ALGSYS cannot solve - system too complicated."))
  511.             ((pconstp (car tlhsl)) (return nil))
  512.             ((punivarp (car tlhsl))
  513.              (return (bakalevel (callapprs (car tlhsl))
  514.                         lhsl nil))))))))
  515.  
  516. (defun tayapprox (p)
  517.        (cons '(MPLUS)
  518.          (mapcar (function (lambda (x)
  519.              (list '(MYCABS) (pdis (ptimes (list x 1 1)
  520.                                (pderivative p x))))))
  521.              (listovars p))))
  522.  
  523. (defmfun mycabs (x)
  524.        (and (complexnump x) (cabs x)))
  525.  
  526. (defun distrep (lol)
  527.        (condensesolnl (condensesublist (combiney lol))))
  528.  
  529. (defun condensey (l)
  530.   ((lambda (result)
  531.     (MAPL #'(lambda (q) (or (memalike (car q) (cdr q))
  532.               (setq result (cons (car q) result))))
  533.      l)
  534.     result)
  535.    nil))
  536.  
  537. (defun condensesublist (lol) (mapcar #'condensey lol))
  538.  
  539. (defun exclude (l1 l2) 
  540.        (cond ((null l2) nil)
  541.          ((zl-MEMBER (car l2) l1) (exclude l1 (cdr l2)))
  542.          (t ;(append (list (car l2)) (exclude l1 (cdr l2)))
  543.         (cons (car l2) (exclude l1 (cdr l2)))
  544.         )))
  545.