#364: Symbolic Math with Python using SymPy Transcript
00:00 We're all familiar with the data science tools like NumPy, Pandas, and others.
00:03 These are numerical tools that work with floating point numbers, often to represent real-world systems.
00:09 But what if you could exactly specify the equations, symbolically, like many of us did back in calculus or differential equations courses?
00:17 With SymPy, you can do exactly that.
00:20 Create equations, integrate, differentiate, and solve them.
00:24 Then you can convert those solutions into Python or even C++ and Fortran code.
00:29 We're here with two of the core maintainers, Andrei Sertik and Aaron Moyer, to learn about SymPy.
00:34 This is Talk Python to Me, episode 364, recorded May 6th, 2022.
00:40 Welcome to Talk Python to Me, a weekly podcast on Python.
00:56 This is your host, Michael Kennedy.
00:58 Follow me on Twitter, where I'm @mkennedy.
01:00 And keep up with the show and listen to past episodes at talkpython.fm.
01:04 And follow the show on Twitter via at Talk Python.
01:07 We've started streaming most of our episodes live on YouTube.
01:11 Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
01:18 This episode is sponsored by Microsoft for startups.
01:26 Founders Hub to get early support for your startup.
01:29 And it's brought to you by Sentry.
01:31 Don't let those errors go unnoticed.
01:33 Use Sentry.
01:34 Get started at talkpython.fm/sentry.
01:37 Transcripts for this and all of our episodes are brought to you by Assembly AI.
01:42 Do you need a great automatic speech-to-text API?
01:45 Get human-level accuracy in just a few lines of code.
01:47 Visit talkpython.fm/assemblyai.
01:52 Andre and Aaron, welcome to Talk Python to Me.
01:54 Thanks for having us.
01:56 Yeah.
01:56 It's great.
01:58 Yeah, it's fantastic to have you both here.
02:00 You know, what a cool topic.
02:01 Symbolic math with Python.
02:03 I think I'd heard of SymPy before, but I didn't fully appreciate, you know, how neat and how advanced it really was.
02:11 So people are going to enjoy diving into this and we can talk some internals and whatnot.
02:18 And if you're doing anything scientific or computational, this is certainly a project worth checking out.
02:23 But before we get to that, let's just hear your story.
02:27 How did you get into programming in Python?
02:28 Aaron, you want to go first?
02:29 I've always kind of been into computers ever since I was a little kid.
02:34 I actually started messing around with programming and AppleScript in my family's Macintosh back when I was, like, a really little kid.
02:46 Nice.
02:47 But didn't really do any serious programming until college when I started taking, like, computer science courses.
02:54 And actually, for Python, my college had a free course that they were offering to teach this little language called Python.
03:04 So, you know, the CS course that I was taking was in, like, Java and C.
03:10 And those languages are – I wasn't a huge fan of those languages.
03:14 But I learned about this language called Python, and, yeah, I thought it was great.
03:18 Yeah, I was immediately hooked with Python just because it's, you know, it's so easy to use.
03:25 It's so easy to just write a program, and you don't have to worry about compilers or all this boilerplate.
03:34 Yeah, I'd always been a little suspicious of languages that described themselves that way, which is ironic given how much I do with Python.
03:42 But still often when you hear that, it's like, oh, it doesn't need all the symbols, and it's super easy to get started.
03:47 That means, like, oh, it's really easy to do easy stuff, but then you can't do interesting things.
03:52 And I think one of the things that's special about Python is, like, you can keep going.
03:56 You know, you don't have to stop once you need advanced ideas.
03:58 That's pretty awesome.
04:00 Yeah, it really is.
04:01 You're right.
04:02 A lot of languages kind of stop.
04:04 But Python, I mean, it's got a lot of advanced stuff as well, and it's got a huge ecosystem of libraries you can do just pretty much anything you want in it.
04:15 Yeah, for sure.
04:17 The big paradox for me is there's a joke T-shirt that I've seen that says, I learned Python.
04:23 It was a great weekend, which I think is kind of true.
04:25 You can do that.
04:26 But at the same time, for many, many years now, I've been studying Python, and there's still just so much more to learn.
04:32 One, about the language, and also just, like, as you said, all the different libraries, like, oh, I want to learn Pydantic now, or this other thing, or so on.
04:40 Very cool.
04:41 All right, how about now?
04:42 What are you working on day-to-day?
04:43 Yeah, so I work at a company called Quansight.
04:48 We do consulting, mostly around open source Python, open source data science stack.
04:56 I work about 50% of my time on SimPy as part of a grant, which we might talk about later, I think.
05:04 And I also work on different consulting projects.
05:10 Actually, right now, I'm part of a project called the Data APIs Consortium, which is trying to standardize the array API libraries for different Python array libraries, the APIs for those.
05:30 So, you know, like, NumPy and X-Array and those types of things?
05:32 NumPy, PyTorch, Jax, QPy.
05:36 So, the idea is that all these libraries have very slightly different APIs, and it makes it hard to write code against that just works against all of them.
05:47 So, what we're doing is creating a standard API that all of these libraries will target.
05:52 And so, you can write code that will just work with NumPy, but you can also just, instead of importing NumPy, you can import QPy, and that same code will run on the GPU, for example.
06:04 Oh, that's fantastic.
06:05 Yeah, that's a really good, ambitious goal.
06:08 It sounds so easy, and I'm sure it's pretty challenging.
06:12 Yeah, well, I think we're being successful.
06:15 We just released the first version of the specification, and we've got several libraries that are implementing it already, including NumPy, QPy, several others.
06:25 So, it's actually, I think it's being a successful project and should really help push the Python data science ecosystem forward.
06:35 Yeah, it sounds like a definitely good step.
06:37 Andrei, how about you?
06:38 How did you get into programming in Python?
06:40 You know, probably in high school, I was trying to figure it out when I got into it.
06:44 I think at high school.
06:45 I don't know.
06:45 I don't remember how I found it, but it was early 2000s, I'm guessing.
06:51 It was before NumPy.
06:53 It was, I think, it was NumArray, I think.
06:55 It was the array library in Python.
06:57 And during my undergrad, I was studying physics.
07:01 I wanted to play with the mathematical formulas in Python.
07:06 So, that's when I started SymPy.
07:07 And then I used Python, you know, pretty much, probably close to 20 years now, or over 20 years.
07:12 And I cannot say I'm an expert.
07:15 You know, it wasn't a good weekend.
07:20 I don't know.
07:20 A lot of the stuff I'm not that great at, you know, but the basics, I would say I know pretty well.
07:26 Yeah, sure.
07:27 After my PhD in physics, I went to work at Los Alamos National Lab for about eight years.
07:32 Computational physicist.
07:34 I use Python.
07:36 I use a lot of Fortran, a lot of computational codes, and a lot of C++.
07:39 That sounds fun.
07:40 There's a lot of Python stuff happening there at Los Alamos.
07:42 Yeah, it is.
07:43 The NetworkX, I think, library was started here.
07:48 And then, very recently, half a year ago, I changed jobs.
07:53 I now work at a company called GSI Technology, which is a hardware vendor, as a compiler developer.
08:00 And so, at Los Alamos, I started this compiler for Fortran called L-Fortran.
08:07 It's a compiler for Fortran, but it also allows you to use it interactively, just like you would Python.
08:11 It runs in a Jupyter Notebook, as well, as a kernel.
08:14 And at this new company, we are also, in addition to L-Fortran, creating a new frontend called L-Python,
08:22 which takes Python, but compiles it through the same pipelines, through the same intermediate representation
08:28 and all the backends.
08:29 All the code is the same.
08:31 So, effectively, it treats Python like Fortran.
08:33 So, the same speed, and so forth.
08:37 Oh, wow.
08:37 That sounds awesome.
08:38 It is awesome.
08:39 Yes.
08:39 Very, very cool.
08:41 All right.
08:42 Well, super fun to be talking about SymPy with you all today, symbolic math.
08:48 I want to start this off, though, with a write-up from Aaron that is maybe not what people would expect
08:56 as the first topic to introduce SymPy.
08:58 SymPy has been in the news a little bit for the wrong reasons recently, right?
09:02 Right, Aaron?
09:04 So, it was even on the front page of Hacker News because this company, HackerRank, reached
09:12 out to GitHub, sounds like through automated ways, and said, we seem to see some math that
09:20 looks like questions we might ask or something like that.
09:23 So, we need to completely ban SymPy because they're stealing our interview questions or something
09:29 like that, right?
09:30 Give us the story.
09:31 What kind of madness was this?
09:33 Yeah.
09:33 So, we sort of just got this notice from GitHub that a DMCA takedown had been issued against
09:40 one of the pages on our documentation.
09:44 And the way the DMCA works and the way GitHub's DMCA policy works is when somebody issues a notice,
09:51 they basically just have to take it down.
09:55 And GitHub basically took down the entire documentation site for about 12 hours.
10:03 And so, I've got a timeline of everything that happened here in this blog post.
10:10 But basically, yeah, they had some company that they were working with to try to find their
10:20 solutions on GitHub and issued DMCA takedown notices against them.
10:25 And somehow, this SWIRTH IT solutions company decided that our docs was one of these, and they
10:32 just issued the notice.
10:33 And so, yeah, it ended up taking down our documentation, which immediately, like you said, it made it
10:42 to the top of Hacker News and kind of tension.
10:46 Because it's too outrageous.
10:46 Yeah.
10:47 So, the notice itself, it was completely ridiculous.
10:53 Like, the stuff that they were claiming was their copyright is probably not even copyrightable.
11:02 Like, if you look at the examples on that documentation page that they took down, they're just like
11:08 simple math examples.
11:09 Yeah.
11:09 It was like X squared minus two solution is, you know, negative plus or minus radical two.
11:16 Right?
11:16 Like, that you shouldn't be able to copyright.
11:19 I think that actually predates HackerRank's foundation.
11:23 I think it predates HackerRank as a company.
11:26 Yeah.
11:27 Yeah.
11:27 So, the CEO of HackerRank, I guess, noticed the buzz that was being made about it and retracted
11:36 the notice.
11:36 So, the docs ended up going back online about 12 hours later.
11:41 If they hadn't done that, we would have had to issue a counter notice, which would have kept
11:47 the docs offline for about two weeks before that counter notice would have taken effect.
11:53 And that's just because of the way the DMCA law works.
11:55 I also explained how the DMCA law works in this blog post.
12:00 If anyone's wondering, like, why would GitHub even do this?
12:04 Like, well, they're kind of required to do this kind of stuff by law.
12:07 There are some ways I think they could have improved what they did here, which I go over
12:12 as well.
12:12 But this DMCA law is really...
12:14 It's probably like pointing those out.
12:15 Yeah.
12:15 So, I mean, the DMCA provides what's called safe harbor for places that host user-generated
12:22 content, basically.
12:22 YouTube, the social media places.
12:25 GitHub clearly has a ton of user-generated content that's public.
12:29 If you got the source code of Windows or something and you posted it up there, right?
12:35 Theoretically, Microsoft might say, you know, we don't really want you hosting this.
12:38 It's not supposed to be open source.
12:40 Please take it down, right?
12:41 So that's the idea.
12:43 The way it works, though, is basically once there's a request to take it down, they just
12:49 have to...
12:50 Here's the part that I think that got missed.
12:52 Decide that it's a valid request and then just take it down.
12:55 Like, they don't really try to negotiate or determine the right...
13:00 The correctness of that assertion, right?
13:03 Yeah.
13:03 So they sort of have to stay, like, as a disinterested third party, I guess.
13:11 And the reason is that in order for them to have the safe harbor, the safe harbor status
13:17 sort of frees them from the liability on either side if there is a copyright claim or if there's
13:24 a lawsuit or something.
13:25 They can just say, okay, well, we're just hosting the content.
13:29 The law sort of allows them to do that.
13:31 But in order to do that, they sort of have to just...
13:34 If they get a DMCA claim, they have to just take it down.
13:36 And then if there's a counter notice issued, then they can put it back up.
13:40 And the DMCA has these...
13:42 The DMCA sort of tells them that if they get a claim, they have to sort of take it down expeditiously.
13:49 And if there's a counter notice, they have to put it back up in 10 to 14 days.
13:54 So it's...
13:55 There's a lot of parts of the law that they sort of have to do.
13:59 There's some things I think that they could have done better.
14:02 And there's also some things that they already do, which they don't have to do, which are nice,
14:06 including they have a repo where they actually post every single DMCA notice that they've received,
14:12 going all the way back to 2011, actually.
14:15 Interesting.
14:16 So you can actually see all the DMCA notices that have been issued against GitHub repositories on that repo.
14:22 It's github.com/github slash DMCA.
14:28 This portion of Talk Python to Me is brought to you by Microsoft for Startups Founders Hub.
14:32 Starting a business is hard.
14:35 By some estimates, over 90% of startups will go out of business in just their first year.
14:39 With that in mind, Microsoft for Startups set out to understand what startups need to be successful
14:45 and to create a digital platform to help them overcome those challenges.
14:49 Microsoft for Startups Founders Hub was born.
14:52 Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
14:58 The platform provides technology benefits, access to expert guidance and skilled resources,
15:04 mentorship and networking connections, and much more.
15:07 Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be
15:13 investor-backed or third-party validated to participate.
15:16 Founders Hub is truly open to all.
15:19 So what do you get if you join them?
15:21 You speed up your development with free access to GitHub and Microsoft Cloud computing resources
15:25 and the ability to unlock more credits over time.
15:29 To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI,
15:34 a global leader in AI research and development, to provide exclusive benefits and discounts.
15:39 Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
15:44 You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of
15:49 disciplines and areas like idea validation, fundraising, management and coaching, sales and marketing,
15:55 as well as specific technical stress points.
15:58 You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
16:03 Make your idea a reality today with the critical support you'll get from Founders Hub.
16:08 To join the program, just visit talkpython.fm/founders hub, all one word.
16:13 No links in your show notes.
16:14 Thank you to Microsoft for supporting the show.
16:19 I want to preface this by saying I'm not a lawyer, so I'm only speculating here.
16:24 But one of the things that seems very, very much like it fell through the cracks.
16:28 And this part, I think, is both maliciousness and laziness on the worth IT company, as well as,
16:36 you know, sort of either laziness or disinterest, I guess, from GitHub.
16:42 I don't really know how to characterize it.
16:43 But this company came and said, on your documentations, there is content that is copyright.
16:50 And it comes from our website.
16:52 And it just linked just to the homepage of that other website.
16:56 You got to take it down.
16:57 That seems like insufficient information to GitHub to go, yeah, well, they said there's a website.
17:04 And here's a website.
17:05 That website doesn't like this one.
17:06 So it should go away.
17:07 It should say, do you see these lines of code here?
17:11 That was stolen from us.
17:13 And here's where it originates.
17:15 Or, you know, our thing is not public.
17:16 But these are the lines.
17:17 They didn't even say what was wrong, right?
17:19 It just said, we believe this code is going to destroy them.
17:22 It was insufficient even for us if it was an accurate claim.
17:25 Because if you look at this page that they put the claim on, it's a huge page.
17:30 Because it's got, like, about a dozen different functions on it.
17:35 And it just said that they copied our examples.
17:38 It didn't say which part of the page was copied or anything.
17:41 So, yeah, I mean, I still don't know, like, how they even decided that this was a thing.
17:49 That somehow their automation got flagged incorrectly or something.
17:54 I don't know.
17:55 Like, I don't know if we're ever going to know that.
17:57 Yep.
17:58 All right.
17:59 Well, I don't want to spend the whole time on this.
18:01 But let me wrap it up with a quick thought.
18:04 The CEO of HackerRank, Vivek, posted a message that said, this was not our intended consequence.
18:13 Yes.
18:14 But if you send bots running around the internet looking for algebraic equations and saying that those are, you know, like, this is your problem, even if it was not your intent to do these things.
18:30 And so they fixed it.
18:34 I don't know what they're doing now.
18:35 But they said, we're going to stop the whole process for now and figure out what we can do better.
18:38 But on the other hand, we should give them props for donating $25,000 to the Senpai project as a, we're sorry.
18:45 That's actually kind of cool.
18:47 They didn't have to do that.
18:49 No, they did not have to do that.
18:50 And they did send the money, I think, last week.
18:53 And so just...
18:55 You guys are all on vacation?
18:56 What is this, Hawaii?
18:57 I'm just teasing.
18:58 Or if the finances are online, you can find them up.
19:03 I think it's an open collective and it pretty much almost doubles our budget.
19:07 And so it will allow us to really fund all kinds of cool development.
19:11 One thing on this note I wanted to say is that I was thinking, so when it all started, I felt like a little guy completely being crushed by some huge corporation or just this.
19:23 You know, they just take down the documentation and GitHub just says, you know, it's not enough to put a commit to fix it.
19:29 You have to excise the commit from the Git history.
19:32 So we would have to figure out exactly what line was copied.
19:36 And so I went to the Git history and tried to look up, well, maybe some of our contributors maybe copied some stuff from HackerRank.
19:42 So I went to the history, but they didn't see anything.
19:45 They did not see any mention of HackerRank.
19:47 You know, oh, I copied this from HackerRank.
19:49 They didn't see anything like that.
19:50 They didn't see anything suspicious.
19:51 But the consequence was dire.
19:54 And also the documentation is generated from the Simpi source code.
19:57 So really, the offending lines are coming from the Simpi repository itself, not just the documentation.
20:03 So luckily they missed it.
20:05 We were really, I was like, well, this might be, this is terrible.
20:09 And then they, oh, and also we thought maybe, maybe this looks like a spam, you know, maybe it's just a spam.
20:16 So we kind of ignored it a little bit, not ignored it, but, you know, we didn't know.
20:20 And so I emailed GitHub right away, is this real or is this just a spam?
20:24 And they got back to us on Monday evening and said, no, this isn't real.
20:27 And then the next morning they took down the whole documentation.
20:29 So I felt really just, you know, I spent, Aaron and others spent so many hours just trying to figure out what we should do and what the options are.
20:38 And I was, it was, Google Summer of course was, Redline was on that Tuesday, I think as well.
20:44 So I was just super busy with that.
20:46 I just felt, you know, this is, and I'm doing this for free for Simpa.
20:48 I don't think I've ever paid anybody to work on Simpa.
20:52 I just felt, you know, this is, this is not right.
20:55 And then when it got to Hacker News, I thought, you know, I thought about how can the company, what can they do to like fix it?
21:02 And I thought, you know, there's not much they can do, the time was wasted.
21:04 But then Drag Race got an idea, Oliphant got an idea, well, why don't they donate some money?
21:10 And I thought, you know, this would fix it.
21:12 And so I didn't think they would do that, but I'm very happy that they did.
21:15 As far as I'm concerned, personally, I don't, I think we are even, they, they give us the money and we can use it to really progress the development forward.
21:25 So I'm very happy that how it all ended for Simpa.
21:28 Sure.
21:29 You could pay to hire somebody to work on some important part, or you could pay to have sprints, like bring the people together to work together or something like that.
21:37 Right?
21:37 Nice.
21:38 Yeah.
21:38 We're still, we're still talking about what we're going to do.
21:40 Cool.
21:42 Well, I'm glad it came out well, but what a wild story.
21:46 I've had, I've had run-ins like this before, and they are incredibly frustrating.
21:51 Even when you're on the right side of it, it's just like, you know, you're, you're up against lawyers from.
21:58 Yeah.
21:59 You're on, you're on YouTube.
22:00 So I've heard that DMCA is going to be pretty bad on YouTube.
22:03 I don't know if that you've ever been hit by anything like that there.
22:05 I, you know, what's so funny is only once as it happened on YouTube, it's happened for my courses.
22:12 It's not exactly, it's happened sort of almost in reverse for my courses.
22:16 I put one of my free courses on Udemy as a way to try to reach out to people who didn't already know about my content.
22:24 Like, I'll put it up there for free.
22:25 People can experience it there, and then maybe they'll go look for other courses for me, like, you know, something like that.
22:31 Someone stole my free course, started selling it on Udemy, and it took me two weeks to get them to, to even take it down.
22:39 Even though at the beginning, it's a picture of me saying, hi, I'm Michael.
22:43 And I'm like, you gotta, we don't believe this is yours.
22:46 Like, what do you mean?
22:47 Have you watched it?
22:49 The person who is the account it's under is absolutely clearly not Michael.
22:55 Anyway, on YouTube, what has happened to me is I was doing a webcast way back in the day when people would call in, sometimes on phones,
23:04 and somebody interrupted someone else on, during the webcast, and they put it on hold.
23:11 And it was really frustrating because their hold music started playing back into the webcast.
23:16 And for some reason, the way it was set up by the company I was working with to do it, they couldn't stop it.
23:21 So there was just like five minutes of hold music going along with the presentation.
23:26 That hold music got a DMCA takedown, and it took down my webcast.
23:30 So what are you going to do?
23:33 I didn't really mind.
23:35 It was kind of a crappy thing anyway, but, you know, it was up there, and it got taken down.
23:38 All right, let's talk about Senpai because I think this is a really neat project.
23:43 Like I said, when I think about the data science stack and the scientific computing stack of Python,
23:49 traditionally what I've thought of is NumPy, Pandas, Matplotlib, the stuff that does numerical processing,
23:59 and then maybe visualizes that or does machine learning off of it or something like that.
24:03 But Senpai, I think, occupies a slightly different but really important space in this whole computational Python stuff.
24:11 Tell us about it.
24:11 Yeah, so Senpai, like you said, it sort of stands in contrast to these other libraries in that it's not,
24:18 it is a mathematics library, but it's not numerical, it's symbolic.
24:22 So the focus is on computing with mathematical expressions exactly.
24:29 So, you know, if you tell Senpai to, like you said earlier, solve the equation x squared minus 2 equals 0,
24:37 you'll get the exact answer, square root of 2 minus square root of 2.
24:41 You won't get a numerical answer like, you know, 0.7, whatever square root of 2 is.
24:48 Yeah.
24:48 But you'll get that exactly, square root of 2.
24:52 And so there's all sorts of things that you can do with symbolic mathematics.
24:57 People may be familiar with other similar tools called, it's basically, it's called the computer algebra system.
25:07 There's proprietary tools like Maple and Mathematica.
25:10 There are some other open source systems that people may have used as well, like Sage and Maxima.
25:18 So just, if you've ever heard of any of those, Senpai sort of occupies a similar space.
25:23 But Senpai, I guess, sort of stands apart from those in that it's open source and it's also, it's a Python library.
25:30 So if you're familiar at all with Python, it's really easy to start using Senpai because it's just Python.
25:37 Yeah.
25:38 I think people who have not seen this kind of stuff in action should definitely go poke around and check it out.
25:45 And we'll talk about some ways in which you can play with it just online with super low effort.
25:49 I remember the first time I had been previously using MATLAB or something like that.
25:56 And I saw Maple, which is one of the ones you called out, which is a symbolic sort of solving thing.
26:02 You can say, oh, here, I want to do the integral from negative infinity to positive infinity of this thing.
26:07 And it looks like it would come out of the textbook and it will sometimes even show you the steps.
26:12 It's unbelievable.
26:13 And that was 20 years ago when I saw it.
26:15 I'm like, that's unbelievable that this computer is doing this.
26:18 And Senpai is like that, but for Python, which is fantastic.
26:22 Yeah.
26:22 So it's, you know, it's basically, you know, it's the math that you would learn in a classroom.
26:28 Except it, you know, it can also get very advanced.
26:31 Like you said, we can do integrals.
26:34 We have lots of very advanced mathematical features.
26:37 We can do, we have a module for doing various areas of physics, for example.
26:44 Nice.
26:45 And it's also the foundation of many other things as well.
26:49 Just as a, like setting the stage, a preview is you've got algebra, you've got calculus, you've got differential equations, you've got linear algebra and matrices.
27:00 It's there's a lot of, a lot of good stuff in here.
27:01 Andrei, do you want to maybe give us a little run through of like sort of the selling points of Senpai?
27:08 Yeah, that's very easy.
27:10 I was an undergrad student and, you know, studied physics or any kind of engineering a lot of times, even math.
27:16 You have to do a lot of symbolic, you know, I would say derivations on paper.
27:21 And I remember sitting in a physics class and I thought, you know, this, I would like to do this from Python, interactively.
27:29 And so that's the idea.
27:30 And then of course I sat down and I thought, well, let's get started.
27:34 And my friends were telling me, you know, what, you know, can it do Gaussian integrals?
27:38 You know, it's this integral of exponential, some polynomial, you know, X squared, for example.
27:42 And I said, you know, it cannot because, but it will in five years, just not now.
27:48 That's the hard problem.
27:51 Oh, and I said, well, then use Mathematica.
27:53 It could do it now.
27:54 But, but they asked me, well, why don't you use Mathematica?
27:58 You know, and I said, you know, Mathematica is great.
28:00 Maple as well.
28:02 It's absolutely, as you said, Michael, absolutely amazing that, you know, 20 years ago, and it could do all these integrals and, and serious expansion of these functions.
28:10 Yeah, I was using Windows NT when I did that.
28:13 I like how old that was.
28:14 I did too.
28:14 I did too, actually.
28:15 And so, yeah, and, but, but the motivation is, to be able to do this from Python interactively allows you to kind of almost program with the symbolics using a language.
28:27 That's a pretty decent language that you might already use for something else.
28:32 And so what I wanted to do is assign the expression to a variable, then use the variable interactively and write some scripts to kind of handle my, my calculation and maybe save it to a file after that.
28:43 And, and so on.
28:44 And so that's, once you want to program with that, Mathematica, it allows you to program, but you have to learn.
28:50 Yeah.
28:51 And so that's why I wanted to have that in Python.
28:53 Yeah.
28:53 And so that's why I wanted to have that in Python.
28:57 Well, the other thing that from this perspective, sitting on the Python or the comp size side of things and looking back is obvious.
29:07 I don't know that it is as obvious coming from the other perspective of like, oh, I'm doing a MATLAB.m file or whatever.
29:13 But in that world, if you work in MATLAB or Mathematica, you can do what MATLAB or Mathematica does.
29:20 Right.
29:21 That's a, it's really amazing in its specialty, but it's very specialized and limited.
29:26 Right.
29:26 You can't build like, you know, FastAPI and database driven apps that are doing some of this kind of computation along the way.
29:33 right, if you move it to Python, like this is now, this capability is now accessible for all the applications, not just within, you know, the, the MATLAB or Maple environment.
29:46 Yeah.
29:47 And I, I guess it's an argument, you know, what's the advantage of Python, let's say for numerical computing, let's use it by or scientific, let's say for scientific computing, but the advantage of Python over, let's say Mathematica.
29:58 And I think it's not a clear good answer.
30:00 I think Mathematica is great.
30:01 And they've done actually, it's quite amazing how good job they've done because they designed the language, I believe in the early eighties and they did not have to really modify the language too much.
30:10 it was same spirit.
30:11 So that's kind of amazing.
30:12 It's much older than Python.
30:14 So it's quite amazing how far, and then it still works pretty well and it's a decent language.
30:19 But I think what I like about Python for scientific computing, you know, is that it's open source and it's the language just seems more kind of robust and kind of easier, more imperative.
30:29 Don't have to really learn too much.
30:30 It seems that anybody can learn it quickly and doesn't seem to have too many kind of things that would surprise you.
30:37 Yeah.
30:38 Very cool.
30:39 So how long ago did you start on Senpai?
30:42 I think I started in 2005 or six.
30:45 Nice.
30:46 It's been going for a while.
30:47 Yes.
30:48 So that really predates a lot of the scientific computing frameworks that are well known today, right?
30:54 So you must have felt good about picking the right horse as you saw, you know, Jupyter or IPython at the time come along and those libraries like that.
31:04 Way before Jupyter, IPython was there.
31:07 Somebody told me about it and I tested it out and I thought, you know, this is pretty cool.
31:11 It looks like Mathmerica.
31:12 Then I later, when I talked to Fernando Perez who wrote it, he said, yeah, it's Mathmerica.
31:16 That's what I wanted to have in Python.
31:17 That's what I wanted to have in Python.
31:18 So kind of the same motivation almost.
31:20 Just, you know, so he kind of provided the foundation for the interactive part, you know, with the prompt and the numbers.
31:28 This portion of Talk Python to me is brought to you by Sentry.
31:32 How would you like to remove a little stress from your life?
31:34 Do you worry that users may be encountering errors, slowdowns or crashes with your app right now?
31:40 Would you even know it until they sent you that support email?
31:43 How much better would it be to have the error or performance details immediately sent to you, including the call stack and values of local variables and the active user recorded in the report?
31:54 With Sentry, this is not only possible, it's simple.
31:57 In fact, we use Sentry on all the Talk Python web properties.
32:00 We've actually fixed a bug triggered by a user and had the upgrade ready to roll out as we got the support email.
32:07 That was a great email to write back.
32:09 Hey, we already saw your error and have already rolled out the fix.
32:12 Imagine their surprise.
32:14 Surprise and delight your users.
32:16 Create your Sentry account at talkpython.fm/sentry.
32:20 And if you sign up with the code talkpython, all one word, it's good for two free months of Sentry's business.
32:26 This is a great idea of Sentry's business plan, which will give you up to 20 times as many monthly events as well as other features.
32:32 Create better software, delight your users and support the podcast.
32:36 Visit talkpython.fm/sentry and use the coupon code talkpython.
32:41 When you work with Senpai, we'll see some examples and talk about them in a minute.
32:47 You can put it into this pretty printing mode where it attempts with as much as it can within the terminal output to have more formal mathematical representation.
32:59 So instead of like E^x, it might put a little smaller x up high and then an E down slightly to the lower left of it like you would try to write it.
33:09 It seems that if it's in a notebook, it should be able to do even better, like maybe a LaTeX rendering or something really shiny.
33:16 Yeah, it does.
33:17 So in the notebook, it'll use the MathJax.
33:19 So it'll, it'll, yeah, it'll, it'll just use, it'll look, it'll look great basically.
33:24 Cause it, the MathJax looks just like, it's the same as a Logitech document.
33:28 Yeah.
33:29 Yeah.
33:30 Oh man.
33:31 Yeah.
33:32 And in the terminal we use, we use, we use all these different Unicode characters to, to sort of render it as 2D text in the terminal so that it looks, it looks pretty decent in the terminal considering the constraints of a terminal.
33:46 Nice.
33:47 And I personally use it.
33:49 I mainly use it in the terminal.
33:51 I saw it.
33:52 Yeah.
33:53 So let's go and maybe, maybe we could walk through a little bit on one of the tutorials here.
33:57 I mean, obviously we don't want to talk too much code or whatever, but I do think maybe just touching on this, will give people a sense of what it's like to work with this because.
34:09 Yeah.
34:10 So I think.
34:11 Yeah.
34:12 Yeah.
34:13 Give it, give us a sense of what.
34:14 In the tutorial, there's a, there's actually a section somewhere.
34:16 where is that section?
34:19 This one perhaps.
34:20 But didn't get deleted.
34:22 That's, it's in the introduction page.
34:25 Yeah, it's on that page.
34:26 But, if you maybe, scroll down, to this, the power of symbolic computation is the name of the header.
34:33 There you go.
34:34 So this is just, this is just sort of a, a bucket list of, just sort of a, a bunch of different examples of, of things that can do.
34:41 So just to give you an idea and actually you can see there.
34:45 also you can also see the, the pretty printing there as well, that Unicode pretty printing, that it does.
34:51 that law tag is what we would see in the notebook.
34:54 So you have to run underscore printing using Unicode equals true, right?
34:57 It, it doesn't do it by default.
34:59 it, it, yeah.
35:00 So that in, in the notebook, it does actually do it by default.
35:03 Sure.
35:04 But not in the terminal or the rebel.
35:05 Yeah.
35:06 In the terminal, you need to, you need to run this.
35:08 Otherwise it'll just print out like a one dimensional string that, that, you would get.
35:13 it would, it looks sort of like what you would input.
35:16 but yeah, you can see here, we can, it can take derivatives, take integrals.
35:21 if you keep scrolling down, you can see, I think limits and, differential equations.
35:28 you can solve.
35:30 Yeah.
35:31 So let me, let me talk people through just a couple of things, because I think.
35:34 it's a little hard to understand how this might work.
35:37 And the trick, I think really Andre, you tell me your thoughts on this is the, the ability
35:45 for it to, define these symbols and these functions, here.
35:50 Yeah.
35:51 So the trick able to represent the expression symbolically.
35:54 So you type, X plus Y, and plus some function sine X.
35:59 And in, in memory, it represents it as a tree and it, and it, of course, the expression in symbolic
36:04 form.
36:05 And then it allows, it has all kinds of functionality that allows you to manipulate the expression,
36:09 print it, you know, differentiate it.
36:11 So many differentiate, or let's say an expression that takes the original expression and creates
36:15 a new expression, the derivative.
36:17 Right.
36:18 With normal math, like pen and paper math, you don't usually define variables every now and
36:24 then you say, you know, let X be an element of like the real L, real numbers such that,
36:28 whatever.
36:29 Normally you just say F of X or F of T or something like that, or Y.
36:34 And it just works.
36:35 You needed some way in Python to allow you to write expressions like X plus two Y without Python
36:44 going, I have no idea what that means.
36:45 Right.
36:46 Yes, that's right.
36:47 So, and yes, you first have to declare what X and Y is.
36:50 You declare it as a symbol and then you can use it.
36:52 We override the Python operation like plus, minus, and then you can construct the expression.
36:58 And so what's nice about Python is that when I started with simple, I mean, I was kind of
37:02 investigating the, the, the idea.
37:03 What's nice that Python pretty much allows you to override all these operations.
37:07 And so you can write it almost like math, you, in exponential, two stars.
37:12 Yeah.
37:13 Only caveat is that if you write, let's see one divided by two, and we started in Python
37:18 two, that gives you a zero, I believe.
37:20 And that's very confusing from Synthy's perspective, because you would like it, you would like it
37:24 to give, the expression one over two, not, not zero.
37:28 And because, and so I, I don't think there is any way still to, to, to fix that, to override
37:34 this division.
37:35 Yeah.
37:36 At least in Python three, you get the right, at least you can load.
37:38 I, what you get, I float double precision.
37:41 Yeah.
37:42 Yeah.
37:43 You don't want that.
37:44 You want one divided by two as simple expression.
37:46 So, so when you have something like that, you have to wrap the number one into a teacher
37:51 S.
37:52 Yeah.
37:53 Or, define some kind of symbol with that value and then use it like, like you have
37:57 to go over B from, you know, quadratic equation.
38:01 Right.
38:02 You could like that kind of thing.
38:03 but yeah, so you create these symbols and then you can write simple math that looks
38:09 like it's just straight Python.
38:10 So you could say X and Y are symbols.
38:13 And then you could say something like X plus two times Y plus one.
38:18 And that, that isn't not evaluated in any way.
38:22 It's just becomes this, like, as you said, as tree, this expression that then you can operate
38:26 on, like integrate it, take the derivative of it, find the limit of it, all those kinds of
38:31 things.
38:32 Right.
38:32 So, yeah, that's the basic idea.
38:33 Yeah.
38:34 Yeah.
38:35 That's the basic idea.
38:36 and, and you can use it to do any, basically any sort of math that you would normally do,
38:42 with, with so that sort of expression, except you're doing it on the computer.
38:46 So cool paper.
38:47 You can do, you know, just like a real simple example might be, rational polynomials
38:52 or something like that.
38:53 Like if you had X squared minus one is one equation and then X plus one as another equation,
39:00 you could say the first equation divided by a second and get, geez, which did I say minus
39:05 that you get X minus one as simplifications.
39:08 Another one where you can take something and it'll, it can figure out how to simplify it to
39:13 an equivalent form.
39:14 That's like, like dividing out factors and things like that.
39:18 Yeah.
39:19 Okay.
39:20 These are, are super neat.
39:22 you can do factors.
39:23 So like you say, you could say like, polynomial factors, you know, one of the things I don't
39:28 know if I should point this out, or maybe this should have been a warning to the whole show.
39:33 If you're in high school or early college, this might be a terrible cheat sheet for homework
39:41 and other types of is fantastic, right?
39:44 If you're in an algebra course, you can do, do your work and then you could type this in and
39:49 type this in and go, did I get it right?
39:51 Wham.
39:52 And out it comes, especially in a notebook.
39:53 Right.
39:54 Yep.
39:55 Yeah.
39:56 I mean, I think that's kind of unavoidable these days.
39:58 you know, there's cause I mean, there's, there's also, you know, just graphing calculators
40:05 that do this as well from alpha.
40:07 I think simple is a great, a great way to do that if you're going to do it because now
40:11 you're also learning Python.
40:12 Right.
40:13 Which I think is, would be great for someone who's like a high school student or an undergraduate
40:19 because that, that's an actual useful skill as well.
40:22 It might be even more, utilitarian in the long run than the calculus they're learning.
40:29 so yeah, you can do like, derivatives and integrals of these equations.
40:35 So you could say integrate E to the X times sine of X plus E to the X times cosine of X.
40:41 And it will give you the result, which apparently is E to the X sine of X.
40:45 I used to be able to do that.
40:46 I can't anymore.
40:47 Well, you can see that the line above it, it's differentiating that.
40:51 So it's just undoing the line above it.
40:53 Oh, I see.
40:53 Well, that, that does, that is a bit of a cheat, isn't it?
40:56 Yeah.
40:57 But yeah, I mean that that's, yeah, you don't, that it, the integration is nice.
41:01 Cause you don't have to remember all the, these, how to do all this integration by parts
41:05 or whatever you would do.
41:06 Yeah, exactly.
41:07 So another thing it can do is, like concrete.
41:10 I forgot.
41:11 There's like a better term for that, but definitely integration over a range or, or so.
41:16 So you could say integrate from like negative 10 to 20 of sine of X squared, or here's the
41:22 example of negative infinity to positive infinity.
41:25 And it says that square root of two, you know, radical two, radical pi over two as the answer,
41:31 not like point.
41:32 What is that point to something, something, something, something, something, I don't know,
41:37 something like that.
41:38 right.
41:39 It gives you the actual theoretical answer, the exact mathematical answer in symbols, which
41:44 is amazing.
41:45 It is, it's amazing.
41:46 And it's also not easy to.
41:48 So when I started in SIFI, I knew this is not easy to program.
41:51 Like how, how do you program such an integrator?
41:53 It's not easy.
41:54 But I figured, you know, if I can at least figure, at least get the basics, you know, like
41:58 be able to represent these equations at least, that would still be a huge help.
42:02 Cause sometimes the expression can be long and be able to manipulate it.
42:05 And then as we were joined with, you know, so many, excellent people, they, they contributed
42:10 all the, all the features students, mostly actually it was developed by Google summer of
42:14 cold students.
42:15 And okay.
42:16 Yeah.
42:17 Cool.
42:18 It's, it, it, it, I would not be able to do that.
42:21 Let's just put it that way.
42:22 It's a, it's a lot of work that's behind it.
42:24 Yeah.
42:25 I'm looking at this.
42:27 I know these concepts just on pure math are hard and then to automate it in general, it's
42:32 got to be next level.
42:33 so other things you can do is like, you can define a function.
42:36 So here you say, here's a function called Y, and then you can say, well, what if you had
42:41 the differential equation that was, you know, the second derivative of Y minus Y equals E
42:46 to the T, right?
42:48 Solve that.
42:49 And then sure enough, outcomes, the solution.
42:53 So that's a function for that.
42:55 what the function is, which is pretty amazing.
42:58 Yeah.
42:59 So does things like, eigen values from, linear algebra and all kinds of stuff.
43:06 yeah.
43:07 Great.
43:08 And then we have in Python, we have stir and repper.
43:12 You guys also have late tech, which is pretty cool.
43:16 Right.
43:17 I just call latex, latex on a function and out it comes with like the crazy escape code.
43:22 Latex that you would need for a paper or something.
43:25 Right.
43:26 Yep.
43:27 Yeah.
43:28 And this, this actually, I mean, this is only even scratching the surface of, of the, what
43:32 Simpa can do.
43:33 So it's actually quite a large library.
43:37 Yeah.
43:38 I don't want to focus too much on just the pure math, but maybe give us a sense of like some
43:42 of the things that amaze you.
43:43 What do you have in mind when you're saying that kind of stuff?
43:45 that amaze me.
43:46 Yeah.
43:47 I mean, I'm, I think the whole thing's amazing still, even though I know how it works
43:53 and I've been working on it for awhile, but yeah, just the fact that the computer can do,
43:57 the same sort of mathematics that you would do, on a piece of paper is, is incredible.
44:03 some of the algorithms that to do like integration and stuff are also, pretty interesting
44:09 because, they, they sort of, they go beyond what you would learn in a calculus class.
44:14 there, there are algorithms that, that can compute integrals that you would, you would
44:18 never be able to know how to compute them just using what you'd learn in a, in a calc one
44:23 or calc two.
44:24 Sure.
44:25 but those, those are something that you can actually implement in something like Simpi
44:29 and then, Simpi will be able to do those integrals for you.
44:33 some of the features that, I mean, if you go on the website, there's a, there's a
44:39 huge list of features.
44:40 I think, one feature that we didn't mention that's, that's maybe worth mentioning,
44:46 is, code generation.
44:49 So, code generation, means that you take one of these expressions and you turn it
44:56 into basically code for another language, whether that's C or Fortran or, pretty much any,
45:05 any language that you would want to, translate it into.
45:09 And then you can then take that expression and, and, basically convert it into, something
45:15 that you could numerically evaluate, very fast in, in whatever language you prefer
45:19 to use.
45:20 Wow.
45:21 Okay.
45:22 So you've got your notebook written in Python or something and you've come up with some expressions
45:25 and you're like, I would like to just do that in Fortran or C and I, and I don't trust myself
45:31 to get it right.
45:32 myself to get it right.
45:33 So just print out the syntax basically.
45:36 Yeah.
45:37 Yeah.
45:38 Oh, go ahead, Andre.
45:39 Yeah.
45:40 Well, let's say you want to approximate some function, you know, with a polynomial.
45:43 So you, you can use him by to do that.
45:45 And then at the end, you just want the polynomial in the form that you can put in your production
45:49 code, whether for Tron or C.
45:50 So it's still simple to do it.
45:52 Then you can copy and paste it.
45:53 You know, it's correct.
45:54 Assuming there is no back in simple.
45:55 Yeah, sure.
45:56 Yeah.
45:57 But I suspect it's probably pretty straightforward.
46:01 Once you've got the expression to break it down into, you know, this is a multiply.
46:06 Here's where the parentheses that group it in the expression tree.
46:09 But yeah, there's, I mean, there's, there's a few places where it's like, okay, we need
46:14 to make sure we get the semantics.
46:16 The semantics might be a little different between like C and, and Python or something like that.
46:22 Yeah.
46:23 So we need to make sure we sort of translate that correctly.
46:25 But yeah, it's, I mean, in principle, it's not that hard, but I mean, it's not that hard.
46:30 I mean, it's also not something you want to do by hand either because.
46:34 Yeah.
46:35 It's super error prone if you were to try to do it by hand.
46:37 Yeah.
46:38 Yeah.
46:39 It sounds like a great feature.
46:40 That's, that's quite neat.
46:42 Maybe we could talk just a little bit internally, Andre, about how you accomplish this.
46:48 Yeah.
46:49 Like how I started it.
46:50 Well, just like, how does it work?
46:51 If I give it a, if I give it a, an expression of, you know, e to the x cosine x, and I say integrate
46:59 that, like, where do you even start?
47:01 Yeah, exactly.
47:02 Well, the integration, I guess, I don't know, those more details, there's like a couple different
47:06 algorithms, but I'll tell you kind of the basic idea.
47:09 When I did, you know, the first thing you do in your search, how do you do symbolic integration?
47:14 And then there is this famous algorithm called the RISH algorithm.
47:18 So you kind of start studying and then you realize, oh, that's like multiple years of
47:22 worth of work to implement this.
47:24 And it's kind of fragile and doesn't always work.
47:27 And Mathematica, they, as the company, and Perkis Wolfram, they, they managed to do that.
47:33 That's a lot of effort, a lot of work.
47:35 And they had to invest in a large teams of people, test it carefully and so on.
47:38 But in practice, there are other approaches.
47:43 And it turns out that you can integrate a lot, you know, wide classes of functions just
47:49 by implementing an algorithm that works.
47:51 For example, for a polynomial, it's easy.
47:53 Anybody, anybody can do it, right?
47:55 And then you can add some trigonometric functions.
47:57 So you kind of implement algorithm for that.
47:59 Then you kind of built your way up.
48:01 It turns out when you do that, you can make it very useful in practice.
48:05 Maybe it's not as powerful as Mathematica is, but it's very helpful.
48:10 So that's how we started.
48:11 And then once you have the rules, I mean, first, second, third year of calculus, there's
48:19 in math, I, there is a ton of creativity in the calculus classes.
48:23 It's a lot of like, I just today we're doing integration by parts today.
48:27 We're doing like integration of stuff that's divided or what, you know, like there's a,
48:31 there's set algorithms that they tell you to follow.
48:33 And once you get the basics, it seems like, I guess you could compose them.
48:36 Yeah.
48:37 So that was kind of my initial idea.
48:38 Let's just kind of do stuff that we know how to do.
48:41 And it's kind of straightforward.
48:43 But, but then kind of the engineering part comes to it as well, because you don't want,
48:49 you want things to always work quickly.
48:51 And if it cannot be done, you would like to know the answer.
48:53 This cannot be done quickly, not to wait a couple hours.
48:56 until it tries all the functions.
48:58 Yeah.
48:59 And so then it just becomes a lot of, I would say engineering decisions, how to make this
49:04 all work.
49:05 And I think we are still not done yet.
49:07 I think there are a couple of, I would say promising approaches.
49:11 one approach is a certain professor, I think, or a professor, I think in Canada, he has,
49:20 he figured out how to take all these rules, how to integrate functions and compose them into
49:23 just a decision tree.
49:24 So you give it an expression and then it just figures out exactly as you said, is it the polynomial?
49:29 Is it like dividing?
49:30 Is it like dividing?
49:31 And so on.
49:32 And then the decision tree tells it exactly how to go about it to give you the final formula,
49:37 the integral.
49:38 Okay.
49:39 And here's the small formula you apply to it or whatever.
49:41 So you take out these 5,000 formulas and then he takes them and actually he uses Mathematica
49:47 and he composes those into a decision tree and then it prints the decision tree as for example,
49:51 Python code and so on.
49:52 And we still haven't, well actually, so we have a module for that.
49:56 And it's something that, what I like about this approach is that it's quick.
49:59 In principle, it's quick.
50:00 You just go through the decision tree and it gives you a formula or it says it cannot be there.
50:04 And I would like, but you know, there are all kinds of practical issues.
50:09 The tree is pretty quick.
50:10 And so when you encode it in Python, it takes forever to import and so on.
50:14 So we are still kind of struggling with these issues, but it just gives you an idea what kind of issues are,
50:18 engineering, I would say issues are involved in.
50:20 Yeah, that's pretty wild.
50:22 I mean, have you thought of or are you using things like Cython or these other types of speed up type things?
50:29 Yes.
50:30 Yeah, I spent, so maybe 10 years ago, I spent a lot of time investigating how to make Simpy faster.
50:35 Simpy is great, it's pure Python, it's easy to contribute to, and for many things it's amazing, just works and that's all you need.
50:42 But sometimes you need either larger calculation or a lot of calculations and it's not fast enough.
50:48 So how to speed it up?
50:49 So we investigated just pure C, Cython, all kinds of tricks in Python itself to speed it up.
50:56 Eventually, that kind of led to the SimEngine project.
50:59 I decided, let's just use C++.
51:01 It's the only tool that I know that actually can deliver the performance and kind of maintaining a bigger project.
51:08 So that's SimEngine and then we have Python wrappers and then Simpy can use it.
51:14 So there are modules in Simpy such as the dynamic, kind of dynamic, what do I say?
51:20 The classical, mechanical, I guess, module that allows you to simulate a solid body, you know, physics.
51:26 It's able to use SimEngine out of the hood so it gets much, much faster.
51:31 Okay, interesting.
51:32 Yeah, so this is a C++ project, but it has Python wrappers for easy Python integration with Simpy and other things.
51:40 Yeah, that's cool.
51:41 You know, I think that kind of summarizes a lot of scientific Python is there's a really great API.
51:49 And when you ask it to do things, it takes the data and hands it off to some C layer that actually does it for Rust or something like that, right?
51:56 Yes.
51:57 And it's not just writing it in C++.
52:00 There are other libraries that also in C++, but to make it really fast, one has to spend the time and figure out how to represent the expression in memory,
52:09 how to allocate the memory, how to, so we have to make, you know, reference content pointers, for example.
52:16 So that's what, that's the design I chose.
52:18 How to make the reference content pointer as fast as possible, things like that.
52:23 How to make sure that you can actually maintain it so that it gives you, if you make a mistake, it doesn't give you a segfold, but some kind of a, in debug mode, some kind of ways to debug it, right?
52:32 So there's all kinds of engineering, you know, decision behind the scenes.
52:37 I asked it to solve this and it went poof and went away.
52:39 I guess that means something.
52:40 I don't know.
52:41 Yep.
52:42 So we don't want that.
52:43 But anyway, but yes, so the symmetry works.
52:45 It's, it, it contains kind of like the core level of the core of Simpy.
52:50 Is this what I would, if I go pip install Simpy, do I get this or do I have to do something special to like swap out the computation engine with this?
52:59 You have to install it as a separate library.
53:01 So if you do just pip install Simpy by default, it only installs Simpy, but, but you can do pip, I think you can do pip install Sim engine.
53:08 I use Coda.
53:09 So you can do Coda install Sim engine, that install Sim engine as a, as a library.
53:13 And in Python, you do import Sim engine, and then you use it kind of like Simpy.
53:17 And Simpy can also optionally use it.
53:20 Got one to build.
53:21 Okay.
53:22 Yeah, this looks really neat.
53:24 one of the things I wanted to touch on here, and at the top right of the page, if I go just to the Simpy page, it says try it with Simpy gamma.
53:34 And so maybe we could sort of close out the conversation a bit with just poking around with this and then maybe highlighting some projects that use it.
53:42 So for example, it says, oh, you could just try some random example.
53:45 And it's got like algebra, algebraic things I could do.
53:49 So it says, you know, polynomial divisor, I'm coming in and copy this.
53:53 And if I go, there's a little calculator like thing at the top where I go hit equals, and it will go and run that in,
54:01 The polynomial division in this case, it looks like.
54:03 Yeah, yeah.
54:04 Like what are the divisors of, of this thing, right?
54:06 Something like that.
54:07 Yeah.
54:08 So this is sort of our, our little version of, of Wolfram alpha, but using Simpy under the hood.
54:13 it's not quite as powerful as Wolfram alpha.
54:16 We don't support like, natural language input.
54:20 that sort of thing.
54:21 But, yeah, you can, you can kind of get an idea of sorts of things Simpy can do here.
54:27 maybe one of the interesting ones.
54:28 If you scroll down a little bit, and click on one of the, integral, the one that says get steps for integrals.
54:35 Yeah.
54:36 How about this?
54:37 I, I'm a big fan of, E.
54:39 There's a whole book called E the story of a number.
54:41 I have you guys read it.
54:42 no, I haven't heard of it.
54:43 You haven't E, E the story of a number is a great book.
54:45 It's about like Euler and all that stuff.
54:47 Okay.
54:48 Yeah.
54:49 So if this was just integrate E to the X over one plus E to the two X, right?
54:54 Yeah.
54:55 So if you scroll down here, hopefully, should see something that says, see steps.
55:03 yeah.
55:04 I see under the derivative, for example.
55:06 Yeah.
55:07 That was pretty interesting.
55:08 I don't know if this is the one that has steps, but I saw it in other places.
55:11 yeah, maybe that's, maybe this example is not working right now.
55:15 Yeah.
55:16 Yeah.
55:17 There's some, here, let's do, probably the differentiation of something might be, I bet it's got some steps for that, but that was part of what I was talking about.
55:23 I don't know what I was talking about with the cheat and not, and I don't mean that in a negative way, but like, it will show you the steps as if it was written out in a textbook, of how like this one right here, like, look at this.
55:36 You're going to apply the quotient rule, which is the X of F of X over G of X equals this.
55:41 And then you're going to apply this.
55:42 And I mean, this is amazing.
55:45 Yeah.
55:46 Well, I mean, I think, I think it's, you know, it's instructive.
55:50 It's not, it's not just cheating.
55:52 It's not just cheating.
55:53 No, of course it's not.
55:54 And I do think it's really instructive because it's one thing to just go take a function or an expression and say, take the derivative of this.
56:03 And it says, great.
56:04 It's this crazy thing.
56:06 Like, how was I supposed to know?
56:07 It was like the tan of the cotangent of X or like something like that.
56:11 Right.
56:12 but if it says, you know, like, look, here's how we got there.
56:15 That's yeah.
56:16 That's very educational.
56:17 Yeah.
56:18 So it's not, this, this, but many parts of Senpai don't work like this because, sort of the underlying algorithms don't, don't really work the same way that you would do it by hand.
56:29 But there are some that basically work the same way you would do it by hand, like differentiation as an example.
56:35 So we can, we can sort of extract the steps and show them to you.
56:39 Yeah, this is great.
56:40 I'll put this, this explanation example into the show notes so people can, come back and check it out.
56:46 But gamma.senpai.org and then just choose some of the examples is really how to do it.
56:50 And it's how it gets there.
56:51 So very nice.
56:53 So let's, let's wrap this up by going to senpai.org.
56:59 And then on senpai.org, if you go just down a little bit, there's projects using Senpai that are, they all sound super interesting to me.
57:08 You've got like chempy, a package for chemistry in Python, Einstein pi for symbolic numeric, for general relativity.
57:16 Are there any of these that you think are particularly neat or stand out to you?
57:19 You want to give a shout out to either of you?
57:21 Oh yeah.
57:22 I, all of them, but I like the pi guy, for example, it's a, it's a very nice package for, you can, can.
57:27 Pi dies and dynamics.
57:29 Yeah.
57:30 So you can, it allows you to simulate, you get kind of like a robot or multiple, you know,
57:37 a pendulum, like double pendulum.
57:38 You just kind of tell it exactly the relations of the body and then it allows you to write.
57:43 And then pi die can derive equations of motion.
57:45 And those equations get extremely complicated, real quick.
57:49 for triple pendulum, which just gets very complicated.
57:52 Pi die can derive the equations for you, correctly.
57:56 And so, it's, it's a, it's a certainly not neat project.
57:59 Yeah.
58:00 That one's really cool.
58:01 So you can see the chem pie kind of stands out for me.
58:03 Cause I've, I've always loved chemistry.
58:05 Yeah.
58:06 Any others that you want to give a shout out to?
58:08 well, I guess one, one that I'll mention here, actually it's listed as a sage.
58:13 So sage, sage is something that a lot of people might know as sort of an alternative, computer algebra system.
58:20 Yeah.
58:21 I've actually had a William Stein on the show to talk about it as well from a sage math and,
58:27 yeah.
58:28 So sage, sage sort of integrates a lot of libraries, including Senpai itself.
58:31 You can see Senpai is listed there on the, on the front page of their website.
58:34 Yep.
58:35 so, if you use sage, there's, there's a chance that you're actually just using Senpai under the hood.
58:42 so that, yeah, it's, that's, that's one that I like.
58:48 a lot of these are, are, are making use of that, the code generation, concept that I talked about where they're, they're basically sort of modeling whatever chemistry or dynamics and in Senpai.
59:00 And then, then taking that expression and turning it into something that they can numerically evaluate.
59:07 Yeah.
59:08 It looks like maybe some quantum computing stuff here.
59:11 All right, great.
59:12 Now these are all cool.
59:13 And I think probably seeing some uses of it, like give people ideas for their own projects.
59:19 Let's wrap this up, this, conversation up just, to talk about maybe bridging the gap or bridging the world of computational stuff, symbolic stuff, and then, this numerical side, right?
59:34 So I've gone through and I've said, here's some complex function and maybe here's another one.
59:39 And I'm going to combine them through whatever in some, some way, and then now generate me a second derivative or whatever it is I need or integrate it.
59:48 I've now got a new expression.
59:50 Can I somehow take that and turn it into something I can call as a Python function?
59:56 Like here's a number of what's the answer effectively, or here's a numpy array.
01:00:00 Give me the evaluation across the numpy array.
01:00:02 Yeah.
01:00:03 So there's, there's a function called lambda phi.
01:00:05 it's a L A M B D A F Y, which basically does exactly what you said.
01:00:12 It takes an expression and it turns it into a function that you can evaluate with numpy.
01:00:19 so, yeah, that, that workflow is basically exactly what you describe.
01:00:24 You, you, you, you simply derive whatever it is you're doing using the mathematics of,
01:00:30 of your problem.
01:00:31 And then you, you put that inside of lambda phi, and now you have something that you can actually
01:00:35 pass, your data to with numpy, and, evaluate it numerically.
01:00:42 Nice.
01:00:43 That's awesome.
01:00:44 Does it effectively use that, that code generation thing you were talking about?
01:00:48 Yeah.
01:00:49 So under the hood, it's, it's using, it's basically generating code for a language equals.
01:00:55 Okay.
01:00:56 Yeah.
01:00:57 Yeah.
01:00:58 Numpy itself is sort of a language.
01:01:00 It's got its own set of functions.
01:01:02 and right, right.
01:01:03 Instead of looping, you'll, you do sort of vector operations and things like that, which you'd
01:01:09 want it to do that.
01:01:10 Yeah.
01:01:11 Yeah.
01:01:12 there are other functions, which you can do to, to, instead of calling numpy, if
01:01:16 you want to like call it through C as well, there, there's options for that as well.
01:01:20 but yeah, that, that lambda phi is sort of the, the big one that, that you need to know
01:01:25 if you want to do that.
01:01:26 Okay.
01:01:27 Cause to me, that seems like a really important bridge.
01:01:30 You know, I've got this idea.
01:01:32 I here's my theoretical equations, but at some point I want to evaluate it and make, make the
01:01:38 computer, you know, generate a graph based on these numbers or something.
01:01:43 Right.
01:01:44 Yeah, definitely.
01:01:45 Cool.
01:01:46 Good work on this project.
01:01:47 You guys, it, it's pretty amazing.
01:01:49 And, and the explanation, thing, Aaron, you had me pull out.
01:01:55 That's really cool.
01:01:57 How much it will say, these are the algorithms we applied and, and here's the little lesson
01:02:01 to take from, like why this makes sense here and so on that.
01:02:05 That's a way better than just some sort of numerical integral.
01:02:09 Like you gave me this function and it's 7.2 is the answer.
01:02:13 Like, well, great.
01:02:14 But what do I do with that?
01:02:15 Right.
01:02:16 Yeah.
01:02:17 Yeah.
01:02:18 So maybe people, people could use it as a teaching tool.
01:02:20 Assuming.
01:02:21 Yeah.
01:02:22 There are people who use it in the classroom.
01:02:23 Definitely.
01:02:24 Sure.
01:02:25 Yeah.
01:02:26 Yeah.
01:02:27 Well, before we're done, let me ask you both the final two questions briefly.
01:02:31 If you've got some kind of notable package, maybe it's not the most popular thing, but you,
01:02:37 you know, some Python package that's awesome.
01:02:39 That needs a shout out.
01:02:40 There probably are a lot on this page already and you've already given some, but anything you
01:02:45 want to just, call out real quick.
01:02:47 well, so perhaps unrelated to Senpai, a little bit, but, It can be unrelated, anything.
01:02:55 Yeah.
01:02:56 well, I, I, I'd have to say one of my favorite packages that I use, is this
01:03:04 testing library called hypothesis.
01:03:05 Yeah.
01:03:06 I'd actually like to, to make use of it in Senpai.
01:03:09 We aren't using it right now, but, I'd like to, but, if you haven't used it before
01:03:15 the, the idea, it's sort of, it sort of flips the, the idea of, of how you do tests on its
01:03:20 head a little bit.
01:03:21 instead of, instead of sort of coming up with a bunch of examples and sort of testing
01:03:25 that they, your function, you know, does the right thing on, on the, on different inputs,
01:03:30 you just sort of tell it what your function should do.
01:03:32 And then it takes care of the job of, of generating examples.
01:03:36 And the end result is that you, you end up testing a lot more of your code than you would
01:03:41 with a normal test.
01:03:43 And you get, you end up with much more robust code as a result.
01:03:47 So I recommend checking it out.
01:03:48 It's called hypothesis.
01:03:49 I don't know if you've had hypothesis on this.
01:03:51 I have, it's been quite a while.
01:03:54 It's been three or four years at least, but yeah, it's, it's a very neat project.
01:03:58 And I'm glad to see it's still going strong.
01:04:00 I hear a lot about it.
01:04:01 Andre.
01:04:02 Oh, I was going to say, do you want a Python package or any package?
01:04:06 Python.
01:04:07 If you got one, if not, we can fall back to any.
01:04:09 yeah, I was going to actually have both of these also.
01:04:12 I also discovered it kind of actually relatively recently.
01:04:15 yeah.
01:04:17 Yeah.
01:04:18 I recommend people to check it out.
01:04:19 Which one?
01:04:20 Sorry.
01:04:21 Oh, the hypothesis.
01:04:22 Oh yeah.
01:04:23 Uh huh.
01:04:24 Sure.
01:04:25 And I did talk about it way back in the day.
01:04:27 This is 2016 had a David McIver on to talk about it.
01:04:32 So that was cool.
01:04:33 All right.
01:04:34 And then final question.
01:04:35 If you're going to write some code, some Python code, what editor do you use?
01:04:40 I use Emacs.
01:04:42 Emacs right on.
01:04:43 And I use Wim.
01:04:44 Oh, and you guys still get along.
01:04:46 Yeah.
01:04:47 Of course.
01:04:48 No, just teasing.
01:04:49 That's awesome.
01:04:50 All right.
01:04:51 Well, thanks so much for being here.
01:04:53 You know, final call to action.
01:04:54 People are excited to get started with Senpai.
01:04:56 Like what do they do?
01:04:57 How do they get started?
01:04:58 Where do they go?
01:04:59 well, so the easiest way is, if you go to Senpai.org, like you said, like,
01:05:06 you said, you can try it online.
01:05:08 there's also a link there to, to download it.
01:05:12 yeah.
01:05:13 Otherwise, you know, I would say, if you're going to go to Senpai.
01:05:15 you know, you can, if you really want to get dive in, you can join our mailing list,
01:05:20 or, you can follow us on Twitter.
01:05:23 We're at Senpai and, yeah, it, the, basically the easiest way to get it.
01:05:29 Is it just pip install Senpai or condo install Senpai and you'll have it.
01:05:33 Nice.
01:05:34 Andre.
01:05:35 Yeah.
01:05:36 That's a, or simengine.org.
01:05:38 You can like, you like the plus plus version.
01:05:40 Nice.
01:05:41 And you have the tutorials that I highlighted.
01:05:42 I'll link in the show notes so that you can go through on Senpai.org as well.
01:05:46 Fantastic.
01:05:47 Really nice work.
01:05:48 I love to see you bringing this to all the developers and data scientists and stuff.
01:05:53 So thanks for being here and sharing Senpai.
01:05:56 No, thank you for having us.
01:05:57 You bet.
01:05:58 Yeah.
01:05:58 Thank you so much.
01:05:59 Thank you.
01:06:00 This has been another episode of Talk Python to me.
01:06:03 Thank you to our sponsors.
01:06:05 Be sure to check out what they're offering.
01:06:06 It really helps support the show.
01:06:08 Starting a business is hard.
01:06:10 Microsoft for startups founders hub provides all founders at any stage with free resources
01:06:16 and connections to solve startup challenges.
01:06:19 Apply for free today at talk python.fm/foundershub.
01:06:23 Take some stress out of your life.
01:06:26 Get notified immediately about errors and performance issues in your web or mobile applications with
01:06:31 Sentry.
01:06:32 Just visit talkpython.fm/sentry and get started for free.
01:06:37 And be sure to use the promo code talkpython, all one word.
01:06:40 Want to level up your Python?
01:06:42 We have one of the largest catalogs of Python video courses over at Talk Python.
01:06:46 Our content ranges from true beginners to deeply advanced topics like memory and async.
01:06:51 And best of all, there's not a subscription in sight.
01:06:54 Check it out for yourself at training.talkpython.fm.
01:06:57 Be sure to subscribe to the show.
01:06:59 Open your favorite podcast app and search for Python.
01:07:02 We should be right at the top.
01:07:03 You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct
01:07:09 RSS feed at /rss on talkpython.fm.
01:07:13 We're live streaming most of our recordings these days.
01:07:16 If you want to be part of the show and have your comments featured on the air, be sure
01:07:19 to subscribe to our YouTube channel at talkpython.fm/youtube.
01:07:23 This is your host, Michael Kennedy.
01:07:26 Thanks so much for listening.
01:07:27 I really appreciate it.
01:07:28 Now get out there and write some Python code.
01:07:30 We'll see you next time.
01:07:31 Bye.
01:07:31 Bye.
01:07:31 Bye.
01:07:32 Bye.
01:07:32 Bye.
01:07:33 Bye.
01:07:33 Bye.
01:07:34 Bye.
01:07:35 Bye.
01:07:36 Bye.
01:07:37 Bye.
01:07:38 Bye.
01:07:39 Bye.
01:07:40 Bye.
01:07:41 Bye.
01:07:42 Bye.
01:07:43 Bye.
01:07:44 Bye.
01:07:45 Bye.
01:07:45 Bye.
01:07:46 Bye.
01:07:47 you you you Thank you.
01:07:50 Thank you.