Sure thing. I made an error in the orignal formula (since corrected), which might have thrown you off: ...IF[oc<(i*n+s)... should read ...IF[oc<(i*s+n)...
Here's the logic behind the formula
# ways = COMB(oc-1,n-1) + SUM(i=1,n-1) {(-1)^i * IF[oc<(i*s+n),0,COMB(n,i)*COMB(oc-i*s-1,n-1)]}
_____________________________________________
The 1st term COMB(oc-1,n-1):
As posted by Drawmack, presented by K. Ross & C. Wright (Discrete Mathematics (Fourth Edition) by: Kenneth A. Ross & Charles R.B. Wright ISBN: 0-13-096141-8). The total number of ways of summing to a number, oc, with n whole numbers is COMB(oc+n-1,n-1). Think of n-1 as the number of partitions between sets of identical objects, with each set representing a number. The total of all identical objects among all sets is oc.
Ok. To get an oc of 10 with n of 4 means that COMB(oc+n-1,n-1) counts ways like 10|0|0|0, 9|1|0|0, 9|0|1|0, 7|1|1|1, etc. But in our case 10|0|0|0, 9|1|0|0, 9|0|1|0 are examples of ways which shouldn't be counted, because we're using dice to generate our numbers. With 4 dice you'd instead build from 1|1|1|1, using oc-4 as the # of objects to arrange around n-1 partitions. Hence, COMB(oc+n-1-n,n-1) = COMB(oc-1,n-1)
Now, back to the 4d6 outcome 17 example. As I've shown above, the 1st term is COMB(16,3), which is 560.
_______________________________________________
The 1st corrective term -IF[oc<(n+s),0,COMB(n,1)*COMB(oc-s-1,n-1)]}:
For this example,
17 is not less than 4+6, so this term is -COMB(4,1)*COMB(17-6-1,3) = -4*COMB(10,3) = -480.
What does it mean? The problem with the 1st term is that for an outcome like 17 with 4d6, it counts ways like 7|6|3|1. But you can't roll a 7 with a six-sided die, unless you're blitzed. How many ways were erroneously counted? For now just consider the example of one set having at least a 7 (one d6 rolled at least a 7). This leaves behind 17 - 7 - 3 (the other sets still have to have at least one identical object) = 7 objects to place around 3 partitions--you can still place more objects in the 7-hole, getting a higher #. Hence COMB(7+3,3). But wait, this assumes one die has at least a 7--but which one? The 1st term erroneously counted all 4 possibilities, or COMB(4,1). So 7|6|3|1, 6|7|3|1, 6|3|7|1, & 6|3|1|7. Ok, generalizing, we get the 1st corrective term.
________________________________________________
The 2nd corrective term (-1)^2IF[oc<(2s+n),0,COMB(n,2)*COMB(oc-2s-1,n-1)]}:
For this example,
17 is not less than 2*6+4, so this term is +COMB(4,2)*COMB(17-12-1,3) = +6*COMB(4,3) = +24.
This is a correction to the correction. 17 is one of the bigger outcomes for 4d6; one erroneous way to get it is to roll 7|7|2|1.
How many of these terms are there? Restrict two sets to have at least 7, and the other two to have at least one. Then that's 17 - 14 - 2 = 1 object to put around 3 partitions, so figure the combination of 4 things taken 3 (or one) at a time. Or that's 17(oc) - 4(at least one object/set) - 2*6(2 sets have at least six more objects) + 3(partitions) = 17-2*6-1 = 4 things, 3 of which are identical (partitions). Hence, COMB(4,3), generalized to COMB(oc-2*s-1,n-1). But any two sets can be 7s or greater. There are COMB(4,2) ways of arranging 2 sets among 4 where each set is only distinguished by weather it has 7 or more or 6 or less objects. So that's COMB(4,2), or COMB(n,i), generalized. Multiply by COMB(oc-2*s-1,n-1) to get total # of ways to roll (at least 7)|(at least 7)|(6 or less)|(6 or less).
But why is it a correction of the 1st correction? Because for every 7|7|2|1, the 1st correction subtracts twice. Suppose you needed to put just a few more object into
(at least 7)|(exactly 6)|(6 or less)|(6 or less). Usually, if you assign the remaining objects, you'll get (at least 7)|(6 or less)|(6 or less)|(6 or less), like 8|6|2|1 or 7|6|3|1. The 1st correction subtracts these impossibilities away. The exception is when you have (at least 7)|(at least 7)"|(6 or less)|(6 or less). You want to subtract this term away once, but the 1st correction counts (at least 7)|(at least 7)"|(6 or less)|(6 or less) and (at least 7)"|(at least 7)|(6 or less)|(6 or less) as separate things.
________
And so on. This correction-for-a-correction-for-a-correction business gets pretty confusing, and I'm not even sure I've grasped the idea right. What is nice is that it does work for every die combo I've tested.
Hope your forehead hasn't struck your keyboard spasmodically.
HUGE EDIT:
2nd correction corrected. Big sorry folks. Thanks a lot Storminator!