Modular arithmetic and wraparound
Modular arithmetic and wraparound
Modular arithmetic means arithmetic inside a fixed range. If the modulus is , then every integer reduced modulo lands in one of these values:
This should be familiar if you have done any programming: a mod q gives a remainder between 0 and q - 1.
In lattice cryptography it is not the modulo operation itself that really matters, it is how we reason about values after they have wrapped around. In normal programming, it is often enough to know the result is inside the range. In lattice cryptography, we often need to ask another question:
How far is this modular value from zero?
For example, modulo , the value is close to , because one more step wraps it back to .
Reducing values modulo
Reducing a value modulo means keeping its remainder after division by . For :
You can read this as: "when is reduced modulo , the result is ". That is because:
The remainder is . A few more examples:
because:
And:
because is one step below , and modulo that lands on . So modular arithmetic keeps values inside a fixed range. Values do not keep growing forever, they wrap back into the range to .
Same value, different integers
Because values wrap around, different integers can land in the same modulo value. For :
These are different integers, but they all land in the same place modulo . We can write this as:
This is read as: ", , , and are congruent modulo ". This does not mean the integers are equal, it means they become the same value after reducing modulo .
A representative is the integer we choose to write down for a modular value. For example, all of these integers represent the same value modulo :
The usual representative is the one in the range:
This is called the standard representative. For the modular value above, the standard representative is .
Signed distance from zero
The standard representative is the usual output of modulo reduction. For , the standard representatives are:
But when we ask whether a modular value is small, we usually do not mean:
Is the standard representative numerically small?
We mean:
How far is this value from after accounting for wraparound?
For example, the standard representative is one step below modulo :
The standard representative is two steps below :
The standard representative is three steps below :
Writing modular values this way is called using centered representatives. For , the standard representatives are:
The centered representatives are:
Or, written in order around zero:
These are the same modular values. The centered version just writes them by signed distance from .
Small values modulo
A modular value is small if its centered representative has small absolute value.
For :
| Standard representative | Centered representative | Distance from |
|---|---|---|
From the table, the values closest to modulo are:
The values and are both distance from . The difference is the sign:
The values and are the farthest from modulo :
So the centered representative gives two pieces of information:
- the sign, meaning which side of the value sits on,
- the size, meaning its distance from .
This is the meaning of "small modulo " used throughout lattice cryptography. It does not mean "small as a standard representative", it means "small after converting to the centered representative".
What about when is even?
When is odd, the centered range is symmetric. For , we used:
When is even, one value sits exactly opposite . For , the standard representatives are:
A common centered range is:
Here:
The value is exactly halfway around the modulo range. It is equally far from in both directions. Some conventions choose . Some choose . The convention we choose is important when writing precise code or proofs. For now, the main point to remember is that values around are the farthest from .
So, in summary:
- values near are close to ,
- after reduction to the standard range, values near represent small negative values,
- values near are far from .
Decoding by distance from zero
Here is a small example of why distance from matters. Suppose we have a rule for turning a modular value back into a bit:
- values near decode as ,
- values near decode as .
If a value meant to be shifts to , it is still close to and decodes correctly. Working modulo , if it shifts to it also decodes correctly, because:
But if it moves near or , it is no longer close to . It is near , and the rule above would decode it as the wrong bit. The arithmetic modulo is still correct; the value has crossed a decoding boundary.
Vectors modulo
A vector modulo has entries that are each interpreted modulo . For example:
Read this as: " is a vector whose entries are considered modulo ". Each entry is called a coefficient. The coefficients are:
To reason about size, we center each coefficient. Modulo :
So the centered version is:
Now we can use the same norm ideas from chapter 2. If we care about the largest coefficient, we use the infinity norm. First take the absolute value of each centered coefficient:
The largest of these is , so:
This tells us that has one coefficient that is far from modulo and that coefficient is in standard form. So although may look large in the standard range, it is actually small after centering. The coefficient is the problem if we are trying to keep every coefficient of the vector close to .
What to remember
- Modular arithmetic keeps values inside a fixed range: to .
- Different integers can land in the same modular value.
- The standard representative is the usual value in the range .
- When reasoning about size, we usually care about signed distance from .
- Centered representatives are the formal way to write that signed-distance view.
- For , the standard representative has centered representative .
- A modular value is small if its centered representative has small absolute value.
- After reduction to the standard range, values near represent small negative values.
- Values near are far from .