Hi, I am trying to get the general conditions of a list in order to simplify it, for example, if I have a list:
List=[['1','A1','B1','Kc','Ka'],['1','A1','B1','D2','Kc','Ka'], ['-1','A1','B1','D1','Kc','Ka'],['1','A1','B1','D1','KD','Ka'], ['-1','B1','D1','C1','Kc','Ka','KF'],['1','B1','D1','F1','Kc','Kz','Kl']]
is there any function that can give me the result:
List_output=[['A1', 'B1', [['D1', [['KD', 'Ka'], ['-1', 'Ka', 'Kc']]], ['Ka', 'Kc'], ['D2', 'Ka', 'Kc']]], ['B1', 'D1', [['F1', 'Kc', 'Kl', 'Kz'], ['-1', 'C1', 'KF', 'Ka', 'Kc']]]]
What I basically want to do is algebraic reduction.
(A1 B1 Kc Ka + A1 B1 D2 Kc Ka - A1 B1 D1 Kc Ka + A1 B1 D1 KD Ka - B1 D1 C1 Kc Ka KF + B1 D1 F1 Kc Kz Kl ) -> A1B1[D1[-KcKa + KDKa] + D2KcKa +KcKa] + B1D1[-C1[KcKaKF] + F1[KcKzKl]]
The only requirement for simplification is that all simplified terms must depend on the sum or remainder of K. In other words, everything should be a function of the linear combination K: [-KcKa + KDKa] ; [KcKaKF] ; [['-1','Kc','Ka'],['+1','KD','Ka']] .
I'm trying to use SymPy, but my problem is that the abbreviations come from other sources, so I never know what the characters will be. To use SymPy, you need to declare characters, right? Any idea on how I can solve this problem?