I want to define a function f
such that f[x]
is real whenever x
is real. So I define
f /: Re[f[x_]] /; Element[x, Reals] := f[x];
Now if I try Im[f[1]]
, it does not simplify. It does after adding another (redundant) rule:
f /: Im[f[x_]] /; Element[x, Reals] := 0;
However, the following still stay unevaluated (i.e. outer Im
or Re
are not removed) even after adding above two rules:
Re[f[1]^2] (** should output f[1]^2 **)
Re[f[2]/(1+f[f[1]])] (** should output f[2]/(1+f[f[1]]) **)
Refine[Re[f[x]^2], x \[Element] Reals] (** should output f[x]^2 **)
Im[Sin[f[0]]] (** should output 0 **)
Is there anyway to make the above four (and other similar ones) give out their desired output?
Observe that for a general symbolic x
, Refine[Re[Sin[x^2]], x \[Element] Reals]
is able to return Sin[x^2]
. Therefore I think there are more internal definitions associated to Sin
and Power
that make Refine
works, so perhaps achieving the above would be difficult solely via commands in System`
?
Refine[Im[f[x]], Element[x, Reals]]
andIm[f[x]]
still returns unevaluated with your rules (and this is expected). $\endgroup$