 So here we are in our lecture one. We're just going to introduce SMPI. I'm using the ipython notebook here, which is probably the best thing since chocolate cake. And probably stands in my mind equal to the brilliance of SMPI, really combining the notebook and SMPI. It doesn't get much better than this. Fantastic work by all involved, certainly. So SMPI stands for symbolic computation of mathematical objects in Python. Of course, it's a computer algebra system. It's written in Python, and so it does not depend on any other Python library. So what you do is take mathematical objects, and you can represent them exactly. Let's just skip down right to the first example. Here's normal Python. I'm going to import math and then have math dot square root of 8. And when I run that, of course, I get the numerical representation as a few decimal points here, 2.8282. But we all know we can simplify this. So here we go. Let's try the exact same thing, but in SMPI. So I'm going to import SMPI as SYM. Now, I think most of the things you'll see, people will just suggest import from SMPI import everything, the star. Can't really use SMPI because that's usually for PSYPIE. But this is just to get your namespaces right. So in this instance, I'm just going to use import SMPI as SYM. So if I now have the square root of 8, let's run that. And lo and behold, we get something that's much more used to us. It's 2 times the square root of 2, so we've actually simplified that. 2 times the square root of 2 looks a bit better mathematically than 2.82847, etc. So that is what a computer algebra system does in short. So let's expand this to a bit of rational numbers. Here, I'm going to use the variable R1, and I'm going to call it SYM. So SMPI dot rational 4.5. So that would be the numerator and that would be the denominator. And I'm also going to have a second variable, R2 here, and that will just be a different rational if I run that. Nothing's going to happen. We're just storing the results into those two variables. I now have a print command. The first rational is colon, and then we're going to print out and see what it looks like. If I run that, I see the first rational is 4 over 5. 4 divided by 5. The division indicator there. If I run the second one, we're going to get 5 over 4. There was my numerator, there's my denominator, and that is what it's going to do. Now we can add these two together, and that's what makes life very fantastic. Now I'm going to get those results. Now, unfortunately with these cells, you can only execute one of these CARES computer algebra system commands at a time. So let's run there. We can see the addition of these two rationals is 41 over 20. So you've got the common denominator of 20, between the 5 and the 4, and that is what you're going to have. Lastly, we can also divide it, and I'll get a proper answer of 16 over 25. Now that looks beautiful, but what if I want to use symbols? That's what a computer algebra system is all about. So I can have my variables to find the symbols in Sympi. I can still assign a variable and then have a symbol to that. But I can also change that variable into a symbol itself. Let's have a look. I have x comma y equals, and here's your keyword, symbols. So it's Sympi dot symbols. Then I'm going to have x and y. Now they should not be that comma in there. You just leave it as such, and it's got to be in the same order because it's going to map this x to a symbol x instead of a variable. And this symbol y, this variable y to this symbol y. So I'm just equating this, mapping this symbol, this variable to a symbol. Then we're going to have two expressions, expression 1 and 2. Those are just variable names, and now it's going to be y plus 2 times x. Now, I have not defined or given y a value or x a value. As I would have to do in Python, I would have had to say y equals 1 and x equals 4, and then execute this now, get an answer, but now I have to find them as place all the symbols as the symbols. And there's my expression 2, 2 times x plus y. So you see these two are exactly the same. And to get more than one of these, well, I'm not really executing anything. All I'm going to do is just to print these two, the values of these two variables. So there we go. I have 2 times x plus y. So I didn't calculate anything. It kept them as symbols as a computer algebra system. And look at the order. It's keeping x and then y. It's got nothing to do with the order in which I defined these. In other words, let's try that. I can have y and x, and then just map them to the same thing. Otherwise, things can become a bit hairy. I can do this, and if I execute it now, I'm still going to have it in that order. It's written in the Python, the Sympi library that I'm going to have x as before, y. As well, there are various rules as to what goes, and before what, and you get used to it. Now, the beauty of this, I can also do simple calculations with this. So if I have expression 1, that's 2 times x plus y, and I subtract x from that. So it's 2x minus x. Or I take expression 2, which is 2x plus y, and I add 1 to it. So look what happens. This is beautiful. So I had 2x minus x. That just leaves me an x. So the system actually did that calculation for me, and now I have 2 times x plus y plus 1 for expression 2, to which I've added 1. So that works quite well. Now remember, not all expressions are simplified in this order. The default is this factorized view, and you can expand and factor various expressions, and we'll have a look at that. Let's just look at this one. So x times expression 1 is going to leave it as x times 2x plus y. It's not going to say 2x squared plus xy. It's going to leave it in this factorized form. Okay, so yeah indeed, we're going to try this expanded and factorized view. So yeah, I have this expression 1 times x. So I'm going to x times 2x plus y, and I'm going to use this command expand. Sympy, my reference there, sym.expand. Let's see what happens there. So it's now going to distribute that x in. It's going to expand now. I suppose some of these keywords can not be so clearly meaning, but expand means it's going to distribute that x in, so it's going to be 2x squared plus xy. And if I have this 2x squared plus xy, I can also factorize it. So I'm going to have sympy.factor, and if I run that, lo and behold, it's going to take out the common factor of x, and I'm left with 2x plus y. So that's a short introduction to sympy. In lecture 2, we'll move on to something a bit more advanced. See you then.