#C21.txt: April 11, 2013: Iterated Prisoner's Dilemma #according to Bill Press and Freeman Dyson Help:=proc(): print(` SS(T) , Apq(p,q), sX(R,S,T,P,p,q), sY(R,S,T,P,p,q) `): print(` FixIncomeY(R,S,T,P,p,Amount) `): end: ##SS(T): inputs a stochastic matrix T #given as a list of lists, where T[j][i] #is the prob. of moving in one step from #state j to state i.Outputs a prob. vector v #of length nops(T), such that after googol days #your prob. of being at state is v[i] # i.e. the solution of v T= v #v(T-I)=0 SS:=proc(T) local i,j,eq,var,n,v: n:=nops(T): var:={seq(v[i],i=1..n)}: #v[i]=v[1]*T[1][i]+v[2]*T[2][i]+ ... +v[n]*T[n][i] eq:={seq( v[i]=add(v[j]*T[j][i],j=1..n), i=1..n)}: eq:=eq union { add(v[i],i=1..n)=1}: var:=solve(eq,var): subs(var,[seq(v[i],i=1..n)]): end: #Apq(p,q): Given the prob. strategy of X, p #and of Y, q Apq:=proc(p,q) [ [p[1]*q[1],p[1]*(1-q[1]), (1-p[1])*q[1],(1-p[1])*(1-q[1])], [p[2]*q[3],p[2]*(1-q[3]), (1-p[2])*q[3],(1-p[2])*(1-q[3])], [p[3]*q[2],p[3]*(1-q[2]), (1-p[3])*q[2],(1-p[3])*(1-q[2])], [p[4]*q[4],p[4]*(1-q[4]), (1-p[4])*q[4],(1-p[4])*(1-q[4])] ]: end: #sX(R,S,T,P,p,q): The ultimate pay-off per day of play #of player X sX:=proc(R,S,T,P,p,q) local v: v:=SS(Apq(p,q)): v[1]*R+v[2]*S+v[3]*T+v[4]*P: end: #sY(R,S,T,P,p,q): The ultimate pay-off per day of play #of player X sY:=proc(R,S,T,P,p,q) local v: v:=SS(Apq(p,q)): v[1]*R+v[2]*T+v[3]*S+v[4]*P: end: #FixIncomeY(R,S,T,P,p,Amount): #Finds those p (in terms of parameters p[1], ..., p[4] #that forces player Y to always get Amount no matter #what q is FixIncomeY:=proc(R,S,T,P,p,Amount) local eq,i, q,freeman, tent, dyson: eq:= {seq(sY(R,S,T,P,p,[0$(i-1),1,0$(4-i)])=Amount,i=1..4), sY(R,S,T,P,p,[1/3,1/4,3/5,2/5])=Amount }: freeman:={solve(eq,{seq(p[i],i=1..4)})}: dyson:={}: for i from 1 to nops(freeman) do tent:=subs(freeman[i],[p[1],p[2],p[3],p[4]]): if normal(sY(R,S,T,P,tent,q)-Amount)=0 then dyson:= dyson union {tent}: fi: od: dyson: end: