(1) The assignment farg : ++ 1 simply does farg : 1. Did you expect something else?
(2) The assignment farg : farg can be deleted.
(3) Isn't q zero when farg isn't greater than zero? Thus I think
if farg>0 then funmake(f, inverse_additive(q,f))+r else q+r
Could be simply
if farg>0 then funmake(f, inverse_additive(q,f))+r else q
(4) Instead of making listarith true for the entire body of the lambda form, you could make listarith : true
only while doing q : q + lx.
Thus
inverse_additive(e,f) :=
subst("+" =
lambda([[l]],
block([q : 0, lx, r : 0, farg : 0],
for lx in l do (
if not mapatom(lx) and op(lx)=f then (farg : 1,q : block([listarith : true], q + args(lx))) else r : r+lx),
if farg>0 then funmake(f, inverse_additive(q,f))+r else q+r)),
e)$
With this code:
(%i6) inverse_additive([a]+[b],'f),listarith : false;
(%o6) [b]+[a]
--Barton
________________________________
I changed "farg".
inverse_additive(e,f) :=
subst("+" =
lambda([[l]],
block([listarith : true, q : 0, lx, r:0,farg : 0],
for lx in l do (
if not mapatom(lx) and op(lx)=f then (farg : ++1,lx : args(lx),q : q +lx) else (r:r+lx,farg : farg)
),
if farg>0 then funmake(f, inverse_additive(q,f))+r else q+r
)
),
e)$
Part Marty