Alejandro Vizcarra wrote:
> I always have problems when dealing with complex numbers. How can i
> work with Mathematica in such a way that every expression will
> be considered real unless it is declared explicitly complex (like a = 3 +
> 4 I ) ?
The best recommendation that I can make is to routinely simplify expressions
using something like:
In := assume = Im[a] == 0 && Im[b] == 0;
In := FullSimplify[-Im[Sin[a + b]] + Re[Cos[a + b]], assume]
Out := Cos[a + b]
But this requires FullSimplify rather than Simplify and FullSimplify is very
time consuming on large expressions.
An alternative is to define up-values associated with the variables to
declare that their real parts are themselves and their imaginary parts are
zero, rather than keeping and passing my "assume" variable around:
In := Re[a] ^= a; Im[a] ^= 0; Re[b] ^= b; Im[b] ^= 0;
In := FullSimplify[-Im[Sin[a + b]] + Re[Cos[a + b]]]
Out := Cos[a + b]
But I have a hunch that this won't be as powerful at simplifying the
expressions as the "assume" approach.
I do not know of any way to manifestly declare something as being
real-valued. I believe this would be a bad idea anyway, as the current
method enforces mathematical rigour. Whilst checking a proof for my PhD
thesis, for example, Mathematica's pedantry led me to make two of my
assumptions explicit. Although the assumptions may have been "obvious" to a
human reader, it can be nice to have that kind of pedantry. :)
HTH.
Cheers,
Jon.