%mathpiper,def="Tan"

1 # TanMap( _n )_(Not(IsRationalOrNumber(n))) <-- ListToFunction({ToAtom("Tan"),n*Pi});
2 # TanMap( _n )_(n<0) <-- -TanMap(-n);
2 # TanMap( _n )_(n>1) <-- TanMap(Modulo(n,1));
4 # TanMap( _n )_(n>1/2) <-- -TanMap(1-n);

5 # TanMap( 0 ) <-- 0;
5 # TanMap( 1/6 ) <-- 1/3*Sqrt(3);
5 # TanMap( 1/4 ) <-- 1;
5 # TanMap( 1/3 ) <-- Sqrt(3);
5 # TanMap( 1/2 ) <-- Infinity;

10 # TanMap(_n) <-- ListToFunction({ToAtom("Tan"),n*Pi});




2 # Tan(x_IsNumber)_InNumericMode() <-- TanNum(x);
4 # Tan(ArcTan(_x))           <-- x;
4 # Tan(ArcSin(_x)) <-- x/Sqrt(1-x^2);
4 # Tan(ArcCos(_x)) <-- Sqrt(1-x^2)/x;
5 # Tan(- _x)_(Not IsConstant(x))                  <-- -Tan(x);
6 # (Tan(x_IsConstant))_(IsNegativeNumber(N(Eval(x))))   <-- -Tan(-x);

// must prevent it from looping
6 # Tan(Infinity) <-- Undefined;
6 # Tan(Undefined) <-- Undefined;

110 # Tan(Complex(_r,_i)) <-- Sin(Complex(r,i))/Cos(Complex(r,i));

200 # Tan(v_CanBeUni(Pi))_(Not(InNumericMode()) And Degree(v,Pi) < 2 And Coef(v,Pi,0) = 0) <--
      TanMap(Coef(v,Pi,1));

100 # Tan(_x)/Sin(_x) <-- (1/Cos(x));
100 # Tan(_x)*Cos(_x) <-- Sin(x);

Tan(xlist_IsList) <-- MapSingle("Tan",xlist);

%/mathpiper



%mathpiper_docs,name="Tan",categories="User Functions;Trigonometry (Symbolic)"
*CMD Tan --- trigonometric tangent function
*STD
*CALL
	Tan(x)

*PARMS

{x} -- argument to the function, in radians

*DESC

This function represents the trigonometric function tangent. MathPiper leaves 
expressions alone even if x is a number, trying to keep the result as 
exact as possible. The floating point approximations of these functions 
can be forced by using the {N} function.

MathPiper knows some trigonometric identities, so it can simplify to exact
results even if {N} is not used. This is the case, for instance,
when the argument is a multiple of $Pi$/6 or $Pi$/4.

These functions are threaded, meaning that if the argument {x} is a
list, the function is applied to all entries in the list.

*E.G.

In> Tan(1)
Result: Tan(1);
In> N(Tan(1),20)
Result: 1.5574077246549022305;
In> Tan(Pi/4)
Result: 1;

*SEE Sin, Cos, ArcSin, ArcCos, ArcTan, N, Pi
%/mathpiper_docs