# Redefine ArcCot to be inverse of range [0, Pi]

Mathematica implements ArcCot function as an inverse to Cot on range [-Pi/2, Pi/2]. I personally prefer the other definition (as it's used in courses I attend). Is it possible to redefine the function?

Current implementation:

My prefered implementation:

(images taken from http://intmstat.com/blog/2011/04/cotx_2.gif)

-
example of redefining a function, utilizing the original: forums.wolfram.com/mathgroup/archive/2013/Sep/msg00006.html – george2079 Dec 27 '13 at 13:31
@george2079 awesome, thanks, this completes the answers below. – Mikulas Dite Dec 27 '13 at 15:32

Long comment / warning..

http://stackoverflow.com/questions/4198961/what-is-in-your-mathematica-tool-bag/5149656#5149656

Which in this case is implemented as:

Unprotect[ArcCot];
ArcCot[args___ ] :=
Block[{$inAcot = True}, Mod[ArcCot[args], Pi]] /; ! TrueQ[$inAcot]
Protect[ArcCot]


And seems to work ..

{ArcCot[1], ArcCot[-1]} -> {Pi/4, 3 Pi /4}


However in some unexpected circumstances we fall back on the original..

GraphicsRow[{
ListPlot[Table[ {x, ArcCot[ x]} , {x, -5, 5, .2}], Joined -> True],
ListPlot[Table[ {x, ArcCot[ x]} , {x, -5, 5, .02}], Joined -> True],
Plot[ ArcCot[ x], {x, -5, 5}]}, PlotRange -> All]


Table[] uses the new definition in the first case and the original in the second.. go figure.

  First@Table[ {x, ArcCot[ x]} , {x, -1, 0, .01}]  -> {-1., 2.35619}
First@Table[ {x, ArcCot[ x]} , {x, -1, 0, .001}] -> {-1., -0.785398}


Same results with this:

 Unprotect[ArcCot];
ArcCot[args___ ] := Pi/2 - ArcTan[args];
Protect[ArcCot];


( 9.0.0.0 / windows..)

-
Falling back to the original behaviour is most probably due to auto-compilation, which uses the built in functions. This can be circumvented by using an additional Evaluate or in the case of Plot by the option Evaluated->True. – sebhofer Dec 28 '13 at 14:33
@sebhofer confirmed that does fix things. Still you need to wonder where else this issue might show up. – george2079 Dec 30 '13 at 19:25
It's well known that compilation does not use user defined rules for built in functions (at least for some of them, I'm not sure if it's true for all of them). On the other hand I don't think it's surprising that things like this happen when you redefine protected functions. An easy fix is to define your own... – sebhofer Dec 31 '13 at 9:24

You could use ArcTan[t, 1] instead of ArcCot[t]

-
Oh this is so easy it's awesome. Thanks :) – Mikulas Dite Dec 28 '13 at 14:25

Just take the result mode Pi?

  myArcCot[n_] := Mod[ArcCot[n], Pi]
N@myArcCot[-Pi/4]
(*2.23657007682325*)


And if you want, you can change the definition of ArcCot by removing the read protection on it and redfining it, but I would think making you own wrapper would be more safe.

-
Thanks, the issue though is that I can't manage to redefine the original function. Unprotect[ArcCot]; ArcCot[x_] := Mod[ArcCot[x], Pi] does not work for obvious reason. – Mikulas Dite Dec 26 '13 at 14:49
@MikulasDite, sure and that is why I said it is better to make a wrapper around it as I have shown above. – Nasser Dec 27 '13 at 6:39

Another possibility is

Block[{ArcCot = π/2 - ArcTan[#] &}, Plot[ArcCot[x], {x, -10, 10}]]


-