Support RETURN-FROM in DEF%TR forms
[maxima.git] / src / desoln.lisp
blobd97f6fc05621b64c72c9489404e2d27867331228
1 ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
3 (in-package :maxima)
5 (defmfun $desolve (eqns vars)
6 (let (teqns tvars ovar (lvar ($gensym)) (flag nil) ($dispflag nil))
7 (declare (special $dispflag))
8 (if ($mapatom vars)
9 (merror (intl:gettext "desolve(<eqn>,<depvar>): dependant variable <depvar> cannot be a mapatom, found: ~M") vars))
10 (unless ($listp vars)
11 (setq eqns (list '(mlist) eqns))
12 (setq vars (list '(mlist) vars))
13 (setq flag t))
14 (setq ovar (maref vars 1))
15 (unless (= ($length ovar) 1)
16 (merror (intl:gettext "desolve: more than one independent variable: ~M") ovar))
17 (setq ovar (simplify ($inpart ovar 1)))
18 (setq teqns
19 (simplify (map1 (getopr (m-tlambda&env (($z) (ovar lvar))
20 nil
21 (simplify ($laplace $z ovar lvar))))
22 eqns)))
23 (setq tvars
24 (simplify (map1 (getopr (m-tlambda&env (($z) (ovar lvar))
25 nil
26 (simplify `((%laplace) ,$z ,ovar ,lvar))))
27 vars)))
28 (setq teqns
29 (let ((errcatch (cons bindlist loclist))
30 (ret (errset (simplify ($solve teqns tvars)))))
31 (when (null ret)
32 (errlfun1 errcatch))
33 (cons '(mlist) ret)))
34 (when (or (like teqns '((mlist)))
35 (like teqns (list '(mlist) '((mlist)))))
36 ;; NOT CLEAR WHAT IS THE PROBLEM. SHOULD BE MORE EXPLICIT.
37 (merror (intl:gettext "desolve: can't handle this case.")))
38 (setq teqns (simplify ($first teqns)))
39 (unless (like flag t)
40 (setq teqns (simplify ($first teqns))))
41 (setq teqns
42 (simplify (map1 (getopr (m-tlambda&env (($z) (lvar ovar))
43 nil
44 (simplify ($ilt $z lvar ovar))))
45 teqns)))
46 (if (and flag (= ($length tvars) 1))
47 (maref teqns 1)
48 teqns)))