This gives a nice result.
var('p w0 c g dc dg dp dw0')
EUa=function('EUa')(p,w0,c,g)
EUa_c=diff(EUa,c)
EUa_g=diff(EUa,g)
#
EUna=function('EUna')(p,w0,c,g)
EUna_g=diff(EUna,g)
EUna_c=diff(EUna,c)
##
dEUa=EUa_c*dc + EUa_g*dg
dEUna=EUna_c*dc + EUna_g*dg
###
show(EUa)
show(EUna)
show(dEUa)
show(dEUna)
sol=solve(dEUa==dEUna, dg)
sol=(sol[0]/dc).full_simplify()
show(sol)
But now, I would like to substitute to EUa(p,w0,c,g) = p*U(w0)+(1-p)*U(0)
and EUna(p,w0,c,g) = p*U(w0-c)+(1-p)*U(g*w0-c)
then, later change the unknown function U(w)
to say ln(w)
or w^(1/2)
.