<jupyter_start><jupyter_text>Ratios of ratios on the complex plane.In the mid 1500s polymath & gambler [Gerolamo Cardano](https://en.wikipedia.org/wiki/Gerolamo_Cardano) (re-)invented [Complex numbers](https://en.wikipedia.org/wiki/Complex_number), to allow the use of negative numbers to calculate odds of winning (or loosing). For centuries afterward, mathemiticians tried to deny imaginary numbers, but they work and they model some real world problems better than anything else available. Does mathematics exist in nature or is a human invention? If we invented it, is it in nature?. [Leonhard Euler](https://en.wikipedia.org/wiki/Leonhard_Euler) legitimatized imaginary numbers (also $\pi$ and the natural logarithm $e$) with ["Euler's Formula"](https://en.wikipedia.org/wiki/Euler%27s_formula) in the profoundly magical identity relating the base of the natural log, $\pi$ and the imaginary root of negative one to unity and nothing. $$\ \theta \mbox{  is an angle expressed in radians} \\\ i = \sqrt{-1} \\\ \\\ e^{i * \theta} = \cos{\theta} + \sin{\theta} * i \\\ \\\ e^{i\pi} - 1 = 0 \\$$With polynomials on the complex plane the real and imaginary axis are so simple as x, and y. Complex vector addition ($\mathcal{Z + Z}$) is like adding arrowheaded lines, mulitiplication is a rotation with contraction or expansion. These qualities make repeated iteration of difference equations much more interesting. $$\ Z_{n+1} = f(Z_{n}) \\$$Repeated multiplacation of a real number has only three possible futures: $$\ \mbox{consider real number x:} \in \mathbb{R}^{1} \\\ x_{n+1} = x_{n}^{2} \\\ \\\ \mbox{if   } x_{0} = 1 \\\ x_{n} == 1 \mbox{  (forever)} \\\ \\\ \mbox{if   } x_{0} > 1 \\\ x \Rightarrow \infty  \mbox{  (sooner or later)} \\\ \\\ \mbox{if   } x_{0} < 1 \\\ x \Rightarrow 0 \mbox{  (sooner or later)} \\$$Not so simple if the number is complex as shown in the code cells below. The print statements display the formatted results named in each cell.<jupyter_code>""" 
import numerical python and name it np
assign a complex number the to the letter z
get the magnitude of that vector z
get the rotation of that vector z
convert to degrees for dispaly
print out the named results
"""
import numpy as np
z = 1 + 1j
z_magnitude = np.abs(z)
z_theta = np.arctan2(z.imag, z.real)
z_theta_degrees = 180 * z_theta / np.pi
print('\ncomplex z =', z, 'one unit right, one imaginary unit up',
      '\nvector with magnitude: %03f, rotation: %03f radians'%(z_magnitude, z_theta), 
      '\n(rotation:) %0.3f in degrees'%(z_theta_degrees))
"""
Complex vectors on the unit circle for 10 angles:
"""
magnitude = 1.0
for theta in np.linspace(0, 2*np.pi, 10):
    z = np.exp(theta * 1j) * magnitude
    if z.imag >= 0:
        print('\t%0.3f + %0.3fi'%(z.real, z.imag))
    else:
        print('\t%0.3f  %0.3fi'%(z.real, z.imag))

"""
Negative Real Numbers Iterated:
"""
n_powers = 7
x = -1
print('\nmagnitude x_0 =', np.abs(x), '\n')
s = ''
for k in range(n_powers):
    s += ' x^%i = %i, '%(k, (x)**k)
print(s[:-2])

x = -1.2
print('\n\nmagnitude x_0 =', np.abs(x), '\n')
s = ''
for k in range(n_powers):
    s += ' x^%0.1f = %0.1f, '%(k, (x)**k)
print(s[:-2])

x = -0.8
print('\n\nmagnitude x_0 =', np.abs(x), '\n')
s = ''
for k in range(n_powers):
    s += ' x^%0.1f=%0.1f, '%(k, (x)**k)
print(s[:-2])

"""
Complex Numbers Iterated:
"""
n_per_line = 3
z = np.cos(np.pi/4) + np.sin(np.pi/4) * 1j
m = np.abs(z)
theta = np.arctan2(z.imag, z.real)
theta_degrees = theta * 180 / np.pi
print('\nmagnitude =', m,' rotation = %0.2f radians'%(theta), '  (or %0.2f degrees)\n'%(theta_degrees))
s = ''
for k in range(5):
    z_n = (z)**k
    s += ' z^%i = %0.2f %0.2fi , '%(k, z_n.real, z_n.imag)
print(s[:-2])

# or they flip out towards zero if they start inside the unit circle
z = (np.cos(np.pi/4) + np.sin(np.pi/4) * 1j) * 0.9
print('\n\nmagnitude z_0 =', np.abs(z), '\n')
s = ''
for k in range(100):
    z_n = (z)**k
    if k > 0 and k % n_per_line == 0:
        s += '\n'
    if z_n.imag >= 0:
        s += ' z^%i = %0.6f+%0.6fi, '%(k, z_n.real, z_n.imag)
    else:
        s += ' z^%i = %0.6f%0.6fi, '%(k, z_n.real, z_n.imag)
print(s[:-2])

# and they flip out towards infinity if they start outside the unit circle
z = (np.cos(np.pi/4) + np.sin(np.pi/4) * 1j) * 1.1
print('\n\nmagnitude z_0 =', np.abs(z), '\n')
s = ''
for k in range(100):
    z_n = (z)**k
    if k > 0 and k % n_per_line == 0:
        s += '\n'
    if z_n.imag >= 0:
        s += ' z^%i = %0.1f+%0.1fi, '%(k, z_n.real, z_n.imag)
    else:
        s += ' z^%i = %0.1f%0.1fi, '%(k, z_n.real, z_n.imag)

print(s[:-2])<jupyter_output>magnitude = 1.0  rotation = 0.79 radians   (or 45.00 degrees)

 z^0 = 1.00 0.00i ,  z^1 = 0.71 0.71i ,  z^2 = 0.00 1.00i ,  z^3 = -0.71 0.71i ,  z^4 = -1.00 0.00i 


magnitude z_0 = 0.9 

 z^0 = 1.000000+0.000000i,  z^1 = 0.636396+0.636396i,  z^2 = 0.000000+0.810000i, 
 z^3 = -0.515481+0.515481i,  z^4 = -0.656100+0.000000i,  z^5 = -0.417539-0.417539i, 
 z^6 = -0.000000-0.531441i,  z^7 = 0.338207-0.338207i,  z^8 = 0.430467-0.000000i, 
 z^9 = 0.273948+0.273948i,  z^10 = 0.000000+0.348678i,  z^11 = -0.221898+0.221898i, 
 z^12 = -0.282430+0.000000i,  z^13 = -0.179737-0.179737i,  z^14 = -0.000000-0.228768i, 
 z^15 = 0.145587-0.145587i,  z^16 = 0.185302-0.000000i,  z^17 = 0.117925+0.117925i, 
 z^18 = 0.000000+0.150095i,  z^19 = -0.095520+0.095520i,  z^20 = -0.121577+0.000000i, 
 z^21 = -0.077371-0.077371i,  z^22 = -0.000000-0.098477i,  z^23 = 0.062670-0.062670i, 
 z^24 = 0.079766-0.000000i,  z^25 = 0.050763+0.050763i,  z^26 = 0.000000+0.064611i, 
 z^27 = -0.041118+0.041118i,  z^28 = -0.0523[...]
{'fraction_non_alphanumeric': 0.19015340706386016, 'fraction_numerical': 0.11113093114520158, 'mean_word_length': 3.086734693877551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '615773', 'license': 'MIT', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2346, 'n_words': 650, 'path': 'docs/complex_story.ipynb', 'repo_name': 'dlanier/FlyingMachineFractal', 'size': '5606'}