 Hello everyone. So we have finally started now. So this is SimPy and you had a PiDi workshop right now. So most of the people have already installed SimPy when you install Anaconda. And PiDi uses SimPy for that. PiDi uses SimPy a lot for doing symbolic stuff. So all the magic you see in PiDi is because of SimPy. So first of all who am I? I am a developer at SimPy and a student at Relative Knowledge University. I am a Pythonista and of course a force enthusiast. So what is SimPy? SimPy is basically an open source Python library. It is used for symbolic computation. It is written entirely in Python. It does not require any external dependencies except a small package named mpmath which is I guess 100 kbs. So what is symbolic computation? So I hope you understand this Pi. Raise your hand if you understand Pi. Do you understand Pi? 3.14. So when I say Pi then it is a symbolic stuff. When you say 3.14 then it is numeric. So if in layman terms if I am to explain you what is symbolic. So this is Pi is symbolic. And which one do you think is the exact value of Pi? This one is this one. You can put a million digits here but it will still not be exact. So the one above is the exact value of Pi. The exact representation of Pi. So why SimPy? SimPy is totally standalone so it does not require anything else. And it is full featured. And it is a BSD license. So how many of you understand what is a BSD license? So BSD is something you can do anything with a package. So you can even use it for commercial purposes as well. So there is a liberal license. So you can use SimPy for commercial purposes and make money out of it. And some of the apps you will do this. Embraces Python. So it tried to use all the Python idioms wherever possible. So it does not reinvent the wheel. Usable as a library. So most of the computer algebra systems are not usable as a library. For example we have Sage or a lot of things are here. So you have something like, for example we have Ipython. So it is more of our command line based. So you can use SimPy as a library as well. So if you do on the top of the strip from SimPy import everything, you can use it in the library and use all the functionality in that. So the goal. The goal is to become a full featured computer algebra system. So a bit of history here. Andre Sertic started the project in 2006 and now it is the 10th year of SimPy. Thanks to Google for financial support. Most of the code of SimPy has been written by Google Summer of Code students. And I am one of them. It has participated in every GSOC since 2007. And Aaron Merl who is the lead developer of SimPy was also a GSOC student in 2009 and 2010. So here is a quick dump of features SimPy have. Small package, less than 5 megabytes and can do a lot of things. You will see. So here is some quick stats. Over 400 contributors. Half a million lines of code. 2700 star geysers on GitHub. 1400 forks. And a lot of other things. And the best part is that we have recently released SimPy 1.0. So it has been 10 years since SimPy started. So you can see it is a way well tested library. So now basically we have moved from the point of SimPy as a toy to a SimPy as a tool. So you can simply use SimPy for some real stuff now. So here is some stats about SimPy. The blue line you see. Okay you don't see. The blue line you see is of SimPy in this one. So we can see SimPy has a pretty large community and a lot of contributors. So that was a bit about SimPy. So future plans make things faster. So symbolic is particularly pretty slow. So doing things faster in a symbolic manipulation system is always the goal. Implement more algorithms. Encourage more people to use SimPy. Use and contribute to SimPy. That's why I'm here. So if you want to know what the goal of SimPy is, you can go to this GSOC Ideas page. Which pretty much lists everything we need to implement in future. So that was about SimPy. So let's start now with a tutorial. So all of you have tutorials like tutorial exercises. The one I gave you on the pen drive. Okay you don't have. Okay you can go here once again. You can go to this page and you can get the tutorials from here. You can get this from this website also. Start the Jupyter notebook on the same directory which you have the tutorial exercises. So using SimPy you can simply do from SimPy import everything. And we have a printing module for printing stuff in latex pretty quick. And that uses, Chrome uses MathJax to lend a latex. So I'll simply, Python has a map module and which has a sqrt function. So if you do math.sqrt2 you'll get 1.414. So this result is basically symbolic. Then we have also defines sqrt in SimPy as well. So this sqrt is from SimPy. And this is the symbolic result we get in SimPy. So I hope you have an idea of what is symbolic and what is numeric. Basically this is not a teaching session so I'll not be doing everything. We have some exercises here. So I want you people to do that. And we have some stickers as well. So I hope all of you have opened the tutorial exercises. So it says call aCos on minus 1 to find where on the circle the x coordinate equals 1. So we have all the trigonometry defined in SimPy. You can simply call aCos of minus 1. So what you saw here is called aCos on minus 1. And the answer is of course pi. And this aCos is from SimPy. So math also does have a aCos function. The math module from Python. So let's call aCos on that function. So this is the numeric result which Python gives you. So now we have symbols. So like if you have used numpy you have nda and if you have used pandas you have data frames. But in SimPy we have symbols. So if you want to do anything in SimPy using symbols. Symbols is basically mathematical stuff. So you need to write some symbols. If you want to use x, y, z as a symbol, mathematical symbols. You will simply pass the arguments x, y, z. Or you can separate them with space. So this x, y, z now holds the SimPy variable x, y, z. And we also have some fancy symbols, alpha, beta, gamma. And you have free to create expressions as you want. Let's say log of alpha into beta. Free to create some crazy expressions from SimPy. Two symbols named mu and sigma. So how we do it is this. Now if you call mu, then you will see the fancy mu. Okay, it's m, y, u actually. There is a smaller size. You need to write bell curve in SimPy. So you have to do this. Try creating this bell curve. Are you able to see this bell curve? v to the power x minus mu holds square upon sigma square. So this is just an expression. You have to create variables and then create an expression out of them. So that's it. So let's try creating one. X minus mu holds square. And then we have... So does that looks like bell curve? Okay, does that looks like bell curve? It is rearrange. Okay, am I speaking Hebrew? You're not getting? Yes. Okay. Just let me know what you're not getting. So we have used some SimPy symbols to create a complex expression. The bell curve. So here is another exercise. Find the derivative of x square. Okay, we have already found the derivative. So when you create an x symbol, and when you're creating an expression from that x symbol, that is x square. So x square is basically a SimPy expression. So you can call this dot diff method on any SimPy expression to differentiate it. Alright, that's how differentiation is done in SimPy. You can do it on some other complex expression as well and trigonometric as well. So if you differentiate sine x, you will get cos x of course. And you can also differentiate multivariate of course. So with respect to the variable you want. Now take the derivative of bell curve with respect to x. Now here is another exercise. Derivative of bell curve with respect to sigma. Are you able to? There is another exercise. Find the second and third derivative of bell curve. Okay, just raise your hands if you're able to do this. Okay. The second and third derivative of bell curve. Second and third derivative of bell curve. See, bell curve is very important, right? Of the bell curve. The bell curve we wrote earlier. Yeah. With respect to x. Yes, with respect to x. Can you do non-partial differentiation? Sorry? Can you do non-partial? Non-partial? Yeah. Like, you know, get the gradient. Okay, non-partial you mean. Okay, you want to differentiate with every variable it means. Yeah, so we have to get the gradient. Okay. So with some multivariate, it needs to... Okay, let's try to do that. So it will give you an... Because for a multivariate expression, you specify the variable you want to differentiate with respect to. So here the exercise is you need to find the second as well as third derivative of bell curve. With respect to x. So when you write this, you have the first derivative of bell curve. If you want to find the second derivative, you'll call the dip method on the return value. You have the second derivative here. And if you want to find the third derivative, you can do the same stuff. We have a straight complex expression with simplify as you saw already. We have this simplify function. So simplify as a word. So just say what you expect from it. It will try to simplify a complex mathematical expression into simple terms. So let's try to simplify this. So what do you think this simplification of sin square x plus cos square x will give? So try to call this simplify on third derivative of bell curve. So that's very difficult. How do you simplify? So we also have simplify in simplify. So don't confuse simplify and simplify. Simplify is the mathematical simplification. And simplify is a simplify simplification. So basically if you have a string, you can convert into a simplify expression. So we have passed a string here r into cos theta square. So r cos theta square. So if you pass a string, it will convert itself into a simplify string. Simpy expression. Though we don't use this carrot symbol in simplify, but it is capable of parsing a lot of complex expressions as well. So this was the symbols and derivatives functions. Let's go to this again. So simplify also have a solve function, which is used to solve expressions, equations. The first argument is the expression itself, the function itself. And the second argument is the variable with respect to you want to solve the expression well. So here we have passed x square minus 4 with respect to x. So that's what you expect from it. So equations in simplify is represented as x square minus 9 w equals to 0. So if you solve this, you'll get minus 3 plus 3. Okay. Sorry. It's a gotcha actually. So double equals to is what is comparing values in Python. So simplify is not doing anything like reinventing its wheel. So if you equate two things which are not equal, so it will return false. So if you pass false to a solve function, it will turn false, of course. There are three variables height with the area and try to solve with this area with respect to height. We are trying to solve height in terms of area and width. So nothing fancy here. So we have an expression for a volume of a sphere and we want to solve the expression for the radius of a sphere. So we will first create the expression and we'll first define the symbols. The symbols which are using here is v and r, created expression for the volume of a sphere. You want to solve this for radius of a sphere. So we'll pass the expression to solve function and the variable to solve for would be r, the radius. And this is the solution you'll get. It's a volume form. Python function for substitution. So substitution is what you expect in mathematics. Substituting a variable with respect to another variable. So we have an expression here x square and we want to substitute y in the place of x. You will simply call subs on the expression and pass the dictionary of key values and it will replace the expression. So here the exercise is create this expression x square plus 2x plus 1 and try to substitute sin x in the place of x. So we have the expression here. So it substitutes sin x in the place of x. We'll do a lot of stuff with solve here. You can solve the volume, the area with respect to height and if you want the first solution, this is simple, you can get this first solution here and you can define any type of expression in SimPy. So there is an assumption module in SimPy. For example, if you define a symbol and you want it to be real always. So you have a keyword argument for that. For example, you are defining a couple of symbols v and r and you know that volume and radius of a sphere would be always real. So you can pass this keyword argument real equal to true and if you want, you can check it as well. For example, v0 is real. So where is my size? Compute the surface area of sphere in terms of volume. I'll leave this on you. We'll move fast now. So there is some plotting support as well which is because of matplotlib. So SimPy is not inventing its own plotting module in plotting engine. So it uses matplotlib and it's for plotting module. You can plot some simple expressions in SimPy. There is outlooks and there is next plot. So now let's move to more magic. The integrals module of SimPy. So SimPy is also capable of integrating functions, expressions. So let's call SimPy and create some variables here. So we have an integrated function for that. Pass the equation, the expression and the variable with the structure you want to integrate the expression. So if you integrate x square, you'll get x cube by 3. That's what you expect. So for definite integrals, you have a couple arguments for that. The first argument is the expression for which you want to, the symbol for which you want to integrate and the upper and lower limits. And you can also do this for symbolic arguments as well. So x to the power n can also be integrated definitely from two variable arguments. This is how it looks. So here's some quick exercises to solve our integrals. Let's do some. Integrate sine x from 0 to pi. So this is the integral of sine x with respect to x from 0 to pi. So here's a small exercise. Try to find some integrals which SimPy is not capable of finding. And you can easily find some because it's not very easy to find some complex expressions. So let's move to the matrices model. We have a matrices module in SimPy which does all the matrices operation. And PiDi uses a lot of matrices. So let's create some simple symbols. And let's create a rotation matrix that is all cos theta, minus r sin theta, r sin theta and r cos theta. It is also printed pretty. So if you want to find legitimate, you can find this the jet method. You can also find the inverse and singular values. So here's a small exercise here. Find the inverse of the above matrix. So this is the inverse of 1x, 1y, y1 matrix. So the operators in SimPy also work for matrices. So you can simply multiply the matrix with 2 by doing this simple expression. And of course you can multiply matrices as well. Here's how you create a column matrix. And if you want to rotate that matrix to n angle theta, you can do rotation into that matrix. And this is how you find the inverse. Here's a small exercise. Multiply the matrix m by its inverse. So try to see if you're getting the same model matrix. So do we get the same matrix? We need to simplify that to see the original matrix. So SimPy does not do any automatic simplification. You need to simplify by yourself and expand by yourself because a lot of time we need the expanded version and a lot of time we need the expanded version. So it does not try to guess what you need. You need to explicitly mention what you need. So here's a small exercise. Find methods to compute eigenvalues and eigenvectors. So that shouldn't be a difficult task. So this is how you find eigenvalues. And you can access the items similar to what you do in NumPy. I'm finding the determinant of the rotation matrix and then simplifying it. So you can explore a lot of other functionalities in matrices module. It's going to look like a lot of things. So this is how you can see what are the methods available with matrices. m is the matrix here and you can see all the by pressing a tab button here in iPython notebook. Okay, let's see some numerical evaluation. So you may be wondering why numerical evaluation is in this SimPy library. So why I'm talking about numerics in SimPy? Since SimPy is a Symbolics library. So a lot of times you need to find the numeric result because Symbolics is not capable of doing everything for you. So you need to convert those. You need to have the functionality to use that in your numerics code. So you can find that in SimPy. So SimPy has support to... SimPy does not leave you when you are not able to do stuff in Symbolics. It will show you a path to numerics as well. So this is how you do it. So let's do some simple methods. EvaluF is basically a numerical evaluation. So what I'm doing is... So if you call a cos minus mass, it will give you pi. And if you want the numerical results, so what you will do is you will call the EvaluF function on this. There is also a shortcut for that. You can also do n here. And you can also set arbitrary precision. So if you want the value of pi to 100 digits, you can also find that. That's the value of pi to 1000 digits. So where is the smallest size? We recently found the integration of x to the power n. And the size is try to substitute that definite integral. Try to substitute that result with the values given here. n equal to 2, y equal to 0 and z equal to 3. So try to solve this. Just raise your hands if you are able to do this. Complete the integral on these values of n, y and z and get the numeric result. This is the result. And if you want to find the numeric result, you can call the EvaluF function on this. We have some small exercises we can do. So let's move to the solvers. Let's go to calculus first. There are some small exercises we can do. Try to find the differentiation of all these functions. This is how you calculate the differentiation of this function. You can create your own functions using the functionality in SimPy. You can create a function for L-Hospital rule if you remember. So I will not deep dive much into calculus here. Let me show you some features of the solvers module. So SimPy already have a solve function, which you already saw. So recently we wrote a new function, solveSet. So let me show you why we wrote that new function. Try to play with the solveSet function in SimPy. S-O-L-V-E-S-E-T. This new fusion has been implemented in SimPy 1.0 only. So recently we introduced SimPy 1.0. So if you are using an older version like 0.76, you will not be able to use this version of solvers. So let me show you what solvers was earlier and what it is now. So we have already seen some of the features of solver and the input API. So this is the old solve. And you can solve some equations with this. Not some, you can solve a lot of equations with this. So let's try to solve some. You can solve it for a single equation, for a single solution, for a set of solutions as well. And you can also solve for symbolic equations, totally symbolic equations. So here we have x to the power x-1 equal to 0. And we have solved this for x and we are getting the result 0. So let's try to solve b to the power x plus 1. So you guessed it, no solution. But it has a solution, i pi. So it actually has infinitely many solutions. If you remember the boiler's identity. So it has written only one solution. So that's actually wrong. So here we have x to the power x plus 1. And solving it for x, we will get i pi as well. That's because of the famous salary identity. And here also we are calculating the solution for e to the power x minus 1 upon x. So it has no solutions. It has written the empty list. So we don't know actually what has happened here. Because are there no solutions or we couldn't find any? So both the cases are possible. So this was a mess earlier. Let's solve the sine x minus 1 equation. That is, how many solutions do you think this equation has? Sine x minus 1 equal to 0. That is sine x equal to 1. Any guesses? It has actually infinitely many solutions. But it returns only one solution. That is the principal solution. So this is also actually wrong. Because we need to turn all the solutions. And now we have this equation 1. And this expression 1. And we want to solve this for x. So no solution. Or we can't find any. So it also does an empty list. So now we have the equation x minus x equal to 0. So how many solutions does this have? x equal to x. So it also has infinitely many solutions. Because you put anything in the place of x, it will always be true. But the result is empty list here. So this was actually wrong. And this is actually wrong. So we introduced a new module named Solset. Which I and my mentor started in year of 2014. So let's try to see how Solset handles these conditions. So long-zimpy imports Solset. Okay. You're using old Zimpy. You're not using the latest Zimpy. I need to update this. So you can just download this and run it. Just download this and run it. Okay. You want to? I'll show it out normally. No. Just download this and run it locally. Okay. Where is it? Okay. It's running here. Also it's running in the browser. Okay. Let me enter it. Okay. First equation with Solset. A x square plus B x plus C. That's the general quadratic equation. So you all know the solution. For the solution, minus B plus minus and root B square minus four is C upon two x. So it will give you what you expect. So now we have an equation one. And we'll solve it for x. So what you expect is no solution. So how do you represent a no solution in mathematics? So you represent a no solution in mathematics by empty set. So that's what it gives you. An empty set. And then we have an equation x minus x. In Solset, we also have our domain keyword argument in which you can set the domain in which you want to solve the equation. For example, if you want to solve the equation only in real complex domain, you can set it. Or if you want to solve the equation in a particular interval, for example, zero to infinity or zero to ten or anything like that. So you can set those as well. So x minus x is always true equation. So it will give you the whole real thing because you're solving it in only real domain. And if you solve it in complex domain, it will give you the whole complex domain. Now let's solve this equation x to the power x minus one. So as I already told you, there are infinite solutions to this equation. That is e to the power x equal to one because of the famous Euler's identity. So it should return infinite solutions. So how do we represent infinite solutions in simplify is this. So you're solving it in only reals. So in reals, it has only one solution. But sine x equal to one, it will solve it in real. So it has infinitely many solutions. So it should represent all the solutions. This is how it works. So basically, we have an image set module for representing these infinite solutions. And a complex set module for representing infinite solutions in complex domain. So we also implemented a linear system solver function. I did last Google summer code. So if you have a matrix and we want to solve that matrix linearly, that matrix represents the linear system of equation, you can solve that with this Linsol function. This Linsol function was inspired from the mathematical Linsol function. So let's say we have a matrix M and we want to solve this system of equation with respect to the variables x, y, and z. So we can solve that as well. And if we have two matrices A and B, and we want to solve that with respect to Linsol, the first argument is the tuple of A and B. So this is how the solution will look like. So basically, it is capable of accepting all types of input formats. Either you give it an augmented matrix, a simple matrix, or a list of equations. So it can do all the stuff. It's solid enough to solve all types of systems. So let's try to solve an augmented matrix with respect to Linsol. And we have defined some variables which we can use to solve for. So here is the solution. So the solution is minus 2x, minus 3x, 4 plus 2. So you're getting the solution because the system is under determined. So it has infinitely many solutions. For different values of x4, x4 and x2 are free variables. So for different values of x2 and x4, you'll get infinitely many solutions. So that's what it presents. And the third input type is the list of equations format. So if you have a list of equations, you can simply pass to the Linsol function. And these other elements would be the symbols you want to solve for. So let's say we have defined the equations here. These are the equations. So x1 plus 2x2 plus x3 plus x4 minus 7 equal to 0 and so on. These are the three equations and you want to solve for four variables. So let's try to solve this with Linsol. This is how you can solve all types of input format to stop the equations with Linsol and solve it. So currently, there are a lot of things which can be done in Solvers' Model. It has a lot of scope and we participate in all the rules in our code. So we hope to implement more features this desol. And if you're interested in contributing to SIFI, you can, I have list all the links here. So here's a link for mailing list. Get a sign. So get a sign is pretty active. If you want to ask for quick help, you can get here. And all the contents of this today's workshop you can find here. The slides, the notebooks, the HTML source and the source repo on GitHub. And here is my Twitter handle of SIFI and the GitHub repository of SIFI. So that's it for today. Thank you. So any questions? Yeah. Is there any other online material you can use to better understand SIFI? SIFI. There are many, there are many SIFI tutorials, there are PIDA tutorials and there are documentation. So you can find everything on SIFI.org or the PIDA.org. Okay. How about some tutorial videos and more details? Yeah, so we have actually presented everything in the SIFI. SIFI conferences. Yeah. So you can just search on YouTube about SIFI and SIFI. So let me just do that for you. Okay. So we have all the talks part one, part two and okay. So these are the videos. They are very detailed and they are just awesome. Even we have learned from them. Yeah. That's so pretty much it. So and you can search PIDAI too. So yeah. So this is one video from Jason Murek. He at least started PIDAI. He actually shifted the module from Senpai to PIDAI and he's a co-manager of the PIDAI and Senpai. He maintains a packet. So this is a talk by him and it contains everything that I've covered and in much more detail with all the realist physics and everything else. Yeah. So you can get the PIDAI with all the information that you need. Okay. And you can go to Senpai.org. Yeah. So if you have everything else. Okay.