anchor.diff:    "Delay simplification of a block of code"
     `(let ((bld-maxima::*delay* t))
        ,@body))
  +
  +(defun simplify-lisp-expr (lexpr &optional (simpfun '$ev))
  +  "Simplify a lisp expression using socket to Maxima"
  +  (let* ((mstring (lisp-to-maxima-string (princ-to-string lexpr)))
  +	 (lfuns (match-lisp-funs mstring))
  +	 (rfuns (loop for lfun in lfuns
  +		   collect (princ-to-string (gensym)))))
  +    (read-from-string
  +     (maxima-to-lisp-string
  +      (re-rename-lisp-funs
  +       (princ-to-string
  +	(second
  +	 (maxima-send-lisp
  +	  (format nil "(mfuncall '~a '~a)"
  +		  simpfun
  +		  (rename-lisp-funs mstring lfuns rfuns)))))
  +       lfuns rfuns)))))
  +
  +(defun simp (lexpr &optional (simpfun '$ev))
  +  "Simplify a lisp math expression using specified Maxima
  +simplification function. Just return the expression if *DELAY* is T."
  +  (if *delay* lexpr (simplify-lisp-expr lexpr simpfun)))
  +
  +(defun trigreduce (lexpr)
  +  (simp lexpr '$trigreduce))
  +
  +(defun trigexpand (lexpr)
  +  (simp lexpr '$trigexpand))
  +
  +(defun trigsimp (lexpr)
  +  (simp lexpr '$trigsimp))
  +
  +(defun trigrat (lexpr)
  +  (simp lexpr '$trigrat))
  
positive.code: (defvar *delay* nil "Check whether to defer evaluation")
  (defvar *maxima-binary* #+win32 "maxima.bat" #+unix "maxima")
  (defvar *maxima-init-expressions* nil)
  (defparameter *maxima-lisp-table*
    '((mplus +)
      (mminus -)
      (mtimes *)
      (mexpt expt)
      (mlist list)
  ;;    (mequal =) ; comparison operators not really useful with Maxima
  ;;    (mgreaterp >)
      (mabs abs)
      (rat /)
      (%sin sin)
      (%cos cos)
      (%tan tan)
  
negative.code: (defun maxima-to-lisp-string (maxima-string)
    "convert simplified maxima output string to lisp string"
    (let* ((*read-default-float-format* 'double-float)
  	 ;; fix Maxima output & replace RAT with ratios
  	 (lisp-string 
  	  (rat-string-to-ratio
  	   (princ-to-string (read-from-string maxima-string)))))
      (loop for (maxima lisp) in *maxima-lisp-table-string*
         do (setq lisp-string
  		(regex-replace-all (format nil "\\(~a( SIMP)?( RATSIMP)?\\)" maxima) lisp-string lisp)))
  