Hi I am trying to get the common terms of a list to simplify it for example if the list I have is:
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 could give me as a 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 an 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 the simplification is that all terms simplified need to depend on a sum or rest of K's. In other words, everything needs to be a function of a linear combination of K's: [-KcKa + KDKa]
; [KcKaKF]
; [['-1','Kc','Ka'],['+1','KD','Ka']]
.
I am trying to use SymPy but the problem I have is that the terms to reduce come from elsewhere so I never know what the symbols will be. To use SymPy you need to declare the symbols, right? Any idea of how I can tackle this problem?