Re: Re: confused about asserting variable is
- To: mathgroup at smc.vnet.net
- Subject: [mg103224] Re: [mg103196] Re: [mg103084] confused about asserting variable is
- From: dushanm at spinn.net (Dushan Mitrovich)
- Date: Fri, 11 Sep 2009 05:24:35 -0400 (EDT)
Leonid Shifrin <lshifr at gmail.com> wrote:
> Dushan,
>
> Modifying global system variables globally is certainly an option, but it
> may lead to undesired effects if you forget about it and these variables
> are used in some places where the assigned assumptions should no longer
> hold. Here is an "intermediate" possibility: create a wrapper within
> which all computations will be performed with given assumptions
>
>
> ClearAll[computeUnderAssumptions];
> SetAttributes[computeUnderAssumptions, HoldFirst];
> computeUnderAssumptions[expr_, assumptions_List] :=
> Block[{$Assumptions = And[$Assumptions, Sequence @@ assumptions]},
> expr];
>
> Example:
>
> In[1] =
> computeUnderAssumptions[
> FullSimplify[Im[(a + I*b)^2]] +
> FullSimplify[Re[(a + I*c)^2],
> ComplexityFunction -> (Count[#, _Complex,
> Infinity] &)], {Element[{a, b, c}, Reals]}]
>
> Out[1] = 2 a b + (a - c) (a + c)
>
> In this case, the global value of $Assumptions does not change after the
> computation is complete, but it does change temporarily during the
> computation inside computeUnderAssumptions.
>
> Regards,
> Leonid
Leonid,
Thanks for this suggestion - it seems a useful alternative. I'll play
with it to get a feel of how it works.
- Dushan