Home > Blockchain >  Code/Algorithm for Logical Expression Simplifier
Code/Algorithm for Logical Expression Simplifier

Time:07-11

I'm building a logical expression from multiple inputs and combining them with an OR, so my expression becomes something like below

(1 AND 2 AND 3 AND 4 AND (50 OR 51) AND 7 AND 8)
OR
(1 AND 2 AND 3 AND 41 AND (50 OR 51) AND 71)

There are many repetitive elements in it which can be combined to build the optimal & final logical expression as

(1 AND 2 AND 3 AND (50 OR 51) AND ((4 AND 7 AND 8) OR (41 AND 71)))

Is there any way by which this can be done? I'm currently building this as a string into javascript but any generic algorithm would help which I can apply to trim my logical expression

CodePudding user response:

This is a classical problem, read https://en.wikipedia.org/wiki/Quine–McCluskey_algorithm

CodePudding user response:

Be careful, the simplified expression you gave is wrong

Correction :

(1 && 2 && 3 && (50 || 51) && ((4 && 7 && 8) || (41 && 71)) )


1, 2 and 3 must always be true
50 or 51 must be true
4 us true (and 41 false) => 7 and 8 must be true
4 is false but 41 is true => 71 must be true
4 and 41 are both true => 71 or (7 and 8) must be true

Hope is helps you ;)

  • Related