4 ms·
In algebra, mod is not an operator. We say 17 mod 4 is 1, but what we write is something like 17 = 1 (mod 4) To say that 17 and 1 have the same remainder when
by dmurray 8y ago
In algebra, mod is not an operator. We say 17 mod 4 is 1, but what we write is something like
17 = 1 (mod 4)
To say that 17 and 1 have the same remainder when divided by 4. If you do all of your operations and comparisons mod 4, it doesn't matter if we call the number 1 or -3.
In real life, we often need the remainder function, and we usually need it with positive numbers (how many eggs will I have left if I put these into boxes of 12). We sometimes call this the modulo function, which is a slight abuse of notation from the algebraic meaning of modulo. For positive numbers, it works completely intuitively. There are a couple of natural ways to extend this to negative numbers - an extension which would be meaningless or irrelevant in algebra - and computer language authors have (usually) called one rem and one mod.
- alexlarsson 8y agoI don't think that is quite true. Yes, for normal intergers 17 and 4, you can say the above. But mod can also be used as an operation on (and into) the equivalence classes of Z mod 4.
- edflsafoiewq 8y agoFor this reason, x % 0 should be x.
- abakker 8y agoIt's funny, I posted this same thing on the 1/0 = 1 thread the other day. It seemed to me that the logic was linked. https://news.ycombinator.com/item?id=17737175 https://news.ycombinator.com/item?id=17737175
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- gowld 8y agoFor polyglots, the problem is that % sometimes mean mod, sometimes means rem, or sometimes means something else: -7 % 2 7 % -2 Admit 4 possible sets of answers.
- nmyk 8y agoStrictly speaking, it's not the case that 17 = 1 (mod 4) but rather 17 ≅ 1 (mod 4) i.e. "17 is congruent to 1 mod 4", not "equal", though congruency mod n is an equivalence relation.
- antoineMoPa 8y agoYeah I remember this notation completely messing up with my brain back in my discrete math class.
- 0x7f800000 8y agoClock arithmetic. Modulo 4: a clock with only four evenly-spaced marks on it. 17 is congruent to 1 (modulo 4) means: Starting at the top of the clock, go clockwise one mark. Starting at the top of the clock, go clockwise seventeen marks. You'll end up at the same position. That's congruence.
- gizmo686 8y agoWhat do you mean by "17". The standard way of constructing modular arithmetic in "upper level" [0] is to define it over equivalence classes. For instance, let a ~ b mod 4 be the expected equivalence relationship for mod-4 arithmetic. Then, define [x] = {a | a~x} to be the set of all numbers which are congruent to x mod 4. At this point, we define [x]+[y] = [x+y] (along with the other arithmetic operations which are defined similarly). Then, there is just a bit of work to prove that the above definition is actually well defined (since the representative element we pick from both of the [x] and [y] sets is arbitrary, we must show that [x+y] is the same set regardless of which x and y we choose). This means that, when we write 17 = 1 (mod 4), we are really saying [17]_4 = [1]_4; where [x]_n is the mod-n equivalence class containing x. The equal sign is literal, the numbers are not. This type of implicit injection is actually fairly common in algebra. It is how we can view, for example, 17 as a natural number, real number, complex number, and polynomial without explicitly mapping it each time. [0] Eg. an introductory undergrad course in abstract algebra.
- wcr3 8y agoconcrete math has a nice def of mod as a binary operation: x mod y = x - y*floor(x/y), for y != 0; x mod 0 = 0. this works for all integers.