Target AC = a
Attack Bonus = b
Average Damage = c
Hand Multiple = d
Critical Multiple = p
With the above definitions, and with combining only a few of the fractions and constants, I arrived at the follwoing:
Now, my next step is to work out the multiplication and simplification of , then I can differentiate and find the maximum or minimum of the funciton, but firstly I need to make sure I clarify the following things with you:
 When you say 1_FOR_CRITICAL_MISS, do you mean for that value to simply be a 1 there, or is the whole "1_FOR_CRITICAL_MISS" one distinct value? I ask the same question for the phrase "1_FOR_NAT_20".
 All the values that I assigned to variables, are they values that are "constants" in the game? What I mean is that not that they are actually neccesarily constant in the game, but that for any given turn they become real values, and that the x is the deciding variable. In other words, I can only help you if what your looking for is the minimum (or maximum, I can't remember which you were attempting to find) of the function, in terms of all the above variables. So for example, the minimum or maximum would be some expression containing some or all of the variables I assigned above.
 The way you defined your question and itself was very confusing. Granted, maybe this wasn't actually due to the manner in which you defined , but rather the complexity of the problem that seemed to manifest the confusion. Either way, in noting that I myself was alittle confused by the question and the definition for , I ask you to take a second look at what I came up for and any comments I have made in this post and please tell me if you see any errors or mistakes in my understanding of your question.
If you can clarify the above questions for me, I think I'll be able to hammer out the maximum (or minimum, I can't remember which one you were trying to find) of the function , in terms of