/usr/share/maxima/5.32.1/src/outmis.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 | ;;; -*- 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 ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(in-package :maxima)
;; ** (c) Copyright 1982 Massachusetts Institute of Technology **
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;;
;;; Miscellaneous Out-of-core Files ;;;
;;; ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(macsyma-module outmis)
(declare-top (special $exptisolate $labels $dispflag errorsw))
(defmvar $exptisolate nil)
(defmvar $isolate_wrt_times nil)
(defmfun $isolate (e *xvar)
(iso1 e (getopr *xvar)))
(defun iso1 (e *xvar)
(cond ((specrepp e) (iso1 (specdisrep e) *xvar))
((and (free e 'mplus) (or (null $isolate_wrt_times) (free e 'mtimes))) e)
((freeof *xvar e) (mgen2 e))
((alike1 *xvar e) *xvar)
((member (caar e) '(mplus mtimes) :test #'eq) (iso2 e *xvar))
((eq (caar e) 'mexpt)
(cond ((null (atom (cadr e))) (list (car e) (iso1 (cadr e) *xvar) (caddr e)))
((or (alike1 (cadr e) *xvar) (not $exptisolate)) e)
(t (let ((x ($rat (caddr e) *xvar)) (u 0) (h 0))
(setq u (ratdisrep ($ratnumer x)) x (ratdisrep ($ratdenom x)))
(if (not (equal x 1))
(setq u ($multthru (list '(mexpt) x -1) u)))
(if (mplusp u)
(setq u ($partition u *xvar) h (cadr u) u (caddr u)))
(setq u (power* (cadr e) (iso1 u *xvar)))
(cond ((not (equal h 0))
(mul2* (mgen2 (power* (cadr e) h)) u))
(t u))))))
(t (cons (car e) (mapcar #'(lambda (e1) (iso1 e1 *xvar)) (cdr e))))))
(defun iso2 (e *xvar)
(prog (hasit doesnt op)
(setq op (ncons (caar e)))
(do ((i (cdr e) (cdr i))) ((null i))
(cond ((freeof *xvar (car i)) (setq doesnt (cons (car i) doesnt)))
(t (setq hasit (cons (iso1 (car i) *xvar) hasit)))))
(cond ((null doesnt) (go ret))
((and (null (cdr doesnt)) (atom (car doesnt))) (go ret))
((prog2 (setq doesnt (simplify (cons op doesnt)))
(and (free doesnt 'mplus)
(or (null $isolate_wrt_times)
(free doesnt 'mtimes)))))
(t (setq doesnt (mgen2 doesnt))))
(setq doesnt (ncons doesnt))
ret (return (simplifya (cons op (nconc hasit doesnt)) nil))))
(defun mgen2 (h)
(cond ((memsimilarl h (cdr $labels) (getlabcharn $linechar)))
(t (setq h (displine h)) (and $dispflag (mterpri)) h)))
(defun memsimilarl (item list linechar)
(cond ((null list) nil)
((and (char= (getlabcharn (car list)) linechar)
(boundp (car list))
(memsimilar item (car list) (symbol-value (car list)))))
(t (memsimilarl item (cdr list) linechar))))
(defun memsimilar (item1 item2 item2ev)
(cond ((equal item2ev 0) nil)
((alike1 item1 item2ev) item2)
(t (let ((errorsw t) r)
(setq r (catch 'errorsw (div item2ev item1)))
(and (mnump r) (not (zerop1 r)) (div item2 r))))))
(defmfun $pickapart (x lev)
(setq x (format1 x))
(cond ((not (fixnump lev))
(merror (intl:gettext "pickapart: second argument must be an integer; found: ~M") lev))
((or (atom x) (and (eq (caar x) 'mminus) (atom (cadr x)))) x)
((= lev 0) (mgen2 x))
((and (atom (cdr x)) (cdr x)) x)
(t (cons (car x) (mapcar #'(lambda (y) ($pickapart y (1- lev))) (cdr x))))))
(defmfun $reveal (e lev)
(setq e (format1 e))
(cond ((and (eq (ml-typep lev) 'fixnum) (> lev 0)) (reveal e 1 lev))
(t (merror (intl:gettext "reveal: second argument must be a positive integer; found: ~M") lev))))
(defun simple (x)
(or (atom x) (member (caar x) '(rat bigfloat) :test #'eq)))
(defun reveal (e nn lev)
(cond ((simple e) e)
((= nn lev)
(cond ((eq (caar e) 'mplus) (cons '(|$Sum| simp) (ncons (length (cdr e)))))
((eq (caar e) 'mtimes) (cons '(|$Product| simp) (ncons (length (cdr e)))))
((eq (caar e) 'mexpt) '|$Expt|)
((eq (caar e) 'mquotient) '|$Quotient|)
((eq (caar e) 'mminus) '|$Negterm|)
((eq (caar e) 'mlist)
(cons '(|$List| simp) (ncons (length (cdr e)))))
(t (getop (mop e)))))
(t (let ((u (cond ((member 'simp (cdar e) :test #'eq) (car e))
(t (cons (caar e) (cons 'simp (cdar e))))))
(v (mapcar #'(lambda (x) (reveal (format1 x) (1+ nn) lev))
(margs e))))
(cond ((eq (caar e) 'mqapply) (cons u (cons (cadr e) v)))
((eq (caar e) 'mplus) (cons u (nreverse v)))
(t (cons u v)))))))
(declare-top (special atvars munbound $props $gradefs $features opers
$contexts $activecontexts $aliases))
(defmspec $properties (x)
(setq x (getopr (fexprcheck x)))
(unless (or (symbolp x) (stringp x))
(merror
(intl:gettext "properties: argument must be a symbol or a string.")))
(let ((u (properties x)) (v (or (safe-get x 'noun) (safe-get x 'verb))))
(if v (nconc u (cdr (properties v))) u)))
(defun properties (x)
(if (stringp x)
; AT THIS POINT WE MIGHT WANT TO TRY TO TEST ALL CHARS IN STRING ...
(if (and (> (length x) 0) (member (char x 0) *alphabet* :test #'eq))
'((mlist) $alphabetic)
'((mlist)))
(do ((y (symbol-plist x) (cddr y))
(l (cons '(mlist simp) (and (boundp x)
(if (optionp x) (ncons "system value")
(ncons '$value)))))
(prop))
((null y)
(if (member x (cdr $features) :test #'eq) (nconc l (ncons '$feature)))
(if (member x (cdr $contexts) :test #'eq) (nconc l (ncons '$context)))
(if (member x (cdr $activecontexts) :test #'eq)
(nconc l (ncons '$activecontext)))
(cond ((null (symbol-plist x))
(if (fboundp x) (nconc l (list "system function")))))
l)
;; TOP-LEVEL PROPERTIES
(cond ((setq prop
(assoc (car y)
`((bindtest . $bindtest)
(sp2 . $deftaylor)
(sp2subs . $deftaylor)
(assign . "assign property")
(nonarray . $nonarray)
(grad . $gradef)
(integral . $integral)
(distribute_over . "distributes over bags")
(simplim%function . "limit function")
(conjugate-function . "conjugate function")
(commutes-with-conjugate . "mirror symmetry")
(risplit-function . "complex characteristic")
(noun . $noun)
(evfun . $evfun)
(evflag . $evflag)
(op . $operator)) :test #'eq))
(nconc l (ncons (cdr prop))))
((setq prop (member (car y) opers :test #'eq))
(nconc l (list (car prop))))
((and (eq (car y) 'operators) (not (eq (cadr y) 'simpargs1)))
(nconc l (list '$rule)))
((and (member (car y) '(fexpr fsubr mfexpr*s mfexpr*) :test #'eq)
(nconc l (ncons "special evaluation form"))
nil))
((and (or (get (car y) 'mfexpr*) (fboundp x))
;; Do not add more than one entry to the list.
(not (member '$transfun l))
(not (member '$rule l))
(not (member "system function" l :test #'equal)))
(nconc l
(list (cond ((get x 'translated) '$transfun)
((mgetl x '($rule ruleof)) '$rule)
(t "system function")))))
((and (eq (car y) 'autoload)
(not (member "system function" l :test #'equal)))
(nconc l (ncons (if (member x (cdr $props) :test #'eq)
"user autoload function"
"system function"))))
((and (eq (car y) 'reversealias)
(member (car y) (cdr $aliases) :test #'eq))
(nconc l (ncons '$alias)))
((eq (car y) 'data)
(nconc l (cons "database info" (cdr ($facts x)))))
((eq (car y) 'mprops)
;; PROPS PROPERTIES
(do ((y
(cdadr y)
(cddr y)))
((null y))
(cond ((setq prop (assoc (car y)
`((mexpr . $function)
(mmacro . $macro)
(hashar . "hashed array")
(aexpr . "array function")
(atvalues . $atvalue)
($atomgrad . $atomgrad)
($numer . $numer)
(depends . $dependency)
($nonscalar . $nonscalar)
($scalar . $scalar)
(matchdeclare . $matchdeclare)
(mode . $modedeclare)) :test #'eq))
(nconc l (list (cdr prop))))
((eq (car y) 'array)
(nconc l
(list (cond ((get x 'array) "complete array")
(t "declared array")))))
((and (eq (car y) '$props) (cdadr y))
(nconc l
(do ((y (cdadr y) (cddr y))
(l (list '(mlist) "user properties")))
((null y) (list l))
(nconc l (list (car y)))))))))))))
(defmspec $propvars (x)
(setq x (fexprcheck x))
(do ((iteml (cdr $props) (cdr iteml)) (propvars (ncons '(mlist))))
((null iteml) propvars)
(and (among x (meval (list '($properties) (car iteml))))
(nconc propvars (ncons (car iteml))))))
(defmspec $printprops (r) (setq r (cdr r))
(if (null (cdr r)) (merror (intl:gettext "printprops: requires two arguments.")))
(let ((s (cadr r)))
(setq r (car r))
(setq r (cond ((atom r)
(cond ((eq r '$all)
(cond ((eq s '$gradef) (mapcar 'caar (cdr $gradefs)))
(t (cdr (meval (list '($propvars) s))))))
(t (ncons r))))
(t (cdr r))))
(cond ((eq s '$atvalue) (dispatvalues r))
((eq s '$atomgrad) (dispatomgrads r))
((eq s '$gradef) (dispgradefs r))
((eq s '$matchdeclare) (dispmatchdeclares r))
(t (merror (intl:gettext "printprops: unknown property ~:M") s)))))
(defun dispatvalues (l)
(do ((l l (cdr l)))
((null l))
(do ((ll (mget (car l) 'atvalues) (cdr ll)))
((null ll))
(mtell-open "~M~%"
(list '(mlabel) nil
(list '(mequal)
(atdecode (car l) (caar ll) (cadar ll)) (caddar ll))))))
'$done)
(defun atdecode (fun dl vl)
(setq vl (copy-list vl))
(atvarschk vl)
(let ((eqs nil) (nvarl nil))
(cond ((not (member nil (mapcar #'(lambda (x) (signp e x)) dl) :test #'eq))
(do ((vl vl (cdr vl)) (varl atvars (cdr varl)))
((null vl))
(and (eq (car vl) munbound) (rplaca vl (car varl))))
(cons (list fun) vl))
(t (setq fun (cons (list fun)
(do ((n (length vl) (1- n))
(varl atvars (cdr varl))
(l nil (cons (car varl) l)))
((zerop n) (nreverse l)))))
(do ((vl vl (cdr vl)) (varl atvars (cdr varl)))
((null vl))
(and (not (eq (car vl) munbound))
(setq eqs (cons (list '(mequal) (car varl) (car vl)) eqs))))
(setq eqs (cons '(mlist) (nreverse eqs)))
(do ((varl atvars (cdr varl)) (dl dl (cdr dl)))
((null dl) (setq nvarl (nreverse nvarl)))
(and (not (zerop (car dl)))
(setq nvarl (cons (car dl) (cons (car varl) nvarl)))))
(list '(%at) (cons '(%derivative) (cons fun nvarl)) eqs)))))
(defun dispatomgrads (l)
(do ((i l (cdr i)))
((null i))
(do ((j (mget (car i) '$atomgrad) (cdr j)))
((null j))
(mtell-open "~M~%"
(list '(mlabel) nil
(list '(mequal)
(list '(%derivative) (car i) (caar j) 1) (cdar j))))))
'$done)
(defun dispgradefs (l)
(do ((i l (cdr i)))
((null i))
(setq l (get (car i) 'grad))
(do ((j (car l) (cdr j))
(k (cdr l) (cdr k))
(thing (cons (ncons (car i)) (car l))))
((or (null k) (null j)))
(mtell-open "~M~%"
(list '(mlabel)
nil (list '(mequal) (list '(%derivative) thing (car j) 1.) (car k))))))
'$done)
(defun dispmatchdeclares (l)
(do ((i l (cdr i))
(ret))
((null i) (cons '(mlist) ret))
(setq l (car (mget (car i) 'matchdeclare)))
(setq ret (cons (append (cond ((atom l) (ncons (ncons l))) (t l))
(ncons (car i)))
ret))))
(declare-top (special trans ovar nvar tfun invfun $programmode nfun
*roots *failures varlist genvar $ratfac))
(defmfun $changevar (expr trans nvar ovar)
(let (invfun nfun $ratfac)
(cond ((or (atom expr) (eq (caar expr) 'rat) (eq (caar expr) 'mrat)) expr)
((atom trans) (merror (intl:gettext "changevar: second argument must not be an atom; found: ~M") trans))
((null (atom nvar)) (merror (intl:gettext "changevar: third argument must be an atom; found: ~M") nvar))
((null (atom ovar)) (merror (intl:gettext "changevar: fourth argument must be an atom; found: ~M") ovar)))
(setq tfun (solvable (setq trans (meqhk trans)) ovar))
(changevar expr)))
(defun solvable (l var &optional (errswitch nil))
(let (*roots *failures)
(solve l var 1)
(cond (*roots ($rhs (car *roots)))
(errswitch (merror (intl:gettext "changevar: failed to solve for ~M in ~M") var l))
(t nil))))
(defun changevar (expr)
(cond ((atom expr) expr)
((or (not (member (caar expr) '(%integrate %sum %product) :test #'eq))
(not (alike1 (caddr expr) ovar)))
(recur-apply #'changevar expr))
(t (let ((deriv (if tfun (sdiff tfun nvar)
(neg (div (sdiff trans nvar) ;IMPLICIT DIFF.
(sdiff trans ovar))))))
(cond ((and (member (caar expr) '(%sum %product) :test #'eq)
(not (equal deriv 1)))
(merror (intl:gettext "changevar: illegal change in summation or product")))
((setq nfun ($radcan ;NIL IF KERNSUBST FAILS
(if tfun
(mul (maxima-substitute tfun ovar (cadr expr))
deriv)
(kernsubst ($ratsimp (mul (cadr expr)
deriv))
trans ovar))))
(cond ;; DEFINITE INTEGRAL,SUMMATION, OR PRODUCT
((cdddr expr)
(or invfun (setq invfun (solvable trans nvar t)))
(list (ncons (caar expr)) ;THIS WAS CHANGED
nfun ;FROM '(%INTEGRATE)
nvar
($limit invfun ovar (cadddr expr) '$plus)
($limit invfun
ovar
(car (cddddr expr))
'$minus)))
(t ;INDEFINITE INTEGRAL
(list '(%integrate) nfun nvar))))
(t expr))))))
(defun kernsubst (expr form ovar)
(let (varlist genvar nvarlist)
(newvar expr)
(setq nvarlist (mapcar #'(lambda (x) (if (freeof ovar x) x
(solvable form x)))
varlist))
(if (member nil nvarlist :test #'eq) nil
(prog2 (setq expr (ratrep* expr)
varlist nvarlist)
(rdis (cdr expr))))))
(declare-top (special $listconstvars facfun))
(defmfun $factorsum (e)
(factorsum0 e '$factor))
(defmfun $gfactorsum (e)
(factorsum0 e '$gfactor))
(defun factorsum0 (e facfun)
(cond ((mplusp (setq e (funcall facfun e)))
(factorsum1 (cdr e)))
(t (factorsum2 e))))
(defun factorsum1 (e)
(prog (f lv llv lex cl lt c)
loop (setq f (car e))
(setq lv (cdr ($showratvars f)))
(cond ((null lv) (setq cl (cons f cl)) (go skip)))
(do ((q llv (cdr q)) (r lex (cdr r)))
((null q))
(cond ((intersect (car q) lv)
(rplaca q (union* (car q) lv))
(rplaca r (cons f (car r)))
(return (setq lv nil)))))
(or lv (go skip))
(setq llv (cons lv llv) lex (cons (ncons f) lex))
skip (and (setq e (cdr e)) (go loop))
(or cl (go skip2))
(do ((q llv (cdr q)) (r lex (cdr r)))
((null q))
(cond ((and (null (cdar q)) (cdar r))
(rplaca r (nconc cl (car r)))
(return (setq cl nil)))))
skip2 (setq llv nil lv nil)
(do ((r lex (cdr r)))
((null r))
(cond ((cdar r)
(setq llv
(cons (factorsum2 (funcall facfun (cons '(mplus) (car r))))
llv)))
((or (not (mtimesp (setq f (caar r))))
(not (mnump (setq c (cadr f)))))
(setq llv (cons f llv)))
(t (do ((q lt (cdr q)) (s lv (cdr s)))
((null q))
(cond ((alike1 (car s) c)
(rplaca q (cons (dcon f) (car q)))
(return (setq f nil)))))
(and f
(setq lv (cons c lv)
lt (cons (ncons (dcon f)) lt))))))
(setq lex
(mapcar #'(lambda (s q)
(simptimes (list '(mtimes) s
(cond ((cdr q)
(cons '(mplus) q))
(t (car q))))
1 nil))
lv lt))
(return (simplus (cons '(mplus) (nconc cl lex llv)) 1 nil))))
(defun dcon (mt)
(cond ((cdddr mt) (cons (car mt) (cddr mt))) (t (caddr mt))))
(defun factorsum2 (e)
(cond ((not (mtimesp e)) e)
(t (cons '(mtimes)
(mapcar #'(lambda (f)
(cond ((mplusp f)
(factorsum1 (cdr f)))
(t f)))
(cdr e))))))
(declare-top (special $combineflag))
(defmvar $combineflag t)
(defmfun $combine (e)
(cond ((or (atom e) (eq (caar e) 'rat)) e)
((eq (caar e) 'mplus) (combine (cdr e)))
(t (recur-apply #'$combine e))))
(defun combine (e)
(prog (term r ld sw nnu d ln xl)
again(setq term (car e) e (cdr e))
(when (or (not (or (ratnump term) (mtimesp term) (mexptp term)))
(equal (setq d ($denom term)) 1))
(setq r (cons term r))
(go end))
(setq nnu ($num term))
(and $combineflag (integerp d) (setq xl (cons term xl)) (go end))
(do ((q ld (cdr q)) (p ln (cdr p)))
((null q))
(cond ((alike1 (car q) d)
(rplaca p (cons nnu (car p)))
(return (setq sw t)))))
(and sw (go skip))
(setq ld (cons d ld) ln (cons (ncons nnu) ln))
skip (setq sw nil)
end (and e (go again))
(and xl (setq xl (cond ((cdr xl) ($xthru (addn xl t)))
(t (car xl)))))
(mapc
#'(lambda (nu de)
(setq r (cons (mul2 (addn nu nil) (power* de -1)) r)))
ln ld)
(return (addn (if xl (cons xl r) r) nil))))
(defmfun $factorout (e &rest vl)
(prog (el fl cl l f x)
(when (null vl)
(merror (intl:gettext "factorout: at least two arguments required.")))
(unless (mplusp e)
(return e))
(or (null vl) (mplusp e) (return e))
(setq e (cdr e))
loop (setq f (car e) e (cdr e))
(unless (mtimesp f)
(setq f (list '(mtimes) 1 f)))
(setq fl nil cl nil)
(do ((i (cdr f) (cdr i)))
((null i))
(if (and (not (numberp (car i)))
(apply '$freeof (append vl (ncons (car i)))))
(setq fl (cons (car i) fl))
(setq cl (cons (car i) cl))))
(when (null fl)
(push f el)
(go end))
(setq fl (if (cdr fl)
(simptimes (cons '(mtimes) fl) 1 nil)
(car fl)))
(setq cl (cond ((null cl) 1)
((cdr cl) (simptimes (cons '(mtimes) cl) 1 t))
(t (car cl))))
(setq x t)
(do ((i l (cdr i)))
((null i))
(when (alike1 (caar i) fl)
(rplacd (car i) (cons cl (cdar i)))
(setq i nil x nil)))
(when x
(push (list fl cl) l))
end (when e (go loop))
(do ((i l (cdr i)))
((null i))
(push (simptimes (list '(mtimes) (caar i)
($factorsum (simplus (cons '(mplus) (cdar i)) 1 nil))) 1 nil) el))
(return (addn el nil))))
|