karnaugh-map-2.tex 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. \documentclass[border=2pt]{standalone}
  2. \usepackage{tikz}
  3. \usetikzlibrary{matrix,calc}
  4. %internal group
  5. %#1-space between node and grouping line. Default=0
  6. %#2-top left node
  7. %#3-bottom right node
  8. \newcommand{\implicant}[3][0]{
  9. \draw[rounded corners=3pt] ($(#2.north west)+(135:#1)$) rectangle ($(#3.south east)+(-45:#1)$);
  10. }
  11. %group lateral borders
  12. %#1-space between node and grouping line. Default=0
  13. %#2-top left node
  14. %#3-bottom right node
  15. \newcommand{\implicantcostats}[3][0]{
  16. \draw[rounded corners=3pt] ($(rf.east |- #2.north)+(90:#1)$)-| ($(#2.east)+(0:#1)$) |- ($(rf.east |- #3.south)+(-90:#1)$);
  17. \draw[rounded corners=3pt] ($(cf.west |- #2.north)+(90:#1)$) -| ($(#3.west)+(180:#1)$) |- ($(cf.west |- #3.south)+(-90:#1)$);
  18. }
  19. %group top-bottom borders
  20. %#1-space between node and grouping line. Default=0
  21. %#2-top left node
  22. %#3-bottom right node
  23. \newcommand{\implicantdaltbaix}[3][0]{
  24. \draw[rounded corners=3pt] ($(cf.south -| #2.west)+(180:#1)$) |- ($(#2.south)+(-90:#1)$) -| ($(cf.south -| #3.east)+(0:#1)$);
  25. \draw[rounded corners=3pt] ($(rf.north -| #2.west)+(180:#1)$) |- ($(#3.north)+(90:#1)$) -| ($(rf.north -| #3.east)+(0:#1)$);
  26. }
  27. %group corners
  28. %#1-space between node and grouping line. Default=0
  29. \newcommand{\implicantcantons}[1][0]{
  30. \draw[rounded corners=3pt] ($(rf.east |- 0.south)+(-90:#1)$) -| ($(0.east |- cf.south)+(0:#1)$);
  31. \draw[rounded corners=3pt] ($(rf.east |- 8.north)+(90:#1)$) -| ($(8.east |- rf.north)+(0:#1)$);
  32. \draw[rounded corners=3pt] ($(cf.west |- 2.south)+(-90:#1)$) -| ($(2.west |- cf.south)+(180:#1)$);
  33. \draw[rounded corners=3pt] ($(cf.west |- 10.north)+(90:#1)$) -| ($(10.west |- rf.north)+(180:#1)$);
  34. }
  35. %Empty Karnaugh map 4x4
  36. \newenvironment{Karnaugh}%
  37. {
  38. \begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
  39. \draw (0,0) grid (4,4);
  40. \draw (0,4) -- node [pos=0.7,above right,anchor=south west] {cd} node [pos=0.7,below left,anchor=north east] {ab} ++(135:1);
  41. %
  42. \matrix (mapa) [matrix of nodes,
  43. column sep={0.8cm,between origins},
  44. row sep={0.8cm,between origins},
  45. every node/.style={minimum size=0.3mm},
  46. anchor=8.center,
  47. ampersand replacement=\&] at (0.5,0.5)
  48. {
  49. \& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
  50. |(r00)| 00 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
  51. |(r01)| 01 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
  52. |(r11)| 11 \& |(12)| \phantom{0} \& |(13)| \phantom{0} \& |(15)| \phantom{0} \& |(14)| \phantom{0} \& \\
  53. |(r10)| 10 \& |(8)| \phantom{0} \& |(9)| \phantom{0} \& |(11)| \phantom{0} \& |(10)| \phantom{0} \& \\
  54. |(rf) | \phantom{00} \& \& \& \& \& \\
  55. };
  56. }%
  57. {
  58. \end{tikzpicture}
  59. }
  60. %Empty Karnaugh map 2x4
  61. \newenvironment{Karnaughvuit}%
  62. {
  63. \begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
  64. \draw (0,0) grid (4,2);
  65. \draw (0,2) -- node [pos=0.7,above right,anchor=south west] {bc} node [pos=0.7,below left,anchor=north east] {a} ++(135:1);
  66. %
  67. \matrix (mapa) [matrix of nodes,
  68. column sep={0.8cm,between origins},
  69. row sep={0.8cm,between origins},
  70. every node/.style={minimum size=0.3mm},
  71. anchor=4.center,
  72. ampersand replacement=\&] at (0.5,0.5)
  73. {
  74. \& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
  75. |(r00)| 0 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
  76. |(r01)| 1 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
  77. |(rf) | \phantom{00} \& \& \& \& \& \\
  78. };
  79. }%
  80. {
  81. \end{tikzpicture}
  82. }
  83. %Defines 8 or 16 values (0,1,X)
  84. \newcommand{\contingut}[1]{%
  85. \foreach \x [count=\xi from 0] in {#1}
  86. \path (\xi) node {\x};
  87. }
  88. %Places 1 in listed positions
  89. \newcommand{\minterms}[1]{%
  90. \foreach \x in {#1}
  91. \path (\x) node {1};
  92. }
  93. %Places 0 in listed positions
  94. \newcommand{\maxterms}[1]{%
  95. \foreach \x in {#1}
  96. \path (\x) node {0};
  97. }
  98. %Places X in listed positions
  99. \newcommand{\indeterminats}[1]{%
  100. \foreach \x in {#1}
  101. \path (\x) node {X};
  102. }
  103. \begin{document}
  104. \begin{Karnaugh}
  105. \contingut{0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,1}
  106. \implicant{0}{2}
  107. \implicantdaltbaix[3pt]{3}{10}
  108. \implicantcostats{4}{14}
  109. \end{Karnaugh}
  110. \begin{Karnaugh}
  111. \minterms{4,10,11,13}
  112. \maxterms{1,3,6,7,8,9,12,14}
  113. \indeterminats{0,2,5,15}
  114. \implicant{4}{5}
  115. \implicant{11}{10}
  116. \implicant{13}{15}
  117. \implicantcostats{0}{2}
  118. \implicant[3pt]{0}{4}
  119. \implicant[3pt]{5}{13}
  120. \implicant[3pt]{15}{11}
  121. \implicantdaltbaix[3pt]{2}{10}
  122. \end{Karnaugh}
  123. \end{document}