Re: Persistent assumption
- To: mathgroup at smc.vnet.net
- Subject: [mg106057] Re: [mg106019] Persistent assumption
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Thu, 31 Dec 2009 03:17:56 -0500 (EST)
- References: <200912300915.EAA17336@smc.vnet.net>
Sam, you can use the global variable $Assumptions - in particular, temporarily redefine it as a logical And of what it is currently and the conditions you wish to hold for your block of code. Here is one possible way to do this using Block (reprinting from one of the past threads where a similar question was asked) 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) Hope this helps. Regards, Leonid On Wed, Dec 30, 2009 at 1:15 AM, Sam Takoy <samtakoy at yahoo.com> wrote: > Hi, > > Is it possible to make an Assumption for the duration of a block of > code? In other words, to say "In all of the following code, Assume[x>0]". > > I appreciate that it is possible to use, > > Assuming[x>0, > > a whole lot of code > > ] > > but that's quite awkward. Looking for a better alternative. > > Thanks, > > Sam > >
- References:
- Persistent assumption
- From: Sam Takoy <samtakoy@yahoo.com>
- Persistent assumption