Testwiki:Reference desk/Archives/Mathematics/2020 August 12

From testwiki
Jump to navigation Jump to search

Template:Error:not substituted

{| width = "100%"

|- ! colspan="3" align="center" | Mathematics desk |- ! width="20%" align="left" | < August 11 ! width="25%" align="center"|<< Jul | August | Sep >> ! width="20%" align="right" |Current desk > |}

Welcome to the Wikipedia Mathematics Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


August 12

Modular Arithmetic

How can I calculate modular subtraction if a is greater than b.

b¯a¯

— Preceding unsigned comment added by 185.181.55.124 (talk) 11:04, 12 August 2020 (UTC)

Courtesy link: Modular arithmetic -- ToE 12:53, 12 August 2020 (UTC)
For modulus Template:Mvar, if your difference is negative, then add as many multiples of Template:Mvar as is necessary to make it nonnegative. Specifically, if Template:Math, then the addition of a single copy of Template:Mvar suffices:
Template:Math
This is similar to how with addition you subtract an Template:Mvar if Template:Math.
-- ToE 12:53, 12 August 2020 (UTC) Edit: Restated in terms of Modulo operator. -- ToE 13:11, 12 August 2020 (UTC) Edited again to correct order in inequality. Thanks Lambiam. -- ToE 15:31, 12 August 2020 (UTC)
Strictly speaking, the equality ba=ba holds in modular arithmetic, also when a is greater than b. But that is apparently not the answer you are looking for; you want a solution to the equation ba=x in which the right-hand side is normalized, that is, such that 0x<n. Recalling the definition of the congruence class denoted by ba, we see that it is the set
{...,(ba)2n,(ba)n,(ba),(ba)+n,(ba)+2n,...},
so that the question now is: which of these infinitely many elements lies in the range from 0 to n1? (I am assuming here that the modulus n>0.) Each element of this set is of the form (ba)+kn, in which k is an integer. So to find x=(ba)+kn subject to the constraint that 0x<n, we need to find k satisfying 0(ba)+kn<n, or, equivalently,
abnk<n+abn.
There is only one integer satisfying both inequations, and if some k does, then k+1 will also satisfy the left inequation and therefore fail the other one. This means that k is the least integer satisfying abnk, and so is given by k=abn, in which denotes the ceiling function. This is of course equivalent to the much simpler answer provided in the first response, but gives an explicit formule for the general case, together with the mathematical reasoning behind it.  --Lambiam 15:06, 12 August 2020 (UTC)
There is a lot of confusion between congruence classes and the remainder function, exacerbated by the fact that computer notation often uses 'mod' to denote the remainder. This can have the effect of making modular arithmetic seem difficult. But actually people do modular arithmetic (addition and subtraction at least) without thinking about it when dealing with time. I assume most people can figure out how many hours it is from 10 o'clock to 2 o'clock without thinking about equivalence classes and residue systems; see the lead section of the article on modular arithmetic. --RDBury (talk) 21:48, 12 August 2020 (UTC)