The name is still misleading. This is really "evaluate and resimplify with
assumptions", and *not* "simplify with assumptions".
I would suggest something like this:
/* internal programming version without convenience feature */
with_assumption_list (e, fcts) ::=
buildq ([e, fcts],
unwind_protect(
(apply ('supcontext, [?gensym ("cntxt")]),
apply ('assume, fcts),
e),
killcontext (context)))$
/* evaluate with assumptions */
with_assumptions(e,[fcts]) ::=
buildq([e,fcts],
with_assumption_list(e,fcts))$
/* resimplify with assumptions */
resimplify(e,[fcts]) := /* Note := NOT ::= */
if fcts=[]
then expand(e,0,0)
else with_assumption_list(expand(e,0,0),fcts)$
Examples:
with_assumptions changes the evaluation context:
(%i9) with_assumptions(integrate(x^a,x),not equal(a,-1));
(%o9) x^(a+1)/(a+1) <<< takes assumptions into account in evaluating
the integral
(%i10) foo:abs(x)$
(%i11) resimplify(foo,x<0);
(%o11) -x <<< resimplifies the expression abs(x)
(%i12) with_assumptions(foo,x<0);
(%o12) abs(x) <<< evaluating 'foo' in that context doesn't resimplify
the result
(%i13) resimplify(integrate(x^a,x),not equal(a,-1));
Is a+1 zero or nonzero? <<< expression is not
evaluated in the assumption context
n;
(%o13) x^(a+1)/(a+1)
An evaluate-and-resimplify function combines two different concepts -- but
it might be easier to use for new users, so perhaps with_assumptions should
do an implicit resimplify....
-s
On Fri, Mar 16, 2012 at 01:56, Robert Dodier <robert.dodier at gmail.com>wrote:
> Well, fwiw here's another attempt at simp_assuming ...
>
> simp_assuming (e, [fcts])::=buildq ([e, fcts],
> unwind_protect ((apply (supcontext, ?gensym ("cntxt")]),
> apply (assume, fcts),
> expand (e, 0, 0)),
> killcontext (context)));
>
> (killcontext(context) kills the current context whatever it is,
> so it isn't necessary to remember the gensym.)
>
> Does that work any better?
>
> best
>
> Robert Dodier
>