# OK to post homework # RDB, 2022-01-30, HW3 # 1. I identify as etc. etc. # 2. Done. # 3. (* [[13*, 8*] [14*, 6] [11, 4] [6, 5] ] 13 [ ] [[9, 10] [1, 11*] [16*, 3] [7, 9] ] 1 [ ] [[3, 2] [2, 7] [12, 15*] [5, 1] ] 12 [ ] [[4, 13] [10, 16*] [8, 12] [15*, 14]] 10 8 6 3 14 Assuming that the column player will maximize their return, the row player will choose row 1, then the column player will choose column 8. Assuming the same thing about the row player, the column player will choose column 4, and the row player will choose row 4. Nash equilibrium: [1, 1] *) (* [[30, 28] [16, 13] [15, 21] [11, 2] [17, 23] [29, 15] [28, 33]] 28 [ ] [[32, 27] [1, 35] [26, 17] [31, 16] [12, 11] [9, 19] [22, 1] ] 1 [ ] [[18, 6] [13, 9] [24, 29] [8, 26] [25, 32] [33*, 34*] [10, 10]] 33 [ ] [[34*, 30*] [27, 25] [2, 12] [23, 20] [20, 22] [4, 8] [14, 24]] 34 [ ] [[21, 3] [6, 5] [3, 4] [19, 31] [5, 7] [7, 14] [35, 18]] 19 30 25 17 16 32 34 18 Row first: [4, 1] Column first: [3, 6] Nash equilibria: [3, 6], [4, 1] *) # 4. with(combinat): AllGames := proc(a, b) games := []: k := 0: N := (a * b)!^2: for rowPayoffs in permute(a * b) do for colPayoffs in permute(a * b) do game := [seq([seq([rowPayoffs[b * i + j + 1], colPayoffs[b * i + j + 1]], j=0..b-1)], i=0..a-1)]: games := [op(games), game]: if k mod 10000 = 0 then print(evalf(k / N)): fi: k := k + 1: od: od: games: end: # 5. read "hw2RDB.txt": read "C3.txt": FullStat := proc(a, b) # For efficiency purposes, I will not use AllGames, because that computes # every game first, *then* iterates over the list. This is terribly # inefficient for a number of potential reasons. counts := [0, 0, 0, 0, 0, 0]: k := 0: N := (a * b)!^2: for rowPayoffs in permute(a * b) do for colPayoffs in permute(a * b) do game := [seq([seq([rowPayoffs[b * i + j + 1], colPayoffs[b * i + j + 1]], j=0..b-1)], i=0..a-1)]: if k mod 10000 = 0 then print(evalf(k / N)): fi: nash := nops(PureNashEqui(game)): if nash = 0 then counts[1] := counts[1] + 1: elif nash = 1 then counts[2] := counts[2] + 1: elif nash = 2 then counts[3] := counts[3] + 1: fi: RC := [DynRC(game)]: CR := [DynCR(game)]: if RC[2][1] < CR[2][1] then counts[4] := counts[4] + 1: fi: if CR[2][2] < RC[2][2] then counts[5] := counts[5] + 1: fi: if RC = CR then counts[6] := counts[6] + 1: fi: k := k + 1: od: od: counts: end: # Here's a fun test. # with(CodeTools[Profiling]): # Profile(FullStat): # Profile(AllGames): # FullStat(3, 2): # I'm not brave enough to run this on (3, 2). # AllGames(2, 2): # PrintProfiles(FullStat); # PrintProfiles(AllGames);