 Welcome back to another screencast about functions, and this is another example that's going to instantiate some of the basic definitions about functions that we saw earlier. This example is going to involve integer congruence, so let's jump right into it. So this process I'm defining is called f, and it takes integers and turns them into other integers. Right now, again, I have not told you the rule, so right now I couldn't say anything about this function until I've specified what the rule is, so let's do that. The rule here, how I'm going to specify this, is that when I take an input n and run it through my process, what I'm going to return is n squared mod 4. That is, I'm going to square n and then look at its least non-negative residue modulo 4. So that will certainly be another integer for sure. And let's see how this works. So this is a process that's fairly well defined. Let's tick through our usual questions about this. Is the input set specified? Yeah, I told you what that is. We're taking integers as our inputs. Is the output set specified? Did I tell you what that is? Yes. That's going to be integers coming out of this function. And as the process specified, did I tell you what the function actually does? Yes. We take the input and return its square mod 4. Does every input actually have an output? Yes. This is more of a formula, and there's no integer that makes that formula to simply not compute. Does every valid input have only one output? And that's one we have to sort of think about for a second. The answer here is going to be yes as well. Given a single integer, first of all, if I square it, it doesn't square into two different things. Remember, we're trying to avoid situations where the input splits into two different things. That doesn't happen with squaring. And so it's not going to happen if I square and then reduce mod 4 either. So every valid input has only one, exactly one output here. Now that it's a function, let's talk about its domain and co-domain. Again, this is very easy if you just look back at where the function is defined. The domain is here and the co-domain is here. So both of those, in this case, are the set of all integers. Now, again, we're going to have a question later on about, okay, what's the difference between the co-domain and the range of this function? Can every integer actually appear as an output of this function? That's a different question, though. That's a question about the range. So here the domain and co-domain are specified to be the entire set of integers for now. Now, let's talk about this function, how it behaves. This is important because we want to get a feel, especially when I'm working with the formula, for how the function behaves and operates here. So let's try some numbers and just run them through. Let's make a little table for that just to see what happens here. And let's go with say zero and one, five, ten, maybe choose a negative number like negative three, just to try a few various outputs here. And so what I'm going to try to do is compute n squared mod four. I really think of that as almost two steps to this. So let's do n squared first and then reduce mod four. Well, zero squared is certainly zero and zero mod four is zero itself. One squared is one and one mod four is one. Five squared is 25 and looking at the non-negative, at least non-negative residue of 25 mod four, that's just asking what's the remainder when I divide 25 by four? Four goes into 25 six times with the remainder of one. So the output is one there. Ten, okay, it's square is 100 and that 100, so I'll write that here, and 100 mod four of course is zero because four divides 100 evenly. Negative three, it's square is positive nine and nine mod four is one. Now it's interesting that we only got zeros and ones out here. I'll have to think about that in a little while. But at least we understand now how images and how certain things behave here. What about pre-images of points in the co-domain? So let's just start pulling integers out of the co-domain, out of the receiving end of this function and see if I could put something in. Certainly I think we know that zero and one have pre-images. I could fill in the blanks here and find points in the domain that get sent to zero and get sent to one. And there are a lot of different choices. For example, zero will work for it to get sent to zero, and so does ten and one gets sent to one, but so does five also gets sent to one. It seems like there are a lot of possibly infinitely many points that are pre-images of zero, and there are infinitely many pre-images for one as well. Now what about something like two? Does that have a pre-image? We certainly didn't see to show up as an actual output. So it makes us wonder if there really is anything at all that I could plug in for f to give me two. Now we're going to leave that question unanswered for right now, at least we see the question about pre-images involves going to the code domain and to the full set of integers first and then working backwards to try to find points in the domain that I would put in to get that point. So zero and one definitely have lots of pre-images. Two, we're not so sure about. And I think anything negative would not because we have to square the number first and then reduce mod four. Now let's get on to that question about what are the set of all actual outputs of this function. Certainly zero and one are among that set, and we see that because we made the table over here and saw that zero and one occur as outputs here. Now what else could be outputs here? Well think about how the function is defined. f of n is n squared mod four. Now since I'm reducing mod four, the division algorithm gives me only a few possible inputs. The only things that I can get out of reducing something mod four are zero, one, two, or three. These are the only possible remainders here. So I know that for example the number 22 cannot be an output of this function because I cannot get 22 as a remainder if I divide something by four. So that makes us think, well maybe there are not a lot of outputs to this at all. Zero and one certainly are actual outputs. What about two or three? Could those occur as outputs of this function? It turns out the answer is no. And I'm just going to state this as a lemma that you can prove on your own if you want to. And that lemma just says that for every integer n, n squared is going to be congruent to either zero mod four or one mod four. You can run through the table that we saw over here with many other different values of the inputs and you'll find very quickly that no matter what you put in here, your outputs are always going to be zero or one. You never pick up a two, you never pick up a three. And that might make you think, well gosh, maybe that's true in general and that's what this lemma is saying here. So I encourage you and invite you to prove that lemma. And that would say that no matter what I put in for n, the square is always going to be zero or one mod four. So the upshot of this is that the range of this function is just the set consisting of zero and one, just a two element set. So although the co-domain is a gigantic infinite set of all integers, the range of this function only consists of two things, zero and one. And we only get that by playing with the problem again, our theme throughout this course. We understand problems by playing with them. So that's another example. Hope that makes sense. Thanks for watching.