In this video, we're going to see how we can use lists together with common operators. So let's create a new file. Let's call it ListOperations. So whenever I speak of an operation in my course, then I typically mean that we use some operands and connect them together with an operator like PLUS, for example. So let's make an example. Let's create a list of names, just as we did in the previous video. And let's put in there the names, for example, Bertolt, German name, but also Oliver, also German name, but also international name, of course, and Karl with a C. So now we have a list with these elements as strings. In memory, this would look somewhat like this. So we have a list object, and by now we know that list objects have a little bit more space in them because that allows us to append some stuff at the end without having to create new list objects. Now let's go ahead and abbreviate that a little bit. So the first element, for example, would be Bertolt. So it would be a string object. I simply write it here as B. Let's go ahead, create another string object here, and let's take another string object here, this would be C. And we call the list names, so let's simply go ahead and make a variable called names from the global scope, simply reference the list object here. So what could we do here, using operators? So one thing that we have already seen in chapter one is that we can take a list and we can add to that, for example, another list. So that may strike you in a weird way. So how can I add lists together? Does that even make sense? So let's use a second list and let's put in the names, for example, Dietrich, and another German name, which would be Yves, here just to have a variation of a couple of names. And the answer to the question, can two list objects, so the list names and the other list object here, can they actually be added together? And the answer is yes, and what we get back is another list object here, with now five elements in there. So when I executed this cell here, names plus a new list, Dietrich and Yves, let's see how that looks like in memory. So first of all, Python reads here from left to right, therefore it reads the variable names first, this is simply a reference lookup, then it says plus, and then it has to, on the right hand side, first create a new list object on the fly, and on the fly simply means we create it without giving it a name. So let's go ahead and create another list object here, on the fly, so to say. And the first element in there would simply be Dietrich, so let's abbreviate that with a D, and the second one, the second element would be Yves, so let's abbreviate that with a Y. Now we have two list objects, and now we are concatenating them, that is the technical term concatenation, we've also seen that when we talked about the string data type in chapter six, so I'm now going ahead and I want to add this list with this list here, and what Python does is, the list, the addition operator, it simply goes ahead and asks the left hand operand, so this list here, hey, can you add yourself to this one here? And then the list object says, well, this is also a list, I know how to do that, and then the two of them go ahead, and what they do is, they are going to create a third list object, and now the third list object will be created like that, the first element will be the first element from the left operand, so we will simply get a reference to here, then we get a reference here, and another reference here. The same holds true for D and Y, so we get references right here, however, these are not the first and second references, these are here references four and five, right? And now this list object here is basically the return value that is given back to us, so I indicate that with a red dotted line here, so that is what we see below the cell, and I could have stored that in a variable, maybe let's do that and call that moreNames equals, or set it equal, or assign to it the result of that, and now moreNames would be this longer list, and that would mean we create a new variable here, let's call it moreNames as we did in JupyterLab, and put a reference right here, so whenever you remember that from the very first chapter, whenever I put a red dotted line going from right to left, it simply means we get back a reference to this object, and then it depends on us what we do with the reference, here I store it in the variable moreNames, and now this list object is going to survive, and this list object here is not going to survive because it has no further reference going to it, so therefore the garbage collector is going ahead and will simply remove this list object here, and the references, these two string objects however, they are going to survive, and they have a reference from this new list object. So what do we learn from that here? So first we can add two list objects together, we call that concatenation, and also what we see here from the diagram I drew is concatenation also is very much similar to the concept of a shallow copy, so now we have the old, the original names list with three references, and we have a new list here, moreNames, with also a couple of references, and these three references reference objects that are also referenced by the names list, right? So these three objects here, they are shared between the first and the second list, and that is similar to the concept of a shallow copy that we saw a couple of videos ago, okay? So let's continue, what other operators are there? Well, just as we did with string concatenation in chapter six, well there's also a multiplication operator, so let's say I say two times names, and I get back Bertolt, Oliver, Karl, Bertolt, Oliver, Karl. So how does that look like in memory? So how that looks like is as follows, a new list object is created on the fly, just like that, and now let me maybe use a different color so that you can still recognize where something is going. So the first reference is of course going to be because that is the first reference of the original names list and I'm multiplying two times names here, so that is why we take all the references from this list here. So the second reference is going here, the third reference is going here, and now you may wonder where is this reference here going? Well, this reference is of course also going here, and this one here, and this one here. So now we have those three objects here, B, O, and C, the string objects, they have now many references going to them. So that is what happens here. So when we multiply a list, we get back a new list object where the references are taken from the list object that is being multiplied, and then the references are simply repeated. So what we learn from that is that Python is a very memory-efficient language, so all the operations in this video that we saw so far, but also the example I showed you in the video Shallow vs. Deep copies, they show you that whenever it's possible, Python does not copy the actual data object, so data objects meaning the string objects here with the actual data in it, so whenever Python can do so, it simply goes ahead and copies all the references, and nothing but references. However, this is also similar to the concept of a shallow copy, so we must be careful here. Let's assume that B, O, and C were themselves mutable objects, so they are string objects, they are immutable, but let's assume that they are mutable. So what would that mean if I change, if I went via this variable here to the first reference here and I made a change to that object here? Well, I would also see the same change in the fourth spot here, in index number three, right? Because index number zero and index number three are really pointing to the same object. So whenever these objects here, the data objects, they are immutable, and the most important immutable data types that we know are of course the string data type, but also all the numeric data types, then everything will be fine because we can never make a change to that. However, if we use a NASA data structure, and we have, let's say, a list here, or maybe some other data structure that can be mutated, then we have a big problem. If we make a change via the first reference, we would see the very same change via the fourth reference here, right? So we have to be careful here. And this all goes back to the video shallow versus deep copy. So if you understand shallow versus deep copies, then you should also understand everything that is right here. And all the details that I'll show you in the videos, as a beginner, most likely you're not going to need to know that, but after a while when you write bigger programs, you will run into problems where some outcome of some algorithm is not what you expected to be. And then one fun thing you should have in your mind is that Python at many places makes shallow copies or things or operations that are comparable to a shallow copy, so copying only references and not the data themselves. And whenever that happens behind the scenes without you knowing, then maybe that could be a source of a semantic error in your programs, right? So I want to plan that in the back of your head if you want to continue to become good at Python and maybe want to go into a data science career, then you should really focus into these details as well because at some point not knowing that will bite you. Okay, so let's see what else is there to be said. So of course, obviously we could also multiply names from the right and not only from the left with a number. So now we repeat the same elements three times and that is the two operators plus and multiplication that are supported not only by numbers, but also by sequences in general or in abstract terms. So remember how concatenation also worked for strings and now it also works for lists here and that is not an accident. The reason why concatenation works for both strings and lists is simply because both strings and lists are examples of sequences. Okay, the abstract data type or the abstract concept of a sequence is basically what is behind all that. So concatenation works for sequences in general usually and lists and strings are simply examples of a sequence and therefore concatenation also works for these data types. Now let's look into something that is not strictly speaking an operator but that looks like an operator and that is very valuable to know and you will see it all the time in Python code. So this is, let me give it a new header, unpacking and there will also be the opposite of that called packing in future video. So what is unpacking? So let's assume you want to create a new list and the new list is going to be a list of names because it's just the example here. So let's say the first name in the list is going to be Achim, a German name and the last name will be Xavier. That's probably an international name also works in German. So now let's assume that what you want to do is you want to put the names from the names list so the names Bertolt, Oliver and Karl you want to put these three names inside this list here. Well what you could do of course what we saw in the previous video you could simply refer to the names list here. However then we don't have a flat data structure we have a nested data structure, nested meaning some elements of the outer list contain a reference to some inner list that itself contains the data. So that is a nested data structure but what we want to do instead is instead of creating a nested data structure I want to do the opposite I want to create a new list with flat data here a programmer to use the term flat what they mean is they mean that there is only one object one container that holds all the references to all the data objects in a flat way. There is no hidden layer where you have to grab into in order to get to some deeply nested data piece. So how can we do that? How can I get rid of these lists here? This list syntax here. So there is a syntax in Python called the unpacking syntax and we will simply write star operator here on asterix. So these star names see maybe I leave that here in as an example so that you can refute later and maybe also see the difference right away if I put the star right here what you see now is that we have the same names in one list object but there is no inner list object. So we have flattened the data and in a future exercise I think it is in chapter 9 when we once we talked about mappings there will be an exercise in the book where one of the tasks is you are given nested data and you have to make it flat and what we mean by flattening the data is by simply making sure that you only have one container object that holds all the data in a flat manner. And strictly speaking this here is not an operator this is some literal built-in syntax that looks like an operator but it is not comparable to a star operator in this context here in this context having a left and a right operand that is when the star operator is really an operator but written in this way this is really not an operator but the unpacking syntax but it's just a minor detail don't worry about that I just put it inside this video because it looks very much the same and it's worthwhile to know you often see that when you call functions and you want to unpack let's say some container and you want to pass the arguments in a flat way then you often see that in function calls for example but we will see that in future videos a couple of times so just understand that this just unpacks the data in the container okay so maybe another way for those of you who still don't get this is to write it in a manual way so to say so this is the same so this line here is the same as if I use the index operator just like that so let's copy that let's copy that like that and let's copy it one more time this would give me the same result however often times when you work with lists like data you don't know how many elements are in a list so here I know that there are three names in the names list therefore I can fully enumerate all of them by saying names 0, names 1, names 2 but sometimes the list has like a million entries a million elements and then you couldn't write that with your hands so this is just a manual so to say way of writing everything out but the unpacking syntax basically does that here for you it basically automates the indexing here so worthwhile to know so now let's finish this video by talking about another operator or another set of operators namely the comparison operators that we saw the first time in chapter 3 when we talked about the so-called relational operators relational operators are all the operators that compare a left and a right operand and that also works in the context of lists of course so let's do the following I'm going to use my names list ideally and let's copy paste what we see below the cell here and let's go ahead and let's take the names list and compare it regarding equality to what I just copy pasted here and maybe if you want replace the single quotes with double quotes as you know that I personally prefer the double quotes but you could also simply leave the single quotes wouldn't make any difference so now we get back through why because I have a list on the left hand side and I created a new list on the right hand side on the fly and both lists contain the same elements or elements with the same value that is important in the same order okay and if that is the case then both lists compare equal let's go ahead and check what happens if I add another element here on the left hand side let's say I go ahead and I add Carl with a K and now I get back false why because the list on the left hand side obviously has not the same number of elements than on the right hand side and then therefore the elements are just different also if I go ahead and compare names to the actual names list here and I change Carl with a C into Carl with a K I of course also get a false okay now let's look at another operator this is now equality comparison but let's also look at a couple of others for example just to remind you that it exists the unequal operator in python we are going to write that as exclamation mark equals this is now going to return the opposite of the of the equality comparison operator since that here was false this here must be true because it's the same expression and the only difference being instead of equality we are checking for inequality so these are the opposite cases and now you may wonder how do the smaller than operators work in this context well let's do that let's copy maybe this cell here and let's go ahead and ask the question is the left hand side smaller than the right hand side and intuitively this is true and the reason why is because they are all equal except for the last entry here and if the list on the left hand side contains an entry all the entries are the same on the right hand side except for it does not contain all the elements then it is smaller but also note how let's copy paste that instead of comparing that to a list with more elements I compare that to a list maybe let's put names above here one more time so if I compare the names list with a list of the same size but Carl here is not written with a C but a K then this also gives me back true why? because Python would go ahead from left to right and compare a bearthold so this bearthold with this bearthold and this Oliver with this Oliver compares Carl here with a C with this Carl with a K and Carl with a C let's also write that here Carl with a C is smaller than it is strictly smaller than Carl with a K because of how string comparison works and therefore because of that result the entire list is also considered smaller than the other list here okay and of course if you do that the other way around so let's maybe do another example let's copy this list here and let's say as the question is that smaller than Carl or the names list that has the Carl with a C in it now we get back false why because Carl with a K is now not smaller than Carl with a C right? it's it comes after Carl with a C so that is also how you can use comparison so the exact rules of how these operators work are exactly the same as we saw in the chapter on string comparison so first of all in other words to summarize that Python takes both sides the left and the right hand operand and it goes in a stepwise fashion it compares element by element and once the first pair of elements when comparing in a pairwise fashion is not equal then a decision has to be made whether or not the left hand side is smaller or greater than the right hand side and the decision that is made will be done according to basically the rule that has to be applied when the two objects are simply compared to each other so and then in the rare case where all the elements are equal and let's say one of two lists has one more element then automatically the list that has one more element is considered greater it's intuitively so this is how we would interpret this sign here this symbol in an intuitive way just as well okay so that is operators so relational operators work for lists a couple of arithmetic operators work for lists as we saw they do concatenation please keep in mind that the way this concatenation is done follows the same logic as we saw in when we talked about shallow copies and also the unpacking syntax here is quite nice to know it's not strictly an operator but you could actually view it kind of as an operator here okay so that leaves us here with this video when we talked about list operators and operations and in the next video we are going to see further details about what to look out for when working with list objects so I see you then


What's up everybody in the mangos, you were awesome and Sereth got herself a new skin in over prime. And in true, soley fashion, it's a little cheeky. I personally don't play much Sereth, but I've seen her wreck teams a few times so I kinda want to learn her and a bit of side cheek is all I need to pick up a new hero. I won't be commentating this match like I usually do because I just flat out don't have her figured out yet. Just like countless though, I'm going to keep playing her till I do. Like this video if you enjoy it, sub for more 3rd person Mova content, but for now let's get to it. Being buffed or at least kind of put back to how it was, she might be strong in mid and support again or even off lane possibly. I actually think off lane maybe more because I tend to go against more melee's so you can keep the link longer. Might be worth it going. Oh, you're going to have a fun lane, you're going up against this sparrow or at least this sparrow went into that lane.  And I already forced this guy to AFK. Literally legitimately just AFK'd. It's so funny.  That was a wrong idea sparrow. Oh, he's back. Okay, so maybe he actually got legitimately DC'd. Or he didn't want the penalty.     I've really got to focus up on these last hits now, dude. Mm-hmm. I'm annoyed by that. I was trying to poke under tower and I walked, like put a foot basically within tower range and the sparrow stunned me as I got tower aggro so I died. So that was a bit of an annoyance to say the least. I feel so slow. I hear you there. He's coming to your side. Yeah, a lot of company mid lane, huh? Yep. Coming over. Okay. I'm good. Yeah, they're leaving. Punishing him pretty hard. So it's not a surprise that they're coming to help him. Mid severog, you know. There's Kongs over there. I'm going over there as well. He got back in the lane so fast. Ooh, okay. That was aggressive of our team to go under tower. Seb's on his way to you guys. It's been safe. It is safe. The ally tower is under attack. Should have went into pen first. Oh well.   Okay. Yeah, I'm coming. Actually, our jungle is not... Our carry's there though. Doesn't seem like it'll matter. He gets away. Just gonna back.   Enemy tower is under attack. Oh man, I know a blamer. Smart play from her. Very frustrating for me. Defeated by a sublime enemy. Has been summoned by an enemy. The ally tower destroyed. You're very much by yourself. Our carry's in a three for that though. Are they on major prime? Yeah. God, I should have taken smite. Mm-hmm. I'm on my way to help, but this is... Risky at best.   I did. I did with my... Right click.  Yup. Faye is still strong in teamfights, baby. She might not be as strong in... In lane anymore, but she definitely still carries teamfights. I mean, that's the whole point of the... People keep calling it a nerf. It was just a redistribution of the damage. It was not a nerf. They did not nerf major. Enemy tower is under attack. Well, I mean, it nerfed the early game and forced them to be more of a late game, right? Yeah, nerfed the early game, buffed the early game. Like, it had a redistribution of damage. Yeah. Well, I think the late game is still lower than it was. Right? Like, their scaling is still... Better late than early, but I don't know. It is what it is, either way. I definitely don't... Good.  Jesus. I thought you were going to say, thank god they all trickled in one at a time instead of... There's three heading that way. Yup. She might just be fucked. Or have ultimate or anything. I actually think the item... nerfs are probably the worst for mages. Which had a better idea.  The timer on the... portals. Like, just by looking at the map. Yeah, instead of the... 115 seconds or whatever, nonsense. I want to catch my lane, but it looks like everybody else was to fight. I mean, I'm just keeping the pressure mid. If a fight happens, we're here behind you guys. Fuck!  The enemy inhibitor is under attack.  Planes are pushing against us. Careful you're there by it with two. Ooh! I'm coming. He peed after you. Almost got him. Got him. Two for one. Not that bad, I guess. Not ideal, obviously, but... Looks like Arzina is about to disconnect. Why? Ah, she was just lagging crazy on my screen. Oh. Three, man, I believe. Set the slow push left. Yeah, they're getting frustrated not having lunch to go off of in mid. Oh, he's fighting. Oh, you're fighting. I'm here. You got me. We got him. Arzina's A-of-K. I don't know if we can do this, but... Oh, we got it, barely. They tried to steal it with... What's his name? Yeah, I was watching the whole time. I need something to heal up off of. Does he get out? So far, so good. Had a blink, but we take those. Our jungler's probably dead there. I didn't realize they got our tower. Behind you is, uh... I don't know who to help. Me, obviously. Oh, holy... Always me, Mangoos. Always help me. If you want to start that, I can come and help you DPS it down. Wukong's like right here. Oh, okay. I'm on my way. Do you beat him now? That's the question.  Ah, it's close. I'm coming. Sounds like somebody else is coming now, too. Yep. I'm out. I almost died. That was close. His foreshot, man.  Oh, he almost saw me. He didn't check the bush. What is up with people never checking the bushes? It's so weird. His crowd's on their way also. Our support is left by himself. Oh, no. You have, uh... Swank. Uh-huh. They need it, though. Yeah, definitely. Apparently not. Like before, I could see what the health was. There's no tower there. Yep. Not bad. You're good. That's how it would have gone in. Yep. That's all good, though. I'm also just wanting to keep the pressure so we can actually start working multiple lanes here. If you guys could push up that right lane. I could take somebody into the shadow realm. He took me. He took me. I killed him, though, I think. Yep, I do. I'm being focused. Yep.  Yeah. Our jungler is literally never with us when it's time to fight.  And now we're not going to have anyone unfortunately to defend it. That's a bummer. Dude, just get out.  Oh, I see the new inhibitor. I can get all three inhibits. Oh, come on.  Let me back in. Wow. Fuck! Bang! Go!


I am Colour Sergeant Ben Goodchild. I'm from the First Italian Culture and Guards and I'm currently working with the Royal Military Academy Sandhurst. They're currently on Exercise Dynamic Victory, which is their final exercise before commissioning as an officer. That's broken down into two parts. This part here is the life-fire and tactical training part of the exercise, which is based more on planning and orders, delivery and testing their leadership. It's a life-firing range and it's planned in a way that allows them to either go right flanking, left flanking or a full frontal assault. It gives them the freedom of movement to execute a low-level plan whilst firing live ammunition and live grenades. My name's Tom Allen. I'm an officer cadet in the senior term of the Royal Military Academy at Sandhurst. So the experience so far has been really, really good. The training facilities have been an absolute top notch. We've been able to really put into practice on some good facilities the skills and drills that we've learned back in the UK. Certainly the life-fire aspect really helps to sharpen the skills with live rounds going downrange. Everyone becomes a lot more focused and there's an added element of danger as well with the grenade throwing at the very end, which is something we haven't really experienced much of back at Sandhurst. So it's a real good opportunity to put into practice the sort of training we've had over the last year with live rounds going downrange.


This lecture is part of Berkeley Math 115, an introductory undergraduate course on number theory. And it will be about solving equations like fx is congruent to zero, modulo p, where p is a prime modulus. So just as background, we would recall that we've considered equations fx is congruent to zero, modulo m for m and arbitrary number. And we first showed that we can reduce the case when m is arbitrary to the case when we're working modulo p to the n using the Chinese remainder theorem. Next, we can reduce the case of working mod p to the n, the case of working mod p most of the time using Newton's method or Hensel's lemma. And so the third case is the case when p is a prime. So if we can solve the case when p is a prime, then we can sort of solve the case working modulo any number. And this lecture will be about this case here and previous lectures were about the other two cases. So how can we solve modulo p a prime?  And this is fine if p is small, less than about 10 if you're doing by hand or maybe less than a million or a billion if you're doing it by computer, but it's quite hopeless if p is really large, maybe p has 100 digits in it or something and this would take far too long. So we want to find some methods for solving this equation, even when p is a really large prime. Well, let's start by looking at some advantages of p being prime as opposed to an arbitrary modulus. So the first example is there are no zero divisors. So a zero divisor is something that divides zero but isn't zero. So what this means is that if a b is common to zero modulo p, then either a is common to zero mod p or b is common to zero mod p, which is very useful. We recall that this definitely fails if p is not prime. For instance, two times three is common to zero mod six, but two is not common to zero mod six and three is not common to zero mod six. So it's sort of very disconcerting to have a product of two non-zero things that can be zero. The next nice property is that inverses exist, at least provided something is not zero. So if a is not common to zero mod p, then a b is common to one for some number b. And remember, we can find b quite rapidly using Euclid's algorithm or something like that. And of course, inverses obviously don't exist modulo six because two doesn't have an inverse, for example. These two properties are very closely related. In fact, if inverses of non-zero elements exist, this immediately implies there are no zero divisors. Another nice property is that polynomials of degree n have at most n roots. You sort of may remember this from high school algebra and you may think, well, we know that all polynomials of degree n have at most n roots, but it's actually not true if you're not working modulo a prime. For example, we just recall that x squared minus one mod eight has four roots, one, three, five, and seven. So if you're not working modulo a prime, then usually polynomials of degree n may have an unexpectedly large number of roots, which is, again, rather inconvenient. Next, we've got Fermat's theorem, which says that x to the p is congruent to x mod p. And this is one of the absolute basic results in number theory we use all the time. And you may say, well, if we're not working modulo a prime, we've got Euler's theorem x to the phi of m is congruent to one modulo m. But this just isn't as easy to use. I mean, we've got to start using Euler's totient function, which is a little bit messy, and being able to raise things to the power of the prime p makes life so much easier. And another advantage is primitive roots. So primitive roots exist modulo p. And I'm not gonna say anything very much about primitive roots this lecture, but we'll be covering them in a later lecture. Anyway, this is another big advantage of primes that we have primitive roots. So let me first say a little bit more about why the polynomials of degree n, if this is a polynomial mod p, has at most n roots provided p is prime. So in order to understand why we need p to be prime, let's go through the usual proof of this and see why it works for p prime and fails if p is not prime. So suppose we've got a polynomial fx of degree n. And suppose a is a root. This means f of a is equal to zero. Now, what we do is we take f of x and we divide it by the polynomial x minus a, and we get g of x plus some remainder r. So we can always divide a polynomial by some other polynomial of leading coefficient one, and we get a quotient and a remainder. And now if we put x equals a, we have f of a equals a minus a times g of a plus the remainder. And this is zero because a is a root and this is obviously zero. So r equals zero. So f of x is equal to x minus a times g of x. So whenever a is a root of a polynomial, the polynomial is divisible by x minus a. And now we can try and show that f has at most n roots by induction. Well, we know g has at most n minus one roots as the degree of g is equal to n minus one and we're applying some sort of inductive hypothesis to g.  And this is the key point of the proof because this step here, we're using the fact that there are no zero divisors, modulo p, I guess. And so if there are zero divisors, we can't conclude that b must be either a or a root of g. Well, obviously if b is a or a root of g, this immediately implies there are at most n roots of f. So polynomials to the degree n modulo p have at most n roots. And let's just see this step actually failing if we're not working modulo of prime. So I suppose we take f of x to be x squared minus one and we work mod eight. Then obviously there's a root, which is just one. So we write x squared minus one is equal to x minus one, x plus one. But the problem is if this is zero, it doesn't imply that one of the two factors is zero. For instance, if we put x equals three, we get factor three minus one times three plus one. And this is not congruent to zero. And this is not congruent to zero, mod eight of course, but this product is congruent to zero, mod eight. So we found a new root of x squared minus one that isn't a root of either of its factors. So let's have a look at a particularly important polynomial. And look at its roots. So let's take the polynomial x to the p minus x. And we know it's roots by firma. So the roots are just zero, one, two, up to p minus one, mod p. Of course anything else is a root, but these are the p distinct roots modulo p. So as before, we can take this polynomial and divide it by x minus a root. And we see that it's divisible by x times x minus one times x minus two all the way up to times x minus p minus one because these are all distinct roots. And now we notice that these polynomials have the same degree and the same leading term. So they must actually be the same. And we find extra p minus x is congruent to this modulo p. And now we can get some nice identities by just expanding this out. So let's first do a few explicit examples. So we have x times x minus one times x minus two is equal to x cubed minus three x plus two x. So this is p equals three. I guess I should do the case p equals two with x, x minus one equals x squared minus x. So this is p equals two. For p equals five with x, x minus one, x minus two, x minus three, x minus four is equal to x to the five minus 10x plus 35, so 10x to the four plus 35x cubed minus 50x squared plus 24x. And we notice that a lot of the coefficients are divisible by p. So this coefficient is divisible by three. These coefficients are divisible by five. And if we go on like this, let's do the one more case, x, x minus one, all the way up to x minus six. And this is equal to x to the seven minus 21x to the six plus 175x to the five minus 735x to the four plus 1624x cubed minus 176x squared plus 720x. And again, if you're really good at mental arithmetic, you will have noticed that all these numbers are divisible by seven. And these two aren't, of course, because those are the ones that are the x to the seven minus x. And how do we calculate these coefficients? Well, if we expand this out, we see all these coefficients come by adding up various products of the numbers here. So for example, this 10 is one plus two plus three plus four. And I guess I should have a plus zero. This number 35, we get by adding up all products of pairs. So zero times one plus zero times two and so on. See these zero times something are a bit silly.  And the 50 is going to come from, I'll miss out the ones with the zero and I'm getting bored of them.  So if we multiply this out explicitly, we see we get x times x minus one all the way up to x minus p minus one is equal to x to the p minus sigma one x to the p minus one plus sigma two x to the p minus two minus sigma three x to the p minus three all the way up to plus or minus sigma to the p minus one x plus zero because the sigma p is zero. Where sigma p is the sum of all the products of, sorry, sigma i is the sum of all products of i of these. So for example, sigma one is equal to one plus two plus three. So I should have a plus zero and sigma two is equal to zero times one plus zero times two plus one times two and so on. And sigma three is all sums of one times two times three plus one times two times four and so on.  So in fact, sigma p minus one is just p minus one factorial. Well, all of these things are just congruent to zero mod p by what we said earlier. This one must be congruent to minus one mod p because it's the coefficient of x in x to p minus x. At least if x is odd, if x is even, this is actually also true but you sort of think slightly more about it. So we in fact get another proof of Wilson's theorem that p minus one factorial is congruent to minus one mod p, so this is Wilson's theorem all over again. So you can think of all these others as being a sort of variation of Wilson's theorem except we've got some slightly more complicated sums and they're all congruent to zero. So we can give an application of this to something called Volstein-Holm's theorem. Actually, there are several slightly different theorems called Volstein-Holm's theorem. So I'll first do the sort of easy in fact rather trivial case of it and then I'm a slightly more interesting one. So this is the one where you look at the denominator one plus a half plus a third all the way up to plus one over p minus one. And Volstein-Holm's theorem says that the numerator is divisible by p. Well, we should start off by checking this for a few small values of p. So let's try p equals two and this sum is one over one plus, oops. Well, this is just one and the numerator of this is certainly not divisible by p. It's odd not even. So, so Volstein-Holm's theorem seems to be wrong in the most silly possible way. Well, that's because I missed out a condition it's divisible by p if p is greater than two.  It looks as if I just sort of randomly added the simplest possible condition I can think of to avoid the obvious counter example. Well, let's check it for a few other cases just to make sure I haven't forgotten any other conditions. So for p equals three, we get one plus a half which is three over two. For p equals five, we add up one plus a half plus a third plus a quarter which is 25 over 12. For p equals seven, we get 49 over 20 and for p equals 11 we get 7381 over 2520 and so on. And you notice this is divisible by three, by five, by seven.  So this theorem does seem to be okay. And now let's see why it's true. Well, that follows easily because if we take one plus a half plus a third plus one over p minus one we can expand this out. So it's one times two times three times p minus one on the bottom. And then on the top we've got one times two times all the way up to p minus two plus one times two all the way up to p minus three times p minus one and so on plus all the way up to two times all p minus one. So we've got all the sums of p minus two of these. So this is sigma P minus two, and this is sigma P minus one. And we know that sigma P minus two is common to zero mod P if P is greater than two. Because if P equals two, this is the sum of the zero. This doesn't work. Um, incidentally, there's another somewhat easier way of proving this. What we do is we look at all these fractions modulo P and we see that the numbers one, a half up to one over P minus one are all non-zero numbers modulo P. Because if you take all the numbers, non-zero numbers modulo P and then take all their inverses, you've again got all the numbers modulo P. So these are all congruent to one, two, three up to P minus one in some order. I don't mean that half is congruent to two and a third is congruent to three.  What I mean is a half is congruent to one of these numbers and a third is congruent to another one of them. So one plus a half, plus all the way up to plus one over P minus one is congruent to one plus two plus P minus one, which is equal to P times P minus one over two. And this is divisible by P if P is not equal to two, because if P is equal to two, this factor of two on the bottom cancels out P. So that gives us second proof of the easy version of Volstein-Holm's theorem. Next, if we go back and look at our calculations, what we notice is that we've actually got something a bit better because we notice that this thing here is actually divisible by five squared. And this thing is divisible by seven squared. And think about a bit, this is divisible by 11 squared. So the numerator is not just divisible by P. It's actually divisible by P squared. And this gives us the sort of better version of Volstein-Holm's theorem. The numerator of one plus a half plus one over P minus one is divisible by P squared. Well, of course, it's enough to show that the numerator, instead of doing the numerator being divisible by P squared, we can, all we need to do is to show that sigma P minus two is divisible by P squared because the numerator is this time, something co-pront of P. So let's go back to our polynomial F of X, which is X minus one up to, all the way up to X minus P minus one. And we're going to put X equals P.   And now we notice that sigma P minus one is just equal to this term here, P minus one factorial. So all this bit here is equal to zero. And now we notice that this bit here, everything except the last two terms is divisible by at least P cubed because we've always got P to the three or something there. So we find that sigma P minus three P squared minus sigma P minus two P is divisible by P cubed.  Well, sigma P minus three is going to be zero mod P if P is greater than three because all these all these sigmas were zero and less the subscript was zero. But if P is three, then this is sigma zero, which is not divisible by P. So this gives us sigma P minus two is congruent to zero modulo P squared if P is greater than three, which is what we are trying to show. It shows the denominator is divisible by P squared. So now that we've looked at the polynomial X, the P minus one minus one in some detail, let's look at the following general problem. Given a solution FX is congruent to zero, mod P, we have the following problems. Does it have solutions? So for instance, we might ask, does X squared is congruent to minus one, mod P have any solutions? Are there square roots of minus one? In this particular case, we saw that was true if P is congruent to two or one, mod four. Secondly, we can ask how many? And thirdly, we might want to find them. So these are increasingly difficult problems. And what I want to do is to start on showing how to solve these reasonably faster. Of course, all of these problems are easy to solve just by trial and error provided P is small. The real problem is try and solve them and P is too large to just check every possible case. Well, there's one neat way to find the number of solutions. Let's take the greatest common divisor of F of X and X to P minus X. So you remember this is X times X minus one times X minus P minus one. So the greatest common divisor will just be the product of X minus A where F of A is equal to zero. So the greatest common divisor will just be the linear factors of X to the P minus X that divide F of X. So we can find the number of distinct solutions is just the degree of this. So how many solutions, the number of distinct solutions is just going to be the degree of the greatest common divisor of F and X to the P minus X. So that's rather neat because we can find it how many solutions there are without actually finding them all. So let's do a rather trivial example. So let's do the number of solutions of X cubed minus X squared plus X minus one mod three. And of course, mod three, it would be faster just to check zero one and two to see if there's solutions. But I want to show this more an example of this more general method. Well, we just take the greatest common divisor with X cubed minus X.  So we're using Euclid's method. So we take this polynomial, divide it by that and take the remainder, which is X squared plus X plus one.  And we have a remainder, which is minus X minus one. And then we take this X squared plus X plus one and we write it as X minus one times X minus one. And now there's no remainder, so we're finished. And the greatest common divisor is X minus one. And now we notice the degree is equal to one. So there is one root. Notice this won't detect multiple roots. If a polynomial has the root one three times, that will still only count as one root because X to P minus X only has single roots. Well, at first sight, this seems to give a neat method of finding the number of solutions. At second sight, to set your eyes, it seems to be useless because the time taken to find the greatest common divisor of two polynomials, F and G, is something to do with the degree of F plus the degree of G number of steps because each time you divide a polynomial by another, you're going to reduce the degree by one unless you're really lucky. And the problem here is that the degree of X to P minus X is P, which might be huge. So if P has 100 digits, you don't seem to, I mean, taking the greatest common divisor of X to P minus X is going to take about 10 to the 100 steps. And this is no better than just finding the roots one by one. Fortunately, there's a cunning method of speeding things up. So we want to speed up finding the greatest common divisor of X to P minus X and F of X. And how can we do this? Well, the key point, although the degree is huge, this is a sparse polynomial that most coefficients are zero, in fact, all but two of them are zero. And if one of the polynomials is sparse, then you can enormously speed up finding the greatest common divisor. Actually, this one is sparse and this one has small degree. And if one polynomial has small degree and the other is sparse, we can speed up the greatest common divisor by using the Russian peasant method. So what do I mean by this? Well, the key point is we want to work out, we want to find X to the P modulo F of X. And then once we found X to the P, it's easy to subtract X. So the key point is we want to work out this exponent. And now we can just use the Russian peasant method to find an X to the P. So we write P in binary and we calculate X, X squared, X to the four, X to the eight and so on, modulo F of X. And at each step, we should of course remember to reduce the polynomial modulo F of X so these powers don't get too big. And we should also reduce modulo P in order that the coefficients don't get too big. And once we've done that, we can actually calculate X to the P modulo F of X, actually rather fast. So although at first sight, this method seems to be rather slow, there's this cunning method of speeding it up. So we really can find the number of roots of a polynomial quite fast without actually finding the roots. By the way, I should say that by extending these ideas, you can not just find the number of roots of a polynomial, but you can actually find the roots explicitly and more generally, we can actually factor the polynomial into irreducible factors. I might say something more about this in a later lecture. In the meantime, we're just going to use this simple idea for finding the number of roots. So let's do an example. Suppose we take F of X to be X squared minus A. So we can ask when is A a square modulo P? And we can just look at the greatest common divisor the greatest common divisor of X squared minus A and X to the P minus X. So to do this, we take X to the P minus X and we divide it by X minus A. And this isn't actually very difficult to do. Let's write this as X to the P minus one minus one. So I don't have to worry about X equals zero, which is annoying. So we have X to the P minus one minus one is equal to X squared minus A.   So this is the remainder. Here I'm taking, I should have said I'm taking P odd because if P is even, something always goes wrong. Not like you couldn't divide P minus one by two. And so we see that the greatest common divisor is going to be given like this. If A to the P minus one minus one is not zero. So if A to the P minus one over two minus one is not zero mod P, it means there's no root. And if A to the P minus one over two minus one is common to zero, there's a root. Well, A to the P minus one over two is common to plus or minus one because it's square is one by Fermat's theorem. So we have the following neat result which is originally due to Euler. A to the P minus one over two is common to plus one if A is square modulo P and minus one if A is not square. So this gives us a fast method to check if A is square mod P. All we have to do is to calculate this which we can do using the Russian peasant method of exponentiating and we just see whether it's one or minus one. Actually, this is a rather bad fast method. So I'll just say later on, we're going to replace by a faster method using something called the Jacobi or Jacobi symbol. So don't actually use this method to check whether A is a square or not. Although it's fast it's there is a much better method coming up in a few lectures. So let's have another example. If D divides P minus one then x to the D minus one congruent to zero mod P has exactly D roots. And we can see this by noting that x to the P minus one minus one is divisible by x to the D minus one if D divides P minus one. This is just because y to the N minus one is divisible by y. Here we take y equals x to the D and N is equal to P minus one over D. So that means the greatest common divisor of x to the P minus one minus one and x to the D minus one is just x to the D minus one. So all which has degree D so there must be exactly D roots of it. We can take a look at this. Let's take a look at cubes modulo seven and modulo 11. So modulo 11 all numbers are cubes. So that x cubed congruent to one has only one solution because there can't be any other number of order three because three doesn't divide 11 minus one. But modulo seven, if we look at the numbers modulo seven there's zero, one, two, three, four, five, six. So these two are cubes. And we notice that one cubed equals two cubed equals four cubed equals one and three cubed equals five cubed equals six cubed equals six. So three is dividing seven minus one. So there are three cubes of one and in fact three cubes of all the other numbers. So the number of cubes of one modulo some prime depends on whether P minus one is divisible by three or not. Okay, next lecture will be another theorem about solving equations modulo P called the Chevelle warning theorem where we will show an equation always as roots modulo P provided it has enough variables.


Jason has the top-rated question and asks, what would a state-sponsored attack, technological, not political or legal, on Bitcoin look like? What could be done to defend against it? That's a great question, Jason. I think I've talked before about political and legal attacks on Bitcoin, which are really the most viable ones. But what about technological attacks on Bitcoin? I think the most obvious technological attack is to try to block traffic, use denial-of-service attacks, flood the network with fake nodes that provide fake information, or delay things by clogging up all of the available connections on the real nodes, and then don't relay transactions and don't relay blocks. Or collect information in order to do various types of analytics, and clog up all of the connections on all of the nodes. Oh, wait, that's already happening. Other types of attacks might be specific types of attacks that have to do with the packet inspection. So looking at traffic on the internet, trying to determine which of that traffic is Bitcoin-related traffic, and trying to block that traffic, of course, all of these technological attacks will create various countermeasures. So if the network is under attacks like that, there are a number of things that the developers and the node operators and the miners can do to diminish the capability to do that attack. Of course, attacks like that are only going to spur on the deployment of countermeasures and for node operators, miners, and others, to strengthen the infrastructure by making it more resilient, specifically to those and related attacks. So there are a number of ways to get around these, including the use of Tor, which is the onion routing network, the use of encrypted communications between peers, which was introduced with two BIPs in the latest version of Bitcoin Core. If I remember correctly, those are BIP 150 and BIP 151 by Jonas Nelly. The use of various obfuscation, stealth, or VN techniques in addition to Tor to make the traffic much harder to find, analyze, the use of filler traffic, where packets are transmitted, whether or not the transaction exists, just to fill up the network so that you can't do traffic analysis on it, as well as the use of alternative communication channels, direct modem connections between important nodes, for example, direct satellite connections, so either satellite broadcast, which is a project that Blockstream has been working on, which allows your nodes to receive the blocks and transactions from satellite, in addition to network connectivity, or even private satellite channels for important uses like miners, direct satellite connections, have a bit of latency, but if you're being blocked, that's a price worth paying. For the first denial of service attacks, various forms of node reputation management already exist inside Bitcoin Core and other node implementations. In the P2P layer, if your node doesn't route well enough or gives incorrect and valid transactions or blocks, it will get banned, and other nodes will remember its IP address, and they will preferentially connect to nodes that have been useful, have been truthful, and are remembered from the past, which means that it's already resistant to the kind of jamming denial of service attack that is most likely to happen. Anonymous asks, if China requires all miners in their country to join a single government-controlled mining pool, can they effectively attack the Bitcoin network? Yes. And what they can do is they can deny service, resequence transactions, deny access to transactions, but they can actually steal any that other people own. They can also fork the network, which they can do anyway, and they can bog down things. Of course, if they do that and attack the Bitcoin network, the Bitcoin network will counterattack. It will counterattack in a way that will effectively not just disarm their attack, but also turn all of their equipment into worthless electronics, burning a multi-hundred million dollar infrastructure, which wasn't really used for very long. Very quickly, there will be a counterattack, and the counterattack may vary. It may be denying service to Chinese IP addresses, or cutting them off from the network, which may or may not be effective to a certain degree. Finally, the nuclear option, which is to switch the proof-of-work algorithm. That may also be used as a countermeasure to this. Who knows? There is so little advantage to attacking the network in that way. It is so expensive to do, with so little advantage. China right now has a unique advantage, which is that they are domestically producing bitcoins, but they are not importing, and do not require them to export to you on currency, in order to get those bitcoins, because of the presence of miners in their country. Talk about killing the goose that lays the golden eggs. No, I don't think that is a smart strategic move. Chinese culture is really good at strategy. You don't stick around for 3,000 years as a culture without knowing how to work out strategy. Ked says, Western government pumps Bitcoin price, mainstream FOMO at pumped prices. Government's tax price acquires BTC from panic selling, and causes short-term pure damage for masses. Pro is cons. That is a very, very expensive way to mess with Bitcoin. Also, government would not be the only one acquiring Bitcoin during the panic. It would be at least one other party acquiring Bitcoin during the panic. A lot of other people have a long-term perspective of this, and are not FOMOing, chasing after the pumped prices now. I think there are a lot of sophisticated investors who can use the futures market to make a lot of money, making this very expensive maneuver. Let's look at some parallels from history. If it was that simple, a lot of people will tell you that the gold and silver markets are manipulated. I have no doubt about that. I think the gold and silver markets are manipulated to a great extent, but they still can't do what you just described here, this kind of pump-and-tump. They can keep supply or demand for quite a long time by playing very big moves in the market. But they can't do this kind of pump-and-tump, FOMO-driven price fluctuation, because it gets very expensive very quickly, and it doesn't really achieve much. If it worked exactly as you were talking about, where the government then comes back in and buys Bitcoin from the panic selling, they will drive the price back up. What do you teach the markets? Hey, it can drop, but if it drops, it's also coming back. If you teach the markets that, they won't let it drop in the first place, because as soon as it starts dropping, they will buy the dip, because they think it will come back. That means the drops become shorter, and the whole pump-and-tump thing gets very expensive. I think a lot of people who are worried about this don't really understand how markets work. I probably don't either, but I'm not that concerned about governments manipulating the price to that extent, in a way that's not very expensive to them for very little return in terms of the effect. MJ asks, do you think that the United States and the European Union may be forced to embrace Bitcoin due to smaller nations doing it first? That's a fascinating question. Yes, I think we're going to start seeing a lot more geopolitics play in this space. As more nations are implementing their own cryptocurrencies, often cryptocurrencies backed by resources like oil or minerals that are available in that country. And using that sometimes to bypass sanctions imposed by some of the superpowers, or sometimes just to get more sovereignty, really. Connecting that concept, that cryptocurrency security equals sovereignty, first for small nations, first for rogue nations. Sure, okay. First for criminals. Sure, okay. And then the rest of them get jealous. They're like, oh, these criminals are doing a lot of privacy and sovereignty, and I'm not a criminal, but I like me some privacy and sovereignty. These rogue states are doing a lot of privacy and sovereignty, but I'm not a rogue state, but I like me some sovereignty, too. That changes the strategic and geopolitical impact of the whole cryptocurrency space, in fact, the entire monetary system itself. So yes, I think the EU and the US are forced to reckon with the fact that when they squeeze things out of their respective jurisdictions, there are plenty of other countries that go, hey, we'll take you, you know, Singapore, Switzerland, Malta, a whole bunch of other small countries may make a play to become the next Switzerland, the next Cyprus, the next Singapore, the next Hong Kong, by using cryptos geopolitically. So yes, I think that puts a lot of constraints on the actions of superpowers. In fact, what it does is it decentralizes geopolitical power, which is as it should be. The next question comes from Nacho, and Nacho asks, if you were a state actor that was comfortable carrying $200 trillion in debt and unfunded liabilities, how would you attack Bitcoin given your ability to print money and run deficits? Could you spin up 100,000 nodes? Could you take over consensus in some other way? What does the network response to your most likely attack look like? Thank you, Nacho, for that question. I think that because we're engaged in technology, we assume that the types of attacks that this system will face are going to be technological attacks. But that doesn't really make a lot of sense. If I'm a state actor and I want to attack a cryptocurrency, I would use technology as the absolute last form of attack. Why would I go and play in the turf of the other party? Technology is what we do, and we're damn good at it, and most governments are not that good at technology. It's like trying to attack a young person on social media. They're much better at social media than you are. You don't attack a technology platform using technology. That's not very good. You're going to lose that. It's asymmetric warfare, where the technologies have significant advantage. No, I would attack it by creating legal uncertainty. How about making it so that you have to file capital gains for every single dollar you spend, even if it's for a pack of gum or a cup of coffee, to make it impossible to engage in regular commerce? Instead of treating it like a foreign currency or any type of currency, treating it like a commodity... Oh, wait, they already did that, which is why it cost me more in my accounting fees than my capital gains... in order to do my tax reporting. How about making it legally vague as to whether you're allowed to hold it or not to hold it? How about creating various ways of scaring the middle class and the mainstream? How about using propaganda and media and dropping announcements by officials about how this technology... can't be trusted, you're likely to lose your money, and we're all drug dealers and criminals anyway? Those are much more effective.  I mean, who wants to engage in cryptocurrency when all of the people in this space seem so nasty and dramatic? Well, most of those people are not in the space. They're in fact trolls who are doing this for fun, or paid infiltrators who are doing this as a job. Just recently, we found out, for example, that I believe it was in Poland. The central bank paid a YouTube artist $30,000 to create this laughably bad public service announcement type video, where they make crypto look bad by having this guy take his girlfriend to a pizzeria, and then he tries to pay with crypto, and he can't, so she walks out, and it was just ridiculous. Anyway, this kind of propaganda is definitely happening. State actors, if they want to attack a grassroots movement, use infiltration, surveillance, intimidation, coercion, blackmail, rumors, and drama. They've done that with every grassroots movement in history, and it is naive to think that they're not doing it this time. Why not? Of course they are. So, state actors do not use overt, direct, and technological attacks, especially not against technologists. They're going to use covert, underhanded, and mostly psychological, reputation, and sentiment attacks to attack this technology. And they already are doing so. Banksters vs. Bitcoin, Yvonne asks, as big banks, governments, ruling organizations, are threatened, or should be threatened by Bitcoin. Eventually they will lose money and power. How do you see this big, upcoming battle playing out? It's very difficult to predict how this battle will play out. I'm actually gratified by the fact that, so far, the main reaction has been to underestimate the threat. There's one advantage here, which is that big, incumbent organizations historically massively underestimate the threat of disruptive technologies, until it's too late to do anything about it, whether it is Kodak underestimating digital cameras, and then getting steamrolled by Nokia, which wasn't even a camera manufacturer, whether it's car companies underestimating Tesla, whether it's Walmart underestimating Amazon and online shopping, whether it's Blockbuster underestimating Netflix. Until very, very late into the competition, you were still hearing many of the executives of these companies saying, we have a hundred years of tradition behind us, loyal customers, the tangible quality of analog film, the eternal joy of analog photography, these new technologies cannot possibly, will not possibly overtake us. Nobody will want to shop online. Nobody can really stream videos online. People like rewinding VHS cassettes. Okay, they never said that one. But still, hubris, dismissive attitudes, complacency are characteristics of large, incumbent organizations. One of the things that makes me optimistic is that I think they will continue to underestimate Bitcoin. And I hope they do for a very long time until it's way, way too late to do anything. And even if they did figure it out and wanted to try to do something, they don't really have too many options. They can't compete against it, because the very architecture of these organizations is centralized, and they can't compete against decentralized threats. They can't regulate it out of existence, because regulation is the first thing that this technology disrupts. They can't prevent people from using it, because in the places where it's needed most, people are so desperate to use technologies to gain their financial freedom, that they will break any law put in their place and risk imprisonment, or worse, as we've seen in places like Venezuela. They can't intimidate people from stopping to use it. And so, in the end, there's really not much they can do. But still, I'd rather they didn't figure that out until a lot later. Somewhat of a related question. In your view, what's going to be the geopolitical impact of this, especially when it comes to pegged currencies or rogue nations? Yes. The geopolitical impact of this is absolutely enormous. Part of the reason for that is because over the last 50 years, we have converted money from being a store value medium of exchange and unit of account, into being a system of control and a geopolitical pawn in a global game. When you have national money, what I call flag money. You remember the old airlines that had a flag on the tail? Those are obsolete. Now that's happening to money. The idea that money becomes a system of control to play geopolitical games through embargoes and currency controls, is itself a relic of the industrial era, and is being made rapidly obsolete by this technology. It has radical geopolitical implications. It removes the ability of sovereigns to control monetary supply. Most importantly, it removes the ability of central banks to take the entire population hostage on some kind of crazy hyperinflation drive into disaster. As we're seeing happen right now in Venezuela, we've seen it happen in Brazil, Argentina, Cyprus, Greece, etc. In all of those cases, the initial reaction is to apply currency controls, so as to stop the population from fleeing and keep them all bound into this experiment. That game is over, not yet visible, because only a tiny sliver of the population can escape the controls. Right now in Venezuela, we see the largest surge in use of Bitcoin in the world because of their hyperinflation problems. Only a tiny percentage of the population can escape. What happens when that's 10% of the population? When it's 15%, 20%, 25%, at that point the entire hyperinflation experiment goes wrong. The entire central bank currency control system becomes fatally undermined. This has enormous geopolitical implications. Your initial reaction to this is, but we shouldn't, but we mustn't, but we can't. But it is. That's the basis we have to start with.


So, the other day I built a signal generator with moderate levels of incompetence, I was going to also build the matching frequency counter to go with it, but didn't have time, so let's do that now. This is a cheap $10 frequency counter from Banggood, produced by GeekCrite. It's a kit which I need to assemble, and I have not opened this before other than to take this cable out, so let's have a look and see what we get. We have a PIX 16F68A microcontroller with a socket and the display for the frequency. What this is, it will measure the frequency of an incoming signal and then display it here, which I need for work on the flux engine. Bag for the components, a box and the PCB. The box is, it looks like exactly the same laser cut acrylic that I had such a difficulty with for the signal generator, which I'm going to demonstrate, which is here. The box fastens together in a rather unobvious way. I had difficulty figuring it out and I ended up having to glue it together. Some instructions that are probably in mangled English, a yellow double-sided PCB. This is interesting, compared to the other one, well the other one was a red PCB but the manufacturing was different. The pads were smaller and the holes were bigger, so yeah, I don't know what that will, how much effect that will be on the construction. Smaller holes should mean more secure component mounting. The acrylic case is just as usual, it does not appear to have the weird cog pattern in the holes that the bolts were supposed to screw into. So probably the bolts just go straight through in a much more conventional fashion. What we have here, some bags of capacitors, a socket, some diodes, a couple of transistors, a clock crystal, always a good sign for a frequency counter because that means it might be right. A button and a switch for the button, nice switch, good and clicky. Okay, what have we got in terms of resistors? Are all these the same? These all look the same, these are different, this one is different again, so you have three types of resistor, some ceramic capacitors, no electrolytics. This is the mount for the input signal, this is interesting, so you've got a socket and we've got three jumpers, I wonder if that's supposed to go together. Okay, let's take a look at the manual frequency counter installation instructions. This looks diode black in the negative, that seems all reasonably well, reasonably clear and translated, five volt voltage regulator, that'll be one of these. Two transistors and a U1, here we go, U2 and U3 NPN transistors, yep, oh boy, the welding installation considerations, follow these steps. The components are welding the front board from low to high principles, namely the first low welding components, yeah this is the same instructions as the signal generator. The welding microcontroller header and then welding triode button and power outlet. The back with the diagonal cutting pliers to cut short the pins as far as possible. Using the step, before measuring signal please switch J1 jumper cap, blue terminals for the in before measuring crystal, please switch the J1 jumper cap. Ah right, you can switch this between measuring the frequency of an incoming signal or measuring a crystal, that's cool, we have a circuit diagram, a QR code and nothing on the back. Okay, so, let's rearrange things a bit, right, well we need to go from low to high principles. First low welding components, crystals, capacitors, resistors, diodes, round hole of seats, okay, so let's try the resistors. We have three, six, nine of these resistors, our six to our thirteen, one K resistor. Actually I'm going to go with the lone resistor first, just to be on the safe side, stick it in my component tester, hundred K resistor, there should be a single hundred K which is R1 and R1 goes there, that's pretty good, it's a nice tight fit so the component stays put, okay, soldering iron is hot, leaded solder, did not feel like a good joint, that's fine, good. The next step, let's go for these three, these are, these are probably the ten K resistors labels here, just be on the safe side, ten K, R2, R3, R5, R2 is here, so what this is is a PIC microcontroller based device, it will count pulses on the signal, there will be some analog electronics to actually couple it with the signal, it is a very small computer, I actually have a programmer, I'm not sure it will work on PIC, if I really wanted to I could probably reprogram this to do something else, which I probably don't want to. PIC assembly is kind of weird, I've done a little bit of programming in it, this is a PIC 16 I believe, yeah that's an interesting choice, I wonder why they didn't use a 12 which is smaller and cheaper, so the PIC instruction set is extremely peculiar, it's got a handful of bytes of memory mapped to registers so it doesn't really distinguish between IO devices and RAM, it's got depending on which version of the PIC you're using the instruction set varies from 11 bits, maybe 12 bits up, so the program held in flash uses a weird width of flash memory, I think it's 14 actually, so trying to actually copy programs into RAM which is 8 bits wide is very peculiar, R2, R3, where is R3, R3, R2, R5, I need R5 next, where is R5, R2, diode, R4, no that's a 1K, where is R5, bunch of resistors here, capacitor, capacitor, clock crystal, capacitor, jumper, jumper, capacitor, R4, now I want R5, there it is, right it's pretending to be a diode, a row of diodes with the resistor next to it, so now I want to put in all the 1K resistors which should be all the rest and again just double check, helps if you plug it in, 1K, 1003 ohms, I have no idea how accurate that thing is, I suspect not very but it is very good as a quick and easy sanity check to make sure I've done everything right, R4 is a 1K resistor, okay, all the other resistors go in this bank up here I believe, this is 3, 6 and 8, yep 8 of them, R6 to R13, so R6, R7, I'll get this one a bit straighter, R8, it doesn't matter which way around you put resistors but just for needless, let's have all the stripes lined up the same way, it's not very neat, R9, having all the stripes lined up the same way also makes it more obvious if the wrong resistor gets in the mix, put all the components in so that we can solder all the legs together in a group which is substantially simpler and easier and quicker. The last three is R11, R12, R13, R11, this is R12, so looking at the, ah yes, looking at the circuit diagram which is just off the top of the screen so you can't see it, these are the resistors for the 7-segment display LEDs, you notice that there are fewer resistors than there are segments, LEDs are not ohmic devices which means the current through them does not vary in proportion to the the resistance so you have to have a resistor in series with an LED to keep the current under control otherwise you blow the LED and you may notice that the there are eight resistors but the 7-segment display has a lot more than eight LEDs in it because each digit is made out of eight LEDs, seven for the digit itself and one for the dot and the way this works is that probably only one digit is displayed at a time and the pick will rapidly cycle through all the digits displaying each one in turn for a brief moment of time and persistence of vision means that you can't actually tell this it looks like a constant display but it means that because only eight LEDs are ever energized at one time you only need eight resistors and just as importantly far fewer connection to the module okay let's remove some of these wires that should be all the resistors component legs are worth keeping it's amazing how frequently a short piece of stiff wire comes in handy so that was all the resistors I think next I'll do the diodes as they are smaller than the other components and we do after all have to go from low to high principles so here are the diodes let's just sweep this away a bit diode are polarized they only go in one way around so now it says on the instructions d1 to d5 diode black in the negative so these are these diodes here and d1 there I assume that the stripe matches up there is a black stripe one end of the diode which is the negative side so we can actually using the trusty testing tool yes the arrow indicates the direction of current flows so the black is the negative side it'd be nice if the pcb actually had a plus or a minus on it but there is a stripe marked so diode and now we do the other four this bank here so the diodes for be these four here I can't tell off the top of my head they are connected to a transistor they're also connected to the lines for the led the internal resistors on picks are the internal transistors on picks are quite powerful so they use a lot for powering leds so I just wonder what this transistor is for the transistor is connected to the led bank so maybe that is to do with powering the led display anyway let's get these diodes mounted not very elegantly I have to say all the black stripes through the top so it's time to do the soldering that one moved slightly when I was as I was soldering it the joints seem to be all right so that would be the diodes what we've got next are oh yeah the unpolarized capacitors these little brown things and they're all different so the instructions I've got two point one micro farad capacitors labeled 104 one 102 22 p 22 pico farad so we've got a 104 a 102 22 that's probably the 22 p that's another 104 another 22 22 yeah there are four of these 22s right so let's do the 102 that's the old one that is c6 c6 is here it's even more or less upright yes that does say 102 and it is in c6 the 104s go in c1 and c7 so c1 is here and c7 r is next to it actually so right next to u1 here uh I'm not going to do those I'm going to work sideways let's go with c2 c2 is the 22 p I wonder what this 22 p is it is a not known yeah I don't know what that is and neither does the machine so 22 p in c2 yes that goes in here next to it is c3 that is another 22 p then we get to c7 which is a 104 and then we get u1 what is u1 it is a five voltage regulator five voltage regulator 7550-1 that would be one of these uh packages that's a so it's a 58050 right that's an npn transistor 58050 therefore they must be this one 7550-1 yep I assume it goes this way around judging by the shape of the silk screen it would go in like this wouldn't make any sense the other way around uh looking at the tracks I can see this is where the barrel connector goes I can see the ground is connected to this bottom pin our voltage to the middle pin and the output five volt is going to is from the top pin so that seems to make sense okay be nice so if there's a little bit more assistance on the board yeah there is I'm doing them in this order is so that I have space to work I don't have to solder components between two other components right c1 is the other 104 that's this one this c1 here is a smoothing capacitor between ground and the input voltage yeah yeah these are both smoothing capacitors c1 this one is smoothing before regulation and c7 is smoothing after regulation what they do is they soak up any spikes or glitches in the power supply voltage so that the voltage that the pic the processor sees is reasonably level k so there are only two more capacitors which are these 22s and these must be c4 and c5 which are here right again there are three components in a row so I will do them in that order now I happen to know from the the circuit these two capacitors are used by the clock which is this clock crystal the clock provides no the clock crystal provides the frequency reference that drives the pic and also is used to and is used to measure the frequency and you need a clock crystal and two capacitors so that's c4 and c5 here that's going to fall out if I turn the board over and clock crystals are fairly fragile so I actually need to be careful with this they are also unpolarized it doesn't matter which way around I put it he says just after he checks the circuit diagram which I should have done before I actually soldered the thing on but never mind the last capacitor and remove the wires I am not sure why these are sticking to the wire cutters because these wires are supposed to be copper and copper it's not magnetic maybe it's just that the wire cutters are slightly sticky these will not be the greatest components they'll be sourced from fairly low-end manufacturers but there's isn't that cutting huh they managed to solder two wires together interesting okay so we've got a lot of stuff what do we have left you've got two npn transistors and these are identical they are both 58050s they are what does the component test to think they are it's a diode um yeah transistors and diodes are pretty similar so I'm not surprised it gets that wrong and these would go into u2 and u3 I'm going to assume that the rounded side matches putting those up a little right solder what's next we have the input and output terminal which goes here uh but we also have j1 so let's put that on first j1 is three pin jumper cap that will be this I assume it's that yes this goes on here and immediately falls out now we can put on this this is the screw terminal for the input signal that goes in spoke too soon I need the tape again a crystal tester this is the socket here for attaching a crystal if we had the if this worked I could then demonstrate using the crystal that this uses but I wouldn't be able to because I wouldn't be able to test that crystal without removing the crystal and then it wouldn't work makes sense really I actually one think I might have a crystal somewhere that's worth a try rapidly running out of components which is what I like to see right that has not worked right the crystal has the socket has moved when I plugged the thing in so it's actually standing a bit proud of the board fixing this is going to be tricky because I need to melt all three connections simultaneously ow and then burn myself or you know that looks fine it'll do so here is the jumper it's one of the same jumpers with a tag on it for easy access the function generator used uh what is left well not much really we've got the barrel connector for the power big thick chunky pads that take a while to heat up okay that's reasonably level I think this board is noticeably better than the other one it the solder is wicking through the wires very nicely uh what do we have next well there's the socket for the processor uh we have the dimple indicating the top which matches the diagram the image on the sub screen so that will go on here and let's tape that down it'll work very well what do we have I can prop this up on that will do yeah just one solder spot is enough to hold it in place notice that one of the pads that one there is square that's another way to mark pin one on the chip all the pins that looks fine okay so we now I have the lcd module the lcd module is u4 led displays by screen printing layer now I would rather like it if there was a socket for this but there isn't so I'm just going to have to solder the thing directly to the board this means that if I get it wrong I will never get it off again at least intact also the pins are not quite going through the holes they don't quite line up with the pcb that is luckily tight enough that it fits right double check it's the right way around you see the dots on the lcd module are on the bottom which they are here and solder time should now be firmly soldered in place never to be moved again and there is only one more component which is the switch which is here the switch is this one s1 switch s1 regardless of the polarity so this goes on here whoops that stays in place reasonably well yeah this is working really well the solder is easily melting and flowing smoothly into the the holes the holes are plated on the inside just as with the other board because it's a double sided board so yeah that's good that's it that's all the components so all we need to do is attach the button insert the chip the right way around bend the legs together a bit not quite that far do not know why the legs of chips are always a bit splayed because it makes them hard to fit into the sockets the software for the chip has been pre-programmed i hope so now all we need to do is to plug it in and see how it works which i should just do all right so here we have the signal generator that i built yesterday and this is connected to my bench power supply at 9.4 volts because this needs nine volts to run and it's configured for a sine wave and with some random stuff this however is plugged into usb and producing five volts so we plug this in here and see what happens it's a number is that showing up on the screen no on the camera let's try that it says 0.144 so if i adjust one of these knobs very nice this is fine this is coarse we don't know what the scale is oh hang on i've missed mr step mr step i need to insert the cap uh this the jumper this needs to be here to say that i want to measure a signal zero uh does the button do nothing much intriguing so looking at looking at the instructions it does say uh before measuring signals switch j1 jumper cap blue terminals for the inf signal input yeah that's this one so why is that registering zero is the amplitude not enough for it to register it was working with with the jumper removed ah yes i forgot about this all these knobs are backwards so if we turn this clockwise the amplitude goes down so that wants to be there for maximum amplitude so if i turn this clockwise the frequency increases i assume this is megahertz it doesn't register anything 200 400 i think what's happening is as the frequency goes up the voltage goes down and eventually this stops measuring it so what about this one 30 kilohertz maybe this one these do seem to be powers of 10 oh yeah there is actually a label right 1 to 10 hertz it is measuring in kilohertz not megahertz so that is 0.3 kilohertz so if i stick this up to this one this is the 100 to 3 kilohertz range so that is 500 hertz yeah i don't really follow what this is doing it's showing a number which i hope is showing up on the screen is that better so it says 0.216 oh yeah i can do this too much better at least for me uh so this is going down the minimum rate the minimum level is 140 odds that must be 140 hertz so we turn the knob up and that's fine this one's course 200 300 400 and suddenly the number drops off interesting uh let me make a small adjustment so this is currently connected to the sine wave output for the signal generator so let's put it in this one this is the square wave output and if anyone actually watched the other day's video the square wave the amplitude is always about 10 volts so this is showing 6700 and that stops let's try it with the jumper in i don't know what the button does let's power cycle it see what happens that's better numbers quite small the knobs seem to have no effect on the reading that says 0.19 but it's changing this is the 10 to 100 hertz range so that is registering seven hertz if it's measuring kilohertz so one end of the range is seven and the other is 19 yeah i haven't i don't think this is doing anything particularly useful the numbers just seem to be randomly in under debugging steps check the ic weather against such as anti please timely correction who knows what that means after the check the electricity the fourth digital tube displays zero said the installation was successful so if i unplug this fourth display is registering zero well that was an adventure i do finally have it working as you can see by the 0.2 registered here and i'm going to explain what the problem was and why i need this extra board with the help of my trusty oscilloscope which should be appearing up there somewhere so currently it's showing a flat zero volts that just means noise this is what the signal generator is producing and you can see that there's a pretty hefty dc offset of about uh four and a half volts and it turns out that as i thought the frequency counter requires the signal to cross zero volts before it is counted so in order to remove the dc offset i need to decouple the signal to remove the dc offset which i do using a decoupling capacitor and a resistor to bias the output towards zero uh this is what the frequency counter is actually seeing and you can see that the dc offset has been mostly removed it's going from about plus five to about minus one volts uh you can change the amount of offset that is removed by changing the value of the resistor the smaller the resistor the closer the result will be to zero unfortunately the smaller the resistor the smaller the output signal so if the output signal gets too small the frequency counter just can't count it anymore this appears to be a reasonable compromise it's crossing zero enough it's going negative enough that it's actually managing to count i can adjust the amplitude so if i reduce the amplitude to here you can see that the counter just stops being able to count it and starts producing gibberish so let's crank that back up until about there that's the point where uh it starts to clip so that does seem to be working this is registering in kilohertz i found the manual the slow flashing decimal point indicates that the result is in kilohertz so we're seeing about a 200 hertz signal and i can wind that up you can see the frequency increase and it counts and if we go that's over a kilohertz it's two and a bit kilohertz we have the jumper here in the hundred hertz three kilohertz range so that's up the top of the range that's pretty good let's go up a step and adjust the oscilloscope to get more of a signal so the we still have the slow flashing dot it's still in kilohertz so we can continue to wind this up and eventually uh we get a fast flashing dot which according to the manual means something else but that is still reading in kilohertz interesting that goes up to 40 ish it says 65 on here what's the next range up to 72 right the the see that's now flashing even faster it's supposed to indicate the uh the unit it's measured in but i think the manual is wrong and all it's doing is registering which uh digit the ones digit is so the decimal point is always showing kilohertz that's 120 kilohertz oh wrong way uh that's showing on the oscilloscope a 10 about a 10 microsecond peak between two successive waves and this goes all the way up to this says a megahertz that says 650 kilohertz which i reckon is about right the as you wind the frequency up on this the amplitude goes down so it's only just going negative yeah so that was weird but uh now that i've sorted out what's happening that seems to be fairly plausible i believe that the dc offset on the signal generator is intentional you're supposed to use a capacitor to decouple it and you need quite a big capacitance and i believe the dc offset is there so that you can use one of these polarized electrolytic capacitors because you can guarantee that this side is a higher voltage than this side and because these things are polarized and have to go in the right way around this makes life easier if there wasn't dc offset you wouldn't be able to use an electrolytic and you'd have to use a much more expensive uh non polarized capacitor so yeah i believe that works so there's only one more bit to do which is to assemble the case i have taken all the brown tape off the uh perspex because that's really boring so let us unwire this and put it together and let's have a look and see what the result looks like not sure what i'm going to do about the need to decouple it i suppose ideally the uh the capacitor and the decoupling resistor would be adjustable and somewhere on this i might need to build a board i'm not really into pcb manufacture unfortunately it should be easy enough to make one so how does this go together this is clearly the bottom this is clearly the top because this goes over here so i believe that it just bolts onto the uh bolts onto the bottom sheet so that would probably be the small bolts to be honest the frequency counter seems rather more useful than the signal generator given the slight weirdness of the signal generator and i'm probably going to have to put the side pieces on this box before putting the board on let's just double check that this has the notch on it over here yeah this is got the notch for the output so that means that this one goes here and this one goes here okay right i can do that without needing to take the board off so let's do the rest of these bolts up these laser cut acrylic cases are primitive but effective the the lugs of the dc jack project more project further than the other uh pins so in fact the board they're touching the acrylic and the board is bending so i might need to be a bit clever how many bolts did they give us 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 right i know this is supposed to work hopefully i'll make a bit less of a dog's dinner of this than i did the the box for the frequency counter which is now held together by glue right the way i believe this works is that that these bolts go on here and these then form the stands that hold the pcb off the bottom of the case and now i'm looking at it i wonder if i'd be better off with the bolts on the top and the screws going up let's just try putting it together and seeing how big things are so you see then this goes on here and the more bolts hold the pcb on so it's actually going to stand on these uh yeah let's actually take this apart for the bolts on the other way up so it actually has to go assemble this way up this time and then the bolts that hold the top of the case on will go the other way and that will form four nice feet for the thing to stand on i hope the board then sits on like this okay that does go on i thought for a moment that the bolt wouldn't go round because of the the led unit next to it but in fact it does go on across i want these two tight all right so that seemed good and solid now we put these on at the side where the the connector here you have the side for the power jack is that going to go on there we go there we go the two blank sides this goes on top there we go there we go right so these bolts go through like this they seem to have given us more more nuts than were really required but not enough for two nuts in the spacer because if the board was supposed to come up another a row of nuts you'd need a four extra but in fact we only have two and looking at the way that the looking at the size of the case there's clearly no not enough room for an extra for nuts this is the right size okay that it's not moving smoothly so so we appear to just have three extra i suspect they just put a handful in the bag and didn't actually count them all right there we go in a fairly neat box we have the jumper for the i've got to be careful because this is actually the nine volt supply this is the five volt supply yes this is the jumper that selects between measuring this the frequency of a signal measuring the frequency of a crystal when the when this is in the bottom two holes it actually connects a pull-up resistor and bypasses the circuitry the oscillator circuitry for the crystal when you pull it out to disconnect the pull-up resistor and then when you put it in the top row it hooks up the oscillator i don't actually think i have a crystal spare to try i had a look uh the button is actually for the user interface which is well you press and hold it and you get this menu which allows you to do various things no psu i believe this turns it sets it to power saving mode so it doesn't it stops measuring if there's no signal add and sub allow you to do offsets for measuring differences in frequencies it's apparently useful for shortwave radio which i know nothing about zero uh yeah that undoes an add or a sub table is something to do with crystals and quit just goes back to uh frequency measurement mode i cannot imagine anything i want to do involving the user interface at all i just don't need any of those features it's interesting that they managed to actually get a complete menu into a single button it uses short and long presses to do things which is amazingly cheap but yeah that is the frequency generator there's actually appear to be no problems with this whatsoever all the trouble i had was due to the signal generator and its dc offset which i wasn't expecting i would probably recommend this i may not recommend this now i know more about it i mean it's perfectly functional it's just it's got some rather odd built-in assumptions was it worth ten dollars yeah i reckon so now it's put together and bolted it's a decent decently solid box it seemed to do the job i do actually have a high precision one kilohertz signal source which is part of the oscilloscope that i tried it on and it registered 1.000 yeah anyway now i have a frequency counter i hope you enjoyed this video let me know what you think in the comments


That was nice, thanks Rebecca. And happy Friday everyone. Welcome back to this week's episode because it's Friday. I'm here with Xavier and all we want to say today is that we went overboard for Christmas and we created this thing called 12 art resin days of Christmas. So starting next week about midweek for 12 days we'll release a new video with a really cool Christmas product craft that used art resin and uh check it out and let us know what you think and have a wonderful weekend. Until next Friday. Video Friday with art resin.


Well to the pool we go undefeated Brainerd battling with sock rapids rice this evening. We start in the 50 yard freestyle it's close but the Warriors Jacqueline Wood comes up just short. She finishes in second. Now it's the last leg of the 200 yard freestyle and if you thought the 50 was close check this out. It's Brainerd's Katie Streep and sock rapids rice. He had to change tangent neck and neck but Streep takes it by four hundredths of a second. The photo finished wow that would however though I think Brainerd wins that one 105 to 81 sorry the scores were incorrect on that one. If you've enjoyed this segment of Lakeland news please consider making a tax deductible contribution to Lakeland Public Television.