 And so you've seen me take pencil to paper and solve cubic equations. Now let's make our lives much, much easier. Let's see how to do that using Sympi, that is symbolic Python. I've opened a new notebook on the top left. You see I called it lecture eight dot IPYNB. And on the right, I've already clicked on connect to connect to Google service to start an instance of Python. As per usual now, I'm only going to import the functions and symbols that I want from the Sympi package. And the first function that I'm going to call is the init underscore printing function. Once again, so that we have nice mathematical type setting to the screen when we execute Sympi code. Now here's our first problem factor, X cubed plus A cubed. Now I will have to create these symbols. By now you should be familiar with the symbols function. I'm creating the mathematical variable X using the symbol X and I'm assigning that to the computer variable X and I'm setting X that variable to be any real number. Next we've got to do the same for the A symbol. A is also in this instance a variable and I'm going to use the symbols function as I did before. I'm not setting any particular parameter for that. It's not important for this problem. Let's print this to the screen. As you can see, I'm using a set of parentheses around every cube. We do not need to do that because Sympi is going to adhere to the order of medical operation. So it's certainly going to do the power A to the power three and X to the power three is going to do that before addition. But just to show you that you can put parentheses just to be very clear about what we are doing. So you can see Sympi changed the order instead of X cubed plus A cubed. We have A cubed plus X cubed. Now we do have commutativity on addition so that does not make any difference. Now I'm going to create a single object. So I'm going to put both X cubed plus A cubed inside of a set of parentheses. We do need to do that because we want to call the factor method on that whole object. And when we factor that we see exactly what we saw in the pencil and paper lecture. We see A plus X and then A cubed minus AX plus X squared is just that order of the addition that is different. Let's do the same for X cubed minus A cubed. I'm going to print that to the screen first. As you can see the order is the other way round again. And if we factor this, again we see what we saw in the pencil and paper lecture. We see negative A plus X and then A squared plus AX plus X squared. Now let's move on to a specific example. We've got X cubed plus 27 equals zero. So we've got an equation on the left hand side, and we want to solve this. First of all, let's print this equation to the screen. Now as you know, we use the EQ function for that. I have as my first argument the left hand side comma, then the right hand side is my second argument to the EQ function. And we see beautiful mathematical typesetting to the screen because we use the init underscore printing function. So we see X cubed plus 27 equals zero. Let's pass that whole equation as first argument to the solve function comma the variable in which we want to see the result. We want to solve for X and we see X equals negative three. And again, we can verify the result. We're just going to substitute negative three wherever we see X in our equation. So it's negative three cubed plus 27. And if we execute that, we should see zero and indeed we do. We have to ask ourselves is that the only solution though? Let's factor the left hand side. So I'm only using the left hand side X cubed plus 27 and I'm calling the factor method on there. Now we see the factors here X plus three and the second factor X squared minus three X plus nine. Now either of them can be zero for the equation to hold and we've only seen this first solution. So let's take that first factor and we're going to solve for X and we see the X equals negative three. Now let's solve this second factor. Let's set that equal to zero and solve for it. And we see no solution there. There's no real solution for X setting the second term equal to zero. Now in case you are curious, remember they are complex solutions as well. So I'm going to reassign X and this time I'm going to set it to be any complex number. If we now solve for the second term, we see that we get two more solutions and we should have three solutions because this is a cubic equation. And there you see the other two. They are both complex numbers. If we now solve for the original equation, there are our three solutions. It's negative three and then the two complex numbers. And so when we do the substitution of this second solution and then you see cubed plus 27, this is our result. It's just done the substitution but the arithmetic hasn't taken place. So I'm going to take all of that, set it inside of a set of parentheses and then call the simplify method. And indeed we see the value zero. We can also do that for the third solution. So when we do that substitution, we see it indeed it's 27 plus our solution there cubed. We're going to pass all of that inside of a set of parentheses called the simplify method on that and then we're going to see zero as well. So we've verified all three of our solutions. Let's do this problem. X cubed minus eight X equals zero. First of all, I'm going to print that to the screen. I see it is indeed X cubed minus eight times X equals zero. Now let's factor this left hand side. Just remember that in this instance, it's really our D that is zero and we do have these two factors. It's X and then X squared minus eight. And so we know either of them can be zero. Let's solve and we see three solutions. They're all three real numbers, zero negative two times the square root of two and two square root of two. Let's do this one. X cubed minus four X squared minus five X equals zero. Let's print that to the screen in the form of the EQ function. We see we've made no mistakes. So let's factor that left hand side. If I factor the left hand side, immediately I see the three factors. I know X is zero or X is five or X is negative one. Let's verify that. Let's pass the equation to the solve function and there we see our three solutions. Minus one is zero and five. Let's do the same for X cubed minus three X squared. I've printed it to the screen. That looks correct. Let's factor the left hand side and we can see X squared and X minus three. So we know X is zero or X equals three. Let's solve and make sure that is true. Yes, indeed we see zero and three. In actual fact, there are two zeros. We do have to have three solutions. So there's a cubic equation, but zero equals zero. So we're only gonna see the two solutions. Now this one we also did in the pencil and paper lecture. I showed you two ways to solve this problem. Let's print it to the screen. We see X cubed plus X squared minus four X minus four. Remember we did grouping and we did division. Let's factor that left hand side and we see our three factors there. And immediately we'll see that X is two, X is negative one or X is negative two. Let's solve that using the solve function and we see our solutions negative two, negative one and two. Look just how easy it is to solve cubic equations using some pie.