3.3: Using Sage to Graph Lines and Solve Equations
In this section we will use technology to graph lines and solve for the intersection point. In particular, we will use an open online resource called Sage .
Let's continue to consider the game given in Table \(3.2.1\) by
| Table \(3.3.1\): Example \(3.1.1\) with Named Strategies | ||
|---|---|---|
| C | D | |
| A | \(1\) | \(0\) |
| B | \(-1\) | \(2\) |
Recall, our goal is to determine how often Player 1 should play A and how often she should play B.
We will follow the same steps as in Section 3.2 . Let \(p\) be the probability that Player 1 plays B. Let \(m\) be the payoff to Player 1. Since we are trying to find a mixed strategy for Player 1, we will pick a strategy for Player 2 and try to determine the possible payoffs for Player 1.
Let us determine some pairs \((p, m)\text{.}\)
Step 1: Assume Player 2 plays pure strategy \(C\text{.}\)
Step 1a: If Player 1 always plays \(A\text{,}\) then we are considering the strategy pair \([A, C]\text{.}\) Since Player 1 never plays \(B\text{,}\) \(p=0\text{.}\) The payoff to Player 1 for \([A, C]\) is \(m=1\text{.}\) Thus, for the strategy pair \([A, C]\) we get \((p, m)=(0, 1)\text{.}\)
Step 1b: If Player 1 always plays \(B\text{,}\) then we are considering the strategy pair \([B, C]\text{.}\) Since Player 1 always plays \(B\text{,}\) \(p=1\text{.}\) The payoff to Player 1 for \([A, C]\) is \(m=-1\text{.}\) Thus, for the strategy pair \([B, C]\) we get \((p, m)=(1, -1)\text{.}\)
Step 1c: Now we want to know what Player 1's payoff will be as she varies the probability, \(p\text{,}\) with which she plays \(B\text{.}\) We can draw a graph where the \(x\)-axis represents to probability with which she plays B (\(p\)) and the \(y\)-axis represents the expected payoff (\(m\)). Thus, when Player 1 plays only \(A\text{,}\) she is playing \(B\) with probability \(0\); when Player 1 plays only B, she is playing B with probability \(1\). It might be easier to remember if you label your graph as in Figure \(3.2.1\).
Step 1d: Now we can use Sage to plot the points we determined in Step 1a and Step 1b and the line between them. This line represents Player 2's pure strategy \(C\text{.}\) See Figure \(3.2.2\). Click on the “run” button to plot the line between the points \((0, 1)\) and \((1, -1)\text{.}\)
Before moving on, let's again, make sure we understand what this line represents. Any point on it represents the expected payoff to Player 1 as she varies her strategy, assuming Player 2 only plays \(C\) . In this case, we can see that as she plays \(B\) more often, her expected payoff goes down. You can now use this Sage cell to plot any line for Player 2's pure strategy \(C\text{.}\) Just edit the values for the points \(u\) and \(v\text{.}\) Go ahead and try it! (Don't worry the original values will reset when you refresh the page.)
Now let's do the same thing, assuming Player 2 plays only \(D\text{.}\)
Step 2: Assume Player 2 plays pure strategy \(D\text{.}\)
Step 2a: If Player 1 always plays \(A\text{,}\) then we are considering the strategy pair \([A, D]\text{.}\) Since Player 1 never plays \(B\text{,}\) \(p=0\text{.}\) The payoff to Player 1 for \([A, D]\) is \(m=0\text{.}\) Thus, for the strategy pair \([A, D]\) we get \((p, m)=(0, 0)\text{.}\)
Step 2b: If Player 1 always plays \(B\text{,}\) then we are considering the strategy pair \([B, D]\text{.}\) Since Player 1 always plays \(B\text{,}\) \(p=1\text{.}\) The payoff to Player 1 for \([B, D]\) is \(m=2\text{.}\) Thus, for the strategy pair \([B, D]\) we get \((p, m)=(1, 2)\text{.}\)
Step 2c: Now, on our same graph from Step 1, we can plot the points we determined in Step 2a and Step 2b. We will connect them with a line representing Player 2's pure strategy \(D\text{.}\) See Figure \(3.2.3\).
Now we can see that if Player 2 plays only \(D\text{,}\) then Player 1 does best by playing only \(B\text{.}\) Again, you can use this Sage cell to plot both Player 2's pure strategies. Points \(u\) and \(v\) are for strategy \(C\text{,}\) while points \(w\) and \(z\) are for strategy \(D\text{.}\)
As we saw in Section 3.2 , for each choice of \(p\text{,}\) the top line represents the highest expected value for Player 1; the bottom line represents the lowest expected value for Player 1; the area between the lines represents the possible expected values for Player 1. Thus, Player 1 wants to maximize the minimum expected value, which means she wants to find the maximin strategy. And, as we saw in Section 3.2 , the maximin strategy occurs at the intersection of the two lines.
Step 3: Find the intersection of the two lines.
Step 3a: Find the equation for Line C. This is the line passing through the points \((0, 1)\) and \((1, -1)\text{.}\) It has slope \(-2\) and \(y\)-intercept \(1\). Thus, it has equation \(m=-2p+1\text{.}\) (Recall the \(x\)-axis represents probability \(p\) and the \(y\)-axis represents expected payoff \(m\text{.}\))
Step 3b: Find the equation for Line D. This is the line passing through the points \((0, 0)\) and \((1, 2)\text{.}\) It has slope \(2\) and \(y\)-intercept \(0\). Thus, it has equation \(m=2p\text{.}\)
Step 3c: Now we can use technology to help us solve the equations.
The solution for Player 1 is \((p, m)\text{.}\) Where \(p\) is the probability Player 1 plays B, and \(m\) is the expected payoff to Player 1.
We can use this Sage cell to solve for \(p\) and \(m\) for any \(2\times 2\) game by editing the equations \(m==-2*p+1, m==2*p\text{.}\)
Step 4: Determine Player 1's maximin mixed strategy. Recalling that \(p\) is the probability that Player 1 plays \(B\text{,}\) we know that Player 1 will play \(B\) with probability \(\dfrac{1}{4}\), and thus, play A with probability \(\dfrac{3}{4}\). The expected payoff for Player 1, \(m\text{,}\) is \(\dfrac{1}{2}\). It is important to check the algebraic solution with where the intersection point appears on the graph. Although we are using technology to help us graph and solve for the intersection point, we need to be able to catch any errors we make entering the information into Sage.
We have seen that we can use the same matrix with Player 1's payoffs to find the strategy for Player 2. Using the same game matrix as above:
and continuing to label Player 1's strategies by \(A\) and \(B\text{,}\) and Player 2's strategies by \(C\) and \(D\text{,}\) we can graph lines for Player 1's pure strategies \(A\) and \(B\text{.}\) We now let the \(x\)--axis represent the probability that Player 2 plays \(D\text{.}\) In the Sage applet below, for \(u\) and \(v\) enter the coordinates of two points that determine the line for when Player 1 plays \(A\text{,}\) then the two points for \(w\) and \(z\) that determine the line for when Player 1 plays \(B\text{.}\) We will then have Sage graph the lines. You can enter new values for \(u, v, w, z\) if you would like to draw the graph for a different matrix.
Now determine and enter the equations of the two lines and have Sage solve for the intersection point.
You can now use these last two Sage cells to solve any \(2 \times 2\) game with a mixed strategy equilibrium. You can also take some time to experiment with what happens if the game has a pure strategy equilibrium.
Now use the Sage cells to help you analyze some more games!
Consider the zero-sum game \(\begin{bmatrix}-4 & 4 \\2 & -2 \end{bmatrix}\).
- Does this game have a pure strategy equilibrium?
- Just by looking at the matrix, do you think this game will be fair? (Would you rather be Player 1 or Player 2?)
- Use Sage to draw the appropriate graph for this game. Which pure strategy does the blue line represent? Which pure strategy does the red line represent?
- Use your graph to determine if there is a mixed strategy equilibrium point. If there is, use Sage to determine how often Player 1 should play each strategy. What is the expected payoff to each player?
- Is this game fair? Explain. Compare your answer to (b).
Consider the zero-sum game \(\begin{bmatrix}0 & 1 \\1 & -10 \end{bmatrix}\).
- Does this game have a pure strategy equilibrium?
- Just by looking at the matrix, do you think this game will be fair? (Would you rather be Player 1 or Player 2?)
- Use Sage to draw the appropriate graph for this game. Which pure strategy does the blue line represent? Which pure strategy does the red line represent?
- Use your graph to determine if there is a mixed strategy equilibrium point. If there is, use Sage to determine how often Player 1 should play each strategy. What is the expected payoff to each player?
- Is this game fair? Explain. Compare your answer to (b).