TRIG_TR5

This transformation rewrites powers of sine into expressions involving cosine.

The base identity is:

\sin^2(x)=1-\cos^2(x)

It can be applied to higher even powers and controlled with maximum power and power-handling options.

Excel Usage

=TRIG_TR5(expression, max_power, use_pow)
  • expression (str, required): Expression containing sine powers to rewrite (expression string).
  • max_power (int, optional, default: 4): Maximum exponent power to target for rewriting (count).
  • use_pow (bool, optional, default: false): Apply power-focused behavior where supported (true/false).

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

Example 1: Rewrites sine squared identity

Inputs:

expression
sin(x)^2

Excel formula:

=TRIG_TR5("sin(x)^2")

Expected output:

"1 - cos(x)**2"

Example 2: Rewrites sine to the fourth power

Inputs:

expression
sin(x)^4

Excel formula:

=TRIG_TR5("sin(x)^4")

Expected output:

"(1 - cos(x)**2)**2"

Example 3: Uses custom maximum power threshold

Inputs:

expression max_power
sin(x)^6 6

Excel formula:

=TRIG_TR5("sin(x)^6", 6)

Expected output:

"(1 - cos(x)**2)**3"

Example 4: Rewrites sine powers inside a larger expression

Inputs:

expression
sin(x)^2 + sin(y)^2

Excel formula:

=TRIG_TR5("sin(x)^2 + sin(y)^2")

Expected output:

"-cos(x)**2 - cos(y)**2 + 2"

Python Code

from sympy import sympify
from sympy.simplify.fu import TR5 as sympy_tr5

def trig_tr5(expression, max_power=4, use_pow=False):
    """
    Replace even powers of sine using a cosine-based identity.

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

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

    Args:
        expression (str): Expression containing sine powers to rewrite (expression string).
        max_power (int, optional): Maximum exponent power to target for rewriting (count). Default is 4.
        use_pow (bool, optional): Apply power-focused behavior where supported (true/false). Default is False.

    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_tr5(expr_obj, max=max_power, pow=use_pow)
        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Expression containing sine powers to rewrite (expression string).
Maximum exponent power to target for rewriting (count).
Apply power-focused behavior where supported (true/false).