Let's say I have a matrix of cases. A row of the matrix corresponds to a sensor in a physical system, and a column of the matrix corresponds to a state that the system can be in. The entries in the matrix itself correspond to, say, a safe high limit for the sensor in that row. Here's an example:

http://quicklatex.com/cache3/ql_9c51...d65d09a_l3.png

The code used to produce this table is as follows:

\begin{tabular}{c|ccc}&\text{Off} &\text{Start} &\text{Run}\\ \hline \text{Temp} &90^{\circ}\text{C} &100^{\circ}\text{C} &150^{\circ}\text{C}\\ \text{Pressure} &10 \text{psig} &20 \text{psig} &30 \text{psig}\end{tabular}

Now, then. I need to create nested case structures to handle outputting these limits to the checking routine. I want to minimize the total number of cases I have to code by altering the nesting of the cases. I can either check by state first, or by sensor first. For example, if the rows were "more uniform", then it would be better to have the state checking nested inside the sensor checking thus:

Code:

case sensor
Temp
case state
Off
Start
Run
end case
Pressure
case state
Off
Start
Run
end case
end case

That way, I could have fewer outer entries (I can combine cases if they're the same). On the other hand, if the columns were "more uniform", then it would be better to reverse the nesting order thus:

Code:

case state
Off
case sensor
Temp
Pressure
end case
Start
case sensor
Temp
Pressure
end
Run
case sensor
Temp
Pressure
end case
end case

So I was thinking about a way to quantify whether the rows or columns are "more uniform". Here's my thought: to measure the uniformity of the columns, take each column, find its cardinality (the number of different items in that column), and sum over all the column cardinalities. To measure the uniformity of the rows, take each row, find its cardinality, and sum over all the row cardinalities.

If the sum of the row cardinalities is smaller than the sum of the column cardinalities, then have the row cases on the outside. If the sum of the row cardinalities is greater than the sum of the column cardinalities, then have the row cases on the inside.

Here's my question: will this procedure minimize the number of cases I have to code?

Thank you!