• date post

22-Mar-2018
• Category

## Documents

• view

217

1

Embed Size (px)

### Transcript of Typesetting Karnaugh Maps and Veitch Charts with LATEX Andreas...

• Typesetting Karnaugh Maps and Veitch Charts

with LATEX

Andreas W. WielandeMail: [email protected]

January 7th, 2002

1 Abstract

Karnaugh maps and Veitch charts1 are used to simplify logic equations. Thedrawing of them used to be a boring, annoying and error-prone task. With theincluded macros this is no longer a problem. They can typeset Karnaugh mapsand Veitch charts with up to ten variables, which is more than you might likelyneed. You only have to provide a list of variable identifiers plus the functiontable of your logic function(s). The macros also allow to mark the simplificationsof your logic function directly within a Karnaugh map or Veitch chart.

2 Introduction

Karnaugh maps and Veitch charts are used to simplify logic equations. Theyare map representations of logic functions, and in that they are equivalent.The difference between the two kinds of diagrams is the way in which the vari-ables of the functions are located within the diagrams: The Karnaugh map. . . displays a functions discriminants according to the reflected binary (Gray)code. The Veitch chart . . . displays the discriminants in natural binary order.(F. M. Brown)

However, the drawing of either kind of them used to be a boring, annoyingand error-prone task. Since I had to typeset a 50+ page collection of exercises fora basic computer-science lecture with plenty of Karnaugh maps in it, I decidedto write some macros that would do this task for me. Let us start first with anintroduction on how to use these Macros:

The first thing you have to do is to put the macro file kvmacros.tex into adirectory where TEX will find it, i.e. you have to put it into a directory whereyour TEXINPUTS environment variable points to. You can then load them bytyping \input kvmacros somewhere in the preamble of your document.

1In previous releases of this document I referred to Karnaugh maps as Karnaugh-Veitch-Maps. This was definitely not correct. Thanks to F. M. Brown for pointing this error out tome.

1

• Suppose now you have a logic function f with the following function table:

Index a b c d f0 0 0 0 0 11 0 0 0 1 12 0 0 1 0 13 0 0 1 1 04 0 1 0 0 05 0 1 0 1 16 0 1 1 0 17 0 1 1 1 0

Index a b c d f8 1 0 0 0 09 1 0 0 1 1

10 1 0 1 0 111 1 0 1 1 012 1 1 0 0 013 1 1 0 1 114 1 1 1 0 115 1 1 1 1 0

This logic function can easily be put into a Karnaugh map by using the\karnaughmap-macro2. It has five parameters: The number of variables in themap, an identifier for the function, a list of variable identifiers for the variables,and the list of values of f for each line in the function table. The variableidentifiers in the third parameter are ordered from highest to lowest significance(the same way as in the function table, with a having a significance of 23 = 8and d having a significance of 20 = 1). The list of values of f was read fromlowest to highest index. The fifth parameter remains empty in this example, itwill be discussed below:

\karnaughmap{4}{f(a,b,c,d):}{abcd}{1110011001100110}{}

This produces the following Karnaugh map, where the indices in the lowerleft corner of each box correspond to the indices in the function table:3

f(a,b,c,d):

10

11

12

03

04

15

16

07

08

19

110

011

012

113

114

015a

b

c

d

The macros work similar for Veitch charts:

\veitchchart{4}{f(a,b,c,d):}{abcd}{0110011001100110}{}

2Users of older versions of the macro package will notice that the name has changed. Belowyou will find a discussion of the changes between versions.

3The indices can easily be calculated from the variable values in the function table, i.e.line 11: the index equals a 23 + b 22 + c 21 + d 20 = 1 8 + 0 4 + 1 2 + 1 1 = 11.

2

• f(a,b,c,d):

00

11

12

03

04

15

16

07

08

19

110

011

012

113

114

015

a

b

c

c

d d

Notice the difference in the variable location in the diagrams. In my opinionKarnaugh maps are much easier to use if you need to simplify a logic function;therefore Veitch charts will not be discussed any further in this document. Ex-cept otherwise noticed, the macros syntax and functionality are exactly thesame for Karnaugh maps and Veitch charts.

The macros that read the variable list and the list of logic values (i.e. pa-rameters #3 and #4) work recursively. Therefore, you have to take special careto supply the correct number of tokens to print: If you supply a list of variableidentifiers or a list of logic values that contains fewer elements than needed themacros will cause error messages similar to the following:

! Argument of \kvgetonechar has an extra }.

\parl.201 }{}

?

On the contrary, if any of the two lists is longer than needed, you will not benotified! Moreover, each entry has to be one character long, otherwise like avariable identifier enclosed in $s you have to put it into braces: \karnaughmap{4}{$f(a,b,c,d):$}{{$a$}{$b$}{$c$}{$d$}}{0110011001100110}{} This produces the following Karnaugh map: 3 • f(a, b, c, d) : 00 11 12 03 04 15 16 07 08 19 110 011 012 113 114 015a b c d 3 Marking simplifications The already mentioned fifth parameter can be used if you want to draw some-thing inside the Karnaugh map. For example this is useful if you want to showhow you simplified a logic function: \karnaughmap{4}{$f(a,b,c,d):$}{{$a$}{$b$}{$c$}{$d$}}%{0110011001100110}%{%\put(0,2){\oval(1.9,1.9)[r]}\put(4,2){\oval(1.9,1.9)[l]}\put(2,0){\oval(1.9,1.9)[t]}\put(2,4){\oval(1.9,1.9)[b]}} The corresponding Karnaugh map looks like this:$%

'&' $& %f(a, b, c, d) : 00 11 12 03 04 15 16 07 08 19 110 011 012 113 114 015a b c d You can use any of LATEXs graphics macros for this purpose. The Kar-naugh map has its pivot point at the lower left point4 and a unitlength that is 4This is not exactly true, but sufficient if you do not want to modify the macros. 4 • equal to the length of a single box within the Karnaugh map. Sometimes youmay find that the \ovals that you want to draw inside a Karnaugh map areslightly shifted to the right. This occurs if you use the eepic-Package in yourdocument. In this case, make a copy of the eepic.sty file, rename it to some-thing like myeepic.sty and comment out the definition of the \oval-macro inyour local copy. If you put this new myeepic.sty file somewhere into yourTEXs search path so that TEX can find it and you load it properly with e.g.\usepackage{myeepic}, you shouldnt experience any more trouble. 4 Other features There are some more features that you can use. Possibly the most important isthat you can change the size of the diagrams by changing the size of the boxeswithin the map, simply by typing: \kvunitlength=15mm\karnaughmap{4}{$f:$}{abcd}{0110011001100110}{} This results in the following Karnaugh map. The setting of the\kvunitlength remains active until you change it again;5 the default\kvunitlength is 8 mm: f : 0 0 1 1 1 2 0 3 0 4 1 5 1 6 0 7 0 8 1 9 1 10 0 11 0 12 1 13 1 14 0 15a b c d 5Or, of course, until you leave the group in which you redefined the value. This applies toall changeable parameters and macro definitions in this section! 5 • Another feature is that you can switch off the indices inside the map bytyping: \kvnoindex\karnaughmap{4}{$f:$}{abcd}{0110011001100110}{} f : 0 1 1 0 01 10 0 1 1 0 01 10a b c d This setting also remains active until you switch indexing on again using the\kvindex-macro: \kvindex\karnaughmap{4}{$f:$}{abcd}{0110011001100110}{} f : 00 11 12 03 04 15 16 07 08 19 110 011 012 113 114 015a b c d Usually, the font size of the maps contents and indices should besuitable (the defaults are \tiny for \kvindexsize and \normalsize for\kvcontentsize). If you want to change them, you can do this by redefin-ing the \kvcontentsize- and \kvindexsize-macros (Preferably, you should dothis in the preamble of your document): \renewcommand\kvindexsize{\footnotesize}\karnaughmap{4}{$f:$}{abcd}{0110011001100110}{} 6 • f : 00 11 12 03 04 15 16 07 08 19 110 011 012 113 114 015a b c d In the same way you can also change the font family (Although I doubt thatthis is sensible): \renewcommand\kvindexsize{\footnotesize\it}\karnaughmap{4}{$f:\$}{abcd}{0110011001100110}{}

f :

00

11

12

03

04

15

16

07

08

19

110

011

012

113

114

015a

b

c

d

These macros are named \kvfoo, because they work both for Karnaughmaps and Veitch charts.

5 If you use an older version of the macros. . .

. . . you will certainly have noticed a number of changes. The most importantone is that I have changed the name of the macro that draws Karnaugh mapsfrom \kvmap to \karnaughmap. I suggest that you use the new name in doc-uments that you