 We're going to be going over the greedy plumber problem. This is something one of my teachers gave us in math class, I think yesterday and there are two solutions. There's the one I did which is terrible but it worked and there's the other solution which is the conclusion you're supposed to go to. So here's the problem. Let's say you're a plumber and there is a water line right here, this is a straight line and there are two houses. There's house A and it's to the north or above the water line and then there's house B which is to the right of house A and also above the water line. The question is at which point should the plumber put like a little pump so that the least amount of pipe is used? Now there's a simple answer to this that some of you might have thought of but I didn't think of that answer. I don't know what I was doing. I just did and made it the first thing that came to mind. I didn't really think too hard about the problem but anyway here is the first answer which is over complicated. So first we will need to define things so let's put this on a Cartesian plane. Let's make A, zero B at a point called zero A and the origin is just a horizontal line from A and where it crosses the water line which would be the x axis. And the house B would be located at point B, C and now we have the last thing which is where the pump is going to be placed so it would be x, zero. So what we want to do is we want to get an equation for what x equals. Now my solution is kind of brain dead. It involved using calculus which I'm not in calculus yet but this is just a but I knew what a derivative was so I looked up what derivatives did. Okay let's go back to our graph. We need to define this as a function so let's call this line A and let's call this one line B and so line A can be defined as the following using the Pythagorean theme. The square root of x squared plus A squared because this is the distance x, this is the distance A and now time for line B which can be defined as the square root of B minus x squared plus C squared. Now we just need to add these two and that gives us a function for how this is going to work. So at every point this function will look like this. It will look like some sort of this curve and the bottom point will be a valley. And in this point so what you can do here, oh I forgot to mention, this describes the length of these two together at point x, okay that's how, maybe that was obvious. And so the lowest point will be what you want to find and so how you get the lowest point is get the derivative, you get the derivative of the function you just defined. So D over dx, let's try, I'm going to have to write this again real quickly, square root of x squared plus A squared plus the square root of B minus x squared, okay and the lowest point will be when this equals zero, let me pause for a second, okay. So the lowest point will be when this equals zero. So we need to find a formula that leaves us with x equals and then it does something with A, B and C, okay. So first we need to find the derivative of this first thing and we're going to use the power rule and the chain rule for this. So f of x can be defined as you know the square root of x and we can find its derivative by instead of seeing the square root of x, we raise it to x to the power of 1 or 2 and using the power rule we define this as 0.5 times x then what's 0.5 minus 1 will give you negative 0.5. So x divided by 2 to the power of negative 0.5 and if you simplify that that will give you, that will give you 1 over 2 to the square root of x, that's f, that's f prime. Now next is g which is what happens inside that function. So g of x equals x squared, x squared plus A squared. Now since A is a constant it is ignored in the derivative, since A is a constant it does not affect the rate of change so we ignore this, I'm going to get rid of that because we're going to need this for later for the chain rule and so we no longer have an A squared. So now we just need to find the derivative of x squared which we can find using the power rule. So this would just be 2x because you bring this down here and you subtract 1 from 2 and you get 2 times x to the power of 1. Okay and now we can use the chain rule which says that if you put gx, if you put gx inside f prime and then you multiply that by g prime that gives you, that gives you the derivative of the whole function. So what this would be is 1 over 2, over 2 times square root of x squared plus A squared and now we multiply that by 2x and so these two cancel out and this x goes on top. So now your derivative is x over square root of x squared plus A squared. So let's get rid of all this work right here, move this here. Now we just need to find the derivative of this one. So again we do the same thing but this time g of x will be a little bit more complicated. Again in this case f of x is still the square root of x and we can get f prime like we did the other time. It's the same f prime that gives you 1 over 2 to the square root of x, not 2 times the square root of x. Now g of x is a little bit trickier but it can be done. g of x is the minus x squared and since c squared over here is a constant it can be ignored in this next one, we'll write this again, cleaner c squared. It can be ignored in the next one. So to find out what g prime is we now need to expand this one. Now if we expand this we would get b squared minus 2bx plus x squared. Now since b squared is a constant we get rid of that. Now the derivative of x squared like we said previously is just 2x. To find the derivative of this first we need to take the derivative of x which is since it's x to the power of 1 we just bring that down here, subtract this by 1 and that would just give you 1. That's the derivative of x. So this would be that derivative, 2x minus 2b. Let me get rid of all this work here, I think it's simpler. Hopefully you can't hear all that noise in the background, let's keep going. Now we just need to use the chain rule, f prime, put g of x inside f prime and then multiply that by g prime of x. Now I don't, this is all new to me, I just learned these rules like yesterday. So I don't know why this works, but I know why the power law works, but only for like whole integers, because that makes sense. But I don't know how the chain rule works, I mean why the chain rule works, regardless let's keep doing this. Now f prime, okay you get 1 over 2 to the square root and here's our re-insert gx which would be b minus x squared plus c squared, the square root of b minus x squared plus c squared, okay. And now we multiply that by 2x minus 2b, it barely fits, okay, 2x minus 2b can just be simplified as 2x minus b. These two cancel out and this goes on top and so the new, the derivative of this now would just be x minus b over the square root of b minus x squared plus c squared, okay now let's get rid of all this work, hopefully you understood this because I had to, I'm gonna move this here and now this is the whole derivative. Now we just need to do some algebra to get x alone for this equals 0, I'm gonna do a time lapse, I'm gonna do a time lapse of me solving this in either k algebra or Desmos, probably Desmos. Okay and so here we see that the simplified version of that derivative equals 0, we'll give you x equals ab over c plus a, wait I'm gonna rewrite that to a plus c and it works no matter how you move it. So let's go record that back into the white board and now it's time for, wait, ab is ab over a plus c, okay it was ab over a plus c, that was x, that's where our pump should be placed. Now it's time for the really smart guy solution, the solution that only really smart people know how to do, or like the simple solution that didn't require me learning high school level calculus. So it's pretty simple, you take what we had before, here we go, okay I'm gonna try to redo this, you take what we had before, you get point a, okay and the argument goes like this, if you move point b to the opposite of where it is, remember b is in point bc so therefore if it were here it would be in point b negative c, okay if we did that, if we put b in that placement, yeah I'd say it's just not being good for you, okay if we put it that way the argument is that the distance between a and then this would be actual b, this would be the negative b, that the distance between these two and this way would be the same and you can prove it, oh let's take the one that was here, which was the square root b minus x squared plus c squared, okay and you can prove that because negative c squared still is always positive and the same goes for c squared, okay here's a proof, negative c squared equals c squared so it doesn't matter if it's this way and then it uses another geometric property which is just, which is a very simple property, it's just that a line is the shortest path between two points and so if you had your pump over here this would not make a straight line, so how do we know, so the pump would be where these two lines, when this line hits the x axis, okay so how do you define that, you get an x, that's your slope, slope of one, it would be what's the rise over run here, the rise would be negative a plus c and the run would just be, well b, run would just be b, I'm pretty sure, oh yeah, this would be, this would be the slope and then you just have to add, you just have to add a to it, okay that would have to be equal to zero, this is where the pump would go, now it's just a way simpler algebra problem instead of having to do whatever this was, okay, you put this, let me get rid of, yeah I'm just gonna make a new layer and okay x negative a plus c over b, okay, okay it was x negative a plus c over b plus a equals zero, okay this would look like x, let's just do normal algebra here, take a little bit, sorry for the dog, okay now we multiply this by b, so b gets canceled, now we got x equals x times negative a plus c, it's getting worse, equals negative a b and so now we just divide these two by each other, let's just take that real quick and a negative divided by a negative, those two would negate each other and you would get to the same answer a b over a plus c, this is the same answer, this is the same answer we got the other way, was it, yeah that's the same answer we got previously, that's just, that's all I'm gonna say, that makes me sad, I spent like two hours learning these calculus rules and then and then like and it just took five minutes after learning this, after learning how to do this, hey but at least I got to learn a little bit of a little bit of calculus, okay I think that's it, okay so this is both a reflection and a correction, first the correction, it wouldn't be wouldn't be a b over a plus c for the for this equals zero, for the derivative equals zero, it would be x equals a b over a plus the absolute value of c because of the discontinuous properties of the square root, what else, oh yeah the lesson I learned, I guess it's the main lesson you can get from this is work smarter, not harder, the calculus, the calculus part of this video is like 14 minutes long and the algebra, the algebra side was six, eight, I don't know, that's all, that's all I had to say, it was probably never gonna have anything to do with calculus since it was a pre-calculus class, the teacher was just trying to get us to think out of a box and I guess this was out of the box, gonna play around with this a bit more