Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Modulo
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Modulo with offset=== Sometimes it is useful for the result of {{mvar|a}} modulo {{mvar|n}} to lie not between 0 and {{math|''n'' β 1}}, but between some number {{mvar|d}} and {{math|''d'' + ''n'' β 1}}. In that case, {{mvar|d}} is called an ''offset'' and {{math|1=''d'' = 1}} is particularly common. There does not seem to be a standard notation for this operation, so let us tentatively use {{math|''a'' mod<sub>''d''</sub> ''n''}}. We thus have the following definition:<ref name="Mathematica Mod" >{{cite web |url=https://reference.wolfram.com/language/ref/Mod.html |title=Mod |author=<!--Not stated--> |date= 2020 |website= Wolfram Language & System Documentation Center |publisher=[[Wolfram Research]] |access-date=April 8, 2020 }}</ref> {{math|1=''x'' = ''a'' mod<sub>''d''</sub> ''n''}} just in case {{math|''d'' β€ ''x'' β€ ''d'' + ''n'' β 1}} and {{math|1=''x'' mod ''n'' = ''a'' mod ''n''}}. Clearly, the usual modulo operation corresponds to zero offset: {{math|1=''a'' mod ''n'' = ''a'' mod<sub>0</sub> ''n''}}. The operation of modulo with offset is related to the [[Floor and ceiling functions|floor function]] as follows: ::<math>a \operatorname{mod}_d n = a - n \left\lfloor\frac{a-d}{n}\right\rfloor.</math> To see this, let <math display="inline">x = a - n \left\lfloor\frac{a-d}{n}\right\rfloor</math>. We first show that {{math|1=''x'' mod ''n'' = ''a'' mod ''n''}}. It is in general true that {{math|1=(''a'' + ''bn'') mod ''n'' = ''a'' mod ''n''}} for all integers {{mvar|b}}; thus, this is true also in the particular case when <math display="inline">b = -\!\left\lfloor\frac{a-d}{n}\right\rfloor</math>; but that means that <math display="inline">x \bmod n = \left(a - n \left\lfloor\frac{a-d}{n}\right\rfloor\right)\! \bmod n = a \bmod n</math>, which is what we wanted to prove. It remains to be shown that {{math|''d'' β€ ''x'' β€ ''d'' + ''n'' β 1}}. Let {{mvar|k}} and {{mvar|r}} be the integers such that {{math|1=''a'' β ''d'' = ''kn'' + ''r''}} with {{math|0 β€ ''r'' β€ ''n'' β 1}} (see [[Euclidean division]]). Then <math display="inline">\left\lfloor\frac{a-d}{n}\right\rfloor = k</math>, thus <math display="inline">x = a - n \left\lfloor\frac{a-d}{n}\right\rfloor = a - n k = d +r</math>. Now take {{math|0 β€ ''r'' β€ ''n'' β 1}} and add {{mvar|d}} to both sides, obtaining {{math|''d'' β€ ''d'' + ''r'' β€ ''d'' + ''n'' β 1}}. But we've seen that {{math|1=''x'' = ''d'' + ''r''}}, so we are done. The modulo with offset {{math|''a'' mod<sub>''d''</sub> ''n''}} is implemented in [[Mathematica]] as {{code|Mod[a, n, d]}} .<ref name="Mathematica Mod" />
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)