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

How to force Mathematica to treat a number as positive and real?

1,672 views
Skip to first unread message

Rainer

unread,
Nov 3, 2004, 1:58:11 AM11/3/04
to
I'd like to do some symbolic computation with parameters. These
parameters (named, e.g. "a") are always *real-valued* and positive. I
managed to tell Mathematica that a is a real number by using:

a/:Im[a]=0;

This works since the response to "Re[a]" is now "a" (and not "Re[a]"
which is the general result when one does not use the above definition
of a).

Now, I would like to do a similar thing, forcing Mathematica to assume
that a is a positive number. I want that the result of Abs[a] is equal
to a. I tried:

a/:Positive[a]=True;

but it does not work. Does anybody know how I can do this?
Thanks
Rainer

Bob Hanlon

unread,
Nov 4, 2004, 2:18:21 AM11/4/04
to
Clear[a];
a /: Abs[a]=a;

Abs[a]

a

However, trying to specify all desired results with upvalues (TagSet) can easily
lead to recursion problems. It is easier to just use an assumption with
Simplify or FullSimplify.

Clear[a];

Simplify[
{Re[a], Im[a], Abs[a], a>0, a<0, Sqrt[a^2]},
a>0]

{a,0,a,True,False,a}


Bob Hanlon

Andrzej Kozlowski

unread,
Nov 4, 2004, 2:19:22 AM11/4/04
to

On 3 Nov 2004, at 15:24, Rainer wrote:

> I'd like to do some symbolic computation with parameters. These
> parameters (named, e.g. "a") are always *real-valued* and positive. I
> managed to tell Mathematica that a is a real number by using:
>
> a/:Im[a]=0;
>
> This works since the response to "Re[a]" is now "a" (and not "Re[a]"
> which is the general result when one does not use the above definition
> of a).
>
> Now, I would like to do a similar thing, forcing Mathematica to assume
> that a is a positive number. I want that the result of Abs[a] is equal
> to a. I tried:
>
> a/:Positive[a]=True;
>
> but it does not work. Does anybody know how I can do this?
> Thanks
> Rainer
>
>

Assuming you have Mathematica 5.0 you should use Refine and the
Assumptions mechanism. You can even do it in a "global" way, as folows:

This tells Mathematica to Refine every statement using the current
assumptions:

$Pre = Refine[#] &;

Next, define the assumptions:

$Assumptions = {a ł 0};

Now


Abs[a]

a


Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/

David Bailey

unread,
Nov 4, 2004, 2:25:27 AM11/4/04
to
You can use the Assumptions option in Simplify and FullSimplify to
specify that a number belongs to a particular field - Reals in your case
- and also to supply additional information, e.g.


Simplify[{Abs[a], Re[a]}, Assumptions ->
{a ∈ Reals, a >= 0}]

{a,a}

You might find it convenient to define your own simplification function
with the necessary assumptions built in:

MySimplify[x_] := Simplify[x, Assumptions -> {a ∈ Reals, a ≥ 0}]

{Abs[a], Re[a], Min[a, 0]} // MySimplify

{a, a, 0}

David Bailey

Steve Luttrell

unread,
Nov 4, 2004, 2:33:35 AM11/4/04
to
This works:

Simplify[Abs[a],a>0]

and this does too:

Assuming[a>0,Simplify[Abs[a]]]

Have a look at the Help Browser for more information on Assuming.

Steve Luttrell

"Rainer" <wilhelm...@gmx.net> wrote in message
news:cm9vi3$8nc$1...@smc.vnet.net...

David Bailey

unread,
Nov 5, 2004, 2:43:43 AM11/5/04
to
Sorry, I notice that a special character in my reply has got scrambled
in the email.
The character in question is the one you obtain by typing \[Element]

So, for example I meant to write:

Simplify[{Abs[a], Re[a]}, Assumptions ->

{a \[Element] Reals, a >= 0}]

David Bailey

0 new messages