Rearranging an equation with the variable also in the exponent

Rej

New member
Joined
Apr 5, 2021
Messages
18
I must confess this is beyond what I remember from my school days many decades ago so I am hoping for some help.

I found an equation on-line for win rates and probabilities and added to it to get loss rates as well, that was simple enough. Ultimately I was able to get a list of probabilities such what are the odds to win or lose 2,3,4,5... times in a row.

I put this in a spreadsheet which is here. I made it publicly editable and it's just a copy so do whatever you like to it.

The equation goes like this:

Losing Odds = 1-(1-R^L)^((T-L)*(1-R)+1) . (G4 to G18 in the spreadsheet).

where:

L = Length of run of losses e.g.: 1,2,3,4,5... (E4 to E18 in the spreadsheet)
R = Lose rate e.g.: 20% etc. (C6 in the spreadsheet)
T = Tries: e.g. 100 (C4 in the spreadsheet)

What I want to do is rearrange this so I can solve L (Length of run of losses) given the rest. So in English:

If I know my losing odds to be 20 % over 100 tries then what will my length of run be at a probability of say 1% or less. I hope I worded that well but just in case my wording is muddy, the answer is obvious when looking at the spreadsheet, somewhere between 5 and 6, that being between cells E8 and E9.

With L, (the Length of the Run of Losses) being both in the normal part and the bracketed exponent part of the equation I don't really know how to rearrange this with the little I remember from my school days so help would be very much appreciated.
 
Last edited:
I must confess this is beyond what I remember from my school days many decades ago so I am hoping for some help.

I found an equation on-line for win rates and probabilities and added to it to get loss rates as well, that was simple enough. Ultimately I was able to get a list of probabilities such what are the odds to win or lose 2,3,4,5... times in a row.

I put this in a spreadsheet which is here. I made it publicly editable and it's just a copy so do whatever you like to it.

The equation goes like this:

Losing Odds = 1-(1-R^L)^((T-L)*(1-R)+1) . (G4 to G18 in the spreadsheet).

where:

L = Length of run of losses e.g.: 1,2,3,4,5... (E4 to E18 in the spreadsheet)
R = Lose rate e.g.: 20% etc. (C6 in the spreadsheet)
T = Tries: e.g. 100 (C4 in the spreadsheet)

What I want to do is rearrange this so I can solve L (Length of run of losses) given the rest. So in English:

If I know my losing odds to be 20 % over 100 tries then what will my length of run be at a probability of say 1% or less. I hope I worded that well but just in case my wording is muddy, the answer is obvious when looking at the spreadsheet, somewhere between 5 and 6, that being between cells E8 and E9.

With L, (the Length of the Run of Losses) being both in the normal part and the bracketed exponent part of the equation I don't really know how to rearrange this with the little I remember from my school days so help would be very much appreciated.
You are using a spread-sheet. If it is MS_Excel, you have an equation solver in there, it will give you an approximation of the number. Read up on it.
 
You are using a spread-sheet. If it is MS_Excel, you have an equation solver in there, it will give you an approximation of the number. Read up on it.
I don't have excel but I do have LibreOffice Calc and looking at it I don't see it being able to rearranging the equation using their equivalent, "Goal Seek", certainly I don't see it on Google Sheets. Even if a spreadsheet could do approximations that's not going to help my need because I want the formula to put into my code (software) which has nothing to do with spreadsheets.

That said, I did write some code (I'm about to test/debug) with a couple of loops to do an approximation with the current formula but that's rather inefficient compared to having the formula that gives the answer from the variables at hand which is the ideal way to do it.

Ultimately, I should be able to get by with my code but it would nice to do it efficiently by using a specific formula rather than some looping code.
 
With L, (the Length of the Run of Losses) being both in the normal part and the bracketed exponent part of the equation
You are correct - in this case, I do not know of any "elementary" algebraic operation/s that could solve for 'L'
 
That said, I did write some code (I'm about to test/debug) with a couple of loops to do an approximation with the current formula but that's rather inefficient compared to having the formula that gives the answer from the variables at hand which is the ideal way to do it.

Ultimately, I should be able to get by with my code but it would nice to do it efficiently by using a specific formula rather than some looping code.
If you're concerned with the speed and efficiency of your code then you could consider using an algorithm like binary search (click)or Newton's method (click). Alternatively it might be possible to use the Lambert W function (but before you consider this you should make sure that it's available in your programming language).
 
If you're concerned with the speed and efficiency of your code then you could consider using an algorithm like binary search (click)or Newton's method (click). Alternatively it might be possible to use the Lambert W function (but before you consider this you should make sure that it's available in your programming language).
Thanks but I'm fine. I don't have a need for high accuracy, it's just an estimation. Right now I test in integers and it's never gone above 12 so that's a max of 12 iterations to integer resolution. I then do a 2nd loop at increments of 0.05 so I get to an accuracy of 0.05 with a max of 31 iterations and what seems to be averaging about 12-15 iterations. That's effectively nothing computationally for a modern computer.
 
Thanks but I'm fine. I don't have a need for high accuracy, it's just an estimation. Right now I test in integers and it's never gone above 12 so that's a max of 12 iterations to integer resolution. I then do a 2nd loop at increments of 0.05 so I get to an accuracy of 0.05 with a max of 31 iterations and what seems to be averaging about 12-15 iterations. That's effectively nothing computationally for a modern computer.
Cool. If you ever need to improve your function for accuracy or speed then please post back.

--

FYI: Using Newton's method, if you have a close enough starting guess for "L", then the following (horrendous) expression should give you an improved value for L...

L - ((1 - R^L)^(1 - (T - L)*(R - 1)) + O - 1)/((1 - R^L)^((R - 1)*(L - T) + 1)*ln(R^(R^L*(1 - (1 - R)*(L - T))/(R^L - 1))*(1 - R^L)^(R - 1)))

where O=Losing Odds, and "ln" is the natural logarithm. Or, if you need it written with "pow" instead of "^" (which is more convenient for some computer languages) then...

L - (pow(1 - pow(R, L), 1 - (T - L)*(R - 1)) + O - 1)/(pow(1 - pow(R, L), (R - 1)*(L - T) + 1)*ln(pow(R, pow(R, L)*(1 - (1 - R)*(L - T))/(pow(R, L) - 1))*pow(1 - pow(R, L), R - 1)))
 
Cool. If you ever need to improve your function for accuracy or speed then please post back.
Wow. That's a formula I would just have to use and forget about trying to understand it. I guess I should read up on Newton's method some day.
 
Top