 Now you've seen me take pencil to paper and we looked at variables and expressions but now we're going to do the same thing but using symbolic Python. This is still very much an exploratory video, we're just trying to get used to how to do things in Sympi. One of the very exciting things that we're going to do is we're going to create mathematical variables. Now that's not normal for computer language but we can do it with Sympi and later on in this course it's really going to help us solve for x. I have opened my Google Drive and I've navigated the folder structure so that I'm in this folder that contains my notebooks for this course in Algebra. I'm going to go to New and More and a new Google Colab notebook. My new notebook is open and the first thing I might want to do is just to change the name of this notebook. I'm going to highlight this portion that I want to replace and I'm going to just call it let's call it lecture number two. I'm going to create a new text cell right at the top so I'm hovering above this code cell that was already created for me just on top of that going to hover click on text and let's give this notebook a name or title at least I'm going to double click there a single hashtag symbol and a space and I'm just going to call it two and a space. I'm going to use this straight line as this way to demarcate the number and the name and let's make this variables and expressions. I'm going to hold down shift and hit return or enter and that line of markdown will be executed and I see a beautiful title. The next thing that I might want to do just to try and keep this notebook nice and neat is just to do the section where I'm going to do all the imports so again I'm just going to hover in the middle choose text and this time I want two hashtag symbols because I want the second largest font size and that's going to be the size for all my thick all my sections and so I might write something like packages and I know in this section I'm going to import all my packages. Now I'm going to import some py sympy symbolic python later on we might learn other ways to import these packages and modules but for now I'm just going to use the whole word that is not the most efficient way to do this but we're just learning as we go. I'm going to hold down shift and hit return or enter and what you'll see at the top corner is it's connecting to a kernel that means python is starting on google service so that I can actually see the code being executed. So we've imported sympy and the next thing I might want to do is to initialize the printing that's pretty printing so that I do see nice mathematical type setting for my results and that is a function that lives inside of sympy so I have to say sympy dot and the function that I'm after is init underscore printing open and close parentheses. I know that this is a function because it has the open close parentheses this is not a function that is part of base python it lives inside of the sympy package and because of the way that I imported the package I have to reference the whole name of the package dot and then init printing so instead of hitting shift and return I'm just going to click on the play button and that code is executed for me and now we can simply just play a little bit. The first thing that we want to do is just create a new section so let's do two hashtag symbols and I'm just going to call this symbols. The way that most computer languages work is that we create variable names names that we decide just for ourselves and we assign something to that name the assignment happens with the mathematical equal symbol now an equal symbol inside of a computer language is not the equal symbol we see in mathematics in most computer languages or let's say in many computer languages the equal sign is actually an assignment operator it assigns something that it's to its right to the name that is to its left so on the left hand side of the assignment operator we have a name and that name is up to us now there are certain restrictions so I cannot have illegal characters in my names I cannot have spaces for instance in the name so there are some constraints but by and large that is up to you so in this instance I am going to create a variable named x and now once again please note as it stands right now that x is a computer variable named not a mathematical variable and so usually we would create a list of values say for instance we want to capture the age of some participants I might call my variable age and I'll say age equals and then I'll create a python list object and I'll just list all the ages now I've assigned that list object to the variable name age and that is a computer variable name but I'm using sympi and sympi stands for symbolic python I can actually change the behavior of python such that these variables actually become mathematical variables and that is not something that many languages can do we can do that in python with the sympi package and the way that we're going to do that is to use a function inside of sympi called the symbols function so I'm going to say sympi dot symbols open parentheses so once again that is a function I notice that that's a function because it's the two parentheses the open close parentheses and it is a function that is not available in base python so I can't just use it I have to tell this kernel this running instance of python that that function symbols lives inside the sympi package once again I have to do this because of the way I started my notebook off by just saying import sympi as mentioned later on we'll see other ways to do this that is more efficient but for now I'm going to say x equals sympi dot symbols and what we pass inside of a set of parentheses that is called an argument we give information to the function and our function now it's the symbols function we give it information we give it something to act upon every function in a computer language does something but it has to do that something to something and that's something that it does it's job on well that's the argument now some functions don't need arguments like look at that inner printing we didn't pass any arguments and that is quite fair but here we need an argument and we're going to pass this argument inside of quotation marks now you can use double quotation marks or single quotation marks but it has to be inside of quotation marks that tells the python computer programming language that this is a string object remember I said everything in python is an object or most things in python are an object and yeah this is a string object and don't worry about it now just accept it as is you have to pass this argument inside of marks now I'm going to execute this I'm just going to hold down shift and hit return or enter and now x this computer variable x has been assigned the mathematical symbol x and let's print this out I'm going to just type x that's it and my next line of code and execute that and look at that beautiful type setting does that not look like what you would expect in your mathematical textbook look at that beautiful x that's being rendered to the screen now let me show you the example I spoke about before maybe I want something like age equals and I'm going to say well the first person was 56 the second person was 51 the next person was 50 the next person was 66 now look at this I created a computer variable called age I assigned to that with assignment operator a list object and the list contains all these ages of these four subjects with a comma in between each of these values so if I execute the cell I now have this computer variable with a name and all that does is create some space in computer memory where this object is stored that I can now call this object and if I execute that code I see there's the list of all the ages now we've done the same to x but we've done something very special to this x we've assigned to it this instance of a mathematical symbol x which is now very different from a normal variable that just holds some value let's just try that again let's do the same for y y equals sum pi dot symbols and now I'm going to say well make that y please hold down shift and hit enter and now I have a y now look at this I can say x plus y what's going to happen well look at that beautiful x plus y just as your textbook would do it that is symbolic mathematics let me show you a different example I'm going to say let's say v equals the number 30 and w equals the number 40 so v w quite legitimate variable names I chose them no problem what if I now say v plus w well I'm gonna get the actual execution 30 plus 40 is 70 see how different that is from what we did up here it did not print to the screen 30 plus 40 no it just gave us the solution that's numerical computation what I'm doing up here is symbolic computation very difficult for computer to do but python can do that with the help of the simpi package so x is now a mathematical symbol y is a symbol and when I say x plus y I've got nothing assigned to x and y except it being mathematical symbols and now it will do that symbolic computation for me x plus y versus if it was a good old numerical computation it's just going to do the computation for me and that is very very nice now we can go even further with this symbols object let's do two more I'm going to say a comma b and look at this another powerful thing on the left hand side I can do more than one variable here I'm doing two variables as long as I separate them by commas that's the most important part so let's do some pie dot symbols and open and close parentheses and I'm going to do a and b now here comes a little trick I can just say a space b I don't put commas inside of those quotation marks okay we don't have to do that now outside of the quotation marks but still within the parentheses I'm going to put a comma a space and now I'm going to do real equals true now look at what has happened here first of all notice that there's my string it's inside of quotation marks comma and now I have real equals true in other words I've got two arguments here and all arguments must be separated by commas some arguments are very very special instead of just the value of the argument which would be true in this case this argument actually has a keyword name and its name is real and I'm setting real to true now later on you'll see this happen more and more and you'll get used to it for now please note that there are two arguments here and they are separated by commas now what this symbols function can do is not only create the symbols but I can put restrictions on those symbols I'm going to say that mathematically they must both be real numbers so a and b can contain real numbers symbolically so no complex numbers or other kinds of numbers now some pi has some built in symbols look at this some pi dot pi for pi look what happens now if I print this to the screen I don't get a numerical approximation 3.141 etc I get the actual mathematical symbol pi and some pi knows the irrational value of pi yes of course it will use it in computation and we can't force it to do numerical approximation we'll look at that a little bit later but look at that it contains this symbol pi and that is a mathematical number pi so let's do something crazy with everything we have now let's build an expression so look at my expression I'm going to say a times and let's do parentheses x plus y let's do that and see what happens now a remember that was assigned there's a it was assigned to be a symbol and it's just left to right a was first and that's assigned to a and b was second and the second one that was listed there was a b just here you don't need any commas remember and now all of these things a b x and y are mathematical symbols they are no longer normal computer language variables I've got my parentheses x plus y again just as you would see it in a textbook and later on this is going to be so powerful as we do distributing as we do factoring as we solve for x this is just going to become so important and powerful now let's go crazy look at this I'm going to say a times now look at this sim pi dot s i n there's a sine function inside of sim pi that will do the sine the sine calculation for us now I'm going to say some pi dot pi let's say times b and let's say plus three times x times y notice that I'm using using the star symbol for multiplication let's do minus four times x now everything here the a the b the x and the y I've already told python that these are symbols mathematical symbols so it knows what to do with them I'm using the sine function and I am using the pi symbol as well and let's see what this expression looks like look at that a times the sine of pi times b plus three times x times y minus four times x and you can build any expression that you want it is just absolutely fantastic so let's create a brand new section I'm going to do a text cell or markdown cell I'm just going to put two hashtags it's my indication my font size indication for my sections and let's say signed numbers just want to think a little bit about positive and negative values and so let's look at this let's say negative 16 minus 14 so I'm just doing some simple arithmetic and of course that's going to be negative 30 now inside of this section I want to show you something truly special let's have a look at this negative 16 negative 14 I want to know is this equal to negative 30 and the way that we do that because remember I cannot use the equal symbol that's an assignment operator but what about two equal symbols and now I'm going to say negative 30 I already know the answer is negative 30 those two equal symbols that is much closer to what we think in mathematics as an equal symbol I have a left hand side negative 16 minus 14 on the right hand side I have negative 30 and that is like I would write with pencil and paper negative 16 minus 14 equal city that is an equation and the left hand side is equal to the right hand side but what I'm doing here is something even more special those double equal symbols there those are actually a comparison operator it's going to compare the left hand side to the right hand side and it's going to ask the question is it really equal to each other is the left hand side really equal to the right hand side and that's a mathematical statement and statements can either be true or false remember true and false are Boolean values and those are the only two things there's no maybe here it's either true or false so let's execute this and we see the result is true indeed negative 16 minus 14 is equal to negative 30 and that is quite fantastic because now we can start thinking about the following let me take negative 16 and I'm going to add to that a negative number negative 14 is this still equal to negative 30 of course it's still equal to negative 30 you know that you know that addition is nothing other than in this instance here this negative this negative 16 minus 14 that that negative is actually a positive in disguise and we're taking this 14 and we're doing what we call its additive inverse negative 14 as the additive inverse of 14 because if you add both of them you get to the additive identity which is zero and so those are additive inverses of each other 14 and negative 14 so when I say minus 14 I'm actually saying add to the negative 16 another negative 14 and so is this equal to each other yes of course it is because that subtraction is nothing other than addition in disguise so let's have a little bit of fun let's say three times four we all know that's got to be 12 but what if I want three times negative four well I've got to put that negative four inside of a set of parentheses because I can't have multiplication and then the subtraction symbols the star and the little minus symbol right next to each other so I have to do that negative four inside of parentheses and now I'm going to get negative 12 what if I wanted to do negative three times four that's how I would do that and now we see the result is also going to be negative 12 what if I do negative three times negative four well that's going to give me a positive 12 and this is what we have to learn here a positive times a positive is a positive a positive times a negative is a negative a negative times a positive is a negative and a negative times a negative is a positive and that's what I mean by the sign of numbers very easy for us to look at now remember the same is going to hold for division let's have a positive divided by a negative three divided by four sorry that's a positive divided by a positive, that gives me a positive result. What about a positive divided by a negative? Well, that's also going to give me a negative. What about a negative, negative three, divided by a positive, that's gonna give me a negative, and then a negative divided by negative, negative three, divided by, remember, I'm just using it here, but the four slash is division, and I've got negative four, negative divided by negative, that's gonna give me a positive result. So it's just those couple of things that one has to remember. Now, let's go absolutely crazy here with these signs. Now, I've already assigned x and y to be mathematical symbols. Remember, anything in Python, as far as these variables are concerned, you can reassign them. So they already exist, but you can just go ahead and let's say, erase them and write over them. So I'm gonna have x, y, and z this time. I'm gonna say those are all some pi dot symbols. And now I'm going to have quotation marks, remember, x, space y, space z. I have to keep them in that order, and now I'm gonna do something else. Remember, before we said, well, these must be real numbers, I can also do the following. Positive equals true. Now, some pi is going to know that even though these are absolutely valid mathematical variables, I'm making them all positive values. They have to only hold positive values. Now, look at this magic. What if I now say minus x times y? What do you think is gonna happen? Of course, it's gotta be negative x, y. I'm telling you that x only holds positive values. Y only holds positive values, but now I'm saying negative a positive value. Now that becomes a negative value, and a negative times a positive is going to give you back a negative. And this is how you can solve these kind of problems in your textbook of managing signs in algebra. So let's do a fantastically long one. Let's do the following. Let's have negative x. Let's do the following. Let's multiply by y. Let's multiply by negative z. And let's divide by, and I'm gonna put inside of parentheses the whole of the denominator. So I'm acting as if this is all of this is my numerator, and I'm gonna put all my denominator inside of parentheses just to make it clear what I'm doing. Let's do x times, and then a negative y. And let's do times a z. Let's do times another negative x. Let's do times a negative y. Let's see what happens. And sympi is going to be clever enough to realize that this is negative one over xy. So it's going to do the numerator denominator for you, work that out perfectly, and it's going to get the sign correct. And you can force that issue by just telling sympi, or Python in this instance, through sympi that these symbols are indeed positive values. And so that's it for lecture number two. It's not really a long lecture. I just wanted for you to start getting familiar with using Python and using sympi. We haven't done anything really crazy or really useful just yet, but I promise you that it's coming. Imagine you can just use these symbols, write out expressions and solve those expressions. Do distribution, do factoring, solve for x, calculate roots, you can do all of that with symbolic Python.