Logical expression

How can you express X from Y that are true, in logical logic? a rule must be true equal to 2 of the following conditions: (A, B, C, D, E, F) Is this a form of multiplication or set operations?
The end result is all permutations, such as AB OR AC OR AD, if you said 3 of them correspond to ABC, ABD, ABE, etc., so that it looks like (A, B, C) ^ 2?

thank!

+3
source share
7 answers
In logical logic ( v is OR, ' , following the predicate: NOT):
A B C'D'E'F' v
A B'C'D'E'F  v
A'B C'D'E'F' v
: : : : : :
<absolute bucketload of boolean expressions>
: : : : : :
A'B'C'D'E F

With permutations, you need to write a lot of subexpressions.

, , 0 1, , 2.

+3

, # - , bool!= int:

bool nOf(int n, bool[] bs)
{
    foreach(bool b in bs)
    {
      if((n -= b ? 1 : 0) <= 0) break;
    }
    return n == 0;
}
+3

Python:

expressions = [A, B, C, D, E, F, G ]
numTrue = len(filter(None, expressions)

PHP:

$expressions = array(A, B, C, D, E, F, G);
$numTrue = count(array_filter($expressions));
+3

. "k of n hold", , k. , A B C D E, 3 5,

(A  &  B &  C & ~D & ~E) |
(A  &  B & ~C &  D & ~E) |
(A  &  B & ~C & ~D &  E) | ...
(~A & ~B &  C &  D &  E)

"", | "" "".

+2

"A "

,

2 : a&(b|c|d|e|f) | b&(c|d|e|f) | c&(d|e|f) | d&(e|f) | e*f
3 : a&(b&(c|d|e|f) | c&(d|e|f) | d&(e|f) | e*f) | b&(c&(d|e|f) | d&(e|f) | e*f) | c&(d&(e|f) | e*f) | d&e&f

bool AofB(int n, bool[] bs)
{
   if(bs.length == 0) return false;
   if(n == 0) return true;

   foreach(int i, bool b; b[0..$-n])
      if(b && AofB(n-1,b[i+1..$]) return true;

   return false;
}

bool AofB(int n, bool[] bs)
{
   foreach(bool b; bs) if(b && --n == 0) return true;
   return false;
}
0

. , , , .

Basic Half-Adder

A, B : 1st 2nd bits
O, C : unit output and carry to next unit

O := A xor B;
C := A and B;

[Wikipedia] [http://en.wikipedia.org/wiki/Half_adder (Half-Adder)]

3 , , , .

pop ( ) , , 2. [Hakmem 169] [http://home.pipeline.com/~hbaker1/hakmem/hacks.html#item169 (popcount)].

0

, , " " " ".

{A..F} Pax Charlie Martin " " ( , ), , , " " :

(A && B) || (A && C) || ... || (D && E) || (D && F) || (E && F)

- , , , , A B , - - ( ).

, , , () , :

#{x | x <- {A, B, C, D, E, F} | x} = 2

:

#{...}

, :

{x | x <- {A, B, C, D, E, F} | x}

reads "a set xwhere xis one of Athrough F, but xis true." In other words, given the set of variables Athrough F, a subset consisting of variables with true values ​​has exactly two elements. (Use <=instead of '=' to express a different interpretation of your question.)

0
source

Source: https://habr.com/ru/post/1699436/


All Articles