T = ln([1+ROI*(1/SR-1)/SWR]/[1+ROI*(1/SR-1)*AoE])/ln(1+ROI)

T = time to retirement, in years

ROI = return on investment during accumulation, in real terms (4% is 0.04)

SR = savings rate (50% = 0.5)

SWR = safe withdrawal rate

AoE = assets over expenses, number of years worth of expenses you have saved

Edit: fix equation