开发者

Boolean Logic: How can I simplify this IF statement?

I inherited some code that contains an IF statement I'd like to reduce if possible.

It is, in essence, a simple IF (A or B) THEN. But it gets tricky because A and B are generalizations of other express开发者_Go百科ions.

Question: How can I re-express this, if possible, in simpler terms?

Here's the original IF statement....

For clarity, I've substituted brackets and braces for parentheses.

IF ( { W & X & Y & Z } or  { C & D & [ ( F & G) or (H & G) or (F & J) ] } )
/* Comment: For what it's worth: (Z = not c) */


From a logic perspective, you can't. There are no duplicate variables (Z = ¬C doesn't help much) and because of the nesting normal forms will be longer than this. This seems to be as short as it gets.

From a programming perspective, if absolute maximum speed is less important than readability (or you've got a decent compiler) I would re-group them in a way that makes the decision structure more clear (which of these are related from a (program execution) logic point of view?), even if that duplicates checks to certain variables (assuming that these are not function calls). I'd also split this up into several separate definitions and only combine the results inside the if.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜