TRIG_TR6

This transformation rewrites powers of cosine into expressions involving sine.

The base identity is:

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

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

Excel Usage

=TRIG_TR6(expression, max_power, use_pow)
  • expression (str, required): Expression containing cosine 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 cosine squared identity

Inputs:

expression
cos(x)^2

Excel formula:

=TRIG_TR6("cos(x)^2")

Expected output:

"1 - sin(x)**2"

Example 2: Rewrites cosine to the fourth power

Inputs:

expression
cos(x)^4

Excel formula:

=TRIG_TR6("cos(x)^4")

Expected output:

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

Example 3: Uses custom maximum power threshold

Inputs:

expression max_power
cos(x)^6 6

Excel formula:

=TRIG_TR6("cos(x)^6", 6)

Expected output:

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

Example 4: Rewrites cosine powers inside a larger expression

Inputs:

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

Excel formula:

=TRIG_TR6("cos(x)^2 + cos(y)^2")

Expected output:

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

Python Code

from sympy import sympify
from sympy.simplify.fu import TR6 as sympy_tr6

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

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

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

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

Online Calculator

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