Description

Set theory might sound like a scary, super-math thing, but it's not! Well, it is a math thing, but it doesn't have to be super scary. In fact, if you already know how venn diagrams work, then you basically already know set theory. We'll walk you through it all and show you how it connects back to computer science with the help of our favorite foods.

Show Notes

This episode of the Basecs podcast is based on Vaidehi's blog post, Set Theory: the Method To Database Madness from her basecs blog series.

Transcript

Saron: [00:00:01] Welcome to the basecs podcast. Where we explore the basics of computer science concepts. I'm your host Saron, founder of CodeNewbie.

Vaidehi: [00:00:08] And I'm Vaidehi Joshi, author and developer.

Saron: [00:00:11] And she is the brilliant mind behind the basecs blog series. Today we're talking about:

Vaidehi: [00:00:16] Set Theory.

Saron: [00:00:18] This season of the Basecs podcast is brought to you by our wonderful friends at Twilio. If you haven't checked out their API yet you totally should. With Twilio your app can send text messages and make phone calls with just five lines of code. Just five lines. And for a lot of developers Twilio is the first API they've ever used. And that first time you type a few lines of code, run your program, and see your phone light up with a text message, it's kind of magical. And as a thank you for listening to the show, you get a promo code for twenty dollars and free Twilio credit. Just text your name to 4 8 0 4 8 5 4 3 2 1. You'll also get a link to a quick start guide for your favorite language. So text 4 8 0 4 8 5 4 3 2 1. Link is in the show notes.

Saron: [00:01:07] And we're also sponsored this season by Digital Ocean. They provide the easiest cloud platform to deploy, manage, and scale applications of any size. They remove infrastructure friction and provide predictability so you can spend more time building what you love. Digital Ocean for free by going to d o.c o slash code newbie and get one hundred dollars in infrastructure credit. Link is in your show notes. OK. Let's get started.

Saron: [00:01:36] Okay so set theory sounds scary. It sounds very math and it's not that math is inherently scary but it sounds like the kind of math that is scary. You know what mean like it sounds. It sounds like it's gonna be really intense. Is it as scary as—

Vaidehi: [00:01:52] The word “theory" is in it. So.

Saron: [00:01:53] Okay you know what? I'm so glad you brought that up. I think that's what it is. I genuinely think, if you said it's going to be set math I'd be like that's fine but you're like set theory and I'm like whoa, you know. That's intense.

Vaidehi: [00:02:06] Game over.

Saron: [00:02:07] Game over. Done. Is it going to be a scary as I think it's going to be?

Vaidehi: [00:02:12] No it's not. Actually I can basically describe it to you in two words and you're gonna to be less scared.

Saron: [00:02:18] I'm excited.

Vaidehi: [00:02:19] You ready.

Saron: [00:02:19] I'm very ready.

Vaidehi: [00:02:22] Venn Diagram.

Saron: [00:02:23] Oh I know what those are.

Vaidehi: [00:02:25] Yeah. That’s uh that's like, that’s the short version of set theory really.

Saron: [00:02:29] I've been doing those since I was five. Does that sound right? Is that when people get introduced to Venn Diagrams?

Vaidehi: [00:02:32] Ish.

Saron: [00:02:36] Everyone's like uh I did it when I was two. Wait. Seriously though like set theory is just Venn, no.

Vaidehi: [00:02:44] I mean it’s, it is it is operations upon a Venn diagram in a way where you're like trying to figure out you know what exists in one thing or doesn't exist in another part of the diagram.

Saron: [00:02:56] Okay.

Vaidehi: [00:02:56] But like. And it’s like a fancy you know equations and symbols that we won't even get into. But that's really what the theory is.

Saron: [00:03:04] Okay well that makes me feel a lot better.

Vaidehi: [00:03:06] Oh that's good.

Saron: [00:03:07] Thank you. Okay. Okay, so in a Venn Diagram let's do an example in a in a in a Venn diagram let's do let's do Saron and Vaidehi's favorite foods.

Vaidehi: [00:03:21] Now this is good.

Saron: [00:03:22] I'm really excited about this because I actually don't know what your favorite foods are and I feel like this will bring me closer to you and I'm very excited about that. Okay so in a Venn Diagram you have two circles right> So you have like the Saron favorite food circle. Is that is it called a set by the way? Like, my circle.

Vaidehi: [00:03:41] Yes I think that's.

Saron: [00:03:42] Oooh.

Vaidehi: [00:03:45] You have I don't know actually but I think that's right. I can google it.

Saron: [00:03:49] Making connections. That sounds, that sounds like that could be a thing.

Vaidehi: [00:03:50] Yes.

Saron: [00:03:51] OK. So we'll have Saron's Saron's set of favorite foods and then Vaidehi's set of favorite foods. OK so we're each going to pick three. Hopefully one of them, we will have in common. OK wait let me think let me think oh my god I'm so nervous I'm so nervous. OK. Okay, I’m gonna think of one.

Vaidehi: [00:04:10] Wait we're thinking of one or we're thinking of three?

Saron: [00:04:12] OK let's do one at a time.

Vaidehi: [00:04:13] OK.

Saron: [00:04:13] I'll do one you do one and then we'll go back and forth. OK?

Vaidehi: [00:04:17] OK.

Saron: [00:04:18] Okay. My first one is steak.

Vaidehi: [00:04:21] Oh I like steak.

Saron: [00:04:24] Calm down, calm down Saron.

Vaidehi: [00:04:27] So I'm supposed to say something now?

Saron: [00:04:28] Yes.

Vaidehi: [00:04:29] I like eggplant.

Saron: [00:04:30] Oh my God Jesus Christ. OK.

Vaidehi: [00:04:32] You don't like it?

Saron: [00:04:33] No. What am I gonna do with an eggplant? What am I gonna do with that?

Vaidehi: [00:04:35] Eat it with some steak, it tastes great.

Saron: [00:04:40] No no no, rejected. OK. I reject your eggplant. OK. All right so so far we we're each in our own little independent sets. Okay I’m gonna do another, do another one.

Vaidehi: [00:04:50] Wait, do you not like steak?

Saron: [00:04:51] No, I love— are you doing steak to yours?

Vaidehi: [00:04:54] Yeah, I like steak so we share steak.

Saron: [00:04:56] OK we share steak. Oh my God. OK we share steak.

Vaidehi [00:04:56]: We have one thing that we both like. And then I have a thing that I don't know why you don't like it, but I like it.

Saron: [00:05:02] I don't know why you like it. Okay, you have eggplant. I'm OK. I'm going to do one. I'm gonna do one. I really like. I really like I don't know if this counts as a food.

Vaidehi: [00:05:15] This is does not bode well.

Saron: [00:05:17] Plastic, no I'm just kidding. Um. I really like nachos and cheese. It's like two foods but it's a unit.

Vaidehi: [00:05:23] Oh, I like those too.

Saron: [00:05:24] Really? Oh my, I love. It's like one of my guilty pleasures. I love nachos and cheese. OK. I have to pick something you don't have. You can't just be all up in my set.

Vaidehi: [00:05:33] I know. I know.

Saron: [00:05:33] Girl.

Vaidehi: [00:05:33] We have two shared things and I have a thing you don't like.

Saron: [00:05:36] I need a thing. OK. What don't you like? I bet you I like it.

Vaidehi: [00:05:38] I don't like clams or mussels.

Saron: [00:05:41] Aren't you like vegan or? No. You eat steak.

Vaidehi: [00:05:43] No I'm not. I do. Yes, I'm a vegan who eats steak. I don't like bacon that much.

Saron: [00:05:49] Oh bacon's awesome. What's wrong with you? OK I'm gonna put bacon in mine.

Vaidehi [00:05:52]: It’s OK, it's fine.

Saron [00:05:53]: OK. So Saron's set. Mine—

Vaidehi: [00:05:57] Yours is bacon and steak and nachos and cheese.

Saron: [00:06:00] I like to like to stay fit. Like to be healthy. Okay, so my set is nachos and cheese, steak and bacon. That is such a terrible group of foods. Um and yours is eggplant, steak and nachos and cheese. Okay so we worked, we worked one veggie into this into this equation so that's that's fine. That's fine.

Vaidehi: [00:06:24] I would have worked in more if we'd done more.

Saron: [00:06:26] No. There's no time for this, there’s no time. OK. So we have our favorite food Venn diagram um. What makes this Venn diagram uh a part of set theory? Like what makes what makes a thing a set? Like if I can I add uh can I add like another steak in my Venn diagram? Okay so when I think about what makes a Venn diagram a Venn diagram there is there's two sets and the things that we have in common only show up one time. Right? Like I don't have two different steaks and two different although two different steaks sounds pretty good too. But I don't have you know two different steaks and like.

Vaidehi: [00:07:09] It's more the concept of steak like we've agreed that that's a one you know one thing it's a single occurrence.

Saron: [00:07:15] Exactly. Yes it's a it's a single it's a single occurrence. Yes. So like is that what makes it look a set like set theory is that is that important to this definition?

Vaidehi: [00:07:26] Well the set I should define what it is is.

Saron: [00:07:29] Okay.

Vaidehi: [00:07:29] It's the collection of those elements. So it's really all those things we just explained or listed off rather, that's the set. And a set is nothing more than a unordered collection of elements, no duplicates. That's that’s the important. And that's why, if you think about the concept of our you know shared interest in food, you wouldn't really have duplicates because either you like it, I like it or both of us like it or it exists outside and it's like a thing we don't like but it's still you know there's only one of it in the set.
Saron: [00:07:58] Right

Vaidehi: [00:07:58] That bit is important the fact that there are no duplicates and there are distinct unique objects unique you know elements in the set and that there was no order either to them right.

Saron: [00:08:10] Oh yeah.

Vaidehi: [00:08:10] It wasn't like we listed steak first and then nachos second.

Saron: [00:08:13] That's true. We didn't like rank them.

Vaidehi: [00:08:15] Right. We're just like these exist in this space the space that is both Vaidehi and Saron's.

Saron: [00:08:15]: They’re just there.

Saron: [00:08:21] OK.

Vaidehi: [00:08:21] I almost said Varon by the way.

Saron: [00:08:23] Ayy team name. Varon. I approve, I like it. Okay, so that makes sense. So the three qualities are that the things in the set are unordered.

Vaidehi: [00:08:36] Mhm.

Saron: [00:08:37] There are distinct elements and there are no duplicates which you know makes total sense. It fits what I've always known about Venn diagrams and how they work so I'm very relieved that there's nothing surprising there. Um but why are we talking about Venn diagrams? Like what am I supposed to do with this information?

Vaidehi: [00:08:58] Well I guess the thing that we should do is remind ourselves about the things you can do with Venn diagrams.

Saron: [00:09:04] OK.

Vaidehi: [00:09:05] Kind of go through a couple terms.

Saron: [00:09:06] OK cool.

Vaidehi: [00:09:07] That we probably know we know them inherently but we might not have the terminology to describe what we're saying.

Saron: [00:09:12] Ok, fair.

Vaidehi: [00:09:14] So the first thing is the things that we both like. This is actually an operation that you can perform on a set math, like mathematically there are like symbols to denote these operations.

Saron: [00:09:25] Mhm.

Vaidehi: [00:09:26] And the one that probably is most exciting to both of us are the things that we share, the common interest that we have in food.

Saron: [00:09:31] Steak and nachos and cheese.

Vaidehi: [00:09:33] Mhm. I know we should have a dinner party that is just that.

Saron: [00:09:36] Yes, ugh.

Vaidehi: [00:09:39] Um, but the thing that exists in both your space and mine it's the intersection. It's basically the set of elements that exist in Saron's list, and Vaidehi's list.

Saron: [00:09:53] Okay.

Vaidehi: [00:09:51] That's called the intersection. And when you perform an intersection operation, it actually yields another set.

Saron: [00:09:57] Oh.

Vaidehi: [00:09:58] And the other set is the intersection of Saron and Vaidehi.

Saron: [00:10:00] Oh cool. Okay. So when you operate on I don't know if that's the right way to think about it but when you operate on this these two sets, my list and your list than you get, you get a new thing and I guess that means you can like work with this new thing if you want to do stuff to that. Okay intersection cool. I like that because it makes sense. I can visualize it in my Venn diagram, I can see the intersection. So so far I am not scared. This is great.

VaidehI: [00:10:28] That’s the episode title. So far I'm not scared. I love it. Um well I guess if we're talking about intersection the next thing that kind of makes sense to describe is the opposite of that, which is basically the things that don't exist in our shared space. So the things that exist either in your list or in my list which I guess would be eggplant and then bacon. Right? That was your thing?

Saron: [00:10:54] Yes.

Vaidehi: [00:10:55] And that's called the Union. And so when you were finding the union in our set you get another set that contains the things that are either in your list or in my list.

Saron: [00:11:06] Okay. I don't like that one.

Vaidehi: [00:11:09] That's fine cause you don't like it cause of the eggplant, I don't like because the bacon. Eggplant and bacon don't go together. It's fine. We don't need to talk about unions anymore.

Saron: [00:11:17] They really don't go together though. But no, I think that's a confusing name because when I think about uh. Oh okay I understand now. It's a union because we're bringing together these two otherwise unrelated things. Is that why it's called a union?

Vaidehi: [00:11:36] I have no idea but I like that.

Saron: [00:11:38] Right? Okay cause the reason why initially I was very opposed—

Vaidehi: [00:11:42] Intersection makes sense.

Saron: [00:11:42] Right because intersection is like oh we are at the intersection so I'm thinking Union we're at the Union. No. You know but it's not we're not at the Union we are— I almost said unionfying. We are bringing together, we're unifying — I dunno If that's the way to describe it — you know what I mean — we are creating a union because we're creating a new set of things that otherwise don't want to hang out.

Vaidehi: [00:12:05] Yeah kind of.

Saron: [00:12:06] OK cool, I'm OK with union now. Let's continue. What else can we do with these uh, with these, uh, with these sets?

Vaidehi: [00:12:11] Well you can also kind of do a more unique kind of union I guess as a way to think about it. It's actually like if we kind of ignored the fact that we have shared you know our lists and it's kind of just like what are the things that Saron likes that Vaidehi doesn't like. Or what are the things that Vaidehi likes that Saron doesn't like.

Saron: [00:12:30]: Mhm, mhm.

Vaidehi: [00:12:31] It's kind of like the differences between our two sets. If you think about it like that so we could say the set of elements in Saron's lists that are not in Vaidehi's lists.

Saron: [00:12:41] Right.

Vaidehi: [00:12:42] And if you think about it that way then obviously the things that you listed that I like can't be in it. So.

Saron: [00:12:47] Okay.

Vaidehi: [00:12:48] Even though you listed steaks and nachos and cheese because those also exist in my list, that can't be part of this, can't be part of the set difference. There's also another way of thinking about it which is something called a relative complement.

Saron: [00:13:01] OK.

Vaidehi: [00:13:02] That's also kind of the same thing. It's like a set of elements that are in Vaidehi's lists but don't also exist in Saron's lists. But both of these the set difference and the relative complement, what you're really saying is what exists in this set that doesn't exist in the other. So it's kind of like subtracting Vaidehi's items from Saron’s which means anything that exists in mind can't exist in the relative complement.

Saron: [00:13:25] Okay. Okay that's not that bad. So far it's I'm okay with this. I'm still not scared. This is great.

Vaidehi: [00:13:31] Cool.

Saron: [00:13:32] Is there anything else we should know or the other stuff we could do with these sets?

Vaidehi: [00:13:37] I think the last thing I want to talk about is, imagine that we both suddenly disagreed and we wanted to come up with a list of things that only one of us that exists in only one of our sets but is not a shared thing. So it's kind of the opposite of the intersection.

Saron: [00:13:51] Mmm, yeah yeah yeah.

Vaidehi: [00:13:53] In that it's all the things that you like and I like but that we both don't like together. This is something called the symmetric difference, which basically is these set of elements that exist in either of our sets but do not exist in the intersection of the two sets.

Saron: [00:14:12] Mm. Okay.

Vaidehi: [00:14:13] And there's another name for symmetric difference called the disjunctive union. I like that one that much because it's hard to say.

Saron: [00:14:21] It's also sad like unions are fun and then now they're disjunctive.

Vaidehi: [00:14:25] Yeah. So junctive.

Saron: [00:14:30] So junctive. Okay.

Vaidehi: [00:14:32] The reason I wanted to bring up symmetric differences is because it's an extension of the relative complements we were just talking about where I was saying the relative complement or the set difference of your list would be just bacon and mine would be just eggplant. And if we found the symmetric difference then it would be the complement of both of the sets. So the things that only you like and the things that only I like.

Saron: [00:14:56] Okay, okay I think I'm okay with this. This doesn't seem like it feels like we just looked at the Venn diagram and just did all the combinations we possibly could. And then gave them names.

Vaidehi: [00:15:07] Yep.

Saron: [00:15:08] That’s what it feels like. That’s what it feels like.

Vaidehi: [00:15:09] And I am convinced we should never combine eggplant, bacon, steak, and nachos and cheese because the more you talk about I was like some of these go together but not all four.

Saron: [00:15:19] No. No definitely not. Okay, so we talked about what a set is. We had an amazing example of a Venn diagram called Saron and Vaidehi's favorite foods and we use that to talk about all the different things we could possibly do, all the different operations we can actually do with with our lists of favorite foods. But how does that relate back to computer science? Because last time I did a Venn diagram I think I was like 8. So what does it have to do with with coding?

Vaidehi: [00:15:52] The really cool part is that the thing that a lot of us interact with as developers are um are actually based in set theory and what I'm referencing is relational databases.

Saron: [00:16:03] Ooh, oh.

Vaidehi: [00:16:05] Most of us have either worked with an API that eventually pulls from a database, a relational database, or some of us are you know more backend engineers and we actually you know write SQL or whatever that deals with the database. But in some way shape or form whenever you're doing anything with web applications or mobile applications, or anything that's stored in a database really, you are working with some kind of operation that is based in set theory.

Saron: [00:16:31] OK.

Vaidehi: [00:16:32] There's also some computer science-y stuff in how sets are implemented and what we use to implement them.

Saron: [00:16:40] Okay.

Vaidehi: [00:16:41] But I won't tell you how yet.

Saron: [00:16:44] Always leave us on a cliffhanger. Um but you're basically telling me that all the years I've been doing my SQL queries and been working with Postgres and doing all my relational database stuff I've been doing set theory this whole time?

Vaidehi: [00:16:58] Yeah in a way you have.

Saron: [00:17:00] Oh my gosh.

Vaidehi: [00:17:00] From a distance you've always been very close to it.

Saron: [00:17:03] I'm I'm so smart and I'm really glad that everyone knows it now.

Saron: [00:17:07] Um, okay cool so we're gonna to dig into the computer science-y part and the application of set theory next episode. But for today that's the end of the show. If you liked what you heard leave us a review and make sure to check out Vaidehi's blog post. Link to that is in your show notes. Also want to give a huge shout out to Twilio for sponsoring the show. Make sure to check out their awesome API to get your twenty dollars in free Twilio credit. Text your name to 4 8 0 4 8 5 4 3 2 1. Link to that is in your show notes. Also want to give another shout out to Digital Ocean. They are the easiest way to deploy, manage and scale your application. Everything about it was built with simplicity at the forefront: setting, deploying, even billing. Their support is amazing. They've got hundreds of detailed documents and tutorials, so if it's your first time deploying an app, don't worry. They've got great tools and community to make it nice and easy. Try Digital Ocean for free by going to d o. c o slash code newbie and get a hundred dollars in infrastructure credit. Link is in your show notes. Vaidehi, you want to say goodbye.

Vaidehi: [00:18:13] Bye everyone.

Saron: [00:18:14] Thanks for listening. See you next week.

Saron: [00:18:19] That was a stupid question.

Vaidehi: [00:18:20] Well.

Saron: [00:18:21] I'm not asking that question, that question didn’t make any sense.

Thank you for supporting the show!

Get a promocode for $20 in free Twilio credit and a quickstart guide for your favorite language.

Text your name to 480-485-4321.

The easiest cloud platform to deploy, manage, and scale applications of any size.

Try it for free with a $100 credit.

Thank you for supporting the show!

Get a promocode for $20 in free Twilio credit and a quickstart guide for your favorite language.

Text your name to 480-485-4321.

The easiest cloud platform to deploy, manage, and scale applications of any size.

Try it for free with a $100 credit.