using Roots

function opt2τσ(γ,cFrac)
    c = cFrac*γ^2
    lhs(τ) = exp(2τ/γ)*(γ^2-c)*(γ-2)+2exp(τ/γ)*γ*(γ-τ*(γ-1))-γ*(γ^2-c)
    find_zero(lhs,(0,20))
end

function optReward(γ,cFrac)
    A₁(τ,γ) = exp(2τ/γ)*((τ-1)*γ^3-(3τ-2)*γ^2 + 2τ*γ) -2exp(τ/γ)*γ^2*(1-γ)^2 + 2γ^4 + (τ-3)*γ^3 - τ*γ^2
    A₂(τ,γ) = (γ-1)*(exp(2τ/γ)*(γ-2) + γ)
    A₃(τ,γ) = γ^3+(τ-2)*γ^2-τ*γ-exp(2τ/γ)*(γ^3-(τ+2)*γ^2 + 3τ*γ-2τ)
    g(τ,γ,c) = (A₁(τ,γ) - c*A₂(τ,γ))/A₃(τ,γ)
    
    c = cFrac*γ^2
    τ̂ = opt2τσ(γ,cFrac)
    g(τ̂,γ,c)
end


# opt2τσ(0.4,0.7)

# optReward(0.4,0.5)