 So this is going to be our first lecture just looking at how to use Python to do our mathematics. Now you do not need any prior knowledge of Python. You don't even have to install anything. There is a link in the description down below to a video where I show you how to set up your Google Drive such that you can use a Google Colab file that looks very much like a Google Doc into which you're going to type your Python code. So you really need no Python experience and you don't need to install anything. What I do want you to have watched is the first video in this lecture series where I take pencil and paper and we talk about this stuff in lecture number one. It's simple arithmetic and talking about numbers. In this lecture though we're going to use Python to do all the mathematics that we learned about in lecture number one. So to start with we have lecture number one. So we might as well go right to the top and you see if I hover in the middle between these two cells you see code and text. So let's enter some text. Now this is going to be a title for me. So if I double click here double click or enter to edit if I double click you see I have a bar that allows me to use bold face italics insert images all sorts of things. I'm going to use a single hashtag symbol or pound symbol and I'm going to say lecture one. So lecture one and perhaps I'll have a space and I'll put a little bar there on my keyboard. It's right above the right shift key. This is a MacBook Pro. You'll have to find that on your own keyboard. Of course you can type any kind of title that you want and I'm going to call this one arithmetic. The single hashtag symbol there with a space behind it indicates to this notebook that this must be the largest font size that this notebook can render and if I just hold down shift and hit enter that cell is executed and now you can see it's quite a large font. I have lecture one and then I have my little horizontal my little vertical bar should say and arithmetic and so the first thing that I like to do in these notebooks is to import all the extra packages that I'm going to use in this session of Python. So I'm going to hover in the middle between these two cells. There's a code cell which was there automatically but just above that so between the stick cell that I've just created and this code cell if I hover over the middle you'll see code and text and I'm going to add a new text cell. This time I want the second largest font so I'm going to use two hashtags or pound symbols and then a space and then I'm going to write imports and if I hold down shift and hit return or enter that cell is executed and you can see the font size is slightly smaller from my largest font size which I use for my title and then for subtitles or sections I will use the second largest font size which is indicated by those two hashtag or two pound symbols. Now I want to use a code cell now there's already a code cell for me there so we might as well make use of that and I'm going to import a few things and the keyword in Python to import a new package is just import it's very much like English and I leave a little space and the package that I want to import is the math package and all I have to do now is hit that little play button but I can also hold down shift and hit return or enter. Now what I don't have at the moment is a running Python kernel. Now remember all of this is happening on Google's servers not on my own computer so I have to start Python on their computer and one thing I can do is hit that little connect button that you see right at the top or when you execute your first cell that's going to happen automatically so let's do that I'm going to click on this little run button you see the marching ends walk around walk around the play button things are happening behind the scenes that we've started Python on the Google server side and we see a little check mark there that code cell has executed we have now imported the math module the math module is full of extra functionality that is not in base Python which is now expanded what I can do with Python. Let's do that once again I'm going to go to just below hover in the middle just below the cell that we've just had and I'm going to add a new code cell and import and this time I'm going to import some pi that's sympy short for symbolic Python I'm going to hold down my shift key and hit my enter key or my return key when I do that a new cell will automatically appear below but look at that there's a little check mark there we have successfully imported numpy now I can always come back and add more cells in between cells that are already there the execution will be in temporal order unfortunately that means the order in which we have from top to bottom that is not going to happen as I execute this current notebook so we always just have to be aware of that so let's create a new text cell so I'm going to click on the text button let's make it another section and my sections are the second largest font size so there'll be two hashtag or two pound symbols and let's type in Python types now hold down shift and hit return or enter and now you see my notebook is starting to look very neat I've got my title I do have these two sections now everything in Python or let's say most things in Python are really just objects and as far as objects are concerned objects have a certain type and one way that we can find out about the type of something is using a Python function and functions in Python are keywords and you can see me type there the word type that is a function in Python a keyword and all functions are immediately followed by a set of parentheses open and close parentheses so every time you see a word and then open and close parentheses that would be a Python function inside of those parentheses we pass an argument it tells the function this function can do something but what must it use to do its job well that is the argument that we pass and this time I'm going to use single quotation marks and as soon as I hit the single quotation mark remember you can also use double quotation symbol that doesn't really make a difference and I'm going to say I love mathematics and I've typed that sentence and but it is inside of quotation marks if I highlight it can you see that that is inside of quotation marks that whole thing inside of the quotation marks together with the quotation marks that is an argument I'm passing that argument to the function type type knows what to do you must just tell it what must I act upon now it is acting upon this argument and that is I love python in quotation marks now as soon as we put something in quotation marks what we are telling python is that this is a string type so let's hit that play button or shift enter shift return and we see the result immediately str and that's a short fork string anything that's inside of a set of quotation marks is a string and you can think of this as just normal english it can be a single letter a single number it can be a sentence it can be a paragraph anything that goes inside of set of quotation marks is a string object now that it is that data type string python can do a lot of stuff with strings but the stuff that it can do with strings is very specific to strings they will mostly only work on strings and so python needs to know what this is and it knows that this is a string and I can find out for myself as a human being what does python see this as by using the type function so let's try the type function again I'm going to say type in this time as argument I'm going to put just the number one just sing simply the number one so there's no quotation marks which means this is not going to be a string we already know that and let's do shift and enter shift and return and we see that's int that is short for integer otherwise known as a whole number and so we can see that object there the object is the number one and all objects have a certain type we can use the type function pass this one as an argument to the type function type knows what to do just wants to know what must I act upon well there's your argument it's one and it is returned we can see that it is an integer let's carry on with us let's do type and this time I'm going to put one point zero so there's a decimal value there I've added one single zero decimal point and as soon as I do that we see now we have a float that is short for floating point number which just means numbers with decimal points and again python has a bunch of stuff that it can do to strings it has a bunch of stuff it can do to integers it has a bunch of stuff that it can do with floats it just needs to know what that object is of course python will know what it is but I'm using the type function to find out for myself as a human being you know what is going on here I want to show you one exciting one and we are going to look at this doing this course and that is just one j so there's no spaces between the one and j and let's have a look at that that's a complex number so in engineering we use j for the imaginary unit mathematics we usually use i but here in python you can just use the j so one j is the imaginary unit i and that is of type complex that is part of being a complex number let's have a look at a couple more and I'm just using different arguments to just show you some of the data types that python has so this time i'm going to use the keyword true and you can see that it's spelled with an uppercase t and let's have a look at what that is that is a bull which is short for boolean boolean is just true and false if you have a mathematical statement what we do in mathematics is we have statements and they can either be true or false there's no maybe there's no gray area it's true or false and in computer science we also have this idea of true and false let's have a look at the type of false now that is uppercase f and if we look at that scroll down that's also a bull that's very very important a boolean type and the only two is true and false for us here and behind the scenes I just want to let you know very interestingly two is actually represented by the number one and and false is represented by the number zero so that I can actually say do some mathematics is the first mathematics we're gonna see true plus true and now that is you know space plus space then true you don't have to use those spaces it just looks a bit neater to my eye but look at what happens when I execute this I get the result two because behind the scenes python is storing true as the number one and false as the number zero so if you say one plus one it is definitely going to be true let's look at one more type that I want to show you in this section so I'm going to say type and then none and then the end the first end is uppercase as well and we see that has a very special type and that's called the non type once again a computer language such as python needs to know what type an object is because it can do certain things with certain types of objects which it cannot do with other types of objects that is how the language is designed now we've worked on our file a little bit it's starting to look very nice but right at the top there's something we haven't done yet we haven't named our notebook so you can see if I hover over untitled zero dot ip y and b I can rename this notebook so I can click anywhere in there let's go to the right of the zero and let's delete all of that and I'm going to call this lecture 01 and I'm just going to hit enter or return and this notebook now has a specific name that is saved and if you go back into your folder your google drive folder you'll see this is now called lecture 01 dot ip y and b and of course you can call your notebooks anything you like let's create a new text cell and I'm just going to put two hashtag symbols and so I'm starting a brand new section by the way if we go all the way back up we see we have these little downward facing arrows if I click on that it is going to close up that section and if I go there it closes up that section and this makes it even neater because now those are collapsed and I can just re-expand them as I need them so let's leave that collapsed and we can as I say always re-expand them so let's do a little bit of arithmetic now I'm going to start this section in arithmetic of with looking at a very specific function and that's called the round function so round does what the name implies it rounds off to a certain number of decimal points so let's use just a single number let's do 10.4 I'm passing 10.4 that is my argument to the round function I'm going to hold down shift hit return or enter to execute the cell and by default we see that it is rounded off to the nearest integer so there we see point four was just rounded down remember at point five point six point seven anything five or more it's going to round up and then less than five it's going to round down so let's have a look at what happens if we do round let's do 10 point let's do 4999 let's see what happens now again that four is less than five so it's going to round down and we see as we expected we see a 10 but what if we want more decimal places involved let's do round let's do 3.141 and now I'm going to put a comma and a space now one thing about python is you can pass and for many functions at least more than one argument and we separate those arguments by commas so here we have our first argument is the number and our second argument might be how many decimal places do we want and so let's say that we want a single decimal place and for that I just type the number one and now you can see it's been rounded off to one significant digit to one three point one is one decimal place and so you can pass other values two three four depending on how many decimal values you would like now there are two other important functions when it comes to rounding and that is the floor function and the seal function for floor and ceiling now those are very important functions we've discussed them in the pencil and paper lecture so let's have a look at them one thing that we are going to see now is that the floor function and the seal function which are we going to see is not available in base python they live inside of one of the packages that we imported and to make use of them we've got to tell python that this function that we're interested in is inside of that package now this package is going to be the math package remember right at the beginning we imported that so we type the name of the package and then we say dot or full stop and then let's do the floor function and there we go we see floor that floor I cannot just write remember with type and here with round I could just type those names of the function because those are functions inside of base python this floor function is not inside of base python it is inside of the math package and hence I have to reference that package name and I say math dot or full stop and then the name of the function now this active session of python will know where to go and look for this function and let's do 3.999 and what the floor function is going to do remember it's always going to round down to the nearest integer so if I execute that that is going to give me back a three it falls down to the floor and no matter how high those decimal values are if they are five or more it's not going to work as normal rounding it's going to round down and we also have math dot seal and that is short for sealing that is the official name of this function inside of the math package and let's do 3.001 and let's look at what the ceiling of that is of course it grounds up to the nearest integer and so we see that the nearest integer rounding upwards from 3.001 would be four so that's very interesting I always like to start arithmetic by just a reminder of rounding and floor and ceiling functions because we do make use of these in so many of our calculations more importantly let's get to some real arithmetic and the first thing we're going to do is addition so we might as well make our notebook look very nice let's create a new text cell and I'm going to put three hashtag symbols because now I want the third largest font and let's start with addition let's start with addition and now you can see that's even smaller than the font size for arithmetic because I used three hashtag symbols so let's just do a little bit of arithmetic now I've already shown you true plus true but let's do something like three plus four and it's very simple that's all you do three plus four now again I need not have put the spaces there I can also type three plus four that's very acceptable I like to put the spaces it just looks a little bit neater and python allows me the freedom to use white space python doesn't really care about my spaces and I'm going to hold down shift hit return or enter and I see as I expected the result would just be seven let's do something more exciting let's do three plus four plus five shift and return 12 three plus four is seven seven plus five is indeed 12 and I can just keep on adding adding adding as many numbers as I like addition is no problem whatsoever let's go and have a look at subtraction I'm going to hit the little text button one two three hashtags and I'm going to do subtraction and so let's just do subtraction let's do three minus four and I'm just using the minus symbol of my keyboard shift and enter and indeed three minus four is negative one I can do something more complicated let's do 23 minus six minus 10 and if I do that 23 minus six minus 10 that's 23 minus 16 indeed that is just seven so very very simple to do and of course you can just keep on going and add more and more of these by the way you can also do addition and subtraction together and we'll look at that a little bit later let's just carry on with our simple exploration of arithmetic for now I'm going to add a text cell one two three pound symbols and let's do multiplication there we go now there's no multiplication symbol on keyboards and so we use another symbol and that is the star symbol on my keyboard that will be shift and eight so let's do three times four so that time symbol there is just the asterisk or the star symbol and if I say shift and enter I get 12 three times four is indeed 12 once again I can do more let's do three times four times two and that's going to give me 24 and you can just carry on as long as you like let's have a look at something a bit more exciting let's look at division so I'm creating a new text cell I'm doing one two three hashtags I'm writing division division by the way let's just go up and let's start collapsing these I'm going to collapse addition I'm going to collapse subtraction multiplication just making my notebook look a little neater so let's do division and now let's do something very simple let's say 10 divided by two once again there's no division symbol on my keyboard and what we use is the forward slash key so 10 forward slash two means 10 divided by two and I see 5.0 and we know what type that is that is a floating point number versus just a five which would have been an integer so we've learned something here if we do division in python we are indeed going to get we are absolutely going to get a floating point value now I can just keep on going I can say 10 divided by two divided by five let's carry on and that's going to be one because 10 divided by two reading from the left is going to be five and five divided by five is just simply going to be is simply going to be one now let's make use of another strength of python and that's the simpy package I just want to show you something let's do two divided by five if I take two and I divide by five I get 0.4 0.4 but what if I did not want that floating point value 0.4 so let's use something that's inside of the simpy package now because we imported that package as its full name I have to say simpy dot and there's something in simpy called a rational and that's with an uppercase r it's going to create an instance of the rational class we don't have to be too concerned about that and it's got parentheses so we are going to see this as a function let's call it the rational function and I'm going to say two comma five I'm passing two arguments to this rational function I'm separating them by a comma and it's two comma five let's have a look at what happens now and just absolutely look at how beautiful that is I see it as I would see it in my math textbook I see a fraction we did not execute two divided by five to get this decimal value 0.4 we've actually got the fraction there and we got that fraction two divided by five by using this simpy function called rational and I think that is very very beautiful and now let's go right up back to the top because I want to expand this import section again and I'm going to create a brand new cell here and that's going to be a code cell now I was fortunate that I saw that fraction two over five if you don't see that you have to tell this session of python this notebook that you want your simpy the execution or the results of your simpy functions to be printed very nicely and the way that you would go about that is to say simpy dot init underscore printing init printing it is a function open close parentheses and so there's no argument that we pass to this function I can just hold down shift and hit return or enter that is going to be executed now and that is telling this notebook right now that if you use simpy please print everything to the screen in nice mathematical notation just as we've seen right down here we see two divided by five as a beautiful fraction and that is a very powerful thing or one of the first powerful things that we'll see about the symbolic python package so let's carry on I'm going to use text and I'm going to use one two three hashtag symbols and I'm going to do powers so let's look at some powers how can we do something like two to the power three now once again there's no way to do superscripts you know we put either if we say two or three to the power two we need that little two to be in a superscript we don't have that so what we do in python if we want to say three squared we'll do three and then two star symbols and two so that means three to the power two now I don't like to put spaces here because when I write this in my you know with pencil and paper I put the superscript two right up against the three and this just is for me a nice way to write it so let's execute that three to the power two that's three times three and as we can see there that is equal to nine and that is how we do powers now I can do a power of a power so let's take three to the power two which is going to be nine what happens now if I do another to the power two and now I get 81 that is where we make use of the multiplication of those powers three to the power two is nine and nine to the power two is indeed 81 so powers are quite easy to deal with let's go up and just close these let's close division let's close power because the next one that I want to show you is how to deal with square roots so let's do one two three hashtag symbols and I'm going to type square roots so let's deal with square roots so by the way you could see there when I collapse powers and I opened a new cell we got this automatic cell entered that happens you can just go you know click inside of that cell go to the right and click on that little trash can icon and indeed that cell is gone so let's close powers again and let's talk about square roots now one way to write the square root or something is to raise it to a power half we looked and we looked at that inside of the pencil and paper lecture so maybe I want to take the square root of nine I would say nine to the power now I'm going to use parentheses because I want to put a half then one way to do a half is just to say one divided by two one divided by two is a half so I'm saying nine raised to the power a half and when I look at the results it looks fantastic it says 3.0 fortunately for us we don't have to do all of this inside of the math package there is a function sqrt so that is not in base python it isn't the math package so I have to tell python where to find this function sqrt and that's inside of the math function let's do a set of parentheses again that sqrt is a function we have to have open close parentheses and we're going to pass the argument nine to this function and we see the result is again three do note here though that python is not going to tell you that it's plus or minus three it omits that negative and it's just going to assume that you know that there should be a negative as well now let's do something like math dot sqrt of ten now we know that's not going to be you know an easy integer solution and indeed if we look at that we're going to get this numerical approximation 3.162 776 and that is great because usually we want to deal with that number but I want to show you the difference between the sqrt function that is in the math package versus the sqrt function that's inside of simpi so if I say simpi dot unfortunately there's also an sqrt function inside of simpi and now if I pass 10 to this look what happens I get the exact numerical representation or the exact representation I should say I get the square root of 10 so here I have the numerical approximation and here I have the exact solution that's what with the terms that we use in mathematics same function sqrt sqrt but they behave very different differently because the people who designed the square root function inside of the math package that's a very different set of work than the people working on the sqrt function inside of the simpi package they perform very differently although the name is the same now when you develop your own package you are free to use the function names whichever ones you want and just so happens sqrt short for square root was the same function name that was chosen by both sets of developers now in simpi it's also easy to get the numerical approximation let me show you how to do that simpi dot sqrt I'm going to pass 10 to that and now I'm going to do a very weird thing I am going to use another function but this is a very special way to do this I'm going to put another dot and then I'm going to say eval f and that stands for evaluate this function and just open and close parentheses there's nothing that I'm going to pass as an argument there so what is happening here now you don't have to know about this at this stage but let me just explain that for your interest simpi dot sqrt 10 is going to be a certain object and indeed we saw the object that's the square root of 10 in symbolic notation but I can now take this object and I can pass it as argument to a function but I can do it in this way by appending this object with a dot and then the function name instead of saying eval f and inside of the parentheses pass simpi dot sqrt 10 I'm doing it in this order and in this sense we call this a method this function is called a method that is when we apply a function to an object that already exists so that's a brief little introduction to the way that methods work and we won't go into the details there but the result is spectacular so now I get the numerical approximation of this exact solution which is square root of 10 I get the numerical approximation that says I'll actually evaluate this for me the same as the square root function inside of the math package would have done for me anyway so I think that is just a little bit of fun now just to show you you know before we spoke about briefly about the complex numbers now we will have a lecture where we take the roots of quadratic functions and the complex numbers complex roots will come up so I just want to show you for now not too important but let's do that let's do simpi dot sqrt of a negative number now we are going to deal with this later on in the course for now we know that we cannot take the square root of a negative number but I just want to show you what simpi would do with this it actually actually gives us back this complex solution three times i the imaginary unit i so simpi can absolutely deal with this kind of algebra as I said we will work with it a little bit later in the course now let's create a new texel and I'm going to use three hashtag symbols again because this is still one of my subsections under my arithmetic and I'm going to do higher roots so what if we by higher roots I mean not just the square root but the cube root or anything higher than that to the power one over four power one over five etc so if I want to look for instance at the cube root of 27 I would have to do 27 and then two star symbols and then one divided by three 27 to the power a third that would be the cube root of 27 and lo and behold I get the right solution and that is going to be three because three times three times three is indeed 27 let's take for instance 16 and I'm going to trace that to the power one over four the fourth root day of 16 and that's two because two times two times two times two is indeed 16 inside of simpi simpi dot there is a root function simpi dot root and now I can simply pass the value that I want to root of 64 and what root do I want I want the third root of that so that would be 64 to the power one over three or the cube root of 64 and the solution is four because four times four times four is indeed 64 so you start getting a sense of how these functions work the root function and remember this is just human beings designing it that way that they say well there should be two arguments the first argument must be the number and the second argument must be you know this power that I want I want to the power one over three when it comes to the root functions because I want the third root of 64 the cube root of 64 let's move on to a new sex subsection and I'm going to call this one so three has hashtags absolute values absolute values no you know what happens to the absolute values it turns any number into its positive version let's go up I'm just going to collapse this section on square roots there we go it's collapse the section on higher roots and I'm working with absolute values now there's a function abs and if I pass negative three to that function abs I get positive three so note I can just use abs as is it is inside of base python it's a function that lives inside of base python it's I don't have to use abs if it is in one of the other packages it is in root python and so I can just use it as is so it's going to turn any number into its positive version and that's actually all I want to show you about absolute values it's quite easy to do so now let's look at logarithms so I'm going to do one two three and I'm going to do logarithms logarithms now we've discussed logarithms in the pencil and paper section we deal with logarithms logarithms so many times inside of data science and so let's have a quick look at that if I do math dot log there is a log function built in and you see there's actually log log 10 log 1p log 2 there's a few of these if we just use log it is going to be base e in other words oiler's number that is the natural log so if I take the log of say 10 well let's make it 100 just to show you math log 100 is going to be 4.6 that is e to the power of 4.6 gives me 100 as I showed you there there is a log 10 function as well and if I now put a 100 in there I should get back 2 because 10 to the power 2 gives me 100 so you just have to be clear about this but look at this the math dot log function so once again you can clearly see log the log function does not live inside of base python base python cannot do a log so I have to use one of the packages that can do logarithms I can say I want the log of 100 but I can also say comma and now I can tell it what I want the base to be but default the base is going to be e so the natural log but I can say comma base 10 and now I'm going to get the two back again so you see log 10 and log with the second argument of 10 that's going to do exactly the same thing now let's look at some pie dot log seems like there is a log function inside of some pie as well and let's do 100 and what am I going to get back I get back this exact or symbolic representation that is log 100 it has not evaluated that function for me so once again if I wanted the evaluation of that from some pie I would have to say some pie log and then I'm going to say 100 and then remember that is going to give me back an object and now I'm going to use the eval f method eval f and let's return that and now I actually get that same numerical value same numerical approximation as I got from the math so what we've seen now is all these functions inside of the math package that's just going to do plain and simple the stuff that your calculator would do for you it's going to give you this numerical approximation but some pie is a bit special it can do that for you but by default it's going to give you the stuff that you see in your math textbook so you're going to see this these nice symbols now let's look at math dot exp and I'm just going to pass the value one as an argument and what I get back is 2.71828 and that is Euler's number anything raised to the power one is just that number and the exp short for exponent is very special that does refer to Euler's number e and so I'm saying take e and raise it to the power one and that actually gives me back Euler's number so if you ever wanted to know the first couple of places decimal places of Euler's number just like pi you know we learned 3.14125 etc here's Euler's number 2.7182818 it's also an irrational number so just to show you that we can do that as well can we do the same with some pie let's explore some pie and let's see if there's an exp function and some pie and I'm going to pass the number one to that so that says the exponent one e to the power one and what do we get instead of this numerical approximation only to a number of decimal places we actually get the exact solution the exact value represented by this symbol e so once again I just want to show you how special some pie is I absolutely love some pie it really helps us to do proper mathematics that it looks like we are working with a textbook so let's create a brand new section and we're just going to talk a little bit about the properties of real numbers remember we did that in the pencil and paper lecture so this is going to be a brand new section for me so I'm only using two hashtag symbols and I'm going to say properties of the natural numbers shift and enter so let's go back up I'm going to close down algorithms and I'm going to close down absolute values and we can actually go way back up and we can close up all of the section on arithmetic now you don't need to do this I'm just trying to keep my notebook nice and neat so properties of our real numbers now first thing I want to teach you here is about something called conditionals now a conditional looks at something and something else so two things and it wants to compare them and the best way to compare things or the first way to compare things is to see if they are equal to each other and the way that we do that in python is to write a statement and it's going to return to us a boolean value so is this true or false so let's look at three and the way that we test what quality is by two equal symbols three equals equals three this is what we call a conditional what I'm asking with this code is s three equal to three so I've got two things there a three and a three you can think start thinking about this as an equation so on the left hand side of a three on the right hand side of a three and I'm asking is three equal to three now this is a statement that is either true or false now obviously three is equal to three so let's execute this code and we're going to see a boolean data type return to us and there's only two possible things it's going to be true or false and indeed we see it is true now I'm going to use this this conditional and I'm going to look at some of the properties of natural numbers so let's do that let's see if the commutative property holds and of course it does we know it does but let's check on that if I say three plus four is that equal to four plus three so does the order in which I add two numbers does that differ now we know three plus four seven and four plus three seven so we know we're going to return a two but we're seeing something deeper here we see that the commutative property on addition holds that if I do you know it does not matter what the order is I get the same solution we know that that is not true for subtraction because three minus four let's check if that is equal to four minus three and the result is going to be false because three minus four is negative one and four minus three is positive one and negative one is not equal to positive one and indeed we see there that we get the result is is false now there's another conditional I'm just having a bit of fun here let's have a look at that three minus four not equal to so exclamation mark equal is also conditional operator and it's asking is it not equal to and let's do four minus three so this statement is saying is three minus four not equal to four minus three and then they are not equal to each other for sure they're not equal to each other and python tells me you absolutely right that is absolutely true now the same is going to go for multiplication if I do three times four is that equal to four times three yes it's 12 equal to 12 no problem but what about three divided by four is that equal to four divided by three well no it is not three quarters is not equal to one and a third and I get false but if I say three divided by four is that not equal to four divided by three then I'm going to get back a true response so I'm using a bit of simple arithmetic here and these you know lot using a bit of logic for these comparisons just to see to teach you about how we could go about using a computer language later on if we want to test whether something is true or false now what about the associative properties let's look at three times four and then times five and I want to know is this equal to doing three times four times five now I'm using my parentheses and PEM dash we know what's inside the parentheses will be executed first so on the left hand side I'm going to do three times four which is 12 and then 12 times five which is 60 versus on the right hand side I'm doing four plus four times five that's 20 and 20 times three is 60 is this the same yes true and we can see this idea of associativity holds as far as as far as multiplications concerned and I'm going to leave it in your hands to play with this use these conditionals and look at the different properties that we discussed in the pencil and paper section to see whether where the certain properties hold as far as the natural numbers are concerned so let's do a new section and I'm going to just talk about the uses of division that's going to be a new section for me and I'm going to say the uses of division now remember we did discuss this in pencil and paper section let's close this section on the properties of natural numbers and I really want you to explore that on your own now in the pencil and paper section we spoke about this idea of using fractions which is just something divided by something else usually we would say fractions that the numerator is smaller than the denominator but that's not necessarily true just dividing two numbers now we've seen the sympi dot rational we've seen the sympi dot rational function and for instance I want to have a look at three over eight and so I would just pass those two arguments three comma eight not three divided by eight and now I see this nice exact solution three divided by eight three over eight and for me that is indeed a fraction now let's have a look at another one let's do sympi dot rational and let's do a three divided by five so that's three comma five this function is taking a numerator and denominator as it's two arguments and arguments are separated by commas and I can see three fifths now let's do what we did with a pencil and paper let's see if three eighths is less than three fifths now what I'm going to do is something we do quite often we cheat a little bit I'm going to copy so command or control c and I'm going to control or command v and I'm going to say less than now have you seen that in mathematics of course you have seen so let's go back and let's copy this bit of code command c control c and now I'm going to go right back there and paste it and now look at that as three eighths less than three fifths now we use the double equal and the exclamation mark equal before and this is exactly the same thing I'm asking is three eighths less than three fifths and this is a statement and it's going to be true or false and let's execute that and see and we see it is true if I cut my cake into eight pieces and I take three of those or if I cut my cake into five equal pieces of course those five pieces are bigger so three of those fifths that is going to be bigger than three of the eighths so three eighths is less than three fifths and if you ever have to do this kind of thing work with fractions very nice to do here of course here I'm just using the the rationals or that rational function now that means I can also do a bit of addition here so I'm going to copy and paste this whole line of code now look at how naughty I'm going to be here and I'm going to paste it right there but maybe I want to add those two things to each other so I'm just going to replace my less than symbol with a plus so instead of having to type out everything I'm just making use of a bit of copying and pasting so I'm saying three eighths plus three fifths and let's execute that and look at that that is 39 40 39 over 40 and isn't that a thing of beauty here with some pie now let's try and do the same thing just with normal mathematics so let me put inside of parentheses because I do want to do three divided by eight and then add to that so I'm using Pem das I'm using the parentheses to now instruct the order of this arithmetic operation and so I can do this all in base python I don't need to use anything else so I'm saying three divided by eight plus three divided by five now if I look at the solution now I'm going to get 0.975 that is the decimal representation but look what some pie can do for me it can make it look like a nice little fraction from my textbook and I absolutely absolutely love that let's do another bit of cheating let's take those exact same two I'm going to highlight and copy those I'm going to come down to the cell and paste them and I'm just going to change my addition to multiplication so I'm putting a little star symbol in between the two so three over eight times three over five and look what I get I get nine over 40 again for me that is a thing of beauty and it's already going to be reduced for me now that is the smallest numerator and denominator I cannot simplify that any further so that is absolutely beautiful let me show you this let's copy and paste I love to copy and paste to save so much time and let's do something like five over 10 if I use five over 10 if I use that on some pie it's five over 10 it's going to reduce that for me to a half instead of doing the five over 10 so some pie is even going to do that nice little bit of mathematics for me now one of the things we talked about is the least common multiple and in some pie we have some pie dot lcm now remember we broke it down into its prime we took a whole number we broke it down into its prime factors but look at this if I want the least common multiple of two numbers look at that there's an lcm function it does not exist in base python it exists in the simple package so let's have a look at what is the least common multiple of four and six and the least common multiple is 12 four times three is 12 six times two is 12 so it's so easy to get the least common multiple and you know if you want to add two fractions the two denominators must be the same and this is just such an easy way to find the least common multiple between two integers it's absolutely lovely to do now one thing we spoke about in the pencil and paper section again was a some was a remainder I just want to show if you do some pie dot mod mod but that m has to be an uppercase and I'll do 13 divided by 2 now I know that 13 divided by 2 is 6 as a whole number but 6 times 2 is 12 but I need to get to 13 so there is a remainder of 1 so if you always want to know what the remainder is use the mod function so hopefully this has given you a good start an enjoyable start to using python for your mathematics everything we've done now is display a little bit it's quite easy to do and I want you to explore on your own do a couple of these on your own once again using mathematics in terms of a computer language is a participatory sport you can't just watch me code and learn to code you have to code yourself and you're going to get a bunch of errors no matter how long we use a computer language you will always make mistakes people with 10 20 30 years of experience make mistakes every day and if you see little errors pop up because if you do something and it does not execute for you you are going to see an error try and fix that try and figure out how to fix that so this is a brief introduction specifically about the simpy package because we're going to use the simpy package throughout the rest of this course hopefully you could see just how easy it is to start using it