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
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
> 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/
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
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...
So, for example I meant to write:
Simplify[{Abs[a], Re[a]}, Assumptions ->
{a \[Element] Reals, a >= 0}]
David Bailey