#C19.txt: Nash equilibrium
Help:=proc(): print(`BRA(A,y), BRB(B,x), NE2(A,B)`):
print(`BRAs(A,x,y) , BRBs(B,y,x)`):
end:
#NE2(A,B):inputs two 2 by matrices A=[[CC,CD],[DC,DD]]
#indicating what the first player (player A) would get
#if he cooperates/defects and the player B cooperates defects
#and B=[[CC,CD],[DC,DD]] the same for player B
#In Sigmund's book T=DC (temptation) S=CD (sucker)
#P=DD (punishment), R=CC (reward)
#outputs set of {[x,y]} that are Nash equilibrium
#meanaing A should cooperate with prob x. (defect with prob. 1-x)
#B with prob. y
NE2:=proc(A,B)
print(`Not yet started`):
end:
#BRA(A,y): The Best Response for A to B's decision to
#cooperate with prob. y
BRA:=proc(A,y) local x, PayOff,v:
v:=[A[1][1]*y+A[1][2]*(1-y), A[2][1]*y+A[2][2]*(1-y)]:
PayOff:=v[1]*x+v[2]*(1-x):
if coeff(PayOff,x,1)>0 then
RETURN(1, subs(x=1,PayOff)):
elif coeff(PayOff,x,1)<0 then
RETURN(0, subs(x=0,PayOff)):
else
RETURN(x,PayOff):
fi:
end:
#BRB(B,x): The Best Response for B to A's decision to
#cooperate with prob. x
BRB:=proc(B,x) local y, PayOff,v:
v:=[B[1][1]*x+B[2][1]*(1-x), B[1][2]*x+B[2][2]*(1-x)]:
PayOff:=v[1]*y+v[2]*(1-y):
if coeff(PayOff,y,1)>0 then
RETURN(1, subs(y=1,PayOff)):
elif coeff(PayOff,y,1)<0 then
RETURN(0, subs(y=0,PayOff)):
else
RETURN(y,PayOff):
fi:
end:
#BRAs(A,x,y): The Best Response for A to B's decision to
#cooperate with prob. y for symbolic y
#the output would give you an expression in terms of y
#{[Exp1(y), PayOff, Cond(y)]}
BRAs:=proc(A,x,y) local PayOff,v,J1,J1a:
v:=[A[1][1]*y+A[1][2]*(1-y), A[2][1]*y+A[2][2]*(1-y)]:
PayOff:=v[1]*x+v[2]*(1-x):
J1:=coeff(PayOff,x,1):
[ [ 1, subs(x=1,PayOff) ,J1>0], [x,PayOff,J1=0],
[0, subs(x=0,PayOff) , J1<0]]:
end:
#BRBs(B,x,y): The Best Response for A to B's decision to
#cooperate with prob. y for symbolic y
#the output would give you an expression in terms of y
#{[Exp1(y), PayOff, Cond(y)]}
BRBs:=proc(B,y,x) local PayOff,v,J1:
v:=[B[1][1]*x+B[2][1]*(1-x), B[1][2]*x+B[2][2]*(1-x)]:
PayOff:=v[1]*y+v[2]*(1-y):
J1:=coeff(PayOff,y,1):
[ [ 1, subs(y=1,PayOff) ,J1>0], [y,PayOff,J1=0],
[0, subs(y=0,PayOff) , J1<0]]:
end:
#IsNE(A,B,x0,y0): Is player A cooperating with prob. x
#and player B cooperating with prob. y a Nash equilibrium?
#i.e. if x0 a member of subs(y=y0,BRAs(A,x,y))
#and y0 is a member of subs(x=x0, BRBs(B,y,x))
IsNE:=proc(A,B,x0,y0) local x,y,F1,F2:
print(`Not yet started`):
end: