randRange(-5, 5) randRange(-5, 5) randRange(-5, 5) randRangeNonZero(-5, 5) ANSWER_REAL * B_REAL - ANSWER_IMAG * B_IMAG ANSWER_REAL * B_IMAG + ANSWER_IMAG * B_REAL A_IMAG > 0 ? "+" : "-" B_REAL * B_REAL + B_IMAG * B_IMAG (A_REAL * B_REAL) + (A_IMAG * B_IMAG) (A_IMAG * B_REAL) - (A_REAL * B_IMAG) complexNumber(ANSWER_REAL, ANSWER_IMAG) complexNumber(A_REAL, A_IMAG) complexNumber(B_REAL, B_IMAG) -B_IMAG complexNumber(B_REAL, B_CONJUGATE_IMAG)

Divide the following complex numbers.

\qquad \dfrac{A_REP}{B_REP}

ANSWER_REAL + ANSWER_IMAGi

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} SIGN \dfrac{coefficient(abs(A_IMAG))i}{B_REP}

Factor out \dfrac 1i.

\qquad = \dfrac 1i \left( \dfrac{A_REAL}{B_IMAG} SIGN \dfrac{coefficient(abs(A_IMAG))i}{B_IMAG} \right)

\qquad = \dfrac 1i (complexNumber(-ANSWER_IMAG, ANSWER_REAL))

\qquad \dfrac 1i = \dfrac 1i \cdot \dfrac ii = \dfrac{1 \cdot i}{i \cdot i} = \dfrac{i}{-1} = -i

Substitute -i for \dfrac 1i:

\qquad \begin{eqnarray} &=& -i (complexNumber(-ANSWER_IMAG, ANSWER_REAL)) \\ &=& ANSWER_IMAGi + -ANSWER_REALi^2 \\ &=& ANSWER_REP \end{eqnarray}

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)} {negParens(B_REAL)^2 - (coefficient(B_IMAG)i)^2}

Evaluate the squares in the denominator and subtract them.

\qquad = \dfrac{(A_REP) \cdot (CONJUGATE)} {(B_REAL)^2 - (coefficient(B_IMAG)i)^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}

The denominator now doesn't contain any imaginary unit multiples, so it is a real number.

Note that when a complex number, a + bi is multiplied by its conjugate, the product is always a^2 + b^2.

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}

\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