The denominator is the same on all of them, [1+re(1-tie)]^n(1-Te)
I use the second formula with [1+rg(1-tig)]^n(1-Tg) as my base. This assumes the donee pays the tax.
For a tax free gift, remove (1-Tg).
Donor pays tax, add +Tg*Te after (1-Tg). So it should be (1-Tg+Tg*Te).
Charitable gift adds (1+rg)^n+Toi in front. So it should look like (1+rg)^n+Toi[1+rg(1-Tig)]^n(1-Tg)]