Skip to main content
Logo image

Section 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 from Section 3.2 given by
Table 3.3.1. Small Repeated Game.
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.
    • Step 1a. Assume Player 1 plays pure strategy A.
      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. Assume Player 1 plays pure strategy B.
      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. Player 1 varies her strategy.
      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.2.
    • Step 1d. Plot points.
      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.3. Click on the “Evaluate (Sage)” 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.
    • Step 2a. Assume Player 1 plays pure strategy A.
      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. Assume Player 1 plays pure strategy B.
      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. Player 1 varies her strategy.
      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.4.
      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. Use technology to find the point of intersection.
      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.
    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 1/4, and thus, play A with probability 3/4. The expected payoff for Player 1, \(m\text{,}\) is 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:
\begin{equation*} \left[\begin{matrix}1\amp 0\\ -1\amp 2 \end{matrix} \right], \end{equation*}
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!

Activity 3.3.1. Use Sage to find a mixed strategy equilibrium.

Consider the zero-sum game \(\left[\begin{matrix}-4\amp 4\\ 2\amp -2 \end{matrix} \right].\)
  1. Does this game have a pure strategy equilibrium?
  2. Just by looking at the matrix, do you think this game will be fair? (Would you rather be Player 1 or Player 2?)
  3. 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?
  4. 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?
  5. Is this game fair? Explain. Compare your answer to (b).

Activity 3.3.2. More practice with Sage.

Consider the zero-sum game \(\left[\begin{matrix}0\amp 1\\ 1\amp -10 \end{matrix} \right].\)
  1. Does this game have a pure strategy equilibrium?
  2. Just by looking at the matrix, do you think this game will be fair? (Would you rather be Player 1 or Player 2?)
  3. 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?
  4. 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?
  5. Is this game fair? Explain. Compare your answer to (b).

Reading Questions Check Your Understanding

The following exercises will use the Sage applets above to find the mixed strategy for Player 1.

1.

    True or False: The following zero-sum game
    Table 3.3.2.
    C D
    A 5 -2
    B 1 3
    has a pure strategy equilibrium.
  • True.

  • False.

2.

    Consider the zero-sum game given by Table 3.3.2. If we are finding Player 1’s mixed strategy, which two points are on the line for Player 2’s pure strategy C?
  • \((0, 5)\)
  • Correct.
  • \((1, 1)\)
  • Correct.
  • \((0, -2)\)
  • Player 2 is playing C, not D.
  • \((1, 3)\)
  • Player 2 is playing C, not D.
  • \((1, 5)\)
  • Check the probability with which Player 1 is playing A.
  • \((0, 1)\)
  • Check the probability with which Player 1 is playing B.
  • \((1, -2)\)
  • Player 2 is playing C, not D.
  • \((0, 3)\)
  • Player 2 is playing C, not D.

3.

    Consider the zero-sum game given by Table 3.3.2. If we are finding Player 1’s mixed strategy, which two points are on the line for Player 2’s pure strategy D?
  • \((0, 5)\)
  • Player 2 is playing D, not C.
  • \((1, 1)\)
  • Player 2 is playing D, not C.
  • \((0, -2)\)
  • Correct.
  • \((1, 3)\)
  • Correct.
  • \((1, 5)\)
  • Player 2 is playing D, not C.
  • \((0, 1)\)
  • Player 2 is playing D, not C.
  • \((1, -2)\)
  • Check the probability with which Player 1 is playing A.
  • \((0, 3)\)
  • Check the probability with which Player 1 is playing B.

4.

The line between the points \((0, 5)\) and \((1, 1)\) has slope and \(y\) intercept .

5.

The line between the points \((0, -2)\) and \((1, 3)\) has slope and \(y\) intercept .

6.

    True or False: When finding the mixed strategy, it is possible that \(p\) is negative.
  • True.

  • Remember, \(p\) is a probabilty. What is the smallest a probability can be?
  • False.

  • Remember, \(p\) is a probabilty. What is the smallest a probability can be?

7.

    True or False: When finding the mixed strategy, it is possible that \(p\) is greater than 1.
  • True.

  • Remember, \(p\) is a probabilty. What is the largest a probability can be?
  • False.

  • Remember, \(p\) is a probabilty. What is the largest a probability can be?

8.

    Consider the zero-sum game given by Table 3.3.2. Use Sage to find the mixed strategy for Player 1.
  • \((7/9, 2/9)\)
  • Remember \(x\) in the intersection point is the probability that Player 1 plays B.
  • \((2/9, 7/9)\)
  • Correct. Player 1 should play A with a probability of \(2/9\) and B with a probability of \(7/9\text{.}\)
  • \((2/9, 17/9)\)
  • This is the intersection point, not the mixed strategy.

9.

    Consider the repeated zero-sum game given by Table 3.3.2. If Player 1 plays the maximin mixed strategy, her expected payoff is
  • \(7/9\)
  • Remember \(x\) in the intersection point is the probability that Player 1 plays B.
  • \(17/9\)
  • Correct. The \(y\) in the intersection point is the payoff to Player 1.
  • It depends on what Player 2 plays.
  • The maximin strategy gives the same expected payoff no matter what Player 2 does.

10.

    Is the game in Table 3.3.2 fair?
  • Yes.
  • Think about the expected payoff of this game.
  • No, Player 1 has an advantage.
  • Correct, since the expected payoff to Player 1 is positive.
  • No, Player 2 has an advantage.
  • Incorrect, since the expected payoff to Player 1 is positive, the expected payoff to Player 2 is negative.

11.

Use Sage to find the mixed strategy for Player 1 for the following game.
Table 3.3.3.
C D
A -2 1
B 1 -2
Player 1 should play A with a probability of and B with a probabilty of . The expected payoff to Player 1 is .

12.

Use Sage to find the mixed strategy for Player 2 for the game in Table 3.3.2.
Player 2 should play C with a probability of and D with a probabilty of . The expected payoff to Player 2 is . (Use 3 decimal places if necesary)

13.

    If we use the graph to try to find Player 1’s mixed strategy, which of the following can we determine with just the graph, without solving for the intersection point?
  • Whether Player 1 should play A more often than B.
  • If the intersection seems to be closer to \(x=0\) than \(x=1\text{,}\) then Player 1 should play A more often than B.
  • Whether Player 1’s expected payoff is positive or negative.
  • If the intersection point is above the \(x\)-axis, then the payoff is positive.
  • Whether Player 2’s expected payoff is positive or negative.
  • If the intersection point is above the \(x\)-axis, then the payoff to Player 1 is positive, hence the payoff to Player 2 is negative.
  • Whether Player 2 should play C more often than D.
  • We can’t determine Player 2’s mixed strategy from Player 1’s graph.
  • Whether Player 1 will win or lose if the game is played once.
  • We are finding the expected payoff. The actual payoff will depend on what each player plays in one game.
  • Whether Player 1 will win or lose if the game is played 10 times.
  • We are finding the expected payoff. The actual payoff will depend on what each player plays over the 10 games.