Re: Re: confused about asserting variable is
- To: mathgroup at smc.vnet.net
- Subject: [mg103245] Re: [mg103196] Re: [mg103084] confused about asserting variable is
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Fri, 11 Sep 2009 05:28:26 -0400 (EDT)
- References: <200909101121.HAA18052@smc.vnet.net>
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 On Thu, Sep 10, 2009 at 3:21 PM, Dushan Mitrovich <dushanm at spinn.net> wrote: > Many thanks to all who replied. Bob Hanlon's several alternative usages > were particularly informative. The one I was most interested in, also > suggested by Dan Litchblau: > > $Assumptions = Element[a, Reals]; > or > $Assumptions = $Assumptions && Element[a, Reals]; > > > Leonid Shifrin notes that > > In some hypothetical procedural language the statement Element[a, Reals] > would only make sense if it globally assigns <a> a property of being > real. > > In fact, this is precisely what I want: an instruction telling Mathematica > that, within the scope of that particular Notebook and absent user instruc- > tions to the contrary, it is to assume in all procedures that the specified > variable is real. In particular, I don't want to have to re-specify that > property every time I perform an operation, as suggested below: > > In Mathematica, everything is an expression, and most expressions don't > introduce side effects (global changes). When you enter Element[a, > Reals], this by itself does nothing. It does not, in particular, change > any global property of symbol <a>. However, this expression can be used > in commands like Simplify, FullSimplify, etc., to give them the informa- > tion that <a> should be considered real (in that particular computation) > > > I did initially refer to the UsingAssociations.html article, where I found > this description, > > x \[Element\ dom or Element[x,dom] assert that x is an element > of the domain dom > > This seemed like a straightforward statement of what I wanted to do, so > that's what I tried. The problem is that I thought it was an instruction > that applied globally to that Notebook. Now I've learned better. > > Thanks for all the help and education. > > - Dushan > > >
- References:
- Re: confused about asserting variable is element of
- From: dushanm@spinn.net (Dushan Mitrovich)
- Re: confused about asserting variable is element of