def _minpoly_tan(ex, x):
    'Returns the minimal polynomial of ``tan(ex)``.'
    (c, a) = ex.args[0].as_coeff_Mul()
    if ((a is pi) and c.is_Rational):
        c *= 2
        n = c.denominator
        a = (n if ((c.numerator % 2) == 0) else 1)
        terms = []
        for k in range(((c.numerator + 1) % 2), (n + 1), 2):
            terms.append((a * (x ** k)))
            a = ((- ((a * ((n - k) - 1)) * (n - k))) // ((k + 1) * (k + 2)))
        r = Add(*terms)
        (_, factors) = factor_list(r)
        return _choose_factor(factors, x, ex)
    raise NotAlgebraic(f"{ex} doesn't seem to be an algebraic element")
Returns the minimal polynomial of ``tan(ex)``.
def _minpoly_tan(ex, x):
    
    (c, a) = ex.args[0].as_coeff_Mul()
    if ((a is pi) and c.is_Rational):
        c *= 2
        n = c.denominator
        a = (n if ((c.numerator % 2) == 0) else 1)
        terms = []
        for k in range(((c.numerator + 1) % 2), (n + 1), 2):
            terms.append((a * (x ** k)))
            a = ((- ((a * ((n - k) - 1)) * (n - k))) // ((k + 1) * (k + 2)))
        r = Add(*terms)
        (_, factors) = factor_list(r)
        return _choose_factor(factors, x, ex)
    raise NotAlgebraic(f"{ex} doesn't seem to be an algebraic element")