An alternative way to build a function from the rules of the form fun1 value if fun2 value2 and ... is to pick the most commonly referenced fun name in the conditional side of the rules and then divide the rules into subgroups, as before. If funi is tested for n different values, the rules are divided into n + 1 subgroup. There is one subgroup for each of the n values, and one subgroup for the rules in which funi does not appear. Call these subgroups sg1, sg2, ..., sgn, sgother. Now, instead of combining sgother with each of the other subgroups, which will cause them to be processed more than once, we will process them only once. Here is a pseudocode outline of what the result might look like: if funi == value1 { [the rules having funi value1 in them have the funi value1 pair removed from then and then conditional code from them is generated using the same procedure that I am desribing now.]} else if funi == value2 { [the same thing for the rules having fun1 value2 in them]} ... else if funi == valuen { [the same thing for the nth subgroup of rules]} [now, repeat the process I am describing to the rules in sgother] I haven't told you how this recursion ends. Whenever a group of rules contains a rule with no conditions left, the appropriate string will be assigned to result and then that result will be returned as the value of fun1. The process just described should check for this possibility before splitting a group of rules into subgroups based on the most frequently mentioned function name. The procedure described above deals with the middle part of the body of the fun1 function. The first part, which decides when to return result immediately, is the same as before. Also, after the code that is generated by the procedure just described, the following code is added: result = "unknown"; return result;} closing off the definition of fun1. Here is an example of the kind of code that might be generated for function fun1. We will assume the following rules, with capital letters being names of other functions, and lowercase letters standing for possible values. fun1 a if A b and B c and C d fun1 z if A b and C e fun1 a if A b and D g fun1 u if A f and H b fun1 v if E h and F i and G j Here is the pseudocode: char * fun1() { static char * result = "undecided"; if result != "undecided" return result; if A == b { if C == d { if B == c { result = a; return result;}} else if C == e { result = z; return result;} if D == g { result = a; return result;}} else if A = f { if H == b { result = u; return result;}} if E == h { if F == i { if G == j { result = v; return result;}}} result = "unknown"; return result;} The idea is that when some of the rules seem promising control flows through those rules trying to reach a conclusion while using all the successful decisions so far. If a decision fails to continue testing for the rules in the group being checked, control falls back to a previous level in the tree and tries some other rules that still have some conditions satisfied. If control backs up all the way to the top of the tree, the rules that didn't depend of the test at the top of the decision tree are tried, by exploring a new tree that was generated from them. If you have any questions, let me know.