TRIG_TR2

This transformation replaces tangent and cotangent with explicit sine/cosine ratios.

It uses:

\tan(x)=\frac{\sin(x)}{\cos(x)},\quad \cot(x)=\frac{\cos(x)}{\sin(x)}

Converting to a common basis helps later algebraic simplification.

Excel Usage

=TRIG_TR2(expression)
  • expression (str, required): Expression containing tan and cot terms (expression string).

Returns (str): Transformed expression as a string, or an error message.

Example 1: Rewrites tangent as sine over cosine

Inputs:

expression
tan(x)

Excel formula:

=TRIG_TR2("tan(x)")

Expected output:

"sin(x)/cos(x)"

Example 2: Rewrites cotangent as cosine over sine

Inputs:

expression
cot(x)

Excel formula:

=TRIG_TR2("cot(x)")

Expected output:

"cos(x)/sin(x)"

Example 3: Simplifies nested tangent ratio structure

Inputs:

expression
tan(tan(x) - sin(x)/cos(x))

Excel formula:

=TRIG_TR2("tan(tan(x) - sin(x)/cos(x))")

Expected output:

"0"

Example 4: Rewrites mixed tangent and cotangent expression

Inputs:

expression
tan(a) + cot(b)

Excel formula:

=TRIG_TR2("tan(a) + cot(b)")

Expected output:

"sin(a)/cos(a) + cos(b)/sin(b)"

Python Code

from sympy import sympify
from sympy.simplify.fu import TR2 as sympy_tr2

def trig_tr2(expression):
    """
    Rewrite tangent and cotangent into sine-cosine ratio forms.

    See: https://docs.sympy.org/latest/modules/simplify/fu.html#sympy.simplify.fu.TR2

    This example function is provided as-is without any representation of accuracy.

    Args:
        expression (str): Expression containing tan and cot terms (expression string).

    Returns:
        str: Transformed expression as a string, or an error message.
    """
    try:
        expr_text = expression.replace("^", "**") if isinstance(expression, str) else expression
        expr_obj = sympify(expr_text)
        result = sympy_tr2(expr_obj)
        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Expression containing tan and cot terms (expression string).