code_junkie

Boolean Expression

Nov 12th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. A B C'D'E'F' v
  2. A B'C'D'E'F v
  3. A'B C'D'E'F' v
  4. : : : : : :
  5. <absolute bucketload of boolean expressions>
  6. : : : : : :
  7. A'B'C'D'E F
  8.  
  9. bool nOf(int n, bool[] bs)
  10. {
  11. foreach(bool b in bs)
  12. {
  13. if((n -= b ? 1 : 0) <= 0) break;
  14. }
  15. return n == 0;
  16. }
  17.  
  18. expressions = [A, B, C, D, E, F, G ]
  19. numTrue = len(filter(None, expressions)
  20.  
  21. $expressions = array(A, B, C, D, E, F, G);
  22. $numTrue = count(array_filter($expressions));
  23.  
  24. (A & B & C & ~D & ~E) |
  25. (A & B & ~C & D & ~E) |
  26. (A & B & ~C & ~D & E) | ...
  27. (~A & ~B & C & D & E)
  28.  
  29. 2 : a&(b|c|d|e|f) | b&(c|d|e|f) | c&(d|e|f) | d&(e|f) | e*f
  30. 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
  31.  
  32. bool AofB(int n, bool[] bs)
  33. {
  34. if(bs.length == 0) return false;
  35. if(n == 0) return true;
  36.  
  37. foreach(int i, bool b; b[0..$-n])
  38. if(b && AofB(n-1,b[i+1..$]) return true;
  39.  
  40. return false;
  41. }
  42.  
  43. bool AofB(int n, bool[] bs)
  44. {
  45. foreach(bool b; bs) if(b && --n == 0) return true;
  46. return false;
  47. }
  48.  
  49. Basic Half-Adder
  50.  
  51. A, B : 1st 2nd bits
  52. O, C : unit output and carry to next unit
  53.  
  54. O := A xor B;
  55. C := A and B;
  56.  
  57. (A && B) || (A && C) || ... || (D && E) || (D && F) || (E && F)
  58.  
  59. #{x | x <- {A, B, C, D, E, F} | x} = 2
  60.  
  61. #{...}
  62.  
  63. {x | x <- {A, B, C, D, E, F} | x}
Add Comment
Please, Sign In to add comment