• + 0 comments

    In deriving tan(n * alpha) we can use tangent identity recursively until it reaches tan(alpha).

    tan(alpha + beta)
    = [tan(alpha) + tan(beta)] / [1 - tan(alpha) * tan(beta)]
    

    The right hand side expanded recursively overflows. To avoid overflow we can ues modular division.

    (a / b) mod n
    = [(a mod n)(b^(−1) mod n)] mod n
    
    when the right hand side is defined
    (that is when b and n are coprime).
    

    To find modular multiplicative inverse of b modulo n, i.e. x below,

    bx ≡ 1 mod n
    
    or
    
    bx + ny = gcd(b, n) = 1
    

    use Extended Eucleadean Algorithm that finds quotients x and y in addition to gcd(b, n).