STATUS: Draft
import numpy as np
import sympy as sp
import pickle
from IPython.display import HTML
import ipywidgets as widgets
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
import pandas as pd
import itertools
# This is commented out
#%matplotlib widget
# function to print latex
def renderListToLatex(e):
latex_rendering = []
for i in range(len(e)):
latex_rendering.append("$$" + sp.latex(e[i]) + "$$<br/>")
return(HTML("".join(latex_rendering[0:])))
Let g1 be solutions of $a_i$ for a general cubic from the notebook: Solving Polynomial Equations (3).
with open('./SharedOutputs/SPE3.pickle', 'rb') as input:
imported_outputs_from_another_notebook = pickle.load(input)
g1 = imported_outputs_from_another_notebook['generalCubicSolutions']
Create needed variables.
c_0, c_1, c_2, c_3, x, t, a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7, a_8, a_9, x_1, x_2, s_1, s_2 = sp.symbols('c_0, c_1, c_2, c_3, x, t, a_0, a_1, a_2, a_3, a_4, a_5, a_6, a_7, a_8, a_9, x_1, x_2, s_1, s_2')
Recall solutions of general cubic where $ a_0 = 0$:
latex_rendering = ["$$ a_0 = 0 $$"]
for i in range(len(g1)):
latex_rendering.append("$$" + sp.latex(g1[i].simplify()) + "$$")
HTML("".join(latex_rendering[1:]))
Introduction
Goal: find pattern in these numbers.
Observe: Patterns occuring in indices, powers, coefficients and signs.
Observe: All terms $a_k$ have the same total degree (k - 1) (e.g each term in $e_6$ is homogenous).
Observe: There appears to be some kind of relationship between indices and powers (note indices are related position).
Definition: The index degree of a term $c_1^m c_2^m c_3^m $ be the sum of the products of the indices and the degrees of each of the consituent variables and the claim is that this is constant in each of the values. It appears then that the index degree is always twice the usual degree (when indices are ignored
Observe: total usual degree is (k - 1) while the index degree is 2 (k - 1).
# TODO function to check indices
Strategy: Place all numbers in a matrix of coefficients (of size 7 x 7) , padded with with zeros to enable pattern exploration
# Let g8 be a matrix of the coefficients for the general solution of primes
arraySize = 4
g2 = [g1[i].simplify().rhs for i in range(len(g1))]
g3 = [sp.fraction(x)[0].expand() for x in g2]
g4 = [sp.Poly(g3[i]).coeffs() for i in range(2,len(g3))]
# Let g5 and g6 be filled array of numerator values
g5 = [np.pad(np.abs(np.array([g3[i]])), (0, arraySize - len(np.array([g3[i]])))) for i in range(0, len(g3[0:2]))]
g6 = [np.pad(np.flip(np.abs(np.array(g4[i]))), (0, arraySize - len(g4[i]))) for i in range(len(g4))]
g7 = g5 + g6
g8 = sp.Matrix(np.stack(g7, axis = 0))
g8
Strategy: Prime decomposition
# Let g9 be g8 under prime decomposition
g9 = g8.applyfunc(sp.primefactors)
g9
Strategy: Examine in the contdext of $c_1, c_2$ and $c_3$
# Let g16 be a list of all coefficeints and their
g10 = [g1[i].simplify().rhs for i in range(len(g1))]
g11 = [sp.fraction(x)[0].expand() for x in g10]
g12 = [list(g11[i].args) for i in range(2,len(g11))]
g12
g13 = [np.pad(np.abs(np.array([g11[i]])), (0, arraySize - len(np.array([g11[i]])))) for i in range(0, len(g11[0:2]))]
g14 = [np.pad(np.abs(np.array(g12[i])), (0, arraySize - len(g12[i]))) for i in range(len(g12))]
g15 = g13 + g14
g16 = sp.Matrix(np.stack(g15, axis = 0))
g16
# Write data that will be used again
data = {'matrixOfCoefficients': g8,
'matrixOfCoeffiencientsAsDecomposedPrimes':g9,
'matrixOfTerms': g16}
f = open('./SharedOutputs/SPE4.pickle', 'wb')
pickle.dump(data, f)
f.close()
Summary
Looking for patterns in solutions in is a powerful strategy to understand if a solution can be generalised or has some dependency on some kind of on-series or on-sequence. Rendering numbers in matrices tends to expose these patterns and also allows the use of linear algebra to seek patterns which may not be as obvious.