4
$\begingroup$

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?

$\endgroup$
5
  • 3
    $\begingroup$ Why positive infinity? Why not DirectedInfinity[-1]? For ArcTan, why not -Pi/2? $\endgroup$
    – Michael E2
    Jan 28, 2021 at 23:23
  • $\begingroup$ Actually yeah I would like it to be positive or negative infinity depending on sign of n. $\endgroup$
    – user824530
    Jan 29, 2021 at 5:13
  • 1
    $\begingroup$ $\frac{4}{0} = {\infty}_{+}$ when $`` 0 "$ is infinitesimally positive ("positive zero"), but not when it's infinitesimally negative ("negative zero") nor perfectly zero (integer-zero). So it'd seem like, for this to be a correct result, you'd need to clarify what $`` 0 "$ means in that expression. $\endgroup$
    – Nat
    Jan 29, 2021 at 19:35
  • 1
    $\begingroup$ @Nat, this is where it'd have been nice to have a "signed zero" like in IEEE's model, but alas... $\endgroup$ Jan 30, 2021 at 2:04
  • 1
    $\begingroup$ @user, then you should indeed be using two-argument arctangent in the first place. $\endgroup$ Jan 30, 2021 at 2:05

3 Answers 3

4
$\begingroup$

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  *)
$\endgroup$
1
  • $\begingroup$ Perfect. Thank you! $\endgroup$
    – user824530
    Jan 29, 2021 at 5:11
22
$\begingroup$

Use the two-arg version of ArcTan instead:

ArcTan[0, 4]

π/2

$\endgroup$
1
  • 5
    $\begingroup$ ...and if you also need to evaluate at 0, 0, you could use Arg[x + I y] instead. $\endgroup$ Jan 29, 2021 at 1:15
6
$\begingroup$

You can convert expressions of ComplexInfinity to Infinity by using the ReplaceAll operator /..

ArcTan[4/0 /. ComplexInfinity -> Infinity]

which gives Pi/2 as output.

$\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.