Talk:Modulo operation
From Wikipedia, the free encyclopedia
Contents |
[edit] Remainder algorithms for various moduli
Such as number modulo 3 := sum of the digits (decimal base)
Example: 62837 mod 3 = 6+2+8+3+7 mod 3 = 26 mod 3 = 2+6 mod 3 = 8 mod 3 = 2
Another: number modulo 7 := number lest the last digit - 2 * last digit (decimal base)
Example: 62837 mod 7 = 6283-14 mod 7 = 6269 mod 7 = 626-18 mod 7 = 608 mod 7 = 60-16 mod 7 = 44 mod 7 = 2
Ïnteresting would be an algorithm for numbers modulo 31; with that you could calculate in your head certain check digits to forge a social security number in situ...
[edit] please read this before further action on the article
This Modulo operation page was created because there was a need to separate the many meanings of the word "modulo" which were all put together in the articles modulo and modular arithmetic with lots of overlap, ambiguity, and incoherence. As result, the modulo page was put (and still is) on the list Wikipedia:Pages needing attention/Mathematics, although ever since it is been significantly improved.
The biggest two mistakes done by the authors contributing to modular arithmetic was to not read the article before modifying it, and not knowing what "modular arithmetic" acually means. As consequence, I am sorry to say this, but the very best version of the page modular arithmetic was the very first.
This page now contains exclusively information about the remainder function in computer science, no more no less. This is according to the belief that separate matters need to be kept in different places in order to avoid confusion.
Care has been taken in this article to refer to the proper place discussing the relationships between the many meanings of modulo.
If by any means you do not agree with creating this article, please express your opinion before attepting to delete this article or to revert it to the form it was before the cleanup. Thank you. Oleg Alexandrov 04:20, 3 Jan 2005 (UTC)
- Thank you for separating this out; a separate article for modulo-as-used-in-computing should have existed from the start. As one of the people who upset you by expanding and rephrasing parts of the original article in ways that reflected my ignorance of modular arithmetic, I apologize for upsetting your delicate sensibilities.
- However, your implicit insistence that computer programmers (and users of calculators with 'mod' buttons) be well-versed in the nuances of modular arithmetic and the ways in which modulo operators & functions both refine and place arbitrary constraints on the pure mathematical theory is missing the point of Wikipedia, and putting the cart before the horse. I came here as a programmer looking to better understand why "a % b" produced (to me) weird results when one of the operands was negative. You seem to be of the opinion that I should already know the answer, or that it was perfectly clear from the original description of modular arithmetic. It was not (or at least, was predicated on a more thorough understanding of remainder than the average high school graduate is likely to have). - mjb 19:38, 20 Jan 2005 (UTC)
-
- Hi there. I am happy you agree that the articles should have been separated. I see your point above. The original problem is that "modulo" means so many things to so many people, so it is hard to make everybody happy. Some of the answers to your questions should have been on the remainder page, rather than on modular arithmetic. I will put more stuff on that page soon.
-
- We can continue in the discussion I just started on Talk:Modular arithmetic about the future of that page. Oleg Alexandrov | talk 20:30, 20 Jan 2005 (UTC)
-
- Hi there. Again, you have point. Could you take a look at the remainder page and let me know what you think. I am sorry if you thought I am kind of elitist or something. I do think though that the remainder page is a better place to talk about your mod issue. This because modular arithmetic heavily relies on the remainder concept, but is, in itself, much more than just the remainder issue. Looking forward to feedback. Cheers, Oleg Alexandrov | talk 23:22, 20 Jan 2005 (UTC)
[edit] Remainders for non-integers
I've edited both this article (Modulo operation) and remainder in order to make them both more encyclopedic and to explain things in a way that should make it suitable for the audiences likely to be reading the articles (those whose level of understanding is about where mine was before I started researching the articles). Please review the new versions and see if there are any errors.
One major change I made in this article was an attempt to address the fact that it stated that a and n must be integers. Computers actually also allow floating point, and perhaps even complex numbers, to be used. For example, mod(5.5, 1.3) returns 0.3 (actually, 0.29999999999999982 on my Win32 Python build, due to inherent limitations of floating-point number representation in a binary storage system, for which I'm sure there's an article on Wikipedia somewhere). What I did not do was make a similar change to the remainder article. I would prefer someone more knowledgable than me to clarify whether, and how, non-integers can be divided to produce a quotient and remainder outside of the context of computing. If you or someone could tackle that, that would be great. Thanks! - mjb 04:15, 30 Jan 2005 (UTC)
- I replied on Talk:Remainder. Again, mathematicians don't use these generalizations. Actually, you know what we should add on remainder? Something must be said about remainder when dividing polynomials. That is indeed an existing concept, and a very important one in math. Oleg Alexandrov | talk 05:14, 30 Jan 2005 (UTC)
[edit] On what should be moved and to where
I recommend moving modular operation to this page near the beginning to first define what the modulo function actually does. I say move it here because modular aritmetic is a far more common thing to be searced for and that page can become a redirect page. The clock arithmetic page should also be made to be a redirect page because clock arithmetic is just another way to say it, and not the correct one I might add. As for what to do with advanced modular arithmetic I think it should be mentioned here and the page made into a redirect as well, because it is just more elaboration on a higher level; nothing truly unique enough to really give it its own page.
Either way I am going to move clock arithmetic here and make it a redirect (if it hasn't already been done) because that really makes the most sense for it as it really is just another, less correct, way of saying modular aritmetic.
Guardian of Light 5 July 2005 14:31 (UTC)
- 1. modular operation is simply a recently-created redirect to this article; there was never anything else in it, so there is nothing to merge. Is the redirect insufficient?
- 2. The modulo operation article contains a significant amount of info that is specific to its topic, and it is fairly specialized to the computing field, so it really should remain in a separate article that is merely referenced from the modular arithmetic article. There is nothing to do; nothing needs to be merged. — mjb 5 July 2005 23:54 (UTC)
-
- While the modulo operation does have things in common with modular arithmetic, I would argue that those similarites end at taking the remainder. But even here things are different. Modular arithmetic deals with integers, this article deals mostly with real numbers. I agree with Mjb that this article has a lot of computing specific information which has no place in modular arithmetic. Oleg Alexandrov 6 July 2005 03:21 (UTC)
-
- Yup. I think the modulo operation is also put to use in ways that resemble modular arithmetic, while the operation itself is very remainder-focused. For example, when you have a set of data that is grouped in repeating structures, like an 80×25 grid of character cells in a text display, and you want to know the position (row & column) of the 993rd cell (assume the cells are numbered first by column, then row), the modulo operation is quite useful: row=floor(993÷80) and column=modulo(993÷80) — or column=993 modulo 80. That's a fairly high-level application. A lower-level or more general application would be to find relative offset of a piece of information in any sequential, cyclic data structure, like bits in fixed-width binary values, upon which all primitive datatypes are based. It crops up a lot in binary arithmetic. So you can see (perhaps) how its use quite resembles modular arithmetic in this regard, and the use of the word "modulo" is appropriate as well, but the operation itself is not synonymous with the more general topic of modular arithmetic. — mjb 6 July 2005 05:44 (UTC)
- I see your points. Okay, I'm done here then.Guardian of Light 6 July 2005 13:28 (UTC)
- Yup. I think the modulo operation is also put to use in ways that resemble modular arithmetic, while the operation itself is very remainder-focused. For example, when you have a set of data that is grouped in repeating structures, like an 80×25 grid of character cells in a text display, and you want to know the position (row & column) of the 993rd cell (assume the cells are numbered first by column, then row), the modulo operation is quite useful: row=floor(993÷80) and column=modulo(993÷80) — or column=993 modulo 80. That's a fairly high-level application. A lower-level or more general application would be to find relative offset of a piece of information in any sequential, cyclic data structure, like bits in fixed-width binary values, upon which all primitive datatypes are based. It crops up a lot in binary arithmetic. So you can see (perhaps) how its use quite resembles modular arithmetic in this regard, and the use of the word "modulo" is appropriate as well, but the operation itself is not synonymous with the more general topic of modular arithmetic. — mjb 6 July 2005 05:44 (UTC)
[edit] Operator Symbols
In the section Remainder calculation for the modulo operation, a formula for performing the modulo operation uses a symbol which is apparently the floor function. The symbol encloses the fraction and looks like brackets [] minus the top horizontal lines. This is to suggest adding an internal link to the floor function and/or defining the symbol after the formula. --Sablime 03:13, 1 December 2005 (UTC)
- Done. By the way, one should write ==Operator symbol==, and not ==Operator Symbols==. That if you allow me to pick at minor things also. :) Oleg Alexandrov (talk) 04:02, 1 December 2005 (UTC)
- Thank you for your time and effort. Your edit will help people like me who do not recognize the notation. Also thanks for the capitalization tip. Sablime 04:30, 2 December 2005 (UTC)
[edit] ANSI C
I'm not sure that ANSI/ISO C doesn't define the remainder operator for negative values. The draft on http://www.open-std.org/jtc1/sc22/wg14/www/docs/n843.htm says in 6.6.5 [#6] "When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.76) If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a.". In other words a%b = a-(a/b)*b - I fail to see why that is undefined for a<0. Jefischer 16:29, 4 December 2005 (UTC)
- Because you quoted the C99 draft which uses round towards 0 for a/b. The C89 standard allowed an implementation to implement a/b as round towards 0 or round towards -Inf. TomJF 05:31, 8 February 2006 (UTC)
Years of discussion on comp.lang.c says that you are right :) http://groups.google.co.in/groups/search?q=modulus+negative+comp.lang.c&qt_s=Search —The preceding unsigned comment was added by 203.200.55.101 (talk • contribs) 10:12, 24 April 2006 (UTC).
[edit] fortran 95
In fortran 95 there are two modulo operations mod and modulo. The latter always returns a positive number. —The preceding unsigned comment was added by 203.200.55.101 (talk • contribs) 10:12, 24 April 2006 (UTC).
[edit] Remainder constraint
The constraint formula "0 <= |r| < n" is wrong when n<0, i think it shuld be "0 <= |r| < |n|" or something like that. --Martin Rizzo 15:20, 19 May 2006 (UTC)
[edit] Naming
"Given two numbers, a and n, a modulo n (abbreviated as a mod n) is the remainder, on division of a by n. "
When referring to 'a' or 'n', a name is helpfull. In the paper of Leijen, Daan (December 3, 2001) (see Notes, reference 2) they are described as
- 'a' dividend
- 'n' divisor
--217.140.108.2 10:39, 22 November 2006 (UTC)
Since no protest has arisen, the naming scheme has been adopted.
[edit] FMod
Why does FMod redirect to this page? I dont know of the relevance to this article and FMod is a company and computer game Sound Engine. Mloren 05:37, 26 September 2007 (UTC)
- A quick Google search reveals that
fmod()is a floating-point (not integer) remainder function found in several(?) programming languages. It would be fine to set up a real FMod page for the company and sound engine; just use a template like this one at the very top of that article, like this:
- {{for|the fmod function in computer programming languages|modulo operation}}
- It will result in a message like this: For the fmod function in computer programming languages, see modulo operation. —mjb 06:15, 26 September 2007 (UTC)
[edit] MS Excel
Since when is Excel a programming language? It's an application that some naive users might think of as a programming language.
--BigDumbDinosaur

