Ask Your Question

Revision history [back]

You should write

EUa = function('EUa')

instead of

EUa = function('EUa')(p,w0,c,g)

in order to distinguish the function EUa from its value at the point (p,w0,c,g). In this way, you will be able to use the method substitute_function to perform the substitution that you wish. If you want a shortcut for EUa(p,w0,c,g), then you should give it a name distinct from EUa. The next step to achieve what you want is to introduce a callable symbolic expression that contains the value that you want to substitute, e.g.

U = function('U')
EUa_U(p,w0,c,g) = p*U(w0) + (1-p)*U(0)
EUna_U(p,w0,c,g) = p*U(w0-c) + (1-p)*U(g*w0-c)

Then you can perform the substitution via

sol_U = sol.substitute_function(EUa, EUa_U).substitute_function(EUna, EUna_U)

Finally, the second operation that you mention is achieved by

U_1(w) = ln(w)
sol_U.substitute_function(U, U_1)

Here is the full example:

var('p w0 c g dc dg dp dw0')
EUa = function('EUa')
EUa_c = diff(EUa(p,w0,c,g), c)
EUa_g = diff(EUa(p,w0,c,g), g)
#
EUna = function('EUna')
EUna_g = diff(EUna(p,w0,c,g), g)
EUna_c = diff(EUna(p,w0,c,g), c)
#
dEUa = EUa_c*dc + EUa_g*dg 
dEUna = EUna_c*dc + EUna_g*dg
#
sol = solve(dEUa==dEUna, dg)
sol = (sol[0]/dc).full_simplify()
#
U = function('U')
EUa_U(p,w0,c,g) = p*U(w0) + (1-p)*U(0)
EUna_U(p,w0,c,g) = p*U(w0-c) + (1-p)*U(g*w0-c)
sol_U = sol.substitute_function(EUa, EUa_U).substitute_function(EUna, EUna_U)
#
U_1(w) = ln(w)
sol_U.substitute_function(U, U_1)

The outcome is

dg/dc == (g*w0 - c)*((p - 1)/(g*w0 - c) + p/(c - w0))/((p - 1)*w0)