Divide the following complex numbers.
\qquad \dfrac{A_REP}{B_REP}
Since we're dividing by a single term, we can simply divide each term in the numerator separately.
\qquad \dfrac{A_REP}{B_REP} = \dfrac{A_REAL}{B_REP} A_IMAG > 0 ? "+" : "-" \dfrac{abs(A_IMAG) === 1 ? "" : abs(A_IMAG)i}{B_REP}
Simplifying the two terms gives ANSWER_REP.
Factor out a 1/i.
\dfrac{A_REAL}{B_REP} A_IMAG > 0 ? "+" : "-" \dfrac{abs(A_IMAG) === 1 ? "" : abs(A_IMAG)i}{B_REP} = \dfrac 1i \left( \dfrac{A_REAL}{B_IMAG} A_IMAG > 0 ? "+" : "-" \dfrac{abs(A_IMAG) === 1 ? "" : abs(A_IMAG)i}{B_IMAG} \right) = \dfrac 1i (complexNumber(-ANSWER_IMAG, ANSWER_REAL))
After simplification, 1/i is equal to -i, so we have:
\dfrac 1i (complexNumber(-ANSWER_IMAG, ANSWER_REAL)) = -i (complexNumber(-ANSWER_IMAG, ANSWER_REAL)) = ANSWER_IMAGi + -ANSWER_REALi^2 = ANSWER_REP
We can divide complex numbers by multiplying both numerator and denominator by the denominator's complex conjugate, which is \green{CONJUGATE}.
\qquad \dfrac{A_REP}{B_REP} =
\dfrac{A_REP}{B_REP} \cdot
\dfrac{\green{CONJUGATE}}{\green{CONJUGATE}}
We can simplify the denominator using the fact (a + b) \cdot (a - b) = a^2 - b^2.
\qquad \dfrac{(A_REP) \cdot (CONJUGATE)}
{(B_REP) \cdot (CONJUGATE)} =
\dfrac{(A_REP) \cdot (CONJUGATE)}
{negParens(B_REAL)^2 - (B_IMAGi)^2}
Evaluate the squares in the denominator and subtract them.
\qquad \dfrac{(A_REP) \cdot (CONJUGATE)}
{(B_REAL)^2 - (B_IMAGi)^2} =
\qquad \dfrac{(A_REP) \cdot (CONJUGATE)}
{B_REAL * B_REAL + B_IMAG * B_IMAG} =
\qquad \dfrac{(A_REP) \cdot (CONJUGATE)}
{B_REAL * B_REAL + B_IMAG * B_IMAG}
Note that the denominator now doesn't contain any imaginary unit multiples, so it is a real number, simplifying the problem to complex number multiplication.
Now, we can multiply out the two factors in the numerator.
\qquad \dfrac{(\blue{A_REP}) \cdot (\red{CONJUGATE})}
{DENOMINATOR} =
\qquad \dfrac{\blue{A_REAL} \cdot \red{negParens(B_REAL)} + \blue{A_IMAG} \cdot \red{negParens(B_REAL) i} + \blue{A_REAL} \cdot \red{B_CONJUGATE_IMAG i} + \blue{A_IMAG} \cdot \red{B_CONJUGATE_IMAG i^2}}
{DENOMINATOR}
Evaluate each product of two numbers.
\qquad \dfrac{A_REAL * B_REAL + A_IMAG * B_REALi + A_REAL * B_CONJUGATE_IMAGi + A_IMAG * B_CONJUGATE_IMAG i^2}
{DENOMINATOR}
Finally, simplify the fraction.
\qquad \dfrac{A_REAL * B_REAL + A_IMAG * B_REALi + A_REAL * B_CONJUGATE_IMAGi - A_IMAG * B_CONJUGATE_IMAG}
{DENOMINATOR} =
\dfrac{REAL_NUMERATOR + IMAG_NUMERATORi}
{DENOMINATOR} =
ANSWER_REP