Well, like a song trapped in my head, this question has haunted me for a while. I don’t claim to have solved it, but I think that I’ve developed some ideas that simplify the calculation. The first idea is that of using a matrix’s profile.
There’s probably some other name for it in the mathematical literature, so let me explain what I mean by “profile”. The profile of a matrix is just that matrix viewed from one side, essentially an ordered list of sets of number. For example, the 3x3 matrix:
1 2 3
4 5 6
7 8 9
has a horizontal profile of { (1, 2, 3), (4, 5, 6), (7, 8, 9) } and a vertical profile of { (1, 4, 7), (2, 5, 8), (3, 6, 9) }. The number of profiles for a matrix made up of the numbers 1 through 9 is 9 choose 3 * 6 choose 3 * 3 choose 3 = 1680. The hope is that we can break down the problem into steps where the temporary results can be described by profiles, each profile having a count of how many solutions to that point have that profile.
Note that when I write matrix below, I mean only a 3x3 grid. I hope I don’t confuse anybody by my terminology, but I’ve been thinking about this problem using these terms up to this point, and they seem natural to me.
Next we want to decrease the search space. As noted by others, we can specify that one of the 9 matrices, say the top left, can have its order explicitly set, and merely multiply the solution by 9!. We can also say that for the three middle columns, that we can easily permute their order and still have a valid answer, so we can specify a strict ordering for them and then multiply the final result by 6. We can also do this for the final 3 columns, the center 3 rows, and the final 3 rows, and then multiply the final result by 6[sup]4[/sup]. Finally, we can see that we can swap the center 3 columns with the final 3 columns and again have no loss of generality, so we can again specify a strict ordering for the two of them, as well as the center and bottom bars, and multiply the result by 4.
Another speedup is to analyze how many permutations can exist for a particular horizontal profile for a matrix when it must meet the sudoku condition vertically with respect to another matrix. It turns out that for that particular horizontal profile, there are exactly 0 or 8 valid permutations. The proof is as follows: for any row R of a matrix’s horizontal profile H, the three elements show up in either 1, 2, or 3 distinct columns of the vertically constraining profile V. If all three elements are in one column, then there is no number to place in that column and therefore there are no valid matrices for this profile, regardless of the other two rows this profile. If the elements are in two distinct columns, then two of the elements must be in one column, and one element in another. The latter element is therefore the only element that can go into the column forbidden to the first two, and then there are two permutations of the other two elements in the remaining two spaces. Finally, if all three elements are in distinct columns, then there are also two permutations allowed: where the element forbidden from column 1 is in column 2, the element forbidden from column 2 is in column 3, and the element forbidden from column 3 is in column 1; or where the element forbidden from column 1 is in column 3, the element forbidden from column 3 is in column 2, and the element forbidden from column 2 is in column 1. Since there are 3 rows, either at least one of the rows is forbidden, in which case there are 0 valid permutations, or all 3 rows are permitted, in which case exactly 2[sup]3[/sup] = 8 are permitted.
The basic algorithm is as follows: start off with the fixed matrix in the top left corner. There are 56 valid profiles for its horizontal neighbor. Each of those profiles combined with the fixed matrix’s profile specify an exact profile for the matrix in the upper right corner. We only need to concern ourselves with half of those, since for each solution we can swap the middle matrix with the right matrix and have exactly one of the other solutions. Next, for each of those matrices, there are 216 different permutations of the top, middle, and bottom rows. We can drop that down to 36 each since we can specify an exact ordering for the 3 resultant columns in each matrix. Finally, for all of those solutions we have generated, there is a 9-set vertical profile, of which the first 3 sets will always be (1, 4, 7), (2, 5, 8), and (3, 6, 9). For each profile, we would store the number of permutations that have that particular vertical profile. I have already written a program to calculate them, and there are 22266 distinct profiles.
Next, using similar math we can calculate 28 different vertical profiles to look at for the center left matrix and the 36 relevant permutations of each of those. It turns out that there will be only 225 distinct horizontal profiles for those 1008 vertical profiles; 27 with 8 vertical profiles and the remainign 198 with 4 vertical profiles. Now here, I believe that the right way to procede would be to iterate through those distinct profiles. For each one of those horizontal profiles H, we would iterate through the 22266 distinct vertical profiles V of the top blocks. For each pairing (H, V), there are 56 (note, not 28 – we’ve already exploited the search space’s symmetry) possible horizontal profiles of the center matrix C and a single counterpart R for the right matrix. If any of the rows of C are identical to the center 3 columns of V, then this combination is invalid. If any of the rows of R are identical to the right 3 columns of V, then this combination is invalid. Otherwise, there are 64 (8 * 8) valid permutations of the elements of C and R. We determine the vertical profile of these permutations along with the valid permutations of H and note that, together with V they express an inverse profile – the inverse of the elements that would be allowed in the vertical profile of the bottom bar. Similar to the creation of the 22266 vertical profiles, we will then add the count on the vertical profile V to the bottom bar profile in question. Once all of those profiles have been created and enumerated, we go through the bottom profiles. For each one of those, there are 36 permutations of the left matrix to consider. For each of those permutations there are either 0 or 8 valid permutations of the center matrix. If there are 8, then there is either 0 or 1 valid matrix for the right-hand matrix. We can iterate over all of these and count them up. If the estimate of 6 *10[sup]21[/sup] is right, then the total that we’ll be counting up will be about 3 trillion, well within the limits of 64-bit integers – remember, we’ve already divided out 9! * 6[sup]4[/sup] * 4 = 1881169920.
Obviously, the middle part is the bottleneck in the calculation. It will take about 225 * 22266 * (56 * 64) = ~18 billion steps to do, with each step taking 100-200 operations. It will need to store values for 28 * 1680[sup]2[/sup] = ~8 million different profiles for the bottom bar. I can’t really see how to simplify it any more. Those numbers are right on the threshhold of what todays computers can do in a reasonable amount of time. The nice thing about it, though, is that it’s easily parallelizable. It’s still a work in progress, so if you have anything to add or point out, feel free to say it.