#C8.txt Help8:=proc(): print(` PayOffGG(G,p1,p2), MNE2(G), BRLG(f,var) `): end: with(combinat): #PayOffGG(G,p1,p2): Inputs a 2-player game with m:=nops(G) strategies for player Row, and n:=nops(G[1]) strategies for Player Col #given in terms of its bi-matrix, and probability vectors [p1[1],...p1[m]] and probabilty vectors [p2[1],...p2[m]] #outputs the pay-off vectors PayOffGG:=proc(G,p1,p2) local i1,i2,m,n: m:=nops(G): n:=nops(G[1]): if not (nops(p1)=m and nops(p2)=n) then print(`bad input`): RETURN(FAIL): fi: [add(add(G[i1][i2][1]*p1[i1]*p2[i2],i2=1..n),i1=1..m), add(add(G[i1][i2][2]*p1[i1]*p2[i2],i2=1..n),i1=1..m)]: end: #BRLG(f,var): Given a linear expression f in x[1],..., x[nops(x)] finds the best response conditions as a set of sets of condtions #Try: #BRLG(a1*x+a2*y+a3*z,{x,y,z}); BRLG:=proc(f,var) local S,s,sC,CON,s1,i1: S:=powerset(var) minus {{}}: CON:={}: for s in S do sC:=var minus s: CON:=CON union {{add(s1,s1 in s)=1, seq(coeff(f,s[1],1)>coeff(f,s1,1),s1 in sC), seq(coeff(f,s[1],1)=coeff(f,s[i1],1),i1=2..nops(s))}}: od: CON: end: #MNE2(G): The set of mixed Nash equilibria for a 2-person game with each player having two strategies, where G is given #as a 2 by 2 bimatrix. It gives all the pairs (p1,p2) such that if #Player Row plays stragety R1 with prob. p1 (and hence strategy R2 with prob. 1-p1) #and Player Col plays stragety C1 with prob. p2 (and hence strategy C2 with prob. 1-p2) #these stochastic stragies are Best responses to each other, in the sense that for either player #deviating from them (while the other player keeps his or her strategy) will make her or his #EXPETED payoff worse. Try: #G:=RG(3,3,100); MNE2(G): MNE2:=proc(G) local p1,p2,P, m,n,L1,L2,i1,i2,eq,j,S,sol: m:=nops(G): n:=nops(G[1]): P:=PayOffGG(G,[seq(p1[i1],i1=1..m)],[seq(p2[i1],i1=1..n)]): L1:=BRLG(P[1],{seq(p1[i1],i1=1..m)}): L2:=BRLG(P[2],{seq(p2[i1],i1=1..n)}): S:={}: for i1 from 1 to nops(L1) do for i2 from 1 to nops(L2) do eq:={seq(p1[i1]>=0,i1=1..m),seq(p1[i1]<=1,i1=1..m), seq(p2[i1]>=0,i1=1..n),seq(p2[i1]<=1,i1=1..n), add(p1[i1],i1=1..m)=1,add(p2[i1],i1=1..n)=1} union L1[i1] union L2[i2]: sol:=[solve(eq,{seq(p1[i1],i1=1..m),seq(p2[i1],i1=1..n)})]: for j from 1 to nops(sol) do S:=S union {subs(sol[j], [[seq(p1[i1],i1=1..m)],[seq(p2[i1],i1=1..n)]])}: od: od: od: S: end: