ngraymon / termfactory

Exploring a formal representation for the residual terms and/or cleaning up code of the residual equation generator
MIT License
2 stars 1 forks source link

Fatorizing out X, X2 etc terms? #45

Closed ngraymon closed 2 years ago

ngraymon commented 2 years ago

terms such as

dz_i -= 0.5 * X * np.einsum('k,l,ykli->yi', T_conj[1], T_conj[1], Z[3])
dz_i -= 0.5 * np.einsum('k,l,ykli->yi', T_conj[1], T_conj[1], dz_3)

where

X = np.einsum('k,k->', T_conj[1], dT[1])
X2 = np.einsum('k,j,kj->', T_conj[1], T_conj[1], dT[1])

although maybe X2 doesn't even make sense? so maybe just abandon this whole thing

ngraymon commented 2 years ago

There was some kind of pattern in that whenever you took a line ending in dz and had the same line ending in z[#] then the z line was multipled by X like so

image

ngraymon commented 2 years ago

Also explored the use of code modification inside the function collect_z_contributions but it seems a hell of a mess so lets abandon

# h^0_0 with zero order Taylor series contributions
for z_order, z_dict in h_dict.items():
if z_dict is {}: continue;  # skip if empty

# exception case for z_order == 0 which has no if statement
tab_adjust = nof_tabs if z_order == 0 else nof_tabs + 1

temp_z_list = []  # if not empty

"""
possibly entry point for using X/X2/X3 shorthand for
    X = np.einsum('k,k->', T_conj[1], dT[1])
and so forth
"""

fast_dthing = {
    't_conj[(0, 1)], dT[(1, 0)], ': 'X',
    't_conj[(0, 1)], t_conj[(0, 1)], dT[(1, 0)], ': 'X2',
    't_conj[(0, 1)], t_conj[(0, 1)], t_conj[(0, 1)], dT[(1, 0)], ': 'X3'
}

for prefactor, string_list in z_dict.items():
    if string_list == []: continue;  # skip if empty

    print(f"{string_list =}")
    for string in string_list:
        print(f"{string =}")

        for k in fast_dthing.keys():
            if k in string:
                print(f"{k =}")
                print(f"{string =}")
                new_string = string.replace(k, '')
                print(f"{new_string =}")

                print(f"{prefactor =}")
                import pdb; pdb.set_trace()

import pdb; pdb.set_trace()