| 1 |
%% |
| 2 |
%% |
| 3 |
%% askmaps.tex |
| 4 |
%% |
| 5 |
%% (c)2020, J.E.J. op den Brouw <[email protected]> |
| 6 |
%% |
| 7 |
%% document v0.1 - 2013/12/04 |
| 8 |
%% v0.1a - 2013/12/07 |
| 9 |
%% - added \karnaughmap example |
| 10 |
%% - minor changes in text |
| 11 |
%% v0.2 - 2020/23/10 |
| 12 |
%% - added section on how to render covers |
| 13 |
%% - changes to the text. |
| 14 |
%% |
| 15 |
|
| 16 |
\documentclass[a4paper,10pt]{ltxdoc} |
| 17 |
\usepackage[a4paper,left=1.5in,right=1.5in,top=1.5in,bottom=1.5in]{geometry} |
| 18 |
|
| 19 |
%% PDF Version and compression... |
| 20 |
\pdfminorversion=5 |
| 21 |
\pdfobjcompresslevel=2 |
| 22 |
|
| 23 |
%% English spelling of chapter, section, etc. |
| 24 |
\usepackage[english]{babel} |
| 25 |
|
| 26 |
%% Use some packages |
| 27 |
\usepackage[scaled=0.92]{helvet} |
| 28 |
\usepackage{sansmath} |
| 29 |
\usepackage{color} |
| 30 |
\usepackage{float} |
| 31 |
\usepackage{listings} |
| 32 |
\usepackage{array} |
| 33 |
\usepackage{tikz} |
| 34 |
%% The next lines are commented out by default. If you want these to appear |
| 35 |
%% in the resulting PDF, you have to have the kvmacros.tex somewhere is your |
| 36 |
%% LaTeX search path or have a copy of the kvmacros.tex file in the |
| 37 |
%% current directory. If so, uncomment the next lines and LaTeX this file. |
| 38 |
%% |
| 39 |
\input kvmacros |
| 40 |
|
| 41 |
%% Use askmaps |
| 42 |
\usepackage{askmaps} |
| 43 |
|
| 44 |
%% Use hyperrefs in PDFs |
| 45 |
\usepackage{hyperref} |
| 46 |
\hypersetup{ |
| 47 |
colorlinks=true, |
| 48 |
linkcolor=blue, |
| 49 |
pdftitle={American Style Karnaugh Maps}, |
| 50 |
pdfauthor={J.E.J op den Brouw}, |
| 51 |
pdfsubject={Drawing 1, 2, 3, 4 and 5 variables K-maps}, |
| 52 |
pdfkeywords={K-maps, Karnaugh maps, Digital Design} |
| 53 |
} |
| 54 |
\definecolor{red}{rgb}{1,0,0} |
| 55 |
\definecolor{blue}{rgb}{0,0,1} |
| 56 |
\definecolor{darkgreen}{rgb}{0,0.4,0} |
| 57 |
\definecolor{orange}{rgb}{1,0.5,0} |
| 58 |
\definecolor{gray}{rgb}{0.5,0.5,0.5} |
| 59 |
\definecolor{lightgray}{rgb}{0.95,0.95,0.95} |
| 60 |
|
| 61 |
%% Making captions nicer... |
| 62 |
\usepackage[font=footnotesize,format=plain,labelfont=bf,textfont=sl]{caption} |
| 63 |
\usepackage[labelformat=simple,font=footnotesize,format=plain,labelfont=bf,textfont=sl]{subcaption} |
| 64 |
\captionsetup[figure]{justification=centering,singlelinecheck=off,belowskip=-1ex} |
| 65 |
\captionsetup[table]{justification=centering,singlelinecheck=off,skip=1ex} |
| 66 |
\captionsetup[subtable]{justification=centering,singlelinecheck=off,skip=3pt} |
| 67 |
\renewcommand\thesubfigure{(\alph{subfigure})} |
| 68 |
\renewcommand\thesubtable{(\alph{subtable})} |
| 69 |
|
| 70 |
%% Set up the LaTex language layout |
| 71 |
\lstset{ % |
| 72 |
language=[LaTeX]tex, |
| 73 |
basicstyle=\footnotesize\fontfamily{pcr}\selectfont, |
| 74 |
commentstyle=\itshape, |
| 75 |
numbers=left, |
| 76 |
numberstyle=\tiny\color{gray}, |
| 77 |
stepnumber=1, |
| 78 |
numbersep=5pt, |
| 79 |
%backgroundcolor=\color{lightgray}, |
| 80 |
showspaces=false, |
| 81 |
showstringspaces=false, |
| 82 |
showtabs=false, |
| 83 |
frame=lines, |
| 84 |
rulecolor=\color{black}, |
| 85 |
tabsize=4, |
| 86 |
captionpos=b, |
| 87 |
breaklines=true, |
| 88 |
breakatwhitespace=false, |
| 89 |
title=\lstname, |
| 90 |
morekeywords={RequirePackage,ProvidesPackage}, |
| 91 |
aboveskip=\bigskipamount |
| 92 |
} |
| 93 |
|
| 94 |
%% Need one more footnote... |
| 95 |
%% Display package name teletype... |
| 96 |
\renewcommand*{\thefootnote}{\fnsymbol{footnote}} |
| 97 |
\newcommand\Package[1]{\texttt{#1}} |
| 98 |
|
| 99 |
%% \cmdinvoke et al politely reused from the miscdoc.sty file |
| 100 |
\makeatletter |
| 101 |
\DeclareRobustCommand\cmdinvoke{\@ifstar |
| 102 |
{\let\@tempa\emph\@scmdinvoke}% |
| 103 |
{\let\@tempa\relax\@scmdinvoke}% |
| 104 |
} |
| 105 |
\def\@scmdinvoke#1{\texttt{\symbol{92}#1}% |
| 106 |
\futurelet\@let@token\@cmdinvoke |
| 107 |
} |
| 108 |
\def\@cmdinvoke{\ifx\@let@token\bgroup |
| 109 |
\let\@tempb\@cmdinvoke@lbrace |
| 110 |
\else |
| 111 |
\ifx\@let@token[% ] |
| 112 |
\let\@tempb\@cmdinvoke@lbrack |
| 113 |
\else |
| 114 |
\ifx\@let@token(% ) |
| 115 |
\let\@tempb\@cmdinvoke@lparen |
| 116 |
\else |
| 117 |
\let\@tempb\@empty |
| 118 |
\fi |
| 119 |
\fi |
| 120 |
\fi |
| 121 |
\@tempb |
| 122 |
} |
| 123 |
\def\@cmdinvoke@lbrace#1{\penalty0\hskip0pt\relax |
| 124 |
\texttt{\symbol{123}\@tempa{#1}\symbol{125}}% |
| 125 |
\futurelet\@let@token\@cmdinvoke |
| 126 |
} |
| 127 |
\def\@cmdinvoke@lbrack[#1]{\penalty-150\hskip0pt\relax |
| 128 |
\texttt{[\@tempa{#1}]}% |
| 129 |
\futurelet\@let@token\@cmdinvoke |
| 130 |
} |
| 131 |
\def\@cmdinvoke@lparen(#1){\penalty-150\hskip0pt\relax |
| 132 |
\texttt{(\@tempa{#1})}% |
| 133 |
\futurelet\@let@token\@cmdinvoke |
| 134 |
} |
| 135 |
\makeatother |
| 136 |
|
| 137 |
%% No indent |
| 138 |
\setlength{\parindent}{0pt} |
| 139 |
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex} |
| 140 |
|
| 141 |
%% At last, the document... |
| 142 |
\begin{document} |
| 143 |
\title{The \Package{askmaps} package} |
| 144 |
\author{Jesse op den Brouw\thanks{The Hague University of Applied Sciences, |
| 145 |
\href{mailto:[email protected]}{[email protected]}}} |
| 146 |
\date{\askmapsdate, version \askmapsversion} |
| 147 |
\maketitle |
| 148 |
\setcounter{footnote}{1} |
| 149 |
|
| 150 |
\section{Abstract} |
| 151 |
\label{sec:abstract} |
| 152 |
This package generates configurable American style Karnaugh maps for 1, 2, 3, |
| 153 |
4 and~5 variables as can be found in numerous books on digital design. |
| 154 |
Note that there are many ways to draw correct Karnaugh |
| 155 |
maps\footnote{E.g., a four-variable Karnaugh map can be drawn in 384 different |
| 156 |
and correct ways} and this packages creates only one version. |
| 157 |
|
| 158 |
There are more packages and examples that produce Karnaugh maps. A highly |
| 159 |
recommendable package is written by Andreas W. Wieland\footnote{See |
| 160 |
\url{http://www.ctan.org/tex-archive/macros/latex/contrib/karnaugh}}. |
| 161 |
This package creates maps that are frequently found in European |
| 162 |
textbooks\footnote{E.g. Digitale Techniek, A.P. Thijssen} but not in American |
| 163 |
textbooks. |
| 164 |
|
| 165 |
\section{Overview} |
| 166 |
\label{sec:overview} |
| 167 |
After \cmdinvoke{usepackage}[\textit{option}]{askmaps}, siz new commands are |
| 168 |
available to draw Karnaugh maps:% using the \Package{picture} environment: |
| 169 |
\begin{table}[H] |
| 170 |
\begin{tabular}{p{2.8cm}p{10cm}} |
| 171 |
\cs{askmapi} & draws a one-variable Karnaugh map \\ |
| 172 |
\cs{askmapii} & draws a two-variable Karnaugh map \\ |
| 173 |
\cs{askmapiii} & draws a three-variable Karnaugh map \\ |
| 174 |
\cs{askmapiiialt} & draws an alternate style three-variable Karnaugh map \\ |
| 175 |
\cs{askmapiv} & draws a four-variable Karnaugh map \\ |
| 176 |
\cs{askmapv} & draws a five-variable Karnaugh map \\ |
| 177 |
\end{tabular} |
| 178 |
\end{table} |
| 179 |
|
| 180 |
These commands have five parameters which have the same meaning for each |
| 181 |
commands. This will be explained in Section \ref{sec:outline}. As can be seen |
| 182 |
later on, many of the parameters can include typesetting commands such as |
| 183 |
coloring and math notation. |
| 184 |
|
| 185 |
The new dimension \cs{askmapunitlength} is available and specifies the length |
| 186 |
and width of the squares. It defaults to 1 cm (about 0.4 in) which is good in |
| 187 |
combination with a~12 pt font size. |
| 188 |
|
| 189 |
The global definitions \cs{askmapsversion} and \cs{askmapsdate} will render |
| 190 |
to the current version and date respectively. |
| 191 |
|
| 192 |
There are three commands that control the size (and shape) of the rendered |
| 193 |
text. The \cs{askmapindexsize} command sets the size and shape of the index |
| 194 |
number, the default is \cs{scriptsize}\cs{slshape}. The \cs{askmapcontentsize} command sets |
| 195 |
the size of the contents of the cells. It defaults to \cs{normalsize}. The |
| 196 |
\cs{askmapbitcombinationsize} sets the the size of the bit combinations |
| 197 |
on the edges of the Karnaugh map. It defaults to \cs{footnotesize}. These |
| 198 |
sizes can be changed using the appropriate \cs{renewcommand} command. |
| 199 |
|
| 200 |
The command \cs{askmapvarsep} contains the length of the variable separator |
| 201 |
line in de Karnaugh maps. The default is 0.7. Note that it is merely a |
| 202 |
number, not a length. It can be altered using the appropriate |
| 203 |
\cs{renewcommand} command. See Section~\ref{sec:use} for more details. |
| 204 |
|
| 205 |
The command \cs{askmap} provides drop-in replacement for the \cs{karnaughmap} |
| 206 |
command available in the \Package{kvmacros} package and internally calls one |
| 207 |
of the five commands (the \cs{askmapiiialt} command is not supported), but |
| 208 |
there are some drawbacks on using this command. |
| 209 |
|
| 210 |
\section{Outline} |
| 211 |
\label{sec:outline} |
| 212 |
%% 2013/12/07: functions -> commands |
| 213 |
All six commands take the form |
| 214 |
\cs{askmap<spec>\{\#1\}\{\#2\}\{\#3\}\{\#4\}\{\#5\}} where \texttt{<spec>} is |
| 215 |
one of \texttt{i}, \texttt{ii}, \texttt{iii}, \texttt{iiialt}, \texttt{iv} or |
| 216 |
\texttt{v} and the parameters \texttt{\#1} to \texttt{\#5} have the following |
| 217 |
meaning: |
| 218 |
|
| 219 |
\begin{itemize} |
| 220 |
\itemsep0pt |
| 221 |
\item[\texttt{\#1}] is the function output variable. |
| 222 |
\item[\texttt{\#2}] is a list of function input variables. |
| 223 |
\item[\texttt{\#3}] contains a list op options, see table below. |
| 224 |
\item[\texttt{\#4}] is a list of function values. |
| 225 |
\item[\texttt{\#5}] can be used to display user defined picture commands. |
| 226 |
\end{itemize} |
| 227 |
|
| 228 |
If a parameter contains fewer elements than needed, you will get empty spaces |
| 229 |
in the Karnaugh map. If a parameter contains more elements than needed, all |
| 230 |
elements in excess are not printed. In both situations, you will not be |
| 231 |
notified. |
| 232 |
|
| 233 |
The third parameter contains a list of options as explained below. |
| 234 |
\begin{itemize} |
| 235 |
\itemsep0pt |
| 236 |
\item[\texttt{i}] index numbers are printed in the lower left corner of |
| 237 |
each square. |
| 238 |
\item[\texttt{I}] no index numbers are printed (default). |
| 239 |
\item[\texttt{f}] function output variable is printed at the upper right |
| 240 |
corner of the Karnaugh map together with a small line |
| 241 |
extending from the square to the function |
| 242 |
name (default, see Package Option Handling). |
| 243 |
\item[\texttt{F}] no function output variable is printed |
| 244 |
\item[\texttt{b}] bit combinations of the function input variables are |
| 245 |
printed on top of the columns and at the left of the the |
| 246 |
rows (default). |
| 247 |
\item[\texttt{B}] bit combinations are not printed. |
| 248 |
\item[\texttt{c}] shortcut for \texttt{ifb}. |
| 249 |
\item[\texttt{C}] shortcut for \texttt{IFB}. |
| 250 |
\end{itemize} |
| 251 |
|
| 252 |
Options are evaluated from left to right, so a combination of \texttt{iI} will |
| 253 |
yield in no index numbers being printed. Please note that macros are not |
| 254 |
expanded to a list of tokens but to one token. |
| 255 |
|
| 256 |
%%%%If you look at American style Karnaugh maps, you will see that the function |
| 257 |
%%%%output variable usually isn't printed with the map, but is printed below or |
| 258 |
%%%%besides the map (if it is printed at all). This behavior can be simulated by |
| 259 |
%%%%using the \texttt{F} option, in which case the first parameter (the function |
| 260 |
%%%%output variable) may be left unused. |
| 261 |
|
| 262 |
\section{Package Option Handling} |
| 263 |
\label{sec:optionhandling} |
| 264 |
As of version 0.2, the option \texttt{disablef} disables the default rendering |
| 265 |
of the function output variable at the upper right corner of the Karnaugh map |
| 266 |
together with a small line extending from the square to the function name |
| 267 |
(option \texttt{f} in the third parameter). This is more common found in |
| 268 |
American textbooks. |
| 269 |
|
| 270 |
|
| 271 |
\section{Use} |
| 272 |
\label{sec:use} |
| 273 |
Let's say we have the following truth table for a function S with two variables |
| 274 |
a and b and the function values 1, 0, 1 and 1 respectively. |
| 275 |
|
| 276 |
\begin{table}[H] |
| 277 |
\centering |
| 278 |
\caption{A truth table.} |
| 279 |
\begin{tabular}{cc|c} |
| 280 |
%\hline |
| 281 |
a & b & S \\ \hline |
| 282 |
0 & 0 & 1 \\ |
| 283 |
0 & 1 & 0 \\ |
| 284 |
1 & 0 & 1 \\ |
| 285 |
1 & 1 & 1 \\ |
| 286 |
%\hline |
| 287 |
\end{tabular} |
| 288 |
\end{table} |
| 289 |
|
| 290 |
The command |
| 291 |
\begin{verbatim} |
| 292 |
\askmapii{S}{ab}{i}{1011}{} |
| 293 |
\end{verbatim} |
| 294 |
will produce the two-variable Karnaugh map as presented in |
| 295 |
Figure~\ref{fig:askmapii}. |
| 296 |
\begin{figure}[h] |
| 297 |
\centering |
| 298 |
\askmapunitlength=0.88cm |
| 299 |
\askmapii{S}{ab}{i}{1011}{}% |
| 300 |
\caption{Karnaugh map for two variables.} |
| 301 |
\label{fig:askmapii} |
| 302 |
\end{figure} |
| 303 |
|
| 304 |
As you can see, the function output variable is printed top right of the |
| 305 |
Karnaugh map, with a small line from the variable to the top right square. |
| 306 |
The most significant function input variable is printed on the top left just |
| 307 |
above the small line extending from the top left square (the variable |
| 308 |
separator line). The least significant |
| 309 |
function input variable is printed just below that line. The bit combinations |
| 310 |
for the most significant function input variables are printed on top of the |
| 311 |
columns, the bit combinations of the least significant function input variable |
| 312 |
are printed left of the rows. You can see how the function values are |
| 313 |
placed in the squares by observing the small index numbers in the lower left |
| 314 |
corners of the squares. |
| 315 |
\medskip |
| 316 |
|
| 317 |
The command |
| 318 |
\begin{verbatim} |
| 319 |
\askmapiii{S}{abc}{}{10110110}{} |
| 320 |
\end{verbatim} |
| 321 |
will produce a three-variable Karnaugh map as presented in |
| 322 |
Figure~\ref{fig:askmapiii}. In this case, the index numbers are not printed. |
| 323 |
|
| 324 |
\begin{figure}[H] |
| 325 |
\centering |
| 326 |
\askmapunitlength=0.88cm |
| 327 |
\askmapiii{S}{abc}{}{10110110}{}% |
| 328 |
\caption{Karnaugh map for three variables.} |
| 329 |
\label{fig:askmapiii} |
| 330 |
\end{figure} |
| 331 |
|
| 332 |
Sometimes you need a three-variable Karnaugh map that is printed in the |
| 333 |
vertical direction. It will leave you room to print accompanying text to |
| 334 |
the left or right of the map. The command |
| 335 |
|
| 336 |
\begin{verbatim} |
| 337 |
\askmapiiialt{S}{abc}{}{10110110}{} |
| 338 |
\end{verbatim} |
| 339 |
will produce the vertical oriented version of the three-variable Karnaugh map |
| 340 |
as can been seen in Figure~\ref{fig:askmapiiialt}. |
| 341 |
|
| 342 |
\begin{figure}[H] |
| 343 |
\centering |
| 344 |
\askmapunitlength=0.88cm |
| 345 |
\askmapiiialt{S}{abc}{}{10110110}{}% |
| 346 |
\caption{Vertical version of the Karnaugh map for three variables.} |
| 347 |
\label{fig:askmapiiialt} |
| 348 |
\end{figure} |
| 349 |
|
| 350 |
Let's draw a Karnaugh map for a logic function with four inputs. |
| 351 |
The output will become logic~1 if three or four inputs are logic 1, otherwise |
| 352 |
the output is logic 0. (Of course you can set up a truth table first; this is |
| 353 |
left as an exercise to the reader). |
| 354 |
The command |
| 355 |
\begin{verbatim} |
| 356 |
\askmapiv{S}{abcd}{}{0000000100010111}{} |
| 357 |
\end{verbatim} |
| 358 |
will produce a four-variable Karnaugh map for the given logic function and is |
| 359 |
presented in Figure~\ref{fig:askmapiv}. |
| 360 |
|
| 361 |
\begin{figure}[H] |
| 362 |
\centering |
| 363 |
\askmapunitlength=0.88cm |
| 364 |
\askmapiv{S}{abcd}{}{0000000100010111}{} |
| 365 |
\caption{Karnaugh map for four variables.} |
| 366 |
\label{fig:askmapiv} |
| 367 |
\end{figure} |
| 368 |
|
| 369 |
Using the command |
| 370 |
\begin{verbatim} |
| 371 |
\askmapv{S}{abcde}{}{00101101010010111011110011101011}{} |
| 372 |
\end{verbatim} |
| 373 |
a five-variable Karnaugh map is produced as shown in Figure~\ref{fig:askmapv}. |
| 374 |
|
| 375 |
\begin{figure}[H] |
| 376 |
\centering |
| 377 |
\askmapunitlength=0.88cm |
| 378 |
\askmapv{S}{abcde}{}{00101101010010111011110011101011}{} |
| 379 |
\caption{Karnaugh map for five variables.} |
| 380 |
\label{fig:askmapv} |
| 381 |
\end{figure} |
| 382 |
|
| 383 |
Of course you can do a lot more with the arguments of the commands. You |
| 384 |
can use inline math to produce sophisticated variable names, you can |
| 385 |
use coloring for the function values. However, please note that the second |
| 386 |
and fourth parameter act as a list of tokens, so you have to use braces to |
| 387 |
separate the tokens in the lists if they consists of multiple characters. |
| 388 |
A list of tokens such as |
| 389 |
\begin{verbatim} |
| 390 |
{abcd} |
| 391 |
\end{verbatim} |
| 392 |
will yield a, b, c and d as separate tokens, but |
| 393 |
\begin{verbatim} |
| 394 |
{$m_{0}$$m_{1}$$m_{0}$$m_{1}$} |
| 395 |
\end{verbatim} |
| 396 |
will not work. You have to write |
| 397 |
\begin{verbatim} |
| 398 |
{{$m_{0}$}{$m_{1}$}{$m_{0}$}{$m_{1}$}} |
| 399 |
\end{verbatim} |
| 400 |
|
| 401 |
The fifth parameter can be used to supply user created picture commands |
| 402 |
such as dashed rectangles or ovals to emphasize the simplifications in the |
| 403 |
function. Note that the origin of the picture (0,0) is at the lower left |
| 404 |
corner of the lower left square. Sections~\ref{sec:drawing} and~% |
| 405 |
\ref{sec:examples} show some examples. |
| 406 |
\bigskip |
| 407 |
|
| 408 |
%%%The size of the indexes is scriptsize, the size of the bit combinations |
| 409 |
%%%on the edges of the Karnaugh maps is footnotesize. All other text is |
| 410 |
%%%in normalsize. Note that there are no commands to change the font sizes |
| 411 |
%%%in the Karnaugh maps. |
| 412 |
%%%\bigskip |
| 413 |
|
| 414 |
|
| 415 |
The command \cs{askmap} provides a drop-in replacement for the command |
| 416 |
\cs{karnaughmap} from the Karnaugh package. The command |
| 417 |
\begin{verbatim} |
| 418 |
\askmap{4}{S}{abcd}{0100101010100011}{} |
| 419 |
\end{verbatim} |
| 420 |
produces the Karnaugh map in Figure \ref{fig:askmap}. |
| 421 |
\begin{figure}[H] |
| 422 |
\centering |
| 423 |
\askmapunitlength=0.88cm |
| 424 |
\askmap{4}{S}{abcd}{0100101010100011}{} |
| 425 |
\caption{Karnaugh map using drop-in replacement.} |
| 426 |
\label{fig:askmap} |
| 427 |
\end{figure} |
| 428 |
|
| 429 |
Note that when using this command the output function variable is always |
| 430 |
printed. |
| 431 |
|
| 432 |
Only Karnaugh maps of one to five variables are supported, any other number |
| 433 |
will trigger a warning. Please note that \cs{kvindex} and \cs{kvnoindex} are |
| 434 |
supported as can be seen in Figure~\ref{fig:karnaughmapindex}, but |
| 435 |
\cs{kvindexsize} and \cs{kvcontentsize} commands are not supported. |
| 436 |
\begin{verbatim} |
| 437 |
\kvindex |
| 438 |
\askmap{4}{f(a,b,c,d):}{abcd}{1110011001100110}{} |
| 439 |
\end{verbatim} |
| 440 |
\begin{figure}[H] |
| 441 |
\centering |
| 442 |
\askmapunitlength=0.88cm |
| 443 |
\kvindex |
| 444 |
\askmap{4}{f(a,b,c,d):}{abcd}{1110011001100110}{} |
| 445 |
\caption{Karnaugh map using the \Package{kvmacros} package.} |
| 446 |
\label{fig:karnaughmapindex} |
| 447 |
\end{figure} |
| 448 |
|
| 449 |
%% The next lines are commented out by default. If you want these to appear |
| 450 |
%% in the resulting PDF, you have to copy the kvmacros.tex file in the |
| 451 |
%% current directory, uncomment the next lines and LaTex this file. |
| 452 |
%% |
| 453 |
The packages \Package{kvmacros} and \Package{askmaps} can be used in the same |
| 454 |
document as shown in Figure \ref{fig:karnaughmapnoindex}. |
| 455 |
\begin{verbatim} |
| 456 |
\kvnoindex |
| 457 |
\karnaughmap{4}{f(a,b,c,d):}{abcd}{1110011001100110}{} |
| 458 |
\end{verbatim} |
| 459 |
\begin{figure}[H] |
| 460 |
\centering |
| 461 |
\kvnoindex |
| 462 |
\karnaughmap{4}{f(a,b,c,d):}{abcd}{1110011001100110}{} |
| 463 |
\caption{Karnaugh map using the \Package{kvmacros} package.} |
| 464 |
\label{fig:karnaughmapnoindex} |
| 465 |
\end{figure} |
| 466 |
|
| 467 |
The lenght of the line separating the input variables can be set to a |
| 468 |
different value as shown in Figure~\ref{fig:difflenvarsep}. |
| 469 |
|
| 470 |
\begin{verbatim} |
| 471 |
\renewcommand{\askmapvarsep}{0.6} |
| 472 |
\askmapiii{S}{abc}{}{00111010}{} |
| 473 |
\renewcommand{\askmapvarsep}{0.9} |
| 474 |
\askmapiii{F}{xyz}{}{11111010}{} |
| 475 |
\end{verbatim} |
| 476 |
\begin{figure}[H] |
| 477 |
\centering |
| 478 |
\renewcommand{\askmapvarsep}{0.6} |
| 479 |
\askmapiii{S}{abc}{}{00111010}{} |
| 480 |
\renewcommand{\askmapvarsep}{0.9} |
| 481 |
\askmapiii{F}{xyz}{}{11111010}{} |
| 482 |
\caption{Different lengths of the variable separator line.} |
| 483 |
\label{fig:difflenvarsep} |
| 484 |
\end{figure} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
\section{Drawing covers and more} |
| 489 |
\label{sec:drawing} |
| 490 |
One of the uses of Karnaugh maps is to simplify logic functions. The |
| 491 |
simplifications are usually shown as (part of) circles or ovals (also squares can be used) combining |
| 492 |
the function values that make up the simplified terms (either product terms |
| 493 |
or sum terms).% These |
| 494 |
|
| 495 |
Let's begin with a simple example. The code is shown below, the map is |
| 496 |
shown in Figure~\ref{fig:kmapsthree}. Note that one function variable is |
| 497 |
covered by all three ovals, hence it looks as if it is covered by a circle. |
| 498 |
|
| 499 |
\begin{minipage}[c]{0.5\textwidth} |
| 500 |
\begin{verbatim} |
| 501 |
\askmapiii{s}{abc}{}{00010111}{% |
| 502 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 503 |
\put(2.0,0.5){\oval(1.8,0.8)}% |
| 504 |
\put(3.0,0.5){\oval(1.8,0.8)}% |
| 505 |
}% |
| 506 |
\end{verbatim} |
| 507 |
\end{minipage}\hfill% |
| 508 |
\begin{minipage}[c]{0.5\textwidth} |
| 509 |
\begin{figure}[H] |
| 510 |
\centering |
| 511 |
\askmapunitlength=0.88cm |
| 512 |
\askmapiii{s}{abc}{}{00010111}{% |
| 513 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 514 |
\put(2.0,0.5){\oval(1.8,0.8)}% |
| 515 |
\put(3.0,0.5){\oval(1.8,0.8)}% |
| 516 |
}% |
| 517 |
\caption{Karnaugh map for three variables.} |
| 518 |
\label{fig:kmapsthree} |
| 519 |
\end{figure} |
| 520 |
\end{minipage} |
| 521 |
\bigskip |
| 522 |
|
| 523 |
Function values on the edges of Karnaugh maps can be combined in one term. |
| 524 |
The values are not adjacent in the maps so covering oval or circle has to be |
| 525 |
split. This is shown in Figure~\ref{fig:kmapsthreemarkedges}. The code is |
| 526 |
shown left. As can be seen, for marking the edges only half a circle has to |
| 527 |
be drawn. Note the lines extending the edges of the map. |
| 528 |
|
| 529 |
|
| 530 |
\bigskip |
| 531 |
\begin{minipage}[c]{0.5\textwidth} |
| 532 |
\begin{verbatim} |
| 533 |
\askmapiii{s}{abc}{}{11100111}{% |
| 534 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 535 |
\put(1.0,1.5){\oval(1.8,0.8)}% |
| 536 |
\put(3.5,0.5){\oval(0.8,0.8)[l]}% |
| 537 |
\put(3.5,0.9){\line(1,0){0.7}}% |
| 538 |
\put(3.5,0.1){\line(1,0){0.7}}% |
| 539 |
\put(0.5,0.5){\oval(0.8,0.8)[r]}% |
| 540 |
\put(0.5,0.9){\line(-1,0){0.7}}% |
| 541 |
\put(0.5,0.1){\line(-1,0){0.7}}% |
| 542 |
}% |
| 543 |
\end{verbatim} |
| 544 |
\end{minipage}\hfill% |
| 545 |
\begin{minipage}[c]{0.5\textwidth} |
| 546 |
\vspace*{-3\baselineskip} |
| 547 |
\begin{figure}[H] |
| 548 |
\centering |
| 549 |
\askmapiii{s}{abc}{}{11100111}{% |
| 550 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 551 |
\put(1.0,1.5){\oval(1.8,0.8)}% |
| 552 |
\put(3.5,0.5){\oval(0.8,0.8)[l]}% |
| 553 |
\put(3.5,0.9){\line(1,0){0.7}}% |
| 554 |
\put(3.5,0.1){\line(1,0){0.7}}% |
| 555 |
\put(0.5,0.5){\oval(0.8,0.8)[r]}% |
| 556 |
\put(0.5,0.9){\line(-1,0){0.7}}% |
| 557 |
\put(0.5,0.1){\line(-1,0){0.7}}% |
| 558 |
}% |
| 559 |
\caption{Example of how to mark edges.} |
| 560 |
\label{fig:kmapsthreemarkedges} |
| 561 |
\end{figure} |
| 562 |
\end{minipage} |
| 563 |
\bigskip |
| 564 |
|
| 565 |
Making ``square'' ovals doesn't always produce a good result as can be seen |
| 566 |
in Figure~\ref{fig:kmapsquareoval}. The column second to the right seems to |
| 567 |
be covered by it's own oval. |
| 568 |
|
| 569 |
\bigskip |
| 570 |
\begin{minipage}[c]{0.5\textwidth} |
| 571 |
\begin{verbatim} |
| 572 |
\askmapiii{s}{abc}{}{00111111}{% |
| 573 |
\put(2.5,1.0){\oval(0.8,1.8)[rb]}% |
| 574 |
\put(2.5,1.0){\oval(0.8,1.8)[rt]}% |
| 575 |
\put(1.5,1.0){\oval(0.8,1.8)[lb]}% |
| 576 |
\put(1.5,1.0){\oval(0.8,1.8)[lt]}% |
| 577 |
\put(1.5,1.9){\line(1,0){1.0}}% |
| 578 |
\put(1.5,0.1){\line(1,0){1.0}}% |
| 579 |
\put(3.5,1.0){\oval(0.8,1.8)[rb]}% |
| 580 |
\put(3.5,1.0){\oval(0.8,1.8)[rt]}% |
| 581 |
\put(2.5,1.0){\oval(0.8,1.8)[lb]}% |
| 582 |
\put(2.5,1.0){\oval(0.8,1.8)[lt]}% |
| 583 |
\put(2.5,1.9){\line(1,0){1.0}}% |
| 584 |
\put(2.5,0.1){\line(1,0){1.0}}% |
| 585 |
}% |
| 586 |
\end{verbatim} |
| 587 |
\end{minipage}\hfill% |
| 588 |
\begin{minipage}[c]{0.5\textwidth} |
| 589 |
\vspace*{-3\baselineskip} |
| 590 |
\begin{figure}[H] |
| 591 |
\centering |
| 592 |
\askmapiii{s}{abc}{}{00111111}{% |
| 593 |
\put(2.5,1.0){\oval(0.8,1.8)[rb]}% the square oval |
| 594 |
\put(2.5,1.0){\oval(0.8,1.8)[rt]}% in the middle |
| 595 |
\put(1.5,1.0){\oval(0.8,1.8)[lb]}% of the map |
| 596 |
\put(1.5,1.0){\oval(0.8,1.8)[lt]}% |
| 597 |
\put(1.5,1.9){\line(1,0){1.0}}% |
| 598 |
\put(1.5,0.1){\line(1,0){1.0}}% |
| 599 |
\put(3.5,1.0){\oval(0.8,1.8)[rb]}% the square oval |
| 600 |
\put(3.5,1.0){\oval(0.8,1.8)[rt]}% on the right |
| 601 |
\put(2.5,1.0){\oval(0.8,1.8)[lb]}% of the map |
| 602 |
\put(2.5,1.0){\oval(0.8,1.8)[lt]}% |
| 603 |
\put(2.5,1.9){\line(1,0){1.0}}% |
| 604 |
\put(2.5,0.1){\line(1,0){1.0}}% |
| 605 |
}% |
| 606 |
\caption{Example of bad use of ovals.} |
| 607 |
\label{fig:kmapsquareoval} |
| 608 |
\end{figure} |
| 609 |
\end{minipage} |
| 610 |
\bigskip |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
Let's try a four-variable map, see Figure~\ref{fig:kmapsthreemarkedges2} |
| 617 |
and accompanying code. Here we have deliberately used an oval with a |
| 618 |
bigger size (see code line marked \textasteriskcentered) otherwise it will |
| 619 |
interfere with the covering of the lower left and right edges. An example |
| 620 |
of good use of a ``square'' oval can be found in |
| 621 |
Figure~\ref{fig:kmapforfourvarcorner}. |
| 622 |
|
| 623 |
\bigskip |
| 624 |
\begin{minipage}[c]{0.5\textwidth} |
| 625 |
\begin{verbatim} |
| 626 |
\askmapiv{s}{abcd}{}{0111010001110111}{% |
| 627 |
\put(2.0,2.5){\oval(3.8,0.8)}% |
| 628 |
\put(0.5,1.0){\oval(0.8,1.8)[rb]}% |
| 629 |
\put(0.5,1.0){\oval(0.8,1.8)[rt]}% |
| 630 |
\put(0.5,1.9){\line(-1,0){0.7}}% |
| 631 |
\put(0.5,0.1){\line(-1,0){0.7}}% |
| 632 |
\put(3.0,1.0){\oval(1.8,1.8)}% (*) |
| 633 |
\put(3.5,1.0){\oval(0.8,1.8)[lb]}% |
| 634 |
\put(3.5,1.0){\oval(0.8,1.8)[lt]}% |
| 635 |
\put(3.5,1.9){\line(1,0){0.7}}% |
| 636 |
\put(3.5,0.1){\line(1,0){0.7}}% |
| 637 |
}% |
| 638 |
\end{verbatim} |
| 639 |
\end{minipage}\hfill% |
| 640 |
\begin{minipage}[c]{0.5\textwidth} |
| 641 |
\vspace*{-2\baselineskip} |
| 642 |
\begin{figure}[H] |
| 643 |
\centering |
| 644 |
\askmapiv{s}{abcd}{}{0111010001110111}{% |
| 645 |
\put(2.0,2.5){\oval(3.8,0.8)}% |
| 646 |
\put(0.5,1.0){\oval(0.8,1.8)[rb]}% |
| 647 |
\put(0.5,1.0){\oval(0.8,1.8)[rt]}% |
| 648 |
\put(0.5,1.9){\line(-1,0){0.7}}% |
| 649 |
\put(0.5,0.1){\line(-1,0){0.7}}% |
| 650 |
\put(3.0,1.0){\oval(1.8,1.8)}% |
| 651 |
\put(3.5,1.0){\oval(0.8,1.8)[lb]}% |
| 652 |
\put(3.5,1.0){\oval(0.8,1.8)[lt]}% |
| 653 |
\put(3.5,1.9){\line(1,0){0.7}}% |
| 654 |
\put(3.5,0.1){\line(1,0){0.7}}% |
| 655 |
}% |
| 656 |
\caption{Example of how to mark edges.} |
| 657 |
\label{fig:kmapsthreemarkedges2} |
| 658 |
\end{figure} |
| 659 |
\end{minipage} |
| 660 |
\bigskip |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
Every textbook on using Karnaugh maps shows how to combine the corners of a |
| 665 |
four-variable map. The complete code is shown below. The result is shown in |
| 666 |
Figure~\ref{fig:kmapforfourvarcorner}. Each corner marking |
| 667 |
consists of three drawing command: two lines (to the left, right up or |
| 668 |
down) and one (part of a) oval (right-bottom, left-bottom, right-top |
| 669 |
and right-bottom). |
| 670 |
|
| 671 |
|
| 672 |
\begin{verbatim} |
| 673 |
\begin{figure}[H] |
| 674 |
\centering |
| 675 |
\askmapiv{s}{abcd}{}{1010000010100000}{% |
| 676 |
\put(0.5,3.5){\oval(0.8,0.8)[rb]}% left-top |
| 677 |
\put(0.5,3.1){\line(-1,0){0.7}}% |
| 678 |
\put(0.9,3.5){\line(0,1){0.7}}% |
| 679 |
\put(3.5,3.5){\oval(0.8,0.8)[lb]}% right-top |
| 680 |
\put(3.5,3.1){\line(1,0){0.7}}% |
| 681 |
\put(3.1,3.5){\line(0,1){0.7}}% |
| 682 |
\put(0.5,0.5){\oval(0.8,0.8)[rt]}% left-bottom |
| 683 |
\put(0.5,0.9){\line(-1,0){0.7}}% |
| 684 |
\put(0.9,0.5){\line(0,-1){0.7}}% |
| 685 |
\put(3.5,0.5){\oval(0.8,0.8)[lt]}% right-bottom |
| 686 |
\put(3.5,0.9){\line(1,0){0.7}}% |
| 687 |
\put(3.1,0.5){\line(0,-1){0.7}}% |
| 688 |
\put(2.5,2.0){\oval(0.8,1.8)[rb]}% the square oval |
| 689 |
\put(2.5,2.0){\oval(0.8,1.8)[rt]}% in the middle |
| 690 |
\put(1.5,2.0){\oval(0.8,1.8)[lb]}% of the map |
| 691 |
\put(1.5,2.0){\oval(0.8,1.8)[lt]}% |
| 692 |
\put(1.5,2.9){\line(1,0){1.0}}% |
| 693 |
\put(1.5,1.1){\line(1,0){1.0}}% |
| 694 |
}% |
| 695 |
\caption{The corners of the Karnaugh map are connected.} |
| 696 |
\label{fig:kmapforfourvarcorner} |
| 697 |
\end{figure} |
| 698 |
\end{verbatim} |
| 699 |
|
| 700 |
\begin{figure}[H] |
| 701 |
\centering |
| 702 |
\askmapiv{s}{abcd}{}{1010010110100101}{% |
| 703 |
\put(0.5,3.5){\oval(0.8,0.8)[rb]}% left-top |
| 704 |
\put(0.5,3.1){\line(-1,0){0.7}}% |
| 705 |
\put(0.9,3.5){\line(0,1){0.7}}% |
| 706 |
\put(3.5,3.5){\oval(0.8,0.8)[lb]}% right-top |
| 707 |
\put(3.5,3.1){\line(1,0){0.7}}% |
| 708 |
\put(3.1,3.5){\line(0,1){0.7}}% |
| 709 |
\put(0.5,0.5){\oval(0.8,0.8)[rt]}% left-bottom |
| 710 |
\put(0.5,0.9){\line(-1,0){0.7}}% |
| 711 |
\put(0.9,0.5){\line(0,-1){0.7}}% |
| 712 |
\put(3.5,0.5){\oval(0.8,0.8)[lt]}% right-bottom |
| 713 |
\put(3.5,0.9){\line(1,0){0.7}}% |
| 714 |
\put(3.1,0.5){\line(0,-1){0.7}}% |
| 715 |
\put(2.5,2.0){\oval(0.8,1.8)[rb]}% the square oval |
| 716 |
\put(2.5,2.0){\oval(0.8,1.8)[rt]}% in the middle |
| 717 |
\put(1.5,2.0){\oval(0.8,1.8)[lb]}% of the map |
| 718 |
\put(1.5,2.0){\oval(0.8,1.8)[lt]}% |
| 719 |
\put(1.5,2.9){\line(1,0){1.0}}% |
| 720 |
\put(1.5,1.1){\line(1,0){1.0}}% |
| 721 |
}% |
| 722 |
\caption{The corners of the Karnaugh map are connected.} |
| 723 |
\label{fig:kmapforfourvarcorner} |
| 724 |
\end{figure} |
| 725 |
|
| 726 |
|
| 727 |
When writing a textbook on the use of Karnaugh maps, it sometimes helps if |
| 728 |
a cover is accompanied with the term it covers. |
| 729 |
Below is a fine example of explaining the simplification of a logic function |
| 730 |
by showing the product term at each cover. The truth table is shown at the |
| 731 |
right. |
| 732 |
|
| 733 |
\begin{verbatim} |
| 734 |
\begin{figure}[H] |
| 735 |
\begin{subfigure}[c]{0.5\textwidth} |
| 736 |
\centering |
| 737 |
\askmapiii{s}{abc}{}{00010111}{% |
| 738 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 739 |
\put(3.0,3.0){\makebox(0,0){$a\cdot b$}}% |
| 740 |
\put(3.0,2.8){\line(-1,-5.0){0.2}}% |
| 741 |
\put(2.0,0.5){\oval(1.8,0.8)}% |
| 742 |
\put(0.5,-0.8){\makebox(0,0){$b\cdot c$}}% |
| 743 |
\put(0.5,-0.6){\line(1,0.9){0.8}}% |
| 744 |
\put(3.0,0.5){\oval(1.8,0.8)}% |
| 745 |
\put(4.5,-0.8){\makebox(0,0){$a\cdot c$}}% |
| 746 |
\put(4.5,-0.6){\line(-1,0.9){0.8}}% |
| 747 |
}% |
| 748 |
\end{subfigure}% |
| 749 |
\begin{subfigure}[c]{0.5\textwidth} |
| 750 |
\centering |
| 751 |
\begin{tabular}{ccc|c} |
| 752 |
$a$ & $b$ & $c$ & $s$ \\ \hline |
| 753 |
0 & 0 & 0 & 0 \\ |
| 754 |
0 & 0 & 1 & 0 \\ |
| 755 |
0 & 1 & 0 & 0 \\ |
| 756 |
0 & 1 & 1 & 1 \\ |
| 757 |
1 & 0 & 0 & 0 \\ |
| 758 |
1 & 0 & 1 & 1 \\ |
| 759 |
1 & 1 & 0 & 1 \\ |
| 760 |
1 & 1 & 1 & 1 \\ |
| 761 |
\end{tabular} |
| 762 |
\end{subfigure}% |
| 763 |
\bigskip\caption{Karnaugh map for three variables.} |
| 764 |
\label{fig:karnaughmajorfunctie} |
| 765 |
\end{figure} |
| 766 |
\end{verbatim} |
| 767 |
|
| 768 |
|
| 769 |
\begin{figure}[H] |
| 770 |
\begin{subfigure}[c]{0.5\textwidth} |
| 771 |
\centering |
| 772 |
\askmapunitlength=0.88cm |
| 773 |
\askmapiii{s}{abc}{}{00010111}{% |
| 774 |
\put(2.5,1.0){\oval(0.8,1.8)}% |
| 775 |
\put(3.0,3.0){\makebox(0,0){$a\cdot b$}}% |
| 776 |
\put(3.0,2.8){\line(-1,-5.0){0.2}}% |
| 777 |
\put(2.0,0.5){\oval(1.8,0.8)}% |
| 778 |
\put(0.5,-0.8){\makebox(0,0){$b\cdot c$}}% |
| 779 |
\put(0.5,-0.6){\line(1,0.9){0.8}}% |
| 780 |
\put(3.0,0.5){\oval(1.8,0.8)}% |
| 781 |
\put(4.5,-0.8){\makebox(0,0){$a\cdot c$}}% |
| 782 |
\put(4.5,-0.6){\line(-1,0.9){0.8}}% |
| 783 |
}% |
| 784 |
\end{subfigure}% |
| 785 |
\begin{subfigure}[c]{0.5\textwidth} |
| 786 |
\centering |
| 787 |
\begin{tabular}{ccc|c} |
| 788 |
$a$ & $b$ & $c$ & $s$ \\ \hline |
| 789 |
0 & 0 & 0 & 0 \\ |
| 790 |
0 & 0 & 1 & 0 \\ |
| 791 |
0 & 1 & 0 & 0 \\ |
| 792 |
0 & 1 & 1 & 1 \\ |
| 793 |
1 & 0 & 0 & 0 \\ |
| 794 |
1 & 0 & 1 & 1 \\ |
| 795 |
1 & 1 & 0 & 1 \\ |
| 796 |
1 & 1 & 1 & 1 \\ |
| 797 |
\end{tabular} |
| 798 |
\end{subfigure}% |
| 799 |
\bigskip\caption{Karnaugh map for three variables.} |
| 800 |
\label{fig:karnaughmajorfunction} |
| 801 |
\end{figure} |
| 802 |
|
| 803 |
A very notable feature is when you use Ti\textsl{k}Z. When you use the package with |
| 804 |
|
| 805 |
\begin{verbatim} |
| 806 |
\usepackage{tikz} |
| 807 |
\end{verbatim} |
| 808 |
|
| 809 |
you can use Ti\textsl{k}Z' opacity control to add opaque solid rectangles in the back: |
| 810 |
|
| 811 |
\begin{verbatim} |
| 812 |
\askmapii{F}{xy}{f}{0111}{ |
| 813 |
\setlength\fboxsep{0pt}\linethickness{0pt} |
| 814 |
\put(1.1,0.1){\pgfsetfillopacity{0.2}\colorbox{red}{\framebox(0.8,1.8){}}\pgfsetfillopacity{1}}% |
| 815 |
\put(0.1,0.1){\pgfsetfillopacity{0.2}\colorbox{blue}{\framebox(1.8,0.8){}}\pgfsetfillopacity{1}}% |
| 816 |
} |
| 817 |
\end{verbatim} |
| 818 |
|
| 819 |
\askmapii{F}{xy}{f}{0111}{ |
| 820 |
\setlength\fboxsep{0pt}\linethickness{0pt} |
| 821 |
\put(1.1,0.1){\pgfsetfillopacity{0.2}\colorbox{red}{\framebox(0.8,1.8){}}\pgfsetfillopacity{1}}% |
| 822 |
\put(0.1,0.1){\pgfsetfillopacity{0.2}\colorbox{blue}{\framebox(1.8,0.8){}}\pgfsetfillopacity{1}}% |
| 823 |
} |
| 824 |
|
| 825 |
\bigskip |
| 826 |
In fact, you can use a \texttt{tikzpicture} environment to use Ti\textsl{k}Z commands |
| 827 |
but you have to set an invisible point to coordinate to (0,0): |
| 828 |
|
| 829 |
\begin{verbatim} |
| 830 |
\askmapii{F}{xy}{f}{0111}{% |
| 831 |
\begin{tikzpicture}[x=\askmapunitlength,y=\askmapunitlength]% |
| 832 |
\draw[draw=none,fill=none] (0,0) -- (0,0); % Set default corner |
| 833 |
\draw[red, ultra thick] (0,0) rectangle (2,2);% |
| 834 |
\end{tikzpicture}% |
| 835 |
} |
| 836 |
\end{verbatim} |
| 837 |
|
| 838 |
\askmapii{F}{xy}{f}{0111}{% |
| 839 |
\begin{tikzpicture}[x=\askmapunitlength,y=\askmapunitlength]% |
| 840 |
\draw[draw=none,fill=none] (0,0) -- (0,0); % Set default corner |
| 841 |
\draw[red,ultra thick] (0,0) rectangle (2,2);% |
| 842 |
\end{tikzpicture}% |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
\section{Additional command} |
| 847 |
The command \cmdinvoke{askmapindexsize} sets the size and typeface of the minterm numbers in the cells. The default definition is set to |
| 848 |
|
| 849 |
\begin{lstlisting} |
| 850 |
\newcommand{\askmapindexsize}{\scriptsize\slshape} |
| 851 |
\end{lstlisting} |
| 852 |
|
| 853 |
The command \cmdinvoke{askmapcontentsize} sets the size and typeface for the cell's contents. The default definition is |
| 854 |
|
| 855 |
\begin{lstlisting} |
| 856 |
\newcommand{\askmapcontentsize}{\normalsize} |
| 857 |
\end{lstlisting} |
| 858 |
|
| 859 |
The command \cmdinvoke{askmapbitcombinationsize} sets the size and typeface for the bit combinations at the top and the left. The default definition is |
| 860 |
|
| 861 |
\begin{lstlisting} |
| 862 |
\newcommand{\askmapbitcombinationsize}{\footnotesize} |
| 863 |
\end{lstlisting} |
| 864 |
|
| 865 |
The command \cmdinvoke{askmapvarsep} sets the relative line length of the variable separator on the left of the Karnaugh map. The default definition is |
| 866 |
|
| 867 |
\begin{lstlisting} |
| 868 |
\newcommand{\askmapvarsep}{0.70} |
| 869 |
\end{lstlisting} |
| 870 |
|
| 871 |
These commands may be changed using the appropriate \cmdinvoke{renewcommand} command. |
| 872 |
|
| 873 |
|
| 874 |
%\newpage |
| 875 |
\section{Examples} |
| 876 |
\label{sec:examples} |
| 877 |
\askmapunitlength=0.88cm |
| 878 |
The most simple Karnaugh maps you can make with only one variable. |
| 879 |
\begin{verbatim} |
| 880 |
\askmapi{s}{a}{i}{00}{} |
| 881 |
\askmapi{s}{a}{}{01}{} |
| 882 |
\askmapi{s}{a}{}{10}{} |
| 883 |
\askmapi{s}{a}{}{11}{} |
| 884 |
\end{verbatim} |
| 885 |
\askmapi{s}{a}{i}{00}{}% |
| 886 |
\askmapi{s}{a}{}{01}{}% |
| 887 |
\askmapi{s}{a}{}{10}{}% |
| 888 |
\askmapi{s}{a}{}{11}{}% |
| 889 |
\bigskip\bigskip |
| 890 |
|
| 891 |
The Karnaugh maps for two variables: plain, with indexes and output |
| 892 |
variable. |
| 893 |
\begin{verbatim} |
| 894 |
\askmapii{S}{ab}{F}{1010}{} |
| 895 |
\askmapii{S}{ab}{i}{1110}{} |
| 896 |
\askmapii{S}{ab}{}{1110}{} |
| 897 |
\end{verbatim} |
| 898 |
\askmapii{S}{ab}{F}{1010}{} |
| 899 |
\askmapii{S}{ab}{i}{1110}{} |
| 900 |
\askmapii{S}{ab}{}{1110}{} |
| 901 |
\bigskip\bigskip |
| 902 |
|
| 903 |
The Karnaugh maps for three variables: plain, with indexes and function |
| 904 |
output variable. |
| 905 |
\begin{verbatim} |
| 906 |
\askmapiii{S}{abc}{F}{00111010}{} |
| 907 |
\askmapiii{F}{xyz}{i}{11111010}{} |
| 908 |
\end{verbatim} |
| 909 |
\askmapiii{S}{abc}{F}{00111010}{} |
| 910 |
\askmapiii{F}{xyz}{i}{11111010}{} |
| 911 |
\bigskip\bigskip |
| 912 |
|
| 913 |
The Karnaugh maps for four variables: plain, with function output variable and |
| 914 |
indexes. |
| 915 |
\begin{verbatim} |
| 916 |
\askmapiv{f}{wxyz}{F}{1110001101000101}{} |
| 917 |
\askmapiv{S}{abcd}{i}{1100100100011101}{} |
| 918 |
\end{verbatim} |
| 919 |
\askmapiv{f}{wxyz}{F}{1110001101000101}{} |
| 920 |
\askmapiv{S}{abcd}{i}{1100100100011101}{} |
| 921 |
\bigskip\bigskip |
| 922 |
|
| 923 |
You can also do math things by using the known \$ signs... and you can make an |
| 924 |
empty map for your exams... |
| 925 |
\begin{verbatim} |
| 926 |
\askmapii{$S_{0}$}{{$a_{1}$}{$a_{0}$}}{}{1010}{} |
| 927 |
\askmapii{}{}{F}{}{} |
| 928 |
\end{verbatim} |
| 929 |
\askmapii{$S_{0}$}{{$a_{1}$}{$a_{0}$}}{}{1010}{} |
| 930 |
\askmapii{}{}{F}{}{} |
| 931 |
\bigskip\bigskip |
| 932 |
|
| 933 |
You can do the math thing in roman upright font... and of course you can make |
| 934 |
a \textsl{really} empty map for your exams... |
| 935 |
\begin{verbatim} |
| 936 |
\askmapiii{$\mathrm{M^{n+1}_{0}}$}{{$\mathrm{M^{n}_{2}}$}{$\mathrm{M^{n}_{1}}$} |
| 937 |
{$\mathrm{M^{n}_{0}}$}}{}{11100111}{} |
| 938 |
\askmapiii{}{}{BF}{}{} |
| 939 |
\end{verbatim} |
| 940 |
\askmapiii{$\mathrm{M^{n+1}_{0}}$}{{$\mathrm{M^{n}_{2}}$}{$\mathrm{M^{n}_{1}}$} |
| 941 |
{$\mathrm{M^{n}_{0}}$}}{}{11100111}{} |
| 942 |
\askmapiii{}{}{BF}{}{} |
| 943 |
\bigskip\bigskip |
| 944 |
|
| 945 |
The vertical version of the three variable map, used in a \verb|minipage| |
| 946 |
environment: |
| 947 |
\begin{verbatim} |
| 948 |
\begin{minipage}[c]{0.25\textwidth} |
| 949 |
\askmapiiialt{s}{{c$_{in}$}ab}{}{01101001}{} |
| 950 |
\end{minipage} |
| 951 |
\begin{minipage}[c]{0.25\textwidth} |
| 952 |
\askmapiiialt{c$_{out}$}{{c$_{in}$}ab}{}{00010111}{} |
| 953 |
\end{minipage}\hfill% |
| 954 |
\begin{minipage}[c]{0.40\textwidth} |
| 955 |
As you can see on the left, the function of the sum of the full adder cannot |
| 956 |
be simplified as all 1's are placed diagonal in the map. This means that the |
| 957 |
function for the sum can be expressed with XOR ports. |
| 958 |
|
| 959 |
The carry-out function on the otherhand can be simplified. |
| 960 |
\end{minipage} |
| 961 |
\end{verbatim} |
| 962 |
|
| 963 |
\begin{minipage}[c]{0.25\textwidth} |
| 964 |
\askmapiiialt{s}{{c$_{in}$}ab}{}{01101001}{} |
| 965 |
\end{minipage} |
| 966 |
\begin{minipage}[c]{0.25\textwidth} |
| 967 |
\askmapiiialt{c$_{out}$}{{c$_{in}$}ab}{}{00010111}{} |
| 968 |
\end{minipage}\hfill% |
| 969 |
\begin{minipage}[c]{0.40\textwidth} |
| 970 |
As you can see on the left, the function of the sum of the full adder cannot |
| 971 |
be simplified as all 1's are placed diagonal in the map. This means that the |
| 972 |
function for the sum can be expressed with XOR ports. |
| 973 |
|
| 974 |
The carry-out function on the otherhand can be simplified. |
| 975 |
\end{minipage} |
| 976 |
|
| 977 |
\bigskip\bigskip |
| 978 |
|
| 979 |
|
| 980 |
You can do things with don't cares... |
| 981 |
\begin{verbatim} |
| 982 |
\askmapii{S}{ab}{}{011-}{} |
| 983 |
\askmapiii{S}{abc}{}{001--10-}{} |
| 984 |
\end{verbatim} |
| 985 |
\askmapii{S}{ab}{}{011-}{} |
| 986 |
\askmapiii{S}{abc}{}{001--10-}{} |
| 987 |
\bigskip\bigskip |
| 988 |
|
| 989 |
You can use colors and empty function values and variables as values too... |
| 990 |
\begin{verbatim} |
| 991 |
\askmapiii{S}{abc}{}{{\color{blue}{0}}{\color{blue}{0}}{\color{red}{1}}{ }{ } |
| 992 |
{\color{red}{1}}{\color{blue}{0}}{ }}{} |
| 993 |
\askmapii{S}{ab}{}{{$i_{0}$}{$i_{1}$}{$i_{2}$}{$i_{3}$}}{} |
| 994 |
\end{verbatim} |
| 995 |
\askmapiii{S}{abc}{}{{\color{blue}{0}}{\color{blue}{0}}{\color{red}{1}}{ }{ } |
| 996 |
{\color{red}{1}}{\color{blue}{0}}{ }}{} |
| 997 |
\askmapii{S}{ab}{}{{$i_{0}$}{$i_{1}$}{$i_{2}$}{$i_{3}$}}{} |
| 998 |
\bigskip |
| 999 |
|
| 1000 |
|
| 1001 |
You can set the font to something else ... and use sans math font ... |
| 1002 |
\begin{verbatim} |
| 1003 |
{\fontfamily{phv}\selectfont% |
| 1004 |
\askmapiv{S}{abcd}{}{0110111011110011}{}% |
| 1005 |
} |
| 1006 |
{\fontfamily{phv}\selectfont\sansmath |
| 1007 |
\askmapiv{$Q^{n+1}_{0}$}{{$p^{n}_{1}$}{$p^{n}_{0}$}{$q^{n}_{1}$}{$q^{n}_{0}$}} |
| 1008 |
{}{0110111011110011}{}% |
| 1009 |
} |
| 1010 |
\end{verbatim} |
| 1011 |
{\fontfamily{phv}\selectfont% |
| 1012 |
\askmapiv{S}{abcd}{}{0110111011110011}{}% |
| 1013 |
} |
| 1014 |
{\fontfamily{phv}\selectfont\sansmath |
| 1015 |
\askmapiv{$Q^{n+1}_{0}$}{{$p^{n}_{1}$}{$p^{n}_{0}$}{$q^{n}_{1}$}{$q^{n}_{0}$}} |
| 1016 |
{}{0110111011110011}{}% |
| 1017 |
} |
| 1018 |
\bigskip\bigskip |
| 1019 |
|
| 1020 |
You can use the last parameter to create to your own picture commands. Note |
| 1021 |
that the origin of the picture (0,0) is at the lower left corner of the lower |
| 1022 |
left square. It is also possible to use \cs{raisebox} in conjuction with |
| 1023 |
horizontal spacing to adjust the placing of the left (least significant) |
| 1024 |
variable(s). |
| 1025 |
|
| 1026 |
%\newpage |
| 1027 |
\begin{verbatim} |
| 1028 |
{\fontfamily{phv}\selectfont\sansmath |
| 1029 |
\askmapiii{F}{xy{\raisebox{2ex}{\ \ z}}}{f}{11100111}{% raise Z input |
| 1030 |
\color{red}\put(0.1,0.1){\dashbox{0.1}(0.8,1.8){}}% |
| 1031 |
\color{blue}\put(1.1,1.1){\dashbox{0.1}(1.8,0.8){}}% |
| 1032 |
\color{darkgreen}\put(2.1,0.1){\dashbox{0.1}(1.8,0.8){}}% |
| 1033 |
\color{orange}\put(0.15,1.15){\dashbox{0.1}(1.7,0.7){}}% |
| 1034 |
}}% |
| 1035 |
{\fontfamily{phv}\selectfont\sansmath |
| 1036 |
\askmapiii{F}{xyz}{}{11100111}{% |
| 1037 |
\put(0.5,1.0){\oval(0.8,1.8)}% |
| 1038 |
\put(2.0,1.5){\oval(1.8,0.8)}% |
| 1039 |
\put(2.5,0.5){\oval(0.8,0.8)}% circle |
| 1040 |
\put(3.5,0.5){\oval(0.8,0.8)[l]}% these three create |
| 1041 |
\put(3.5,0.9){\line(1,0){0.6}}% a oval open to the left |
| 1042 |
\put(3.5,0.1){\line(1,0){0.6}}% |
| 1043 |
}}% |
| 1044 |
\end{verbatim} |
| 1045 |
{\fontfamily{phv}\selectfont\sansmath |
| 1046 |
\askmapiii{F}{xy{\raisebox{1.5ex}{\ \ z}}}{f}{11100111}{% raise Z input |
| 1047 |
\color{red}\put(0.1,0.1){\dashbox{0.1}(0.8,1.8){}}% |
| 1048 |
\color{blue}\put(1.1,1.1){\dashbox{0.1}(1.8,0.8){}}% |
| 1049 |
\color{darkgreen}\put(2.1,0.1){\dashbox{0.1}(1.8,0.8){}}% |
| 1050 |
\color{orange}\put(0.15,1.15){\dashbox{0.1}(1.7,0.7){}}% |
| 1051 |
}}% |
| 1052 |
{\fontfamily{phv}\selectfont\sansmath |
| 1053 |
\askmapiii{F}{xyz}{}{11100111}{% |
| 1054 |
\put(0.5,1.0){\oval(0.8,1.8)}% |
| 1055 |
\put(2.0,1.5){\oval(1.8,0.8)}% |
| 1056 |
\put(2.5,0.5){\oval(0.8,0.8)}% circle |
| 1057 |
\put(3.5,0.5){\oval(0.8,0.8)[l]}% these three create |
| 1058 |
\put(3.5,0.9){\line(1,0){0.7}}% an oval open to the left |
| 1059 |
\put(3.5,0.1){\line(1,0){0.7}}% |
| 1060 |
}}% |
| 1061 |
\bigskip\bigskip |
| 1062 |
|
| 1063 |
You can set the length of the squares, but please note that this will also |
| 1064 |
affect the rendering of the text... |
| 1065 |
\begin{verbatim} |
| 1066 |
\askmapunitlength=1cm |
| 1067 |
\askmapii{S}{ab}{}{1011}{} |
| 1068 |
\askmapunitlength=0.88cm |
| 1069 |
\askmapii{S}{ab}{}{1011}{} |
| 1070 |
\askmapunitlength=0.8cm |
| 1071 |
\askmapii{S}{ab}{}{1011}{} |
| 1072 |
\askmapunitlength=0.5cm |
| 1073 |
\askmapii{S}{ab}{}{1011}{} |
| 1074 |
\end{verbatim} |
| 1075 |
|
| 1076 |
{\askmapunitlength=1cm% |
| 1077 |
\askmapii{S}{ab}{}{1011}{}% |
| 1078 |
\askmapunitlength=0.88cm% |
| 1079 |
\askmapii{S}{ab}{}{1011}{}% |
| 1080 |
\askmapunitlength=0.8cm% |
| 1081 |
\askmapii{S}{ab}{}{1011}{}% |
| 1082 |
\askmapunitlength=0.5cm% |
| 1083 |
\askmapii{S}{ab}{}{1011}{}} |
| 1084 |
\bigskip\bigskip |
| 1085 |
|
| 1086 |
%\newpage |
| 1087 |
An example directly from the Karnaugh package: |
| 1088 |
|
| 1089 |
\begin{verbatim} |
| 1090 |
\kvnoindex |
| 1091 |
\askmap{4}{$f(a,b,c,d):$}{{$a$}{$b$}{$c$}{$d$}}% |
| 1092 |
{0110011001100110}% |
| 1093 |
{% |
| 1094 |
\put(0,2){\oval(1.9,1.9)[r]} |
| 1095 |
\put(4,2){\oval(1.9,1.9)[l]} |
| 1096 |
\put(2,0){\oval(1.9,1.9)[t]} |
| 1097 |
\put(2,4){\oval(1.9,1.9)[b]} |
| 1098 |
} |
| 1099 |
\end{verbatim} |
| 1100 |
{\askmapunitlength=0.88cm |
| 1101 |
\kvnoindex |
| 1102 |
\askmap{4}{$f(a,b,c,d):$}{{$a$}{$b$}{$c$}{$d$}}% |
| 1103 |
{0110011001100110}% |
| 1104 |
{% |
| 1105 |
\put(0,2){\oval(1.8,1.8)[r]} |
| 1106 |
\put(4,2){\oval(1.8,1.8)[l]} |
| 1107 |
\put(2,0){\oval(1.8,1.8)[t]} |
| 1108 |
\put(2,4){\oval(1.8,1.8)[b]} |
| 1109 |
}} |
| 1110 |
|
| 1111 |
\bigskip |
| 1112 |
but please note that the ovals do not cover the logic 1's in the Karnaugh map |
| 1113 |
because the function values are placed in a different order. |
| 1114 |
|
| 1115 |
One can use Ti\textsl{k}Z. Please note you have to set a default corner to |
| 1116 |
(0,0), because Ti\textsl{k}Z will create a bounding box around the the |
| 1117 |
\texttt{tikzpicture}: |
| 1118 |
|
| 1119 |
\begin{verbatim} |
| 1120 |
A static hazard can be found by inspecting the Karnaugh map and see if a change |
| 1121 |
of minterms will cross implicants: |
| 1122 |
|
| 1123 |
\askmapiii{F}{xyz}{}{011100100}{% |
| 1124 |
\begin{tikzpicture}[x=\askmapunitlength,y=\askmapunitlength]% |
| 1125 |
\draw[draw=none,fill=none] (0,0) -- (0,0); % Set default corner |
| 1126 |
\draw[red] (0.1,0.1) rectangle (1.9,0.9); |
| 1127 |
\draw[blue] (1.1,1.1) rectangle (2.9,1.9); |
| 1128 |
\draw[purple,thick,->] (1.6,1.5) to[bend left] (1.6,0.5); |
| 1129 |
\end{tikzpicture}% |
| 1130 |
} |
| 1131 |
|
| 1132 |
The function is $F = \overline{x}z + y\overline{z}$. But if the circuit is |
| 1133 |
changing from minterm $m_2$ to $m_3$, a static hazard will occur as can |
| 1134 |
be seen by the arrow. |
| 1135 |
\end{verbatim} |
| 1136 |
|
| 1137 |
|
| 1138 |
A static hazard can be found by inspecting the Karnaugh map and see if a change |
| 1139 |
of minterms will cross implicants: |
| 1140 |
|
| 1141 |
\askmapiii{F}{xyz}{}{011100100}{% |
| 1142 |
\begin{tikzpicture}[x=\askmapunitlength,y=\askmapunitlength]% |
| 1143 |
\draw[draw=none,fill=none] (0,0) -- (0,0); % Set default corner |
| 1144 |
\draw[red] (0.1,0.1) rectangle (1.9,0.9); |
| 1145 |
\draw[blue] (1.1,1.1) rectangle (2.9,1.9); |
| 1146 |
\draw[purple,thick,->] (1.6,1.5) to[bend left] (1.6,0.5); |
| 1147 |
\end{tikzpicture}% |
| 1148 |
} |
| 1149 |
|
| 1150 |
The function is $F = \overline{x}z + y\overline{z}$. But if the circuit is |
| 1151 |
changing from minterm $m_2$ to $m_3$, a static hazard will occur as can |
| 1152 |
be seen by the arrow. |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
\section{Changelog} |
| 1157 |
\label{sec:changelog} |
| 1158 |
\begin{verbatim} |
| 1159 |
4-dec-2013 -- v0.1 |
| 1160 |
initial release |
| 1161 |
23-oct-2020 -- v0.2 |
| 1162 |
added option disablef |
| 1163 |
added askmapi - a K-map for one variable |
| 1164 |
added askmapiiialt - alternate (vertical) version op K-map III |
| 1165 |
added formatting index size, contents size and bit combination size. |
| 1166 |
added support for \kvindex and \nokvindex macros when kvmacros.tex is loaded |
| 1167 |
added formatting for left-placed variables |
| 1168 |
implemented a debug possibility |
| 1169 |
implemented linelength of variable separator |
| 1170 |
resolved an issue with multiple overfull \hbox'es |
| 1171 |
added a section on creating covers |
| 1172 |
added examples with Tikz |
| 1173 |
\end{verbatim} |
| 1174 |
|
| 1175 |
|
| 1176 |
\newpage |
| 1177 |
\section{The source code} |
| 1178 |
\label{sec:sourcecode} |
| 1179 |
The source code is pretty straight forward. It uses a lot of picture primitives |
| 1180 |
for drawing the maps. The package uses three macros for processing |
| 1181 |
variable-length parameters, which were completely reused from the |
| 1182 |
\Package{kvmacros} package. |
| 1183 |
|
| 1184 |
\lstinputlisting{askmaps.sty} |
| 1185 |
|
| 1186 |
\end{document} |