block([simp:false],print(psubst([a=1,b=1],a+b)));
prints 2, while
block([simp:false],print(sublis([a=1,b=1],a+b)));
prints 1+1, as it should.
Here is a quick patch to fix this:
(defmfun $psubstitute (old new &optional (expr nil three-arg?)) (cond (three-arg? (maxima-substitute old new expr)) (t (let ((l old) (z new)) (cond ((and ($listp l) ($listp (cadr l)) (null (cddr l))) ;; A nested list. ($psubstitute (cadr l) z)) ((and ($listp l) (eq (caar (cadr l)) 'mequal) (null (cddr l))) ;; A list with one equation. ($psubstitute (cadr l) z)) ((notloreq l) (improper-arg-err l '$psubstitute)) ((eq (caar l) 'mequal) ;; Do a substitution for one equation. (maxima-substitute (caddr l) (cadr l) z)) (t ;; We have a list of equations. We do parallel substitution. (let (gensymbol genlist eqn (osimp $simp) ($simp nil)) ;; <<< ;; At first substitute a gensym for the expressions of ;; the left hand side of the equations. (do ((l (cdr l) (cdr l))) ((null l) z) (setq eqn (car l)) (when (not (eq 'mequal (caar eqn))) (improper-arg-err old '$substitute)) (setq gensymbol (gensym)) ;; Store the gensym and the new expression into a list. (push (cons gensymbol (caddr eqn)) genlist) ;; Substitute a gensym for the old expression. (setq z (maxima-substitute gensymbol (cadr eqn) z))) ;; Substitute the new expressions for the gensyms. (do ((l genlist (cdr l))) ((null l) ;; Resimplify the result. (let (($simp osimp)) (resimplify z))) ;; <<< (setq z (maxima-substitute (cdar l) (caar l) z))))))))))
I've noticed that psubst calls simplification directly, which subst does not. I think that's a bug in psubst; I think psubst should be consistent with other functions, which do not call simplification directly.
I probably noticed that in some pattern matching stuff. I think the main thing is that it's more nearly possible to predict what's going to happen to the extent that functions work consistently.
I've bumped into this before.
psubst
should honor the prevailing value of thesimp
flag -- I guess that is what the patched version is doing above.