Okay,
I have a spreadsheet which works for up to 9d6. From that I extracted a symbolic function which works for any number of dice, keeping any number, with any number of sides as long as they have the same number of sides. Unfortunately, I cannot figure out how to make one of these nice graphics of the function to post it. In any case, the formula is so complicated that it would take a rather large graphic to understand it. I have included a MS word doc with the equation as a MS Equation 3.0 object. If this is not adequate, perhaps some enlightened soul can make a graphic out of it, or tell me how to do so in Word or Mathcad.
First of all, I am confident the spreadsheet is correct, but I have not tried to test my symbolization of it. Second of all, it is a bunch of summations, but it's not as bad as it looks. Finally, I came up with some kludges to make it work symbolicaly, but perhaps someone with a more theoretical math background can clean it up.
What the equation does is run through all possible sorted combinations of the kept dice that add up to the specified value, and figures out the number of combinations that result in that sorted set of kept dice, sums them all up, and divides by total possible combinations. Where the trick comes in is that figuring out the number of combinations requires a multinomial coefficient, but the inputs to the multinomial coefficient depend on how many and which values on the kept dice are equal to each other. That's what the c_j's calculate.
To represent this, I kludged up the functions represented by circle plus and circle times. Circle plus returns a 1 if the two values are equal, and a 0 if they aren't. Circle times returns a 1 if they aren't equal, and a 0 if they are (it's the negation of circle plus, and is included to clean up the main function a bit). Perhaps there is some better way to represent this mathmatically, but if there is I don't know it.
die kluge, I have a python module that will calculate the exact probability distribution (including mean, median, and standard deviation) of just about any combination of dice you could think of, using brute force. For a reasonable number of dice, it's quite fast. If you (or someone else) wants it, let me know.