Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Persistent assumption

2 views
Skip to first unread message

Sam Takoy

unread,
Dec 30, 2009, 4:18:17 AM12/30/09
to
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

Leonid Shifrin

unread,
Dec 31, 2009, 3:17:33 AM12/31/09
to
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

Bob Hanlon

unread,
Dec 31, 2009, 3:20:08 AM12/31/09
to

$Assumptions = {x > 0};

Simplify[Sqrt /@ {x^2, y^2}]

{x, Sqrt[y^2]}

$Assumptions =.


Bob Hanlon

---- Sam Takoy <samt...@yahoo.com> wrote:

=============

0 new messages