-2

Chanced upon this beautiful problem. Since I am new to Boolean expressions, it is looking quite difficult.

I guess parentheses can be used.

If one of A, B, C is true, A||B||C must be true. Using AND and NOT, it can be done but, how do we know which one has which value?

I tried using truth tables, but three variables were too much.

Any ideas on how to solve, or at least how to make it faster?

Paul
  • 1
  • 2
  • 3 variables are too much? You'll have 8 rows... – MrTux Feb 11 '21 at 07:38
  • Sounds like a homework question. In that case, please ask your teacher. Otherwise, please help us understand the business need; maybe that will drive to a solution. – Dennis Feb 11 '21 at 14:03

2 Answers2

0

Learn De Morgan's laws. It's a little piece of a basic knowledge for a programmer.

They state, among others, that not(X or Y) = (not X) and (not Y).

If you negate both sides and then apply the formula twice—first to ((A or B) or C), treating the (A or B) subexpression as X, and then to (A or B) itself—you'll get the desired result:

A || B || C =
(A || B) || C =
!(!(A || B) && !C) =
!((!A || !B) && !C) =
!(!A && !B && !C)
CiaPan
  • 9,381
  • 2
  • 21
  • 35
  • There's no real reason to apply DeMorgan's to subexpressions, it works with *any* number of individual input variables (as your final line shows). – paxdiablo Feb 11 '21 at 07:57
  • That's right, they inductively extend to arbitrary number of arguments. But the base case is a negation of an alternative or conjunction of two values, so I did that first step of induction explicitly. I expect this will be usefult for OP. :) – CiaPan Feb 11 '21 at 10:49
0

DeMorgan's Law (one of them, anyway), normally applied to two variables, states that:

A or B == not (not A and not B)

But this works equally well for three (or more) variables:

A or B or C == not (not A and not B and not C)

This becomes obvious when you realise that A or B or C is true if any of them are true, the only way to get false if if all of them are false.

And, only if they're all false will not A and not B and not C give true (hence not(that) will give false). For confirmation, here's the table, where you'll see that the A or B or C and not(notA and notB and notC) columns give the same values:

A B C     A or B or C     notA notB notC     not(notA and notB and notC)
-----     -----------     --------------     ---------------------------
f f f          f           t    t    t                     f
f f t          t           t    t    f                     t
f t f          t           t    f    t                     t
f t t          t           t    f    f                     t
t f f          t           f    t    t                     t
t f t          t           f    t    f                     t
t t f          t           f    f    t                     t
t t t          t           f    f    f                     t
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953