;; If x is a symbol for a subvarp, return its general representation.
;; Otherwise signal an error---the argument f is the string name of
;; a function that requires the symbol.
(defun require-symbol (x f)
(setq x ($ratdisrep x))
(if (or (symbolp x) ($subvarp x)) x
(merror "Function ~:M requires a symbol; instead found ~:M" f x)))
;; Map require-symbol over the Maxima list x. When each member of x
;; is a symbol, return (margs x).
(defun require-mlist-of-symbols (x f)
(cond (($listp x) (mapcar #'(lambda (s) (require-symbol s f)) (margs x)))
(t `(,(require-symbol x f)))))
;; Map the function f onto a mbag and simplify the result. When the
;; bag is an equality, list, or matrix, simplification isn't needed;
;; however, new types of bags (say sets) may need simplification after
;; the mapping.
;; Maxima is hit-or-miss about mapping functions over mbags. I suggest
;; we develop that a function similar to this one and that we use it
;; everywhere a function is mapped over a mbag.
;; If the arguments of bag are in CRE form, margs changes them to general
;; form---and mbag-map may return an expression in general form. Maybe this
;; behavior is impolite?
(defun mbag-map (f bag)
(simplify `((,(mop bag)) ,@(mapcar f (margs bag)))))
;; Maxima allows members of ratvars to be nonsymbols, but sqrf
;; doesn't tolerate this. I don't know why Maxima allows
;; nonsymbols to be ratvars.
;; (C1) load("mysqrfr.lisp");
;;
;; (D2) mysqrfr.lisp
;; (C3) ratvars(a