 Now that you've seen me deal with inequalities and pencil and paper, let's use Python and we're gonna make our lives a lot easier. I've opened my new notebook, I've called it lecture nine, as you can see on the top left, let's go to the top right and hit connect so we can connect to the Google service and they can spin up an instance of Python on their side. Now as per usual, I'm gonna start with all the functionality that I want to import from the Sympy package, I'm gonna specify them. The other ones that we've seen before functions like init underscore printing, symbols, EQ and solve, but for inequalities, I've got a few more that I want to import. I've done it on two lines, you don't have to do that, you can just keep on adding commas and adding all the functionality that you require. So I've got ABS, reduce underscore inequalities, reduce underscore abs underscore inequalities, inequalities, poly and solve poly inequality. So let's import all of those and first of all, of course, we're gonna call the init underscore printing function because we want nice mathematical type setting when we execute Sympy code. First thing I wanna talk to you about comparison operators in Python. Look at that first one, it's an equality, it says it's three equal to three, that might seem slightly silly, but it is very valid code and you see the double equal symbols. That asks the question in Python, is the left hand side equal to the right hand side? So what you would see in mathematics with a single equal symbol, but remember in a computer language, a single equal symbol is an assignment operator, so we use double equal symbols here. Let's execute that line of code and we can see the result is true. It says the left hand side is indeed equal to the right hand side. These are what we call Boolean questions, statements that can either be true or false. There's nothing else is possible. So have a look at the second one, I'm asking is three less than or equal to three? Well, it's certainly not less than, but it is equal to, so that's definitely going to return it true as well. Next one is just a simple less than, is three less than four? Yes, indeed it is, we'll see true. Is three greater than or equal to three? Yes, that is so, so we see another true. Now just a simple greater than is four greater than three? Yes, that'll be so. And then this final one is three not equal to, so we see the exclamation mark equal, you combine those two, it says is three not equal to four? Well, it isn't, so we have true as well. So I'm gonna task you with setting up some of these that you might return a false value for your statement. Now though, let's carry on and talk about inequalities. There's our first inequality. We have a left hand side and the right hand side, but we're saying that the left hand side is less than the right hand side. So calculate, we'll solve at least four x, three x minus four is less than five. Now first of all, we've got to create a mathematical variable x using the symbol x, you can see it there, and I'm assigning it to the computer variable named x, let's execute that. Now here we see a function that we've never seen before, reduce underscore inequalities. So I've got three times x minus four less than five, comma my second argument x, I wanna solve for x, so we're not using the solve function here. And we see the result there, we see negative infinity is less than x, and there's this little funny symbol, that's the and symbol, looks like a little tent, it looks like a little a for and, there's just no little line, second line there. So and x is less than three. So you can clearly see x is between negative infinity all the way up to three, but it's not including that three. Now what you can do is just call the simplify method, which is what I've done here. So I've just had the previous line of code and I've said dot simplify, and let's see what happens. Now we see it's much simpler. It just says it's less than three. And of course that means it goes off to negative infinity. So it's this little simplification. I just wanna show you, if you create your mathematical variable x using the symbol x and assigning it to the computer variable x, but you specify x now to be a real number. Here we didn't do that. Here we are gonna specify x to be a real number. If I now use this exact same line of code, I'm using it right here. Now we are gonna see the simplified result, x is less than three. So it just depends, remember how we specified our mathematical variable x. I want to show you another function, solve underscore poly underscore inequality. So as long as you have a polynomial, you can also use this function. It's constructed very differently. Look at this. I have a first argument, which is a function, a poly with an uppercase p that actually creates an object. So that's gonna be poly. I've got three times x minus four minus five. Now what happened there? Well, if I go back to the original problem, I had to make sure that the right-hand side was a zero. So I had to subtract five from both sides. And then I'm only entering the left-hand side. The second argument of this poly function is x. I want a polynomial in x. So all of that becomes the first argument to the solve underscore poly underscore inequality function. The second argument, so comma, inside of quotation marks, I have got the less than symbol because that's what my problem was originally. Let's have a look at this result. And now it's going to do this. It puts inside of square brackets. Now those square brackets is just telling us that Python is creating a list of values. So that's got nothing to do with a mathematics. What we have to look at is inside, I see parentheses, so it's open intervals from negative infinity all the way up to three, not including three. Something else I wanna show you with these inequalities. Look at this. I've got my original problem there. Three times x minus four is less than five. I'm putting that inside of a set of parentheses to create one object. And then I'm calling the subs method. Now the subs method, remember, method is just a function, takes two arguments. The first one is x comma, what do I want to substitute x for? Well, I want to substitute x equals two. Why have I chosen two? Well, if I look at my interval, it says, well, take any value as long as it's less than three. Well, two is less than three, so let's check it out. So I'm substituting into this inequality, the value for x, and that's the value that I'm substituting as two. And if we execute that, we see indeed that is true. Now let's substitute a value that's not in our interval of our solution. So three is not included. Remember, this is an open interval. So if I substitute three into that equation, I should say into that inequality, let's be sure about that. It's an inequality. I get the result, which is false. So let's solve this inequality. Minus two times x minus four is less than five. Now I'm going to just use the reduce underscore inequalities. Remember, I can just write up my problem as is comma, and I want this to be solved for x. And now I see that negative three over two is less than x. Or if I read it from the right-hand side, it's x is larger than three over two. Now once again, I can use simplify. You know, just add the simplify method. And all it's gonna do now is just gonna swap those around. So we read it properly. The way that we would expect it, x is larger than one and a half or three over two. Here's my solve underscore poly underscore inequality again. I can do this because we have a polynomial here. There's my poly function again. So you've got to look at what we had to do. We had to bring that five over to the other side. So we had to subtract five from both sides. And I'm only putting the left-hand side there, then comma x. And then there's my less than symbol as the second argument to the solve underscore poly underscore inequality function. So you really have to pay attention when you wanna use this function. And look at that. We see this open interval from three over two up to positive infinity. Again, please ignore these square brackets. Python is just using that to tell me this is a list of possible solutions. There's only one interval of solution. And that's this open interval from three over two all the way to infinity. Once again, we can use the subs method. Look at that. I'm substituting x equals two into my problem. So there's my problem inside of parentheses using the subs method. And I wanna substitute two as far as x is concerned. And again, two is in my solution interval because this goes from one and a half to infinity. And so certainly two isn't that interval. And I get a result that is true. Now let's use a value for x that's not inside of this interval of solutions. One certainly is not in there. So let's use that, substitute that and now I'm gonna get back a false. So you can always verify your results. Now let's do this example. Show the inequality or at least solve the inequality x squared minus four x is larger than negative three. Let's just do that poly. Remember we use poly as an argument. Let's just see what it does. Now yet you can see it once again, I've taken that negative three. I've added three to both sides so that I only have the left hand side of the inequality. I want this to be an x. And I have to set a domain. And the domain I'm setting is uppercase rr inside of quotation marks. So that's a string and you see this. It's a poly, it's x squared minus four x plus three in the variable x and the domain is the real numbers. That's all that that poly is gonna do for us. So let's pass that as first argument to the solve underscore poly underscore inequality function. My second argument is the greater than symbol which is what I wanted for this problem. And if we solve this, we see that we have two solutions and that's what I mean. Python is gonna use the square brackets to denote this as a list of possible values, possible solutions and the first one is this open interval and the second one is that open interval. So it's all the way from negative infinity to one, not including, and then from three all the way to infinity. Let's use subs. Now here I'm gonna use negative four because certainly negative four is within this lower interval. And if I do that, I'm gonna get a true. Let's substitute a value which is in this open interval from three to infinity. Let's use four there. That's gonna give me a true as well. But now let's use one that's not in the solution. So certainly from one to three, that's not nothing there is included. So let's just use two as an example. If I substitute x equals two, I get a false. So let's do this inequality, x squared minus one divided by x plus three is less than or equal to zero. Now what I'm gonna do, I'm gonna use the reduce inequalities, reduce underscore inequalities function. I've got x squared minus one in the numerator divided by x plus three in denominator and I'm using parentheses here, I have to. Otherwise I'm gonna run into problems because I've got division and I've got subtraction and addition there. So I just wanna make sure that my order of medical operations are understood. So I'm saying that's less than or equal to zero and then I want to solve this or reduce this for x and I'm using the simplify method. So you can have a look at that code and we can see this result. Now this is fairly complicated. Look at this. It says that x is larger than equal to negative one and x is less than or equal to one. So it's on that interval from negative one to one. And then we see this symbol. So it's a little upside down symbol and that's the or symbol and that says or x is less than negative three. So it's gotta be between negative one and one inclusive or it's gotta be less than negative three. So let's have a look at a couple of these. Certainly zero is in this first interval. So let's run that as a substitute. So that works out for us. Let's have something that's less than negative three. Let's make it negative four and we substitute that. That's also true. And now let's use something that's not in our intervals. So it's only something like negative two is not between negative one and one and it's not less than negative three. So that should return a false. So once again, we just verifying our results. Let's talk about solving absolute value problems. Now this can be a little tricky in some pie. So let's have a look at it. I've got the absolute value of x minus three equals five and I wanna solve that for x. Now if I wanna print it to the screen I'm gonna use the ABS. That's a uppercase A. I imported that from some pie so I can use it as is. And there we see it's printed to the screen. Absolute value of x minus three minus five. So what did I do? I bought this five from the right-hand side across to the left-hand side. What I did was subtract five from both sides. And now what I'm gonna do, I'm gonna pass that as first argument to the reduce underscore ABS underscore inequality function. Now that's not an inequality. I can certainly still use this function and I'm just gonna say equal equal as my second argument. So I'm making this an equality and then I want to reduce as far as x is concerned. And we can see our two results. x equals negative two. And we can see this symbol there. That's an or symbol or x equals eight. I can plug in either of those two values. I will get the solution. Now look at this. Now I've used the solve function. We're much more familiar with that one because this is not an inequality. So this might be more appropriate to use. So let's have a look at it. There's my equation function. First argument is the left-hand side. That's the absolute value of x minus three comma. My right-hand side is five. And I want to solve for x. And now I see negative two comma eight. Now I just want you to be careful here. Those square brackets there, again that's just part of a Python list and it's telling me there's two possible solutions that does not indicate a closed interval from negative two to eight. So we just got to be careful when we look at these results. Now if you want to verify these, I'm just going to do it the old-fashioned way. I think this is the only way you can do it. Let's put in negative two. That's one of my solutions. So the absolute value of negative two minus three is that equal to five? So I'm asking equal equal five is the left-hand side equal to the right-hand side when I substitute one of my solutions? Yes, that's correct. Let's substitute the other solution which is eight and indeed that's correct as well. Now let's have this as an inequality. The absolute value of x minus three less than five. So now certainly I've got to use the reduce underscore abs underscore inequality. So there's an absolute value in there. Now there's my absolute value the left-hand side and I've bought that five over to the left-hand side so that I only have the left-hand side. Unfortunately you have to do that. My second argument is the inequality. It's a less than symbol as far as a string is concerned. I've got to put that as a string comma. This is all solved for x and I'm adding the simplify method to all of that and now I get this result. x is larger than negative two and that little tent it looks like a that's and if it's upside down then it's an or or an and you've got to get those two correct. So this says x is larger than negative two and it's less than eight. So it's certainly in that open interval from negative two to eight. So let's choose a value there such as zero that's certainly between negative two and eight and that should return a true and then very lastly let's substitute something that's not in that interval something like nine and if I execute that now I'm gonna get a false and so actually it is a lot of fun rather easy I would say to use some pie for your inequality problems with or without absolute values in them as well.