#Nathan Fox #Homework 19 #I give permission for this file to be posted online ##Read old files read(`C19.txt`): #Help procedure Help:=proc(): print(` NashTest(n) `): end: ##Problem 1 ##BRA case #We have [[R,S],[T,P]]*[[y],[1-y]] = [[R*y+S*(1-y)],[T*y+P*(1-y)]] #So, the payoff is (R*y+S*(1-y))*x+(T*y+P*(1-y))*(1-x). The #coefficient on x is R*y+S*(1-y)-T*y-P*(1-y). Hence, we will have #1 if this quantity is positive, 0 if it is negative, and all x #between 0 and 1 if it is zero. Solving yields (R-S-T+P)*y>P-S. #Hence, if R-S-T+P>0, our 1 condition is y>(P-S)/(R-S-T+P). If #R-S-T+P<0, our 1 condition is y<(P-S)/(R-S-T+P). If R-S-T+P=0, #then the value does not depend on y; it is determined by the #constant term. ##BRB case #We have [x,1-x]*[[R,T],[S,P]] = [[R*x+S*(1-x)],[T*x+P*(1-x)]] #So, the payoff is (R*x+S*(1-x))*y+(T*x+P*(1-x))*(1-y). The #coefficient on y is R*x+S*(1-x)-T*x-P*(1-x). Hence, we will have #1 if this quantity is positive, 0 if it is negative, and all y #between 0 and 1 if it is zero. Solving yields (R-S-T+P)*x>P-S. #Hence, if R-S-T+P>0, our 1 condition is x>(P-S)/(R-S-T+P). If #R-S-T+P<0, our 1 condition is x<(P-S)/(R-S-T+P). If R-S-T+P=0, #then the value does not depend on x; it is determined by the #constant term. ##Problem 2 #If R>T, then [1,1] will be a Nash equilibrium, since both players #will want to cooperate if the other does. #If P>S, then [0,0] will be a Nash equilibrium, since both players #will want to defect if the other does. #If S>P and T>R, then [1,0] and [0,1] will be Nash equilibria, #since A will want to cooperate if B defects, and B will want to #defect if A cooperates, and vice versa #If (T=R and S>=P) or (S=P and T>=R), then there will be no pure #strategy. ##Problem 3 #n = number of iterations NashTest:=proc(n) local i,R,S,T,P,rd,A,B,nash: rd:=rand(-10..10): for i from 1 to n do R:=rd(): S:=rd(): T:=rd(): P:=rd(): print(`R,S,T,P=`): print(R,S,T,P): if R > T then print(`[1,1] should be a Nash equilibrium`): fi: if S > P and T > R then print(`[1,0] should be a Nash equilibrium`): print(`[0,1] should be a Nash equilibrium`): fi: if P > S then print(`[0,0] should be a Nash equilibrium`): fi: if (T = R and S >= P) or (S = P and T >= R) then print(`There should be no pure strategy`): fi: A:=[[R,S],[T,P]]: B:=[[R,T],[S,P]]: nash:=false: #Test [1,1] if BRA(A,1)[1] = 1 and BRB(B,1)[1] = 1 then print(`[1,1] is a Nash equilibrium`): nash:=true: fi: #Test [1,0] if BRA(A,0)[1] = 1 and BRB(B,1)[1] = 0 then print(`[1,0] is a Nash equilibrium`): nash:=true: fi: #Test [0,1] if BRA(A,1)[1] = 0 and BRB(B,0)[1] = 1 then print(`[0,1] is a Nash equilibrium`): nash:=true: fi: #Test [0,0] if BRA(A,0)[1] = 0 and BRB(B,0)[1] = 0 then print(`[0,0] is a Nash equilibrium`): nash:=true: fi: if not nash then print(`No pure strategy`): fi: print(``): od: end: #All the tests I ran confirmed my answer to Problem 2