I'm trying to write a Petrick's method, which is a technique for Quine–McCluskey algorithm.
Assume I have a math equation, which consists of +
and *
. For example:
(K+L)(K+M)(L+N)(M+P)(N+Q)(P+Q)
How can I exand the equation to get all of the sum of products, like this?
K*K*L*M*N*P + K*K*L*M*N*Q + .... (63 terms)
(You can see the inferred result with WolframAlpha)
I somehow doubt this is what you want, but to obtain the result as an array of characters...
w = Expand[(K + L) (K + M) (L + N) (M + P) (N + Q) (P + Q)];
x = ToString@InputForm[w];
z = StringReplace[x, y_ ~~ "^2" :> StringJoin[y, "*", y]]
K*K*L*M*N*P + K*L*L*M*N*P + K*L*M*M*N*P + ... + L*M*N*P*Q*Q
DeleteCases[Characters@z, " "]
{K,*,K,*,L,*,M,*,N,*,P,+, ... ,+,L,*,M,*,N,*,P,*,Q,*,Q}