# Manipulating and assuming properties of non explicit functions

With the nice help of this community, I have been able to write this code replicating what is in the main books dedicated to theoretical insurance (I am sorry for the lengh of the code but it is necessary).

First I need this function

def use_prime(expr):
r"""
Return the expression with one-variable function derivatives "primed".
"""
op = expr.operator()
if op:
args = expr.operands()
aargs = (use_prime(a) for a in args)
opp = op
if (isinstance(op, sage.symbolic.operators.FDerivativeOperator)
and len(args) == 1):
name = op.function().name()
primes = "'" * len(op.parameter_set())
opp = function(f"{name}{primes}")
return opp(*aargs)
else:
return expr


then the code

var('x y p w_0 θ I')
assume(p>=0)
assume(p<=1)
assume(θ>=1)
U = function('U')#déclare U comme le nom d'une fonction
EU(x,y,p) = p * U(x) + (1-p) * U(y)
w_1 = function('w_1')
w_1(w_0, π) = (w_0-π)
w_2 = function('w_2')
w_2(w_0, π, x, I, p) = (w_0 - π) - x + I
π = function('π')
π(p,I,θ)=θ*p*I
U = function('U')
EU(x, y, p) = p*U(x) + (1 - p)*U(y)
x, y, p, w_0, θ, I, = SR.var('x y p w_0 θ I')
f = EU(w_1(w_0, π(p,I,θ)),w_2(w_0, π, x, I, π(p,I,θ)) )
h = diff(f, I)
hh = use_prime(h)
k = diff(f, I,2)
kk = use_prime(k)
show(LatexExpr(r'''\text{La condition d'optimalité du premier ordre est } dEU = 0 \text{, soit : } ''' ))
show(LatexExpr(r'\,\,\,\,\,\,\,\,\,\,\,\,\,\, dEU = '),hh, ' = 0')
d2EU=diff(EU(w_1(w_0, π),w_2(w_0, π, x, I, p),p),I,2)
show(LatexExpr(r'''\text{La condition d'optimalité du second ordre est } dEU = 0 \text{, soit : } ''' ))
show(LatexExpr(r'\,\,\,\,\,\,\,\,\,\,\,\,\,\,'),kk, ' < 0')


This should gives this

And now come my questions :

1) Can I assume $U^\prime>0$,$U^{\prime\prime}<0$ and verify with the other asumptions that the second order is verified, without hand manipulation. 2) How to rewrite the first order condition in such a way that all the terms in $U^\prime$ be on right side of the equation (a ratio) and the other terms on the left side ? 3) But, I think to know the answer, how to substitute $x$ to $I$ in the final stage ?

edit retag close merge delete