A lot of flak from a whole lot of people because yesterday or day before I tweeted, you saw the tweet, I said, let not the… you know, this is about there is a woman was killed in Iran because she did not wear her head scarf properly. That is, little bit of her blonde or jet black hair was showing, whichever one it was. So, they picked her up and I don't know, they may be bit of beaten her to death, she died. And protests are going on everywhere. All these Iranian women have been appealing to me, Sadhguru, please say something, say something. I don't know, anyway said I was just thinking whether they will fight or it'll just blow over. You never know. So, then I tweeted, I said, let not the religious and the lecherous decide how a woman should dress. Let her decide how she should dress. One set of people, one set of people are seeing how every millimeter of her body should be covered. Another set of people are looking at how they can reduce her clothes to millimeters. Both are happening unfortunately. This is all, you know, different interest groups, different interest groups. Why can't women have enough sense to decide by themselves what is appropriate for them, how they should dress? Hello?


Ding right there questions from the homework. What would you like me to go over now is your chance to ask first from page 440? Whatever this is 443 and then I'll do a couple for the other one as well. There was some nasties. I know oh, but some cool ones Which ones oh? Come on. Yes, you did raise your hand. I was gonna say the homework excellent. I'd love to do number eight Okay Hmm one of the cards is red and the other is black how many cards no no how many cards we picking To treat more than two we'll learn other stuff three I'll sometimes still do a tree, but we did say a tree gets pretty unwieldy when we have three or four or five So and here's my treat. I figure Black on the first one. You know what instead of doing not black. Why don't I just do R for red? Red on the first one second card could be black again red again black again red again and You know what I'll even put a one there for the first and the two there for the second how many black cards in the deck so this is gonna be 26 out of 52 26 out of 52. Oh down this branch.  How many are left in the deck 25? out of 51 26 reds out of 51 Here you picked a red. So you got 26 blacks out of 51 and 25 reds out of 51 Double check to the add to one to the add to one to the add to go back to an error check One card is red and the other is black. Here's what I think. I think it could be this branch or That branch what does or me?  I'm just gonna hit pause here quickly Sorry about the interruption for those of you following along at home. You're good. It's that makes sense. Okay? By the way, could you now that you see this could you have visualized the tree without drawing it? Sometimes for two events if they're fairly simple events, I'll do that in my homework When in doubt though the tree makes it so clear Okay, and yeah, the shortcut is this times this times two Apparently any others from page 445 and calling. Okay, then I also assigned some questions from page 450 ish and These ones are tougher, but in my mind also, I got to be honest gen these ones are nerdily cooler in My mind they're nerdically delicious or something like that Any I just made that up that good good. I'll use that for the remainder of my teaching career. Okay Any of these you want me to go over Because I know all of you did the what's the probability of a student waking up on time for class question. Yes Some of you did it three or four times and we're just make yeah, okay any of these you want me to go over Yes, sorry. I didn't see you there Five see I would love to do five see Okay How many people are there in this question breath three? Boy, I'll do a tree. This is about the limit of how big a tree I'll do. It's gonna be a fairly complicated tree it's Andy can solve it or Not Berry can solve it or not Berry can solve it or not Curtis can solve it or not Curtis can solve it. Don't put a Or not Curtis can solve it or not Curtis can solve it or not and I'm gonna cheat Because it's such a long tree to draw I'm only gonna fill in These branches. I'm already gonna put a check mark under only one here all three solved it You know what only one guy solved it on this branch right here only a solved it What's another one that has only one a here? Right didn't yes didn't and yes. Yes. Sorry. No. No. Yes there Okay, let's fill in just those branches as a time saver and this is one way you can kind of be in a cut corners a little bit They're independent so it's gonna be one-third two-thirds It's gonna be one half one half Oh, I'm filling in everything for some dumb reason after I told you I was only gonna fill in part of the branches I got carried away with the mathiness of it. Sorry, and it's independent. So it's gonna be three-fifths two-fifths three-fifths Not three. Mr. Do it Two-fifths, and you can see how cluttered it's getting and this is also why a three-level tree is a bit much but it works Multiply down at a cross so this or that or that it's gonna be One-third do any keep going or you take the rest of the way yourself, right? So I keep going. Okay. Love to times one half times Two-fifths, that's That branch or what does or me? I love it Two-thirds, you know what mr. Do it cleverly highlight since you've got this fancy technology two-thirds one half two-fifths or Two-thirds one half three-fifths Now you can pull out your graph and calculate if you need to I think all of these is gonna be over six times five All of these fractions are gonna be over 30. There's my common denominator, and it's gonna be two plus four Plus six which I think I can do in my head two plus four is six Oh Well about a 30 which in lowest terms divide by six divide by six is is it two out of five? Is that what says in the back? Woo-hoo There you go. Okay That's about as much as I'll tackle with a tree three different Events and three levels. That's a lot of work There is a way to do this coming down the side with combinatorics isn't tight any others. They're good So we're gonna move on to What to me is the coolest or one of the funnest lessons of the year and also one of the most counter-intuitive So let me press pause while I'm handing stuff out. I hit pause lesson five Conditional probability and it correct me if I'm wrong on your notes on the back page the right part of the page is blank Yes, so we're gonna do just to kind of jog our memory here a Generic kind of a tree so if you can go to where the blank section is down here and As a little heading you can write generic probability Tree and all I'm gonna do is I'm gonna fill in a tree Completely with symbols so that if you even get a question with symbols on it, you can oh, they're talking about this branch Okay The cameras way and closer to me because I need my caffeine So we're gonna have two events events A and B generic events. So we would go like this a What am I gonna write over here? What's our symbol for not? Not a and then we're gonna have event B whatever it is And not be B and Not be and then what we introduced last day Jen was the idea of waiting the branches We put numbers here in terms of symbols The number that we put here was the probability of a occurring So in case they give it to you that way, you'll know that's that number What would I call this as a symbol the probability of take a guess? not a okay, and Then we introduced the notion of conditional probability or given that we called this The probability of B occurring given that you're down the a branch Given that a has occurred. What do you think we call this the probability of? B not occurring Given that you're down the a branch. All right, let's see if we can use our math nerd brains What am I gonna call this one here? And I'm gonna have to kind of write small wait a minute, mr. Do it there's an advantage to the software mr. Do it Where's your lasso right there?  What do you think I'm gonna call this one here probability of B given that a did not occur and David since you're on a roll. What am I gonna call this one the probability of? B didn't occur and I already know that a didn't occur. Oh And we said you know they're independent if these two branches match those two branches That was the easy definition of independence as opposed to thinking to yourself does it affect or the yucky math definition? What we're gonna look at today instead of saying what's the probability of B given that a have occurred filling in this one What we're gonna say is this if we know this occurred Which could be this branch or this branch? What are the odds that I came down this one, but not that one we're gonna go backwards up the tree Okay, that's our goal. So here's our generic tree and today is going backwards That's about as ugly a tree as I could have drawn, but I'm gonna leave it because I'm an imperfect teacher I'm not embarrassed by it So a Pot is rent that we're gonna start out first and we'll get used a little more complicated Then we're gonna move backwards up the tree here. We have two separate little pots We're gonna pick a pot first and then we're gonna pick a bill and It wants to know what's the probability that we get a $10 bill, but you know what let's fill in our tree So the first first event here is we have to pick a pot. We have to pick pot one or Pot two how many pots are there? What are the odds of picking pot one? Yeah, now sometimes what they'll do to make it more interesting is they'll have you roll a dice And if you get a one or a two you'll pick pot one and a three four five or six You'll pick pot two in which case it's not one or two, but this one. I think is straight 50-50 Then what are the possibilities from each pot? I can get a zero dollar bill and I know we taught but a zero dollar bill a Ten dollar bill and a twenty dollar bill. So I think I'm gonna have zero ten or 20 zero ten or 20 right Let's fill in the weights if we're in pot one down this branch What are the odds of getting a zero? One out of three, what are the odds of getting a ten? One out of three, what are the odds of getting a 20? One out of three double-check is that to one? Yeah, got it, right? And that's why Brett I rarely don't do the whole tree that built an error check to me is so handy That's why I started doing it instinctively when you asked me that question earlier. Oh Now we're in pot two What are the odds of getting a zero? One out of four, what are the odds of getting a ten? Yeah, what are the odds of getting a 20? One out of four. Okay, we've got our treat and you'll find you get pretty quick at drawing these Now let's answer the questions What's the probability of a ten dollar bill is chosen if it's known that pot one is the selected pot? Okay, here's what this is saying if is another word for given that it's actually saying probability of ten Given we're down one. That's why I did that generic tree earlier. Can you see which number they're talking about? Which number is sitting in the ten given one branch? one-third It's not multiplied down. They didn't say what are the odds of getting pot one and a ten dollar bill They said look, you know, you're in pot one. What are the odds of getting a ten? two What are the odds of a ten dollar bill if you know you're in pot two in terms of our notation? It's a ten given that two has occurred sorry two out of four What's the probability that a ten dollar bill is chosen now? They have think probability tree diagram We already did ours here. What's the probability that a ten dollar bill is chosen? It really means this branch or This branch and here is where we're going to go multiply down At a cross the probability that a ten dollar bill is chosen. What we're really saying is in Our notation it could be pot one and a ten dollar bill or Pot two and a ten dollar bill and I'm not a big fan of the notation I like the tree, but Madison I want to make sure if they use it you're kind of not terrified by it Comma means and what does and means Times what does or mean at it's gonna be this times that it's gonna be one-half times one-third or One-half times two quarters Is there a built-in common denominator here?  It is that I'm interested in saving time So I'm gonna go one-half times one-third plus one-half times Two quarters and then how do you get that? Oh, yeah math and or and or five out of 12 piece of cake Okay, here is the question. We're gonna try and ask today Suppose David has just played this game, but I didn't watch him, but he's holding a ten dollar bill What's the probability it came from pot one? Can you see what they've done in this part D? They've told you the bottom outcome and they're asking about the top outcome Going backwards Okay Says begin by translating this as a conditional probability probability of Let's see What do I know here? What's the support by the way if that's the given? Given that we have a ten dollar bill What do they want us to find? One so the first step to doing conditional probability And this is the only time that I'm gonna do this compute completely with a formula is Translating it into probability speak Yeah Sure Although if you were really able to concentrate and you were a good student you should be able to handle the district shut up Mr. Duke, okay fine my bad Do me a favor this is because this is the only time I'm using the formula Can all of you either find your formula sheets or flip to the inside cover of your workbook because it's there too and What I'd like you to find is the formula that says this The probability of B given a it's on there Which by the way is really what we have here with different stuff Be given a is on there. Is it not is a given B? Okay, sorry. Sorry. Sorry my bad. I couldn't remember is it a given B and What does it say? It's the probability of a and B divided by the probability of B That's the formula that we're gonna use but I got to say that's fairly ugly Because I always get confused by the letters So I'd like you to write this down and then I'm gonna give you mr. Dukes handy-dandy truncated version of this Okay, so there's the formula I Don't remember it that way. I Remember it as when they give me a I got to translate this statement I look for words like if or given or supposed as another word that they use and I say it's the probability of both Over the probability of the given I Remember both of you It's much easier for me to keep track of the letters because Brandon often The a is where the B is and the B is where the a is and again can be forget it I'm not gonna wrap my brain around it. I know that for conditional probability It's gonna be the probability of both over the given one. So let's go to this question that we have here The one that we're actually trying to answer if David won ten bucks What are the odds that it came from pot one? Given that ten dollars has occurred. What's the probability that it came from pot one? That's going to be the probability of Another word for both is and One and ten Divided by the probability of what ten now. Why is that so helpful go look at your tree? Do we have a branch that has one and ten? Walk down that branch because and means what? Multiply down what numbers are gonna go on top of the fraction here two fractions. What are they? one out of two and And you know, it's the one-third because this says both. I know I'm going down the one column not the two call over Ten Now ten would be that or That what does or mean? Oh, wait a minute. Wait a minute. Didn't we just figure that out right here? Conveniently they snuck in this is the probability of ten Right, we did look at both possibilities Multiply down add across in fact the number that's going to go here is just five out of twelve Don't reach for your calculators yet the top Multiplying fractions is the easiest operation top times top bottom times one one out of six Divided by five out of twelve boys and girls. How do you divide by a fraction? I couldn't a pinch do this whole thing by hand. It's gonna be one out of six times twelve out of five so 12 over 30 or in lowest terms, which is what they would put by the way two out of five Strangely enough the same answer as Brett's question earlier today. That's a fluke But conditional probability going backwards if they tell you the bottom has occurred And they want you to figure out the odds that one of the top things has occurred It's both over the given one example two One of the places this is used is an industry to track defects as a matter of fact There was a mathematician back in the 1950s who was doing of his doctorate on probabilistic sampling methods and so he went to the big three automakers for GM in American Motors.  No, thank you So okay So he went across the sea to Japan and he pitched the idea to Honda and Nissan which was Datsun at that time and Toyota and they said this is great You mean we don't have to tell our workers to do any better. We don't have to change anything We'll just catch more stuff mathematically. Yes, it won't cost us anything. Nope and That's why in the 60s and in the 70s and in the 80s Japanese cars had a reputation as being better made. It wasn't that they were coming off the assembly line better They were catching more mistakes Mathematically they were able to if they found a mistake go backwards up the tree and find where it come from something like this The American Motor companies didn't start applying a lot of this until the early 90s and they're still trying to catch up So here's one place that it certainly changed several countries economies a Company has two factories that make computer chips cars if you want to go to the 70% of the chips come from factory one 30% of the chips come from factory two in Factory one 25% of the chips are defective in factory two 10% of the chips are defective Suppose you don't know from which factory a chip came. What's the probability that chip is defective? What they're really saying is find the probability of how about the letter D for defective? I think this is the same as the previous question. There's two events pick a factory and Then pick a chip So I'm gonna do a treat. How about F1 for factory one What would be clever to use for factory two? F2 you say What's the probability that something come that a chip comes from factory one read the question? 70% which as a decimal is 0.7. What's the probability that comes from factory to them? 0.3 then from factory one we can be defective or not defective or not What's the probability that a chip is defective given that it's from factory one? Point two five what about not defective? Use the compliment right this this is where the compliment also comes in really handy Okay, given that you're in factory two. What are the odds that the chip was defective? Point one and Point nine So this first question is simply saying what are the odds that it's defective? Well, look how many branches end in defective. I Think it's gonna be this one or This one What does or mean? Multiply down at a cross in fact now in my probability speak This is really the probability that we're defective and Factory one given factory one or the probability that we're defective. Sorry not my bad. Mr. Do it not given and because we're multiplying down we're multiplying down probability that you're defective and Factory two now there's the probability notation, which I'm not a fan of I can see from the tree It's gonna be point seven Times point two five or Point three times point one and yes, you're allowed to use your calculator this time I Will tolerate going to a calculator for basic decimal if you have a stack of chips You don't know What's the odds that it's defective one you pick one at random Jordan what do you get? Okay, sorry Amrit what'd you get since I see you racing for your calculator? Blinding speed off the blur blur. Oh my hair is getting blown back. I feel the wind. I feel the wind What do you get folks? Point two oh five or if they wanted you to go to a percent Twenty point five percent by the way, I'll take both answers But if it's multiple choice you better be able to if they want a percent be able to recognize the percent answer, right? The more interesting question to me is B. Oh by the way, I like this question. I like this question. I like this question. I like this question. I like this question Why do you think I'd say that Dylan? I think there's why would I say that I like this question? Sorry, what? You didn't hear me say it was gonna be on the test. You're just a good student who notices those things Okay There enough Brainiac that's absolutely when I think of you that the first thing that pops into my eye. I almost got it straight I almost got it out. Sorry my friend. I came close though Always Read B to me kiddo Stop That's also an especially for my ESL students. That's also another synonym or trigger word for given The three words they use most often are suppose that or if or Ideally given that's my preferred trigger word. I usually will use that but Start over kiddo. We need to translate this into a probability statement What's the given? What do we know? What's the suppose? No, what's the suppose? What's the given? The given is that it's defective. They've told me the bottom outcome That's also how you can recognize that we have to use this. What do they want us to find? Okay, we're going backwards up this tree and how are we gonna do that? We can use the fancy schmancy complicated Conditional probability formula from our formula sheet or mr. Dook said it's really easier to remember. This is going to be Both over The given and by both I mean and It's gonna be defective and Factory one divided by just plain old defective Now the nice thing here is what did we find in part a the probability of what? We actually found the denominator already They won't do that always but often part a will be find this and then part B will be a conditional and Hey, great defective, which is point two oh five defective and f1 oh point seven times point two five Put your pencils down and look up for a second Once you've written that down Just for what it's worth Good, you may you know I'm big on built-in error checks this point two oh five came from 87 times point two five Plus point three times point one it came from this right First of all, can I cancel have I so can't cancel but if you are doing a conditional Probability one of the built-in error checks is the both will always appear somewhere in the bottom If it doesn't you messed up or miss something Having said that I know this is point two oh five I'll leave this here in the notes. You guys just wrote point two oh five. So the answer is going to be Point seven times point two five point two five point two five just to do it divided by point two oh five What are the odds that it came from factory one? eighty five point three sorry eighty five point four percent point eight five four point eight five four or eighty five point four percent turn the page a few more and then Maybe I'll save your life. What really yeah example three oh We're picking two cards without replacement got you they want the probability that the second card drawn is a king You know what it depends What does it depend on? First card is a king. So let's set up our tree. We could have King on the first Not king on the first king on the second Not king on the second king on the second not king on the second Let's fill in the branches How many kings are there in the deck out of how many non-kings? Please don't count use the compliment 48 out of 52. All right down this branch.  I didn't get a king How many kings are left in the deck? four out of 51 How many non-kings? 47 out of 51. Okay, we got our tree and Trust me the trees get pretty quick to draw they want the probability of King to how many branches end in King to two of them multiply down out across four out of 52 three out of 51 King one and King two or First card could have not been a king Good gosh, mr. Do it. Let's fix that make that a proper two and second card could have been a king now We noticed yesterday that 52 times 51 was 26 52 I've got that one memorized because it shows up so often the top is gonna be four times three 12 plus 48 times four 196 12 and 196 is 196 and 12 is to is it 208 someone check my math. I'm doing it all my head. Am I no 204 208 is it 208 208 thought I was wrong, please. I never make mistakes All right. I have a doubter here in the front row or times three plus 48 times four is 204 I Am wrong Mr. Do it David. Did you set me up for that because if you did I say to you well played? Yes Yes, you may hustle that kid. Oh, where did I watch that because it's not a hundred ninety six mr. Do it because 192 plus 12 Now that question Nicole we actually did yesterday last day What's the first word Nicole of part B conditional? Okay, so let's set up the statement Given what's the given that they gave me you right say louder in my notation. What is it? K1 not K1 K2 not K2 which K2 right What's the probability that what? What's the probability that the first card was? Not so what am I gonna write here? Not K1, okay I'm getting a bit lazy Jordan. I'm actually just gonna write that's both over the given Okay Which branch has both of those that's what's going to go on top? This one has both this one. Yes Yes, yes, yes, it's gonna be 48 out of 52 and four out of 51 Yo Yeah Try see if you can finish the rest of this on your own my children We're back. By the way, did you guys actually calculate K2 or did you just use this number from here? You could have just dropped this ugly fraction But in case you hadn't done part a ahead of time you could have just said oh get K2. Oh that's whoop Turn the fan on mr. Dukes That's K2 Or that's K2 you could have excuse me. I got the hiccups of me. You could have gone four out of 52 and three out of 51 or 48 out of 52 and four out of 51 However, since Jen we already figured out what this works out to I'm gonna this time erase it and I'm just gonna go to saying hey, this is 204 divided by 26 52 I like to for these because they're multi-level multi-level fractions I'm a little concerned about how my calculator will actually work So usually what I do here is work out the whole top in lowest terms I go 48 over 52 times 4 over 51 enter math enter enter this is 16 out of 2 21 over 204 out of 26 52 and then I would say I'm gonna go the first fraction in brackets 16 divided by 2 21 divided by the second fraction in brackets I'm a little paranoid with multi-level fractions I need to play around with my calculator to see whether I can lose the brackets or not You get 16 out of 17 Numbers questions see Second card drawn as a face card so we could redo this Except instead of a king what would we have here a face card? What's the probability of a face card how many face cards other than 12 and 40 11 we could do this and that would be face card second card and then First card was a face card given that second card was not a face card. You'd actually be doing Second card not first card was you'd be going this way up the branch I'm going to pass on that for a second instead I'd like you to scroll down here below to where you wrote your generic probability tree A couple of conditional probability questions that the math nerd within me just loves tests for Diseases so write this one down, please Okay, suppose there is a Terrible disease called Vitalitis Just making something up off the top of my head the test for this disease Is 98 percent accurate And there have been numerous studies that have been done in the population and you know that two percent of the population suffers from this horrible Insidious Well, okay, we'll leave the adjectives off because I could fill a page from this disease Okay So you know that 98 percent of the population is healthy by the way I'm doing this humorously on purpose but replace the italitis with cancer with hiv with anything you want to something more serious Suppose you test positive What is the probability that you actually have the disease And the sad thing is Most people if they know that the test was 98 percent accurate And they know that 98 percent of the population doesn't have it They assume if they test positive There's a 98 chance that they have it and sadly some doctors think that too and give advice that way Let's see what the real answer is So there's two events here. First of all, you have the disease or you don't And then you test positive or you don't Let's define D You have the disease And how about p Test positive and remember what I said and a lot of people will think 98 chance that they've got cancer hiv whatever Oh, and by the way the tests I've made up here Medical tests are normally nowhere near this accurate. So I'm going almost worst case scenario or best case scenario Let's set up a tree So the first issue is you can have the disease Or not What percent of the population has the disease Point zero two By the way, the most common dumb mistake I see is kids do this That's not two percent. What percent is that? It happens every year to the point where I've made sure one of the probabilities that I give you is below 10 Just to tempt you to write it wrong telling you that's on your test. Don't do that What's going here then Okay, and then you can test positive or not positive Or not now in medical language If you have the disease and the test doesn't catch it. We call that a false negative If you don't have the disease But the test says you do we call that a false positive If you have the disease should you test positive or not? If you have it, okay 98 of the time you should test positive 2 of the time you'll get a false negative reading Down this branch. You don't have the disease Should you test negative or positive then? 98 of the time you should test negative 2 of the time you should test positive you get a false positive Because no lab tests are perfect ever What's the given in this question? What's the suppose? Okay, we want to find Suppose you test positive What do we want to put here? What's the probability that you? We want to find d given p. Can you see we're going backwards up the tree? And you know what it's going to be it's going to be both over the given one so you're ready This is going to be both over The given one both d and p at the which branches both d and up Boom boom point zero two times point nine eight That's both over Dan, what's the given here letter p which stands for? Okay, you know what that's this branch or This branch What does or mean? that So it's going to be Point zero two times point nine eight or point nine eight Times point zero two How many numbers do I have in the denominator? Put the bottom in brackets and get out your calculators I guarantee the answer is surprisingly less than 98 percent What do you get what? What do you get I got to try this myself? This is one of the most counter-intuitive questions you'll ever come across point zero two times point nine eight plus point zero two times point nine eight I put the bottom in brackets check I've typed it in right check You're telling me I only got a 50 chance of having the disease That's not bad odds And here is the horrible horrible tragedy And I apologize. I'm going to get a little serious here every year People find out they've tested positive for something And they kill themselves Because they don't want to face it when they don't realize the conditional probability map Doesn't mean what they think it means So what do I say to all of you if you are ever going through a medical situation? Get a second test always Oh jasmine if you extend this tree One more level and then you work out the odds of if you've tested positive twice Then it's much closer to 92 or 93. Okay Oh also Being a bit judgmental if you ever hear of let's say an athlete or a celebrity testing positive for a drug Suspend your judgment until you hear the results of the second test Because when so-and-so test positive at the olympics It's actually Might mean there's a 50 50 chance that they didn't Now Realistically probably not it's the olympics after all but suspend your judgment and certainly in medical tests. Okay See this question.   So polygraphs.  This was some nerdly cool stuff. Hey, huh? I really I really Pardon me. What was that? Oh, I mean polygraphs. I mean they're sorry By the way, the only way you could get these numbers accurate is to make the polygraph 100 accurate Do you really think lie detector tests are 100 accurate? In fact, let's be clear. Do you really think they're 98 percent accurate? I doubt it I doubt it and medical tests as well are not 98 percent accurate. So So The fact that you have lots of false positives in a conditional probability question can dramatically skew your results Absolutely I would hope so Well, no, the reason they don't use them is Constitutionally, you're not allowed to incriminate yourself. I'm worried with the current climate with 9 11 or not that they might want to And they don't realize Mathematically they're garbage Garbage why because most people will tell the truth Almost everyone will tell the truth in the court of law with lie detector tests and unless it's perfect then that means you're gonna have a Bunch of false positives people are going to be found guilty of lying when they're not And that could really ruin someone's life, right? So what's your homework? Well, first of all, stay healthy and tell the truth Okay Questions to try now. I wrote page 461 to 8 and page 468 I see you guys tomorrow tomorrow with the short. Oh, I don't know. I don't see you guys tomorrow Yeah, I do it's a short friday, and it's a tuesday schedule I may for you guys press pause.  Did you learn something new? Hey, huh? Page 460, um I'm going to assign number one. I hate the wording of number one, but it often shows up. It's weird english So i'm going to assign it I said to try number two I'm actually going to give number three instead now number three instead of using a tree You're going to fill in the chart But from the chart you can get all your probabilities by saying how many out of how many how many out of how many And visualize the tree. So that's good practice Four is good Five is a disease question So five yes Six is okay Seven is a bit overkill. It's a long question. Although it's nearly cool Eight is good. So that's on page 460 Then on page 468 so in page 460 on almost all of those you're still going straight down the tree Only a couple of times you're going backwards The fancy term for conditional probability Is bay's law Oh remind me tomorrow. I need to tell you why had marsha clark had a mathematician on their staff OJ simpson would have been found guilty because the defense used a bad conditional probability as one of their main arguments That's tomorrow See how I left you hook. Dangle there Okay Number one Four, uh, no, I'm gonna nuke five. Sorry. Why did I nuke five because I didn't assign it here? Why did I not assign five? Oh, yeah Now let's get five I think the one I'm looking for Yeah, that's nice number seven because it's university and passing exams, which some of you might be interested in But it's a three level tree You know what I'm gonna do instead I'm not gonna do the three level tree I am going to assign number eight. Now number eight requires you to turn back to page 461 Okay Last thing so i'm done the lesson and if you need to go to the washroom now is the time however Have you ever been standing in line like at the supermarket? And you look at the line to your right And you look at the line to your left And you're convinced that the fates are conspiring against you that no matter what happens Your line is traveling slower Is that your imagination as it turns out there's a valid probability argument that suggests That's not see if you could this this math is at your level. See if you can follow it I'm sure this week you've been trapped in a slumbered line in this box I have a gift which shows how to choose stores with the shortest way It's in old-fashioned telephone. Now, of course, if you're using the phone it's important Okay, I have to pause for a second because apparently I can't have all this software open at the same time So i'm gonna go right click


Hello everybody. Welcome back to another AI video. In this one, we're in Runway ML or Runway Machine Learning. That's what the ML stands for. And in this one, I'm going to show you how to delete anything out of a video. So I'm going to hit play. And I'm going to show you here, the hit the preview button and show you what we got here. We've got some aerial footage, some drone footage of this cool field. You know, fancy, dancy. What if I told you there was a tractor driving in this and I just deleted it? Yeah, that's what it's in there. Watch this. If I hit command Z, look at this now. It's the same thing. I just undid one step and I hit play. And then all of a sudden there's a tractor. How in the heck did I do that? Let me show you step by step. I'm going to delete everything here. Let's just go back. So I'm going to click on this back to projects. We'll delete this project and we'll start from the beginning. Okay, so the first step is you want to go to runwayml.com. I'll put a link in the description below. But when you do that, you're going to see this screen here and you're going to see sign up. It's free and it's free. You get three free projects. You can use some of the AI tools and some of the machine learning tools. It's really, really cool. And if you really, really like it, you can purchase it. But again, this is for the free version. Okay, once you're logged in, you'll see a screen like this. The next step, create a project. So I'm just going to click on this, create your first project. And now we're going to use in painting. This is the tool or the AI tool, the magic tool that deletes that stuff. So I'm going to click on it in painting. Okay, so now we've got a new project. The next step is you got to download or input your footage. So for me, I've got this tractor video. So I'm going to grab it right here. And I'll just drop it in. Of course, I've already done that. It's part it's already in here. But that's the step just in case the next step, I'm going to grab the footage. And I'm just going to drag it in. Oh, missed it. Let's try that again. I'm going to go ahead and drag it into the timeline. And you're going to see something like this. I totally missed on that. So I'm going to hit spacebar to preview it. And there you go. You'll see that the little tractors doing its thing. Beautiful. Now, making sure the play is at the beginning, I'm going to go ahead and grab my little brush. And when you see this year, you'll see the little purple circle around it. That means that we've got the in painting or the magic tool brush getting applied. So I'm going to go ahead and increase the size of the brush here, just to make it nice and thicker. And then again, this isn't going to be perfect. But I just want to show you the technique. And you'll notice that I went a little bit behind it. And that's because there's a little bit of a shimmer when the tractor is moving that some of the stuff that it spit note is also kind of we want to delete that too. And now look, the tractor is gone, done. Now I click preview and presto the tractor is history. That is all there is to it. If you look really, really carefully, you'll see a little bit of a shimmer, but you'd have to be really looking forward to see it. But that's how you delete a person, an object out of a video using AI tools and runway ML in seconds. Thanks for watching.


Reactionary base player don't get a twist that this man puts in the work He understands when it's his turn to swing and what options he has beautiful really late throw escape there from Ayate again The reactions It's not the easiest thing in the world to see that and be able to detect the right way. Yeah, you can say so many things about him You know he's reactionary based. He's also just a great student of the game. Wow. That was a cool little pick up Beautiful execution and not only that the whole time Knewb was taking that dot damage the damage over time because of that acid He's perfectly placed there in the corner I get to talk to Hayate a lot and it's so cool that You know just in talks with him that he talks about other fighting games and other approaches to neutral other approaches to mix ups And that's a big punish that he sees in Tekken that he sees the streets fighting He tried to implement them here I guess it's such a student such a smart guys Ayate and it's really one of the true labbers like true lab gods I would say yeah I mean you have to be smart to succeed in this world You know you have to figure out what the options are you have to figure out all the ins and outs You made him jump and that was just like you know And I feel like that's a situation that Hayate has been in time and time again after the forward after I'm sorry The back throw connects throwing the acid he knows and punishing the any attempts of trying to throw projectile You cannot do that against this variation of air that you cannot that acid puddle is so good at closing out rounds and at 1% And then we're really what other option does your opponent have other than a jump forward there or a jump back where he's just gonna have His stance loaded anything you can't move forward He's gonna walk on the acid puddle just in case you try to teleport in here if you're a doob sidebar I had a flappy here. This is a good second round and back to 2-2 There is hold on a little bit of a drop from Hayate and he's getting punished for his trouble. He's going for the optimal Huge damage leaving him standing because of that projectile and able to get the throw clean wow Little bit of momentum now one round apiece I love that Aaron black has the respect to tip the hat after losing around right there And here we go to the corner and that is so tricky Sonic box break down noob sidebar in the corner and how that string is so good at stopping people from going going for and taking Pros it looks like a throw and then the little naturally launches Massive damage speaking of massive damage every time you bought noob sidebar touches you you get deleted Oh, yes, you do he hits like a truck not really too much in the mix department But that's okay because when you find the openings as long as you capitalize you can make this character work to your favorite He is making it Wow, that looks like a trip card. It was a punish on the back to 2-2 as a puddle is down That was so smart. That's not a cancel you see coming normally off But now we're at kill territory you gotta watch out It wasn't enough to stop him he was down to a pixel the armor saved him Oh What's that? What's he gonna do teleport? No, no, no. Oh, no Okay, he put all the wine did it. He just did it ladies and gentlemen If he thought that a throw was coming or if he thought that any high was coming He could have neutral duck held down without blocking and that down too would have whiffed into an easy victory for amber flabby But that is not one HP is all that came down to one HP I talked about we might have a classic on our hands. You saw the skill that the flappy possesses. Yes coming in the game number two Here we go, ladies and gentlemen I'm absolutely excited for this one down to the wire hi out date You said getting maybe a little bit of murder with that swing of the doubt, too I may have read a jump may have read a lot of things. Yeah, definitely could have been I didn't say you got away with murder I just said it was a very risky It was a risky situation and it paid off and you know you said that before you you alluded to that that Payate is one of those players that will sometimes make a questionable decision just a big swing I'm used to him having this that big swing especially in a tense situation like he found himself and that was That's it was it's a right there was Mortal Kombat 11 at its finest well Hold on Flabby getting something going with the standalone 3 and he decides to air escape now Payate is gonna have no wake-up options for a very long time until that bar comes back. Oh Oh Smacking him out of the just out of this dance taking him for a ride. Oh, no, he teleported himself to the corner I don't know if this was the smartest decision out of Flabby here Maybe thought he could catch hi out they going for a whiff coming with the sides nice not no amplify on a dope I'm gonna need to shout down for as well as good position right now for Flabby And he was a little too quick on the trigger there gonna get with punished himself You know that's if your opponent's pressing buttons on your wake up rolling past them is one of the best Drop the fatal blow it didn't connect, but it's not gone It will come back in just a few seconds if he can survive until then not sure if it's even gonna be an option I'm so scared. Oh Snipe out of the sky that That could have whiffed. I didn't think it had that high of a hipbox to it Must have just barely touched noobs toes as he jumped in the air now Flabby's looking like he's in a bad spot here Air black can start mixing them up here Goes for just a regular overhead this safe stop and Flabby trying to poke trying to take his turn back But hey, I think that's no have a throw tech and more momentum in my favor Forward throw I know tunes. I'm noticing how they swing with with the with the actual boot off of the back to Which makes them able to pick it up off the entire just the back to two will drop so that's really smart I think oh Speaking of smart hit confirm here by Flabby and looking for the read of the throw on the wake up and Tatte with the disrespect one of those options I talked about not just neutral crouching but jumping yes Jumping you can't throw someone who's jumping in the air and you can't throw someone who's crouched crouching without blocking Well, hold on Flabby's trying to cash in here.  Wow standing position goes for the forward throw We does have a fatal blow as well. So does hi out a little throw. This is not enough wait I want to jump if you have the question below to jumping was scary I think it's gonna have a throw meant for him on the ground hi out day two to zero But what a fight from from Flabby here both these players are just phenomenal here And it was a nail-biter down to the wire


So, fantastic conference. It's really funny, because as a speaker, I quite often go to conferences and don't actually go to the conference, but always with these ones I attend because I just learn so much stuff in all the talks. I really, really appreciate it. And I've been thinking, okay, so this is the final keynote. Everyone's kinda like, the two days of really interesting stuff. So I need to give something that's really exciting, that's really motivating, that's really tremendously good. What am I gonna talk about that has all of those great attributes? And I thought, okay, obviously. So I need to talk about, well, ish, okay. So at the Pragmatic Bookshelf, we get quite a few proposals come through for projects where people have basically written some code and they say, I wanna write a book about my latest project. And on the kind of proposal review team, we call those proposals the what I did on my summer vacation proposal. So that's what I'm gonna do now. So the official title is corrupting the world, but the actual title is what I did in the first six months of retirement. So two are actually pretty much the same. So I retired back from the Pragmatic Bookshelf full time back in June. And fundamentally, it was because I had like a backlog of several thousand cool things I wanted to do. And, you know, formatting books and stuff wasn't one of them. So I sat there and I was like, dear in a headlight, suddenly faced with all this freedom. So I spent some time just spinning my wheels. But I did some cool things. And those cool things all kind of like point towards the same direction. And I hadn't realized that until I put this tour together. So let me honestly indulge myself a little bit and talk about some of the projects I've been involved in. Three. Number one is I have always wanted to try this. So I got a gig teaching at SMU. And I taught in the School of Engineering, the Bobby Lyle School, very nice looking building I taught in the basement. And I gave what I think is the first credit university level course on Elixir. I had 35-ish students, a mixture of undergrads and master students. And we went through everything. I was gonna teach in Elixir, the basics of functional programming. And I discovered that these seniors had not actually been exposed to testing. So we spent some time talking about testing. And most of them didn't understand Git. So I spent some time talking about Git as well. But apart from that, we did a whole bunch on functional programming and on concurrency, we did some gen server work. We did some work with Phoenix and Phoenix Channels. And at the end, they had a kind of open project. And I got some really cool projects back. My favorite one I think was somebody did a project. This was back in November, just before the election. And they did a project that was a, used Phoenix Channels to drive a front end. The back end was some servers that went out to Twitter and picked up responses to the Donald Trump and Hillary Clinton Twitter feeds and generated word clouds from those responses in real time. It was actually, it was fascinating to watch. It was real, I mean, I sat there and, because they submit the projects and eventually you have to run them. So I ran them. And I was just sitting there for like 20 minutes, just looking at this thing, updating on the screen, it was so cool. We had a fun time. The actual core of the class, once we got over the syntax and what is an editor, is we just basically wrote a game. And we wrote a game by starting, I had them write the hangman logic for a hangman game. So this is a module that would sit there and score moves basically. And I gave them a set of unit tests and I said, here make these pass. And then eventually we also wrote the human interface to that, the CLI. So they could actually play the game. And some of the master students I made write a computer player. So it would play the game for them. So that was cool. And then we talked about processes and gen servers and stuff. So I made them write this delegating gen server. And by delegating gen server, this is kind of like a bit of a theme of notice going through the last two days, is I really do not like putting my application code in my gen server. Because to my mind, the gen server is simply there to act as some kind of process thing. It's not really my application. So what I tend to do is to write my application logic in a separate module. And Chris was talking about this as well. You write your application logic in a separate module and then I just delegate to it from my gen servers. So I had them do that for this particular module and then for the dictionary module, it was just an inline gen servers. They could compare the two. And that all worked fine. And then we added on Phoenix and a JavaScript client. And that was all fine too. And this got us towards I guess the beginning of November and then they went and did their personal projects. But the cool thing that I pointed out to them, and which I think is actually a real big testament to the way all of this is structured, is that the very first thing they wrote, that Hangman logic at the top there, survived totally unchanged through all of these iterations. So they went from being an inline library to being a background server with state to being some part of a web application with no change whatsoever. And they could still use their human interface directly to it if they wanted to. So I thought that was kind of cool. So that was kind of like one aspect of what I did. It was totally an incremental development and it was made incremental because I get these structuring concepts built into Phoenix, OTP and Elixir. So that's number one. Number two is I wanted to play with, I don't even know what the name is for them. So let me explain where I'm coming from. A big deal at the moment in kind of like many circles is this concept of reducers. So a reducer is a function that takes a state and takes an input and generates a new state from it. And that's the function that we pass into in num.reduce whenever we wanna do things like summer collection or whatever else. It's also the signature of the main body of things like React and Elb, right? They're reducers. They're functions that respond to some environmental change by updating their state. The opposite side of a reducer is called, I have no idea what, expander or something, right? And sorry, I thought someone actually knew which would be really nice. And those are the functions that are used to generate data, like generate a stream for example. So I wanted to play with that. So I decided to have a go writing version of QuickCheck for Elixir and QuickCheck is a property-based testing framework. First came out of, sorry, Haskells? Yeah, it was Haskells and it was John Hughes, yeah. So a property-based test could look something like this. Property test A, which is an integer, B that's an integer and in this case I put a few extra parameters on, I don't really need. And I just want to assert that my integers, if I add A plus B, I get the same result as B plus A. And it's gonna generate random integers and just run that test in this case 50 times. The default's actually, I think 500, I can't remember. And you might say, okay, what's the point of that?  And the idea is in the same way that normal unit testing makes you think about your interfaces. I discovered to my surprise that property-based testing, it's not really about the testing. It's about thinking about the properties of the functions that you're writing, yeah? So the fact that addition is, commutative, I can't remember, is it commutative? That one, yeah, yeah. Is a property of addition. This wouldn't work for subtraction, for example, yeah? It makes you think about the properties. And so as you start writing these kind of tests, you actually start thinking more about all the various edge cases. In fact, in Quixar, I actually made it so that I kind of thought ahead a bit about some of the obvious edge cases. Like for integers minus one, zero and plus one are obvious edge cases. For strings, the empty string is an obvious edge case. All this kind of stuff. So I inject those and then I inject random values. And it's kind of fun. It's surprising it does actually find bugs in code, but like I say, it's as much a design technique as anything else. And then I had fun trying to do things like this. So A is an integer and B is an integer that has to have a value at least A. And that is a wonderful little exercise in keeping stuff until the very last minute until you execute it. I had a whole bunch of fun getting that to work. And then lastly, you can do things like this. So I'm gonna generate a structure of type person and it's gonna contain a name which is a string that contains ASCII characters and an age which is an integer between one and 125. And that all just works. So why I ended up having to do, and this was kind of like the whole point of the exercise as one of the play with this, is I wanted to experiment with how to generate streams of values. And the things that were generating those values were factories. So I ended up trying to implement something that was factories driving streams. So I decided to call it pollution. And this is the actual, this is 90% of the code in Quixar is the pollution framework. And this is the thing, it's actually useful if you ever want to use just general mock data and stuff. The API is simply you can tell it what you want using that kind of A colon int business and then it will go through and it will generate you a stream as long as you want. So yeah, I had a whole bunch of fun with that. And the key to this and what's gonna tie into what follows is this idea of stream.unfold. It's the opposite of inum.reduce in that it takes a state and a generator function and it generates a new state plus a value. And if you implement that, for example, if the function you takes a value and then returns a new state and, sorry, it returns that value as the current value of the stream and then increments the state for the next time around then what you have is an infinite stream of integers. So the first time you call it with 10, it returns 10 and 11. So 10 is the value of the stream. Then the next time you call it, it's gonna get that 11 as a value. So that's the value of the stream, et cetera, et cetera. So it's really, really simple to generate these infinite streams using the stream generators. So you can think of this unfold as being the opposite of reduce. It's kind of an expander. What does it do for us? Well, the fun thing is you can chain them together and you can change them together recursively as stream does, or you can just change them together by just calling one after the other to achieve this set of transformations where each step of the transformation generates an output. And that's where I found it was the most interesting because now I can start creating a genuinely functional solution that also has all these interesting outputs as it goes along. And all this kind of like culminated in an idea I've been kicking around a long time. So this is where I get to do my professor act, okay? If you went, how many people here actually went and did computing at college? Oh, fair number, okay. So at some point in your kind of one of the one level classes, right? I'm pretty much certain that somebody produced a diagram that looked a little bit like this. It was how do computers work? And the diagram was, well, you have an input and it goes into this box that's called a processor and then it produces an output. When I went to college, it would be punch cards go in there and the line pressure starts at that end, right? And then that go, and of course, there's also storage down here, right? Where you can actually store values and retrieve them in later runs of the program. So this was kind of like the basic idea. This is how your hardware works. This is how your processor works, your computer works. Cool. So let's tidy that up just a little bit. Speak to me. This is pretty much identical to the way a function works. Yeah, or a process works in that we have a process that takes input, it produces output. What do we call storage in this case? Thank you. We call it state. So we have these processes that produce input output and they have associated state. And when we're looking at the reducers, sorry, the expanders, right? It's exactly what we're having. We also had this tacitly when we were looking at the hangman server. It was a gen server and that's what that has as well. It has state input output. So this concept, this little three prong diagram is hardwired into a whole bunch of the stuff we do in Elixir. And often we have a state that is passed on from one of these processes to the next. And it can be passed kind of implicitly or explicitly, but that state sits around and gets used between functions. And this is where I started thinking about, okay, how can I use this in a different kind of way? First thing is, it occurs to me that you have different sets of states. So for example, if I have a gen servers, then each gen server is maintaining its own state. And each of those is independent and typically the calls are calls into functions in that gen server and those calls potentially change the state. And they're independent. That's what we like about it. That's the whole point of using gen servers. But if we go back to this idea of just having a common state that's shared, let's look at just one of those boxes. If we look inside those boxers, there is nothing to say we can't have exactly the same structure inside that box. So typically when we write our Elixir code, what we're thinking about is gen servers. And they have these, one set of gen server, sorry, one gen server has one set of state and we don't worry too much about the nesting. What I'm saying is, sometimes we think about nesting explicitly. What kind of cool thing can we do if we allow nesting to occur to kind of like ridiculous levels of depth? Can we have transformations all the way down? So all of our programming consists solely of transformations.  The entire point of a program is input goes to output. The entire point of a program is transformation. And logically, a program is divided into sub-programs and they're into sub-programs so you should be able to do transformations all the way down. So the question I wanted to ask was, can we write non-trivial programs as nothing more than sequences of individual transformations?  Individual transformations with pattern matching are turing complete. So of course I can write entire programs using nothing but those, but it's not the best way to structure programs.  Can we write parts of programs as nothing more than one line transformations? Obviously the answer is yes, but now it's a really good idea because I think it gives us a slightly different way of thinking about programming. Now, before I go any further, anybody who has any sense of computer history at all will know that not a single thing I'm about to show you is new. This is all known technology. Some of it goes back to the 50s or before that. I don't care, right? I'm not claiming to be new, but what I am claiming is that it's a different way at least for me to think about programming and I'm really enjoying what it's letting me do. So I produced a framework. No, it's not framework. I created like two modules that I packaged together. I called it diet because it's based on the idea of reducers. And it lets me play with a programming model. So in diet, all I do is define code as a series of transformation specifications and you group them together into a thing I call reductions and all of the transformations in a particular reduction share a common state. And then you can nest these reductions to write more complicated programs. A reduction looks like input goes to output. So it looks just like the clauses inside a con, for example. It does pattern matching on the input and the output is just an elixir expression. If you want to change the state, then in the output, you're gonna add an extra call, you're gonna say something like update state and give it the new state. And that's what tells it that, yes, I want to change the state and not just use the state. So like I say, inputs are patterns with guard clauses. And what happens is you produce an output and diet assumes that that output is another pattern for the input of something else. And if it finds that, it just invokes that match instead. So it's gonna keep calling those matches until it finds one that doesn't match at which point it's gonna return it to you as the result. So it's kind of like state machines. So let me show you a real simple example. So where I make a fool of myself typing. So we're gonna do FizzBuzz, all right? And we're gonna use this diet thing. So diet dot, oops, transformations. And now I'm gonna define my set of reductions. So my input is gonna be a number. And what I want to return is either that number or if it's a multiple of five, no, hang on, I could never get this right around. Three, I say Fizz, multiple of five, I say Buzz. If it's multiple of both, I say FizzBuzz, all right? So a convenient way to do that is, I'm gonna just call, let's call it FizzB, FB. I'm gonna pass in the number and I'm also gonna pass in the result of remaindering the number by three and remaindering the number by five. Okay, so if I was just to run this, sorry, oh yeah, thank you. Yay, that is the only mistake I'm gonna make all afternoon. So if I was to invoke this and pass in 27, for example, then all that's gonna come back is a tuple, FB2702, which isn't much use. So let's extend that a little bit. So now I'm gonna match FB and I don't care what the number is at this point, but if my remainder is zero for both of those, then my result is gonna be, oops, FizzBuzz, which is actually better, FizzBuzz, right? If the remainder is gonna be zero on the three, then it's gonna be Fizz and if the remainder is gonna be, ah, sorry, zero on the five, buzz. And then the last case is, if it's not gonna be zero on either of those, then don't care, it could be anything. Yeah, let's be consistent. Okay, so that is a program written using that Dart framework, just a series of transformations. Should we run it? Okay, so it's gonna be an IEX. Oh, yeah, that's not supposed to happen. Oops, sorry. Yeah, that's all right, I'll go with that. This worked before I talked to Chris in the green room and showed him just that. It says, actually, 100% Chris's fault. Oh, I really hope this works. It's got some really cool demos to show you. One more time. Yeah, I am, let me go out to, I mean, that's how I run all the time, so I'm not just sure, compilation hangman. That's his fault. That's his fault. Yes. Ah, okay, that's what I get for showing you code just before I talk about it, hang on a second. Hangman model. Yeah. All right, one more time. Don't encourage it, don't encourage it. Okay, so to run this code, I'm gonna need something that steps through all of these cases, yeah? So I have a module called stepper that I feed this thing to and it does the business, right? So let's create a stepper here, so I'm gonna say s equals a bit of ooprogramming. Look at this, stepper.new. I pass it the name of the module, which is fizzbuzz and pay no attention to that last parameter. It'll become clear later on. So this constructs a stepper for me and now I can execute this code. I can say the result and the next version of the stepper equals stepper.run and I'm gonna pass it the stepper and in this case, an input value. So I could pass it, say, let's do two, yeah? And I'm only interested in seeing the result so I'm gonna ask IEX just to output the value of the result. And so if I pass it two, I get a two out. If I pass it three, it says fizz. If I pass it five, I get buzz. If I pass it 15, I get fizzbuzz and 16, you get 16. Right.  Because the, it is magic. That is actually a good question because to be honest with you, normally what I do is I actually pass in like a request like that and this time I thought, hey, I'll show off and not do that. So quite why it doesn't loop infinitely. I would just say it's very, very clever. I'll work out why later on, okay? Oh yes, maybe it is because the number is quoted. Thank you. Yes. Details people, details. I don't know. I'll work that one out. I'll work that one out. Okay. So let's make it slightly more complicated and you'll notice that fizzball walls didn't actually use any state and that's okay because I'm gonna show you state a bit later on. So now our next one is gonna be one of my favorite examples run length encoding because again, it's totally useless just like fizzbuzz. So we're gonna take a list of values and if we detect a repetition in those values, we're gonna replace the value with the tuple of the value followed by the repetition count. Yeah? So we can start this one off again over here. Got one, let's go to RLE1.exe. Okay, so we're gonna use the transformation again and kind of shrink this font just a little bit. Okay, so we're gonna start off with a list and this time I'm gonna pass in a command encode list. We can use guard clauses. So if you wanted to, you could say when is list list. Okay, and I'm gonna have to have a helper function here that has an output result. So I'm gonna have my command is gonna look RLE, it's gonna have the input and it's gonna have the output. So if I was to run just this code, right? So if I compile, did I save it as fizzbuzzle? I didn't save it, that's why. This is a bad idea. I don't know why I'm doing this. Reductions do and, and, that's the wrong file. All right, let's try. Okay, so again, I'm gonna create a stepper and we pass in this case RLE1, no initial state, R comma S equals stepper.run encode. We just pass in a list one, two, two, three, three, three, three, four, five, five, why not? Oh, I didn't pass in the stepper itself. And let's just have it just look the result here. So the result is just that tuple I created, right? RLE and that list and then the output thing is empty. So let's start adding some code. So here I'm gonna say, so to run length and code, an empty list and the result, well then the answer is just the result, right? And if I run length and code, let's start with the simplest stuff here. A list that has the head of A and then rest and a result.  Thank you very much. Who needs a compiler? Okay. So back up here, we'll reload RLE1 and there's an obvious bug in this, right? Apart from the fact that the missing terminator is there. Ding, ding, ding, ding, ding, ding, where's my missing terminator? Okay, so I can just rerun that stepper now and the result comes back backwards, right? Cause we're recursing through it. So I gotta fix that by just reversing that. Okay, so that's just copying the list. Let's start running length and coding it. So if I'm running anything and coding a list where the first two entries are the same and then there's the rest and the result, then the answer to that is what happens if I run length and code, a list that contains the value twice, followed by rest and the result. And then the same kind of thing is if I have a list that starts with A and some count and then another A, the result is going to be A and that count plus one and another A. So now I've written my running length and code are using nothing but transformations. So back up here, it's compiled, yeah? So this is clearly relatively artificial code, yeah? It's not like you don't spend every day writing pure code that does something like that. But I wanted to show it to you because I wanted to show you that you can write stuff using nothing but transformations, yeah? But now you might ask, okay, well how do I know what this is doing? Because it's like kind of non-deterministic, but it's like kind of like it just throws values out and then does things with the results and it's hard to track. But the cool thing is you can track it because the execution is actually run by this stepper thing. So if I go back into the command line here, right? I still have my state that I've kept lying around. So I can say diet.debug and pass at the state. And sorry, pass at the stepper, not the state. And so now it says, okay, I'm diet debugging RLE1. The interesting command at this point is if I type T for trace. It's gonna show me everything, all right? This is showing me every single transformation that took place during the execution of all of those runs of that stepper. So what you have is you have input arrow output. So you can see in this last case, we had a five, no, up here, we have the output, sorry, the input list consists of two fives. So it converts that into five two. Now we have an input list that has five two. It converts that so the output has a five two at the front of it and the input is now empty, input's now empty, so we now produce our result. Yeah? So you can actually trace through all of these things and see what's happening, which is kind of fun. All right, you'll be relieved to know that I'm not going to code the next example. So let's have, I'll have a look at hang person because hangman involves having some kind of state. You have to keep track of the guesses and everything else. And so for the first time, we're gonna introduce state into our diet models. And our state contains all the obvious things. It contains the actual state data, which is the word to guess, the letter is used and the turns left. And it contains what you might call business logic. So the fact that you've used a letter is business logic. The number of turns left is business logic. Whether or not we've won is business logic. So in this way, these things are actually a lot closer to pure models in the correct sense, I guess, than we're used to. It's purely just, it's almost an object actually. It's state plus stuff that operates directly on that state. And it's manipulated from the transformations. And the transformations have no state, no business logic. They're simply the rules by which you invoke parts of the business logic. So our model looks like this. It's just a regular old elixir model, def module, hangman model. The structure is where you define the structure of the state. And then we have down the bottom here, we have our quote business functions. Did we already use this letter? You know, I want to use this letter. Is this letter in the word, et cetera, et cetera. And then the first function there is a function called build, which we use to construct a new model given a word. So how do we use that? Well, now inside our hangman module, this is the one that has the reductions in it. We use diet transformations, but we tell it some extra stuff. We tell it that our module, our model, is a module called hangman model. And because we don't wanna type hangman model all the time, we're gonna alias it as HM. So this is simply telling this module the name of the module that represents our model. Inside the reductions, we don't want to, we don't particularly care about the model as much as we care about the state in that model. And so I guess I probably could have called that state name, but it's called model name. And what it does is it basically ensures that within that block, within that do end block, the variable game will already be set to the current state of the hangman game. So this is the actual logic of hangman. So at the top, we come in, we say the model name is game, and the kind of quote entry point is make move. So we say make move and we give it a move. And it says, okay, to make a move, I'm actually gonna call a separate match because it's a three parameter two plus plus a two one, it's gonna make move the move and a Boolean, have we already used that letter? And then the next two lines say, if we have already used that letter, then I'm just gonna return already tried. Otherwise, I'm gonna record the move. And what does record move do? I mean, I could have made those into one, but I like splitting them out. Record move calls update model and updates the letter, sorry, updates the model by saying I've used the letter. And then it returns the tuple maybe match and a move. Just say we'll hate this somewhere in Poland. A little Brazilian is gnashing his teeth and not knowing why.  I don't care because to me, it makes sense. And I'm the important one. So how does maybe match work? Well, you pass maybe match goes to the model again and says, is this letter in the word? And again, we come back with either true or not true. If it's true, we have match. So then we're gonna go down to match here and it's gonna say is the game one. And if it is, then we're gonna return game one, otherwise, et cetera, et cetera. So it's really pretty straightforward. And it's nice if you write this in regular code, then the natural way to do it involves at least one level of nesting of cons or ifs or whatever it is you prefer to use. But like this, it's all pure linear code. So let's see if we can run this. Based on my current experience, the answer will be no. All right, so I'm gonna create a stepper and I'm gonna create it for hangman. Oh, yeah, you're right. I'm still in the debugger. Thank you. All right, s equals stepper.new. Hangman. And now I'm gonna, now you're gonna see the parameter at use. I'm gonna pass in the word to guess and you're not supposed to look at it because it ruins the fun, okay? So you'll notice that what comes back is a stepper object that contains a model. And that model is one of those hangman model structures. So it's the word one back guess turns left, et cetera, et cetera. So now we can start playing our game. And we can play the game in a couple of ways. One way is I can do it like this. I can say r comma s. This is the way we've seen so far. Equals stepper.new, sorry, stepper.run. Stepper run s. And then I'll just have a look at the result. Good guess, it says. All right, so that's one way of running it. Or I can use this diet.debug thing. And there's actually a thing inside that that lets me run a step and simplifies the syntax a little bit. So I can just say arm make move o, good guess. Hey, look at this, I'm on a roll. M, good guess. E, oh, damn, I made a bad guess. I hate that, right? Because I don't want to have this history of me making a bad guess. Let's have a look at our history. So this is all of the history of that game so far. And you'll notice that the numbers are one dot something, two dot something, and they correspond to the top level entries into the stepper. And then inside the stepper, there are individual sub steps as it's doing the internal matching before it returns. So my first move was an a, so then it calls that model to say have I already used a, no I haven't. So then it's gonna go to record move, it does a record move, there's maybe match. Maybe match is true, so it's a match, right? Have I won, no, so therefore it's a good guess and it returns good guess, yeah? You'll notice that some of these lines have a little arrow next to them. The little arrow means that I changed the state.  And if I wanna find out what I did there, if I just type in that number, was that 1.3, then you can see that at 1.3, my trigger was record move a, the current state of my model was that. The result of the match was a maybe match a, and the changes were, notice it's highlighting the a in guessed. So that says that's what changed in that particular instantiation of the function. If I go down to when it's slightly more interesting, if I go down to 4.7 there, then I now have one less turn left. So turns left was seven and now it's six, yeah? But I don't like the fact that I have this failure in my history. Wouldn't it be nice if we could change history? Let's clone our history, but I'm gonna clone it only as far as 3.8, which was the last time I was successful. You notice that I now got hangman zero and hangman one. If I have a look at the history for hangman one, it only goes up to 3.8. If I switch across to zero, now it goes to 4.8, where my failure is. Let's go back to one because I like that more, right? And now I'll start making some more moves, make move t, I don't need the comma. Good guess, what haven't I guessed yet? W-O-W, I must be getting close to winning. M, I've already tried. Sorry, B, B, one, yay. All right, so between us we won that game. Yeah, isn't that cool? Right, we won and this is in that history change one.  So sad, I think that's kinda cool. I think it's cool to be able to look at the execution of my program in terms of the decisions it made as it was executing and to see the changes of state explicitly as they are made as the program executes. It's fun to be able to change history, to go back and to clone a history up to a certain point and then fork it off. Imagine you had, say you were running a server and it had some relatively expensive initialization where you had to go out and fetch some whole bunch of stuff and do things to it. So you run that initialization forward to that particular point and then fork it, the history, into separate threads. So that all the subsequent execution is independent. It all shares a history and then becomes independent. So there's really very little magic here. It's nothing special. When you say stepper.new, it calls the build function in your model. So first of all, it goes to the model which in this case is hangman and says what's the name of your model? In this case, it says hangman model. It then invokes the build function of the hangman model passing it whatever parameter you passed in and it then goes and associates that with the state inside the stepper. And then whenever you call step, it passes that state into, in this case, a variable called gain. And that makes it available. If you were to say update state inside that game, then it actually changes that value and sends it back out. And so the stepper function is simply calling into each of those transformations one at a time. So it's running one, then it runs another one, then it runs another one until there's no match. And each time it does that, it can record the state, record the history, everything else. So there is, oh, if I'm channeling Trump, there is a functional alternative fact. And that, it's a big one, right? And it's one that we accept without blinking.  And that's what makes it so great. That's what makes it so easy to work with because the data doesn't change because there's no side effects. There is a side effect, and it's an incredibly big one. In every single bit of code that we write. Anybody give me a guess? Think of some piece of state that changes constantly throughout the life of this code. Sorry? And how is time expressed in code? Yeah, it's the program counter, or if you're an Intel person, the instruction pointer, right? But implicitly, our program counter is being changed every time we execute any code. And that change is a fundamental side effect. It's a fundamental change to the state of our program. And it's one that cannot be undone. And that's what makes it so hard to go back. That's what makes it so hard to split our code up at any kind of level that doesn't involve modules and functions and us explicitly telling it to split it up. But if we were to go back to this kind of scheme, when we're running these things here, each time we make a guess, well, not even each time we make a guess, each time it runs one of those transformations, it goes into the code and then comes back out again. And that is a stateless operation. So I could go back in and re-execute that and I would get exactly the same result back every single time. I can copy it and have something else run it. I can run it on totally separate processes and it will run perfectly happily. So this idea that I can just keep this chain of history and if necessary, clone it like this, I think is a really big deal. It's not new, right? The basic ideas here are things like state machines, tuple spaces, that kind of stuff. Databases like Datomic do exactly this to handle changes, right? Nothing new. But Elixir makes it incredibly convenient to write code this way. It gives us all of these interesting side effects because each one of our transformations is fundamentally a single line of code. And I get reuse at that level. I get per line of code parallelism. So I could have my stepper running as a pool of gen servers and if I had a hundred people playing Hangman, then individual lines in that transformation would be running randomly on all the different servers and it wouldn't matter. Per line of code parallelism. You'll notice I was live reloading the state machine as the code was running and it was fine with it. Now, special case because there were no changes to the data structures, but in principle, you get live reloading not just of code, but also of the flow in that code. And obviously you get world peace. So I'm not saying we should throw away our cons and throw away our depths and write everything like this. As I said halfway through, this is not the solution to the universal solution to programming. Nor do I think this is particularly large scale practical. But Jim, for example, was talking about a thing he had where he's writing some code that is going off to some, I guess it's an OAuth server and getting back a token. And then if that token is okay, he's gonna use that to make a couple of subsequent queries that have to go in order and then a few more queries can go in any order. But if at some point that token expires, he's gonna have to go back to the top and re-get a token and repeat the whole sequence.  It's gonna be really ugly, particularly the case that says I'm three levels deep and then suddenly the damn token expires and I gotta abandon the whole thing and go back up the top, right? Just think for a second, how are you gonna implement that? You might even end up sort of throwing and catching or something else to handle that, ugly. But that's totally linear, single level state machine code. And it would be represented in half a dozen lines as those transformations. So there are definitely times where this is valuable. But more than just being valuable, I think it's really interesting to think about this as a different way of thinking about your code. I don't wanna think about my code as what I'm telling the computer to do. I'm gonna think about my code as being transformations that operate on this big pool of state. And it chooses the appropriate transformations based on that state. And then I can nest those to build real world applications. So let's not get fixed into this idea that Elixir is kind of like a better Ruby or a better Rails in Phoenix or whatever else. But instead, let's use some of these wild capabilities, the fact that processes are basically free. The fact that I can just throw around modules and data independently. And let's start using those things to think about different ways of coding, different ways of programming, structuring our thought as well as structuring our code differently. And hopefully along the way, we'll have some fun. Any questions? Thanks, Dave. That was fantastic. I think you blew everyone's mind with that debugger. That was super neat. I just had a question about the history and the changes. As far as applying this to some real world problem like that Jim had, I think it's really neat on the small scale, but do you have any mechanism building currently to truncate history? Whereas if I have some really, really long running thing, I'm gonna have to discard that at some point and what kind of mechanisms you think that would be good fit for. Okay, so this code, I finished writing like two days ago. This is this part. And it's really pretty trivial. It's just an experiment. So the next step is gonna be to take this and actually try and use it for real in something decent size. And that's why I'm gonna bump into issues just like that. I'm gonna run it into performance issues. And I also wanna generate this pooled solution where I have a pool of servers that are exiting the code. And I believe that to get any kind of decent performance, I'm gonna have to implement some kind of affinity so that when I'm inside one of those runs, the steps happen in process and then it goes out of process when you invoke it from the outside. So that's the kind of thing I'm gonna be addressing. I think that there is no intrinsic mechanism, sorry, intrinsic reason why you have to keep history. Yeah? So you could say, for example, I'm only gonna keep the last thousand individual transitions. Then I'm only gonna keep the previous thousand of the high level transition. So I'm gonna ignore the internal ones and just give the entry and exit to the calls to run. And after that, forget it. Or whatever I might do, that's tunable. So I could do something like that. It's not that I'm like, I say a detomic where I'm actually rolling up all the individual deltas. I'm just recording the history and then doing diffs on it to show you the changes. I've noticed it's the speakers that ask questions. We should ban that. Could we extract the debugger and hook it up to function traces to use it on normal gen servers? The debugger is a total of 25 lines of code, honestly. But yes, if you wanted to. It's, hang on. Okay, more than 25, but not much. Okay, so there's trace history. And clone is C, so that's up here. There's the clone. Yeah, I mean, so it's not much. But feel free, I mean, at some point, once this is stabilized just a little bit, it's currently up on GitHub, but it's private because the last thing I want is people saying it doesn't work. I know it doesn't work. But once it's stabilized a bit, I'll make it public and feel free to mess around as much as you want. Okay, I want a non-speaker question and I'm gonna be very patient on this one. Because remember, we've got until midnight. Did you just reinvent prologue? Sorry? Did you just reinvent prologue? Yes, I know. I didn't say it was original, but it doesn't have any backtracking. So no is the simple answer. It's closer, in fact, to tuple space. You know, what you're doing is you're matching on a particular thing and then generating, generating some output based on that. But it's tuple space with executable code. This kind of reminds me of Wolfram's, you know, cellular automatons, right? Just repeated tasks, complex things. Yeah, I mean, the cellular autonomy is basically a state machine. And that's fundamentally what this is. Or the Elm reduction model. Or the Elm reduction model, exactly, yeah. And that's, in fact, why Elm can do things like go back in time. Because it is exactly this. Okay, let's give him a huge round of applause. This was mind blowing.


Aw, snap. I don't know what's going on, man. I might have to restart my dang computer, booze. Hey, y'all, uh... Something's wrong in the neighborhood. Who you gonna call? Ghostbusters. What's going on, everybody? Man, this some Buddha chatter, yo!