1
$\begingroup$

Or put in another way, how to make a variable behave as it belongs to a specific domain, even outside the use of simplify or other commands alike?

For example:

Re[u] returns Re[u] because the kernel cannot tell upfront that u is real. Even after setting $Assumptions = u ∈ Reals, a call to Re[u] keeps returning Re[u]. A call to Re[u] // Simplify works.

But it would be simpler to make a variable behave always like assumed without the need to a call to Simplify. On the other hand a call to Re[π] returns π directly.

Is there a way to make variables behave like π does in the example above?

$\endgroup$
  • 1
    $\begingroup$ What you are proposing doesn't make a lot a sense in Mathematica, where variables are just symbols and don't have any facility for carrying meta data such as type information. How would your idea of strong assumptions handle a variable that was given the strong assumption of being an integer, when that variable was bound to a complex value with Set at a later time? $\endgroup$ – m_goldberg Feb 22 '15 at 1:53
  • $\begingroup$ Thank you for your interest and helpful insights. Well I certainly don't know how to answer that. But there is a point in that question I made. Even though Pi is a symbol, it behaves like a real. Is the symbol Pi a constant or a function to the kernel? How could I define a symbol of my own and tell the kernel my symbol belongs to a specified domain? $\endgroup$ – Leandro Feb 22 '15 at 2:42
2
$\begingroup$

Trivially, in this case you can use Re[x] ^= x. However, you can't use upvalues with expressions like Sqrt[Pi^2] (which evaluates to Pi).

You could use $Post and Refine, but it's sort of a hack.

$Post = Refine[#, x \[Element] Reals] &
Re[x] (* x *)
Sqrt[x^2] (* Abs[x] *)

Note that this system isn't very flexible. If you want to add another assumption, you need to reset $Post, remembering every previous assumption as well. Perhaps something like:

addAssumption[expr_] := ($Assumptions = $Assumptions && expr;
                         $Post = Refine[#, $Assumptions] &)

Again, this is sort of a hacky way to do it. I would recommend just using Simplify, Refine, or ComplexExpand where you need it instead.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.