1. A method, implemented on one or more processors, of solving the problem of decision, searching, counting and optimizing, the method comprising: decomposing an input into sub inputs as pairs of generators; and classifying the sub inputs in one of several classes by testing if one to one of three possible relations holds.