Giter VIP home page Giter VIP logo

Comments (4)

asraa avatar asraa commented on June 10, 2024

Here's the poly.add lowering. For x, y inputs to the addition, with coefficient modulus mod and bit width B =2^N in the case that mod does not divide B.

c1, n1 = addui_extended(x, y)
c0 = [c1 % mod] + [n1 * (B % mod)] % mod

Is it possible that the following sum overflows mod 2^N?
[c1 % mod] + [n1 * (B % mod)]

The answer is no. If that were to happen, then

[[(x + y) % B] % mod] + [B % mod] > B

Note both left operands are less than mod. So if this were true, then

mod > B/2

(strictly greater because it does not divide it).

If so, then

[B % mod] < B/2

Which would imply that

[[(x + y) % B] % mod] >  B/2

But this is impossible because mod < B/2

cc @j2kun

from heir.

j2kun avatar j2kun commented on June 10, 2024

Why is mod < B/2 ? I can imagine a (maybe bizarre) case in which the ring is Z/pZ, where p is a prime of the form 2^N - 1, and N is the bit width of the container.

I don't think any of the Mersenne primes align with powers of two, so that's why this case is kind of bizarre. But 2^32 - 5 is prime, as is 2^32 - 17 (see https://t5k.org/lists/2small/0bit.html)

from heir.

asraa avatar asraa commented on June 10, 2024

It's derived from the assumption that the sum overflows (which reaches a contradiction)

[B % mod] < B/2

from heir.

asraa avatar asraa commented on June 10, 2024

@j2kun 's correction

Following mod > B/2, B % mod = B - mod

[[(x + y) % B] % mod] + [B % mod] > B
[[(x + y) % B] % mod] > mod

from heir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.