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

Re: confused about asserting variable is element of

92 views
Skip to first unread message

Bob Hanlon

unread,
Sep 8, 2009, 5:53:38 AM9/8/09
to

funcs = {Simplify, FullSimplify, Refine};

Use Assuming

Assuming[{Element[a, Reals]},
#[Im[a]]] & /@ funcs

{0,0,0}

Use the Assumptions option

#[Im[a], Assumptions ->
Element[a, Reals]] & /@ funcs

{0,0,0}

Use the Assumptions option short form

#[Im[a], Element[a, Reals]] & /@ funcs

{0,0,0}

Or add your assumption to $Assumptions

$Assumptions = Element[a, Reals];

#[Im[a]] & /@ funcs

{0,0,0}


Bob Hanlon

---- dushan <dus...@spinn.net> wrote:

=============
I'm still learning Mathematica (using 7.0.1) and don't understand
Mathematica's response. After finally finding out how to assert that a
variable is real, I tried to verify this by asking Mathematica to show me that
it knew the imaginary part of the variable is zero. But I couldn't
find a way to do that.. Here're my instructions:

In[1]:= a (ESC)el(ESC) Reals
Out[1]:= a (the element-of symbol) Reals

In[2]:= ##Im[a]
Out[2]:= Im[a]

where '##' is any of {null, Refine[, Simplify[, FullSimplify[}. I
also tried some other combinations, such as 'a^2 - Re[a]^2', but these
didn't help either.

What am I doing wrong? How do I verify such things?

Thanks.

- Dushan Mitrovich

Patrick Scheibe

unread,
Sep 8, 2009, 6:00:01 AM9/8/09
to
Hi,

you have to state that Mathematica should use your assumption

Assuming[a \[Element] Reals, Simplify[Im[a]]]

Maybe you should have a look at the help of the global variable
$Assumptions

Cheers
Patrick

Leonid Shifrin

unread,
Sep 8, 2009, 6:00:23 AM9/8/09
to
Dushan,

you got confused due to your probably procedural programming background.
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 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 information
that <a> should be considered real (in that particular
computation):

In[1] =
ClearAll[a];
Simplify[Im[a], Assumptions -> Element[a, Reals]]

Out[1] = 0

Regards,
Leonid

AES

unread,
Sep 9, 2009, 4:34:46 AM9/9/09
to
In article <h859vn$q48$1...@smc.vnet.net>,
Leonid Shifrin <lsh...@gmail.com> wrote:

> 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 information
> that <a> should be considered real (in that particular computation):

So, could one ever write Assumptions -> Element[I, Reals] in any of
those commands?

Leonid Shifrin

unread,
Sep 10, 2009, 7:16:11 AM9/10/09
to
I don't find anything wrong here:

In[1]:= Simplify[Re[I + 1], Assumptions -> Element[I, Reals]]

During evaluation of In[1]:= Simplify::fas: Warning: One or more assumptions
evaluated to False. >>

Out[1]= 1


On Wed, Sep 9, 2009 at 12:42 PM, AES <sie...@stanford.edu> wrote:

> In article <h859vn$q48$1...@smc.vnet.net>,
> Leonid Shifrin <lsh...@gmail.com> wrote:
>

> > 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 information
> > that <a> should be considered real (in that particular computation):
>

Daniel Lichtblau

unread,
Sep 10, 2009, 7:18:11 AM9/10/09
to
AES wrote:
> In article <h859vn$q48$1...@smc.vnet.net>,
> Leonid Shifrin <lsh...@gmail.com> wrote:
>
>> 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 information
>> that <a> should be considered real (in that particular computation):
>
> So, could one ever write Assumptions -> Element[I, Reals] in any of
> those commands?

Of course one can. Look, I'll do it below.

In[13]:= Simplify[Re[I*x], Assumptions->Element[I, Reals]]

Simplify::fas: Warning: One or more assumptions evaluated to False.

Out[13]= 0

Some people refer to this as GIGO. I am partial to the phrase "You get
what you get".

Daniel Lichtblau
Wolfram Research

Dushan Mitrovich

unread,
Sep 10, 2009, 7:21:10 AM9/10/09
to
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


Bob Hanlon

unread,
Sep 10, 2009, 7:22:37 AM9/10/09
to

It wouldn't have any effect. It just evaluates to False

Element[I, Reals]

False

Simplify[Re[I], Element[I, Reals]]

Simplify::fas: Warning: One or more assumptions evaluated to False. >>

0

Simplify[Im[I], Element[I, Reals]]

Simplify::fas: Warning: One or more assumptions evaluated to False. >>

1


Bob Hanlon

---- AES <sie...@stanford.edu> wrote:

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


In article <h859vn$q48$1...@smc.vnet.net>,
Leonid Shifrin <lsh...@gmail.com> wrote:

> 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

Szabolcs Horvát

unread,
Sep 10, 2009, 7:24:28 AM9/10/09
to

Element[I,Reals] automatically evaluates to False.

Peter Breitfeld

unread,
Sep 11, 2009, 5:24:07 AM9/11/09
to

If you want that the variable x to be treated (like) a real Variable,
you may give UpValue to it:

x/: Re[x]:=x
x/: Im[x]:=0
x/: Conjugate[x]:=x

Then you will get:

In[1]:= Clear[u, v, y]; Re[u+I x]
Out[1]= Re[u]

In[2]:= Im[u I +x]
Out[2]= Re[u]


Dushan Mitrovich wrote:

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

0 new messages