Typesetting Karnaugh Maps and Veitch Charts with LATEX ... · PDF file of your logic function...

Click here to load reader

  • date post

    06-Oct-2020
  • Category

    Documents

  • view

    0
  • download

    0

Embed Size (px)

Transcript of Typesetting Karnaugh Maps and Veitch Charts with LATEX ... · PDF file of your logic function...

  • Typesetting Karnaugh Maps and Veitch Charts

    with LATEX

    Andreas W. Wieland eMail: [email protected]

    January 7th, 2002

    1 Abstract

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

    2 Introduction

    Karnaugh maps and Veitch charts are used to simplify logic equations. They are 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 function’s 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, annoying and error-prone task. Since I had to typeset a 50+ page collection of exercises for a basic computer-science lecture with plenty of Karnaugh maps in it, I decided to write some macros that would do this task for me. Let us start first with an introduction on how to use these Macros:

    The first thing you have to do is to put the macro file kvmacros.tex into a directory where TEX will find it, i.e. you have to put it into a directory where your TEXINPUTS environment variable points to. You can then load them by typing \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 to me.

    1

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

    Index a b c d f 0 0 0 0 0 1 1 0 0 0 1 1 2 0 0 1 0 1 3 0 0 1 1 0 4 0 1 0 0 0 5 0 1 0 1 1 6 0 1 1 0 1 7 0 1 1 1 0

    Index a b c d f 8 1 0 0 0 0 9 1 0 0 1 1

    10 1 0 1 0 1 11 1 0 1 1 0 12 1 1 0 0 0 13 1 1 0 1 1 14 1 1 1 0 1 15 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 the map, 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 variable identifiers 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 = 8 and d having a significance of 20 = 1). The list of values of f was read from lowest to highest index. The fifth parameter remains empty in this example, it will be discussed below:

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

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

    f(a,b,c,d):

    1 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

    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. Below you 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):

    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 15

    a

    b

    c

    c

    d d

    Notice the difference in the variable location in the diagrams. In my opinion Karnaugh 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 the same 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 care to supply the correct number of tokens to print: If you supply a list of variable identifiers or a list of logic values that contains fewer elements than needed the macros will cause error messages similar to the following:

    ! Argument of \kvgetonechar has an extra }.

    \par l.201 }{}

    ?

    On the contrary, if any of the two lists is longer than needed, you will not be notified! Moreover, each entry has to be one character long, otherwise — like a variable 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) :

    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

    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 show how 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) :

    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

    You can use any of LATEX’s 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 you may find that the \ovals that you want to draw inside a Karnaugh map are slightly shifted to the right. This occurs if you use the eepic-Package in your document. 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 in your local copy. If you put this new myeepic.sty file somewhere into your TEX’s search path so that TEX can find it and you load it properly with e.g. \usepackage{myeepic}, you shouldn’t experience any more trouble.

    4 Other features

    There are some more features that you can use. Possibly the most important is that you can change the size of the diagrams by changing the size of the boxes within 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 to all changeable parameters and macro definitions in this section!

    5

  • Another feature is that you can switch off the indices inside the map by typing:

    \kvnoindex \karnaughmap{4}{$f:$}{abcd}{0110011001100110}{}

    f :

    0 1

    1 0

    01

    10

    0 1

    1 0

    01

    10 a

    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 :

    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

    Usually, the font size of the map’s contents and indices should be suitable (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 do this in the preamble of your document):

    \renewcommand\kvindexsize{\footnotesize} \karnaughmap{4}{$f:$}{abcd}{0110011001100110}{}

    6

  • 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

    In the same way you can