let(simp) behaves different when loaded from batch file
Subject: let(simp) behaves different when loaded from batch file
From: Robert Dodier
Date: Sun, 23 Dec 2012 23:24:32 +0000 (UTC)
On 2012-12-23, NB <nijso at hotmail.com> wrote:
> The code below gives different results when run from the command line or when
> loaded using the 'batch' or 'load' command.
> When I run from the command line, the let rule is applied and the result of
> letsimp is '5'. When run from batch, the result is ?%at('diff(f(x),x,1),[x
>=0])
>
> The code below should simplify df(x)/dx to 5 when x=0
>
> test() := block([expr,F],
> expr : diff(f(x), x),
> F(xx) := at(expr, [x = xx]),
> let(at(diff(f(x),x),[x=0]),5),
> letsimp(F(0))
> )$
Well, the problem is that reading the function from a script introduces
debugging data, which confuses letsimp. (Line numbers and file names are
smashed into the same Lisp object which holds the operator of an
expression, which can be distracting if one is looking at operators or
operator flags.) After stripping out the debugging stuff, I find that
the function works as expected. I didn't look too hard to see exactly
where the problem is in src/nisimp.lisp.
If the goal is to carry out just that substitution, maybe you want
'atvalue'. Or maybe tellsimp/tellsimpafter/defrule/defmatch.
best
Robert Dodier
PS. Here is a function to strip debugging stuff from a Maxima function.
;; rm_lineinfo -- remove debugging stuff from a Maxima function
;; copyright 2012 by Robert Dodier
;; I release this work under terms of the GNU GPL.
(defun $rm_lineinfo (fn-name)
(let ((fn-defn (mget fn-name 'mexpr)))
(setf (mget fn-name 'mexpr) (rm-lineinfo-1 fn-defn))))
(defun rm-lineinfo-1 (expr)
(if (atom expr)
expr
(cons (rm-lineinfo-2 (car expr)) (mapcar #'rm-lineinfo-1 (cdr expr)))))
(defun rm-lineinfo-2 (maxima-op)
(remove-if #'(lambda (x) (and (consp x) (integerp (car x)))) maxima-op))