 Now you've seen me take pencil to paper and we looked at powers and we looked at roots and we looked at logarithms. Now we can do all of that with symbolic Python as well. And that's what this lecture is all about. We're still pretty much exploring how to use Sympi. Later on we'll put it to a real test. Now I do want you to watch the pencil and paper videos because that's where we learn about these topics. But here in these videos, in the Python videos, we see how easy it is to deal with that algebra using Sympi and Python. However, you don't have to install anything or have any prior knowledge of Python. Just watch these videos. And there is a link in the description down below to a video where I show you how you can set up your Google Drive to code in Python. I'm inside of my Google Drive. I have navigated to the folder, which is the place that I store all these notebooks and I'm going to go to New, More and Google Colab. First thing is going to be changing the name of this file. So at the top left, I'm going to take away untitled zero and I'm going to call it lecture three. That's fine. And let's do things a little bit differently. I'm going to go to the top right and see the connect button. I'm going to connect right away. So instead of me having to wait until I execute the first Python code cell, I can just connect right away. So let's give this notebook a title. So I'm going to hover right in the middle and I'm going to hit text. Let's double click there. I want to show you a different way just to add the one hashtag or two hashtags. You can just click on this little toggle heading. If I click on it once, it's going to give me the one hashtag or pound symbol, a space, and it's going to just add a title for me. Now I want to delete all of that. So I'll highlight it and just delete it. And let's call this notebook powers, roots, exponents and logarithms. That's quite a few things that we have to cover. Let's create a brand new text cell. So just hover in the middle. I'm going to click the text button. This time I'm going to hit this button, the toggle heading button. I'm going to do it twice, one, two. And now it gives me the two hashtag symbols. Unfortunately, it does give you a name. Just highlight it and delete it. And I'm going to say packages. And this is where we're going to do the imports. Once again, let's do things a little bit differently. So there's my code cell. And now I'm going to do the following. Instead of saying import SMPI, have a look at this. I'm going to say from SMPI import. So we haven't seen this before. Now remember last time in the previous lecture, what we did was, we just said SMPI dot and then this name of a function that was inside of SMPI. But what if I know already all the functions that I want to use and I don't want to say SMPI dot, SMPI dot, SMPI dot all the time. Now this is a way of just importing those functions so that I can just use them without that dot notation. So the first function that I might want is the init underscore printing function. Now I'm just going to use a comma and space. I want the symbols function. We've seen that one last time around. Maybe one that I want is rational. Now that comes with an uppercase R. So just be careful, rational, exp for exponent, log for log. And you can list all the functions that you want to use without going through the SMPI dot. So that this would be a different way, much more efficient way of doing it. The only problem is you would need to know all the functions that you want to use. All the keywords inside of the SMPI package you will need to know. Now you don't need to know them right up front. You can always come back to the cell and just keep on adding more and re-execute this line of code. So that's not a problem at all. Now that those functions were all imported, now I can just use them. I don't have to say SMPI dot. So I'm just going to say init underscore printing and open-close parentheses because it's a function and just execute that. Now remember what that does, that allows for that pretty printing. That is that nice type setting that we see when we print our results to the screen. So let's add a new section. I'm going to hit this toggle heading twice. Just click on the new section because I want to delete it. And there we go. And I'm going to call this section powers. And let's think about doing some powers. Now let's just do it numerically. What is two to the power two? And to the power is the two star symbols, remember? So this says two to the power two. And if I execute that, I should get four. What is two to the power three? Well, I'm going to get eight. And you can do any calculation that you want. Now there's some special things. If I raise anything to the power zero, let's take seven and I raise that to the power zero, we are going to get one. Now let's do zero to the power zero. Now that's a little bit special. Let's execute that in some mathematical circles. We say that zero to the power zero is undefined. In other mathematical circles, we say, well, zero to the power zero should be one because anything raised to the power zero must be one. And that's exactly the camp that's Python is in. So zero to the power zero in Python language at least is going to be one. Really an algebra, just thinking about the basics of algebra, we're going to say that zero to the power zero is undefined. We do not want that. Let's take anything to the power one. So let's again take seven and we're going to raise it to the power one. Well, that's just seven. So those are the basic things with powers of zeros and powers of ones. You know all of these things. Now let's have a little bit of fun with powers. Let's create a couple of mathematical symbols. I want a symbol X, I want a symbol A, and I want a symbol B. I'm going to assign them. That's my single equal symbol. The symbols function and are no longer, do I have to say some pie dot symbols? We've already imported it. Look up there from some pie import. In the last lecture, we just said import some pie, but now we say from some pie import, one of the functions that I imported, what's the symbols function? Now I can just use it outright as if it is part of base Python. And so let's put our parentheses, it is a function. I have to use quotation marks and now I can just say X, space A, space B. I don't have to use commas there. Now I've created mathematical symbols X, A and B and I've assigned them to these computer variables X, A and B, these names X, A and B. So let's have a look at the following. Let me say X to the power A. Now if you did not make these symbols, you're just gonna get an error back from Python because by default, Python wants something to be assigned and that must be a number or a list. Something useful to Python, but this is symbolic mathematics. So now Python understands that these are indeed mathematical symbols and now look what it does. X to the power A and look at that. X to the power A, that's lovely. What if I take X to the power A and I add to that X to the power B? So that's X to the power A plus X to the power B and look at that, X to the power A plus X to the power B. Now let's change things up. I'm going to say X to the power A and then a space and then multiply with X to the power B. Now it's multiplication, not addition. Now can you remember the rule? Let's execute that. Look at that, X to the power A, X to the power B. That's written out very beautifully, but hang on a minute. I just said, do you remember the rule? Well, if my bases are the same, X and an X and I'm multiplying these two powers, shouldn't I get X to the power A plus B? Well, let me show you this. I'm going to do a set of parentheses. Inside of that set of parentheses, I'm gonna say X to the power A space times X to the power B and now I'm putting that inside of parentheses so that that is one entity. And now because this is an object, remember I said most things in Python are objects, now that it's an object, I can do something with that object. And what I want to do to this object is to simplify it. Now watch this, dot simplify, open and close parentheses. Now first I'm just going to execute it and then I'll explain because there's a little bit of computer language knowledge. I'm gonna execute that and now look at that, X to the power A plus B. Some pi knows that rule and look at that, isn't that beautiful? If you just printed it like this, if you wrote that code, it's gonna give you X to the power A times X to the power B and some pi takes away the multiplication symbol or the dot notation. It just takes X to the power A, X to the power B as you would write it, pencil and paper, as your textbook will have it. But if I create a single entity of it by putting it inside of parentheses and then saying dot simplify, it's actually going to apply the rule that we know that you can add those powers. Now, a little bit of technical stuff which you don't have to know but let me explain it to you in any way. Do you see simplify, it looks like a function. Can you see there's open and close parentheses so you think that is a function. Now there's a thing in Python where once you have created an object, you can immediately send that object to a function but this is actually in reversed order. So instead of having the simplify function and passing X to the power A times X to the power B as an argument, in other words, putting it inside of those parentheses, you can apply it after the fact. And this is now turning what is actually a function into something that we call a method. Now there's a bit more to that as well but I just want to keep things simple. This is a method that exists for this object and depending on the object in Python, you can use certain methods. Those methods apply to certain objects and X to the power A times X to the power B gives me this symbolic object and I can apply the Sympy method to that object and this is what we do. As I said, you don't have to know anything about that. That's actually just computer science stuff going on there. I'm interested in the mathematics here. So if I do make that one single entity, that's a term X to the power A times X to the power B and now I say dot simplify, now we're gonna see that rule apply where I can just add those powers to each other and that is absolutely fantastic. Just wanna show you that we needn't just deal with these symbols. What if I just want to look at just using normal numbers? What if I have two to the power three and I want to multiply that by two to the power four? Now look at this, the bases are the same. It's two to the power three and two to the power four. Now if I execute this, I'm just gonna get the solution, 128. There's no symbolics going on here but I just want to show you that remember the bases are the same so I can add those two powers, so three plus four, seven. This would be the same as saying two to the power seven. Will that be the same? Yes it is, 128. And remember from before I can actually use that comparison operator, the double equal symbols. Have a look at this, two to the power three times two to the power four. Is that equal to, so the double equal symbol, two to the power seven, are they equal? Is the left hand side and the right hand side equal? Yes they are, they're both 128, aren't they? So that is absolutely fantastic. Let's explore what happens when you say X to the power three times X to the power four. Let's see what's going to happen. And because we use numbers in the powers, we're going to see that that's already done for us. We don't have to simplify this one. What Simpa is going to do here, it's going to add the three and the four to give us seven in one go. So just be aware of that. Now let's see what happens when we divide something. Let's say X to the power a, divide that by X to the power b. What's going to happen? Well look at this, it's doing some weird notation. I've got X to the power b in the denominator and I can bring that up into the numerator as long as I make that power a negative. So it is indeed actually what we are doing. We are saying X to the power a times X to the power negative b. That would be the same as having X to the power b in the denominator of a fraction. Now let's create two more symbols. Let's create the symbols Y and Z. That equals, now remember, I can use symbols straight away. Quotation marks, I'm going to have a Y and a Z. And I'm just going to execute that. So now X, Y, Z, A and B, they all mathematical symbols. So let's see what happens can Simpa actually do some simplification for us. So let's have the following. Let's have four, and I'm putting this in parentheses, times X to the power six, times let's do Y to the power three. Let's do times Z to the power, let's make that Z to the power two. And now I'm going to go outside that parentheses and I'm going to do a forward slash and another set of parentheses. So I'm going to have a numerator and a denominator. Let's put in the denominator two, times let's make it X to the power four, times let's make it Y to the power three, and let's make it times just Z. Let's see what happens. Oh, and that simplification happened for us. Cancelation, everything happened, it's now two X squared times Z. And isn't that a thing of beauty? So if you're given this very difficult expression, all the cancelation is going to happen right in front of your eyes. And because my powers, they were just numbers. Remember when we said X to the power three, times X to the power four, it already gave me back X to the power seven. So if those powers are not symbols, it's just going to do the simplification right there in front of your eyes. And that is absolutely fantastic. I just want to play around with this notion of having something in the denominator, a power in the denominator and what happens to it. So let's just play with that a little bit. I'm going to say one divided by X to the power A. Let's see what happens. And you can see what's simple is going to do. It's going to say one over X to the power A, I can actually write that as X to the power negative A. Those are exactly the same thing. Now what happens here? Let's do X and let's put that in parentheses actually. Let's do this X to the power A and then directly to the power B. What's going to happen here? It's going to write it out just like I wanted it. X to the power A, raise to the power B and you say, hang on, isn't there a rule for that? Of course there is one. How are we going to do this? Well, let's create one single entity of this. So look at this. I've got my outside set of parentheses. Now my inner set of parentheses X to the power A and then outside of that inner set to the power B. So all I've done is I've taken this line of code and I've wrapped it inside of its set of parentheses. Now I can say dot simplify so that this method is now applied to that whole object. And let's see what happens. What happens? Oh, unfortunately it didn't do X to the power A times B. That would be the rule, but you have to get used to some of the quirks inside of some pie. Not everything will be printed to the screen exactly as your textbook would do, but you've got to explore and get used to this. This is the way that some pie is going to deal with that. The next little trickery I want to show you is the rational function. Remember we imported that, so we can just use it as is. And a rational, remember that's a numerator divided by a denominator, but look at this. The rational function takes a numerator and a denominator as arguments and remember arguments are separated by a comma. So if I want a half, I'm gonna say one comma two, not one fourth slash two. That would just be numerical and it's gonna give me back a half. I want the rational one divided by two. Have a look at this. Oh, isn't that beautiful? Looks like my textbook, that is one half. Now I can start thinking about, hang on a minute, can I not do roots as my power? Yes, absolutely you can. So let's do X to the power rational one comma two. Now this is a little bit superfluous, but I can absolutely do that. And look at that, look what happens. SimPy realizes that's nothing other than the square root of X. Isn't that fantastic? Let's just explore a little bit. The best about these things is just to play. Let's do the rational one over three. What's going to happen there? Oh, look at that, isn't that fantastic? SimPy recognizes that's the cube root of X. I absolutely love this. This is absolutely fantastic. Let's do X to the power. Now I just want to warn you, the rational function, those arguments, the numerator and denominator can only be numbers. For rational, I don't put A's and B's in there. So what I would want to do here is to put inside of parentheses A divided by B. So X to the power A divided by B. And that's what SimPy is going to do with that. It's going to print out for you X to the power A divided by B. Let's have some more fun. X to the power, let's do A over B. And let's multiply that with Y to the power. Let's do A over B. Let's see what that gives us. And exactly as we asked for. X to the power A over B, Y to the power Y over B. Can SimPy simplify this for us? Well, let's give it a go. Now I'm going to do something very cheeky. I select all of that. Hit control or command C to copy it. I'm going to have my parentheses. And inside of the parentheses, I'm just going to do control or command V to paste. And let's say dot simplify. See if that will work. You have to explore these things. And it does actually does nothing. In this instance, once again, the simplify does nothing. But you do remember the rule that you can actually combine those two. Unfortunately, not everything works, especially not these simple things. Later on, when we do some more complicated stuff, you'll see SimPy really start to shine. But what I want to do here is this for you to explore. Now let's do the next little section. I'm going to say text to hashtags. And I'm going to say, let's explore the exponents. By exponents, I'm going to mean, I'm going to put my variable X. I'm going to put that inside of the power. So now I'll have something like A to the power X. See my variable is actually X. A is just a constant. It's going to be some number. But to the power X, and now that's what I mean by exponents. And when we talk about the exponential function, we actually mean the number E. So we imported the EXP function. And remember, anything raised to the power one is just that thing. So I'm just going to pass one as an argument. Look what's going to happen. There we have Oilers number E. So EXP refers to the base E. If I raise it to the power one, I actually just get E back. Now let's do something else. If I go right to the top, let's add something else that I want to be imported. Let's do the number Pi. So I'm saying comma and I'm just adding Pi. And now I'm executing that code. As I say, you can just go back and add some more. And there you've seen an example of that. Let's go back down to the bottom. Let's now just write Pi. And you're going to see that's going to be straightforward Pi to the screen. Now what if I want the actual, or some kind of numerical approximation to this? Now let's say Pi dot. Now look at this Eval F. Open close parentheses. Let's see what happens. Now I get a numerical approximation. Let's do this again. I'm going to say Pi dot Eval F. And I'm going to pass an argument 100. Look at this. 100 decimal places for Pi. Isn't that fantastic? So even though some Pi have these constants, these irrational numbers, and it contains the symbolic representation of that. So the actual value, we can also do numerical approximations are something that's symbolic. And what we do is we just pass the Eval F method at the end. And we can also pass an argument to that Eval F method telling some Pi how many decimal places we want. The last section in this video is just to work with logarithms. So let's do two. Let's just overwrite this logarithms. Just want to show you how logarithms work. So let's ask for the log of 100. What do you think is going to happen? I get the symbolic representation of this. This log function is the log inside of some Pi, not inside of one of the modules that we saw right in the beginning, like the math module. The log function inside of that package was actually just doing the numerical computation for us. If I wanted to get the numerical representation of this, I would say log 100. Now I would say Eval F, and maybe we want 10 decimal places. And there we see a numerical approximation for the log of 10. Now, if we just use the log function, the base is E, Euler's number. And that means the log function inside of some Pi is the natural log. Now I can say, well, I'm not happy with that base. Maybe I want base 10. So let's do log of 100. Then I can pass a second argument, 10. The second argument in the log function in the SimPi package is the base. And now I'm going to get back the result two because 10 times two, 10 to the power two, I should say, is 100. So the log function is very nice because it is going to do this numerical approximation when I ask for it, but it will also do the symbolic representation. So let's look at the log of X times Y, and I get back the log X, Y. Now remember there's a rule for that one, but SimPi is not going to print. In this easy case, it's really not going to print that to the screen for us. And that is it for this lecture. I've given you enough of a base to start playing with. There's nice documentation online for the SimPi package. Go out and learn stuff. By that I mean just go and explore, play, write some code, explore. It is wonderful. And we are nearly there that we can really start using the power of SimPi to do some actual calculations for us.