K-maps

kmap is a specialisation of var, and simplifies the specification and testing of combinatorial functions which can be expressed as Karnaugh maps. For example, the figure below shows a 5-variable K-map, together with the Maia code required to declare and access this K-map:

// declare a 5-variable Karnaugh map
kmap m5 =
      1 1 1 0   1 0 1 1
      0 1 0 1   0 1 0 1
      1 0 1 0   1 0 1 0
      0 1 1 1   1 1 0 1;

// examples of K-map usage, using Algol-style indexing:
assert(m5[0,0,0,0,0] == 1);   // top-left element:     ABCDE = 00000 =  0
assert(m5[1,0,0,0,0] == 1);   // top-right element:    ABCDE = 10000 = 16
assert(m5[0,0,0,1,0] == 0);   // bottom-left element:  ABCDE = 00010 =  2
assert(m5[1,0,0,1,0] == 1);   // bottom-right element: ABCDE = 10010 = 18

Note that m5 is essentially an array, but is not declared using square bracket notation. In this case, the compiler determines that m5 is a 5-dimensional array (with an equivalent declaration of m5[2][2][2][2][2]), and it handles the re-indexing required to access the array using reflected Gray code indices.

K-maps support the logical and comparison operators, assignment, and compound assignment. They are assignment-compatible only with other K-maps of the same number of variables. A single element extracted from a kmap with an indexing operation is a 1-bit var. It is not possible to extract anything other than a single element (a row or a column, for example) from a kmap.