<jupyter_start><jupyter_text>Complex Numbers<jupyter_code>import cmath
from pydash import py_ as _<jupyter_output><empty_output><jupyter_text>IdentityA complex number is the combination of a real number, and an imaginary number.The imaginary number is<jupyter_code>cmath.sqrt(-1)
type(cmath.sqrt(-1))
A = complex(1.0, 2.0); 
B = complex(3.0, 4.0); 
C = complex(-5.0, -6.0);
[A, B, C]<jupyter_output><empty_output><jupyter_text>Polar Coordinates<jupyter_code>{
    "A": [A, cmath.polar(A), [abs(A), cmath.phase(A)]],
    "B": [B, cmath.polar(B), [abs(B), cmath.phase(B)]],
    "C": [C, cmath.polar(C), [abs(C), cmath.phase(C)]],
}<jupyter_output><empty_output><jupyter_text>Powers The imaginary number multiplied by itself is -1<jupyter_code>cmath.sqrt(-1) * cmath.sqrt(-1)<jupyter_output><empty_output><jupyter_text>Higher powers form the points of a complex circle<jupyter_code>[ "i^%d == %s" % (x, cmath.sqrt(-1)**x) for x in range(1,9) ]<jupyter_output><empty_output><jupyter_text>Addition Add the real and imaginary parts<jupyter_code>A + B
(A.real + A.imag*1j) + (B.real + B.imag*1j)
A + B == (A.real + A.imag*1j) + (B.real + B.imag*1j)<jupyter_output><empty_output><jupyter_text>Subtraction Subtract the real and imaginary parts<jupyter_code>A - B
(A.real + A.imag*1j) - (B.real + B.imag*1j)
A - B == (A.real + A.imag*1j) - (B.real + B.imag*1j) == A.real - B.real + A.imag*1j - B.imag*1j
A - (B - C) == (A - B) + C<jupyter_output><empty_output><jupyter_text>Multiplication  Cartisian Multiplication (A1 + A2i) x (B1 + B2i) = (A1 B2 - A1 B2) + (A2 B1+ B1 A2)i<jupyter_code>A * B
((A.real * B.real) - (A.imag * B.imag)) + ((A.real * B.imag) + (A.imag * B.real))*1j
A * B == ((A.real * B.real) - (A.imag * B.imag)) + ((A.real * B.imag) + (A.imag * B.real))*1j
A * B == B * A
A * (B * C) == (A * B) * C<jupyter_output><empty_output><jupyter_text>Polar MultiplicationA * B = (|A|\*|B|)r + (Aφ * Bφ)φ<jupyter_code>A * B, cmath.polar(A*B)
cmath.polar(A*B) == (abs(A)*abs(B), cmath.phase(A)+cmath.phase(B))<jupyter_output><empty_output><jupyter_text>Division  Cartisian Multiplication<jupyter_code>A / B
( ((A.real * B.real) + (A.imag * B.imag)) - ((A.real * B.imag) - (B.real * A.imag))*1j ) / ( B.real**2 + B.imag**2 )
(A / B) == (( ((A.real * B.real) + (A.imag * B.imag)) - ((A.real * B.imag) - (A.imag * B.real))*1j ) / ( B.real**2 + B.imag**2 ))<jupyter_output><empty_output><jupyter_text>Polar DivisionA / B = (|A|/|B|)r + (Aφ - Bφ)φNOTE: small floating point rounding error<jupyter_code>A / B, cmath.polar(A/B)
cmath.polar(A/B), \
(abs(A)/abs(B), cmath.phase(A)-cmath.phase(B))
complex(cmath.rect(*cmath.polar(A/B))) - \
complex(cmath.rect(*(abs(A)/abs(B), cmath.phase(A)-cmath.phase(B))))
def round_complex(number, digits):
    if isinstance(number, complex):
        return complex(round(number.real, digits), round(number.imag, digits))
    if isinstance(number, tuple):
        return tuple( round(n, digits) for n in number )
    return complex(round(number, digits))
round_complex(cmath.polar(A/B), 10), round_complex((abs(A)/abs(B), cmath.phase(A)-cmath.phase(B)), 10)
round_complex(cmath.polar(A/B), 10) == round_complex((abs(A)/abs(B), cmath.phase(A)-cmath.phase(B)), 10)<jupyter_output><empty_output><jupyter_text>Conjugate [Complex_conjugate](https://en.wikipedia.org/wiki/Complex_conjugate)In mathematics, the complex conjugate of a complex number is the number with an equal real part and an imaginary part equal in magnitude but opposite in sign.<jupyter_code>import numpy
[C, numpy.conj(C)]
import math
math.sqrt(C.real**2 + C.imag**2)<jupyter_output><empty_output><jupyter_text>ModulusModulus of complex number, in mathematics, the norm or absolute value, of a complex number, denoted: |c|2 = |x + yi|2 = x2 + y2<jupyter_code>cmath.sqrt(C.real**2 + C.imag**2)<jupyter_output><empty_output><jupyter_text>The modulus is also defined as the sqrt of the complex number multiplied by its conjugate<jupyter_code>cmath.sqrt(C * numpy.conj(C))
numpy.absolute(C)<jupyter_output><empty_output><jupyter_text>|AB| = |A||B|<jupyter_code>numpy.absolute(A) * numpy.absolute(B) == numpy.absolute(A * B)<jupyter_output><empty_output><jupyter_text>|A + B| <= |A| + |B|<jupyter_code>numpy.absolute(A + B) <= numpy.absolute(A) + numpy.absolute(B)
[ numpy.absolute(A + B), numpy.absolute(A) + numpy.absolute(B), [numpy.absolute(A), numpy.absolute(B)]]<jupyter_output><empty_output><jupyter_text>Properties of Complex Numbers  [Associative](https://en.wikipedia.org/wiki/Associative_property)Within an expression containing two or more occurrences in a row of the same associative operator, the order in which the operations are performed does not matter as long as the sequence of the operands is not changed. That is, rearranging the parentheses in such an expression will not change its value.<jupyter_code>A + (B + C) == (A + B) + C
A * (B * C) == (A * B) * C<jupyter_output><empty_output><jupyter_text>Subraction AND Division are NOT associative<jupyter_code>A - (B - C) == (A - B) - (-C)
A / (B / C) == (A / B) / C<jupyter_output><empty_output><jupyter_text>[Commutative](https://en.wikipedia.org/wiki/Commutative_property)In mathematics, a binary operation is '''commutative''' if changing the order of the operands does not change the result.<jupyter_code>A + B == B + A
A * B == B * A<jupyter_output><empty_output><jupyter_text>Subraction AND Division are NOT Commutative<jupyter_code>A - B == B - A
A / B == B / A<jupyter_output><empty_output><jupyter_text>[Distributive](https://en.wikipedia.org/wiki/Distributive_property)The Distributive Law says that multiplying a number by a group of numbers added together is the same as doing each multiplication separately.There is a distinction between left-distributivity and right-distributivity:- A x (B + C) = (A x B) + (A x C) = left-distributive- (A x B) + C = (A x C) + (B x C) = right-distributive<jupyter_code>A * (B + C) == (A * B) + (A * C)
(A + B) * C == (A * C) + (B * C)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1751592356687898, 'fraction_numerical': 0.011062688568555145, 'mean_word_length': 5.170630816959669, 'pattern_counts': {'":': 3, '<': 87, '<?xml version=': 0, '>': 85, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '21', 'dir': 'jupyter-structured-clean-dedup', 'id': '112039', 'license': 'MIT', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2339, 'n_words': 530, 'path': 'juypter/notebooks/complex-numbers/1_cartisian.ipynb', 'repo_name': 'JamesMcGuigan/ecosystem-research', 'size': '5966'}