I would like Mathematica to print $\arctan(4/0)$ as $\frac{\pi}{2}$ but it does not because in mathematica 1/0 is complexinfinity. How do I make it print n/0 as Infinity so that Arctan will give me what I want?
3 Answers
On the off chance that what is desired in a computational environment in which n/0
evaluates to (positive) Infinity
and t = ArcTan[..]
falls in the range -Pi/2 <= t <= Pi/2
. One should use caution when overwriting built-in functions. I doubt this will cause problems in computations in which n/0
should always mean positive Infinity
and not ComplexInfinity
.
ClearAll[evaluateWithRealPower];
SetAttributes[evaluateWithRealPower, HoldFirst];
evaluateWithRealPower[code_] :=
Internal`InheritedBlock[{Power},
Unprotect[Power];
Power[0, p_?Negative] := Infinity;
Power[0., p_?Negative] := Infinity; (* optional *)
Protect[Power];
code];
evaluateWithRealPower[ArcTan[4/0]]
(* \[Pi]/2 *)
-
5$\begingroup$ ...and if you also need to evaluate at
0, 0
, you could useArg[x + I y]
instead. $\endgroup$ Jan 29, 2021 at 1:15
You can convert expressions of ComplexInfinity
to Infinity
by using the ReplaceAll
operator /.
.
ArcTan[4/0 /. ComplexInfinity -> Infinity]
which gives Pi/2
as output.
DirectedInfinity[-1]
? ForArcTan
, why not-Pi/2
? $\endgroup$